|
@@ -55,6 +55,7 @@ const
|
|
nWarnIllegalCompilerDirectiveX = 1028;
|
|
nWarnIllegalCompilerDirectiveX = 1028;
|
|
nIllegalStateForWarnDirective = 1027;
|
|
nIllegalStateForWarnDirective = 1027;
|
|
nErrIncludeLimitReached = 1028;
|
|
nErrIncludeLimitReached = 1028;
|
|
|
|
+ nMisplacedGlobalCompilerSwitch = 1029;
|
|
|
|
|
|
// resourcestring patterns of messages
|
|
// resourcestring patterns of messages
|
|
resourcestring
|
|
resourcestring
|
|
@@ -88,6 +89,7 @@ resourcestring
|
|
SWarnIllegalCompilerDirectiveX = 'Illegal compiler directive "%s"';
|
|
SWarnIllegalCompilerDirectiveX = 'Illegal compiler directive "%s"';
|
|
SIllegalStateForWarnDirective = 'Illegal state "%s" for $WARN directive';
|
|
SIllegalStateForWarnDirective = 'Illegal state "%s" for $WARN directive';
|
|
SErrIncludeLimitReached = 'Include file limit reached';
|
|
SErrIncludeLimitReached = 'Include file limit reached';
|
|
|
|
+ SMisplacedGlobalCompilerSwitch = 'Misplaced global compiler switch, ignored';
|
|
|
|
|
|
type
|
|
type
|
|
TMessageType = (
|
|
TMessageType = (
|
|
@@ -611,6 +613,7 @@ type
|
|
var Handled: boolean) of object;
|
|
var Handled: boolean) of object;
|
|
TPScannerFormatPathEvent = function(const aPath: string): string of object;
|
|
TPScannerFormatPathEvent = function(const aPath: string): string of object;
|
|
TPScannerWarnEvent = procedure(Sender: TObject; Identifier: string; State: TWarnMsgState; var Handled: boolean) of object;
|
|
TPScannerWarnEvent = procedure(Sender: TObject; Identifier: string; State: TWarnMsgState; var Handled: boolean) of object;
|
|
|
|
+ TPScannerModeDirective = procedure(Sender: TObject; NewMode: TModeSwitch; Before: boolean; var Handled: boolean) of object;
|
|
|
|
|
|
TPascalScanner = class
|
|
TPascalScanner = class
|
|
private
|
|
private
|
|
@@ -651,6 +654,7 @@ type
|
|
FOnEvalFunction: TCEEvalFunctionEvent;
|
|
FOnEvalFunction: TCEEvalFunctionEvent;
|
|
FOnEvalVariable: TCEEvalVarEvent;
|
|
FOnEvalVariable: TCEEvalVarEvent;
|
|
FOnFormatPath: TPScannerFormatPathEvent;
|
|
FOnFormatPath: TPScannerFormatPathEvent;
|
|
|
|
+ FOnModeChanged: TPScannerModeDirective;
|
|
FOnWarnDirective: TPScannerWarnEvent;
|
|
FOnWarnDirective: TPScannerWarnEvent;
|
|
FOptions: TPOptions;
|
|
FOptions: TPOptions;
|
|
FLogEvents: TPScannerLogEvents;
|
|
FLogEvents: TPScannerLogEvents;
|
|
@@ -660,6 +664,7 @@ type
|
|
FReadOnlyModeSwitches: TModeSwitches;
|
|
FReadOnlyModeSwitches: TModeSwitches;
|
|
FReadOnlyValueSwitches: TValueSwitches;
|
|
FReadOnlyValueSwitches: TValueSwitches;
|
|
FSkipComments: Boolean;
|
|
FSkipComments: Boolean;
|
|
|
|
+ FSkipGlobalSwitches: boolean;
|
|
FSkipWhiteSpace: Boolean;
|
|
FSkipWhiteSpace: Boolean;
|
|
FTokenOptions: TTokenOptions;
|
|
FTokenOptions: TTokenOptions;
|
|
FTokenStr: PChar;
|
|
FTokenStr: PChar;
|
|
@@ -742,11 +747,11 @@ type
|
|
procedure OpenFile(AFilename: string);
|
|
procedure OpenFile(AFilename: string);
|
|
procedure FinishedModule; virtual; // called by parser after end.
|
|
procedure FinishedModule; virtual; // called by parser after end.
|
|
function FormatPath(const aFilename: string): string; virtual;
|
|
function FormatPath(const aFilename: string): string; virtual;
|
|
- Procedure SetNonToken(aToken : TToken);
|
|
|
|
- Procedure UnsetNonToken(aToken : TToken);
|
|
|
|
- Procedure SetTokenOption(aOption : TTokenoption);
|
|
|
|
- Procedure UnSetTokenOption(aOption : TTokenoption);
|
|
|
|
- Function CheckToken(aToken : TToken; const ATokenString : String) : TToken;
|
|
|
|
|
|
+ procedure SetNonToken(aToken : TToken);
|
|
|
|
+ procedure UnsetNonToken(aToken : TToken);
|
|
|
|
+ procedure SetTokenOption(aOption : TTokenoption);
|
|
|
|
+ procedure UnSetTokenOption(aOption : TTokenoption);
|
|
|
|
+ function CheckToken(aToken : TToken; const ATokenString : String) : TToken;
|
|
function FetchToken: TToken;
|
|
function FetchToken: TToken;
|
|
function ReadNonPascalTillEndToken(StopAtLineEnd: boolean): TToken;
|
|
function ReadNonPascalTillEndToken(StopAtLineEnd: boolean): TToken;
|
|
function AddDefine(const aName: String; Quiet: boolean = false): boolean;
|
|
function AddDefine(const aName: String; Quiet: boolean = false): boolean;
|
|
@@ -756,9 +761,9 @@ type
|
|
function IfOpt(Letter: Char): boolean;
|
|
function IfOpt(Letter: Char): boolean;
|
|
function AddMacro(const aName, aValue: String; Quiet: boolean = false): boolean;
|
|
function AddMacro(const aName, aValue: String; Quiet: boolean = false): boolean;
|
|
function RemoveMacro(const aName: String; Quiet: boolean = false): boolean;
|
|
function RemoveMacro(const aName: String; Quiet: boolean = false): boolean;
|
|
- Procedure SetCompilerMode(S : String);
|
|
|
|
|
|
+ procedure SetCompilerMode(S : String);
|
|
function CurSourcePos: TPasSourcePos;
|
|
function CurSourcePos: TPasSourcePos;
|
|
- Function SetForceCaret(AValue : Boolean) : Boolean; // returns old state
|
|
|
|
|
|
+ function SetForceCaret(AValue : Boolean) : Boolean; // returns old state
|
|
function IgnoreMsgType(MsgType: TMessageType): boolean; virtual;
|
|
function IgnoreMsgType(MsgType: TMessageType): boolean; virtual;
|
|
property FileResolver: TBaseFileResolver read FFileResolver;
|
|
property FileResolver: TBaseFileResolver read FFileResolver;
|
|
property Files: TStrings read FFiles;
|
|
property Files: TStrings read FFiles;
|
|
@@ -770,9 +775,9 @@ type
|
|
property CurToken: TToken read FCurToken;
|
|
property CurToken: TToken read FCurToken;
|
|
property CurTokenString: string read FCurTokenString;
|
|
property CurTokenString: string read FCurTokenString;
|
|
property CurTokenPos: TPasSourcePos read FCurTokenPos;
|
|
property CurTokenPos: TPasSourcePos read FCurTokenPos;
|
|
- Property PreviousToken : TToken Read FPreviousToken;
|
|
|
|
|
|
+ property PreviousToken : TToken Read FPreviousToken;
|
|
property ModuleRow: Integer read FModuleRow;
|
|
property ModuleRow: Integer read FModuleRow;
|
|
- Property NonTokens : TTokens Read FNonTokens;
|
|
|
|
|
|
+ property NonTokens : TTokens Read FNonTokens;
|
|
Property TokenOptions : TTokenOptions Read FTokenOptions Write FTokenOptions;
|
|
Property TokenOptions : TTokenOptions Read FTokenOptions Write FTokenOptions;
|
|
property Defines: TStrings read FDefines;
|
|
property Defines: TStrings read FDefines;
|
|
property Macros: TStrings read FMacros;
|
|
property Macros: TStrings read FMacros;
|
|
@@ -789,8 +794,9 @@ type
|
|
property CurrentValueSwitch[V: TValueSwitch]: string read GetCurrentValueSwitch Write SetCurrentValueSwitch;
|
|
property CurrentValueSwitch[V: TValueSwitch]: string read GetCurrentValueSwitch Write SetCurrentValueSwitch;
|
|
property WarnMsgState[Number: integer]: TWarnMsgState read GetWarnMsgState write SetWarnMsgState;
|
|
property WarnMsgState[Number: integer]: TWarnMsgState read GetWarnMsgState write SetWarnMsgState;
|
|
property Options : TPOptions read FOptions write SetOptions;
|
|
property Options : TPOptions read FOptions write SetOptions;
|
|
- Property SkipWhiteSpace : Boolean Read FSkipWhiteSpace Write FSkipWhiteSpace;
|
|
|
|
- Property SkipComments : Boolean Read FSkipComments Write FSkipComments;
|
|
|
|
|
|
+ property SkipWhiteSpace : Boolean Read FSkipWhiteSpace Write FSkipWhiteSpace;
|
|
|
|
+ property SkipComments : Boolean Read FSkipComments Write FSkipComments;
|
|
|
|
+ property SkipGlobalSwitches: Boolean read FSkipGlobalSwitches write FSkipGlobalSwitches;
|
|
property MaxIncludeStackDepth: integer read FMaxIncludeStackDepth write FMaxIncludeStackDepth default DefaultMaxIncludeStackDepth;
|
|
property MaxIncludeStackDepth: integer read FMaxIncludeStackDepth write FMaxIncludeStackDepth default DefaultMaxIncludeStackDepth;
|
|
property ForceCaret : Boolean read GetForceCaret;
|
|
property ForceCaret : Boolean read GetForceCaret;
|
|
|
|
|
|
@@ -801,6 +807,7 @@ type
|
|
property OnEvalVariable: TCEEvalVarEvent read FOnEvalVariable write FOnEvalVariable;
|
|
property OnEvalVariable: TCEEvalVarEvent read FOnEvalVariable write FOnEvalVariable;
|
|
property OnEvalFunction: TCEEvalFunctionEvent read FOnEvalFunction write FOnEvalFunction;
|
|
property OnEvalFunction: TCEEvalFunctionEvent read FOnEvalFunction write FOnEvalFunction;
|
|
property OnWarnDirective: TPScannerWarnEvent read FOnWarnDirective write FOnWarnDirective;
|
|
property OnWarnDirective: TPScannerWarnEvent read FOnWarnDirective write FOnWarnDirective;
|
|
|
|
+ property OnModeChanged: TPScannerModeDirective read FOnModeChanged write FOnModeChanged; // set by TPasParser
|
|
|
|
|
|
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;
|
|
@@ -1091,6 +1098,9 @@ const
|
|
msISOLikeMod];
|
|
msISOLikeMod];
|
|
|
|
|
|
function StrToModeSwitch(aName: String): TModeSwitch;
|
|
function StrToModeSwitch(aName: String): TModeSwitch;
|
|
|
|
+function ModeSwitchesToStr(Switches: TModeSwitches): string;
|
|
|
|
+function BoolSwitchesToStr(Switches: TBoolSwitches): string;
|
|
|
|
+
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
function FilenameIsWinAbsolute(const TheFilename: string): boolean;
|
|
function FilenameIsWinAbsolute(const TheFilename: string): boolean;
|
|
function FilenameIsUnixAbsolute(const TheFilename: string): boolean;
|
|
function FilenameIsUnixAbsolute(const TheFilename: string): boolean;
|
|
@@ -1254,6 +1264,26 @@ begin
|
|
Result:=msNone;
|
|
Result:=msNone;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function ModeSwitchesToStr(Switches: TModeSwitches): string;
|
|
|
|
+var
|
|
|
|
+ ms: TModeSwitch;
|
|
|
|
+begin
|
|
|
|
+ Result:='';
|
|
|
|
+ for ms in Switches do
|
|
|
|
+ Result:=Result+SModeSwitchNames[ms]+',';
|
|
|
|
+ Result:='['+LeftStr(Result,length(Result)-1)+']';
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function BoolSwitchesToStr(Switches: TBoolSwitches): string;
|
|
|
|
+var
|
|
|
|
+ bs: TBoolSwitch;
|
|
|
|
+begin
|
|
|
|
+ Result:='';
|
|
|
|
+ for bs in Switches do
|
|
|
|
+ Result:=Result+BoolSwitchNames[bs]+',';
|
|
|
|
+ Result:='['+LeftStr(Result,length(Result)-1)+']';
|
|
|
|
+end;
|
|
|
|
+
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
begin
|
|
begin
|
|
{$IFDEF WINDOWS}
|
|
{$IFDEF WINDOWS}
|
|
@@ -2969,22 +2999,37 @@ procedure TPascalScanner.HandleMode(const Param: String);
|
|
const AddBoolSwitches: TBoolSwitches = [];
|
|
const AddBoolSwitches: TBoolSwitches = [];
|
|
const RemoveBoolSwitches: TBoolSwitches = []
|
|
const RemoveBoolSwitches: TBoolSwitches = []
|
|
);
|
|
);
|
|
|
|
+ var
|
|
|
|
+ Handled: Boolean;
|
|
begin
|
|
begin
|
|
if not (LangMode in AllowedModeSwitches) then
|
|
if not (LangMode in AllowedModeSwitches) then
|
|
Error(nErrInvalidMode,SErrInvalidMode,[Param]);
|
|
Error(nErrInvalidMode,SErrInvalidMode,[Param]);
|
|
- CurrentModeSwitches:=(NewModeSwitches+ReadOnlyModeSwitches)*AllowedModeSwitches;
|
|
|
|
- CurrentBoolSwitches:=CurrentBoolSwitches+(AddBoolSwitches*AllowedBoolSwitches)
|
|
|
|
- -(RemoveBoolSwitches*AllowedBoolSwitches);
|
|
|
|
- if IsDelphi then
|
|
|
|
- FOptions:=FOptions+[po_delphi]
|
|
|
|
- else
|
|
|
|
- FOptions:=FOptions-[po_delphi];
|
|
|
|
|
|
+ Handled:=false;
|
|
|
|
+ if Assigned(OnModeChanged) then
|
|
|
|
+ OnModeChanged(Self,LangMode,true,Handled);
|
|
|
|
+ if not Handled then
|
|
|
|
+ begin
|
|
|
|
+ CurrentModeSwitches:=(NewModeSwitches+ReadOnlyModeSwitches)*AllowedModeSwitches;
|
|
|
|
+ CurrentBoolSwitches:=CurrentBoolSwitches+(AddBoolSwitches*AllowedBoolSwitches)
|
|
|
|
+ -(RemoveBoolSwitches*AllowedBoolSwitches);
|
|
|
|
+ if IsDelphi then
|
|
|
|
+ FOptions:=FOptions+[po_delphi]
|
|
|
|
+ else
|
|
|
|
+ FOptions:=FOptions-[po_delphi];
|
|
|
|
+ end;
|
|
|
|
+ Handled:=false;
|
|
|
|
+ if Assigned(OnModeChanged) then
|
|
|
|
+ OnModeChanged(Self,LangMode,false,Handled);
|
|
end;
|
|
end;
|
|
|
|
|
|
Var
|
|
Var
|
|
P : String;
|
|
P : String;
|
|
-
|
|
|
|
begin
|
|
begin
|
|
|
|
+ if SkipGlobalSwitches then
|
|
|
|
+ begin
|
|
|
|
+ DoLog(mtWarning,nMisplacedGlobalCompilerSwitch,SMisplacedGlobalCompilerSwitch,[]);
|
|
|
|
+ exit;
|
|
|
|
+ end;
|
|
P:=UpperCase(Param);
|
|
P:=UpperCase(Param);
|
|
Case P of
|
|
Case P of
|
|
'FPC','DEFAULT':
|
|
'FPC','DEFAULT':
|