mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-04 18:30:36 +02:00
fcl-passrc: resolver: parse library
git-svn-id: trunk@47936 -
This commit is contained in:
parent
e6037961e3
commit
f0122bd4a0
@ -435,6 +435,7 @@ type
|
|||||||
revkSetOfInt, // set of enum, int, char, widechar, e.g. [1,2..3]
|
revkSetOfInt, // set of enum, int, char, widechar, e.g. [1,2..3]
|
||||||
revkExternal // TResEvalExternal: an external const
|
revkExternal // TResEvalExternal: an external const
|
||||||
);
|
);
|
||||||
|
TREVKinds = set of TREVKind;
|
||||||
const
|
const
|
||||||
revkAllStrings = [{$ifdef FPC_HAS_CPSTRING}revkString,{$endif}revkUnicodeString];
|
revkAllStrings = [{$ifdef FPC_HAS_CPSTRING}revkString,{$endif}revkUnicodeString];
|
||||||
type
|
type
|
||||||
@ -447,6 +448,7 @@ type
|
|||||||
function Clone: TResEvalValue; virtual;
|
function Clone: TResEvalValue; virtual;
|
||||||
function AsDebugString: string; virtual;
|
function AsDebugString: string; virtual;
|
||||||
function AsString: string; virtual;
|
function AsString: string; virtual;
|
||||||
|
function TypeAsString: string; virtual;
|
||||||
end;
|
end;
|
||||||
TResEvalValueClass = class of TResEvalValue;
|
TResEvalValueClass = class of TResEvalValue;
|
||||||
|
|
||||||
@ -459,6 +461,7 @@ type
|
|||||||
constructor CreateValue(const aValue: boolean);
|
constructor CreateValue(const aValue: boolean);
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TResEvalTypedInt = (
|
TResEvalTypedInt = (
|
||||||
@ -520,6 +523,7 @@ type
|
|||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
function AsDebugString: string; override;
|
function AsDebugString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalUInt }
|
{ TResEvalUInt }
|
||||||
@ -531,6 +535,7 @@ type
|
|||||||
constructor CreateValue(const aValue: TMaxPrecUInt);
|
constructor CreateValue(const aValue: TMaxPrecUInt);
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalFloat }
|
{ TResEvalFloat }
|
||||||
@ -543,6 +548,7 @@ type
|
|||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
function IsInt(out Int: TMaxPrecInt): boolean;
|
function IsInt(out Int: TMaxPrecInt): boolean;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalCurrency }
|
{ TResEvalCurrency }
|
||||||
@ -556,6 +562,7 @@ type
|
|||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
function IsInt(out Int: TMaxPrecInt): boolean;
|
function IsInt(out Int: TMaxPrecInt): boolean;
|
||||||
function AsInt: TMaxPrecInt; // value * 10.000
|
function AsInt: TMaxPrecInt; // value * 10.000
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ifdef FPC_HAS_CPSTRING}
|
{$ifdef FPC_HAS_CPSTRING}
|
||||||
@ -569,6 +576,7 @@ type
|
|||||||
constructor CreateValue(const aValue: RawByteString);
|
constructor CreateValue(const aValue: RawByteString);
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
@ -581,6 +589,7 @@ type
|
|||||||
constructor CreateValue(const aValue: UnicodeString);
|
constructor CreateValue(const aValue: UnicodeString);
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalEnum - Kind=revkEnum, Value.Int }
|
{ TResEvalEnum - Kind=revkEnum, Value.Int }
|
||||||
@ -596,6 +605,7 @@ type
|
|||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsDebugString: string; override;
|
function AsDebugString: string; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TRESetElKind = (
|
TRESetElKind = (
|
||||||
@ -620,6 +630,7 @@ type
|
|||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
function AsDebugString: string; override;
|
function AsDebugString: string; override;
|
||||||
function ElementAsString(El: TMaxPrecInt): string; virtual;
|
function ElementAsString(El: TMaxPrecInt): string; virtual;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalRangeUInt }
|
{ TResEvalRangeUInt }
|
||||||
@ -631,6 +642,7 @@ type
|
|||||||
constructor CreateValue(const aRangeStart, aRangeEnd: TMaxPrecUInt);
|
constructor CreateValue(const aRangeStart, aRangeEnd: TMaxPrecUInt);
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TResEvalSet - Kind=revkSetOfInt }
|
{ TResEvalSet - Kind=revkSetOfInt }
|
||||||
@ -652,6 +664,7 @@ type
|
|||||||
const aRangeStart, aRangeEnd: TMaxPrecInt); override;
|
const aRangeStart, aRangeEnd: TMaxPrecInt); override;
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
function Add(aRangeStart, aRangeEnd: TMaxPrecInt): boolean; // false if duplicate ignored
|
function Add(aRangeStart, aRangeEnd: TMaxPrecInt): boolean; // false if duplicate ignored
|
||||||
function IndexOfRange(Index: TMaxPrecInt; FindInsertPos: boolean = false): integer;
|
function IndexOfRange(Index: TMaxPrecInt; FindInsertPos: boolean = false): integer;
|
||||||
function Intersects(aRangeStart, aRangeEnd: TMaxPrecInt): integer; // returns index of first intersecting range
|
function Intersects(aRangeStart, aRangeEnd: TMaxPrecInt): integer; // returns index of first intersecting range
|
||||||
@ -665,6 +678,7 @@ type
|
|||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
function Clone: TResEvalValue; override;
|
function Clone: TResEvalValue; override;
|
||||||
function AsString: string; override;
|
function AsString: string; override;
|
||||||
|
function TypeAsString: string; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TResEvalFlag = (
|
TResEvalFlag = (
|
||||||
@ -1188,6 +1202,11 @@ begin
|
|||||||
Result:=inherited AsString;
|
Result:=inherited AsString;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalExternal.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='external value';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalCurrency }
|
{ TResEvalCurrency }
|
||||||
|
|
||||||
constructor TResEvalCurrency.Create;
|
constructor TResEvalCurrency.Create;
|
||||||
@ -1231,6 +1250,11 @@ begin
|
|||||||
{$endif};
|
{$endif};
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalCurrency.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='currency';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalBool }
|
{ TResEvalBool }
|
||||||
|
|
||||||
constructor TResEvalBool.Create;
|
constructor TResEvalBool.Create;
|
||||||
@ -1259,6 +1283,11 @@ begin
|
|||||||
Result:='false';
|
Result:='false';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalBool.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='boolean';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalRangeUInt }
|
{ TResEvalRangeUInt }
|
||||||
|
|
||||||
constructor TResEvalRangeUInt.Create;
|
constructor TResEvalRangeUInt.Create;
|
||||||
@ -1287,6 +1316,11 @@ begin
|
|||||||
Result:=IntToStr(RangeStart)+'..'+IntToStr(RangeEnd);
|
Result:=IntToStr(RangeStart)+'..'+IntToStr(RangeEnd);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalRangeUInt.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='unsigned integer range';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResExprEvaluator }
|
{ TResExprEvaluator }
|
||||||
|
|
||||||
procedure TResExprEvaluator.LogMsg(const id: TMaxPrecInt; MsgType: TMessageType;
|
procedure TResExprEvaluator.LogMsg(const id: TMaxPrecInt; MsgType: TMessageType;
|
||||||
@ -5615,6 +5649,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalValue.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
case Kind of
|
||||||
|
revkNil: Result:='nil';
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalUInt }
|
{ TResEvalUInt }
|
||||||
|
|
||||||
constructor TResEvalUInt.Create;
|
constructor TResEvalUInt.Create;
|
||||||
@ -5640,6 +5683,11 @@ begin
|
|||||||
Result:=IntToStr(UInt);
|
Result:=IntToStr(UInt);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalUInt.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='unsigned int';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalInt }
|
{ TResEvalInt }
|
||||||
|
|
||||||
constructor TResEvalInt.Create;
|
constructor TResEvalInt.Create;
|
||||||
@ -5697,6 +5745,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalInt.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
case Typed of
|
||||||
|
reitByte: Result:='byte';
|
||||||
|
reitShortInt: Result:='shortint';
|
||||||
|
reitWord: Result:='word';
|
||||||
|
reitSmallInt: Result:='smallint';
|
||||||
|
reitUIntSingle: Result:='unsinged int single';
|
||||||
|
reitIntSingle: Result:='int single';
|
||||||
|
reitLongWord: Result:='longword';
|
||||||
|
reitLongInt: Result:='longint';
|
||||||
|
reitUIntDouble: Result:='unsigned int double';
|
||||||
|
reitIntDouble: Result:='int double';
|
||||||
|
else
|
||||||
|
Result:='int';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalFloat }
|
{ TResEvalFloat }
|
||||||
|
|
||||||
constructor TResEvalFloat.Create;
|
constructor TResEvalFloat.Create;
|
||||||
@ -5732,6 +5798,11 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalFloat.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='float';
|
||||||
|
end;
|
||||||
|
|
||||||
{$ifdef FPC_HAS_CPSTRING}
|
{$ifdef FPC_HAS_CPSTRING}
|
||||||
{ TResEvalString }
|
{ TResEvalString }
|
||||||
|
|
||||||
@ -5759,6 +5830,15 @@ function TResEvalString.AsString: string;
|
|||||||
begin
|
begin
|
||||||
Result:=RawStrToCaption(S,60);
|
Result:=RawStrToCaption(S,60);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalString.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
if OnlyASCII then
|
||||||
|
Result:='string'
|
||||||
|
else
|
||||||
|
Result:='ansistring';
|
||||||
|
end;
|
||||||
|
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
{ TResEvalUTF16 }
|
{ TResEvalUTF16 }
|
||||||
@ -5786,6 +5866,11 @@ begin
|
|||||||
Result:=String(UnicodeStrToCaption(S,60));
|
Result:=String(UnicodeStrToCaption(S,60));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalUTF16.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='unicodestring';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalEnum }
|
{ TResEvalEnum }
|
||||||
|
|
||||||
constructor TResEvalEnum.Create;
|
constructor TResEvalEnum.Create;
|
||||||
@ -5849,6 +5934,13 @@ begin
|
|||||||
Result:=ElType.Name+'('+IntToStr(Index)+')';
|
Result:=ElType.Name+'('+IntToStr(Index)+')';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalEnum.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:=ElType.Name;
|
||||||
|
if Result='' then
|
||||||
|
Result:='enum';
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalRangeInt }
|
{ TResEvalRangeInt }
|
||||||
|
|
||||||
constructor TResEvalRangeInt.Create;
|
constructor TResEvalRangeInt.Create;
|
||||||
@ -5920,6 +6012,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalRangeInt.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
case ElKind of
|
||||||
|
revskEnum: Result:='enum range';
|
||||||
|
revskInt: Result:='integer range';
|
||||||
|
revskChar: Result:='char range';
|
||||||
|
revskBool: Result:='boolean range';
|
||||||
|
else
|
||||||
|
Result:='integer range';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TResEvalSet }
|
{ TResEvalSet }
|
||||||
|
|
||||||
constructor TResEvalSet.Create;
|
constructor TResEvalSet.Create;
|
||||||
@ -5980,6 +6084,11 @@ begin
|
|||||||
Result:=Result+']';
|
Result:=Result+']';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TResEvalSet.TypeAsString: string;
|
||||||
|
begin
|
||||||
|
Result:='set';
|
||||||
|
end;
|
||||||
|
|
||||||
function TResEvalSet.Add(aRangeStart, aRangeEnd: TMaxPrecInt): boolean;
|
function TResEvalSet.Add(aRangeStart, aRangeEnd: TMaxPrecInt): boolean;
|
||||||
|
|
||||||
{$IF FPC_FULLVERSION<30101}
|
{$IF FPC_FULLVERSION<30101}
|
||||||
|
@ -1698,6 +1698,7 @@ type
|
|||||||
procedure FinishAncestors(aClass: TPasClassType); virtual;
|
procedure FinishAncestors(aClass: TPasClassType); virtual;
|
||||||
procedure FinishMethodResolution(El: TPasMethodResolution); virtual;
|
procedure FinishMethodResolution(El: TPasMethodResolution); virtual;
|
||||||
procedure FinishAttributes(El: TPasAttributes); virtual;
|
procedure FinishAttributes(El: TPasAttributes); virtual;
|
||||||
|
procedure FinishExportSymbol(El: TPasExportSymbol); virtual;
|
||||||
procedure FinishProcParamAccess(ProcType: TPasProcedureType; Params: TParamsExpr); virtual;
|
procedure FinishProcParamAccess(ProcType: TPasProcedureType; Params: TParamsExpr); virtual;
|
||||||
procedure FinishPropertyParamAccess(Params: TParamsExpr;
|
procedure FinishPropertyParamAccess(Params: TParamsExpr;
|
||||||
Prop: TPasProperty); virtual;
|
Prop: TPasProperty); virtual;
|
||||||
@ -5826,6 +5827,7 @@ begin
|
|||||||
FinishSection(TPasLibrary(CurModule).LibrarySection);
|
FinishSection(TPasLibrary(CurModule).LibrarySection);
|
||||||
// resolve begin..end block
|
// resolve begin..end block
|
||||||
ResolveImplBlock(CurModule.InitializationSection);
|
ResolveImplBlock(CurModule.InitializationSection);
|
||||||
|
ResolveImplBlock(CurModule.FinalizationSection);
|
||||||
end
|
end
|
||||||
else if (CurModuleClass=TPasModule) then
|
else if (CurModuleClass=TPasModule) then
|
||||||
begin
|
begin
|
||||||
@ -7776,6 +7778,8 @@ begin
|
|||||||
FinishMethodResolution(TPasMethodResolution(El))
|
FinishMethodResolution(TPasMethodResolution(El))
|
||||||
else if C=TPasAttributes then
|
else if C=TPasAttributes then
|
||||||
FinishAttributes(TPasAttributes(El))
|
FinishAttributes(TPasAttributes(El))
|
||||||
|
else if C=TPasExportSymbol then
|
||||||
|
FinishExportSymbol(TPasExportSymbol(El))
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
{$IFDEF VerbosePasResolver}
|
{$IFDEF VerbosePasResolver}
|
||||||
@ -9133,6 +9137,31 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPasResolver.FinishExportSymbol(El: TPasExportSymbol);
|
||||||
|
|
||||||
|
procedure CheckExpExpr(Expr: TPasExpr; Kinds: TREVKinds; const Expected: string);
|
||||||
|
var
|
||||||
|
Value: TResEvalValue;
|
||||||
|
ResolvedEl: TPasResolverResult;
|
||||||
|
begin
|
||||||
|
if Expr=nil then exit;
|
||||||
|
ResolveExpr(Expr,rraRead);
|
||||||
|
Value:=Eval(Expr,[refConst]);
|
||||||
|
if (Value<>nil) and (Value.Kind in Kinds) then
|
||||||
|
begin
|
||||||
|
ReleaseEvalValue(Value);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
ReleaseEvalValue(Value);
|
||||||
|
ComputeElement(Expr,ResolvedEl,[rcConstant]);
|
||||||
|
RaiseXExpectedButYFound(20210101194628,Expected,GetTypeDescription(ResolvedEl),Expr);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
CheckExpExpr(El.ExportIndex,[revkInt,revkUInt],'integer');
|
||||||
|
CheckExpExpr(El.ExportName,[revkString,revkUnicodeString],'string');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPasResolver.FinishProcParamAccess(ProcType: TPasProcedureType;
|
procedure TPasResolver.FinishProcParamAccess(ProcType: TPasProcedureType;
|
||||||
Params: TParamsExpr);
|
Params: TParamsExpr);
|
||||||
var
|
var
|
||||||
@ -20836,6 +20865,7 @@ begin
|
|||||||
else if AClass.InheritsFrom(TPasImplBlock) then
|
else if AClass.InheritsFrom(TPasImplBlock) then
|
||||||
// resolved when finished
|
// resolved when finished
|
||||||
else if AClass=TPasAttributes then
|
else if AClass=TPasAttributes then
|
||||||
|
else if AClass=TPasExportSymbol then
|
||||||
else if AClass=TPasUnresolvedUnitRef then
|
else if AClass=TPasUnresolvedUnitRef then
|
||||||
RaiseMsg(20171018121900,nCantFindUnitX,sCantFindUnitX,[AName],El)
|
RaiseMsg(20171018121900,nCantFindUnitX,sCantFindUnitX,[AName],El)
|
||||||
else
|
else
|
||||||
|
@ -447,6 +447,7 @@ type
|
|||||||
PackageName: string;
|
PackageName: string;
|
||||||
Filename : String; // the IN filename, only written when not empty.
|
Filename : String; // the IN filename, only written when not empty.
|
||||||
end;
|
end;
|
||||||
|
TPasModuleClass = class of TPasModule;
|
||||||
|
|
||||||
{ TPasUnitModule }
|
{ TPasUnitModule }
|
||||||
|
|
||||||
|
@ -4360,6 +4360,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
if not (CurToken in [tkComma,tkSemicolon]) then
|
if not (CurToken in [tkComma,tkSemicolon]) then
|
||||||
ParseExc(nParserExpectedCommaSemicolon,SParserExpectedCommaSemicolon);
|
ParseExc(nParserExpectedCommaSemicolon,SParserExpectedCommaSemicolon);
|
||||||
|
Engine.FinishScope(stDeclaration,E);
|
||||||
until (CurToken=tkSemicolon);
|
until (CurToken=tkSemicolon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -142,7 +142,9 @@ type
|
|||||||
Procedure TearDown; override;
|
Procedure TearDown; override;
|
||||||
procedure CreateEngine(var TheEngine: TPasTreeContainer); override;
|
procedure CreateEngine(var TheEngine: TPasTreeContainer); override;
|
||||||
procedure ParseModule; override;
|
procedure ParseModule; override;
|
||||||
|
procedure ParseMain(ExpectedModuleClass: TPasModuleClass); virtual;
|
||||||
procedure ParseProgram; virtual;
|
procedure ParseProgram; virtual;
|
||||||
|
procedure ParseLibrary; virtual;
|
||||||
procedure ParseUnit; virtual;
|
procedure ParseUnit; virtual;
|
||||||
procedure CheckReferenceDirectives; virtual;
|
procedure CheckReferenceDirectives; virtual;
|
||||||
procedure CheckResolverHint(MsgType: TMessageType; MsgNumber: integer;
|
procedure CheckResolverHint(MsgType: TMessageType; MsgNumber: integer;
|
||||||
@ -172,6 +174,7 @@ type
|
|||||||
ImplementationSrc: string): TTestEnginePasResolver;
|
ImplementationSrc: string): TTestEnginePasResolver;
|
||||||
procedure AddSystemUnit(Parts: TSystemUnitParts = []);
|
procedure AddSystemUnit(Parts: TSystemUnitParts = []);
|
||||||
procedure StartProgram(NeedSystemUnit: boolean; SystemUnitParts: TSystemUnitParts = []);
|
procedure StartProgram(NeedSystemUnit: boolean; SystemUnitParts: TSystemUnitParts = []);
|
||||||
|
procedure StartLibrary(NeedSystemUnit: boolean; SystemUnitParts: TSystemUnitParts = []);
|
||||||
procedure StartUnit(NeedSystemUnit: boolean);
|
procedure StartUnit(NeedSystemUnit: boolean);
|
||||||
property Modules[Index: integer]: TTestEnginePasResolver read GetModules;
|
property Modules[Index: integer]: TTestEnginePasResolver read GetModules;
|
||||||
property ModuleCount: integer read GetModuleCount;
|
property ModuleCount: integer read GetModuleCount;
|
||||||
@ -975,6 +978,15 @@ type
|
|||||||
Procedure TestAttributes_NonConstParam_Fail;
|
Procedure TestAttributes_NonConstParam_Fail;
|
||||||
Procedure TestAttributes_UnknownAttrWarning;
|
Procedure TestAttributes_UnknownAttrWarning;
|
||||||
Procedure TestAttributes_Members;
|
Procedure TestAttributes_Members;
|
||||||
|
|
||||||
|
// library
|
||||||
|
Procedure TestLibrary_Empty;
|
||||||
|
Procedure TestLibrary_ExportFunc;
|
||||||
|
Procedure TestLibrary_ExportFunc_NameIntFail;
|
||||||
|
Procedure TestLibrary_ExportFunc_IndexStringFail;
|
||||||
|
Procedure TestLibrary_ExportVar; // ToDo
|
||||||
|
Procedure TestLibrary_Initialization_Finalization;
|
||||||
|
// ToDo Procedure TestLibrary_UnitExports;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function LinesToStr(Args: array of const): string;
|
function LinesToStr(Args: array of const): string;
|
||||||
@ -1193,7 +1205,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomTestResolver.ParseProgram;
|
procedure TCustomTestResolver.ParseMain(ExpectedModuleClass: TPasModuleClass);
|
||||||
var
|
var
|
||||||
aFilename: String;
|
aFilename: String;
|
||||||
aRow, aCol: Integer;
|
aRow, aCol: Integer;
|
||||||
@ -1208,7 +1220,7 @@ begin
|
|||||||
aRow:=E.Row;
|
aRow:=E.Row;
|
||||||
aCol:=E.Column;
|
aCol:=E.Column;
|
||||||
WriteSources(aFilename,aRow,aCol);
|
WriteSources(aFilename,aRow,aCol);
|
||||||
writeln('ERROR: TTestResolver.ParseProgram Parser: '+E.ClassName+':'+E.Message,
|
writeln('ERROR: TTestResolver.ParseMain ',ExpectedModuleClass.ClassName,' Parser: '+E.ClassName+':'+E.Message,
|
||||||
' Scanner at'
|
' Scanner at'
|
||||||
+' '+aFilename+'('+IntToStr(aRow)+','+IntToStr(aCol)+')'
|
+' '+aFilename+'('+IntToStr(aRow)+','+IntToStr(aCol)+')'
|
||||||
+' Line="'+Scanner.CurLine+'"');
|
+' Line="'+Scanner.CurLine+'"');
|
||||||
@ -1225,17 +1237,22 @@ begin
|
|||||||
ResolverEngine.UnmangleSourceLineNumber(E.PasElement.SourceLinenumber,aRow,aCol);
|
ResolverEngine.UnmangleSourceLineNumber(E.PasElement.SourceLinenumber,aRow,aCol);
|
||||||
end;
|
end;
|
||||||
WriteSources(aFilename,aRow,aCol);
|
WriteSources(aFilename,aRow,aCol);
|
||||||
writeln('ERROR: TTestResolver.ParseProgram PasResolver: '+E.ClassName+':'+E.Message
|
writeln('ERROR: TTestResolver.ParseMain ',ExpectedModuleClass.ClassName,' PasResolver: '+E.ClassName+':'+E.Message
|
||||||
+' at '+aFilename+'('+IntToStr(aRow)+','+IntToStr(aCol)+')');
|
+' at '+aFilename+'('+IntToStr(aRow)+','+IntToStr(aCol)+')');
|
||||||
Fail(E.Message);
|
Fail(E.Message);
|
||||||
end;
|
end;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
begin
|
begin
|
||||||
writeln('ERROR: TTestResolver.ParseProgram Exception: '+E.ClassName+':'+E.Message);
|
writeln('ERROR: TTestResolver.ParseMain ',ExpectedModuleClass.ClassName,' Exception: '+E.ClassName+':'+E.Message);
|
||||||
Fail(E.Message);
|
Fail(E.Message);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
TAssert.AssertSame('Has resolver',ResolverEngine,Parser.Engine);
|
TAssert.AssertSame('Has resolver',ResolverEngine,Parser.Engine);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTestResolver.ParseProgram;
|
||||||
|
begin
|
||||||
|
ParseMain(TPasProgram);
|
||||||
AssertEquals('Has program',TPasProgram,Module.ClassType);
|
AssertEquals('Has program',TPasProgram,Module.ClassType);
|
||||||
AssertNotNull('Has program section',PasProgram.ProgramSection);
|
AssertNotNull('Has program section',PasProgram.ProgramSection);
|
||||||
AssertNotNull('Has initialization section',PasProgram.InitializationSection);
|
AssertNotNull('Has initialization section',PasProgram.InitializationSection);
|
||||||
@ -1245,39 +1262,18 @@ begin
|
|||||||
CheckReferenceDirectives;
|
CheckReferenceDirectives;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTestResolver.ParseLibrary;
|
||||||
|
begin
|
||||||
|
ParseMain(TPasLibrary);
|
||||||
|
AssertEquals('Has library',TPasLibrary,Module.ClassType);
|
||||||
|
AssertNotNull('Has library section',PasLibrary.LibrarySection);
|
||||||
|
AssertNotNull('Has initialization section',PasLibrary.InitializationSection);
|
||||||
|
CheckReferenceDirectives;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomTestResolver.ParseUnit;
|
procedure TCustomTestResolver.ParseUnit;
|
||||||
begin
|
begin
|
||||||
FFirstStatement:=nil;
|
ParseMain(TPasModule);
|
||||||
try
|
|
||||||
ParseModule;
|
|
||||||
except
|
|
||||||
on E: EParserError do
|
|
||||||
begin
|
|
||||||
writeln('ERROR: TTestResolver.ParseUnit Parser: '+E.ClassName+':'+E.Message
|
|
||||||
+' File='+Scanner.CurFilename
|
|
||||||
+' LineNo='+IntToStr(Scanner.CurRow)
|
|
||||||
+' Col='+IntToStr(Scanner.CurColumn)
|
|
||||||
+' Line="'+Scanner.CurLine+'"'
|
|
||||||
);
|
|
||||||
Fail(E.Message);
|
|
||||||
end;
|
|
||||||
on E: EPasResolve do
|
|
||||||
begin
|
|
||||||
writeln('ERROR: TTestResolver.ParseUnit PasResolver: '+E.ClassName+':'+E.Message
|
|
||||||
+' File='+Scanner.CurFilename
|
|
||||||
+' LineNo='+IntToStr(Scanner.CurRow)
|
|
||||||
+' Col='+IntToStr(Scanner.CurColumn)
|
|
||||||
+' Line="'+Scanner.CurLine+'"'
|
|
||||||
);
|
|
||||||
Fail(E.Message);
|
|
||||||
end;
|
|
||||||
on E: Exception do
|
|
||||||
begin
|
|
||||||
writeln('ERROR: TTestResolver.ParseUnit Exception: '+E.ClassName+':'+E.Message);
|
|
||||||
Fail(E.Message);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
TAssert.AssertSame('Has resolver',ResolverEngine,Parser.Engine);
|
|
||||||
AssertEquals('Has unit',TPasModule,Module.ClassType);
|
AssertEquals('Has unit',TPasModule,Module.ClassType);
|
||||||
AssertNotNull('Has interface section',Module.InterfaceSection);
|
AssertNotNull('Has interface section',Module.InterfaceSection);
|
||||||
AssertNotNull('Has implementation section',Module.ImplementationSection);
|
AssertNotNull('Has implementation section',Module.ImplementationSection);
|
||||||
@ -2333,6 +2329,16 @@ begin
|
|||||||
Add('program '+ExtractFileUnitName(MainFilename)+';');
|
Add('program '+ExtractFileUnitName(MainFilename)+';');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomTestResolver.StartLibrary(NeedSystemUnit: boolean;
|
||||||
|
SystemUnitParts: TSystemUnitParts);
|
||||||
|
begin
|
||||||
|
if NeedSystemUnit then
|
||||||
|
AddSystemUnit(SystemUnitParts)
|
||||||
|
else
|
||||||
|
Parser.ImplicitUses.Clear;
|
||||||
|
Add('library '+ExtractFileUnitName(MainFilename)+';');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomTestResolver.StartUnit(NeedSystemUnit: boolean);
|
procedure TCustomTestResolver.StartUnit(NeedSystemUnit: boolean);
|
||||||
begin
|
begin
|
||||||
if NeedSystemUnit then
|
if NeedSystemUnit then
|
||||||
@ -3623,7 +3629,7 @@ begin
|
|||||||
' m=low(char)+high(char);',
|
' m=low(char)+high(char);',
|
||||||
' n = string(''A'');',
|
' n = string(''A'');',
|
||||||
' o = UnicodeString(''A'');',
|
' o = UnicodeString(''A'');',
|
||||||
//' p = ^C''bird'';',
|
' p = ^C''bird'';',
|
||||||
'begin']);
|
'begin']);
|
||||||
ParseProgram;
|
ParseProgram;
|
||||||
CheckResolverUnexpectedHints;
|
CheckResolverUnexpectedHints;
|
||||||
@ -18738,6 +18744,95 @@ begin
|
|||||||
CheckAttributeMarkers;
|
CheckAttributeMarkers;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_Empty;
|
||||||
|
begin
|
||||||
|
StartLibrary(false);
|
||||||
|
Add(['begin']);
|
||||||
|
ParseLibrary;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_ExportFunc;
|
||||||
|
begin
|
||||||
|
StartLibrary(false);
|
||||||
|
Add([
|
||||||
|
'procedure Run;',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'procedure Fly;',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'exports',
|
||||||
|
' Run,',
|
||||||
|
' Fly name ''FlyHi'';',
|
||||||
|
'exports',
|
||||||
|
' Run index 3+4;',
|
||||||
|
'begin',
|
||||||
|
'']);
|
||||||
|
ParseLibrary;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_ExportFunc_NameIntFail;
|
||||||
|
begin
|
||||||
|
StartLibrary(false);
|
||||||
|
Add([
|
||||||
|
'procedure Run;',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'exports',
|
||||||
|
' Run name 4;',
|
||||||
|
'begin',
|
||||||
|
'']);
|
||||||
|
CheckResolverException('string expected, but Longint found',nXExpectedButYFound);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_ExportFunc_IndexStringFail;
|
||||||
|
begin
|
||||||
|
StartLibrary(false);
|
||||||
|
Add([
|
||||||
|
'procedure Run;',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'exports',
|
||||||
|
' Run index ''abc'';',
|
||||||
|
'begin',
|
||||||
|
'']);
|
||||||
|
CheckResolverException('integer expected, but String found',nXExpectedButYFound);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_ExportVar;
|
||||||
|
begin
|
||||||
|
exit;
|
||||||
|
|
||||||
|
StartLibrary(false);
|
||||||
|
Add([
|
||||||
|
'var',
|
||||||
|
' Size: word; export name ''size'';',
|
||||||
|
'exports',
|
||||||
|
' Size,',
|
||||||
|
' Fly as ''FlyHi'',',
|
||||||
|
' Run index 3+4;',
|
||||||
|
'begin',
|
||||||
|
'']);
|
||||||
|
ParseLibrary;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestResolver.TestLibrary_Initialization_Finalization;
|
||||||
|
begin
|
||||||
|
StartLibrary(false);
|
||||||
|
Add([
|
||||||
|
'procedure Run(w: word);',
|
||||||
|
'begin',
|
||||||
|
'end;',
|
||||||
|
'exports',
|
||||||
|
' Run;',
|
||||||
|
'initialization',
|
||||||
|
' Run(3);',
|
||||||
|
'finalization',
|
||||||
|
' Run(4);',
|
||||||
|
'']);
|
||||||
|
ParseLibrary;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterTests([TTestResolver]);
|
RegisterTests([TTestResolver]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user