* Added support for class methods/properties in records

git-svn-id: trunk@31205 -
This commit is contained in:
michael 2015-07-12 07:25:08 +00:00
parent 960a72f821
commit d900f4a29f
3 changed files with 215 additions and 136 deletions

View File

@ -683,7 +683,7 @@ type
Args: TFPList; // List of TPasArgument objects
ReadAccessorName, WriteAccessorName,ImplementsName,
StoredAccessorName: string;
IsDefault, IsNodefault: Boolean;
IsClass, IsDefault, IsNodefault: Boolean;
Function ResolvedType : TPasType;
Function IndexValue : String;
Function DefaultValue : string;

View File

@ -64,6 +64,9 @@ resourcestring
SParserNoFieldsAllowed = 'Fields are not allowed in Interfaces';
SParserInvalidRecordVisibility = 'Records can only have public and (strict) private as visibility specifiers';
SErrRecordMethodsNotAllowed = 'Record methods not allowed at this location.';
SErrRecordPropertiesNotAllowed = 'Record properties not allowed at this location.';
SErrRecordVisibilityNotAllowed = 'Record visibilities not allowed at this location.';
type
TPasParserLogHandler = Procedure (Sender : TObject; Const Msg : String) of object;
TPParserLogEvent = (pleInterface,pleImplementation);
@ -154,6 +157,7 @@ type
procedure ParseClassLocalConsts(AType: TPasClassType; AVisibility: TPasMemberVisibility);
procedure ParseClassLocalTypes(AType: TPasClassType; AVisibility: TPasMemberVisibility);
procedure ParseVarList(Parent: TPasElement; VarList: TFPList; AVisibility: TPasMemberVisibility; Full: Boolean);
procedure SetOptions(AValue: TPOptions);
protected
Function SaveComments : String;
Function SaveComments(Const AValue : String) : String;
@ -257,7 +261,7 @@ type
property Engine: TPasTreeContainer read FEngine;
property CurToken: TToken read FCurToken;
property CurTokenString: String read FCurTokenString;
Property Options : TPOptions Read FOptions Write FOptions;
Property Options : TPOptions Read FOptions Write SetOptions;
Property CurModule : TPasModule Read FCurModule;
Property LogEvents : TPParserLogEvents Read FLogEvents Write FLogEvents;
Property OnLog : TPasParserLogHandler Read FOnLog Write FOnLog;
@ -569,7 +573,7 @@ begin
end;
end;
Destructor TPasParser.Destroy;
destructor TPasParser.Destroy;
begin
FreeAndNil(FCommentsBuffer[0]);
FreeAndNil(FCommentsBuffer[1]);
@ -596,12 +600,12 @@ begin
end;
end;
Function TPasParser.CurComments: TStrings;
function TPasParser.CurComments: TStrings;
begin
Result:=FCurComments;
end;
Function TPasParser.SavedComments: String;
function TPasParser.SavedComments: String;
begin
Result:=FSavedComments;
end;
@ -696,13 +700,13 @@ begin
Result := CurTokenString;
end;
Function TPasParser.CurTokenIsIdentifier(Const S: String): Boolean;
function TPasParser.CurTokenIsIdentifier(const S: String): Boolean;
begin
Result:=(Curtoken=tkidentifier) and (CompareText(S,CurtokenText)=0);
end;
Function TPasParser.IsCurTokenHint(out AHint : TPasMemberHint) : Boolean;
function TPasParser.IsCurTokenHint(out AHint: TPasMemberHint): Boolean;
begin
Result:=CurToken=tklibrary;
if Result then
@ -711,21 +715,21 @@ begin
Result:=IsHintToken(CurTokenString,ahint);
end;
Function TPasParser.IsCurTokenHint: Boolean;
function TPasParser.IsCurTokenHint: Boolean;
var
dummy : TPasMemberHint;
begin
Result:=IsCurTokenHint(dummy);
end;
Function TPasParser.TokenIsCallingConvention(S: String; out
function TPasParser.TokenIsCallingConvention(S: String; out
CC: TCallingConvention): Boolean;
begin
Result:=IsCallingConvention(S,CC);
end;
Function TPasParser.TokenIsProcedureModifier(Parent: TPasElement; S: String;
Out Pm: TProcedureModifier): Boolean;
function TPasParser.TokenIsProcedureModifier(Parent: TPasElement; S: String;
out Pm: TProcedureModifier): Boolean;
begin
Result:=IsModifier(S,PM);
if result and (pm in [pmPublic,pmForward]) then
@ -737,7 +741,8 @@ begin
end;
Function TPasParser.CheckHint(Element : TPasElement; ExpectSemiColon : Boolean) : TPasMemberHints;
function TPasParser.CheckHint(Element: TPasElement; ExpectSemiColon: Boolean
): TPasMemberHints;
Var
Found : Boolean;
@ -843,7 +848,8 @@ begin
end;
end;
function TPasParser.ParseSimpleType(Parent: TPasElement; Const TypeName : String; IsFull : Boolean = False): TPasType;
function TPasParser.ParseSimpleType(Parent: TPasElement;
const TypeName: String; IsFull: Boolean): TPasType;
Type
TSimpleTypeKind = (stkAlias,stkString,stkRange);
@ -917,7 +923,8 @@ begin
end;
// On entry, we're on the TYPE token
function TPasParser.ParseAliasType(Parent: TPasElement; Const TypeName: String): TPasTypeAliasType;
function TPasParser.ParseAliasType(Parent: TPasElement; const TypeName: String
): TPasTypeAliasType;
begin
Result := TPasTypeAliasType(CreateElement(TPasTypeAliasType, TypeName, Parent));
try
@ -928,7 +935,8 @@ begin
end;
end;
function TPasParser.ParsePointerType(Parent : TPasElement; Const TypeName : String) : TPasPointerType;
function TPasParser.ParsePointerType(Parent: TPasElement; const TypeName: String
): TPasPointerType;
begin
Result := TPasPointerType(CreateElement(TPasPointerType, TypeName, Parent));
@ -991,7 +999,8 @@ begin
end;
end;
function TPasParser.ParseType(Parent: TPasElement; Const TypeName : String = ''; Full : Boolean = False): TPasType;
function TPasParser.ParseType(Parent: TPasElement; const TypeName: String;
Full: Boolean): TPasType;
Const
// These types are allowed only when full type declarations
@ -1079,7 +1088,8 @@ begin
end;
end;
Function TPasParser.ParseArrayType(Parent : TPasElement; Const TypeName : String; PackMode : TPackMode) : TPasArrayType;
function TPasParser.ParseArrayType(Parent: TPasElement; const TypeName: String;
PackMode: TPackMode): TPasArrayType;
Var
S : String;
@ -1121,7 +1131,8 @@ begin
end;
end;
Function TPasParser.ParseFileType(Parent : TPasElement; Const TypeName : String) : TPasFileType;
function TPasParser.ParseFileType(Parent: TPasElement; const TypeName: String
): TPasFileType;
begin
@ -1187,7 +1198,7 @@ begin
end;
end;
Function TPasParser.TokenToExprOp (AToken : TToken) : TExprOpCode;
function TPasParser.TokenToExprOp(AToken: TToken): TExprOpCode;
begin
Case AToken of
@ -2282,7 +2293,7 @@ end;
// Starts after the type name
function TPasParser.ParseRangeType(AParent: TPasElement;
Const TypeName: String; Full: Boolean): TPasRangeType;
const TypeName: String; Full: Boolean): TPasRangeType;
Var
PE : TPasExpr;
@ -2337,7 +2348,7 @@ begin
end;
function TPasParser.ParseSpecializeType(Parent: TPasElement;
Const TypeName: String): TPasClassType;
const TypeName: String): TPasClassType;
begin
Result := TPasClassType(Engine.CreateElement(TPasClassType, TypeName, Parent, Scanner.CurFilename, Scanner.CurRow));
@ -2378,8 +2389,8 @@ begin
Result:=ParseType(Parent,TypeName,True);
end;
function TPasParser.GetVariableValueAndLocation(Parent: TPasElement; Out
Value: TPasExpr; Out Location: String): Boolean;
function TPasParser.GetVariableValueAndLocation(Parent: TPasElement; out
Value: TPasExpr; out Location: String): Boolean;
begin
Value:=Nil;
@ -2409,7 +2420,7 @@ begin
UngetToken;
end;
function TPasParser.GetVariableModifiers(Out VarMods: TVariableModifiers; Out
function TPasParser.GetVariableModifiers(out VarMods: TVariableModifiers; out
Libname, ExportName: string): string;
Var
@ -2534,14 +2545,22 @@ begin
end;
end;
Function TPasParser.SaveComments: String;
procedure TPasParser.SetOptions(AValue: TPOptions);
begin
if FOptions=AValue then Exit;
FOptions:=AValue;
If Assigned(FScanner) then
FScanner.Options:=AValue;
end;
function TPasParser.SaveComments: String;
begin
if Engine.NeedComments then
FSavedComments:=CurComments.Text; // Expensive, so don't do unless needed.
Result:=FSavedComments;
end;
Function TPasParser.SaveComments(Const AValue: String): String;
function TPasParser.SaveComments(const AValue: String): String;
begin
FSavedComments:=AValue;
Result:=FSavedComments;
@ -2552,7 +2571,7 @@ begin
Result:=E in FLogEvents;
end;
Procedure TPasParser.DoLog(Const Msg: String; SkipSourceInfo: Boolean);
procedure TPasParser.DoLog(const Msg: String; SkipSourceInfo: Boolean);
begin
If Assigned(FOnLog) then
if SkipSourceInfo or not assigned(scanner) then
@ -2561,7 +2580,7 @@ begin
FOnLog(Self,Format('%s(%d) : %s',[Scanner.CurFilename,SCanner.CurRow,Msg]));
end;
Procedure TPasParser.DoLog(Const Fmt: String; Args: Array of const;
procedure TPasParser.DoLog(const Fmt: String; Args: array of const;
SkipSourceInfo: Boolean);
begin
DoLog(Format(Fmt,Args),SkipSourceInfo);
@ -3000,7 +3019,8 @@ begin
end;
Function TPasParser.ParseProperty(Parent : TPasElement; Const AName : String; AVisibility : TPasMemberVisibility) : TPasProperty;
function TPasParser.ParseProperty(Parent: TPasElement; const AName: String;
AVisibility: TPasMemberVisibility): TPasProperty;
procedure MaybeReadFullyQualifiedIdentifier(Var r : String);
@ -3735,7 +3755,8 @@ begin
Until Done;
end;
procedure TPasParser.DumpCurToken(Const Msg : String; IndentAction : TIndentAction = iaNone);
procedure TPasParser.DumpCurToken(const Msg: String; IndentAction: TIndentAction
);
begin
if IndentAction=iaUndent then
FDumpIndent:=copy(FDumpIndent,1,Length(FDumpIndent)-2);
@ -3755,19 +3776,30 @@ Var
Proc: TPasProcedure;
ProcType: TProcType;
Prop : TPasProperty;
isClass : Boolean;
begin
v:=visDefault;
isClass:=False;
while CurToken<>AEndToken do
begin
SaveComments;
Case CurToken of
tkProperty:
tkClass:
begin
if Not AllowMethods then
ParseExc(SErrRecordMethodsNotAllowed);
if isClass then
ParseExc(SParserTypeSyntaxError);
isClass:=True;
end;
tkProperty:
begin
if Not AllowMethods then
ParseExc(SErrRecordPropertiesNotAllowed);
ExpectToken(tkIdentifier);
Prop:=ParseProperty(ARec,CurtokenString,v);
Prop.isClass:=isClass;
Arec.Members.Add(Prop);
end;
tkProcedure,
@ -3775,7 +3807,7 @@ begin
begin
if Not AllowMethods then
ParseExc(SErrRecordMethodsNotAllowed);
ProcType:=GetProcTypeFromtoken(CurToken,False);
ProcType:=GetProcTypeFromtoken(CurToken,isClass);
Proc:=ParseProcedureOrFunctionDecl(ARec,ProcType,v);
if Proc.Parent is TPasOverloadedProc then
TPasOverloadedProc(Proc.Parent).Overloads.Add(Proc)
@ -3787,6 +3819,8 @@ begin
// If (po_delphi in Scanner.Options) then
if CheckVisibility(CurtokenString,v) then
begin
If not (po_delphi in Scanner.Options) then
ParseExc(SErrRecordVisibilityNotAllowed);
if not (v in [visPrivate,visPublic,visStrictPrivate]) then
ParseExc(SParserInvalidRecordVisibility);
NextToken;
@ -3816,11 +3850,14 @@ begin
end;
if CurToken<>AEndToken then
NextToken;
If CurToken<>tkClass then
isClass:=False;
end;
end;
// Starts after the "record" token
Function TPasParser.ParseRecordDecl(Parent: TPasElement; Const TypeName : string; const Packmode : TPackMode = pmNone) : TPasRecordType;
function TPasParser.ParseRecordDecl(Parent: TPasElement;
const TypeName: string; const Packmode: TPackMode): TPasRecordType;
begin
Result := TPasRecordType(CreateElement(TPasRecordType, TypeName, Parent));
@ -4090,7 +4127,7 @@ begin
end;
end;
Function TPasParser.ParseClassDecl(Parent: TPasElement;
function TPasParser.ParseClassDecl(Parent: TPasElement;
const AClassName: String; AObjKind: TPasObjKind; PackMode: TPackMode
): TPasType;

View File

@ -243,6 +243,8 @@ type
Procedure TestTwoDeprecatedFieldsCombinedPlatform;
Procedure TestFieldAndMethod;
Procedure TestFieldAnd2Methods;
Procedure TestFieldAndProperty;
Procedure TestFieldAndClassMethod;
Procedure TestNested;
Procedure TestNestedDeprecated;
Procedure TestNestedPlatform;
@ -1101,7 +1103,7 @@ end;
{ TTestRecordTypeParser }
Function TTestRecordTypeParser.GetField(AIndex: Integer; R: TPasRecordType
function TTestRecordTypeParser.GetField(AIndex: Integer; R: TPasRecordType
): TPasVariable;
begin
AssertNotNull(R);
@ -1111,7 +1113,7 @@ begin
Result:=TPasVariable(R.Members[AIndex]);
end;
Function TTestRecordTypeParser.GetField(AIndex: Integer; R: TPasVariant
function TTestRecordTypeParser.GetField(AIndex: Integer; R: TPasVariant
): TPasVariable;
begin
AssertNotNull(R);
@ -1132,7 +1134,7 @@ begin
Result:=TheType as TPasRecordType;
end;
Function TTestRecordTypeParser.GetVariant(AIndex: Integer; R: TPasRecordType
function TTestRecordTypeParser.GetVariant(AIndex: Integer; R: TPasRecordType
): TPasVariant;
begin
AssertNotNull(R);
@ -1147,7 +1149,7 @@ begin
Result:=GetVariant(AIndex,GetR);
end;
Procedure TTestRecordTypeParser.TestFields(Const Fields: Array of string;
procedure TTestRecordTypeParser.TestFields(const Fields: array of string;
AHint: String; HaveVariant: Boolean);
Var
@ -1193,7 +1195,7 @@ begin
end;
Procedure TTestRecordTypeParser.DoTestEmpty(Const AHint: String);
procedure TTestRecordTypeParser.DoTestEmpty(const AHint: String);
begin
TestFields([],AHint);
AssertNotNull('Have members array',TheRecord.Members);
@ -1207,7 +1209,7 @@ end;
procedure TTestRecordTypeParser.AssertVariant1(Hints: TPasMemberHints;
VariantLabels: Array of string);
VariantLabels: array of string);
Var
I : Integer;
@ -1248,7 +1250,7 @@ begin
end;
procedure TTestRecordTypeParser.AssertVariant2(Hints: TPasMemberHints;
VariantLabels: Array of string);
VariantLabels: array of string);
Var
I : Integer;
@ -1283,7 +1285,7 @@ begin
AssertTrue('Field 1 hints match',TPasVariable(Variant2.Members.Members[0]).Hints=Hints)
end;
procedure TTestRecordTypeParser.DoTestVariantNoStorage(Const AHint: string);
procedure TTestRecordTypeParser.DoTestVariantNoStorage(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : (y : integer;)'],AHint,True);
AssertField1([]);
@ -1292,7 +1294,7 @@ begin
end;
procedure TTestRecordTypeParser.DoTestDeprecatedVariantNoStorage(
Const AHint: string);
const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : (y : integer deprecated;)'],AHint,True);
AssertField1([]);
@ -1301,7 +1303,7 @@ begin
end;
procedure TTestRecordTypeParser.DoTestDeprecatedVariantStorage(
Const AHint: string);
const AHint: string);
begin
TestFields(['x : integer;','case s : integer of','0 : (y : integer deprecated;)'],AHint,True);
AssertField1([]);
@ -1309,7 +1311,7 @@ begin
AssertVariant1([hDeprecated]);
end;
procedure TTestRecordTypeParser.DoTestVariantStorage(Const AHint: string);
procedure TTestRecordTypeParser.DoTestVariantStorage(const AHint: string);
begin
TestFields(['x : integer;','case s : integer of','0 : (y : integer;)'],AHint,True);
AssertField1([]);
@ -1317,7 +1319,7 @@ begin
AssertVariant1([]);
end;
procedure TTestRecordTypeParser.DoTestTwoVariantsNoStorage(Const AHint: string);
procedure TTestRecordTypeParser.DoTestTwoVariantsNoStorage(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : (y : integer;);','1 : (z : integer;)'],AHint,True);
AssertField1([]);
@ -1326,7 +1328,7 @@ begin
AssertVariant2([]);
end;
procedure TTestRecordTypeParser.DoTestTwoVariantsStorage(Const AHint: string);
procedure TTestRecordTypeParser.DoTestTwoVariantsStorage(const AHint: string);
begin
TestFields(['x : integer;','case s : integer of','0 : (y : integer;);','1 : (z : integer;)'],AHint,True);
AssertField1([]);
@ -1336,7 +1338,7 @@ begin
end;
procedure TTestRecordTypeParser.DoTestTwoVariantsFirstDeprecatedStorage(
Const AHint: string);
const AHint: string);
begin
TestFields(['x : integer;','case s : integer of','0 : (y : integer deprecated;);','1 : (z : integer;)'],AHint,True);
AssertField1([]);
@ -1346,7 +1348,7 @@ begin
end;
procedure TTestRecordTypeParser.DoTestTwoVariantsSecondDeprecatedStorage(
Const AHint: string);
const AHint: string);
begin
TestFields(['x : integer;','case s : integer of','0 : (y : integer ;);','1 : (z : integer deprecated;)'],AHint,True);
AssertField1([]);
@ -1355,7 +1357,7 @@ begin
AssertVariant2([hdeprecated]);
end;
Procedure TTestRecordTypeParser.DoTestVariantTwoLabels(Const AHint: string);
procedure TTestRecordTypeParser.DoTestVariantTwoLabels(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0,1 : (y : integer)'],AHint,True);
AssertField1([]);
@ -1363,7 +1365,7 @@ begin
AssertVariant1([],['0','1']);
end;
Procedure TTestRecordTypeParser.DoTestTwoVariantsTwoLabels(Const AHint: string);
procedure TTestRecordTypeParser.DoTestTwoVariantsTwoLabels(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0,1 : (y : integer);','2,3 : (z : integer);'],AHint,True);
AssertField1([]);
@ -1372,7 +1374,7 @@ begin
AssertVariant2([],['2','3']);
end;
procedure TTestRecordTypeParser.DoTestVariantNestedRecord(Const AHint: string);
procedure TTestRecordTypeParser.DoTestVariantNestedRecord(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : ( y : record',' z : integer;','end)'],AHint,True);
AssertField1([]);
@ -1380,7 +1382,7 @@ begin
AssertRecordVariant(0,[],['0']);
end;
procedure TTestRecordTypeParser.DoTestVariantNestedVariant(Const AHint: string);
procedure TTestRecordTypeParser.DoTestVariantNestedVariant(const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : ( y : record',' z : integer;',' case byte of ',' 1 : (i : integer);',' 2 : ( j : byte)', 'end)'],AHint,True);
AssertField1([]);
@ -1391,7 +1393,7 @@ begin
end;
procedure TTestRecordTypeParser.DoTestVariantNestedVariantFirstDeprecated(
Const AHint: string);
const AHint: string);
begin
TestFields(['x : integer;','case integer of','0 : ( y : record',' z : integer;',' case byte of ',' 1 : (i : integer deprecated);',' 2 : ( j : byte)', 'end)'],AHint,True);
AssertField1([]);
@ -1423,23 +1425,23 @@ begin
AssertRecordVariantVariant(1,'j','Byte',[hDeprecated],['2'])
end;
Procedure TTestRecordTypeParser.TestEmpty;
procedure TTestRecordTypeParser.TestEmpty;
begin
DoTestEmpty('')
end;
Procedure TTestRecordTypeParser.TestEmptyComment;
procedure TTestRecordTypeParser.TestEmptyComment;
begin
AddComment:=True;
TestEmpty;
end;
Procedure TTestRecordTypeParser.TestEmptyDeprecated;
procedure TTestRecordTypeParser.TestEmptyDeprecated;
begin
DoTestEmpty('Deprecated')
end;
Procedure TTestRecordTypeParser.TestEmptyPlatform;
procedure TTestRecordTypeParser.TestEmptyPlatform;
begin
DoTestEmpty('Platform')
end;
@ -1524,7 +1526,7 @@ begin
end;
procedure TTestRecordTypeParser.AssertRecordVariant(AIndex: Integer;
Hints: TPasMemberHints; VariantLabels: Array of string);
Hints: TPasMemberHints; VariantLabels: array of string);
Var
F : TPasVariant;
@ -1556,9 +1558,9 @@ begin
end;
Procedure TTestRecordTypeParser.AssertRecordVariantVariant(AIndex: Integer;
Const AFieldName, ATypeName: string; Hints: TPasMemberHints;
VariantLabels: Array of string);
procedure TTestRecordTypeParser.AssertRecordVariantVariant(AIndex: Integer;
const AFieldName, ATypeName: string; Hints: TPasMemberHints;
VariantLabels: array of string);
Var
F : TPasVariant;
@ -1598,13 +1600,13 @@ begin
AssertTrue(MN+'hints match',V.Hints=Hints);
end;
Procedure TTestRecordTypeParser.TestOneField;
procedure TTestRecordTypeParser.TestOneField;
begin
TestFields(['x : integer'],'',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneFieldComment;
procedure TTestRecordTypeParser.TestOneFieldComment;
begin
AddComment:=True;
TestFields(['{a} x : integer'],'',False);
@ -1612,74 +1614,74 @@ begin
AssertEquals('Member 1 comment','a'+sLineBreak,TPAsElement(TheRecord.Members[0]).DocComment);
end;
Procedure TTestRecordTypeParser.TestOneFieldDeprecated;
procedure TTestRecordTypeParser.TestOneFieldDeprecated;
begin
TestFields(['x : integer'],'deprecated',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneFieldPlatform;
procedure TTestRecordTypeParser.TestOneFieldPlatform;
begin
TestFields(['x : integer'],'platform',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneFieldSemicolon;
procedure TTestRecordTypeParser.TestOneFieldSemicolon;
begin
TestFields(['x : integer;'],'',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneFieldSemicolonDeprecated;
procedure TTestRecordTypeParser.TestOneFieldSemicolonDeprecated;
begin
TestFields(['x : integer;'],'deprecated',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneFieldSemicolonPlatform;
procedure TTestRecordTypeParser.TestOneFieldSemicolonPlatform;
begin
TestFields(['x : integer;'],'platform',False);
AssertOneIntegerField([]);
end;
Procedure TTestRecordTypeParser.TestOneDeprecatedField;
procedure TTestRecordTypeParser.TestOneDeprecatedField;
begin
TestFields(['x : integer deprecated;'],'',False);
AssertOneIntegerField([hDeprecated]);
end;
Procedure TTestRecordTypeParser.TestOneDeprecatedFieldDeprecated;
procedure TTestRecordTypeParser.TestOneDeprecatedFieldDeprecated;
begin
TestFields(['x : integer deprecated;'],'deprecated',False);
AssertOneIntegerField([hDeprecated]);
end;
Procedure TTestRecordTypeParser.TestOneDeprecatedFieldPlatform;
procedure TTestRecordTypeParser.TestOneDeprecatedFieldPlatform;
begin
TestFields(['x : integer deprecated;'],'platform',False);
AssertOneIntegerField([hDeprecated]);
end;
Procedure TTestRecordTypeParser.TestOnePlatformField;
procedure TTestRecordTypeParser.TestOnePlatformField;
begin
TestFields(['x : integer platform;'],'',False);
AssertOneIntegerField([hplatform]);
end;
Procedure TTestRecordTypeParser.TestOnePlatformFieldDeprecated;
procedure TTestRecordTypeParser.TestOnePlatformFieldDeprecated;
begin
TestFields(['x : integer platform;'],'Deprecated',False);
AssertOneIntegerField([hplatform]);
end;
Procedure TTestRecordTypeParser.TestOnePlatformFieldPlatform;
procedure TTestRecordTypeParser.TestOnePlatformFieldPlatform;
begin
TestFields(['x : integer platform;'],'Platform',False);
AssertOneIntegerField([hplatform]);
end;
Procedure TTestRecordTypeParser.TestTwoFields;
procedure TTestRecordTypeParser.TestTwoFields;
begin
TestFields(['x : integer;','y : integer'],'',False);
AssertTwoIntegerFields([],[]);
@ -1687,17 +1689,18 @@ end;
procedure TTestRecordTypeParser.TestTwoFieldPrivateNoDelphi;
Var
B : Boolean;
EC : TClass;
begin
try
TestFields(['private','x : integer'],'',False);
Fail('Need poDelphi for visibility specifier')
Fail('Need po_Delphi for visibility specifier');
except
on EA : EAssertionFailedError do
Raise;
on E : Exception do
B:=E is EParserError;
EC:=E.ClassType;
end;
If not B then
Fail('Wrong exception class.');
AssertEquals('Exception class',EParserError,EC);
end;
procedure TTestRecordTypeParser.TestTwoFieldProtected;
@ -1715,7 +1718,7 @@ begin
Fail('Wrong exception class.');
end;
Procedure TTestRecordTypeParser.TestTwoFieldPrivate;
procedure TTestRecordTypeParser.TestTwoFieldPrivate;
begin
Scanner.Options:=[po_Delphi];
TestFields(['private','x,y : integer'],'',False);
@ -1729,119 +1732,121 @@ begin
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldDeprecated;
begin
TestFields(['x : integer;','y : integer'],'deprecated',False);
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldPlatform;
procedure TTestRecordTypeParser.TestTwoFieldPlatform;
begin
TestFields(['x : integer;','y : integer'],'platform',False);
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecated;
begin
TestFields(['x : integer deprecated;','y : integer'],'',False);
AssertTwoIntegerFields([hdeprecated],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecatedDeprecated;
begin
TestFields(['x : integer deprecated;','y : integer'],'deprecated',False);
AssertTwoIntegerFields([hdeprecated],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecatedPlatform;
procedure TTestRecordTypeParser.TestTwoFieldsFirstDeprecatedPlatform;
begin
TestFields(['x : integer deprecated;','y : integer'],'platform',False);
AssertTwoIntegerFields([hdeprecated],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecated;
begin
TestFields(['x : integer;','y : integer deprecated;'],'',False);
AssertTwoIntegerFields([],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecatedDeprecated;
begin
TestFields(['x : integer;','y : integer deprecated;'],'deprecated',False);
AssertTwoIntegerFields([],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecatedPlatform;
procedure TTestRecordTypeParser.TestTwoFieldsSecondDeprecatedPlatform;
begin
TestFields(['x : integer;','y : integer deprecated;'],'platform',False);
AssertTwoIntegerFields([],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecated;
begin
TestFields(['x : integer deprecated;','y : integer deprecated;'],'',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecatedDeprecated;
begin
TestFields(['x : integer deprecated;','y : integer deprecated;'],'deprecated',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecatedPlatform;
procedure TTestRecordTypeParser.TestTwoFieldsBothDeprecatedPlatform;
begin
TestFields(['x : integer deprecated;','y : integer deprecated;'],'platform',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsCombined;
procedure TTestRecordTypeParser.TestTwoFieldsCombined;
begin
TestFields(['x,y : integer;'],'',False);
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsCombinedDeprecated;
procedure TTestRecordTypeParser.TestTwoFieldsCombinedDeprecated;
begin
TestFields(['x,y : integer;'],'deprecated',False);
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoFieldsCombinedPlatform;
procedure TTestRecordTypeParser.TestTwoFieldsCombinedPlatform;
begin
TestFields(['x,y : integer;'],'platform',False);
AssertTwoIntegerFields([],[]);
end;
Procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombined;
procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombined;
begin
TestFields(['x,y : integer deprecated;'],'',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombinedDeprecated;
procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombinedDeprecated;
begin
TestFields(['x,y : integer deprecated;'],'deprecated',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombinedPlatform;
procedure TTestRecordTypeParser.TestTwoDeprecatedFieldsCombinedPlatform;
begin
TestFields(['x,y : integer deprecated;'],'platform',False);
AssertTwoIntegerFields([hdeprecated],[hdeprecated]);
end;
Procedure TTestRecordTypeParser.TestFieldAndMethod;
procedure TTestRecordTypeParser.TestFieldAndMethod;
begin
Parser.Options:=[po_delphi];
TestFields(['x : integer;','procedure dosomething2;'],'',False);
AssertIntegerFieldAndMethod([],[]);
end;
Procedure TTestRecordTypeParser.TestFieldAnd2Methods;
procedure TTestRecordTypeParser.TestFieldAnd2Methods;
Var
P : TPasFunction;
begin
Parser.Options:=[po_delphi];
TestFields(['x : integer;','procedure dosomething2;','function dosomething3 : Integer;'],'',False);
AssertEquals('Member count',3,TheRecord.Members.Count);
AssertField1([]);
@ -1854,7 +1859,44 @@ begin
AssertEquals('Method 2 result type','Integer', P.FuncType.ResultEl.ResultType.Name);
end;
Procedure TTestRecordTypeParser.TestNested;
procedure TTestRecordTypeParser.TestFieldAndProperty;
Var
P : TPasProperty;
begin
Parser.Options:=[po_delphi];
TestFields(['private','x : integer;','public','property MyX : Integer read X write X'],'',False);
AssertEquals('Member count',2,TheRecord.Members.Count);
AssertField1([]);
AssertEquals('Member 2 type',TPasProperty,TObject(TheRecord.Members[1]).ClassType);
P:=TPasProperty(TheRecord.Members[1]);
AssertEquals('Property name','MyX',P.Name);
AssertNotNull('Method 2 type',P.ResolvedType);
AssertEquals('Method 2 type','Integer',P.ResolvedType.Name);
AssertEquals('Method 2 read','X', P.ReadAccessorName);
AssertEquals('Method 2 Write','X', P.WriteAccessorName);
end;
procedure TTestRecordTypeParser.TestFieldAndClassMethod;
Var
P : TPasFunction;
begin
TestFields(['x : integer;','class procedure dosomething2;','function dosomething3 : Integer;'],'',False);
AssertEquals('Member count',3,TheRecord.Members.Count);
AssertField1([]);
AssertMethod2([]);
AssertEquals('Class procedure',TPasProcedure,TObject(TheRecord.Members[1]).ClassType);
AssertEquals('Member 3 type',TPasFunction,TObject(TheRecord.Members[2]).ClassType);
P:=TPasFunction(TheRecord.Members[2]);
AssertEquals('Method 2 name','dosomething3',P.Name);
AssertTrue('Method 2 hints match',[]=P.Hints);
// Standard type
AssertEquals('Method 2 result type','Integer', P.FuncType.ResultEl.ResultType.Name);
end;
procedure TTestRecordTypeParser.TestNested;
begin
TestFields(['x : integer;','y : record',' z : integer;','end'],'',False);
AssertField1([]);
@ -1882,14 +1924,14 @@ begin
AssertRecordField(1,[])
end;
Procedure TTestRecordTypeParser.TestNestedDeprecated;
procedure TTestRecordTypeParser.TestNestedDeprecated;
begin
TestFields(['x : integer;','y : record',' z : integer;','end'],'deprecated',False);
AssertField1([]);
AssertRecordField(1,[])
end;
Procedure TTestRecordTypeParser.TestNestedPlatform;
procedure TTestRecordTypeParser.TestNestedPlatform;
begin
TestFields(['x : integer;','y : record',' z : integer;','end'],'platform',False);
AssertField1([]);
@ -1917,21 +1959,21 @@ begin
AssertRecordField(0,[])
end;
Procedure TTestRecordTypeParser.TestDeprecatedNested;
procedure TTestRecordTypeParser.TestDeprecatedNested;
begin
TestFields(['x : integer;','y : record',' z : integer;','end deprecated;'],'',False);
AssertField1([]);
AssertRecordField(1,[hdeprecated])
end;
Procedure TTestRecordTypeParser.TestDeprecatedNestedDeprecated;
procedure TTestRecordTypeParser.TestDeprecatedNestedDeprecated;
begin
TestFields(['x : integer;','y : record',' z : integer;','end deprecated;'],'deprecated',False);
AssertField1([]);
AssertRecordField(1,[hdeprecated])
end;
Procedure TTestRecordTypeParser.TestDeprecatedNestedPlatform;
procedure TTestRecordTypeParser.TestDeprecatedNestedPlatform;
begin
TestFields(['x : integer;','y : record',' z : integer;','end deprecated;'],'platform',False);
AssertField1([]);
@ -1959,7 +2001,7 @@ begin
AssertRecordField(0,[hdeprecated])
end;
Procedure TTestRecordTypeParser.TestVariantNoStorage;
procedure TTestRecordTypeParser.TestVariantNoStorage;
begin
DoTestVariantNoStorage('');
end;
@ -1976,7 +2018,7 @@ begin
DoTestVariantNoStorage('platform');
end;
Procedure TTestRecordTypeParser.TestVariantStorage;
procedure TTestRecordTypeParser.TestVariantStorage;
begin
DoTestVariantStorage('');
end;
@ -1992,7 +2034,7 @@ begin
DoTestVariantStorage('platform');
end;
Procedure TTestRecordTypeParser.TestDeprecatedVariantNoStorage;
procedure TTestRecordTypeParser.TestDeprecatedVariantNoStorage;
begin
DoTestDeprecatedVariantNoStorage('');
end;
@ -2007,7 +2049,7 @@ begin
DoTestDeprecatedVariantNoStorage('Platform');
end;
Procedure TTestRecordTypeParser.TestDeprecatedVariantStorage;
procedure TTestRecordTypeParser.TestDeprecatedVariantStorage;
begin
DoTestDeprecatedVariantStorage('');
end;
@ -2022,7 +2064,7 @@ begin
DoTestDeprecatedVariantStorage('Platform');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsNoStorage;
procedure TTestRecordTypeParser.TestTwoVariantsNoStorage;
begin
DoTestTwoVariantsNoStorage('');
end;
@ -2037,7 +2079,7 @@ begin
DoTestTwoVariantsNoStorage('platform');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsStorage;
procedure TTestRecordTypeParser.TestTwoVariantsStorage;
begin
DoTestTwoVariantsStorage('');
end;
@ -2052,7 +2094,7 @@ begin
DoTestTwoVariantsStorage('platform');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsFirstDeprecatedStorage;
procedure TTestRecordTypeParser.TestTwoVariantsFirstDeprecatedStorage;
begin
DoTestTwoVariantsFirstDeprecatedStorage('');
end;
@ -2067,7 +2109,7 @@ begin
DoTestTwoVariantsFirstDeprecatedStorage('platform');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsSecondDeprecatedStorage;
procedure TTestRecordTypeParser.TestTwoVariantsSecondDeprecatedStorage;
begin
DoTestTwoVariantsSecondDeprecatedStorage('');
end;
@ -2082,107 +2124,107 @@ begin
DoTestTwoVariantsSecondDeprecatedStorage('platform');
end;
Procedure TTestRecordTypeParser.TestVariantTwoLabels;
procedure TTestRecordTypeParser.TestVariantTwoLabels;
begin
DoTestVariantTwoLabels('');
end;
Procedure TTestRecordTypeParser.TestVariantTwoLabelsDeprecated;
procedure TTestRecordTypeParser.TestVariantTwoLabelsDeprecated;
begin
DoTestVariantTwoLabels('Deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantTwoLabelsPlatform;
procedure TTestRecordTypeParser.TestVariantTwoLabelsPlatform;
begin
DoTestVariantTwoLabels('Platform');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsTwoLabels;
procedure TTestRecordTypeParser.TestTwoVariantsTwoLabels;
begin
DoTestTwoVariantsTwoLabels('');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsTwoLabelsDeprecated;
procedure TTestRecordTypeParser.TestTwoVariantsTwoLabelsDeprecated;
begin
DoTestTwoVariantsTwoLabels('Deprecated');
end;
Procedure TTestRecordTypeParser.TestTwoVariantsTwoLabelsPlatform;
procedure TTestRecordTypeParser.TestTwoVariantsTwoLabelsPlatform;
begin
DoTestTwoVariantsTwoLabels('Platform');
end;
Procedure TTestRecordTypeParser.TestVariantNestedRecord;
procedure TTestRecordTypeParser.TestVariantNestedRecord;
begin
DoTestVariantNestedRecord('');
end;
Procedure TTestRecordTypeParser.TestVariantNestedRecordDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedRecordDeprecated;
begin
DoTestVariantNestedRecord('Deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantNestedRecordPlatform;
procedure TTestRecordTypeParser.TestVariantNestedRecordPlatform;
begin
DoTestVariantNestedRecord('Platform');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariant;
procedure TTestRecordTypeParser.TestVariantNestedVariant;
begin
DoTestVariantNestedVariant('');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantDeprecated;
begin
DoTestVariantNestedVariant('deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantPlatForm;
procedure TTestRecordTypeParser.TestVariantNestedVariantPlatForm;
begin
DoTestVariantNestedVariant('Platform');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecated;
begin
DoTestVariantNestedVariantFirstDeprecated('');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecatedDeprecated;
begin
DoTestVariantNestedVariantFirstDeprecated('deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecatedPlatform;
procedure TTestRecordTypeParser.TestVariantNestedVariantFirstDeprecatedPlatform;
begin
DoTestVariantNestedVariantFirstDeprecated('platform');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecated;
begin
DoTestVariantNestedVariantSecondDeprecated('');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecatedDeprecated;
begin
DoTestVariantNestedVariantSecondDeprecated('deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecatedPlatform;
procedure TTestRecordTypeParser.TestVariantNestedVariantSecondDeprecatedPlatform;
begin
DoTestVariantNestedVariantSecondDeprecated('platform');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecated;
begin
DoTestVariantNestedVariantBothDeprecated('');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecatedDeprecated;
procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecatedDeprecated;
begin
DoTestVariantNestedVariantBothDeprecated('deprecated');
end;
Procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecatedPlatform;
procedure TTestRecordTypeParser.TestVariantNestedVariantBothDeprecatedPlatform;
begin
DoTestVariantNestedVariantBothDeprecated('platform');
end;