Explorar o código

+ compile time variables can be given on the command line

git-svn-id: trunk@923 -
olle %!s(int64=20) %!d(string=hai) anos
pai
achega
2a5e6d7b92
Modificáronse 2 ficheiros con 39 adicións e 2 borrados
  1. 7 2
      compiler/options.pas
  2. 32 0
      compiler/symtable.pas

+ 7 - 2
compiler/options.pas

@@ -603,8 +603,13 @@ begin
 
            'd' :
              if more <> '' then
-               def_system_macro(more);
-
+               begin
+                 l:=Pos(':=',more);
+                 if l>0 then
+                   set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))                  
+                 else
+                   def_system_macro(more);
+               end;
            'D' :
              begin
                include(initglobalswitches,cs_link_deffile);

+ 32 - 0
compiler/symtable.pas

@@ -227,6 +227,7 @@ interface
     {Name can be given in any case (it will be converted to upper case).}
     procedure def_system_macro(const name : string);
     procedure set_system_macro(const name, value : string);
+    procedure set_system_compvar(const name, value : string);
     procedure undef_system_macro(const name : string);
 
 {*** symtable stack ***}
@@ -2321,6 +2322,37 @@ implementation
          mac.defined:=true;
       end;
 
+    procedure set_system_compvar(const name, value : string);
+      var
+        mac : tmacro;
+        s: string;
+      begin
+        if name = '' then
+          internalerror(2004121201);
+         s:= upper(name);
+         mac:=tmacro(search_macro(s));
+         if not assigned(mac) then
+           begin
+             mac:=tmacro.create(s);
+             mac.is_compiler_var:=true;
+             if macrosymtablestack.symtabletype=localmacrosymtable then
+               macrosymtablestack.insert(mac)
+             else
+               macrosymtablestack.next.insert(mac)
+           end
+         else
+           begin
+             mac.is_compiler_var:=true;
+             if assigned(mac.buftext) then
+               freemem(mac.buftext,mac.buflen);
+           end;
+         Message2(parser_c_macro_set_to,mac.name,value);
+         mac.buflen:=length(value);
+         getmem(mac.buftext,mac.buflen);
+         move(value[1],mac.buftext^,mac.buflen);
+         mac.defined:=true;
+      end;
+
     procedure undef_system_macro(const name : string);
       var
         mac : tmacro;