[llvm-commits] [hlvm] r38025 - /hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
Reid Spencer
reid at x10sys.com
Sat Jul 7 16:59:04 PDT 2007
Author: reid
Date: Sat Jul 7 18:59:04 2007
New Revision: 38025
URL: http://llvm.org/viewvc/llvm-project?rev=38025&view=rev
Log:
Add the beginnings of AST node construction.
Modified:
hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp?rev=38025&r1=38024&r2=38025&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul 7 18:59:04 2007
@@ -31,11 +31,14 @@
#include <hlvm/Reader/XML/HLVMTokenizer.h>
#include <hlvm/Base/Locator.h>
#include <hlvm/AST/AST.h>
+#include <hlvm/AST/Bundle.h>
#include <expat.h>
#include <vector>
#include <string>
+#include <iostream>
using namespace hlvm;
+using namespace HLVM_Reader_XML;
namespace {
@@ -82,6 +85,7 @@
std::string local; ///< The local name of the element
int32_t token; ///< Tokenized value of local name
uint32_t ns; ///< Tokenized value of namespace name
+ mutable AST::Node* node; ///< The corresponding AST Node
};
/// This structure provides information about an element. It is used during
@@ -132,8 +136,59 @@
virtual void read();
virtual AST::AST* get();
-/// @name Expat Parsing Handlers
-/// @{
+ void CDataSectionStart(void );
+ void CDataSectionEnd();
+ void NamespaceStart( const char* prefix, const char* uri );
+ void NamespaceEnd( const char* prefix );
+ void ElementStart( const ElementInfo& elem);
+ void ElementEnd( const ElementInfo& elem, uint32_t line, uint32_t column );
+
+ void ProcessingInstruction(const std::string& target, const std::string&data);
+ void Comment( const std::string& );
+ void WhiteSpace( const std::string& );
+ void Characters( const std::string& );
+ void EntityDeclaration(const char *entityName,
+ int is_parameter_entity, const char *value, int value_length,
+ const char *base, const char *systemId,
+ const char *publicId, const char *notationName);
+ void NotationDeclaration(const std::string& notationName,
+ const std::string& systemId, const std::string& publicId);
+
+ uint32_t depth() const { return elems_.size(); }
+
+ const ElementInfo* first() const {
+ if (elems_.empty())
+ return 0;
+ return &elems_.back();
+ }
+
+ const ElementInfo* second() const {
+ if (elems_.size() < 2) return 0;
+ const ElementInfo* result = &elems_.back();
+ return result - 1;
+ }
+
+ const ElementInfo* third() const {
+ if (elems_.size() < 3) return 0;
+ const ElementInfo* result = &elems_.back();
+ return result - 2;
+ }
+
+ const ElementInfo* fourth() const {
+ if (elems_.size() < 4) return 0;
+ const ElementInfo* result = &elems_.back();
+ return result - 3;
+ }
+
+ void make_error(const std::string& msg) {
+ std::cerr << msg;
+ }
+
+ std::string getToken(int32_t token) const
+ {
+ return HLVMTokenizer::lookup(token);
+ }
+
private:
static void XMLCALL
@@ -151,7 +206,7 @@
// Fill in the element info
ei.local = name;
- ei.token = HLVM_Reader_XML::HLVMTokenizer::recognize(name);
+ ei.token = HLVMTokenizer::recognize(name);
ei.set(
"",
p->path_.c_str(),
@@ -178,7 +233,7 @@
// Get the token for the
attr.local = *attributes;
- attr.token = HLVM_Reader_XML::HLVMTokenizer::recognize(*attributes);
+ attr.token = HLVMTokenizer::recognize(*attributes);
attr.value = attributes[1];
// Increment loop counters
@@ -188,7 +243,7 @@
}
// Tell the handler about the element
- //p->handler_->ElementStart(ei);
+ p->ElementStart(ei);
}
static void XMLCALL
@@ -202,7 +257,7 @@
int column = XML_GetCurrentColumnNumber( p->xp_ );
// Convert the element name to a token
- int name_token = HLVM_Reader_XML::HLVMTokenizer::recognize(name);
+ int name_token = HLVMTokenizer::recognize(name);
// Save the previous token before poping it and make sure that it is the
// same as the one the parser told us we're popping.
@@ -210,7 +265,7 @@
assert(token == name_token);
// Tell the handler that we're ending an element.
- // p->handler_->ElementEnd( p->elems_.back(), line, column );
+ p->ElementEnd( p->elems_.back(), line, column );
// Pop the element token and then push it on the "kids" list of the
// parent element indicating that we've completed parsing one child element.
@@ -232,7 +287,7 @@
// Tell the handler about the characters
std::string tmp;
tmp.assign(s,len);
- // p->handler_->Characters(tmp);
+ p->Characters(tmp);
}
static void XMLCALL
@@ -243,7 +298,7 @@
register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
// Tell the handler about the processing instruction
- // p->handler_->ProcessingInstruction(target,data);
+ p->ProcessingInstruction(target,data);
}
static void XMLCALL
@@ -253,7 +308,7 @@
register XMLReaderImpl* p = reinterpret_cast<XMLReaderImpl*>(user_data);
// Comments are always valid
- // p->handler_->Comment(data);
+ p->Comment(data);
}
static void XMLCALL
@@ -273,7 +328,7 @@
p->elems_.push_back(ei);
// Inform the handler of the CData Section
- // p->handler_->CDataSectionStart();
+ p->CDataSectionStart();
}
static void XMLCALL
@@ -292,85 +347,7 @@
p->etop_->kids.push_back(ki);
// Inform the handler (always valid)
- // p->handler_->CDataSectionEnd();
- }
-
- static void XMLCALL
- DefaultHandler(
- void *user_data, const XML_Char *s, int len)
- {
- // static_cast<XMLReaderImpl*>(user_data)->handler_->Other(s,len);
- }
-
- static void XMLCALL
- StartDoctypeDeclHandler(
- void * /*user_data*/,
- const XML_Char * /*doctypeName*/,
- const XML_Char * /*sysid*/,
- const XML_Char * /*pubid*/,
- int /*has_internal_subset*/)
- {
- // FIXME: Implement
- }
-
- static void XMLCALL
- EndDoctypeDeclHandler(void * /*user_data*/)
- {
- // FIXME: Implement
- }
-
- static void XMLCALL
- EntityDeclHandler(
- void * /*user_data*/,
- const XML_Char * /*entityName*/,
- int /*is_parameter_entity*/,
- const XML_Char * /*value*/,
- int /*value_length*/,
- const XML_Char * /*base*/,
- const XML_Char * /*systemId*/,
- const XML_Char * /*publicId*/,
- const XML_Char * /*notationName*/)
- {
- // FIXME: Implement
- }
-
- static void XMLCALL
- NotationDeclHandler(
- void * /*user_data*/,
- const XML_Char * /*notationName*/,
- const XML_Char * /*base*/,
- const XML_Char * /*systemId*/,
- const XML_Char * /*publicId*/)
- {
- // FIXME: Implement
- }
-
- static int XMLCALL
- NotStandaloneHandler(void * /*user_data*/ )
- {
- // FIXME: Implement
- return XML_STATUS_ERROR;
- }
-
- static int XMLCALL
- ExternalEntityRefHandler(
- XML_Parser /*parser*/,
- const XML_Char * /*context*/,
- const XML_Char * /*base*/,
- const XML_Char * /*systemId*/,
- const XML_Char * /*publicId*/)
- {
- // FIXME: Implement
- return XML_STATUS_ERROR;
- }
-
- static void XMLCALL
- SkippedEntityHandler(
- void * /*user_data*/,
- const XML_Char * /*entityName*/,
- int /*is_parameter_entity*/)
- {
- // FIXME: Implement
+ p->CDataSectionEnd();
}
static int XMLCALL
@@ -379,8 +356,8 @@
const XML_Char * /*name*/,
XML_Encoding * /*info*/)
{
- // FIXME: Implement
- return XML_STATUS_ERROR;
+ // make_error("Unknown Encoding");
+ return 1;
}
/// @}
@@ -407,12 +384,127 @@
XML_SetCommentHandler( xp_, CommentHandler );
XML_SetCdataSectionHandler( xp_, StartCdataSectionHandler,
EndCdataSectionHandler );
- XML_SetNotStandaloneHandler( xp_, NotStandaloneHandler );
- XML_SetExternalEntityRefHandler( xp_, ExternalEntityRefHandler);
- XML_SetSkippedEntityHandler( xp_, SkippedEntityHandler);
XML_SetUnknownEncodingHandler( xp_, UnknownEncodingHandler, this);
}
+void
+XMLReaderImpl::CDataSectionStart(void )
+{
+}
+
+void
+XMLReaderImpl::CDataSectionEnd()
+{
+}
+
+void
+XMLReaderImpl::NamespaceStart( const char* prefix, const char* uri )
+{
+}
+
+void
+XMLReaderImpl::NamespaceEnd( const char* prefix )
+{
+}
+
+void
+XMLReaderImpl::ElementStart( const ElementInfo& elem)
+{
+ switch (elem.token) {
+ case TKN_bundle: {
+ const std::string* pubid = 0;
+ elem.find_attrs(TKN_pubid,pubid);
+ if (pubid) {
+ elem.node = new AST::Bundle(static_cast<AST::Bundle*>(0),*pubid);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void
+XMLReaderImpl::ElementEnd(
+ const ElementInfo& elem, uint32_t line, uint32_t column )
+{
+}
+
+void
+XMLReaderImpl::ProcessingInstruction(
+ const std::string& target, const std::string&data)
+{
+}
+
+void
+XMLReaderImpl::Comment( const std::string& )
+{
+}
+
+void
+XMLReaderImpl::WhiteSpace( const std::string& )
+{
+}
+
+void
+XMLReaderImpl::Characters( const std::string& )
+{
+}
+
+
+void
+ElementInfo::find_attrs(int token1, const std::string*& value1) const
+{
+ value1 = 0;
+ std::vector<AttrInfo>::const_iterator I = attrs.begin();
+ std::vector<AttrInfo>::const_iterator E = attrs.end();
+ for ( ; I != E && value1 == 0; ++I ) {
+ if (I->token == token1)
+ value1 = &I->value;
+ }
+}
+
+void
+ElementInfo::find_attrs(
+ int token1, const std::string*& value1,
+ int token2, const std::string*& value2
+) const
+{
+ value1 = value2 = 0;
+ std::vector<AttrInfo>::const_iterator I = attrs.begin();
+ std::vector<AttrInfo>::const_iterator E = attrs.end();
+ for ( ; I != E; ++I ) {
+ if (I->token == token1 && value1 == 0)
+ value1 = &I->value;
+ else if (I->token == token2 && value2 == 0)
+ value2 = &I->value;
+ else if (value1 != 0 && value2 !=0)
+ break;
+ }
+}
+
+void
+ElementInfo::find_attrs(
+ int token1, const std::string*& value1,
+ int token2, const std::string*& value2,
+ int token3, const std::string*& value3
+) const
+{
+ value1 = value2 = value3 = 0;
+ std::vector<AttrInfo>::const_iterator I = attrs.begin();
+ std::vector<AttrInfo>::const_iterator E = attrs.end();
+ for ( ; I != E; ++I ) {
+ if (I->token == token1 && value1 == 0)
+ value1 = &I->value;
+ else if (I->token == token2 && value2 == 0)
+ value2 = &I->value;
+ else if (I->token == token3 && value3 == 0)
+ value3 = &I->value;
+ else if (value1 != 0 && value2 !=0 && value3 != 0)
+ break;
+ }
+}
+
}
XMLReader*
More information about the llvm-commits
mailing list