* Support Hints prior to variable initialization, properties in records

git-svn-id: trunk@29556 -
This commit is contained in:
michael 2015-01-26 13:46:21 +00:00
parent 7bb0b187a4
commit 79e7ba678e
3 changed files with 48 additions and 1 deletions

View File

@ -2417,9 +2417,10 @@ begin
else else
VarType := ParseComplexType(Parent); VarType := ParseComplexType(Parent);
Value:=Nil; Value:=Nil;
H:=CheckHint(Nil,False);
If Full then If Full then
GetVariableValueAndLocation(Parent,Value,Loc); GetVariableValueAndLocation(Parent,Value,Loc);
H:=CheckHint(Nil,Full); H:=H+CheckHint(Nil,Full);
if full then if full then
Mods:=GetVariableModifiers(varmods,alibname,aexpname) Mods:=GetVariableModifiers(varmods,alibname,aexpname)
else else
@ -3619,12 +3620,21 @@ Var
v : TPasmemberVisibility; v : TPasmemberVisibility;
Proc: TPasProcedure; Proc: TPasProcedure;
ProcType: TProcType; ProcType: TProcType;
Prop : TPasProperty;
begin begin
v:=visPublic; v:=visPublic;
while CurToken<>AEndToken do while CurToken<>AEndToken do
begin begin
Case CurToken of Case CurToken of
tkProperty:
begin
if Not AllowMethods then
ParseExc(SErrRecordMethodsNotAllowed);
ExpectToken(tkIdentifier);
Prop:=ParseProperty(ARec,CurtokenString,v);
Arec.Members.Add(Prop);
end;
tkProcedure, tkProcedure,
tkFunction : tkFunction :
begin begin

View File

@ -161,6 +161,7 @@ type
procedure AssertField1(Hints: TPasMemberHints); procedure AssertField1(Hints: TPasMemberHints);
procedure AssertField2(Hints: TPasMemberHints); procedure AssertField2(Hints: TPasMemberHints);
procedure AssertMethod2(Hints: TPasMemberHints); procedure AssertMethod2(Hints: TPasMemberHints);
procedure AssertProperty2(Hints: TPasMemberHints);
procedure AssertVariant1(Hints: TPasMemberHints); procedure AssertVariant1(Hints: TPasMemberHints);
procedure AssertVariant1(Hints: TPasMemberHints; VariantLabels : Array of string); procedure AssertVariant1(Hints: TPasMemberHints; VariantLabels : Array of string);
procedure AssertVariant2(Hints: TPasMemberHints); procedure AssertVariant2(Hints: TPasMemberHints);
@ -232,6 +233,7 @@ type
Procedure TestTwoDeprecatedFieldsCombinedPlatform; Procedure TestTwoDeprecatedFieldsCombinedPlatform;
Procedure TestFieldAndMethod; Procedure TestFieldAndMethod;
Procedure TestFieldAnd2Methods; Procedure TestFieldAnd2Methods;
Procedure TestFieldAndProperty;
Procedure TestVisibilityAndMethods; Procedure TestVisibilityAndMethods;
Procedure TestNested; Procedure TestNested;
Procedure TestNestedDeprecated; Procedure TestNestedDeprecated;
@ -1451,6 +1453,17 @@ begin
AssertTrue('Method hints match',P.Hints=Hints) AssertTrue('Method hints match',P.Hints=Hints)
end; end;
procedure TTestRecordTypeParser.AssertProperty2(Hints: TPasMemberHints);
Var
P : TPasProperty;
begin
AssertEquals('Member 2 type',TPasProperty,TObject(TheRecord.Members[1]).ClassType);
P:=TPasProperty(TheRecord.Members[1]);
AssertEquals('Property name','something',P.Name);
AssertTrue('Property hints match',P.Hints=Hints);
end;
procedure TTestRecordTypeParser.AssertOneIntegerField(Hints : TPasMemberHints); procedure TTestRecordTypeParser.AssertOneIntegerField(Hints : TPasMemberHints);
begin begin
@ -1819,6 +1832,15 @@ begin
AssertEquals('Method 2 result type','Integer', P.FuncType.ResultEl.ResultType.Name); AssertEquals('Method 2 result type','Integer', P.FuncType.ResultEl.ResultType.Name);
end; end;
procedure TTestRecordTypeParser.TestFieldAndProperty;
begin
TestFields(['x : integer;','property something read x write f;'],'',False);
AssertEquals('Member count',2,TheRecord.Members.Count);
AssertField1([]);
AssertProperty2([]);
end;
procedure TTestRecordTypeParser.TestVisibilityAndMethods; procedure TTestRecordTypeParser.TestVisibilityAndMethods;
begin begin
ParseType('record '+slineBreak+ ParseType('record '+slineBreak+

View File

@ -47,6 +47,7 @@ Type
Procedure TestVarPublic; Procedure TestVarPublic;
Procedure TestVarPublicName; Procedure TestVarPublicName;
Procedure TestVarDeprecatedExternalName; Procedure TestVarDeprecatedExternalName;
Procedure TestVarHintPriorToInit;
end; end;
implementation implementation
@ -293,6 +294,20 @@ begin
AssertEquals('Library name','''me''',TheVar.ExportName); AssertEquals('Library name','''me''',TheVar.ExportName);
end; end;
procedure TTestVarParser.TestVarHintPriorToInit;
Var
E : TBoolConstExpr;
begin
ParseVar('boolean platform = false','');
CheckHint(TPasMemberHint(Getenumvalue(typeinfo(TPasMemberHint),'hplatform')));
AssertNotNull('Correctly initialized',Thevar.Expr);
AssertEquals('Correctly initialized',TBoolConstExpr,Thevar.Expr.ClassType);
E:=Thevar.Expr as TBoolConstExpr;
AssertEquals('Correct initialization value',False, E.Value);
end;
initialization initialization
RegisterTests([TTestVarParser]); RegisterTests([TTestVarParser]);