[llvm-commits] [hlvm] r37984 - in /hlvm/trunk/hlvm/AST: Bundle.h Conditionable.h ContainerType.h Function.h LinkageItem.h Node.cpp Node.h Type.h Variable.h

Reid Spencer reid at x10sys.com
Sat Jul 7 16:58:38 PDT 2007


Author: reid
Date: Sat Jul  7 18:58:38 2007
New Revision: 37984

URL: http://llvm.org/viewvc/llvm-project?rev=37984&view=rev
Log:
Add Conditionable class. Move the identifiers to Node and make all classes
support type queries with the "classof" methods.

Added:
    hlvm/trunk/hlvm/AST/Conditionable.h
Modified:
    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/Type.h
    hlvm/trunk/hlvm/AST/Variable.h

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 18:58:38 2007
@@ -44,10 +44,17 @@
       Bundle(
         Bundle* parent,         ///< The bundle to which this bundle belongs
         const std::string& name ///< The name of this bundle
-      ) : Node(parent,name) {}
+      ) : Node(BundleID,parent,name) {}
       virtual ~Bundle();
 
     /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      static inline bool classof(const Bundle*) { return true; }
+      static inline bool classof(const Node* N) { return N->isBundle(); }
+
+    /// @}
     /// @name Data
     /// @{
     protected:

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Conditionable.h (added)
+++ hlvm/trunk/hlvm/AST/Conditionable.h Sat Jul  7 18:58:38 2007
@@ -0,0 +1,60 @@
+//
+// Copyright (C) 2006 HLVM Group. All Rights Reserved.
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License (GPL) as published by
+// the Free Software Foundation; either version 2 of the License, or (at your
+// option) any later version. You should have received a copy of the GPL in a
+// file named COPYING that was included with this program; if not, you can
+// obtain a copy of the license through the Internet at http://www.fsf.org/
+//
+// This program 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 General Public License
+// for more details.
+//
+////////////////////////////////////////////////////////////////////////////////
+/// @file hlvm/AST/Conditionable.h
+/// @author Reid Spencer <reid at hlvm.org> (original author)
+/// @date 2006/05/04
+/// @since 0.1.0
+/// @brief Declares the class hlvm::AST::Conditionable
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef HLVM_AST_CONDITIONABLE_H
+#define HLVM_AST_CONDITIONABLE_H
+
+#include <hlvm/AST/Node.h>
+
+namespace hlvm {
+namespace AST {
+
+  /// This class represents an HLVM Bundle. A Bundle is simply a collection of
+  /// declarations and definitions. It is the root of the AST tree and also
+  /// the grouping and namespace construct in HLVM. Every compilation unit is
+  /// 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 Conditionable : public Node
+  {
+    /// @name Constructors
+    /// @{
+    public:
+      Conditionable(
+        NodeIDs id,
+        Node* parent, 
+        const std::string& name,
+        const std::string& condition_name) 
+      : Node(id,parent,name), cond_name_(condition_name) {}
+      virtual ~Conditionable();
+
+    /// @}
+    /// @name Data
+    /// @{
+    protected:
+      std::string cond_name_;
+    /// @}
+  };
+} // AST
+} // hlvm
+#endif

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 18:58:38 2007
@@ -37,10 +37,10 @@
     /// @{
     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
-        TypeIDs type_id
-      ) : Type(parent,name,type_id) {}
+        const std::string& name ///< The name of the function
+      ) : Type(id,parent,name) {}
       virtual ~ContainerType();
 
     /// @}
@@ -69,7 +69,7 @@
       PointerType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : ContainerType(parent,name,PointerTypeID) {}
+      ) : ContainerType(PointerTypeID,parent,name) {}
       virtual ~PointerType();
 
     /// @}
@@ -96,7 +96,7 @@
       ArrayType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : ContainerType(parent,name,ArrayTypeID) {}
+      ) : ContainerType(ArrayTypeID,parent,name) {}
       virtual ~ArrayType();
 
     /// @}
@@ -125,7 +125,7 @@
       VectorType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : ContainerType(parent,name,VectorTypeID) {}
+      ) : ContainerType(VectorTypeID,parent,name) {}
       virtual ~VectorType();
 
     /// @}
@@ -152,7 +152,7 @@
       StructureType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : ContainerType(parent,name,StructureTypeID) {}
+      ) : ContainerType(StructureTypeID,parent,name) {}
       virtual ~StructureType();
 
     /// @}
@@ -179,7 +179,7 @@
       SignatureType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : ContainerType(parent,name,SignatureTypeID) {}
+      ) : ContainerType(SignatureTypeID,parent,name) {}
       virtual ~SignatureType();
 
     /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul  7 18:58:38 2007
@@ -31,7 +31,7 @@
 namespace AST
 {
   class Block; // Forward declare
-  class Type;  // Forward declare
+  class SignatureType;  // Forward declare
 
   /// This class represents an Function in the HLVM Abstract Syntax Tree.  
   /// A Function is a callable block of code that accepts parameters and 
@@ -47,16 +47,22 @@
       Function(
         Bundle* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : LinkageItem(parent,name) {}
+      ) : LinkageItem(FunctionID,parent,name) {}
       virtual ~Function();
 
     /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      static inline bool classof(const Function*) { return true; }
+      static inline bool classof(const Node* N) { return N->isFunction(); }
+
+    /// @}
     /// @name Data
     /// @{
     protected:
       Block * block_;                   ///< The code block to be executed
-      Type* result_;                    ///< The type of the function's result
-      std::vector<NamedType> arguments_;///< The formal arguments 
+      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=37984&r1=37983&r2=37984&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul  7 18:58:38 2007
@@ -51,9 +51,10 @@
     /// @{
     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(parent,name) {}
+      ) : Node(id,parent,name) {}
       virtual ~LinkageItem();
 
     /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul  7 18:58:38 2007
@@ -22,16 +22,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 #include <hlvm/AST/Node.h>
+#include <hlvm/AST/Conditionable.h>
 #include <hlvm/AST/Type.h>
 #include <hlvm/AST/ContainerType.h>
 #include <hlvm/AST/Bundle.h>
 #include <hlvm/AST/Function.h>
 #include <hlvm/AST/Variable.h>
 
-namespace hlvm
-{
-namespace AST
-{
+namespace hlvm {
+namespace AST {
 
-}
-}
+}}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 18:58:38 2007
@@ -24,6 +24,7 @@
 #ifndef HLVM_AST_NODE_H
 #define HLVM_AST_NODE_H
 
+#include <llvm/Support/Casting.h>
 #include <vector>
 #include <string>
 
@@ -36,6 +37,34 @@
 /// node types of the AST are declared in this namespace.
 namespace AST
 {
+  /// This enumeration is used to identify a specific type
+  enum NodeIDs {
+    // Types
+    VoidTypeID = 0,     ///< The Void Type
+    IntegerTypeID,      ///< The Integer Type
+    RangeTypeID,        ///< The Range Type
+    RealTypeID,         ///< The Real Number Type
+    PointerTypeID,      ///< The Pointer Type
+    ArrayTypeID,        ///< The Array Type
+    VectorTypeID,       ///< The Vector Type
+    StructureTypeID,    ///< The Structure Type
+    SignatureTypeID,    ///< The Function Signature Type
+
+    // Containers
+    BundleID,           ///< The Bundle Node
+    FunctionID,         ///< The Function Node
+
+    // Declarations
+    VariableID,         ///< The Variable Node
+
+    // Enumeration Limits
+    NumNodeIDs,         ///< The number of type identifiers in the enum
+    FirstPrimitiveTypeID = VoidTypeID,
+    LastPrimitiveTypeID  = RealTypeID,
+    FirstContainerTypeID = PointerTypeID,
+    LastContainerTypeID  = SignatureTypeID
+  };
+
   class Type;
 
   /// A NamedType is simply a pair involving a name and a pointer to a Type.
@@ -50,19 +79,32 @@
     /// @name Constructors
     /// @{
     public:
-      Node(Node* parent, const std::string& name) 
-        : name_(name), parent_(parent), kids_() {}
+      Node(NodeIDs id, Node* parent = 0, const std::string& name = "") 
+        : id_(id), parent_(parent), name_(name), kids_() {}
       virtual ~Node();
 #ifndef _NDEBUG
       virtual void dump() const;
 #endif
 
     /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      inline bool isType() const { 
+        return id_ <= FirstPrimitiveTypeID && id_ >= LastContainerTypeID;
+      }
+      inline bool isBundle() const { return id_ == BundleID; }
+      inline bool isFunction() const { return id_ == FunctionID; }
+      inline bool isVariable() const { return id_ == VariableID; }
+      static inline bool classof(const Node*) { return true; }
+
+    /// @}
     /// @name Data
     /// @{
     protected:
-      std::string name_;        ///< The name of this node.
+      NodeIDs id_;              ///< Identification of the node kind.
       Node* parent_;            ///< The node that owns this node.
+      std::string name_;        ///< The name of this node.
       std::vector<Node> kids_;  ///< The vector of children nodes.
     /// @}
   };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 18:58:38 2007
@@ -25,26 +25,9 @@
 #define HLVM_AST_TYPE_H
 
 #include <hlvm/AST/Node.h>
-#include <llvm/Support/Casting.h>
 
 namespace hlvm {
 namespace AST {
-  /// This enumeration is used to identify a specific type
-  enum TypeIDs {
-    VoidTypeID = 0,     ///< The Void Type
-    IntegerTypeID,      ///< The Integer Type
-    RangeTypeID,        ///< The Range Type
-    RealTypeID,         ///< The Real Number Type
-    PointerTypeID,      ///< The Pointer Type
-    ArrayTypeID,        ///< The Array Type
-    VectorTypeID,       ///< The Vector Type
-    StructureTypeID,    ///< The Structure Type
-    SignatureTypeID,    ///< The Function Signature Type
-
-    NumTypeIDs,         ///< The number of type identifiers in the enum
-    LastPrimitiveTypeID  = RealTypeID,
-    FirstContainerTypeID = PointerTypeID
-  };
 
   /// This class represents a Type in the HLVM Abstract Syntax Tree.  
   /// A Type defines the format of storage. 
@@ -55,10 +38,10 @@
     /// @{
     public:
       Type(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name, ///< The name of the function
-        TypeIDs type_id ///< The Type identifier
-      ) : Node(parent,name), id_(type_id) {}
+        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)  {}
       virtual ~Type();
 
     /// @}
@@ -80,14 +63,14 @@
       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 Type*) { return true; }
+      // Methods to support type inquiry via is, cast, dyn_cast
+      static inline bool classof(const Node*) { return true; }
+      static inline bool classof(const Type*) { return true; }
 
     /// @}
     /// @name Data
     /// @{
     protected:
-      TypeIDs id_; ///< The type identifier
     /// @}
   };
 
@@ -102,9 +85,9 @@
     /// @{
     public:
       IntegerType(
-        Node* parent, ///< The bundle in which the function is defined
-        const std::string& name ///< The name of the function
-      ) : Type(parent,name,IntegerTypeID) {}
+        Node* parent = 0, ///< The bundle in which the function is defined
+        const std::string& name = "" ///< The name of the function
+      ) : Type(IntegerTypeID,parent,name) {}
       virtual ~IntegerType();
 
     /// @}
@@ -134,7 +117,7 @@
       RangeType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : Type(parent,name,RangeTypeID) {}
+      ) : Type(RangeTypeID,parent,name) {}
       virtual ~RangeType();
 
     /// @}
@@ -167,7 +150,7 @@
       RealType(
         Node* parent, ///< The bundle in which the function is defined
         const std::string& name ///< The name of the function
-      ) : Type(parent,name,RealTypeID) {}
+      ) : Type(RealTypeID,parent,name) {}
       virtual ~RealType();
 
     /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.h (original)
+++ hlvm/trunk/hlvm/AST/Variable.h Sat Jul  7 18:58:38 2007
@@ -46,10 +46,17 @@
       Variable(
         Node* parent, ///< The bundle or function that defines the ariable 
         const std::string& name ///< The name of the variable
-      ) : LinkageItem(parent,name) {}
+      ) : LinkageItem(VariableID,parent,name) {}
       virtual ~Variable();
 
     /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      static inline bool classof(const Variable*) { return true; }
+      static inline bool classof(const Node* N) { return N->isVariable(); }
+
+    /// @}
     /// @name Data
     /// @{
     protected:





More information about the llvm-commits mailing list