diff options
author | Adrian Thurston <thurston@complang.org> | 2015-02-14 16:45:30 -0500 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-02-14 16:45:30 -0500 |
commit | bbd7ab2bac367385461aca490cf3067bd9f1a78d (patch) | |
tree | 070d017ade4fc3d9e5b392fab49c215e2a5159ab | |
parent | 63e23d75bacdca95863026476b90c76292ec0807 (diff) | |
download | colm-bbd7ab2bac367385461aca490cf3067bd9f1a78d.tar.gz |
need to make vlist and vmap elment structs unique
-rw-r--r-- | src/declare.cc | 8 | ||||
-rw-r--r-- | src/loadcolm.cc | 79 | ||||
-rw-r--r-- | src/parsetree.h | 44 | ||||
-rw-r--r-- | src/resolve.cc | 4 |
4 files changed, 103 insertions, 32 deletions
diff --git a/src/declare.cc b/src/declare.cc index edb2fab7..cde56548 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -226,7 +226,7 @@ LangEl *declareLangEl( Compiler *pd, Namespace *nspace, * it is not there then it will be inserted and last found will be set to it. */ TypeMapEl *inDict = nspace->typeMap.find( data ); if ( inDict != 0 ) - error() << "'" << data << "' already defined as something else" << endp; + error() << "language element '" << data << "' already defined as something else" << endp; /* Language element not there. Make the new lang el and insert.. */ LangEl *langEl = new LangEl( nspace, data, type ); @@ -243,9 +243,9 @@ StructEl *declareStruct( Compiler *pd, Namespace *inNspace, if ( inNspace != 0 ) { TypeMapEl *inDict = inNspace->typeMap.find( data ); if ( inDict != 0 ) - error() << "'" << data << "' already defined as something else" << endp; + error() << "struct '" << data << "' already defined as something else" << endp; } - + StructEl *structEl = new StructEl( data, structDef ); pd->structEls.append( structEl ); structDef->structEl = structEl; @@ -274,7 +274,7 @@ void declareTypeAlias( Compiler *pd, Namespace *nspace, * it is not there then it will be inserted and last found will be set to it. */ TypeMapEl *inDict = nspace->typeMap.find( data ); if ( inDict != 0 ) - error() << "'" << data << "' already defined as something else" << endp; + error() << "alias '" << data << "' already defined as something else" << endp; /* Language element not there. Make the new lang el and insert. */ TypeMapEl *typeMapEl = new TypeMapEl( TypeMapEl::AliasType, data, typeRef ); diff --git a/src/loadcolm.cc b/src/loadcolm.cc index a32d4cef..1028da7a 100644 --- a/src/loadcolm.cc +++ b/src/loadcolm.cc @@ -828,28 +828,51 @@ 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 ); + } + TypeRef *walkValueList( type_ref typeRef ) { TypeRef *valType = walkTypeRef( typeRef._type_ref() ); /* Create the value list element. */ - String name = "vlist_el"; - structHead( internal, name, ObjectDef::StructType ); + String name( 32, "vlist_el_%s", valType->stringify().data ); - /* Var def. */ - String id = "value"; - ObjectField *elValObjField = ObjectField::cons( internal, - ObjectField::StructFieldType, valType, id ); - structVarDef( internal, elValObjField ); + if ( !defined.find( name ) ) { + defined.insert( name ); - /* List El. */ - listElDef( "el" ); + structHead2( internal, name, ObjectDef::StructType ); - structStack.pop(); - namespaceStack.pop(); + /* Var def. */ + String id = "value"; + ObjectField *elValObjField = ObjectField::cons( internal, + ObjectField::StructFieldType, valType, id ); + structVarDef( internal, elValObjField ); + + /* List El. */ + listElDef( "el" ); + + structStack.pop(); + namespaceStack.pop(); + } - TypeRef *elType = TypeRef::cons( internal, - emptyNspaceQual(), "vlist_el" ); + TypeRef *elType = TypeRef::cons( typeRef.loc(), emptyNspaceQual(), name ); return TypeRef::cons( typeRef.loc(), TypeRef::ValueList, 0, elType, valType ); } @@ -858,24 +881,28 @@ struct LoadColm TypeRef *keyType = walkTypeRef( typeRef.KeyType() ); TypeRef *valType = walkTypeRef( typeRef.ValType() ); - String name = "vmap_el"; - structHead( internal, name, ObjectDef::StructType ); + String name( 32, "vmap_el_%s_%s", keyType->stringify().data, + valType->stringify().data ); - /* Var def. */ - String id = "value"; - ObjectField *elValObjField = ObjectField::cons( internal, - ObjectField::StructFieldType, valType, id ); - structVarDef( internal, elValObjField ); + if ( !defined.find( name ) ) { + defined.insert( name ); + + structHead2( internal, name, ObjectDef::StructType ); - /* Map El. */ - mapElDef( "el", keyType ); + /* Var def. */ + String id = "value"; + ObjectField *elValObjField = ObjectField::cons( internal, + ObjectField::StructFieldType, valType, id ); + structVarDef( internal, elValObjField ); - structStack.pop(); - namespaceStack.pop(); + /* Map El. */ + mapElDef( "el", keyType ); - TypeRef *elType = TypeRef::cons( internal, - emptyNspaceQual(), "vmap_el" ); + structStack.pop(); + namespaceStack.pop(); + } + TypeRef *elType = TypeRef::cons( typeRef.loc(), emptyNspaceQual(), name ); return TypeRef::cons( typeRef.loc(), TypeRef::ValueMap, 0, keyType, elType, valType ); } diff --git a/src/parsetree.h b/src/parsetree.h index 0509dbf4..8e26bfbc 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -2218,6 +2218,50 @@ struct TypeRef UniqueType *searchUniqueType; 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; + } }; typedef DList<ObjectField> ParameterList; diff --git a/src/resolve.cc b/src/resolve.cc index 268f9fd0..5f8bfaa4 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -80,7 +80,7 @@ UniqueType *TypeRef::resolveTypeName( Compiler *pd ) nspace = nspace->parentNamespace; } - error(loc) << "unknown type in typeof expression" << endp; + error(loc) << "unknown type " << typeName << " in typeof expression" << endp; return 0; } @@ -110,7 +110,7 @@ UniqueType *TypeRef::resolveTypeLiteral( Compiler *pd ) nspace = nspace->parentNamespace; } - error(loc) << "unknown type in typeof expression" << endp; + error(loc) << "unknown type " << typeName << " in typeof expression" << endp; return 0; } |