From f17bd32429808d4031be7524ba81963e0b42b98c Mon Sep 17 00:00:00 2001 From: mattias Date: Mon, 30 Dec 2002 12:03:21 +0000 Subject: [PATCH] fixed nested comments for fpc sources git-svn-id: trunk@3764 - --- components/codetools/codetoolsstrconsts.pas | 3 +- components/codetools/definetemplates.pas | 9 +++- components/codetools/fileprocs.pas | 4 +- components/codetools/linkscanner.pas | 47 ++++++++++++++++++--- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/components/codetools/codetoolsstrconsts.pas b/components/codetools/codetoolsstrconsts.pas index 1bf5a5f15c..d9e14f5125 100644 --- a/components/codetools/codetoolsstrconsts.pas +++ b/components/codetools/codetoolsstrconsts.pas @@ -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'; diff --git a/components/codetools/definetemplates.pas b/components/codetools/definetemplates.pas index d925c71079..0db901bec8 100644 --- a/components/codetools/definetemplates.pas +++ b/components/codetools/definetemplates.pas @@ -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']), diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index 9b18a6770a..6009778ef2 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -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 diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas index f8469611aa..7fba9d5d1d 100644 --- a/components/codetools/linkscanner.pas +++ b/components/codetools/linkscanner.pas @@ -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;