From faf2bdfd62002c29f5d3374f99523cd0a35301de Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 26 Apr 2010 13:17:26 +0000 Subject: [PATCH] * fix for mantis 16344 (quoted filename in $include ) + testparser example from that series of bugreports. git-svn-id: trunk@15182 - --- .gitattributes | 1 + packages/fcl-passrc/examples/test_parser.pp | 61 +++++++++++++++++++++ packages/fcl-passrc/src/pscanner.pp | 6 ++ 3 files changed, 68 insertions(+) create mode 100644 packages/fcl-passrc/examples/test_parser.pp diff --git a/.gitattributes b/.gitattributes index 55a7e26c27..4bf42f8332 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2054,6 +2054,7 @@ packages/fcl-net/src/win/resolve.inc svneol=native#text/plain packages/fcl-net/src/xmlrpc.pp svneol=native#text/plain packages/fcl-passrc/Makefile svneol=native#text/plain packages/fcl-passrc/Makefile.fpc svneol=native#text/plain +packages/fcl-passrc/examples/test_parser.pp svneol=native#text/plain packages/fcl-passrc/fpmake.pp svneol=native#text/plain packages/fcl-passrc/src/pastree.pp svneol=native#text/plain packages/fcl-passrc/src/paswrite.pp svneol=native#text/plain diff --git a/packages/fcl-passrc/examples/test_parser.pp b/packages/fcl-passrc/examples/test_parser.pp new file mode 100644 index 0000000000..ab70b7db6f --- /dev/null +++ b/packages/fcl-passrc/examples/test_parser.pp @@ -0,0 +1,61 @@ +{$mode objfpc}{$H+} + +uses SysUtils, Classes, PParser, PasTree; + +type + { We have to override abstract TPasTreeContainer methods. + See utils/fpdoc/dglobals.pp for an implementation of TFPDocEngine, + a "real" engine. } + TSimpleEngine = class(TPasTreeContainer) + public + function CreateElement(AClass: TPTreeElement; const AName: String; + AParent: TPasElement; AVisibility: TPasMemberVisibility; + const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; + override; + function FindElement(const AName: String): TPasElement; override; + end; + +function TSimpleEngine.CreateElement(AClass: TPTreeElement; const AName: String; + AParent: TPasElement; AVisibility: TPasMemberVisibility; + const ASourceFilename: String; ASourceLinenumber: Integer): TPasElement; +begin + Result := AClass.Create(AName, AParent); + Result.Visibility := AVisibility; + Result.SourceFilename := ASourceFilename; + Result.SourceLinenumber := ASourceLinenumber; +end; + +function TSimpleEngine.FindElement(const AName: String): TPasElement; +begin + { dummy implementation, see TFPDocEngine.FindElement for a real example } + Result := nil; +end; + +var + M: TPasModule; + E: TPasTreeContainer; + I: Integer; + Decls: TList; +begin + if Paramcount<1 then + begin + // remember to put the whole cmdline in quotes, and + // to always add some path options. Even if only -Fu. -Fi. + writeln('usage: test_parser '); + halt; + end; + E := TSimpleEngine.Create; + try + M := ParseSource(E, ParamStr(1), 'linux', 'i386'); + + { Cool, we successfully parsed the unit. + Now output some info about it. } + Decls := M.InterfaceSection.Declarations; + for I := 0 to Decls.Count - 1 do + Writeln('Interface item ', I, ': ', (TObject(Decls[I]) as TPasElement).Name); + + FreeAndNil(M); + finally + FreeAndNil(E) + end; +end. diff --git a/packages/fcl-passrc/src/pscanner.pp b/packages/fcl-passrc/src/pscanner.pp index d1d45c14a4..e63e1b041a 100644 --- a/packages/fcl-passrc/src/pscanner.pp +++ b/packages/fcl-passrc/src/pscanner.pp @@ -986,6 +986,12 @@ begin IncludeStackItem.Row := CurRow; IncludeStackItem.TokenStr := TokenStr; FIncludeStack.Add(IncludeStackItem); + if Length(Param)>1 then + begin + if (Param[1]=#39) and (Param[length(Param)]=#39) then + param:=copy(param,2,length(param)-2); + end; + FCurSourceFile := FileResolver.FindIncludeFile(Param); if not Assigned(CurSourceFile) then Error(SErrIncludeFileNotFound, [Param]);