Changes in src/Parser/DeclarationNode.cc [5d125e4:1db21619]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r5d125e4 r1db21619 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // DeclarationNode.cc -- 7 // DeclarationNode.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 1 2 20:49:31 201613 // Update Count : 1 6412 // Last Modified On : Tue Jul 14 14:46:32 2015 13 // Update Count : 126 14 14 // 15 15 … … 34 34 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" }; 35 35 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" ,};36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" }; 37 37 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; 38 38 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 39 39 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" }; 40 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };41 40 42 41 UniqueName DeclarationNode::anonymous( "__anonymous" ); 43 42 44 extern LinkageSpec::Type linkage; // defined in parser.yy43 extern LinkageSpec::Type linkage; /* defined in cfa.y */ 45 44 46 45 DeclarationNode *DeclarationNode::clone() const { … … 55 54 newnode->linkage = linkage; 56 55 return newnode; 57 } // DeclarationNode::clone56 } 58 57 59 58 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { … … 97 96 os << endl << string( indent + 2, ' ' ) << "with initializer "; 98 97 initializer->printOneLine( os ); 99 os << " maybe constructed? " << initializer->get_maybeConstructed();100 101 98 } // if 102 99 … … 119 116 newnode->type->function->newStyle = newStyle; 120 117 newnode->type->function->body = body; 121 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );122 118 123 119 if ( body ) { … … 132 128 133 129 return newnode; 134 } // DeclarationNode::newFunction130 } 135 131 136 132 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 139 135 newnode->type->qualifiers.push_back( q ); 140 136 return newnode; 141 } // DeclarationNode::newQualifier137 } 142 138 143 139 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 145 141 newnode->storageClasses.push_back( sc ); 146 142 return newnode; 147 } // DeclarationNode::newStorageClass143 } 148 144 149 145 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 152 148 newnode->type->basic->typeSpec.push_back( bt ); 153 149 return newnode; 154 } // DeclarationNode::newBasicType 155 156 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) { 157 DeclarationNode *newnode = new DeclarationNode; 158 newnode->type = new TypeData( TypeData::Builtin ); 159 newnode->type->builtin->type = bt; 160 return newnode; 161 } // DeclarationNode::newBuiltinType 150 } 162 151 163 152 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 166 155 newnode->type->basic->modifiers.push_back( mod ); 167 156 return newnode; 168 } // DeclarationNode::newModifier157 } 169 158 170 159 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 173 162 newnode->type->forall = forall; 174 163 return newnode; 175 } // DeclarationNode::newForall164 } 176 165 177 166 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 182 171 newnode->type->symbolic->params = 0; 183 172 return newnode; 184 } // DeclarationNode::newFromTypedef185 186 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields , bool body) {173 } 174 175 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) { 187 176 DeclarationNode *newnode = new DeclarationNode; 188 177 newnode->type = new TypeData( TypeData::Aggregate ); … … 190 179 newnode->type->aggregate->name = assign_strptr( name ); 191 180 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 192 newnode->type->aggregate->name = anonymous.newName(); 181 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 182 } else { 183 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified 184 // by "struct" 185 typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD ); 186 DeclarationNode *typedf = new DeclarationNode; 187 typedf->name = newnode->type->aggregate->name; 188 newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() ); 193 189 } // if 194 190 newnode->type->aggregate->actuals = actuals; 195 191 newnode->type->aggregate->fields = fields; 196 newnode->type->aggregate->body = body; 197 return newnode; 198 } // DeclarationNode::newAggregate 192 return newnode; 193 } 199 194 200 195 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 205 200 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 206 201 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 202 } else { 203 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be 204 // qualified by "enum" 205 typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD ); 206 DeclarationNode *typedf = new DeclarationNode; 207 typedf->name = newnode->type->enumeration->name; 208 newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() ); 207 209 } // if 208 210 newnode->type->enumeration->constants = constants; 209 211 return newnode; 210 } // DeclarationNode::newEnum212 } 211 213 212 214 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { 213 215 DeclarationNode *newnode = new DeclarationNode; 214 216 newnode->name = assign_strptr( name ); 215 newnode->enumeratorValue = constant; 216 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 217 return newnode; 218 } // DeclarationNode::newEnumConstant 217 // do something with the constant 218 return newnode; 219 } 219 220 220 221 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 222 223 newnode->name = assign_strptr( name ); 223 224 return newnode; 224 } // DeclarationNode::newName225 } 225 226 226 227 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 231 232 newnode->type->symbolic->actuals = params; 232 233 return newnode; 233 } // DeclarationNode::newFromTypeGen234 } 234 235 235 236 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 240 241 newnode->type->variable->name = newnode->name; 241 242 return newnode; 242 } // DeclarationNode::newTypeParam243 244 DeclarationNode *DeclarationNode::new Trait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {243 } 244 245 DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 245 246 DeclarationNode *newnode = new DeclarationNode; 246 247 newnode->type = new TypeData( TypeData::Aggregate ); 247 newnode->type->aggregate->kind = Trait;248 newnode->type->aggregate->kind = Context; 248 249 newnode->type->aggregate->params = params; 249 250 newnode->type->aggregate->fields = asserts; 250 251 newnode->type->aggregate->name = assign_strptr( name ); 251 252 return newnode; 252 } // DeclarationNode::newTrait253 254 DeclarationNode *DeclarationNode::new TraitUse( std::string *name, ExpressionNode *params ) {253 } 254 255 DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) { 255 256 DeclarationNode *newnode = new DeclarationNode; 256 257 newnode->type = new TypeData( TypeData::AggregateInst ); 257 258 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 258 newnode->type->aggInst->aggregate->aggregate->kind = Trait;259 newnode->type->aggInst->aggregate->aggregate->kind = Context; 259 260 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 260 261 newnode->type->aggInst->params = params; 261 262 return newnode; 262 } // DeclarationNode::newTraitUse263 } 263 264 264 265 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 270 271 newnode->type->symbolic->name = newnode->name; 271 272 return newnode; 272 } // DeclarationNode::newTypeDecl273 } 273 274 274 275 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 276 277 newnode->type = new TypeData( TypeData::Pointer ); 277 278 return newnode->addQualifiers( qualifiers ); 278 } // DeclarationNode::newPointer279 } 279 280 280 281 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 289 290 } // if 290 291 return newnode->addQualifiers( qualifiers ); 291 } // DeclarationNode::newArray292 } 292 293 293 294 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { … … 356 357 } // if 357 358 } 358 359 359 360 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 360 361 if ( q ) { … … 507 508 assert( false ); 508 509 } // switch 509 510 510 511 return this; 511 512 } … … 618 619 assert( a->type->kind == TypeData::Array ); 619 620 TypeData *lastArray = findLast( a->type ); 620 if ( type ) { 621 if ( type ) { 621 622 switch ( type->kind ) { 622 623 case TypeData::Aggregate: … … 662 663 } // if 663 664 } 664 665 665 666 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 666 667 type = addIdListToType( type, ids ); … … 793 794 errors.append( e ); 794 795 } // try 795 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );796 cur = dynamic_cast< DeclarationNode *>( cur->get_link() ); 796 797 } // while 797 798 if ( ! errors.isEmpty() ) { … … 856 857 Declaration *DeclarationNode::build() const { 857 858 if ( type ) { 858 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 859 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) ); 860 return newDecl; 859 861 } // if 860 862 if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) { 861 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension);863 return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ); 862 864 } // if 863 865 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 866 868 Type *DeclarationNode::buildType() const { 867 869 assert( type ); 868 870 869 871 switch ( type->kind ) { 870 872 case TypeData::Enum: … … 879 881 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 880 882 break; 881 case DeclarationNode:: Trait:882 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );883 case DeclarationNode::Context: 884 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name ); 883 885 break; 884 886 default:
Note:
See TracChangeset
for help on using the changeset viewer.