diff options
author | Adrian Thurston <thurston@complang.org> | 2015-02-15 10:11:35 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-02-15 10:11:35 -0500 |
commit | e02a3e7d7369540bf020134d538c2a3f2001c5fa (patch) | |
tree | 69b8fc5f809656d9c6d3f7906bae3df1bc8b2c12 | |
parent | a4be5397162bc38f3b112d9ac675c37c6744f535 (diff) | |
download | colm-e02a3e7d7369540bf020134d538c2a3f2001c5fa.tar.gz |
code cleanup and movement
-rw-r--r-- | src/list.c | 52 | ||||
-rw-r--r-- | src/loadcolm.cc | 39 | ||||
-rw-r--r-- | src/parser.cc | 11 | ||||
-rw-r--r-- | src/parser.h | 3 | ||||
-rw-r--r-- | src/parsetree.cc | 44 | ||||
-rw-r--r-- | src/parsetree.h | 45 | ||||
-rw-r--r-- | src/program.c | 14 | ||||
-rw-r--r-- | src/tree.c | 7 | ||||
-rw-r--r-- | src/tree.h | 7 |
9 files changed, 91 insertions, 131 deletions
@@ -29,10 +29,33 @@ static void colm_list_add_after( List *list, ListEl *prev_el, ListEl *new_el ); static void colm_list_add_before( List *list, ListEl *next_el, ListEl *new_el); -void colm_list_prepend( List *list, ListEl *newEl ); -void colm_list_append( List *list, ListEl *newEl ); ListEl *colm_list_detach( List *list, ListEl *el ); +void colm_list_prepend( List *list, ListEl *newEl ) +{ + colm_list_add_before( list, list->head, newEl ); +} + +void colm_list_append( List *list, ListEl *newEl ) +{ + colm_list_add_after( list, list->tail, newEl ); +} + +ListEl *colm_list_detach_head( List *list ) +{ + return colm_list_detach( list, list->head ); +} + +ListEl *colm_list_detach_tail( List *list ) +{ + return colm_list_detach( list, list->tail ); +} + +long colm_list_length( List *list ) +{ + return list->listLen; +} + void colm_vlist_append( struct colm_program *prg, List *list, Value value ) { struct colm_struct *s = colm_struct_new( prg, list->genericInfo->elStructId ); @@ -87,31 +110,6 @@ Value colm_vlist_detach_head( struct colm_program *prg, List *list ) return val; } -void colm_list_prepend( List *list, ListEl *newEl ) -{ - colm_list_add_before( list, list->head, newEl ); -} - -void colm_list_append( List *list, ListEl *newEl ) -{ - colm_list_add_after( list, list->tail, newEl ); -} - - -ListEl *colm_list_detach_head( List *list ) -{ - return colm_list_detach( list, list->head ); -} - -ListEl *colm_list_detach_tail( List *list ) -{ - return colm_list_detach( list, list->tail ); -} - -long colm_list_length( List *list ) -{ - return list->listLen; -} static void colm_list_add_after( List *list, ListEl *prev_el, ListEl *new_el ) { diff --git a/src/loadcolm.cc b/src/loadcolm.cc index 1028da7a..97388eca 100644 --- a/src/loadcolm.cc +++ b/src/loadcolm.cc @@ -828,36 +828,19 @@ struct LoadColm return repeatType; } - BstSet<String, CmpStr> defined; - - void structHead2( const InputLoc &loc, - const String &data, ObjectDef::Type objectType ) - { - Namespace *inNspace = pd->rootNamespace; - - ObjectDef *objectDef = ObjectDef::cons( objectType, - data, pd->nextObjectId++ ); - - StructDef *context = new StructDef( loc, data, objectDef ); - structStack.push( context ); - - inNspace->structDefList.append( context ); - - /* Make the namespace for the struct. */ - createNamespace( loc, data ); - } + BstSet<String, CmpStr> genericElDefined; TypeRef *walkValueList( type_ref typeRef ) { TypeRef *valType = walkTypeRef( typeRef._type_ref() ); /* Create the value list element. */ - String name( 32, "vlist_el_%s", valType->stringify().data ); + String name( 32, "vlist_el_%s", valType->stringify().c_str() ); - if ( !defined.find( name ) ) { - defined.insert( name ); + if ( !genericElDefined.find( name ) ) { + genericElDefined.insert( name ); - structHead2( internal, name, ObjectDef::StructType ); + structHead( internal, pd->rootNamespace, name, ObjectDef::StructType ); /* Var def. */ String id = "value"; @@ -881,13 +864,13 @@ struct LoadColm TypeRef *keyType = walkTypeRef( typeRef.KeyType() ); TypeRef *valType = walkTypeRef( typeRef.ValType() ); - String name( 32, "vmap_el_%s_%s", keyType->stringify().data, - valType->stringify().data ); + String name( 32, "vmap_el_%s_%s", keyType->stringify().c_str(), + valType->stringify().c_str() ); - if ( !defined.find( name ) ) { - defined.insert( name ); + if ( !genericElDefined.find( name ) ) { + genericElDefined.insert( name ); - structHead2( internal, name, ObjectDef::StructType ); + structHead( internal, pd->rootNamespace, name, ObjectDef::StructType ); /* Var def. */ String id = "value"; @@ -2327,7 +2310,7 @@ struct LoadColm void walkStructDef( struct_def structDef ) { String name = structDef.id().data(); - structHead( structDef.id().loc(), name, ObjectDef::StructType ); + structHead( structDef.id().loc(), curNspace(), name, ObjectDef::StructType ); _repeat_struct_item structItemList = structDef.ItemList(); while ( !structItemList.end() ) { diff --git a/src/parser.cc b/src/parser.cc index 5fd06bb1..5ce080c2 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -98,7 +98,7 @@ void BaseParser::mapElDef( String name, TypeRef *keyType ) void BaseParser::argvDecl() { String structName = "argv_el"; - structHead( internal, structName, ObjectDef::StructType ); + structHead( internal, pd->rootNamespace, structName, ObjectDef::StructType ); /* First the argv value. */ String name = "value"; @@ -264,8 +264,9 @@ LexJoin *BaseParser::literalJoin( const InputLoc &loc, const String &data ) return join; } -void BaseParser::defineToken( const InputLoc &loc, String name, LexJoin *join, ObjectDef *objectDef, - CodeBlock *transBlock, bool ignore, bool noPreIgnore, bool noPostIgnore ) +void BaseParser::defineToken( const InputLoc &loc, String name, LexJoin *join, + ObjectDef *objectDef, CodeBlock *transBlock, bool ignore, + bool noPreIgnore, bool noPostIgnore ) { bool pushedRegion = false; if ( !insideRegion() ) { @@ -982,11 +983,9 @@ void BaseParser::structVarDef( const InputLoc &loc, ObjectField *objField ) object->rootScope->insertField( objField->name, objField ); } -void BaseParser::structHead( const InputLoc &loc, +void BaseParser::structHead( const InputLoc &loc, Namespace *inNspace, const String &data, ObjectDef::Type objectType ) { - Namespace *inNspace = curNspace(); - ObjectDef *objectDef = ObjectDef::cons( objectType, data, pd->nextObjectId++ ); diff --git a/src/parser.h b/src/parser.h index a568eeb8..b38e9e5b 100644 --- a/src/parser.h +++ b/src/parser.h @@ -140,7 +140,8 @@ struct BaseParser LangExpr *require( const InputLoc &loc, LangVarRef *varRef, PatternItemList *list ); void structVarDef( const InputLoc &loc, ObjectField *objField ); - void structHead( const InputLoc &loc, const String &data, ObjectDef::Type objectType ); + void structHead( const InputLoc &loc, Namespace *inNspace, + const String &data, ObjectDef::Type objectType ); StmtList *appendStatement( StmtList *stmtList, LangStmt *stmt ); ParameterList *appendParam( ParameterList *paramList, ObjectField *objField ); ObjectField *addParam( const InputLoc &loc, diff --git a/src/parsetree.cc b/src/parsetree.cc index cc9c6bc6..07f8a97f 100644 --- a/src/parsetree.cc +++ b/src/parsetree.cc @@ -37,6 +37,50 @@ ostream &operator<<( ostream &out, const NameRef &nameRef ); ostream &operator<<( ostream &out, const NameInst &nameInst ); ostream &operator<<( ostream &out, const Token &token ); +string TypeRef::stringify() +{ + string s; + switch ( type ) { + case Unspecified: + s = "unspecified"; + break; + case Name: + s = typeName; + break; + case Literal: + s = "literal"; + break; + case Iterator: + s = "iterator"; + break; + case List: + s = "list"; + break; + case ValueList: + s = "vlist"; + break; + case ListEl: + s = "listel"; + break; + case Map: + s = "map"; + break; + case ValueMap: + s = "vmap"; + break; + case MapEl: + s = "mapel"; + break; + case Parser: + s = "parser"; + break; + case Ref: + s = "ref"; + break; + } + return s; +} + /* Convert the literal string which comes in from the scanner into an array of * characters with escapes and options interpreted. Also null terminates the * string. Though this null termination should not be relied on for diff --git a/src/parsetree.h b/src/parsetree.h index 8e26bfbc..8afb63c5 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -24,6 +24,7 @@ #include <iostream> #include <string.h> +#include <string> #include "global.h" #include "avlmap.h" @@ -2219,49 +2220,7 @@ struct TypeRef GenericType *generic; TypeRef *searchTypeRef; - String stringify() - { - String s; - switch ( type ) { - case Unspecified: - s = "unspecified"; - break; - case Name: - s = typeName; - break; - case Literal: - s = "literal"; - break; - case Iterator: - s = "iterator"; - break; - case List: - s = "list"; - break; - case ValueList: - s = "vlist"; - break; - case ListEl: - s = "listel"; - break; - case Map: - s = "map"; - break; - case ValueMap: - s = "vmap"; - break; - case MapEl: - s = "mapel"; - break; - case Parser: - s = "parser"; - break; - case Ref: - s = "ref"; - break; - } - return s; - } + std::string stringify(); }; typedef DList<ObjectField> ParameterList; diff --git a/src/program.c b/src/program.c index cdd0f335..66fe3509 100644 --- a/src/program.c +++ b/src/program.c @@ -188,18 +188,8 @@ Program *colm_new_program( RuntimeData *rtd ) initPoolAlloc( &prg->headPool, sizeof(Head) ); initPoolAlloc( &prg->locationPool, sizeof(Location) ); - Int *trueInt = (Int*) 1; //treeAllocate( prg ); -// trueInt->id = LEL_ID_BOOL; -// trueInt->refs = 1; -// trueInt->value = 1; -// - Int *falseInt = (Int*) 0; //treeAllocate( prg ); -// falseInt->id = LEL_ID_BOOL; -// falseInt->refs = 1; -// falseInt->value = 0; - - prg->trueVal = (Tree*)trueInt; - prg->falseVal = (Tree*)falseInt; + prg->trueVal = (Tree*) 1; + prg->falseVal = (Tree*) 0; /* Allocate the global variable. */ colm_alloc_global( prg ); @@ -1685,13 +1685,6 @@ struct colm_location *colm_find_location( Program *prg, Tree *tree ) return locSearch( prg, tree ); } -Object *newList2( Program *prg ) -{ - Object *obj = (Object *) malloc( sizeof( Object ) ); - memset( obj, 0, sizeof(*obj) ); - return obj; -} - /* * Tree Printing */ @@ -218,11 +218,6 @@ typedef struct _UserIter long searchId; } UserIter; -typedef struct object -{ - struct object *prev, *next; -} Object; - void treeUpref( Tree *tree ); void treeDownref( struct colm_program *prg, Tree **sp, Tree *tree ); long cmpTree( struct colm_program *prg, const Tree *tree1, const Tree *tree2 ); @@ -252,8 +247,6 @@ Tree *constructObject( struct colm_program *prg, Kid *kid, Tree **bindings, long langElId ); Tree *constructToken( struct colm_program *prg, Tree **args, long nargs ); -Object *newList2( struct colm_program *prg ); - int testFalse( struct colm_program *prg, Tree *tree ); Tree *makeTree( struct colm_program *prg, Tree **args, long nargs ); Stream *openFile( struct colm_program *prg, Tree *name, Tree *mode ); |