diff options
author | Adrian Thurston <thurston@complang.org> | 2015-08-08 11:40:19 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2015-08-08 11:40:19 -0400 |
commit | 42314c5f0f87c45f6968c7c8fcfbfb8eae9f8ad6 (patch) | |
tree | b5d7d144fe4be7181e3cd4c4292ef9efd6b2805e /src | |
parent | 835c359b551831b8272dc71e5feaf702aa189576 (diff) | |
download | colm-42314c5f0f87c45f6968c7c8fcfbfb8eae9f8ad6.tar.gz |
moved MethodMap into NameScope, converted some ptrs to objs
Diffstat (limited to 'src')
-rw-r--r-- | src/declare.cc | 17 | ||||
-rw-r--r-- | src/exports.cc | 16 | ||||
-rw-r--r-- | src/lookup.cc | 16 | ||||
-rw-r--r-- | src/parsetree.h | 23 | ||||
-rw-r--r-- | src/pdabuild.cc | 4 | ||||
-rw-r--r-- | src/resolve.cc | 8 | ||||
-rw-r--r-- | src/synthesis.cc | 16 |
7 files changed, 48 insertions, 52 deletions
diff --git a/src/declare.cc b/src/declare.cc index bce148bc..69c33a91 100644 --- a/src/declare.cc +++ b/src/declare.cc @@ -56,7 +56,7 @@ ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj, ObjectMethod *objMethod = new ObjectMethod( retType, name, methIdWV, methIdWC, 0, 0, 0, isConst ); objMethod->useFnInstr = useFnInstr; - obj->methodMap->insert( name, objMethod ); + obj->rootScope->methodMap.insert( name, objMethod ); if ( useGeneric ) { objMethod->useGenericId = true; @@ -73,7 +73,7 @@ ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj, ObjectMethod *objMethod = new ObjectMethod( retType, name, methIdWV, methIdWC, 1, args, 0, isConst ); objMethod->useFnInstr = useFnInstr; - obj->methodMap->insert( name, objMethod ); + obj->rootScope->methodMap.insert( name, objMethod ); if ( useGeneric ) { objMethod->useGenericId = true; @@ -92,7 +92,7 @@ ObjectMethod *initFunction( UniqueType *retType, ObjectDef *obj, ObjectMethod *objMethod = new ObjectMethod( retType, name, methIdWV, methIdWC, 2, args, 0, isConst ); objMethod->useFnInstr = useFnInstr; - obj->methodMap->insert( name, objMethod ); + obj->rootScope->methodMap.insert( name, objMethod ); if ( useGeneric ) { objMethod->useGenericId = true; @@ -115,7 +115,7 @@ void NameScope::insertField( const String &name, ObjectField *value ) ObjectField *ObjectDef::checkRedecl( NameScope *inScope, const String &name ) { - FieldMapEl *objDefMapEl = inScope->fieldMap->find( name ); + FieldMapEl *objDefMapEl = inScope->fieldMap.find( name ); if ( objDefMapEl != 0 ) return objDefMapEl->value; return 0; @@ -123,15 +123,14 @@ ObjectField *ObjectDef::checkRedecl( NameScope *inScope, const String &name ) void ObjectDef::insertField( NameScope *inScope, const String &name, ObjectField *value ) { - inScope->fieldMap->insert( name, value ); - fieldList->append( value ); + inScope->fieldMap.insert( name, value ); + fieldList.append( value ); value->scope = inScope; } NameScope *ObjectDef::pushScope( NameScope *curScope ) { NameScope *newScope = new NameScope; - newScope->fieldMap = new FieldMap; newScope->owner = this; newScope->parentScope = curScope; @@ -1372,7 +1371,7 @@ void Compiler::makeFuncVisible( Function *func, bool isUserIter ) objMethod->iterDef = uiter; } - globalObjectDef->methodMap->insert( func->name, objMethod ); + globalObjectDef->rootScope->methodMap.insert( func->name, objMethod ); func->objMethod = objMethod; } @@ -1396,7 +1395,7 @@ void Compiler::makeInHostVisible( Function *func ) objMethod->useCallObj = false; objMethod->func = func; - globalObjectDef->methodMap->insert( func->name, objMethod ); + globalObjectDef->rootScope->methodMap.insert( func->name, objMethod ); func->objMethod = objMethod; } diff --git a/src/exports.cc b/src/exports.cc index f32e5a2f..b5b2f7a6 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -118,9 +118,9 @@ void Compiler::generateExports() out << " " << lel->fullName << "( colm_program *prg, colm_tree *tree ) : __prg(prg), __tree(tree) {}\n"; - if ( lel->objectDef != 0 && lel->objectDef->fieldList != 0 ) { - FieldList *fieldList = lel->objectDef->fieldList; - for ( FieldList::Iter ofi = *fieldList; ofi.lte(); ofi++ ) { + if ( lel->objectDef != 0 ) { + FieldList &fieldList = lel->objectDef->fieldList; + for ( FieldList::Iter ofi = fieldList; ofi.lte(); ofi++ ) { ObjectField *field = ofi->value; if ( ( field->useOffset() && field->typeRef != 0 ) || field->isRhsGet() ) { UniqueType *ut = field->typeRef->resolveType( this ); @@ -167,7 +167,7 @@ void Compiler::generateExports() out << "\n"; } - for ( FieldList::Iter of = *globalObjectDef->fieldList; of.lte(); of++ ) { + for ( FieldList::Iter of = globalObjectDef->fieldList; of.lte(); of++ ) { ObjectField *field = of->value; if ( field->isExport ) { UniqueType *ut = field->typeRef->resolveType(this); @@ -206,9 +206,9 @@ void Compiler::generateExportsImpl() /* Function implementations. */ for ( LelList::Iter lel = langEls; lel.lte(); lel++ ) { - if ( lel->objectDef != 0 && lel->objectDef->fieldList != 0 ) { - FieldList *fieldList = lel->objectDef->fieldList; - for ( FieldList::Iter ofi = *fieldList; ofi.lte(); ofi++ ) { + if ( lel->objectDef != 0 ) { + FieldList &fieldList = lel->objectDef->fieldList; + for ( FieldList::Iter ofi = fieldList; ofi.lte(); ofi++ ) { ObjectField *field = ofi->value; if ( field->useOffset() && field->typeRef != 0 ) { UniqueType *ut = field->typeRef->resolveType( this ); @@ -265,7 +265,7 @@ void Compiler::generateExportsImpl() out << "\n"; - for ( FieldList::Iter of = *globalObjectDef->fieldList; of.lte(); of++ ) { + for ( FieldList::Iter of = globalObjectDef->fieldList; of.lte(); of++ ) { ObjectField *field = of->value; if ( field->isExport ) { UniqueType *ut = field->typeRef->resolveType(this); diff --git a/src/lookup.cc b/src/lookup.cc index 90e8c051..ea4885d2 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -49,7 +49,7 @@ ObjectDef *UniqueType::objectDef() ObjectField *ObjectDef::findFieldInScope( const NameScope *inScope, const String &name ) const { - FieldMapEl *objDefMapEl = inScope->fieldMap->find( name ); + FieldMapEl *objDefMapEl = inScope->fieldMap.find( name ); if ( objDefMapEl != 0 ) return objDefMapEl->value; if ( inScope->parentScope != 0 ) @@ -62,9 +62,9 @@ ObjectField *NameScope::findField( const String &name ) const return owner->findFieldInScope( this, name ); } -ObjectMethod *ObjectDef::findMethod( const String &name ) const +ObjectMethod *NameScope::findMethod( const String &name ) const { - MethodMapEl *methodMapEl = methodMap->find( name ); + MethodMapEl *methodMapEl = methodMap.find( name ); if ( methodMapEl != 0 ) return methodMapEl->value; return 0; @@ -125,7 +125,7 @@ bool LangVarRef::isLocalRef() const } else if ( scope->findField( name ) != 0 ) return true; - else if ( scope->owner->findMethod( name ) != 0 ) + else if ( scope->findMethod( name ) != 0 ) return true; return false; @@ -140,7 +140,7 @@ bool LangVarRef::isContextRef() const } else if ( context->objectDef->rootScope->findField( name ) != 0 ) return true; - else if ( context->objectDef->findMethod( name ) != 0 ) + else if ( context->objectDef->rootScope->findMethod( name ) != 0 ) return true; } @@ -218,8 +218,7 @@ VarRefLookup LangVarRef::lookupMethod( Compiler *pd ) const VarRefLookup lookup = lookupObj( pd ); /* Find the method. */ - assert( lookup.inObject->methodMap != 0 ); - ObjectMethod *method = lookup.inObject->findMethod( name ); + ObjectMethod *method = lookup.inScope->findMethod( name ); if ( method == 0 ) { /* Not found as a method, try it as an object on which we will call a * default function. */ @@ -229,8 +228,7 @@ VarRefLookup LangVarRef::lookupMethod( Compiler *pd ) const VarRefLookup lookup = lookupObj( pd ); /* Find the method. */ - assert( lookup.inObject->methodMap != 0 ); - method = lookup.inObject->findMethod( "finish" ); + method = lookup.inScope->findMethod( "finish" ); if ( method == 0 ) error(loc) << "cannot find " << name << "(...) in object" << endp; } diff --git a/src/parsetree.h b/src/parsetree.h index 693260f0..d028b3f7 100644 --- a/src/parsetree.h +++ b/src/parsetree.h @@ -65,6 +65,9 @@ struct TypeAlias; struct RegionSet; struct NameScope; struct IterCall; +struct TemplateType; +struct ObjectMethod; + /* * Code Vector @@ -2315,9 +2318,6 @@ struct ObjectMethod GenericType *generic; }; -typedef AvlMap<String, ObjectMethod*, CmpStr> MethodMap; -typedef AvlMapEl<String, ObjectMethod*> MethodMapEl; - struct RhsVal { RhsVal( ProdEl *prodEl ) @@ -2469,7 +2469,10 @@ typedef DListVal<ObjectField*> FieldList; typedef DList<ObjectField> ParameterList; -struct TemplateType; + +typedef AvlMap<String, ObjectMethod*, CmpStr> MethodMap; +typedef AvlMapEl<String, ObjectMethod*> MethodMapEl; + /* tree_t of name scopes for an object def. All of the object fields inside this * tree live in one object def. This is used for scoping names in functions. */ @@ -2483,7 +2486,8 @@ struct NameScope {} ObjectDef *owner; - FieldMap *fieldMap; + FieldMap fieldMap; + MethodMap methodMap; NameScope *parentScope; DList<NameScope> children; @@ -2505,6 +2509,7 @@ struct NameScope } ObjectField *findField( const String &name ) const; + ObjectMethod *findMethod( const String &name ) const; ObjectField *checkRedecl( const String &name ); void insertField( const String &name, ObjectField *value ); @@ -2536,18 +2541,13 @@ struct ObjectDef o->rootScope = new NameScope; o->rootScope->owner = o; - o->rootScope->fieldMap = new FieldMap; - - o->fieldList = new FieldList; - o->methodMap = new MethodMap; return o; } Type type; String name; - FieldList *fieldList; - MethodMap *methodMap; + FieldList fieldList; NameScope *rootScope; @@ -2560,7 +2560,6 @@ struct ObjectDef void referenceField( Compiler *pd, ObjectField *field ); void placeField( Compiler *pd, ObjectField *field ); void createCode( Compiler *pd, CodeVect &code ); - ObjectMethod *findMethod( const String &name ) const; ObjectField *findFieldInScope( const NameScope *scope, const String &name ) const; ObjectField *checkRedecl( NameScope *inScope, const String &name ); void insertField( NameScope *inScope, const String &name, ObjectField *value ); diff --git a/src/pdabuild.cc b/src/pdabuild.cc index 4efe142d..707f113d 100644 --- a/src/pdabuild.cc +++ b/src/pdabuild.cc @@ -1294,7 +1294,7 @@ struct local_info *Compiler::makeLocalInfo( Locals &locals ) short *Compiler::makeTrees( ObjectDef *objectDef, int &numTrees ) { numTrees = 0; - for ( FieldList::Iter of = *objectDef->fieldList; of.lte(); of++ ) { + for ( FieldList::Iter of = objectDef->fieldList; of.lte(); of++ ) { if ( of->value->exists() ) { UniqueType *ut = of->value->typeRef->resolveType( this ); if ( ut->typeId == TYPE_TREE ) @@ -1306,7 +1306,7 @@ short *Compiler::makeTrees( ObjectDef *objectDef, int &numTrees ) memset( trees, 0, sizeof(short) * numTrees ); short pos = 0; - for ( FieldList::Iter of = *objectDef->fieldList; of.lte(); of++ ) { + for ( FieldList::Iter of = objectDef->fieldList; of.lte(); of++ ) { if ( of->value->exists() ) { UniqueType *ut = of->value->typeRef->resolveType( this ); if ( ut->typeId == TYPE_TREE ) { diff --git a/src/resolve.cc b/src/resolve.cc index 57482b3f..96742435 100644 --- a/src/resolve.cc +++ b/src/resolve.cc @@ -685,7 +685,7 @@ void LangStmt::resolve( Compiler *pd ) const void ObjectDef::resolve( Compiler *pd ) { - for ( FieldList::Iter fli = *fieldList; fli.lte(); fli++ ) { + for ( FieldList::Iter fli = fieldList; fli.lte(); fli++ ) { ObjectField *field = fli->value; if ( field->typeRef != 0 ) @@ -786,19 +786,19 @@ void Compiler::resolveParseTree() ObjectDef *objDef = lel->objectDef; if ( objDef != 0 ) { /* Init all fields of the object. */ - for ( FieldList::Iter f = *objDef->fieldList; f.lte(); f++ ) + for ( FieldList::Iter f = objDef->fieldList; f.lte(); f++ ) f->value->typeRef->resolveType( this ); } } for ( StructElList::Iter sel = structEls; sel.lte(); sel++ ) { ObjectDef *objDef = sel->structDef->objectDef; - for ( FieldList::Iter f = *objDef->fieldList; f.lte(); f++ ) + for ( FieldList::Iter f = objDef->fieldList; f.lte(); f++ ) f->value->typeRef->resolveType( this ); } /* Init all fields of the global object. */ - for ( FieldList::Iter f = *globalObjectDef->fieldList; f.lte(); f++ ) { + for ( FieldList::Iter f = globalObjectDef->fieldList; f.lte(); f++ ) { f->value->typeRef->resolveType( this ); } } diff --git a/src/synthesis.cc b/src/synthesis.cc index 36f781b5..151c941c 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -289,11 +289,11 @@ UniqueType *Compiler::findUniqueType( enum TYPE typeId, GenericType *generic ) ObjectField *ObjectDef::findFieldNum( long offset ) { /* Bounds check. */ - if ( offset >= fieldList->length() ) + if ( offset >= fieldList.length() ) return 0; int fn = 0; - FieldList::Iter field = *fieldList; + FieldList::Iter field = fieldList; while ( fn < offset ) { fn++; field++; @@ -305,7 +305,7 @@ ObjectField *ObjectDef::findFieldNum( long offset ) /* Finds the first field by type. */ ObjectField *ObjectDef::findFieldType( Compiler *pd, UniqueType *ut ) { - for ( FieldList::Iter f = *fieldList; f.lte(); f++ ) { + for ( FieldList::Iter f = fieldList; f.lte(); f++ ) { UniqueType *fUT = f->value->typeRef->resolveType( pd ); if ( fUT == ut ) return f->value; @@ -2613,7 +2613,7 @@ void Compiler::findLocals( ObjectDef *localFrame, CodeBlock *block ) { Locals &locals = block->locals; - for ( FieldList::Iter ol = *localFrame->fieldList; ol.lte(); ol++ ) { + for ( FieldList::Iter ol = localFrame->fieldList; ol.lte(); ol++ ) { ObjectField *el = ol->value; /* FIXME: This test needs to be improved. Match_text was getting @@ -2993,7 +2993,7 @@ void Compiler::placeAllLanguageObjects() ObjectDef *objDef = lel->objectDef; if ( objDef != 0 ) { /* Init all fields of the object. */ - for ( FieldList::Iter f = *objDef->fieldList; f.lte(); f++ ) + for ( FieldList::Iter f = objDef->fieldList; f.lte(); f++ ) objDef->placeField( this, f->value ); } } @@ -3003,14 +3003,14 @@ void Compiler::placeAllStructObjects() { for ( StructElList::Iter s = structEls; s.lte(); s++ ) { ObjectDef *objectDef = s->structDef->objectDef; - for ( FieldList::Iter f = *objectDef->fieldList; f.lte(); f++ ) + for ( FieldList::Iter f = objectDef->fieldList; f.lte(); f++ ) objectDef->placeField( this, f->value ); } } void Compiler::placeFrameFields( ObjectDef *localFrame ) { - for ( FieldList::Iter f = *localFrame->fieldList; f.lte(); f++ ) + for ( FieldList::Iter f = localFrame->fieldList; f.lte(); f++ ) localFrame->placeField( this, f->value ); } @@ -3034,7 +3034,7 @@ void Compiler::placeAllFrameObjects() if ( lel->transBlock != 0 ) { ObjectDef *localFrame = lel->transBlock->localFrame; if ( lel->tokenDef->reCaptureVect.length() > 0 ) { - FieldList::Iter f = *localFrame->fieldList; + FieldList::Iter f = localFrame->fieldList; for ( int i = 0; i < lel->tokenDef->reCaptureVect.length(); i++, f++ ) localFrame->placeField( this, f->value ); } |