[llvm-commits] [hlvm] r38052 - in /hlvm/trunk: hlvm/AST/ hlvm/Reader/XML/ hlvm/Writer/XML/ test/xml2xml/

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


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

URL: http://llvm.org/viewvc/llvm-project?rev=38052&view=rev
Log:
Add support for reading and writing a variable declaration.

Added:
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/Import.cpp
    hlvm/trunk/hlvm/AST/Import.h
    hlvm/trunk/hlvm/AST/LinkageItem.cpp
    hlvm/trunk/test/xml2xml/var.hlx
Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Block.h
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/Conditionable.h
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/Function.h
    hlvm/trunk/hlvm/AST/LinkageItem.h
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Operator.h
    hlvm/trunk/hlvm/AST/Program.h
    hlvm/trunk/hlvm/AST/Type.cpp
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/AST/Variable.cpp
    hlvm/trunk/hlvm/AST/Variable.h
    hlvm/trunk/hlvm/Reader/XML/HLVM.rng
    hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
    hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 18:59:20 2007
@@ -29,14 +29,64 @@
 
 #include <hlvm/AST/AST.h>
 #include <hlvm/AST/Bundle.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/Function.h>
+#include <hlvm/AST/Import.h>
+#include <hlvm/AST/Variable.h>
 
 namespace hlvm {
 namespace AST {
 
+Type* 
+AST::resolveType(const std::string& name) const
+{
+  IntegerType* result = new IntegerType();
+  result->setName(name);
+  return result;
+}
+
 Bundle*
 AST::new_Bundle(const Locator& loc, const std::string& id)
 {
-  Bundle* result = Bundle::create(loc,id);
+  Bundle* result = new Bundle();
+  result->setLocator(loc);
+  result->setName(id);
+  return result;
+}
+
+Function*
+AST::new_Function(const Locator& loc, const std::string& id)
+{
+  Function* result = new Function();
+  result->setLocator(loc);
+  result->setName(id);
+  return result;
+}
+
+Import*
+AST::new_Import(const Locator& loc, const std::string& pfx)
+{
+  Import* result = new Import();
+  result->setLocator(loc);
+  result->setPrefix(pfx);
+  return result;
+}
+
+SignatureType*
+AST::new_SignatureType(const Locator& loc, const std::string& id)
+{
+  SignatureType* result = new SignatureType();
+  result->setLocator(loc);
+  result->setName(id);
+  return result;
+}
+
+Variable*
+AST::new_Variable(const Locator& loc, const std::string& id)
+{
+  Variable* result = new Variable();
+  result->setLocator(loc);
+  result->setName(id);
   return result;
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 18:59:20 2007
@@ -41,8 +41,13 @@
 /// node types of the AST are declared in this namespace.
 namespace AST
 {
-  class Bundle;
-  class Locator;
+  class Bundle;   
+  class Function; 
+  class Import;
+  class Locator; 
+  class SignatureType;
+  class Type;
+  class Variable; 
 
   /// 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.
@@ -69,11 +74,22 @@
       void setSystemID(const std::string& id) { sysid = id; }
       void setPublicID(const std::string& id) { pubid = id; }
       void setRoot(Bundle* top) { root = top; }
+
+    /// @}
+    /// @name Lookup
+    /// @{
+    public:
+      Type* resolveType(const std::string& name) const;
+
     /// @}
     /// @name Factories
     /// @{
     public:
-      static Bundle* new_Bundle(const Locator& loc, const std::string& id);
+      Bundle* new_Bundle(const Locator& loc, const std::string& id);
+      Function* new_Function(const Locator& loc, const std::string& id);
+      Import* new_Import(const Locator& loc, const std::string& id);
+      SignatureType* new_SignatureType(const Locator& l, const std::string& id);
+      Variable* new_Variable(const Locator& loc, const std::string& id);
 
     /// @}
     /// @name Data

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul  7 18:59:20 2007
@@ -64,6 +64,7 @@
     protected:
       std::vector<Operator*> ops_; ///< The operators the Block contains
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 18:59:20 2007
@@ -63,6 +63,7 @@
     /// @{
     protected:
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Conditionable.h (original)
+++ hlvm/trunk/hlvm/AST/Conditionable.h Sat Jul  7 18:59:20 2007
@@ -60,6 +60,7 @@
     protected:
       std::string cond_name_;
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

Added: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38052&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (added)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 18:59:20 2007
@@ -0,0 +1,42 @@
+//===-- hlvm/AST/ContainerType.cpp - AST ContainerType 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/ContainerType.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/05/18
+/// @since 0.1.0
+/// @brief Implements the functions of the various AST container types
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/AST/ContainerType.h>
+
+namespace hlvm { namespace AST {
+
+ContainerType::~ContainerType()
+{
+}
+
+SignatureType::~SignatureType()
+{
+}
+
+}}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 18:59:20 2007
@@ -186,6 +186,7 @@
       Type* result_;   ///< The result type of the function signature
       bool isVarArgs;  ///< Indicates variable arguments function
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul  7 18:59:20 2007
@@ -77,6 +77,7 @@
       Block * block;                   ///< The code block to be executed
       SignatureType* signature;        ///< The function signature.
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

Added: hlvm/trunk/hlvm/AST/Import.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Import.cpp?rev=38052&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/Import.cpp (added)
+++ hlvm/trunk/hlvm/AST/Import.cpp Sat Jul  7 18:59:20 2007
@@ -0,0 +1,38 @@
+//===-- hlvm/AST/Import.cpp - AST Import 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/Import.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/05/18
+/// @since 0.1.0
+/// @brief Implements the functions of class hlvm::AST::Import.
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/AST/Import.h>
+
+namespace hlvm { namespace AST {
+
+Import::~Import()
+{
+}
+
+}}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Import.h (added)
+++ hlvm/trunk/hlvm/AST/Import.h Sat Jul  7 18:59:20 2007
@@ -0,0 +1,75 @@
+//===-- hlvm/AST/Import.h - AST Import 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/Import.h
+/// @author Reid Spencer <reid at hlvm.org> (original author)
+/// @date 2006/05/18
+/// @since 0.1.0
+/// @brief Declares the class hlvm::AST::Import
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_AST_IMPORT_H
+#define HLVM_AST_IMPORT_H
+
+#include <hlvm/AST/Node.h>
+
+namespace hlvm { namespace AST {
+
+  /// This class represents a Import in the HLVM Abstract Syntax Tree.  
+  /// A Function is a callable block of code that accepts parameters and 
+  /// returns a result.  This is the basic unit of code in HLVM. A Function
+  /// has a name, a set of formal arguments, a return type, and a block of
+  /// code to execute.
+  /// @brief HLVM AST Function Node
+  class Import : public Node
+  {
+    /// @name Constructors
+    /// @{
+    protected:
+      Import() : Node(ImportID) {}
+    public:
+      virtual ~Import();
+
+    /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      static inline bool classof(const Import*) { return true; }
+      static inline bool classof(const Node* N) { return N->is(ImportID); }
+
+    /// @}
+    /// @name Mutators
+    /// @{
+    public:
+      void setPrefix(const std::string& pfx) { prefix = pfx; }
+
+    /// @}
+    /// @name Data
+    /// @{
+    protected:
+      std::string prefix;
+    /// @}
+    friend class AST;
+  };
+} // AST
+} // hlvm
+#endif

Added: hlvm/trunk/hlvm/AST/LinkageItem.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItem.cpp?rev=38052&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.cpp (added)
+++ hlvm/trunk/hlvm/AST/LinkageItem.cpp Sat Jul  7 18:59:20 2007
@@ -0,0 +1,38 @@
+//===-- hlvm/AST/LinkageItem.cpp - AST LinkageItem 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/LinkageItem.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/05/18
+/// @since 0.1.0
+/// @brief Implements the functions of class hlvm::AST::LinkageItem.
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/AST/LinkageItem.h>
+
+namespace hlvm { namespace AST {
+
+LinkageItem::~LinkageItem()
+{
+}
+
+}}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul  7 18:59:20 2007
@@ -67,6 +67,7 @@
     protected:
       LinkageTypes type_; ///< The type of linkage to perform for this item
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 18:59:20 2007
@@ -80,6 +80,7 @@
     // Container
     BundleID,           ///< The Bundle Node (a group of other declarations)
     BlockID,            ///< A Block Of Code Nodes
+    ImportID,           ///< A bundle's Import declaration
 
     // Control Flow And Invocation Operators
     CallOpID,           ///< The Call Operator
@@ -220,6 +221,9 @@
       /// Get the Locator
       inline const Locator& getLocator() const { return loc; }
 
+      /// Determine if the node is a specific kind
+      inline bool is(NodeIDs kind) const { return id == unsigned(kind); }
+
       /// Determine if the node is a Type
       inline bool isType() const {
         return id >= FirstPrimitiveTypeID && id <= LastPrimitiveTypeID;
@@ -277,6 +281,7 @@
       Node* parent;            ///< The node that owns this node.
       Locator loc;             ///< The source location corresponding to node.
     /// @}
+    friend class AST;
   };
 
   class ParentNode : public Node {
@@ -317,12 +322,28 @@
       virtual void addChild(Node* n);
 
     /// @}
+    /// @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(); }
+      Node*          front()       { return kids.front(); }
+      const Node*    front() const { return kids.front(); }
+      Node*          back()        { return kids.back(); }
+      const Node*    back()  const { return kids.back(); }
+
+    /// @}
     /// @name Data
     /// @{
     protected:
       std::string name;  ///< The name of this node.
       NodeList    kids;  ///< The vector of children nodes.
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul  7 18:59:20 2007
@@ -66,6 +66,7 @@
     protected:
       std::vector<Operator*> Operands;  ///< The list of Operands
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.h (original)
+++ hlvm/trunk/hlvm/AST/Program.h Sat Jul  7 18:59:20 2007
@@ -67,6 +67,7 @@
       static SignatureType* SignatureTy; ///< The signature for programs
       static SignatureType* initSignature(); 
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul  7 18:59:20 2007
@@ -36,4 +36,8 @@
 {
 }
 
+IntegerType::~IntegerType()
+{
+}
+
 }}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 18:59:20 2007
@@ -77,6 +77,7 @@
     /// @{
     protected:
     /// @}
+    friend class AST;
   };
 
   /// A NamedType is simply a pair involving a name and a pointer to a Type.
@@ -93,7 +94,7 @@
     /// @name Constructors
     /// @{
     public:
-      IntegerType() : Type(IntegerTypeID) {}
+      IntegerType() : Type(IntegerTypeID), numBits(32) {}
       virtual ~IntegerType();
 
     /// @}
@@ -110,6 +111,7 @@
     protected:
       uint32_t numBits; ///< Minimum number of bits
     /// @}
+    friend class AST;
   };
 
   /// A RangeType is an IntegerType that allows the range of values to be
@@ -137,6 +139,7 @@
       uint64_t min_value_; ///< Lowest value accepted
       uint64_t max_value_; ///< Highest value accepted
     /// @}
+    friend class AST;
   };
 
   /// This class represents all HLVM real number types. The precision and 
@@ -167,6 +170,7 @@
       uint32_t precision_; ///< Number of decimal digits of precision
       uint32_t mantissa_;  ///< Number of decimal digits in mantissa
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.cpp (original)
+++ hlvm/trunk/hlvm/AST/Variable.cpp Sat Jul  7 18:59:20 2007
@@ -32,6 +32,15 @@
 namespace hlvm {
 namespace AST {
 
+Variable* 
+Variable::create(const Locator& loc, std::string name)
+{
+  Variable* result = new Variable();
+  result->setName(name);
+  result->setLocator(loc);
+  return result;
+}
+
 Variable::~Variable()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.h (original)
+++ hlvm/trunk/hlvm/AST/Variable.h Sat Jul  7 18:59:20 2007
@@ -49,22 +49,33 @@
     /// @name Constructors
     /// @{
     public:
+      static Variable* create(const Locator& loc, std::string name);
+    protected:
       Variable() : LinkageItem(VariableID) {}
+    public:
       virtual ~Variable();
 
     /// @}
     /// @name Accessors
     /// @{
     public:
+      Type* getType() const { return type; }
       static inline bool classof(const Variable*) { return true; }
       static inline bool classof(const Node* N) { return N->isVariable(); }
 
     /// @}
+    /// @name Accessors
+    /// @{
+    public:
+      void setType(Type* t) { type = t; }
+
+    /// @}
     /// @name Data
     /// @{
     protected:
-      Type* type_; ///< The type of the variable
+      Type* type; ///< The type of the variable
     /// @}
+    friend class AST;
   };
 } // AST
 } // hlvm 

Modified: hlvm/trunk/hlvm/Reader/XML/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/HLVM.rng?rev=38052&r1=38051&r2=38052&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/XML/HLVM.rng Sat Jul  7 18:59:20 2007
@@ -159,16 +159,18 @@
   <define name="bundle.pat">
     <attribute name="pubid"><data type="anyURI"/></attribute>
     <ref name="Documentation.pat"/>
+    <optional>
+      <zeroOrMore>
+        <ref name="import.elem"/>
+      </zeroOrMore>
+    </optional>
     <zeroOrMore>
-      <ref name="import.elem"/>
-    </zeroOrMore>
-    <zeroOrMore>
-      <interleave>
+      <choice>
         <ref name="Bundle.elem"/>
         <ref name="Function.elem"/>
         <ref name="Type.pat"/>
         <ref name="Variable.elem"/>
-      </interleave>
+      </choice>
     </zeroOrMore>
   </define>
 

Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp?rev=38052&r1=38051&r2=38052&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul  7 18:59:20 2007
@@ -33,6 +33,10 @@
 #include <hlvm/Base/Source.h>
 #include <hlvm/AST/AST.h>
 #include <hlvm/AST/Bundle.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/Function.h>
+#include <hlvm/AST/Import.h>
+#include <hlvm/AST/Variable.h>
 #include <libxml/parser.h>
 #include <libxml/relaxng.h>
 #include <vector>
@@ -50,19 +54,19 @@
 
 class XMLReaderImpl : public XMLReader {
   std::string path;
-  AST::AST* node;
+  AST::AST* ast;
   xmlDocPtr doc;
 public:
   XMLReaderImpl(const std::string& p)
-    : path(p), node(0)
+    : path(p), ast(0)
   {
-    node = new AST::AST();
-    node->setSystemID(p);
+    ast = new AST::AST();
+    ast->setSystemID(p);
   }
 
   virtual ~XMLReaderImpl() 
   { 
-    if (node) delete node; 
+    if (ast) delete ast; 
     if (doc) xmlFreeDoc(doc);
   }
 
@@ -82,7 +86,11 @@
   inline void handleValidationError(xmlErrorPtr error);
 
   void parseTree();
-  AST::Bundle* parseBundle(xmlNodePtr& cur);
+  AST::Bundle*   parseBundle(xmlNodePtr& cur);
+  AST::Function* parseFunction(xmlNodePtr& cur);
+  AST::Import*   parseImport(xmlNodePtr& cur);
+  AST::Type*     parseType(xmlNodePtr& cur);
+  AST::Variable* parseVariable(xmlNodePtr& cur);
 private:
 };
 
@@ -106,19 +114,22 @@
     << ": " << e->message << "\n";
 }
 
-void ParseHandler(void* userData, xmlErrorPtr error) 
+void 
+ParseHandler(void* userData, xmlErrorPtr error) 
 {
   XMLReaderImpl* reader = reinterpret_cast<XMLReaderImpl*>(userData);
   reader->handleParseError(error);
 }
 
-void ValidationHandler(void* userData, xmlErrorPtr error)
+void 
+ValidationHandler(void* userData, xmlErrorPtr error)
 {
   XMLReaderImpl* reader = reinterpret_cast<XMLReaderImpl*>(userData);
   reader->handleValidationError(error);
 }
 
-bool skipBlanks(xmlNodePtr &cur)
+bool 
+skipBlanks(xmlNodePtr &cur)
 {
   while (cur && 
       (cur->type == XML_TEXT_NODE ||
@@ -127,37 +138,100 @@
   {
     cur = cur -> next;
   }
-  return cur == 0;
+  return cur != 0;
 }
 
-inline const char* getAttribute(xmlNodePtr cur,const char*name)
+inline const char* 
+getAttribute(xmlNodePtr cur,const char*name)
 {
   return reinterpret_cast<const char*>(
     xmlGetNoNsProp(cur,reinterpret_cast<const xmlChar*>(name)));
 }
 
-inline int getToken(const xmlChar* name)
+inline int 
+getToken(const xmlChar* name)
 {
   return HLVMTokenizer::recognize(reinterpret_cast<const char*>(name));
 }
 
+inline void 
+getNameType(xmlNodePtr& cur, std::string& name, std::string& type)
+{
+  name = getAttribute(cur,"name");
+  type = getAttribute(cur,"type");
+}
+
+AST::Function*
+XMLReaderImpl::parseFunction(xmlNodePtr& cur)
+{
+  assert(getToken(cur->name)==TKN_import);
+  AST::Locator loc(cur->line,0,&ast->getSystemID());
+  std::string name, type;
+  getNameType(cur, name, type);
+  AST::Function* func = ast->new_Function(loc,name);
+  return func;
+}
+
+AST::Import*
+XMLReaderImpl::parseImport(xmlNodePtr& cur)
+{
+  assert(getToken(cur->name)==TKN_import);
+  AST::Locator loc(cur->line,0,&ast->getSystemID());
+  std::string pfx = getAttribute(cur,"prefix");
+  AST::Import* imp = ast->new_Import(loc,pfx);
+  return imp;
+}
+
+AST::Type*
+XMLReaderImpl::parseType(xmlNodePtr& cur)
+{
+  return 0;
+}
+
+AST::Variable*
+XMLReaderImpl::parseVariable(xmlNodePtr& cur)
+{
+  assert(getToken(cur->name)==TKN_var);
+  AST::Locator loc(cur->line,0,&ast->getSystemID());
+  std::string name, type;
+  getNameType(cur, name, type);
+  AST::Variable* var = ast->new_Variable(loc,name);
+  var->setType(ast->resolveType(type));
+  return var;
+}
+
 AST::Bundle*
-XMLReaderImpl::parseBundle(xmlNodePtr &cur) 
+XMLReaderImpl::parseBundle(xmlNodePtr& cur) 
 {
-  int tkn = getToken(cur->name);
-  assert(tkn == TKN_bundle && "Expecting bundle element");
+  assert(getToken(cur->name) == TKN_bundle && "Expecting bundle element");
   std::string pubid(getAttribute(cur, "pubid"));
-  AST::Locator loc(cur->line,0,&node->getSystemID());
-  AST::Bundle* bundle = AST::AST::new_Bundle(loc,pubid);
+  AST::Locator loc(cur->line,0,&ast->getSystemID());
+  AST::Bundle* bundle = ast->new_Bundle(loc,pubid);
+  xmlNodePtr child = cur->children;
+  while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) 
+  {
+    int tkn = getToken(child->name);
+    AST::Node* n = 0;
+    switch (tkn) {
+      case TKN_import   : n = parseImport(child); break;
+      case TKN_bundle   : n = parseBundle(child); break;
+      case TKN_function : n = parseFunction(child); break;
+      case TKN_type:      n = parseType(child); break;
+      case TKN_var:       n = parseVariable(child); break;
+      default:
+        assert(!"Invalid content for bundle");
+        break;
+    }
+    if (n)
+      bundle->addChild(n);
+    child = child->next;
+  }
   return bundle;
 }
 
 void
 XMLReaderImpl::parseTree() 
 {
-  if (node)
-    delete node;
-  node = new AST::AST();
   xmlNodePtr cur = xmlDocGetRootElement(doc);
   if (!cur) {
     error("No root node");
@@ -166,15 +240,14 @@
   int tkn = getToken(cur->name);
   assert(tkn == TKN_hlvm && "Expecting hlvm element");
   cur = cur->children;
-  if (skipBlanks(cur)) return;
-  AST::Bundle* bundle = parseBundle(cur);
-  node->setRoot(bundle);
+  if (skipBlanks(cur)) {
+    AST::Bundle* bundle = parseBundle(cur);
+    ast->setRoot(bundle);
+  }
 }
 
 // Implement the read interface to parse, validate, and convert the
 // XML document into AST Nodes. 
-// TODO: This needs  to (eventually) use the XMLTextReader API that libxml2
-// supports. 
 void
 XMLReaderImpl::read() {
 
@@ -256,10 +329,9 @@
 AST::AST*
 XMLReaderImpl::get()
 {
-  return node;
+  return ast;
 }
 
-
 }
 
 XMLReader* 

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

==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul  7 18:59:20 2007
@@ -30,11 +30,16 @@
 #include <hlvm/Writer/XML/XMLWriter.h>
 #include <hlvm/AST/AST.h>
 #include <hlvm/AST/Bundle.h>
+#include <hlvm/AST/Function.h>
+#include <hlvm/AST/Import.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/Variable.h>
 #include <libxml/xmlwriter.h>
 #include <iostream>
 #include <cassert>
 
 using namespace hlvm;
+using namespace llvm;
 
 namespace {
 
@@ -79,41 +84,11 @@
   inline void putHeader();
   inline void putFooter();
   inline void put(AST::Node* node);
-  inline void put(AST::Bundle* node);
+  inline void put(AST::Bundle* b);
+  inline void put(AST::Variable* v);
+  inline void put(AST::Function* f);
 };
 
-std::string 
-sanitize(const std::string* input)
-{
-  // Replace all the & in the name with &  and simliarly for < and > 
-  // because XML doesn't like 'em
-  std::string output(*input);
-  std::string::size_type pos = 0;
-  while (std::string::npos != (pos = output.find('&',pos)))
-  {
-    output.replace(pos,1,"&");
-    pos += 5;
-  }
-  pos = 0;
-  while (std::string::npos != (pos = output.find('<',pos)))
-  {
-    output.replace(pos,1,"<");
-    pos += 4;
-  }
-  pos = 0;
-  while (std::string::npos != (pos = output.find('>',pos)))
-  {
-    output.replace(pos,1,">");
-    pos += 4;
-  }
-  return output;
-}
-
-std::string 
-sanitize(const std::string& input)
-{
-  return sanitize(&input);
-}
 
 void
 XMLWriterImpl::putHeader() 
@@ -127,6 +102,21 @@
 XMLWriterImpl::putFooter()
 {
   endElement();
+  xmlTextWriterEndDocument(writer);
+}
+
+inline void
+XMLWriterImpl::put(AST::Function* f)
+{
+}
+
+inline void
+XMLWriterImpl::put(AST::Variable* v)
+{
+  startElement("var");
+  writeAttribute("name",v->getName().c_str());
+  writeAttribute("type",v->getType()->getName().c_str());
+  endElement();
 }
 
 inline void 
@@ -134,8 +124,17 @@
 {
   startElement("bundle");
   writeAttribute("pubid",b->getName().c_str());
+  for (AST::ParentNode::const_iterator I = b->begin(),E = b->end(); I != E; ++I)
+  {
+    switch ((*I)->getID()) 
+    {
+      case AST::VariableID: put(cast<AST::Variable>(*I)); break;
+      case AST::FunctionID: put(cast<AST::Function>(*I)); break;
+      default:
+        assert(!"Invalid bundle content");
+    }
+  }
   endElement();
-  xmlTextWriterEndDocument(writer);
 }
 
 void

Added: hlvm/trunk/test/xml2xml/var.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/var.hlx?rev=38052&view=auto

==============================================================================
--- hlvm/trunk/test/xml2xml/var.hlx (added)
+++ hlvm/trunk/test/xml2xml/var.hlx Sat Jul  7 18:59:20 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+  <bundle pubid="bundle">
+    <var name="var" type="int"/>
+  </bundle>
+</hlvm>





More information about the llvm-commits mailing list