[llvm-commits] [hlvm] r38099 - in /hlvm/trunk: hlvm/AST/Bundle.cpp hlvm/AST/Bundle.h hlvm/Writer/XML/XMLWriter.cpp test/xml2xml/doc.hlx

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


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

URL: http://llvm.org/viewvc/llvm-project?rev=38099&view=rev
Log:
Teach Bundle and its users to disambiguate between Types,
Variables and Functions.

Modified:
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
    hlvm/trunk/test/xml2xml/doc.hlx

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 18:59:49 2007
@@ -28,7 +28,9 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/Bundle.h>
-#include <hlvm/AST/LinkageItem.h>
+#include <hlvm/AST/Type.h>
+#include <hlvm/AST/Variable.h>
+#include <hlvm/AST/Function.h>
 #include <hlvm/Base/Assert.h>
 
 using namespace llvm; 
@@ -51,8 +53,14 @@
 void 
 Bundle::insertChild(Node* kid)
 {
-  hlvmAssert(isa<LinkageItem>(kid) && "Can't insert that here");
-  kids.push_back(cast<LinkageItem>(kid));
+  if (kid->isType())
+    types.push_back(cast<Type>(kid));
+  else if (kid->isVariable())
+    vars.push_back(cast<Variable>(kid));
+  else if (kid->isFunction())
+    funcs.push_back(cast<Function>(kid));
+  else
+    hlvmAssert(isa<LinkageItem>(kid) && "Can't insert that here");
 }
 
 void
@@ -60,8 +68,18 @@
 {
   hlvmAssert(isa<LinkageItem>(kid) && "Can't remove that here");
   // This is sucky slow, but we probably won't be removing nodes that much.
-  for (iterator I = begin(), E = end(); I != E; ++I ) {
-    if (*I == kid) { kids.erase(I); return; }
+  if (kid->isType()) {
+    for (type_iterator I = type_begin(), E = type_end(); I != E; ++I ) {
+      if (*I == kid) { types.erase(I); return; }
+    }
+  } else if (kid->isVariable()) {
+    for (var_iterator I = var_begin(), E = var_end(); I != E; ++I ) {
+      if (*I == kid) { vars.erase(I); return; }
+    }
+  } else if (kid->isFunction()) {
+    for (func_iterator I = func_begin(), E = func_end(); I != E; ++I ) {
+      if (*I == kid) { funcs.erase(I); return; }
+    }
   }
   hlvmAssert(!"That node isn't my child");
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 18:59:49 2007
@@ -35,7 +35,9 @@
 namespace hlvm 
 { 
 
-class LinkageItem;
+class Type;
+class Variable;
+class Function;
 
 /// 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
@@ -48,9 +50,17 @@
   /// @name Types
   /// @{
   public:
-    typedef std::vector<LinkageItem*> NodeList;
-    typedef NodeList::iterator iterator;
-    typedef NodeList::const_iterator const_iterator;
+    typedef std::vector<Type*> TypeList;
+    typedef TypeList::iterator type_iterator;
+    typedef TypeList::const_iterator type_const_iterator;
+
+    typedef std::vector<Function*> FuncList;
+    typedef FuncList::iterator func_iterator;
+    typedef FuncList::const_iterator func_const_iterator;
+
+    typedef std::vector<Variable*> VarList;
+    typedef VarList::iterator var_iterator;
+    typedef VarList::const_iterator var_const_iterator;
 
   /// @}
   /// @name Constructors
@@ -80,22 +90,45 @@
   /// @name Iterators
   /// @{
   public:
-    iterator           begin()       { return kids.begin(); }
-    const_iterator     begin() const { return kids.begin(); }
-    iterator           end  ()       { return kids.end(); }
-    const_iterator     end  () const { return kids.end(); }
-    size_t             size () const { return kids.size(); }
-    bool               empty() const { return kids.empty(); }
-    LinkageItem*       front()       { return kids.front(); }
-    const LinkageItem* front() const { return kids.front(); }
-    LinkageItem*       back()        { return kids.back(); }
-    const LinkageItem* back()  const { return kids.back(); }
-
+    type_iterator           type_begin()       { return types.begin(); }
+    type_const_iterator     type_begin() const { return types.begin(); }
+    type_iterator           type_end  ()       { return types.end(); }
+    type_const_iterator     type_end  () const { return types.end(); }
+    size_t                  type_size () const { return types.size(); }
+    bool                    type_empty() const { return types.empty(); }
+    Type*                   type_front()       { return types.front(); }
+    const Type*             type_front() const { return types.front(); }
+    Type*                   type_back()        { return types.back(); }
+    const Type*             type_back()  const { return types.back(); }
+
+    func_iterator           func_begin()       { return funcs.begin(); }
+    func_const_iterator     func_begin() const { return funcs.begin(); }
+    func_iterator           func_end  ()       { return funcs.end(); }
+    func_const_iterator     func_end  () const { return funcs.end(); }
+    size_t                  func_size () const { return funcs.size(); }
+    bool                    func_empty() const { return funcs.empty(); }
+    Function*               func_front()       { return funcs.front(); }
+    const Function*         func_front() const { return funcs.front(); }
+    Function*               func_back()        { return funcs.back(); }
+    const Function*         func_back()  const { return funcs.back(); }
+
+    var_iterator            var_begin()       { return vars.begin(); }
+    var_const_iterator      var_begin() const { return vars.begin(); }
+    var_iterator            var_end  ()       { return vars.end(); }
+    var_const_iterator      var_end  () const { return vars.end(); }
+    size_t                  var_size () const { return vars.size(); }
+    bool                    var_empty() const { return vars.empty(); }
+    Variable*               var_front()       { return vars.front(); }
+    const Variable*         var_front() const { return vars.front(); }
+    Variable*               var_back()        { return vars.back(); }
+    const Variable*         var_back()  const { return vars.back(); }
   /// @}
   /// @name Data
   /// @{
   protected:
-    NodeList    kids;  ///< The vector of children nodes.
+    TypeList    types;  ///< The vector of children nodes.
+    VarList     vars;
+    FuncList    funcs;
   /// @}
   friend class AST;
 };

Modified: hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp?rev=38099&r1=38098&r2=38099&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul  7 18:59:49 2007
@@ -373,13 +373,10 @@
   startElement("bundle");
   writeAttribute("pubid",b->getName().c_str());
   putDoc(b);
-  for (Bundle::const_iterator I = b->begin(),E = b->end(); I != E; ++I)
+  for (Bundle::type_const_iterator I = b->type_begin(), E = b->type_end();
+       I != E; ++I)
   {
-    switch ((*I)->getID()) 
-    {
-      case DocumentationID:    put(cast<Documentation>(*I)); break;
-      case VariableID:         put(cast<Variable>(*I)); break;
-      case FunctionID:         put(cast<Function>(*I)); break;
+    switch ((*I)->getID()) {
       case AliasTypeID:        put(cast<AliasType>(*I)); break;
       case AnyTypeID:          put(cast<AnyType>(*I)); break;
       case BooleanTypeID:      put(cast<BooleanType>(*I)); break;
@@ -396,9 +393,16 @@
       case StructureTypeID:    put(cast<StructureType>(*I)); break;
       case SignatureTypeID:    put(cast<SignatureType>(*I)); break;
       default:
-        hlvmDeadCode("Invalid bundle content");
+        hlvmDeadCode("Unknown Type");
+        break;
     }
   }
+  for (Bundle::var_const_iterator I = b->var_begin(), E = b->var_end();
+       I != E; ++I)
+    put(cast<Variable>(*I));
+  for (Bundle::func_const_iterator I = b->func_begin(), E = b->func_end();
+       I != E; ++I)
+    put(cast<Function>(*I));
   endElement();
 }
 

Modified: hlvm/trunk/test/xml2xml/doc.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/doc.hlx?rev=38099&r1=38098&r2=38099&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/doc.hlx (original)
+++ hlvm/trunk/test/xml2xml/doc.hlx Sat Jul  7 18:59:49 2007
@@ -120,11 +120,11 @@
         <doc>Documentation for field 2</doc>
       </field>
     </structure>
-    <var name="var" type="int">
-      <doc><p>This is documentation for a <i>var</i>iable</p></doc>
-    </var>
     <vector name="aVector" of="f32" length="128">
       <doc>Vector doc</doc>
     </vector>
+    <var name="var" type="int">
+      <doc><p>This is documentation for a <i>var</i>iable</p></doc>
+    </var>
   </bundle>
 </hlvm>





More information about the llvm-commits mailing list