summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordodi <dodi@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-15 13:27:09 +0000
committerdodi <dodi@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-08-15 13:27:09 +0000
commit025b59aad23e047d52d18548c7d7987e281f8e4b (patch)
tree823a6771fd07fce2f13822ef494428e9804b9bce
parentf196cd09f835819b246f21fa672e16c331b57a49 (diff)
downloadfpc-025b59aad23e047d52d18548c7d7987e281f8e4b.tar.gz
NG: cleanup compile/compileMain
git-svn-id: http://svn.freepascal.org/svn/fpc/branches/dodi@15814 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--NoGlobals/compiler/fmodule.pas3
-rw-r--r--NoGlobals/compiler/parser.pas135
-rw-r--r--NoGlobals/compiler/pmodules.pas6
-rw-r--r--NoGlobals/compiler/symbase.pas24
-rw-r--r--NoGlobals/compiler/symtable.pas33
5 files changed, 71 insertions, 130 deletions
diff --git a/NoGlobals/compiler/fmodule.pas b/NoGlobals/compiler/fmodule.pas
index 0ce00d1ac0..834f7cb2eb 100644
--- a/NoGlobals/compiler/fmodule.pas
+++ b/NoGlobals/compiler/fmodule.pas
@@ -227,9 +227,6 @@ interface
SmartLinkOFiles : TCmdStrList; { List of .o files which are generated,
used to delete them after linking }
-
- //procedure set_current_module(p:tmodule); deprecated;
-
{ switch to new module (push), return previous module }
function PushModule(p:tmodule): tmodule;
{ intentionally invalidate current module, return previous module }
diff --git a/NoGlobals/compiler/parser.pas b/NoGlobals/compiler/parser.pas
index c85a57b6d3..fe8990ab83 100644
--- a/NoGlobals/compiler/parser.pas
+++ b/NoGlobals/compiler/parser.pas
@@ -242,78 +242,47 @@ implementation
*****************************************************************************}
type
- polddata=^tolddata;
tolddata=record
{ scanner }
oldtokenpos : tfileposinfo;
- { symtable }
- {$IFDEF old}
- oldmacrosymtablestack : TSymtablestack;
- {$ELSE}
- {$ENDIF}
{ akt.. things }
oldcurrent_filepos : tfileposinfo;
old_current_module : tmodule;
- oldcurrent_procinfo : tprocinfo;
end;
+ polddata=tolddata;
procedure compile(const filename:string);
- var
- olddata : polddata;
procedure SaveParser(var olddata: polddata);
begin
(*todo: saving the scanner/parser state will no more be required
with scanner/parser objects.
+
+ These are (currently) global variables, for error/exception log
*)
- { Uses heap memory instead of placing everything on the
- stack. This is needed because compile() can be called
- recursively }
- new(olddata);
- with olddata^ do
+ with olddata do
begin //removed all local variables
old_current_module:=current_module;
- { save symtable state }
- {$IFDEF old}
- oldmacrosymtablestack:=macrosymtablestack;
- {$ELSE}
- {$ENDIF}
-
- //todo: these should become scanner elements as well
- //oldcurrent_procinfo:=current_procinfo;
- //old_block_type:=current_scanner.block_type;
oldtokenpos:=current_tokenpos;
-
- { save akt... state }
- { handle the postponed case first }
- //flushpendingswitchesstate;
oldcurrent_filepos:=current_filepos;
end;
end;
procedure RestoreParser(var olddata: polddata);
begin
- //must have reset to old module before
- with olddata^ do
+ with olddata do
begin
+ PopModule(old_current_module);
{ restore scanner }
current_tokenpos:=oldtokenpos;
-
- { restore symtable state }
- {$IFDEF old}
- macrosymtablestack:=oldmacrosymtablestack;
- {$ELSE}
- {$ENDIF}
- RestoreProc(oldcurrent_procinfo);
current_filepos:=oldcurrent_filepos;
end;
end;
procedure ParseFinished(var olddata: polddata);
- var
- hp,hp2 : tmodule;
+ //var hp,hp2 : tmodule;
begin
if assigned(current_module) then
begin //todo: move into module
@@ -332,29 +301,20 @@ implementation
{ free symtable stack }
PopSymbolStack(nil); //local in module!
- {$IFDEF old}
- if assigned(macrosymtablestack) then
- begin
- macrosymtablestack.free;
- macrosymtablestack:=nil;
- end;
- {$ELSE}
FreeAndNil(current_module.macrosymtablestack);
- {$ENDIF}
end;
- if (compile_level=1) and
- (status.errorcount=0) then
- { Write Browser Collections }
- do_extractsymbolinfo;
+ {$IFDEF old}
+ if (compile_level=1) then
+ begin
+ { Shut down things when the last file is compiled succesfull }
+ if (status.errorcount=0) then begin
+ { Write Browser Collections }
+ do_extractsymbolinfo;
//RestoreParser(olddata); - moved below
- { Shut down things when the last file is compiled succesfull }
- if (compile_level=1) then begin
- if (status.errorcount=0) then
- begin
- parser_current_file:='';
+ parser_current_file:=''; //here???
{ Close script }
if (not AsmRes.Empty) then
begin
@@ -382,11 +342,9 @@ implementation
unloaded_units.Clear;
end;
end;
- dec(compile_level);
- PopModule(olddata^.old_current_module);
- RestoreParser(olddata);
-
- dispose(olddata);
+ {$ELSE}
+ //in compileMain
+ {$ENDIF}
end;
@@ -401,12 +359,8 @@ implementation
important for the IDE }
{ reset symtable }
PushSymbolStack; //create new
- {$IFDEF old}
- macrosymtablestack:=TSymtablestack.create;
- {$ELSE}
- current_module.macrosymtablestack := TMacroStack.Create;
- WhichMs:=msModule;
- {$ENDIF}
+ current_module.macrosymtablestack := TMacroStack.Create;
+ WhichMs:=msModule;
systemunit:=nil;
{ load current asmdata from current_module }
@@ -424,11 +378,7 @@ implementation
{ init macros before anything in the file is parsed.}
current_module.localmacrosymtable:= tmacrosymtable.create(false);
- {$IFDEF old}
- macrosymtablestack.push(initialmacrosymtable);
- {$ELSE}
macrosymtablestack.Init;
- {$ENDIF}
macrosymtablestack.push(current_module.localmacrosymtable);
{ read the first token }
@@ -462,13 +412,14 @@ implementation
end;
end; //Parse
+ var
+ olddata : polddata;
begin //compile
{ parsing a procedure or declaration should be finished }
if assigned(current_objectdef) then
internalerror(200811122);
SaveParser(olddata);
-
inc(compile_level);
{ reset the unit or create a new program }
if not(assigned(current_module) and
@@ -480,10 +431,14 @@ implementation
Parse;
finally
ParseFinished(olddata);
+ dec(compile_level);
+ RestoreParser(olddata);
end;
end;
procedure compileMain(const filename:string);
+ var
+ hp,hp2 : tmodule;
begin //compile main module
if assigned(current_module) then
internalerror(200501158);
@@ -493,6 +448,44 @@ implementation
addloadedunit(main_module);
main_module.state:=ms_compile;
compile(filename);
+ {$IFDEF old}
+ //moved here
+ {$ELSE}
+ { Shut down things when the last file is compiled succesfull }
+ if (status.errorcount=0) then begin
+ { Write Browser Collections }
+ do_extractsymbolinfo;
+
+ //RestoreParser(olddata); - moved below
+
+ parser_current_file:=''; //here???
+ { Close script }
+ if (not AsmRes.Empty) then
+ begin
+ Message1(exec_i_closing_script,AsmRes.Fn);
+ AsmRes.WriteToDisk;
+ end;
+ end;
+
+ { free now what we did not free earlier in
+ proc_program PM }
+ if needsymbolinfo then
+ begin
+ hp:=tmodule(loaded_units.first);
+ while assigned(hp) do
+ begin
+ hp2:=tmodule(hp.next);
+ if (hp<>current_module) then
+ begin
+ loaded_units.remove(hp);
+ hp.free;
+ end;
+ hp:=hp2;
+ end;
+ { free also unneeded units we didn't free before }
+ unloaded_units.Clear;
+ end;
+ {$ENDIF}
end;
end.
diff --git a/NoGlobals/compiler/pmodules.pas b/NoGlobals/compiler/pmodules.pas
index dc8770c3b9..b1204f2785 100644
--- a/NoGlobals/compiler/pmodules.pas
+++ b/NoGlobals/compiler/pmodules.pas
@@ -620,14 +620,8 @@ implementation
begin
{ we are going to rebuild the symtablestack, clear it first }
symtablestack.clear;
- {$IFDEF old}
- macrosymtablestack.clear;
-
{ macro symtable }
- macrosymtablestack.push(initialmacrosymtable);
- {$ELSE}
macrosymtablestack.Init;
- {$ENDIF}
{ are we compiling the system unit? }
if (cs_compilesystem in current_settings^.moduleswitches) then
diff --git a/NoGlobals/compiler/symbase.pas b/NoGlobals/compiler/symbase.pas
index bb6e743e9b..19a47f67d4 100644
--- a/NoGlobals/compiler/symbase.pas
+++ b/NoGlobals/compiler/symbase.pas
@@ -131,19 +131,11 @@ interface
function top:TSymtable;
end;
-
-{$IFDEF old}
- var
- initialmacrosymtable: TSymtable; { macros initially defined by the compiler or
- given on the command line. Is common
- for all files compiled and do not change. }
- macrosymtablestack : TSymtablestack;
-{$ELSE}
type
eMacroStack = (
- msNone, //nil
+ msNone, //nil
msInitial, //InitialMacroStack
- msModule
+ msModule //from module
);
{ TMacroStack }
@@ -153,20 +145,18 @@ interface
constructor Create;
destructor Destroy; override;
procedure Init; //push InitialMacroSymTable
- //class procedure InsertSystemMacro(mac: TSymEntry);
end;
var
WhichMs: eMacroStack;
- function macrosymtablestack : TMacroStack;
+ function symtablestack : TSymtablestack;
+ function macrosymtablestack : TMacroStack;
- procedure InitMacros;
- procedure DoneMacros;
- procedure InsertSystemMacro(mac: TSymEntry);
-{$ENDIF}
+ procedure InitMacros;
+ procedure DoneMacros;
+ procedure InsertSystemMacro(mac: TSymEntry);
- function symtablestack : TSymtablestack;
{$ifdef MEMDEBUG}
var
diff --git a/NoGlobals/compiler/symtable.pas b/NoGlobals/compiler/symtable.pas
index aa1b3b51d2..f5d1336e5d 100644
--- a/NoGlobals/compiler/symtable.pas
+++ b/NoGlobals/compiler/symtable.pas
@@ -2485,14 +2485,7 @@ implementation
if not assigned(mac) then
begin
mac:=tmacro.create(s);
- {$IFDEF old}
- if assigned(current_module) then
- current_module.localmacrosymtable.insert(mac)
- else
- initialmacrosymtable.insert(mac);
- {$ELSE}
InsertSystemMacro(mac);
- {$ENDIF}
end;
if not mac.defined then
Message1(parser_c_macro_defined,mac.name);
@@ -2512,14 +2505,7 @@ implementation
if not assigned(mac) then
begin
mac:=tmacro.create(s);
- {$IFDEF old}
- if assigned(current_module) then
- current_module.localmacrosymtable.insert(mac)
- else
- initialmacrosymtable.insert(mac);
- {$ELSE}
InsertSystemMacro(mac);
- {$ENDIF}
end
else
begin
@@ -2548,14 +2534,7 @@ implementation
begin
mac:=tmacro.create(s);
mac.is_compiler_var:=true;
- {$IFDEF old}
- if assigned(current_module) then
- current_module.localmacrosymtable.insert(mac)
- else
- initialmacrosymtable.insert(mac);
- {$ELSE}
InsertSystemMacro(mac);
- {$ENDIF}
end
else
begin
@@ -2666,13 +2645,7 @@ implementation
generrorsym:=terrorsym.create;
generrordef:=terrordef.create;
{ macros }
- {$IFDEF old}
- initialmacrosymtable:=tmacrosymtable.create(false);
- macrosymtablestack:=TSymtablestack.create;
- macrosymtablestack.push(initialmacrosymtable);
- {$ELSE}
InitMacros;
- {$ENDIF}
{$ifdef UNITALIASES}
{ unit aliases }
unitaliases:=TFPHashObjectList.create;
@@ -2691,13 +2664,7 @@ implementation
generrorsym.free;
generrordef.owner:=nil;
generrordef.free;
- {$IFDEF old}
- WhichMs:=msNone;
- initialmacrosymtable.free;
- macrosymtablestack.free;
- {$ELSE}
DoneMacros;
- {$ENDIF}
{$ifdef UNITALIASES}
unitaliases.free;
{$endif}