fcl-passrc: fixed stConstDef for class local const

git-svn-id: trunk@38097 -
This commit is contained in:
Mattias Gaertner 2018-02-01 17:48:44 +00:00
parent 1f0e311fdd
commit b8710d8fec
3 changed files with 56 additions and 47 deletions

View File

@ -3103,6 +3103,7 @@ begin
ConstEl := ParseConstDecl(Declarations);
Declarations.Declarations.Add(ConstEl);
Declarations.Consts.Add(ConstEl);
Engine.FinishScope(stConstDef,ConstEl);
end;
declResourcestring:
begin
@ -3190,6 +3191,7 @@ begin
PropEl:=ParseProperty(Declarations,CurtokenString,visDefault,false);
Declarations.Declarations.Add(PropEl);
Declarations.Properties.Add(PropEl);
Engine.FinishScope(stDeclaration,PropEl);
end;
else
ParseExcSyntaxError;
@ -3494,7 +3496,6 @@ begin
if not ok then
ReleaseAndNil(TPasElement(Result));
end;
Engine.FinishScope(stConstDef,Result);
end;
// Starts after the variable name
@ -4825,7 +4826,6 @@ begin
if not ok then
Result.Release;
end;
Engine.FinishScope(stDeclaration,Result);
end;
// Starts after the "begin" token
@ -5718,6 +5718,7 @@ begin
Cons:=ParseConstDecl(ARec);
Cons.Visibility:=v;
ARec.members.Add(Cons);
Engine.FinishScope(stConstDef,Cons);
end;
tkVar:
begin
@ -5750,6 +5751,7 @@ begin
ExpectToken(tkIdentifier);
Prop:=ParseProperty(ARec,CurtokenString,v,isClass);
Arec.Members.Add(Prop);
Engine.FinishScope(stDeclaration,Prop);
end;
tkOperator,
tkProcedure,
@ -5977,7 +5979,7 @@ begin
C:=ParseConstDecl(AType);
C.Visibility:=AVisibility;
AType.Members.Add(C);
Engine.FinishScope(stDeclaration,C);
Engine.FinishScope(stConstDef,C);
// Writeln(CurtokenString,' ',TokenInfos[Curtoken]);
NextToken;
Done:=(Curtoken<>tkIdentifier) or CheckVisibility(CurtokenString,AVisibility);
@ -5996,6 +5998,7 @@ Var
CurSection : TSectionType;
haveClass : Boolean;
LastToken: TToken;
PropEl: TPasProperty;
begin
CurSection:=stNone;
@ -6064,7 +6067,9 @@ begin
if not haveClass then
SaveComments;
ExpectIdentifier;
AType.Members.Add(ParseProperty(AType,CurtokenString,CurVisibility,HaveClass));
PropEl:=ParseProperty(AType,CurtokenString,CurVisibility,HaveClass);
AType.Members.Add(PropEl);
Engine.FinishScope(stDeclaration,PropEl);
HaveClass:=False;
end;
tkSquaredBraceOpen:

View File

@ -8318,48 +8318,52 @@ end;
procedure TTestResolver.TestClass_Const;
begin
StartProgram(false);
Add('type');
Add(' integer = longint;');
Add(' TClass = class of TObject;');
Add(' TObject = class');
Add(' public');
Add(' const cI: integer = 3;');
Add(' procedure DoIt;');
Add(' class procedure DoMore;');
Add(' end;');
Add('implementation');
Add('procedure tobject.doit;');
Add('begin');
Add(' if cI=4 then;');
Add(' if 5=cI then;');
Add(' if Self.cI=6 then;');
Add(' if 7=Self.cI then;');
Add(' with Self do begin');
Add(' if cI=11 then;');
Add(' if 12=cI then;');
Add(' end;');
Add('end;');
Add('class procedure tobject.domore;');
Add('begin');
Add(' if cI=8 then;');
Add(' if Self.cI=9 then;');
Add(' if 10=cI then;');
Add(' if 11=Self.cI then;');
Add(' with Self do begin');
Add(' if cI=13 then;');
Add(' if 14=cI then;');
Add(' end;');
Add('end;');
Add('var');
Add(' Obj: TObject;');
Add(' Cla: TClass;');
Add('begin');
Add(' if TObject.cI=21 then ;');
Add(' if Obj.cI=22 then ;');
Add(' if Cla.cI=23 then ;');
Add(' with obj do if ci=24 then;');
Add(' with TObject do if ci=25 then;');
Add(' with Cla do if ci=26 then;');
Add([
'type',
' integer = longint;',
' TClass = class of TObject;',
' TObject = class',
' strict private const',
' Prefix = ''binary'';',
' PrefixLength = Length(Prefix);',
' public',
' const cI: integer = 3;',
' procedure DoIt;',
' class procedure DoMore;',
' end;',
'implementation',
'procedure tobject.doit;',
'begin',
' if cI=4 then;',
' if 5=cI then;',
' if Self.cI=6 then;',
' if 7=Self.cI then;',
' with Self do begin',
' if cI=11 then;',
' if 12=cI then;',
' end;',
'end;',
'class procedure tobject.domore;',
'begin',
' if cI=8 then;',
' if Self.cI=9 then;',
' if 10=cI then;',
' if 11=Self.cI then;',
' with Self do begin',
' if cI=13 then;',
' if 14=cI then;',
' end;',
'end;',
'var',
' Obj: TObject;',
' Cla: TClass;',
'begin',
' if TObject.cI=21 then ;',
' if Obj.cI=22 then ;',
' if Cla.cI=23 then ;',
' with obj do if ci=24 then;',
' with TObject do if ci=25 then;',
' with Cla do if ci=26 then;']);
ParseProgram;
CheckResolverUnexpectedHints;
end;

View File

@ -1912,7 +1912,7 @@ End.
<h2 id="absolute">Translating var modifier absolute</h2>
The absolute modifier works as an alias. That means it works FPC/Delphi
compatible for related types like Pointer and TObject, and works
incompatible for unrelated types like longword and record (e.g. var r: TPoint absolute MyLongInt).<br>
incompatible for unrelated types like longword and record (e.g. <i>var r: TPoint absolute MyLongInt</i>).<br>
The modifier is currently only supported for local variables.
</div>