Просмотр исходного кода

+ add an overload to arrayconstructor_to_set that allows it to be used without the passed in node being freed

git-svn-id: trunk@36094 -
svenbarth 8 лет назад
Родитель
Сommit
6e31a7ac83
1 измененных файлов с 15 добавлено и 10 удалено
  1. 15 10
      compiler/ncnv.pas

+ 15 - 10
compiler/ncnv.pas

@@ -286,7 +286,8 @@ interface
     procedure inserttypeconv(var p:tnode;def:tdef);
     procedure inserttypeconv(var p:tnode;def:tdef);
     procedure inserttypeconv_explicit(var p:tnode;def:tdef);
     procedure inserttypeconv_explicit(var p:tnode;def:tdef);
     procedure inserttypeconv_internal(var p:tnode;def:tdef);
     procedure inserttypeconv_internal(var p:tnode;def:tdef);
-    procedure arrayconstructor_to_set(var p : tnode);
+    procedure arrayconstructor_to_set(var p : tnode);inline;
+    function arrayconstructor_to_set(p:tnode;freep:boolean):tnode;
     function arrayconstructor_can_be_set(p:tnode):boolean;
     function arrayconstructor_can_be_set(p:tnode):boolean;
     procedure insert_varargstypeconv(var p : tnode; iscvarargs: boolean);
     procedure insert_varargstypeconv(var p : tnode; iscvarargs: boolean);
 
 
@@ -380,10 +381,14 @@ implementation
 *****************************************************************************}
 *****************************************************************************}
 
 
     procedure arrayconstructor_to_set(var p : tnode);
     procedure arrayconstructor_to_set(var p : tnode);
+      begin
+        p:=arrayconstructor_to_set(p,true);
+      end;
 
 
+
+    function arrayconstructor_to_set(p:tnode;freep:boolean):tnode;
       var
       var
         constp      : tsetconstnode;
         constp      : tsetconstnode;
-        buildp,
         p2,p3,p4    : tnode;
         p2,p3,p4    : tnode;
         hdef        : tdef;
         hdef        : tdef;
         constset    : Pconstset;
         constset    : Pconstset;
@@ -478,7 +483,7 @@ implementation
         constsethi:=0;
         constsethi:=0;
         constp:=csetconstnode.create(nil,hdef);
         constp:=csetconstnode.create(nil,hdef);
         constp.value_set:=constset;
         constp.value_set:=constset;
-        buildp:=constp;
+        result:=constp;
         hp:=tarrayconstructornode(p);
         hp:=tarrayconstructornode(p);
         if assigned(hp.left) then
         if assigned(hp.left) then
          begin
          begin
@@ -617,7 +622,7 @@ implementation
                           Message(parser_e_illegal_expression)
                           Message(parser_e_illegal_expression)
                         { if we've already set elements which are constants }
                         { if we've already set elements which are constants }
                         { throw an error                                    }
                         { throw an error                                    }
-                        else if ((hdef=nil) and assigned(buildp)) or
+                        else if ((hdef=nil) and assigned(result)) or
                           not(is_char(hdef)) then
                           not(is_char(hdef)) then
                           CGMessage(type_e_typeconflict_in_set)
                           CGMessage(type_e_typeconflict_in_set)
                         else
                         else
@@ -633,12 +638,13 @@ implementation
               end;
               end;
               { insert the set creation tree }
               { insert the set creation tree }
               if assigned(p4) then
               if assigned(p4) then
-               buildp:=caddnode.create(addn,buildp,p4);
+               result:=caddnode.create(addn,result,p4);
               { load next and dispose current node }
               { load next and dispose current node }
               p2:=hp;
               p2:=hp;
               hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
               hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
               tarrayconstructornode(p2).right:=nil;
               tarrayconstructornode(p2).right:=nil;
-              p2.free;
+              if freep then
+                p2.free;
               current_filepos:=oldfilepos;
               current_filepos:=oldfilepos;
             end;
             end;
            if (hdef=nil) then
            if (hdef=nil) then
@@ -647,14 +653,13 @@ implementation
         else
         else
          begin
          begin
            { empty set [], only remove node }
            { empty set [], only remove node }
-           p.free;
+           if freep then
+             p.free;
          end;
          end;
         { set the initial set type }
         { set the initial set type }
         constp.resultdef:=csetdef.create(hdef,constsetlo.svalue,constsethi.svalue,true);
         constp.resultdef:=csetdef.create(hdef,constsetlo.svalue,constsethi.svalue,true);
         { determine the resultdef for the tree }
         { determine the resultdef for the tree }
-        typecheckpass(buildp);
-        { set the new tree }
-        p:=buildp;
+        typecheckpass(result);
       end;
       end;