Răsfoiți Sursa

* Added new node utility function to search for nodes of a specific type in a node tree

J. Gareth "Curious Kit" Moreton 1 an în urmă
părinte
comite
a91c1ab627
1 a modificat fișierele cu 18 adăugiri și 0 ștergeri
  1. 18 0
      compiler/nutils.pas

+ 18 - 0
compiler/nutils.pas

@@ -210,6 +210,10 @@ interface
     }
     procedure node_reset_pass1_write(n: tnode);
 
+    { Returns True if n one of its children has a type that appears in TypeList }
+    function has_node_of_type(n: TNode; TypeList: TNodeTypeSet): Boolean; {$IFDEF USEINLINE}inline;{$ENDIF USEINLINE}
+
+
 implementation
 
     uses
@@ -1760,4 +1764,18 @@ implementation
        end;
 
 
+     function node_in_list(var n: tnode; arg: pointer): foreachnoderesult;
+       begin
+         if (n.nodetype in PNodeTypeSet(arg)^) then
+           result := fen_norecurse_true
+         else
+           result := fen_false;
+       end;
+
+
+     function has_node_of_type(n: TNode; TypeList: TNodeTypeSet): Boolean;
+       begin
+         Result := foreachnodestatic(n, @node_in_list, @TypeList);
+       end;
+
 end.