Browse Source

fcl-passrc: program, unit, library, initialization: use token start position instead of end

git-svn-id: trunk@37235 -
Mattias Gaertner 8 years ago
parent
commit
1f92f3c754
2 changed files with 19 additions and 13 deletions
  1. 13 11
      packages/fcl-passrc/src/pparser.pp
  2. 6 2
      packages/fcl-passrc/src/pscanner.pp

+ 13 - 11
packages/fcl-passrc/src/pparser.pp

@@ -874,13 +874,10 @@ function TPasParser.CurSourcePos: TPasSourcePos;
 begin
   if HasToken then
     Result:=FTokenRing[FTokenRingCur].SourcePos
+  else if Scanner<>nil then
+    Result:=Scanner.CurSourcePos
   else
-    begin
-    if Scanner<>nil then
-      Result:=Scanner.CurSourcePos
-    else
-      Result:=Default(TPasSourcePos);
-    end;
+    Result:=Default(TPasSourcePos);
 end;
 
 function TPasParser.HasToken: boolean;
@@ -2608,7 +2605,9 @@ end;
 procedure TPasParser.ParseUnit(var Module: TPasModule);
 var
   AUnitName: String;
+  StartPos: TPasSourcePos;
 begin
+  StartPos:=Scanner.CurTokenPos;
   Module := nil;
   AUnitName := ExpectIdentifier;
   NextToken;
@@ -2619,8 +2618,7 @@ begin
     NextToken;
     end;
   UngetToken;
-  Module := TPasModule(CreateElement(TPasModule, AUnitName,
-    Engine.Package));
+  Module := TPasModule(CreateElement(TPasModule, AUnitName, Engine.Package, StartPos));
   FCurModule:=Module;
   try
     if Assigned(Engine.Package) then
@@ -2648,8 +2646,10 @@ Var
   PP : TPasProgram;
   Section : TProgramSection;
   N : String;
+  StartPos: TPasSourcePos;
 
 begin
+  StartPos:=Scanner.CurTokenPos;
   if SkipHeader then
     N:=ChangeFileExt(Scanner.CurFilename,'')
   else
@@ -2665,7 +2665,7 @@ begin
     UngetToken;
     end;
   Module := nil;
-  PP:=TPasProgram(CreateElement(TPasProgram, N, Engine.Package));
+  PP:=TPasProgram(CreateElement(TPasProgram, N, Engine.Package, StartPos));
   Module :=PP;
   FCurModule:=Module;
   try
@@ -2707,8 +2707,10 @@ Var
   PP : TPasLibrary;
   Section : TLibrarySection;
   N: String;
+  StartPos: TPasSourcePos;
 
 begin
+  StartPos:=Scanner.CurTokenPos;
   N:=ExpectIdentifier;
   NextToken;
   while CurToken = tkDot do
@@ -2719,7 +2721,7 @@ begin
     end;
   UngetToken;
   Module := nil;
-  PP:=TPasLibrary(CreateElement(TPasLibrary, N, Engine.Package));
+  PP:=TPasLibrary(CreateElement(TPasLibrary, N, Engine.Package, StartPos));
   Module :=PP;
   FCurModule:=Module;
   try
@@ -2781,7 +2783,7 @@ var
   Section: TInitializationSection;
   SubBlock: TPasImplElement;
 begin
-  Section := TInitializationSection(CreateElement(TInitializationSection, '', CurModule));
+  Section := TInitializationSection(CreateElement(TInitializationSection, '', CurModule,Scanner.CurTokenPos));
   CurModule.InitializationSection := Section;
   repeat
     NextToken;

+ 6 - 2
packages/fcl-passrc/src/pscanner.pp

@@ -509,6 +509,7 @@ type
     FAllowedModeSwitches: TModeSwitches;
     FConditionEval: TCondDirectiveEvaluator;
     FCurrentModeSwitches: TModeSwitches;
+    FCurTokenPos: TPasSourcePos;
     FLastMsg: string;
     FLastMsgArgs: TMessageArgs;
     FLastMsgNumber: integer;
@@ -623,6 +624,7 @@ type
 
     property CurToken: TToken read FCurToken;
     property CurTokenString: string read FCurTokenString;
+    property CurTokenPos: TPasSourcePos read FCurTokenPos;
     Property PreviousToken : TToken Read FPreviousToken;
     Property NonTokens : TTokens Read FNonTokens;
     Property TokenOptions : TTokenOptions Read FTokenOptions Write FTokenOptions;
@@ -2938,7 +2940,7 @@ var
 
 
 begin
-  result:=tkLineEnding;
+  Result:=tkLineEnding;
   if TokenStr = nil then
     if not FetchLine then
     begin
@@ -2947,6 +2949,9 @@ begin
       exit;
     end;
   FCurTokenString := '';
+  FCurTokenPos.FileName:=CurFilename;
+  FCurTokenPos.Row:=CurRow;
+  FCurTokenPos.Column:=CurColumn;
   case TokenStr[0] of
     #0:         // Empty line
       begin
@@ -3727,5 +3732,4 @@ begin
     Exclude(FTokenOptions,toForceCaret)
 end;
 
-
 end.