Browse Source

fcl-passrc: fixed stConstDef for class local const

git-svn-id: trunk@38097 -
Mattias Gaertner 7 years ago
parent
commit
b8710d8fec

+ 9 - 4
packages/fcl-passrc/src/pparser.pp

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

+ 46 - 42
packages/fcl-passrc/tests/tcresolver.pas

@@ -8318,48 +8318,52 @@ end;
 procedure TTestResolver.TestClass_Const;
 procedure TTestResolver.TestClass_Const;
 begin
 begin
   StartProgram(false);
   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;
   ParseProgram;
   CheckResolverUnexpectedHints;
   CheckResolverUnexpectedHints;
 end;
 end;

+ 1 - 1
utils/pas2js/docs/translation.html

@@ -1912,7 +1912,7 @@ End.
     <h2 id="absolute">Translating var modifier absolute</h2>
     <h2 id="absolute">Translating var modifier absolute</h2>
     The absolute modifier works as an alias. That means it works FPC/Delphi
     The absolute modifier works as an alias. That means it works FPC/Delphi
     compatible for related types like Pointer and TObject, and works
     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.
     The modifier is currently only supported for local variables.
     </div>
     </div>