diff options
author | Adrian Thurston <thurston@complang.org> | 2011-07-10 19:29:04 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2011-07-10 19:29:04 +0000 |
commit | 71b76259f4e7a33f8f3cf283f779ae59ac4cc607 (patch) | |
tree | 701ca0292fb700a95746fa1815cedace2047d99f | |
parent | 61423c9f6f28e2e4ce90fc1d823637b7f5b3308c (diff) | |
download | colm-71b76259f4e7a33f8f3cf283f779ae59ac4cc607.tar.gz |
Rest of the generic types (map, list, vector) now supported in type ref.
refs #295.
-rw-r--r-- | colm/parsetree.h | 11 | ||||
-rw-r--r-- | colm/resolve.cc | 87 | ||||
-rw-r--r-- | test/accum1.lm | 5 | ||||
-rw-r--r-- | test/accum2.lm | 3 | ||||
-rw-r--r-- | test/accum3.lm | 4 | ||||
-rw-r--r-- | test/accumbt.lm | 4 | ||||
-rw-r--r-- | test/argv2.lm | 4 | ||||
-rw-r--r-- | test/cxx/cxx.lm | 9 | ||||
-rw-r--r-- | test/dns.lm | 6 |
9 files changed, 95 insertions, 38 deletions
diff --git a/colm/parsetree.h b/colm/parsetree.h index ec414c58..4c95dc39 100644 --- a/colm/parsetree.h +++ b/colm/parsetree.h @@ -1360,7 +1360,7 @@ struct UniqueMap : public AvlTreeEl<UniqueMap> { UniqueMap( UniqueType *key, UniqueType *value ) : - key(key), value(value) {} + key(key), value(value), generic(0) {} UniqueType *key; UniqueType *value; @@ -1383,9 +1383,10 @@ struct UniqueList : public AvlTreeEl<UniqueList> { UniqueList( UniqueType *value ) : - value(value) {} + value(value), generic(0) {} UniqueType *value; + GenericType *generic; }; struct CmpUniqueList @@ -1403,9 +1404,10 @@ struct UniqueVector : public AvlTreeEl<UniqueVector> { UniqueVector( UniqueType *value ) : - value(value) {} + value(value), generic(0) {} UniqueType *value; + GenericType *generic; }; struct CmpUniqueVector @@ -1423,9 +1425,10 @@ struct UniqueAccum : public AvlTreeEl<UniqueAccum> { UniqueAccum( UniqueType *parseType ) : - parseType(parseType) {} + parseType(parseType), generic(0) {} UniqueType *parseType; + GenericType *generic; }; struct CmpUniqueAccum diff --git a/colm/resolve.cc b/colm/resolve.cc index 1ffc6c0a..a5e2f3d1 100644 --- a/colm/resolve.cc +++ b/colm/resolve.cc @@ -115,23 +115,92 @@ UniqueType *TypeRef::lookupTypeMap( ParseData *pd ) UniqueType *TypeRef::lookupTypeList( ParseData *pd ) { -// UniqueType *utValue = typeRef1->lookupType( pd ); -// pd->uniqueListMap.find( utValue ); - return 0; + /* Lookup up the qualifiction and then the name. */ + nspace = nspaceQual->getQual( pd ); + + UniqueType *utValue = typeRef1->lookupType( pd ); + + UniqueList searchKey( utValue ); + UniqueList *inMap = pd->uniqueListMap.find( &searchKey ); + if ( inMap == 0 ) { + inMap = new UniqueList( utValue ); + pd->uniqueListMap.insert( inMap ); + + /* FIXME: Need uniqe name allocator for types. */ + static int listId = 0; + String name( 36, "__list%d", listId++ ); + + GenericType *generic = new GenericType( name, GEN_LIST, + pd->nextGenericId++, 0/*langEl*/, typeRef1 ); + + nspace->genericList.append( generic ); + + generic->declare( pd, nspace ); + + inMap->generic = generic; + } + + return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl ); } UniqueType *TypeRef::lookupTypeVector( ParseData *pd ) { -// UniqueType *utValue = typeRef1->lookupType( pd ); -// pd->uniqueVectorMap.find( utValue ); - return 0; + /* Lookup up the qualifiction and then the name. */ + nspace = nspaceQual->getQual( pd ); + + UniqueType *utValue = typeRef1->lookupType( pd ); + + UniqueVector searchKey( utValue ); + UniqueVector *inMap = pd->uniqueVectorMap.find( &searchKey ); + if ( inMap == 0 ) { + inMap = new UniqueVector( utValue ); + pd->uniqueVectorMap.insert( inMap ); + + /* FIXME: Need uniqe name allocator for types. */ + static int vectorId = 0; + String name( 36, "__vector%d", vectorId++ ); + + GenericType *generic = new GenericType( name, GEN_VECTOR, + pd->nextGenericId++, 0/*langEl*/, typeRef1 ); + + nspace->genericList.append( generic ); + + generic->declare( pd, nspace ); + + inMap->generic = generic; + } + + return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl ); } UniqueType *TypeRef::lookupTypeAccum( ParseData *pd ) { -// UniqueType *utParse = typeRef1->lookupType( pd ); -// pd->uniqueAccumMap.find( utValue ); - return 0; + /* Lookup up the qualifiction and then the name. */ + nspace = nspaceQual->getQual( pd ); + + UniqueType *utParse = typeRef1->lookupType( pd ); + + UniqueAccum searchKey( utParse ); + UniqueAccum *inMap = pd->uniqueAccumMap.find( &searchKey ); + if ( inMap == 0 ) { + inMap = new UniqueAccum( utParse ); + pd->uniqueAccumMap.insert( inMap ); + + /* FIXME: Need uniqe name allocator for types. */ + static int accumId = 0; + String name( 36, "__accum%d", accumId++ ); + + GenericType *generic = new GenericType( name, GEN_PARSER, + pd->nextGenericId++, 0/*langEl*/, typeRef1 ); + + nspace->genericList.append( generic ); + + generic->declare( pd, nspace ); + + inMap->generic = generic; + } + + return pd->findUniqueType( TYPE_TREE, inMap->generic->langEl ); } void TypeRef::resolveRepeat( ParseData *pd ) diff --git a/test/accum1.lm b/test/accum1.lm index 47f8665c..5203a1d6 100644 --- a/test/accum1.lm +++ b/test/accum1.lm @@ -14,10 +14,7 @@ def start Input: start = parse start( stdin ) -accum output - [start] - -Output: output = construct output [] +cons Output: accum<start> [] for Id: id in Input { Output << diff --git a/test/accum2.lm b/test/accum2.lm index 139d6c20..30dca44f 100644 --- a/test/accum2.lm +++ b/test/accum2.lm @@ -26,8 +26,7 @@ context ctx } -parser start_parser [ctx::start] -SP: start_parser = cons start_parser[] +cons SP: parser<ctx::start> [] SP.ctx = cons ctx [] SP << stdin Input: ctx::start = SP.finish() diff --git a/test/accum3.lm b/test/accum3.lm index 40508a0d..81003b0d 100644 --- a/test/accum3.lm +++ b/test/accum3.lm @@ -21,9 +21,7 @@ def item def args [word zero item*] -accum arg_parser [args] - -ArgParser: arg_parser = cons arg_parser [] +cons ArgParser: parser<args> [] ArgV: argv_list ArgV = argv for A: str in ArgV diff --git a/test/accumbt.lm b/test/accumbt.lm index 09abf8a6..fa7317a4 100644 --- a/test/accumbt.lm +++ b/test/accumbt.lm @@ -25,9 +25,7 @@ token EOF /ws+/ def start [prefix choice1 choice2 string id id EOF] -accum input [start] - -I: input = construct input [] +cons I: parser<start> [] I << " id " I << " 77 " diff --git a/test/argv2.lm b/test/argv2.lm index 318a3f14..67b38d91 100644 --- a/test/argv2.lm +++ b/test/argv2.lm @@ -38,9 +38,7 @@ def args # The argument parser. Using an accumulator so we can send nulls after each # arg. -accum arg_parser [args] -ArgParser: arg_parser = - construct arg_parser [] +cons ArgParser: parser<args>[] # Parse the args and extract the result into Args. ArgV: argv_list = argv diff --git a/test/cxx/cxx.lm b/test/cxx/cxx.lm index db2ba1ee..a8dfd37c 100644 --- a/test/cxx/cxx.lm +++ b/test/cxx/cxx.lm @@ -2,9 +2,6 @@ # Data types for global data. # -# Map definition -map object_map [str object_list] - # Language objects. def lang_object typeId: int @@ -13,7 +10,7 @@ def lang_object # If the object is a typedef, this points to the real object. typedefOf: ptr lang_object - objectMap: object_map + objectMap: map<str object_list> inherited: object_list lookupParent: ptr lang_object specializationOf: ptr lang_object @@ -270,7 +267,7 @@ ptr lang_object createLangObject( typeId: int name: str lookupParent: ptr lang_o obj: ptr lang_object = new construct lang_object( typeId: typeId name: name - objectMap: construct object_map [] + objectMap: construct map<str object_list> [] inherited: construct object_list [] lookupParent: lookupParent ) [] return obj @@ -2141,7 +2138,7 @@ int printObject( indent: str obj: ptr lang_object ) if obj->objectMap.length > 0 print( ' {\n' ) - ChildNames: object_map = obj->objectMap + ChildNames: map<str object_list> = obj->objectMap for MapEl: object_list in child( ChildNames ) { for Obj: ptr lang_object in MapEl printObject( indent + ' ' Obj ) diff --git a/test/dns.lm b/test/dns.lm index 0528242e..98205d13 100644 --- a/test/dns.lm +++ b/test/dns.lm @@ -437,9 +437,7 @@ int print_RR_A( s: start ) } } -map name_map [int name] - -int print_name( n: name m: name_map ) +int print_name( n: name m: map<int name> ) { for P: name_part in n { match P [part_len D:nbytes] @@ -459,7 +457,7 @@ int print_name( n: name m: name_map ) int print_all_names( s: start ) { for M: message in s { - construct m: name_map [] + construct m: map<int name> [] O: octet = octet in M |