fixed nested comments for fpc sources

git-svn-id: trunk@3764 -
This commit is contained in:
mattias 2002-12-30 12:03:21 +00:00
parent 14db153343
commit f17bd32429
4 changed files with 52 additions and 11 deletions

View File

@ -32,7 +32,7 @@ interface
uses
Classes, SysUtils;
ResourceString
// codetree
ctsUnknownSubDescriptor = '(unknown subdescriptor %s)';
@ -159,6 +159,7 @@ ResourceString
'Source filenames for the standard fpc units';
ctsFreePascalSourceDir = 'Free Pascal Source Directory';
ctsSrcPathInitialization = 'SrcPath Initialization';
ctsNestedCommentsOn = 'Nested Comments On';
ctsCompiler = 'Compiler';
ctsRuntimeLibrary = 'Runtime library';
ctsProcessorSpecific = 'processor specific';

View File

@ -2320,6 +2320,10 @@ begin
DefTempl:=TDefineTemplate.Create('Reset SrcPath',
ctsSrcPathInitialization,ExternalMacroStart+'SrcPath','',da_DefineRecurse);
MainDir.AddChild(DefTempl);
// turn Nested comments on
DefTempl:=TDefineTemplate.Create('Nested Comments',
ctsNestedCommentsOn,ExternalMacroStart+'NestedComments','',da_DefineRecurse);
MainDir.AddChild(DefTempl);
// compiler
CompilerDir:=TDefineTemplate.Create('Compiler',ctsCompiler,'','compiler',
@ -2422,7 +2426,10 @@ begin
ExternalMacroStart+'IncPath',
'include;include'+ds+TargetOS,
da_Define));
// turn Nested comments on
MainDir.AddChild(TDefineTemplate.Create('Nested Comments',
ctsNestedCommentsOn,ExternalMacroStart+'NestedComments','',da_DefineRecurse));
// examples
DirTempl:=TDefineTemplate.Create('Examples',
Format(ctsNamedDirectory,['Examples']),

View File

@ -53,6 +53,8 @@ const
{$endif}
function CompareFilenames(const Filename1, Filename2: string): integer;
function CompareFileExt(const Filename, Ext: string;
CaseSensitive: boolean): integer;
function DirectoryExists(DirectoryName: string): boolean;
function ExtractFileNameOnly(const AFilename: string): string;
function FilenameIsAbsolute(TheFilename: string):boolean;
@ -69,8 +71,6 @@ function SearchFileInPath(const Filename, BasePath, SearchPath,
Delimiter: string; SearchLoUpCase: boolean): string;
function FilenameIsMatching(const Mask, Filename: string;
MatchExactly: boolean): boolean;
function CompareFileExt(const Filename, Ext: string;
CaseSensitive: boolean): integer;
implementation

View File

@ -49,6 +49,8 @@ uses
const
PascalCompilerDefine = ExternalMacroStart+'Compiler';
NestedCompilerDefine = ExternalMacroStart+'NestedComments';
MissingIncludeFileCode = 1;
type
@ -217,6 +219,7 @@ type
FSkipIfLevel: integer;
FCompilerMode: TCompilerMode;
FPascalCompiler: TPascalCompiler;
procedure SetCompilerMode(const AValue: TCompilerMode);
procedure SkipTillEndifElse;
function SkipIfDirective: boolean;
function IfdefDirective: boolean;
@ -272,6 +275,8 @@ type
EndOfInterfaceFound: boolean;
EndOfSourceFound: boolean;
function MainFilename: string;
// links
property Links[Index: integer]: TSourceLink read GetLinks write SetLinks;
@ -349,7 +354,8 @@ type
property IncludeFileIsMissing: boolean
read GetIncludeFileIsMissing;
property NestedComments: boolean read FNestedComments;
property CompilerMode: TCompilerMode read FCompilerMode write FCompilerMode;
property CompilerMode: TCompilerMode
read FCompilerMode write SetCompilerMode;
property PascalCompiler: TPascalCompiler
read FPascalCompiler write FPascalCompiler;
property ScanTillInterfaceEnd: boolean
@ -961,6 +967,7 @@ begin
EndOfSourceFound:=false;
CommentStyle:=CommentNone;
CommentLevel:=0;
FNestedComments:=false;
CompilerMode:=cmFPC;
PascalCompiler:=pcFPC;
IfLevel:=0;
@ -969,15 +976,25 @@ begin
FInitValues.Assign(FOnGetInitValues(FMainCode,FInitValuesChangeStep));
//writeln('TLinkScanner.Scan D --------');
Values.Assign(FInitValues);
for cm:=Low(TCompilerMode) to High(TCompilerMode) do
if FInitValues.IsDefined(CompilerModeVars[cm]) then begin
CompilerMode:=cm;
end;
// compiler
s:=FInitValues.Variables[PascalCompilerDefine];
for pc:=Low(TPascalCompiler) to High(TPascalCompiler) do
if (s=PascalCompilerNames[pc]) then begin
if (s=PascalCompilerNames[pc]) then
PascalCompiler:=pc;
end;
// compiler mode
for cm:=Low(TCompilerMode) to High(TCompilerMode) do
if FInitValues.IsDefined(CompilerModeVars[cm]) then
CompilerMode:=cm;
// nested comments
if (PascalCompiler=pcFPC) and (CompilerMode in [cmFPC,cmOBJFPC])
and ((FInitValues.IsDefined(NestedCompilerDefine))
or (CompareFileExt(MainFilename,'pp',false)=0))
then
FNestedComments:=true;
//writeln(Values.AsString);
//writeln('TLinkScanner.Scan E --------');
FMacrosOn:=(Values.Variables['MACROS']<>'0');
@ -2475,6 +2492,14 @@ begin
end;
end;
procedure TLinkScanner.SetCompilerMode(const AValue: TCompilerMode);
begin
if FCompilerMode=AValue then exit;
FCompilerMode:=AValue;
FNestedComments:=(PascalCompiler=pcFPC)
and (FCompilerMode in [cmFPC,cmOBJFPC]);
end;
function TLinkScanner.SkipIfDirective: boolean;
begin
inc(IfLevel);
@ -2720,6 +2745,14 @@ begin
RaiseExceptionClass('Abort',ELinkScannerAbort);
end;
function TLinkScanner.MainFilename: string;
begin
if Assigned(OnGetFileName) and (Code<>nil) then
Result:=OnGetFileName(Self,Code)
else
Result:='';
end;
{ ELinkScannerError }
constructor ELinkScannerError.Create(ASender: TLinkScanner;