summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-06-10 20:37:51 -0400
committerAdrian Thurston <thurston@complang.org>2013-06-10 20:37:51 -0400
commitf12a447aa9b3b607a0ceaa3bc297291b5d30136b (patch)
tree22439abe2a1690a3c0242e7ca6f264a87da55e08
parentb020267b0d471c913467a9479f7cc4618356a996 (diff)
downloadcolm-f12a447aa9b3b607a0ceaa3bc297291b5d30136b.tar.gz
added a constructor for string that sources from colm_data
-rw-r--r--aapl/compare.h27
-rw-r--r--src/compiler.cc4
-rw-r--r--src/cstring.h (renamed from aapl/astring.h)51
-rw-r--r--src/loadcolm.cc2
-rw-r--r--src/loadinit.cc4
-rw-r--r--src/parsedata.h2
-rw-r--r--src/parsetree.h3
-rw-r--r--src/pdabuild.cc2
-rw-r--r--src/tree.h1
9 files changed, 61 insertions, 35 deletions
diff --git a/aapl/compare.h b/aapl/compare.h
index 22937e9b..707e6420 100644
--- a/aapl/compare.h
+++ b/aapl/compare.h
@@ -23,7 +23,6 @@
#define _AAPL_COMPARE_H
#include <string.h>
-#include "astring.h"
#include "table.h"
#ifdef AAPL_NAMESPACE
@@ -51,32 +50,6 @@ namespace Aapl {
*/
/**
- * \brief Compare two null terminated character sequences.
- *
- * This comparision class is a wrapper for strcmp.
- */
-template<class T> struct CmpStrTmpl
-{
- /**
- * \brief Compare two null terminated string types.
- */
- static inline long compare( const char *k1, const char *k2 )
- { return strcmp(k1, k2); }
-
- static int compare( const StrTmpl<T> &s1, const StrTmpl<T> &s2 )
- {
- if ( s1.length() < s2.length() )
- return -1;
- else if ( s1.length() > s2.length() )
- return 1;
- else
- return memcmp( s1.data, s2.data, s1.length() );
- }
-};
-
-typedef CmpStrTmpl<char> CmpStr;
-
-/**
* \brief Compare a type for which < and > are implemented.
*
* CmpOrd is suitable for simple types such as integers and pointers that by
diff --git a/src/compiler.cc b/src/compiler.cc
index f4f79744..574f6bd8 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -360,8 +360,8 @@ Compiler::Compiler( )
nextTokenId(1),
rootCodeBlock(0),
mainReturnUT(0),
- access(0),
- tokenStruct(0),
+ //access(0),
+ //tokenStruct(0),
ptrLangEl(0),
boolLangEl(0),
diff --git a/aapl/astring.h b/src/cstring.h
index b141ccf5..a59ebe36 100644
--- a/aapl/astring.h
+++ b/src/cstring.h
@@ -30,6 +30,10 @@
#include <iostream>
#include <assert.h>
+#include "tree.h"
+
+struct colm_data;
+
#ifdef AAPL_NAMESPACE
namespace Aapl {
#endif
@@ -302,6 +306,9 @@ public:
/* Construct a string from with, sprintf. */
StrTmpl( long lenGuess, const char *format, ... );
+ /* Construct a string from with, sprintf. */
+ StrTmpl( const colm_data *cd );
+
/* Set the string from a c-style string. */
StrTmpl &operator=( const char *s );
@@ -456,6 +463,23 @@ template<class T> StrTmpl<T>::StrTmpl( long lenGuess, const char *format, ... )
va_end( args );
}
+/* Create from another string class. */
+template<class T> StrTmpl<T>::StrTmpl( const colm_data *cd )
+{
+ if ( cd->data == 0 )
+ data = 0;
+ else {
+ /* Init space for the data. */
+ initSpace( cd->length );
+
+ /* Copy in the data. */
+ memcpy( data, cd->data, cd->length );
+ data[cd->length] = 0;
+ }
+}
+
+
+
/* Construct a string from with, sprintf. */
template<class T> void StrTmpl<T>::setAs( long lenGuess, const char *format, ... )
{
@@ -802,6 +826,33 @@ template <class T> inline std::ostream &operator<<( std::ostream &o, const StrTm
typedef StrTmpl<char> String;
+/**
+ * \brief Compare two null terminated character sequences.
+ *
+ * This comparision class is a wrapper for strcmp.
+ */
+template<class T> struct CmpStrTmpl
+{
+ /**
+ * \brief Compare two null terminated string types.
+ */
+ static inline long compare( const char *k1, const char *k2 )
+ { return strcmp(k1, k2); }
+
+ static int compare( const StrTmpl<T> &s1, const StrTmpl<T> &s2 )
+ {
+ if ( s1.length() < s2.length() )
+ return -1;
+ else if ( s1.length() > s2.length() )
+ return 1;
+ else
+ return memcmp( s1.data, s2.data, s1.length() );
+ }
+};
+
+typedef CmpStrTmpl<char> CmpStr;
+
+
#ifdef AAPL_NAMESPACE
}
diff --git a/src/loadcolm.cc b/src/loadcolm.cc
index 5d7f9246..a927de28 100644
--- a/src/loadcolm.cc
+++ b/src/loadcolm.cc
@@ -336,7 +336,7 @@ struct LoadColm
String walkOptId( opt_id optId )
{
- String name = 0;
+ String name;
if ( optId.prodName() == opt_id::_Id )
name = optId.Id().text().c_str();
return name;
diff --git a/src/loadinit.cc b/src/loadinit.cc
index 1d165ece..1dc50081 100644
--- a/src/loadinit.cc
+++ b/src/loadinit.cc
@@ -232,13 +232,13 @@ void LoadInit::walkTokenList( token_list &tokenList )
if ( tokenList.IgnoreDef() != 0 ) {
ignore_def IgnoreDef = tokenList.IgnoreDef();
- ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, 0, pd->nextObjectId++ );
+ ObjectDef *objectDef = ObjectDef::cons( ObjectDef::UserType, String(), pd->nextObjectId++ );
lex_expr LexExpr = IgnoreDef.Expr();
LexExpression *expr = walkLexExpr( LexExpr );
LexJoin *join = LexJoin::cons( expr );
- defineToken( internal, 0, join, objectDef, 0, true, false, false );
+ defineToken( internal, String(), join, objectDef, 0, true, false, false );
}
}
diff --git a/src/parsedata.h b/src/parsedata.h
index 6acf5e50..89782bcb 100644
--- a/src/parsedata.h
+++ b/src/parsedata.h
@@ -37,7 +37,7 @@
#include "vector.h"
#include "keyops.h"
#include "parsetree.h"
-#include "astring.h"
+#include "cstring.h"
#include "pdagraph.h"
#include "compare.h"
#include "pdarun.h"
diff --git a/src/parsetree.h b/src/parsetree.h
index f75705e8..b19368ce 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -24,6 +24,7 @@
#include <iostream>
#include <string.h>
+
#include "global.h"
#include "avlmap.h"
#include "bstmap.h"
@@ -32,7 +33,7 @@
#include "dlist.h"
#include "dlistval.h"
#include "dlistmel.h"
-#include "astring.h"
+#include "cstring.h"
#include "bytecode.h"
#include "avlbasic.h"
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index b38c80de..c859485d 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -65,7 +65,7 @@ LangEl::LangEl( Namespace *nspace, const String &name, Type type )
id(-1),
isUserTerm(false),
isContext(false),
- displayString(0),
+ //displayString(0),
numAppearances(0),
commit(false),
isIgnore(false),
diff --git a/src/tree.h b/src/tree.h
index 91051022..fad9387a 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -27,6 +27,7 @@ extern "C" {
#endif
#include <colm/colm.h>
+#include <colm/input.h>
typedef unsigned char Code;
typedef unsigned long Word;