[llvm-commits] [hlvm] r38049 - in /hlvm/trunk/hlvm/AST: AST.cpp AST.h Block.h Bundle.cpp Bundle.h ContainerType.h Function.h LinkageItem.h Location.h Locator.h Node.cpp Node.h Operator.h Program.cpp Program.h Type.h Variable.h

Reid Spencer reid at x10sys.com
Sat Jul 7 16:59:18 PDT 2007


Author: reid
Date: Sat Jul  7 18:59:18 2007
New Revision: 38049

URL: http://llvm.org/viewvc/llvm-project?rev=38049&view=rev
Log:
Make instantiation lightweight so that only the node id is required.
Other data must be set by calling methods after instantiation. Also,
start adding support for Factory methods.

Added:
    hlvm/trunk/hlvm/AST/Locator.h
Removed:
    hlvm/trunk/hlvm/AST/Location.h
Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Block.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/Function.h
    hlvm/trunk/hlvm/AST/LinkageItem.h
    hlvm/trunk/hlvm/AST/Node.cpp
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Operator.h
    hlvm/trunk/hlvm/AST/Program.cpp
    hlvm/trunk/hlvm/AST/Program.h
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/AST/Variable.h

Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 18:59:18 2007
@@ -28,8 +28,16 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/AST.h>
+#include <hlvm/AST/Bundle.h>
 
 namespace hlvm {
 namespace AST {
 
+Bundle*
+AST::new_Bundle(const Locator& loc, const std::string& id)
+{
+  Bundle* result = Bundle::create(loc,id);
+  return result;
+}
+
 }}

Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 18:59:18 2007
@@ -30,6 +30,8 @@
 #ifndef HLVM_AST_AST_H
 #define HLVM_AST_AST_H
 
+#include <string>
+
 /// This namespace is for all HLVM software. It ensures that HLVM software does
 /// not collide with any other software. Hopefully HLVM is not a namespace used
 /// elsewhere. 
@@ -40,6 +42,7 @@
 namespace AST
 {
   class Bundle;
+  class Locator;
 
   /// This class is used to hold or contain an Abstract Syntax Tree. It provides
   /// those aspects of the tree that are not part of the tree itself.
@@ -49,19 +52,36 @@
     /// @name Constructors
     /// @{
     public:
-      AST() : tree_(0) {}
+      AST() : sysid(), pubid(), root(0) {}
 
     /// @}
     /// @name Accessors
     /// @{
     public:
-      Bundle* getBundle() { return tree_; }
+      const std::string& getSystemID() { return sysid; }
+      const std::string& getPublicID() { return pubid; }
+      Bundle* getRoot() { return root; }
+
+    /// @}
+    /// @name Mutators
+    /// @{
+    public:
+      void setSystemID(const std::string& id) { sysid = id; }
+      void setPublicID(const std::string& id) { pubid = id; }
+      void setRoot(Bundle* top) { root = top; }
+    /// @}
+    /// @name Factories
+    /// @{
+    public:
+      static Bundle* new_Bundle(const Locator& loc, const std::string& id);
 
     /// @}
     /// @name Data
     /// @{
     protected:
-      Bundle* tree_;
+      std::string sysid;
+      std::string pubid;
+      Bundle* root;
     /// @}
   };
 } // AST

Modified: hlvm/trunk/hlvm/AST/Block.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul  7 18:59:18 2007
@@ -43,15 +43,12 @@
   /// contained in a Bundle. Local variables are always contained in a
   /// Function.
   /// @brief HLVM AST Variable Node
-  class Block : public Node
+  class Block : public ParentNode
   {
     /// @name Constructors
     /// @{
     public:
-      Block(
-        Node* parent, ///< The bundle or function that defines the ariable 
-        const std::string& name ///< The name of the variable
-      ) : Node(BlockID,parent,name) {}
+      Block() : ParentNode(BlockID), ops_() {}
       virtual ~Block();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/Bundle.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.cpp?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 18:59:18 2007
@@ -36,4 +36,13 @@
 {
 }
 
+Bundle*
+Bundle::create(const Locator& loc, const std::string& id)
+{
+  Bundle* result = new Bundle();
+  result->setLocator(loc);
+  result->setName(id);
+  return result;
+}
+
 }}

Modified: hlvm/trunk/hlvm/AST/Bundle.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 18:59:18 2007
@@ -40,15 +40,15 @@
   /// a Bundle. Bundles can also be nested in other Bundles. All programming
   /// constructs are defined as child nodes of some Bundle.
   /// @brief HLVM AST Bundle Node
-  class Bundle : public Node
+  class Bundle : public ParentNode
   {
     /// @name Constructors
     /// @{
     public:
-      Bundle(
-        Bundle* parent,         ///< The bundle to which this bundle belongs
-        const std::string& name ///< The name of this bundle
-      ) : Node(BundleID,parent,name) {}
+      static Bundle* create(const Locator& location, const std::string& pubid);
+
+    protected:
+      Bundle() : ParentNode(BundleID) {}
       virtual ~Bundle();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 18:59:18 2007
@@ -20,11 +20,11 @@
 // MA 02110-1301 USA
 //
 //===----------------------------------------------------------------------===//
-/// @file hlvm/AST/Type.h
+/// @file hlvm/AST/ContainerType.h
 /// @author Reid Spencer <reid at hlvm.org> (original author)
 /// @date 2006/05/04
 /// @since 0.1.0
-/// @brief Declares the class hlvm::AST::Type
+/// @brief Declares the class hlvm::AST::ContainerType
 //===----------------------------------------------------------------------===//
 
 #ifndef HLVM_AST_CONTAINERTYPE_H
@@ -43,10 +43,8 @@
     /// @{
     public:
       ContainerType(
-        NodeIDs id, ///< The node id of the subclass
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : Type(id,parent,name) {}
+        NodeIDs id ///< The node id of the subclass
+      ) : Type(id) {}
       virtual ~ContainerType();
 
     /// @}
@@ -72,10 +70,7 @@
     /// @name Constructors
     /// @{
     public:
-      PointerType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : ContainerType(PointerTypeID,parent,name) {}
+      PointerType() : ContainerType(PointerTypeID) {}
       virtual ~PointerType();
 
     /// @}
@@ -85,6 +80,7 @@
       // Methods to support type inquiry via is, cast, dyn_cast
       static inline bool classof(const PointerType*) { return true; }
       static inline bool classof(const Type* T) { return T->isPointerType(); }
+
     /// @}
     /// @name Data
     /// @{
@@ -99,10 +95,7 @@
     /// @name Constructors
     /// @{
     public:
-      ArrayType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : ContainerType(ArrayTypeID,parent,name) {}
+      ArrayType() : ContainerType(ArrayTypeID) {}
       virtual ~ArrayType();
 
     /// @}
@@ -128,10 +121,7 @@
     /// @name Constructors
     /// @{
     public:
-      VectorType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : ContainerType(VectorTypeID,parent,name) {}
+      VectorType() : ContainerType(VectorTypeID) {}
       virtual ~VectorType();
 
     /// @}
@@ -155,10 +145,7 @@
     /// @name Constructors
     /// @{
     public:
-      StructureType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : ContainerType(StructureTypeID,parent,name) {}
+      StructureType() : ContainerType(StructureTypeID) {}
       virtual ~StructureType();
 
     /// @}
@@ -182,10 +169,7 @@
     /// @name Constructors
     /// @{
     public:
-      SignatureType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : ContainerType(SignatureTypeID,parent,name) {}
+      SignatureType() : ContainerType(SignatureTypeID) {}
       virtual ~SignatureType();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/Function.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Function.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul  7 18:59:18 2007
@@ -52,26 +52,30 @@
     /// @{
     public:
       Function(
-        SignatureType* sig, ///< The function signature
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name, ///< The name of the function
         NodeIDs id = FunctionID
-      ) : LinkageItem(id,parent,name), block_(0), signature_(sig) {}
+      ) : LinkageItem(id), block(0), signature(0) {}
       virtual ~Function();
 
     /// @}
     /// @name Accessors
     /// @{
     public:
+      Block* getBlock() { return block; }
+      SignatureType* getSignature() { return signature; }
       static inline bool classof(const Function*) { return true; }
       static inline bool classof(const Node* N) { return N->isFunction(); }
 
     /// @}
+    /// @name Mutators
+    /// @{
+    public:
+      void setSignature(SignatureType* SigTy) { signature = SigTy; }
+    /// @}
     /// @name Data
     /// @{
     protected:
-      Block * block_;                   ///< The code block to be executed
-      SignatureType* signature_;        ///< The function signature.
+      Block * block;                   ///< The code block to be executed
+      SignatureType* signature;        ///< The function signature.
     /// @}
   };
 } // AST

Modified: hlvm/trunk/hlvm/AST/LinkageItem.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItem.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul  7 18:59:18 2007
@@ -51,16 +51,14 @@
   /// elsewhere and linked into another bundle to resolve the reference. The
   /// LinkageItem declares what kind of linkage is to be performed.
   /// @brief HLVM AST Bundle Node
-  class LinkageItem : public Node
+  class LinkageItem : public ParentNode
   {
     /// @name Constructors
     /// @{
     public:
       LinkageItem(
-        NodeIDs id, ///< Subclass's node identifier
-        Node* parent, ///< The Bundle to which this bundle belongs, or null
-        const std::string& name ///< The name of the bundle
-      ) : Node(id,parent,name) {}
+        NodeIDs id ///< Subclass's node identifier
+      ) : ParentNode(id) {}
       virtual ~LinkageItem();
 
     /// @}

Removed: hlvm/trunk/hlvm/AST/Location.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Location.h?rev=38048&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/Location.h (original)
+++ hlvm/trunk/hlvm/AST/Location.h (removed)
@@ -1,67 +0,0 @@
-//===-- hlvm/AST/Location.h - AST Location Class ----------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/AST/Location.h
-/// @author Reid Spencer <reid at hlvm.org> (original author)
-/// @date 2006/05/04
-/// @since 0.1.0
-/// @brief Declares the class hlvm::AST::Location
-//===----------------------------------------------------------------------===//
-
-#ifndef HLVM_AST_LOCATION_H
-#define HLVM_AST_LOCATION_H
-
-#include <string>
-
-namespace hlvm {
-namespace AST {
-
-  /// This class is used to hold a source code location as a filename, line
-  /// number and column number. This is used for generating error messages and
-  /// for debugging support.
-  /// @brief Source location holder class.
-  class Location
-  {
-    /// @name Constructors
-    /// @{
-    public:
-      Location(uint32_t line, uint32_t col, const std::string& fname)
-        : line_(line), col_(col), fname_(fname)  {}
-      Location() : line_(0), col_(0), fname_("") {}
-
-    /// @}
-    /// @name Accessors
-    /// @{
-    public:
-
-    /// @}
-    /// @name Data
-    /// @{
-    protected:
-      uint32_t line_;           ///< Line number of source location
-      uint32_t col_;            ///< Column number of source location
-      std::string fname_;       ///< File name of source location
-    /// @}
-  };
-} // AST
-} // hlvm
-#endif

Added: hlvm/trunk/hlvm/AST/Locator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Locator.h?rev=38049&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/Locator.h (added)
+++ hlvm/trunk/hlvm/AST/Locator.h Sat Jul  7 18:59:18 2007
@@ -0,0 +1,67 @@
+//===-- hlvm/AST/Locator.h - AST Location Class -----------------*- C++ -*-===//
+//
+//                      High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software is free software; you can redistribute it and/or modify it 
+// under the terms of the GNU Lesser General Public License as published by 
+// the Free Software Foundation; either version 2.1 of the License, or (at 
+// your option) any later version.
+//
+// This software is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
+// more details.
+//
+// You should have received a copy of the GNU Lesser General Public License 
+// along with this library in the file named LICENSE.txt; if not, write to the 
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/AST/Locator.h
+/// @author Reid Spencer <reid at hlvm.org> (original author)
+/// @date 2006/05/04
+/// @since 0.1.0
+/// @brief Declares the class hlvm::AST::Locator
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_AST_LOCATOR_H
+#define HLVM_AST_LOCATOR_H
+
+#include <string>
+
+namespace hlvm {
+namespace AST {
+
+  /// This class is used to hold a source code location as a filename, line
+  /// number and column number. This is used for generating error messages and
+  /// for debugging support.
+  /// @brief Source location holder class.
+  class Locator
+  {
+    /// @name Constructors
+    /// @{
+    public:
+      Locator(uint32_t line, uint32_t col, const std::string* fname)
+        : line_(line), col_(col), fname_(fname) {}
+      Locator() : line_(0), col_(0), fname_(0) {}
+
+    /// @}
+    /// @name Accessors
+    /// @{
+    public:
+
+    /// @}
+    /// @name Data
+    /// @{
+    protected:
+      uint32_t line_;           ///< Line number of source location
+      uint32_t col_;            ///< Column number of source location
+      const std::string* fname_;///< File name of source location
+    /// @}
+  };
+} // AST
+} // hlvm
+#endif

Modified: hlvm/trunk/hlvm/AST/Node.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.cpp?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul  7 18:59:18 2007
@@ -31,14 +31,13 @@
 
 namespace hlvm { namespace AST {
 
-Node::Node(NodeIDs id, Node* parent, const std::string& name)
-  : id_(id), parent_(parent), kids_(), name_(name)
+Node::~Node()
 {
+  removeFromTree();
 }
 
-Node::~Node()
+ParentNode::~ParentNode()
 {
-  removeFromTree();
 }
 
 void
@@ -46,11 +45,24 @@
 {
 }
 
+void
+Node::setParent(ParentNode* p)
+{
+  parent = p;
+  p->addChild(this);
+}
+
 #ifndef _NDEBUG
 void 
-hlvm::AST::Node::dump() const 
+Node::dump() const 
 {
 }
 #endif
 
+void
+ParentNode::addChild(Node* n)
+{
+  kids.push_back(n);
+}
+
 }}

Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 18:59:18 2007
@@ -31,16 +31,21 @@
 #define HLVM_AST_NODE_H
 
 #include <llvm/Support/Casting.h>
-#include <hlvm/AST/Location.h>
+#include <hlvm/AST/Locator.h>
 #include <vector>
 
 namespace hlvm {
 namespace AST {
 
-  /// This enumeration is used to identify a specific type
+  /// This enumeration is used to identify a specific type. Its organization is
+  /// very specific and dependent on the class hierarchy. In order to use these
+  /// values as ranges for class identification (classof methods), we need to 
+  /// group things by inheritance rather than by function. In particular the
+  /// ParentNode group needs to be distinguished.
   enum NodeIDs {
-    // Primitive Types
-    VoidTypeID = 0,     ///< The Void Type (The Null Type)
+    NoTypeID = 0,       ///< Use this for an invalid type ID.
+    // Primitive Types (no child nodes)
+    VoidTypeID = 1,     ///< The Void Type (The Null Type)
     AnyTypeID,          ///< The Any Type (Union of any type)
     BooleanTypeID,      ///< The Boolean Type (A simple on/off boolean value)
     CharacterTypeID,    ///< The Character Type (UTF-16 encoded character)
@@ -70,11 +75,11 @@
     // Linkage Items
     VariableID,         ///< The Variable Node (a storage location)
     FunctionID,         ///< The Function Node (a callable function)
-    ProgramID,          ///< The Program Node (a
+    ProgramID,          ///< The Program Node (a program starting point)
 
     // Container
     BundleID,           ///< The Bundle Node (a group of other declarations)
-    BlockID,            ///< A Block Of Code Node
+    BlockID,            ///< A Block Of Code Nodes
 
     // Control Flow And Invocation Operators
     CallOpID,           ///< The Call Operator
@@ -154,6 +159,14 @@
     MungeOpID,          ///< General Purpose String Editing Operator
     LengthOpID,         ///< Extract Length of a String Operator
 
+    // Input/Output Operators
+    MapFileOpID,        ///< Map a file to memory (mmap)
+    OpenOpID,           ///< Open a stream from a URL
+    CloseOpID,          ///< Close a stream previously opened.
+    ReadOpID,           ///< Read from a stream
+    WriteOpID,          ///< Write to a stream
+    PositionOpID,       ///< Position a stream
+
     // Constant Value Operators
     IntOpID,            ///< Constant Integer Value
     RealOpID,           ///< Constant Real Value
@@ -165,14 +178,6 @@
     VectorOpID,         ///< Constant Vector Value
     StructureOpID,      ///< Constant Structure Value
 
-    // Input/Output Operators
-    MapFileOpID,        ///< Map a file to memory (mmap)
-    OpenOpID,           ///< Open a stream from a URL
-    CloseOpID,          ///< Close a stream previously opened.
-    ReadOpID,           ///< Read from a stream
-    WriteOpID,          ///< Write to a stream
-    PositionOpID,       ///< Position a stream
-
     // Enumeration Ranges and Limits
     NumNodeIDs,         ///< The number of node identifiers in the enum
     FirstPrimitiveTypeID = VoidTypeID, ///< First Primitive Type
@@ -180,14 +185,12 @@
     FirstContainerTypeID = PointerTypeID, ///< First Container Type
     LastContainerTypeID  = ContinuationTypeID, ///< Last Container Type
     FirstOperatorID = CallOpID, ///< First Operator
-    LastOperatorID =  StructureOpID ///< Last Operator
+    LastOperatorID =  StructureOpID, ///< Last Operator
+    FirstParentNodeID = PointerTypeID,
+    LastParentNodeID = PositionOpID
   };
 
-  class Type;
-
-  /// A NamedType is simply a pair involving a name and a pointer to a Type.
-  /// This is so frequently needed, it is declared here for convenience.
-  typedef std::pair<std::string,Type*> NamedType;
+  class ParentNode;
 
   /// This class is the base class of HLVM Abstract Syntax Tree (AST). All 
   /// other AST nodes are subclasses of this class.
@@ -196,12 +199,9 @@
   {
     /// @name Constructors
     /// @{
+    protected:
+      Node(NodeIDs ID) : id(ID), parent(0), loc() {}
     public:
-      Node(NodeIDs id, Node* parent = 0, const std::string& name = ""); 
-
-#ifndef _NDEBUG
-      virtual void dump() const;
-#endif
       virtual ~Node();
 
     /// @}
@@ -209,29 +209,42 @@
     /// @{
     public:
       /// Get the type of node
-      inline NodeIDs getID() const { return id_; }
+      inline NodeIDs getID() const { return NodeIDs(id); }
 
-      /// Get the name of the node
-      inline const std::string& getName() { return name_; }
+      /// Get the parent node
+      inline Node* getParent() const { return parent; }
+
+      /// Get the flags
+      inline unsigned getFlags() const { return flags; }
+
+      /// Get the Locator
+      inline const Locator& getLocator() const { return loc; }
 
       /// Determine if the node is a Type
-      inline bool isType() const { 
-        return id_ >= FirstPrimitiveTypeID && id_ <= LastContainerTypeID;
+      inline bool isType() const {
+        return id >= FirstPrimitiveTypeID && id <= LastPrimitiveTypeID;
       }
       /// Determine if the node is any of the Operators
       inline bool isOperator() const { 
-        return id_ >= FirstOperatorID && id_ <= LastOperatorID;
+        return id >= FirstOperatorID && id <= LastOperatorID;
       }
+
+      /// Determine if the node is a ParentNode
+      inline bool isParentNode() const {
+        return id >= FirstParentNodeID && id <= LastParentNodeID;
+      }
+
       /// Determine if the node is a Block
-      inline bool isBlock() const { return id_ == BlockID; }
+      inline bool isBlock() const { return id == BlockID; }
       /// Determine if the node is a Bundle
-      inline bool isBundle() const { return id_ == BundleID; }
+      inline bool isBundle() const { return id == BundleID; }
       /// Determine if the node is a Function
-      inline bool isFunction() const { return id_ == FunctionID; }
+      inline bool isFunction() const { return id == FunctionID; }
       /// Determine if the node is a Program
-      inline bool isProgram() const { return id_ == ProgramID; }
+      inline bool isProgram() const { return id == ProgramID; }
       /// Determine if the node is a Variable
-      inline bool isVariable() const { return id_ == VariableID; }
+      inline bool isVariable() const { return id == VariableID; }
+
       /// Provide support for isa<X> and friends
       static inline bool classof(const Node*) { return true; }
 
@@ -239,18 +252,76 @@
     /// @name Mutators
     /// @{
     protected:
-      void removeFromTree();
+      virtual void removeFromTree();
+      virtual void setParent(ParentNode *n);
+      void setLocator(const Locator& l) { loc = l; }
+      void setFlags(unsigned f) {
+        assert(f < 1 << 24 && "Flags out of range");
+        flags = f;
+      }
 
+    /// @}
+    /// @name Utilities
+    /// @{
+    public:
+#ifndef _NDEBUG
+      virtual void dump() const;
+#endif
+
+    /// @}
+    /// @name Data
+    /// @{
+    protected:
+      unsigned id : 8;         ///< Really a value in NodeIDs
+      unsigned flags : 24;     ///< 24 boolean flags, subclass dependent interp.
+      Node* parent;            ///< The node that owns this node.
+      Locator loc;             ///< The source location corresponding to node.
+    /// @}
+  };
+
+  class ParentNode : public Node {
+    /// @name Types
+    /// @{
+    public:
+      typedef std::vector<Node*> NodeList;
+      typedef NodeList::iterator iterator;
+      typedef NodeList::const_iterator const_iterator;
+
+    /// @}
+    /// @name Constructors
+    /// @{
+    protected:
+      ParentNode(NodeIDs id) 
+        : Node(id), name(), kids() {}
+    public:
+      virtual ~ParentNode();
+
+    /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      /// Get the name of the node
+      inline const std::string& getName() { return name; }
+
+      /// Determine if the node has child nodes
+      inline bool hasKids() const { return !kids.empty(); }
+
+      static inline bool classof(const ParentNode*) { return true; }
+      static inline bool classof(const Node* N) { return N->isParentNode(); }
+
+    /// @}
+    /// @name Mutators
+    /// @{
+    public:
+      void setName(const std::string& n) { name = n; }
+      virtual void addChild(Node* n);
 
     /// @}
     /// @name Data
     /// @{
     protected:
-      NodeIDs id_;              ///< Identification of the node kind.
-      Node* parent_;            ///< The node that owns this node.
-      std::vector<Node> kids_;  ///< The vector of children nodes.
-      std::string name_;        ///< The name of this node.
-      Location loc_;            ///< The source location corresponding to node.
+      std::string name;  ///< The name of this node.
+      NodeList    kids;  ///< The vector of children nodes.
     /// @}
   };
 } // AST

Modified: hlvm/trunk/hlvm/AST/Operator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Operator.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul  7 18:59:18 2007
@@ -49,10 +49,8 @@
     /// @{
     public:
       Operator(
-        NodeIDs opID, ///< The Operator ID for this operator kind
-        Node* parent, ///< The bundle or function that defines the ariable 
-        const std::string& name ///< The name of the variable
-      ) : Node(opID,parent,name) {}
+        NodeIDs opID ///< The Operator ID for this operator kind
+      ) : Node(opID), Operands() {}
       virtual ~Operator();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Program.cpp?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.cpp (original)
+++ hlvm/trunk/hlvm/AST/Program.cpp Sat Jul  7 18:59:18 2007
@@ -34,7 +34,8 @@
 namespace AST {
 
 SignatureType* Program::initSignature() {
-  SignatureType* result = new SignatureType(0,"_hlvm_ProgramSignature");
+  SignatureType* result = new SignatureType();
+  result->setName("_hlvm_ProgramSignature");
   return result;
 }
 SignatureType* Program::SignatureTy = Program::initSignature();

Modified: hlvm/trunk/hlvm/AST/Program.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Program.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.h (original)
+++ hlvm/trunk/hlvm/AST/Program.h Sat Jul  7 18:59:18 2007
@@ -50,10 +50,7 @@
     /// @name Constructors
     /// @{
     public:
-      Program(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : Function(SignatureTy,parent,name,ProgramID) {}
+      Program() : Function(ProgramID) {}
       virtual ~Program();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 18:59:18 2007
@@ -38,37 +38,35 @@
   /// This class represents a Type in the HLVM Abstract Syntax Tree.  
   /// A Type defines the format of storage. 
   /// @brief HLVM AST Type Node
-  class Type : public Node
+  class Type : public ParentNode
   {
     /// @name Constructors
     /// @{
     public:
       Type(
-        NodeIDs id, ///< The Type identifier
-        Node* parent = 0, ///< The bundle in which the function is defined
-        const std::string& name = "" ///< The name of the function
-      ) : Node(id, parent, name)  {}
+        NodeIDs id ///< The Type identifier
+      ) : ParentNode(id )  {}
       virtual ~Type();
 
     /// @}
     /// @name Accessors
     /// @{
-      inline bool isPrimitiveType() const { return id_ <= LastPrimitiveTypeID; }
+      inline bool isPrimitiveType() const { return id <= LastPrimitiveTypeID; }
       inline bool isIntegralType()  const { 
-        return id_ == IntegerTypeID || id_ == RangeTypeID; 
+        return id == IntegerTypeID || id == RangeTypeID; 
       }
       inline bool isContainerType() const { 
-        return id_ >= FirstContainerTypeID; 
+        return id >= FirstContainerTypeID; 
       }
-      inline bool isIntegerType() const { return id_ == IntegerTypeID; }
-      inline bool isRangeType() const { return id_ == RangeTypeID; }
-      inline bool isRealType() const { return id_ == RealTypeID; }
-      inline bool isRationalType() const { return id_ == RationalTypeID; }
-      inline bool isPointerType() const { return id_ == PointerTypeID; }
-      inline bool isArrayType() const { return id_ == ArrayTypeID; }
-      inline bool isVectorType() const { return id_ == VectorTypeID; }
-      inline bool isStructureType() const { return id_ == StructureTypeID; }
-      inline bool isSignatureType() const { return id_ == SignatureTypeID; }
+      inline bool isIntegerType() const { return id == IntegerTypeID; }
+      inline bool isRangeType() const { return id == RangeTypeID; }
+      inline bool isRealType() const { return id == RealTypeID; }
+      inline bool isRationalType() const { return id == RationalTypeID; }
+      inline bool isPointerType() const { return id == PointerTypeID; }
+      inline bool isArrayType() const { return id == ArrayTypeID; }
+      inline bool isVectorType() const { return id == VectorTypeID; }
+      inline bool isStructureType() const { return id == StructureTypeID; }
+      inline bool isSignatureType() const { return id == SignatureTypeID; }
 
       // Methods to support type inquiry via is, cast, dyn_cast
       static inline bool classof(const Node*) { return true; }
@@ -81,6 +79,10 @@
     /// @}
   };
 
+  /// A NamedType is simply a pair involving a name and a pointer to a Type.
+  /// This is so frequently needed, it is declared here for convenience.
+  typedef std::pair<std::string,Type*> NamedType;
+
   /// This class represents all HLVM integer types. An integer type declares the
   /// the minimum number of bits that are required to store the integer type.
   /// HLVM will convert this specification to the most appropriate sized 
@@ -91,10 +93,7 @@
     /// @name Constructors
     /// @{
     public:
-      IntegerType(
-        Node* parent = 0, ///< The bundle in which the function is defined
-        const std::string& name = "" ///< The name of the function
-      ) : Type(IntegerTypeID,parent,name) {}
+      IntegerType() : Type(IntegerTypeID) {}
       virtual ~IntegerType();
 
     /// @}
@@ -121,10 +120,7 @@
     /// @name Constructors
     /// @{
     public:
-      RangeType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : Type(RangeTypeID,parent,name) {}
+      RangeType() : Type(RangeTypeID) {}
       virtual ~RangeType();
 
     /// @}
@@ -154,10 +150,7 @@
     /// @name Constructors
     /// @{
     public:
-      RealType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : Type(RealTypeID,parent,name) {}
+      RealType() : Type(RealTypeID) {}
       virtual ~RealType();
 
     /// @}

Modified: hlvm/trunk/hlvm/AST/Variable.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Variable.h?rev=38049&r1=38048&r2=38049&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.h (original)
+++ hlvm/trunk/hlvm/AST/Variable.h Sat Jul  7 18:59:18 2007
@@ -49,10 +49,7 @@
     /// @name Constructors
     /// @{
     public:
-      Variable(
-        Node* parent, ///< The bundle or function that defines the ariable 
-        const std::string& name ///< The name of the variable
-      ) : LinkageItem(VariableID,parent,name) {}
+      Variable() : LinkageItem(VariableID) {}
       virtual ~Variable();
 
     /// @}





More information about the llvm-commits mailing list