* Patch from Mattias Gaertner to make implicitly used units configurable

git-svn-id: trunk@34169 -
This commit is contained in:
michael 2016-07-22 09:23:35 +00:00
parent e9a1ed9446
commit 298a3ba63d
2 changed files with 16 additions and 6 deletions

View File

@ -180,6 +180,7 @@ type
private private
FCurModule: TPasModule; FCurModule: TPasModule;
FFileResolver: TBaseFileResolver; FFileResolver: TBaseFileResolver;
FImplicitUses: TStrings;
FLastMsg: string; FLastMsg: string;
FLastMsgArgs: TMessageArgs; FLastMsgArgs: TMessageArgs;
FLastMsgNumber: integer; FLastMsgNumber: integer;
@ -215,7 +216,6 @@ type
Function SaveComments : String; Function SaveComments : String;
Function SaveComments(Const AValue : String) : String; Function SaveComments(Const AValue : String) : String;
function LogEvent(E : TPParserLogEvent) : Boolean; inline; function LogEvent(E : TPParserLogEvent) : Boolean; inline;
procedure SetCurMsg(MsgType: TMessageType; MsgNumber: integer; Const Fmt : String; Args : Array of const);
Procedure DoLog(MsgType: TMessageType; MsgNumber: integer; Const Msg : String; SkipSourceInfo : Boolean = False);overload; Procedure DoLog(MsgType: TMessageType; MsgNumber: integer; Const Msg : String; SkipSourceInfo : Boolean = False);overload;
Procedure DoLog(MsgType: TMessageType; MsgNumber: integer; Const Fmt : String; Args : Array of const;SkipSourceInfo : Boolean = False);overload; Procedure DoLog(MsgType: TMessageType; MsgNumber: integer; Const Fmt : String; Args : Array of const;SkipSourceInfo : Boolean = False);overload;
function GetProcTypeFromToken(tk: TToken; IsClass: Boolean=False ): TProcType; function GetProcTypeFromToken(tk: TToken; IsClass: Boolean=False ): TProcType;
@ -256,6 +256,7 @@ type
public public
constructor Create(AScanner: TPascalScanner; AFileResolver: TBaseFileResolver; AEngine: TPasTreeContainer); constructor Create(AScanner: TPascalScanner; AFileResolver: TBaseFileResolver; AEngine: TPasTreeContainer);
Destructor Destroy; override; Destructor Destroy; override;
procedure SetLastMsg(MsgType: TMessageType; MsgNumber: integer; Const Fmt : String; Args : Array of const);
// General parsing routines // General parsing routines
function CurTokenName: String; function CurTokenName: String;
function CurTokenText: String; function CurTokenText: String;
@ -323,6 +324,7 @@ type
Property CurModule : TPasModule Read FCurModule; Property CurModule : TPasModule Read FCurModule;
Property LogEvents : TPParserLogEvents Read FLogEvents Write FLogEvents; Property LogEvents : TPParserLogEvents Read FLogEvents Write FLogEvents;
Property OnLog : TPasParserLogHandler Read FOnLog Write FOnLog; Property OnLog : TPasParserLogHandler Read FOnLog Write FOnLog;
property ImplicitUses: TStrings read FImplicitUses;
property LastMsg: string read FLastMsg write FLastMsg; property LastMsg: string read FLastMsg write FLastMsg;
property LastMsgNumber: integer read FLastMsgNumber write FLastMsgNumber; property LastMsgNumber: integer read FLastMsgNumber write FLastMsgNumber;
property LastMsgType: TMessageType read FLastMsgType write FLastMsgType; property LastMsgType: TMessageType read FLastMsgType write FLastMsgType;
@ -620,7 +622,7 @@ end;
procedure TPasParser.ParseExc(MsgNumber: integer; const Fmt: String; procedure TPasParser.ParseExc(MsgNumber: integer; const Fmt: String;
Args: array of const); Args: array of const);
begin begin
SetCurMsg(mtError,MsgNumber,Fmt,Args); SetLastMsg(mtError,MsgNumber,Fmt,Args);
raise EParserError.Create(Format(SParserErrorAtToken, raise EParserError.Create(Format(SParserErrorAtToken,
[FLastMsg, CurTokenName, Scanner.CurFilename, Scanner.CurRow, Scanner.CurColumn]) [FLastMsg, CurTokenName, Scanner.CurFilename, Scanner.CurRow, Scanner.CurColumn])
{$ifdef addlocation}+' ('+inttostr(scanner.currow)+' '+inttostr(scanner.curcolumn)+')'{$endif}, {$ifdef addlocation}+' ('+inttostr(scanner.currow)+' '+inttostr(scanner.curcolumn)+')'{$endif},
@ -657,10 +659,13 @@ begin
If FEngine.NeedComments then If FEngine.NeedComments then
FScanner.SkipComments:=Not FEngine.NeedComments; FScanner.SkipComments:=Not FEngine.NeedComments;
end; end;
FImplicitUses := TStringList.Create;
FImplicitUses.Add('System'); // system always implicitely first.
end; end;
destructor TPasParser.Destroy; destructor TPasParser.Destroy;
begin begin
FreeAndNil(FImplicitUses);
FreeAndNil(FCommentsBuffer[0]); FreeAndNil(FCommentsBuffer[0]);
FreeAndNil(FCommentsBuffer[1]); FreeAndNil(FCommentsBuffer[1]);
if Assigned(FEngine) then if Assigned(FEngine) then
@ -2310,9 +2315,15 @@ procedure TPasParser.ParseUsesList(ASection: TPasSection);
var var
AUnitName: String; AUnitName: String;
Element: TPasElement; Element: TPasElement;
i: Integer;
begin begin
If not (Asection.ClassType=TImplementationSection) Then // interface,program,library,package If not (Asection.ClassType=TImplementationSection) Then // interface,program,library,package
Element:=CheckUnit('System'); // system always implicitely first. begin
// load implicit units, like 'System'
for i:=0 to ImplicitUses.Count-1 do
CheckUnit(ImplicitUses[i]);
end;
Repeat Repeat
AUnitName := ExpectIdentifier; AUnitName := ExpectIdentifier;
NextToken; NextToken;
@ -2674,7 +2685,7 @@ begin
Result:=E in FLogEvents; Result:=E in FLogEvents;
end; end;
procedure TPasParser.SetCurMsg(MsgType: TMessageType; MsgNumber: integer; procedure TPasParser.SetLastMsg(MsgType: TMessageType; MsgNumber: integer;
const Fmt: String; Args: array of const); const Fmt: String; Args: array of const);
begin begin
FLastMsgType := MsgType; FLastMsgType := MsgType;
@ -2693,7 +2704,7 @@ end;
procedure TPasParser.DoLog(MsgType: TMessageType; MsgNumber: integer; procedure TPasParser.DoLog(MsgType: TMessageType; MsgNumber: integer;
const Fmt: String; Args: array of const; SkipSourceInfo: Boolean); const Fmt: String; Args: array of const; SkipSourceInfo: Boolean);
begin begin
SetCurMsg(MsgType,MsgNumber,Fmt,Args); SetLastMsg(MsgType,MsgNumber,Fmt,Args);
If Assigned(FOnLog) then If Assigned(FOnLog) then
if SkipSourceInfo or not assigned(scanner) then if SkipSourceInfo or not assigned(scanner) then
FOnLog(Self,FLastMsg) FOnLog(Self,FLastMsg)

View File

@ -1244,7 +1244,6 @@ procedure TPascalScanner.HandleIncludeFile(Param: String);
begin begin
PushStackItem; PushStackItem;
writeln('TPascalScanner.HandleIncludeFile AAA1 Param="',Param,'"');
if Length(Param)>1 then if Length(Param)>1 then
begin begin
if (Param[1]=#39) and (Param[length(Param)]=#39) then if (Param[1]=#39) and (Param[length(Param)]=#39) then