Changes in src/Parser/DeclarationNode.cc [1db21619:5d125e4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r1db21619 r5d125e4 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 4 14:46:32 201513 // Update Count : 1 2612 // Last Modified On : Tue Jul 12 20:49:31 2016 13 // Update Count : 164 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" }; 40 41 41 42 UniqueName DeclarationNode::anonymous( "__anonymous" ); 42 43 43 extern LinkageSpec::Type linkage; /* defined in cfa.y */44 extern LinkageSpec::Type linkage; // defined in parser.yy 44 45 45 46 DeclarationNode *DeclarationNode::clone() const { … … 54 55 newnode->linkage = linkage; 55 56 return newnode; 56 } 57 } // DeclarationNode::clone 57 58 58 59 DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) { … … 96 97 os << endl << string( indent + 2, ' ' ) << "with initializer "; 97 98 initializer->printOneLine( os ); 99 os << " maybe constructed? " << initializer->get_maybeConstructed(); 100 98 101 } // if 99 102 … … 116 119 newnode->type->function->newStyle = newStyle; 117 120 newnode->type->function->body = body; 121 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 118 122 119 123 if ( body ) { … … 128 132 129 133 return newnode; 130 } 134 } // DeclarationNode::newFunction 131 135 132 136 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { … … 135 139 newnode->type->qualifiers.push_back( q ); 136 140 return newnode; 137 } 141 } // DeclarationNode::newQualifier 138 142 139 143 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { … … 141 145 newnode->storageClasses.push_back( sc ); 142 146 return newnode; 143 } 147 } // DeclarationNode::newStorageClass 144 148 145 149 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { … … 148 152 newnode->type->basic->typeSpec.push_back( bt ); 149 153 return newnode; 150 } 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 151 162 152 163 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { … … 155 166 newnode->type->basic->modifiers.push_back( mod ); 156 167 return newnode; 157 } 168 } // DeclarationNode::newModifier 158 169 159 170 DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) { … … 162 173 newnode->type->forall = forall; 163 174 return newnode; 164 } 175 } // DeclarationNode::newForall 165 176 166 177 DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) { … … 171 182 newnode->type->symbolic->params = 0; 172 183 return newnode; 173 } 174 175 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {184 } // DeclarationNode::newFromTypedef 185 186 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) { 176 187 DeclarationNode *newnode = new DeclarationNode; 177 188 newnode->type = new TypeData( TypeData::Aggregate ); … … 179 190 newnode->type->aggregate->name = assign_strptr( name ); 180 191 if ( newnode->type->aggregate->name == "" ) { // anonymous aggregate ? 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() ); 192 newnode->type->aggregate->name = anonymous.newName(); 189 193 } // if 190 194 newnode->type->aggregate->actuals = actuals; 191 195 newnode->type->aggregate->fields = fields; 192 return newnode; 193 } 196 newnode->type->aggregate->body = body; 197 return newnode; 198 } // DeclarationNode::newAggregate 194 199 195 200 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { … … 200 205 if ( newnode->type->enumeration->name == "" ) { // anonymous enumeration ? 201 206 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 be204 // 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() );209 207 } // if 210 208 newnode->type->enumeration->constants = constants; 211 209 return newnode; 212 } 210 } // DeclarationNode::newEnum 213 211 214 212 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) { 215 213 DeclarationNode *newnode = new DeclarationNode; 216 214 newnode->name = assign_strptr( name ); 217 // do something with the constant 218 return newnode; 219 } 215 newnode->enumeratorValue = constant; 216 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 217 return newnode; 218 } // DeclarationNode::newEnumConstant 220 219 221 220 DeclarationNode *DeclarationNode::newName( std::string *name ) { … … 223 222 newnode->name = assign_strptr( name ); 224 223 return newnode; 225 } 224 } // DeclarationNode::newName 226 225 227 226 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) { … … 232 231 newnode->type->symbolic->actuals = params; 233 232 return newnode; 234 } 233 } // DeclarationNode::newFromTypeGen 235 234 236 235 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) { … … 241 240 newnode->type->variable->name = newnode->name; 242 241 return newnode; 243 } 244 245 DeclarationNode *DeclarationNode::new Context( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {242 } // DeclarationNode::newTypeParam 243 244 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 246 245 DeclarationNode *newnode = new DeclarationNode; 247 246 newnode->type = new TypeData( TypeData::Aggregate ); 248 newnode->type->aggregate->kind = Context;247 newnode->type->aggregate->kind = Trait; 249 248 newnode->type->aggregate->params = params; 250 249 newnode->type->aggregate->fields = asserts; 251 250 newnode->type->aggregate->name = assign_strptr( name ); 252 251 return newnode; 253 } 254 255 DeclarationNode *DeclarationNode::new ContextUse( std::string *name, ExpressionNode *params ) {252 } // DeclarationNode::newTrait 253 254 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) { 256 255 DeclarationNode *newnode = new DeclarationNode; 257 256 newnode->type = new TypeData( TypeData::AggregateInst ); 258 257 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 259 newnode->type->aggInst->aggregate->aggregate->kind = Context;258 newnode->type->aggInst->aggregate->aggregate->kind = Trait; 260 259 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 261 260 newnode->type->aggInst->params = params; 262 261 return newnode; 263 } 262 } // DeclarationNode::newTraitUse 264 263 265 264 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { … … 271 270 newnode->type->symbolic->name = newnode->name; 272 271 return newnode; 273 } 272 } // DeclarationNode::newTypeDecl 274 273 275 274 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { … … 277 276 newnode->type = new TypeData( TypeData::Pointer ); 278 277 return newnode->addQualifiers( qualifiers ); 279 } 278 } // DeclarationNode::newPointer 280 279 281 280 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { … … 290 289 } // if 291 290 return newnode->addQualifiers( qualifiers ); 292 } 291 } // DeclarationNode::newArray 293 292 294 293 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { … … 357 356 } // if 358 357 } 359 358 360 359 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 361 360 if ( q ) { … … 508 507 assert( false ); 509 508 } // switch 510 509 511 510 return this; 512 511 } … … 619 618 assert( a->type->kind == TypeData::Array ); 620 619 TypeData *lastArray = findLast( a->type ); 621 if ( type ) { 620 if ( type ) { 622 621 switch ( type->kind ) { 623 622 case TypeData::Aggregate: … … 663 662 } // if 664 663 } 665 664 666 665 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 667 666 type = addIdListToType( type, ids ); … … 794 793 errors.append( e ); 795 794 } // try 796 cur = dynamic_cast< 795 cur = dynamic_cast<DeclarationNode *>( cur->get_link() ); 797 796 } // while 798 797 if ( ! errors.isEmpty() ) { … … 857 856 Declaration *DeclarationNode::build() const { 858 857 if ( type ) { 859 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) ); 860 return newDecl; 858 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 861 859 } // if 862 860 if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) { 863 return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ));861 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 864 862 } // if 865 863 throw SemanticError( "invalid function specifier in declaration of ", this ); … … 868 866 Type *DeclarationNode::buildType() const { 869 867 assert( type ); 870 868 871 869 switch ( type->kind ) { 872 870 case TypeData::Enum: … … 881 879 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 882 880 break; 883 case DeclarationNode:: Context:884 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );881 case DeclarationNode::Trait: 882 ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name ); 885 883 break; 886 884 default:
Note:
See TracChangeset
for help on using the changeset viewer.