From c5410eee5c3e5a9f1a385c94b2b6e562201ea0d2 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 2 Dec 1999 17:34:34 +0000 Subject: [PATCH] * preprocessor support. But it fails on the caret in type blocks --- compiler/compiler.pas | 10 ++++- compiler/globals.pas | 6 ++- compiler/options.pas | 6 ++- compiler/parser.pas | 76 +++++++++++++++++++++++++++++++++++- compiler/scandir.inc | 15 +++++++- compiler/scanner.pas | 90 +++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 193 insertions(+), 10 deletions(-) diff --git a/compiler/compiler.pas b/compiler/compiler.pas index f8e8d8ea5b..2f5fa7592f 100644 --- a/compiler/compiler.pas +++ b/compiler/compiler.pas @@ -285,7 +285,10 @@ begin {$endif TP} {$endif USEEXCEPT} starttime:=getrealtime; - parser.compile(inputdir+inputfile+inputextension,false); + if parapreprocess then + parser.preprocess(inputdir+inputfile+inputextension) + else + parser.compile(inputdir+inputfile+inputextension,false); if status.errorcount=0 then begin starttime:=getrealtime-starttime; @@ -326,7 +329,10 @@ end; end. { $Log$ - Revision 1.40 1999-11-18 13:43:48 pierre + Revision 1.41 1999-12-02 17:34:34 peter + * preprocessor support. But it fails on the caret in type blocks + + Revision 1.40 1999/11/18 13:43:48 pierre + IsExe global var needed for IDE Revision 1.39 1999/11/12 11:03:50 peter diff --git a/compiler/globals.pas b/compiler/globals.pas index 8a8db15cab..3223e80280 100644 --- a/compiler/globals.pas +++ b/compiler/globals.pas @@ -94,6 +94,7 @@ unit globals; { things specified with parameters } paralinkoptions, paradynamiclinker : string; + parapreprocess : boolean; { directory where the utils can be found (options -FD) } utilsdirectory : dirstr; @@ -1357,7 +1358,10 @@ begin end. { $Log$ - Revision 1.36 1999-11-18 15:34:45 pierre + Revision 1.37 1999-12-02 17:34:34 peter + * preprocessor support. But it fails on the caret in type blocks + + Revision 1.36 1999/11/18 15:34:45 pierre * Notes/Hints for local syms changed to Set_varstate function diff --git a/compiler/options.pas b/compiler/options.pas index 4e5b02ee99..8cb69eb593 100644 --- a/compiler/options.pas +++ b/compiler/options.pas @@ -598,6 +598,7 @@ begin DoWriteLogo:=true else IllegalPara(opt); + 'm' : parapreprocess:=true; 'n' : if More='' then read_configfile:=false else @@ -1276,7 +1277,10 @@ end; end. { $Log$ - Revision 1.37 1999-11-20 01:22:19 pierre + Revision 1.38 1999-12-02 17:34:34 peter + * preprocessor support. But it fails on the caret in type blocks + + Revision 1.37 1999/11/20 01:22:19 pierre + cond FPC_USE_CPREFIX (needs also some RTL changes) this allows to use unit global vars as DLL exports (the underline prefix seems needed by dlltool) diff --git a/compiler/parser.pas b/compiler/parser.pas index 30b1fee29e..708bb59d43 100644 --- a/compiler/parser.pas +++ b/compiler/parser.pas @@ -38,6 +38,7 @@ unit parser; interface + procedure preprocess(const filename:string); procedure compile(const filename:string;compile_system:boolean); procedure initparser; procedure doneparser; @@ -148,6 +149,76 @@ unit parser; end; + procedure preprocess(const filename:string); + var + i : longint; + begin + new(preprocfile,init('pre')); + { default macros } + macros:=new(psymtable,init(macrosymtable)); + macros^.name:=stringdup('Conditionals for '+filename); + default_macros; + { initialize a module } + current_module:=new(pmodule,init(filename,false)); + main_module:=current_module; + { startup scanner, and save in current_module } + current_scanner:=new(pscannerfile,Init(filename)); + current_module^.scanner:=current_scanner; + { loop until EOF is found } + repeat + current_scanner^.readtoken; + preprocfile^.AddSpace; + case token of + _ID : + begin + preprocfile^.Add(orgpattern); + end; + _REALNUMBER, + _INTCONST : + preprocfile^.Add(pattern); + _CSTRING : + begin + i:=0; + while (i0 then + Comment(V_Fatal,'can''t create file '+fn); + getmem(buf,preprocbufsize); + settextbuf(f,buf^,preprocbufsize); + { reset } + eolfound:=false; + spacefound:=false; + end; + + + destructor tpreprocfile.done; + begin + close(f); + freemem(buf,preprocbufsize); + end; + + + procedure tpreprocfile.add(const s:string); + begin + write(f,s); + end; + + procedure tpreprocfile.addspace; + begin + if eolfound then + begin + writeln(f,''); + eolfound:=false; + spacefound:=false; + end + else + if spacefound then + begin + write(f,' '); + spacefound:=false; + end; + end; + + {***************************************************************************** TPreProcStack *****************************************************************************} @@ -815,9 +883,11 @@ implementation else inc(longint(inputpointer)); case c of - #26 : reload; + #26 : + reload; #10, - #13 : linebreak; + #13 : + linebreak; end; end; end; @@ -1075,7 +1145,16 @@ implementation '{' : skipcomment; ' ',#9..#13 : - skipspace; + begin + if parapreprocess then + begin + if c=#10 then + preprocfile^.eolfound:=true + else + preprocfile^.spacefound:=true; + end; + skipspace; + end else break; end; @@ -1698,7 +1777,10 @@ exit_label: end. { $Log$ - Revision 1.101 1999-11-15 17:52:59 pierre + Revision 1.102 1999-12-02 17:34:34 peter + * preprocessor support. But it fails on the caret in type blocks + + Revision 1.101 1999/11/15 17:52:59 pierre + one field added for ttoken record for operator linking the id to the corresponding operator token that can now now all be overloaded