Changeset b87a5ed for translator/Parser/DeclarationNode.cc
- Timestamp:
- May 16, 2015, 3:36:19 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- a32b204
- Parents:
- b8508a2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/Parser/DeclarationNode.cc
rb8508a2 rb87a5ed 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // DeclarationNode.cc -- 8 // 9 // Author : Rodolfo G. Esteves 10 // Created On : Sat May 16 12:34:05 2015 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 16 12:38:20 2015 13 // Update Count : 4 14 // 15 1 16 #include <string> 2 17 #include <list> … … 23 38 24 39 DeclarationNode *DeclarationNode::clone() const { 25 26 27 28 29 30 31 32 33 34 40 DeclarationNode *newnode = new DeclarationNode; 41 newnode->type = maybeClone( type ); 42 newnode->name = name; 43 newnode->storageClasses = storageClasses; 44 newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 45 newnode->hasEllipsis = hasEllipsis; 46 newnode->initializer = initializer; 47 newnode->next = maybeClone( next ); 48 newnode->linkage = linkage; 49 return newnode; 35 50 } 36 51 … … 39 54 40 55 DeclarationNode::~DeclarationNode() { 41 42 43 56 delete type; 57 delete bitfieldWidth; 58 delete initializer; 44 59 } 45 60 46 61 bool DeclarationNode::get_hasEllipsis() const { 47 62 return hasEllipsis; 48 63 } 49 64 50 65 const char *storageClassName[] = { 51 52 53 54 55 56 57 66 // order must correspond with DeclarationNode::StorageClass 67 "extern", 68 "static", 69 "auto", 70 "register", 71 "inline", 72 "fortran", 58 73 }; 59 74 60 75 void DeclarationNode::print( std::ostream &os, int indent ) const { 61 62 63 os << "unnamed: ";64 65 os << name << ": ";66 67 68 69 os << LinkageSpec::toString( linkage ) << " ";70 71 72 73 74 type->print( os, indent );75 76 os << "untyped entity ";77 78 79 80 os << endl << string(indent+2, ' ') << "with bitfield width ";81 bitfieldWidth->printOneLine( os );82 83 84 85 os << endl << string(indent+2, ' ') << "with initializer ";86 initializer->printOneLine( os );87 88 89 76 os << string(indent, ' ' ); 77 if ( name == "" ) { 78 os << "unnamed: "; 79 } else { 80 os << name << ": "; 81 } 82 83 if ( linkage != LinkageSpec::Cforall ) { 84 os << LinkageSpec::toString( linkage ) << " "; 85 } 86 87 printEnums( storageClasses.begin(), storageClasses.end(), storageClassName, os ); 88 if ( type ) { 89 type->print( os, indent ); 90 } else { 91 os << "untyped entity "; 92 } 93 94 if ( bitfieldWidth ) { 95 os << endl << string(indent+2, ' ') << "with bitfield width "; 96 bitfieldWidth->printOneLine( os ); 97 } 98 99 if ( initializer != 0 ) { 100 os << endl << string(indent+2, ' ') << "with initializer "; 101 initializer->printOneLine( os ); 102 } 103 104 os << endl; 90 105 } 91 106 92 107 void DeclarationNode::printList( std::ostream &os, int indent ) const { 93 94 95 os << string( indent, ' ' ) << "and a variable number of other arguments" << endl;96 108 ParseNode::printList( os, indent ); 109 if ( hasEllipsis ) { 110 os << string( indent, ' ' ) << "and a variable number of other arguments" << endl; 111 } 97 112 } 98 113 99 114 DeclarationNode *DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) { 100 101 102 103 104 105 106 107 108 109 newnode->type->function->hasBody = true;110 111 112 113 newnode->type->base = ret->type;114 ret->type = 0;115 delete ret;116 117 118 115 DeclarationNode *newnode = new DeclarationNode; 116 newnode->name = assign_strptr( name ); 117 118 newnode->type = new TypeData( TypeData::Function ); 119 newnode->type->function->params = param; 120 newnode->type->function->newStyle = newStyle; 121 newnode->type->function->body = body; 122 123 if ( body ) { 124 newnode->type->function->hasBody = true; 125 } 126 127 if ( ret ) { 128 newnode->type->base = ret->type; 129 ret->type = 0; 130 delete ret; 131 } 132 133 return newnode; 119 134 } 120 135 121 136 DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) { 122 123 124 125 137 DeclarationNode *newnode = new DeclarationNode; 138 newnode->type = new TypeData(); 139 newnode->type->qualifiers.push_back( q ); 140 return newnode; 126 141 } 127 142 128 143 DeclarationNode *DeclarationNode::newStorageClass( StorageClass sc ) { 129 130 131 144 DeclarationNode *newnode = new DeclarationNode; 145 newnode->storageClasses.push_back( sc ); 146 return newnode; 132 147 } 133 148 134 149 DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) { 135 136 137 138 150 DeclarationNode *newnode = new DeclarationNode; 151 newnode->type = new TypeData( TypeData::Basic ); 152 newnode->type->basic->typeSpec.push_back( bt ); 153 return newnode; 139 154 } 140 155 141 156 DeclarationNode *DeclarationNode::newModifier( Modifier mod ) { 142 143 144 145 157 DeclarationNode *newnode = new DeclarationNode; 158 newnode->type = new TypeData( TypeData::Basic ); 159 newnode->type->basic->modifiers.push_back( mod ); 160 return newnode; 146 161 } 147 162 148 163 DeclarationNode *DeclarationNode::newForall( DeclarationNode* forall ) { 149 150 151 152 164 DeclarationNode *newnode = new DeclarationNode; 165 newnode->type = new TypeData( TypeData::Unknown ); 166 newnode->type->forall = forall; 167 return newnode; 153 168 } 154 169 155 170 DeclarationNode *DeclarationNode::newFromTypedef( std::string* name ) { 156 157 158 159 160 161 171 DeclarationNode *newnode = new DeclarationNode; 172 newnode->type = new TypeData( TypeData::SymbolicInst ); 173 newnode->type->symbolic->name = assign_strptr( name ); 174 newnode->type->symbolic->isTypedef = true; 175 newnode->type->symbolic->params = 0; 176 return newnode; 162 177 } 163 178 164 179 DeclarationNode *DeclarationNode::newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) { 165 166 167 168 169 170 newnode->type->aggregate->name = DeclarationNode::anonymous.newName();171 172 173 174 175 180 DeclarationNode *newnode = new DeclarationNode; 181 newnode->type = new TypeData( TypeData::Aggregate ); 182 newnode->type->aggregate->kind = kind; 183 newnode->type->aggregate->name = assign_strptr( name ); 184 if ( newnode->type->aggregate->name == "" ) { 185 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 186 } 187 newnode->type->aggregate->params = formals; 188 newnode->type->aggregate->actuals = actuals; 189 newnode->type->aggregate->members = fields; 190 return newnode; 176 191 } 177 192 178 193 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) { 179 180 181 182 183 184 newnode->type->enumeration->name = DeclarationNode::anonymous.newName();185 186 187 194 DeclarationNode *newnode = new DeclarationNode; 195 newnode->name = assign_strptr( name ); 196 newnode->type = new TypeData( TypeData::Enum ); 197 newnode->type->enumeration->name = newnode->name; 198 if ( newnode->type->enumeration->name == "" ) { 199 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 200 } 201 newnode->type->enumeration->constants = constants; 202 return newnode; 188 203 } 189 204 190 205 DeclarationNode *DeclarationNode::newEnumConstant( std::string* name, ExpressionNode *constant ) { 191 192 193 194 206 DeclarationNode *newnode = new DeclarationNode; 207 newnode->name = assign_strptr( name ); 208 // do something with the constant 209 return newnode; 195 210 } 196 211 197 212 DeclarationNode *DeclarationNode::newName( std::string* name ) { 198 199 200 213 DeclarationNode *newnode = new DeclarationNode; 214 newnode->name = assign_strptr( name ); 215 return newnode; 201 216 } 202 217 203 218 DeclarationNode *DeclarationNode::newFromTypeGen( std::string* name, ExpressionNode *params ) { 204 205 206 207 208 209 219 DeclarationNode *newnode = new DeclarationNode; 220 newnode->type = new TypeData( TypeData::SymbolicInst ); 221 newnode->type->symbolic->name = assign_strptr( name ); 222 newnode->type->symbolic->isTypedef = false; 223 newnode->type->symbolic->actuals = params; 224 return newnode; 210 225 } 211 226 212 227 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string* name ) { 213 214 215 216 217 218 228 DeclarationNode *newnode = new DeclarationNode; 229 newnode->name = assign_strptr( name ); 230 newnode->type = new TypeData( TypeData::Variable ); 231 newnode->type->variable->tyClass = tc; 232 newnode->type->variable->name = newnode->name; 233 return newnode; 219 234 } 220 235 221 236 DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) { 222 223 224 225 226 227 228 237 DeclarationNode *newnode = new DeclarationNode; 238 newnode->type = new TypeData( TypeData::Aggregate ); 239 newnode->type->aggregate->kind = Context; 240 newnode->type->aggregate->params = params; 241 newnode->type->aggregate->members = asserts; 242 newnode->type->aggregate->name = assign_strptr( name ); 243 return newnode; 229 244 } 230 245 231 246 DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) { 232 233 234 235 236 237 238 247 DeclarationNode *newnode = new DeclarationNode; 248 newnode->type = new TypeData( TypeData::AggregateInst ); 249 newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate ); 250 newnode->type->aggInst->aggregate->aggregate->kind = Context; 251 newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name ); 252 newnode->type->aggInst->params = params; 253 return newnode; 239 254 } 240 255 241 256 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) { 242 243 244 245 246 247 248 257 DeclarationNode *newnode = new DeclarationNode; 258 newnode->name = assign_strptr( name ); 259 newnode->type = new TypeData( TypeData::Symbolic ); 260 newnode->type->symbolic->isTypedef = false; 261 newnode->type->symbolic->params = typeParams; 262 newnode->type->symbolic->name = newnode->name; 263 return newnode; 249 264 } 250 265 251 266 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) { 252 253 254 267 DeclarationNode *newnode = new DeclarationNode; 268 newnode->type = new TypeData( TypeData::Pointer ); 269 return newnode->addQualifiers( qualifiers ); 255 270 } 256 271 257 272 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) { 258 259 260 261 262 263 273 DeclarationNode *newnode = new DeclarationNode; 274 newnode->type = new TypeData( TypeData::Array ); 275 newnode->type->array->dimension = size; 276 newnode->type->array->isStatic = isStatic; 277 newnode->type->array->isVarLen = false; 278 return newnode->addQualifiers( qualifiers ); 264 279 } 265 280 266 281 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) { 267 268 269 270 271 272 282 DeclarationNode *newnode = new DeclarationNode; 283 newnode->type = new TypeData( TypeData::Array ); 284 newnode->type->array->dimension = 0; 285 newnode->type->array->isStatic = false; 286 newnode->type->array->isVarLen = true; 287 return newnode->addQualifiers( qualifiers ); 273 288 } 274 289 275 290 DeclarationNode *DeclarationNode::newBitfield( ExpressionNode *size ) { 276 277 278 291 DeclarationNode *newnode = new DeclarationNode; 292 newnode->bitfieldWidth = size; 293 return newnode; 279 294 } 280 295 281 296 DeclarationNode *DeclarationNode::newTuple( DeclarationNode *members ) { 282 283 284 285 297 DeclarationNode *newnode = new DeclarationNode; 298 newnode->type = new TypeData( TypeData::Tuple ); 299 newnode->type->tuple->members = members; 300 return newnode; 286 301 } 287 302 288 303 DeclarationNode *DeclarationNode::newTypeof( ExpressionNode *expr ) { 289 290 291 292 304 DeclarationNode *newnode = new DeclarationNode; 305 newnode->type = new TypeData( TypeData::Typeof ); 306 newnode->type->typeexpr->expr = expr; 307 return newnode; 293 308 } 294 309 295 310 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 296 297 298 299 300 311 DeclarationNode *newnode = new DeclarationNode; 312 newnode->type = new TypeData( TypeData::Attr ); 313 newnode->type->attr->name = assign_strptr( name ); 314 newnode->type->attr->expr = expr; 315 return newnode; 301 316 } 302 317 303 318 DeclarationNode *DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) { 304 305 306 307 308 319 DeclarationNode *newnode = new DeclarationNode; 320 newnode->type = new TypeData( TypeData::Attr ); 321 newnode->type->attr->name = assign_strptr( name ); 322 newnode->type->attr->type = type; 323 return newnode; 309 324 } 310 325 311 326 static void addQualifiersToType( TypeData *&src, TypeData *dst ) { 312 313 if ( src->forall && dst->kind == TypeData::Function ) {314 315 dst->forall->appendList( src->forall );316 317 dst->forall = src->forall;318 319 320 }321 if ( dst->base ) {322 323 } else if ( dst->kind == TypeData::Function ) {324 325 326 } else {327 328 }329 330 } 331 327 if ( src && dst ) { 328 if ( src->forall && dst->kind == TypeData::Function ) { 329 if ( dst->forall ) { 330 dst->forall->appendList( src->forall ); 331 } else { 332 dst->forall = src->forall; 333 } 334 src->forall = 0; 335 } 336 if ( dst->base ) { 337 addQualifiersToType( src, dst->base ); 338 } else if ( dst->kind == TypeData::Function ) { 339 dst->base = src; 340 src = 0; 341 } else { 342 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 343 } 344 } 345 } 346 332 347 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 333 if ( q ) { 334 storageClasses.splice( storageClasses.end(), q->storageClasses ); 335 if ( q->type ) { 336 if ( ! type ) { 337 type = new TypeData; 338 } 339 addQualifiersToType( q->type, type ); 340 if ( q->type && q->type->forall ) { 341 if ( type->forall ) { 342 type->forall->appendList( q->type->forall ); 348 if ( q ) { 349 storageClasses.splice( storageClasses.end(), q->storageClasses ); 350 if ( q->type ) { 351 if ( ! type ) { 352 type = new TypeData; 353 } 354 addQualifiersToType( q->type, type ); 355 if ( q->type && q->type->forall ) { 356 if ( type->forall ) { 357 type->forall->appendList( q->type->forall ); 358 } else { 359 type->forall = q->type->forall; 360 } 361 q->type->forall = 0; 362 } 363 } 364 } 365 delete q; 366 return this; 367 } 368 369 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 370 storageClasses = q->storageClasses; 371 return this; 372 } 373 374 static void addTypeToType( TypeData *&src, TypeData *&dst ) { 375 if ( src && dst ) { 376 if ( src->forall && dst->kind == TypeData::Function ) { 377 if ( dst->forall ) { 378 dst->forall->appendList( src->forall ); 379 } else { 380 dst->forall = src->forall; 381 } 382 src->forall = 0; 383 } 384 if ( dst->base ) { 385 addTypeToType( src, dst->base ); 343 386 } else { 344 type->forall = q->type->forall; 345 } 346 q->type->forall = 0; 347 } 348 } 349 } 350 delete q; 351 return this; 352 } 353 354 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) { 355 storageClasses = q->storageClasses; 356 return this; 357 } 358 359 static void addTypeToType( TypeData *&src, TypeData *&dst ) { 360 if ( src && dst ) { 361 if ( src->forall && dst->kind == TypeData::Function ) { 362 if ( dst->forall ) { 363 dst->forall->appendList( src->forall ); 364 } else { 365 dst->forall = src->forall; 366 } 367 src->forall = 0; 368 } 369 if ( dst->base ) { 370 addTypeToType( src, dst->base ); 371 } else { 372 switch ( dst->kind ) { 373 case TypeData::Unknown: 374 src->qualifiers.splice( src->qualifiers.end(), dst->qualifiers ); 375 dst = src; 376 src = 0; 387 switch ( dst->kind ) { 388 case TypeData::Unknown: 389 src->qualifiers.splice( src->qualifiers.end(), dst->qualifiers ); 390 dst = src; 391 src = 0; 392 break; 393 394 case TypeData::Basic: 395 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 396 if ( src->kind != TypeData::Unknown ) { 397 assert( src->kind == TypeData::Basic ); 398 dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers ); 399 dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec ); 400 } 401 break; 402 403 default: 404 switch ( src->kind ) { 405 case TypeData::Aggregate: 406 case TypeData::Enum: 407 dst->base = new TypeData( TypeData::AggregateInst ); 408 dst->base->aggInst->aggregate = src; 409 if ( src->kind == TypeData::Aggregate ) { 410 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 411 } 412 dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers ); 413 src = 0; 414 break; 415 416 default: 417 if ( dst->forall ) { 418 dst->forall->appendList( src->forall ); 419 } else { 420 dst->forall = src->forall; 421 } 422 src->forall = 0; 423 dst->base = src; 424 src = 0; 425 } 426 } 427 } 428 } 429 } 430 431 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 432 if ( o ) { 433 storageClasses.splice( storageClasses.end(), o->storageClasses ); 434 if ( o->type ) { 435 if ( ! type ) { 436 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 437 type = new TypeData( TypeData::AggregateInst ); 438 type->aggInst->aggregate = o->type; 439 if ( o->type->kind == TypeData::Aggregate ) { 440 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 441 } 442 type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers ); 443 } else { 444 type = o->type; 445 } 446 o->type = 0; 447 } else { 448 addTypeToType( o->type, type ); 449 } 450 } 451 if ( o->bitfieldWidth ) { 452 bitfieldWidth = o->bitfieldWidth; 453 } 454 } 455 delete o; 456 return this; 457 } 458 459 DeclarationNode *DeclarationNode::addTypedef() { 460 TypeData *newtype = new TypeData( TypeData::Symbolic ); 461 newtype->symbolic->params = 0; 462 newtype->symbolic->isTypedef = true; 463 newtype->symbolic->name = name; 464 newtype->base = type; 465 type = newtype; 466 return this; 467 } 468 469 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode* assertions ) { 470 assert( type ); 471 switch ( type->kind ) { 472 case TypeData::Symbolic: 473 if ( type->symbolic->assertions ) { 474 type->symbolic->assertions->appendList( assertions ); 475 } else { 476 type->symbolic->assertions = assertions; 477 } 377 478 break; 378 379 case TypeData::Basic: 380 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 381 if ( src->kind != TypeData::Unknown ) { 382 assert( src->kind == TypeData::Basic ); 383 dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers ); 384 dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec ); 479 480 case TypeData::Variable: 481 if ( type->variable->assertions ) { 482 type->variable->assertions->appendList( assertions ); 483 } else { 484 type->variable->assertions = assertions; 385 485 } 386 486 break; 387 388 default: 389 switch ( src->kind ) { 390 case TypeData::Aggregate: 391 case TypeData::Enum: 392 dst->base = new TypeData( TypeData::AggregateInst ); 393 dst->base->aggInst->aggregate = src; 394 if ( src->kind == TypeData::Aggregate ) { 395 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 396 } 397 dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers ); 398 src = 0; 399 break; 400 401 default: 402 if ( dst->forall ) { 403 dst->forall->appendList( src->forall ); 404 } else { 405 dst->forall = src->forall; 406 } 407 src->forall = 0; 408 dst->base = src; 409 src = 0; 410 } 411 } 412 } 413 } 414 } 415 416 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) { 417 if ( o ) { 418 storageClasses.splice( storageClasses.end(), o->storageClasses ); 419 if ( o->type ) { 420 if ( ! type ) { 421 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 422 type = new TypeData( TypeData::AggregateInst ); 423 type->aggInst->aggregate = o->type; 424 if ( o->type->kind == TypeData::Aggregate ) { 425 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 426 } 427 type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers ); 428 } else { 429 type = o->type; 430 } 431 o->type = 0; 432 } else { 433 addTypeToType( o->type, type ); 434 } 435 } 436 if ( o->bitfieldWidth ) { 437 bitfieldWidth = o->bitfieldWidth; 438 } 439 } 440 delete o; 441 return this; 442 } 443 444 DeclarationNode *DeclarationNode::addTypedef() { 445 TypeData *newtype = new TypeData( TypeData::Symbolic ); 446 newtype->symbolic->params = 0; 447 newtype->symbolic->isTypedef = true; 448 newtype->symbolic->name = name; 449 newtype->base = type; 450 type = newtype; 451 return this; 452 } 453 454 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode* assertions ) { 455 assert( type ); 456 switch ( type->kind ) { 457 case TypeData::Symbolic: 458 if ( type->symbolic->assertions ) { 459 type->symbolic->assertions->appendList( assertions ); 460 } else { 461 type->symbolic->assertions = assertions; 462 } 463 break; 464 465 case TypeData::Variable: 466 if ( type->variable->assertions ) { 467 type->variable->assertions->appendList( assertions ); 468 } else { 469 type->variable->assertions = assertions; 470 } 471 break; 472 473 default: 474 assert( false ); 475 } 476 477 return this; 487 488 default: 489 assert( false ); 490 } 491 492 return this; 478 493 } 479 494 480 495 DeclarationNode *DeclarationNode::addName( std::string* newname ) { 481 482 496 name = assign_strptr( newname ); 497 return this; 483 498 } 484 499 485 500 DeclarationNode *DeclarationNode::addBitfield( ExpressionNode *size ) { 486 487 501 bitfieldWidth = size; 502 return this; 488 503 } 489 504 490 505 DeclarationNode *DeclarationNode::addVarArgs() { 491 492 493 506 assert( type ); 507 hasEllipsis = true; 508 return this; 494 509 } 495 510 496 511 DeclarationNode *DeclarationNode::addFunctionBody( StatementNode *body ) { 497 498 499 500 501 502 512 assert( type ); 513 assert( type->kind == TypeData::Function ); 514 assert( type->function->body == 0 ); 515 type->function->body = body; 516 type->function->hasBody = true; 517 return this; 503 518 } 504 519 505 520 DeclarationNode *DeclarationNode::addOldDeclList( DeclarationNode *list ) { 506 507 508 509 510 521 assert( type ); 522 assert( type->kind == TypeData::Function ); 523 assert( type->function->oldDeclList == 0 ); 524 type->function->oldDeclList = list; 525 return this; 511 526 } 512 527 513 528 static void 514 529 setBase( TypeData *&type, TypeData *newType ) { 515 516 TypeData *prevBase = type;517 TypeData *curBase = type->base;518 while( curBase != 0 ) {519 520 521 }522 prevBase->base = newType;523 524 type = newType;525 530 if ( type ) { 531 TypeData *prevBase = type; 532 TypeData *curBase = type->base; 533 while( curBase != 0 ) { 534 prevBase = curBase; 535 curBase = curBase->base; 536 } 537 prevBase->base = newType; 538 } else { 539 type = newType; 540 } 526 541 } 527 542 528 543 DeclarationNode *DeclarationNode::addPointer( DeclarationNode *p ) { 529 530 assert( p->type->kind == TypeData::Pointer );531 setBase( type, p->type );532 p->type = 0;533 delete p;534 535 544 if ( p ) { 545 assert( p->type->kind == TypeData::Pointer ); 546 setBase( type, p->type ); 547 p->type = 0; 548 delete p; 549 } 550 return this; 536 551 } 537 552 538 553 DeclarationNode *DeclarationNode::addArray( DeclarationNode *a ) { 539 540 assert( a->type->kind == TypeData::Array );541 setBase( type, a->type );542 a->type = 0;543 delete a;544 545 554 if ( a ) { 555 assert( a->type->kind == TypeData::Array ); 556 setBase( type, a->type ); 557 a->type = 0; 558 delete a; 559 } 560 return this; 546 561 } 547 562 548 563 DeclarationNode *DeclarationNode::addNewPointer( DeclarationNode *p ) { 549 if ( p ) { 550 assert( p->type->kind == TypeData::Pointer ); 564 if ( p ) { 565 assert( p->type->kind == TypeData::Pointer ); 566 if ( type ) { 567 switch ( type->kind ) { 568 case TypeData::Aggregate: 569 case TypeData::Enum: 570 p->type->base = new TypeData( TypeData::AggregateInst ); 571 p->type->base->aggInst->aggregate = type; 572 if ( type->kind == TypeData::Aggregate ) { 573 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 574 } 575 p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers ); 576 break; 577 578 default: 579 p->type->base = type; 580 } 581 type = 0; 582 } 583 delete this; 584 return p; 585 } else { 586 return this; 587 } 588 } 589 590 static TypeData *findLast( TypeData *a ) { 591 assert( a ); 592 TypeData *cur = a; 593 while( cur->base ) { 594 cur = cur->base; 595 } 596 return cur; 597 } 598 599 DeclarationNode *DeclarationNode::addNewArray( DeclarationNode *a ) { 600 if ( a ) { 601 assert( a->type->kind == TypeData::Array ); 602 TypeData *lastArray = findLast( a->type ); 603 if ( type ) { 604 switch ( type->kind ) { 605 case TypeData::Aggregate: 606 case TypeData::Enum: 607 lastArray->base = new TypeData( TypeData::AggregateInst ); 608 lastArray->base->aggInst->aggregate = type; 609 if ( type->kind == TypeData::Aggregate ) { 610 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 611 } 612 lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers ); 613 break; 614 default: 615 lastArray->base = type; 616 } 617 type = 0; 618 } 619 delete this; 620 return a; 621 } else { 622 return this; 623 } 624 } 625 626 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 627 TypeData *ftype = new TypeData( TypeData::Function ); 628 ftype->function->params = params; 629 setBase( type, ftype ); 630 return this; 631 } 632 633 static TypeData *addIdListToType( TypeData *type, DeclarationNode *ids ) { 551 634 if ( type ) { 552 switch ( type->kind ) { 553 case TypeData::Aggregate: 554 case TypeData::Enum: 555 p->type->base = new TypeData( TypeData::AggregateInst ); 556 p->type->base->aggInst->aggregate = type; 557 if ( type->kind == TypeData::Aggregate ) { 558 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 559 } 560 p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers ); 561 break; 562 563 default: 564 p->type->base = type; 565 } 566 type = 0; 567 } 568 delete this; 569 return p; 570 } else { 571 return this; 572 } 573 } 574 575 static TypeData *findLast( TypeData *a ) { 576 assert( a ); 577 TypeData *cur = a; 578 while( cur->base ) { 579 cur = cur->base; 580 } 581 return cur; 582 } 583 584 DeclarationNode *DeclarationNode::addNewArray( DeclarationNode *a ) { 585 if ( a ) { 586 assert( a->type->kind == TypeData::Array ); 587 TypeData *lastArray = findLast( a->type ); 588 if ( type ) { 589 switch ( type->kind ) { 590 case TypeData::Aggregate: 591 case TypeData::Enum: 592 lastArray->base = new TypeData( TypeData::AggregateInst ); 593 lastArray->base->aggInst->aggregate = type; 594 if ( type->kind == TypeData::Aggregate ) { 595 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 596 } 597 lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers ); 598 break; 599 600 default: 601 lastArray->base = type; 602 } 603 type = 0; 604 } 605 delete this; 606 return a; 607 } else { 608 return this; 609 } 610 } 611 612 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 613 TypeData *ftype = new TypeData( TypeData::Function ); 614 ftype->function->params = params; 615 setBase( type, ftype ); 616 return this; 617 } 618 619 static TypeData *addIdListToType( TypeData *type, DeclarationNode *ids ) { 620 if ( type ) { 621 if ( type->kind != TypeData::Function ) { 622 type->base = addIdListToType( type->base, ids ); 635 if ( type->kind != TypeData::Function ) { 636 type->base = addIdListToType( type->base, ids ); 637 } else { 638 type->function->idList = ids; 639 } 640 return type; 623 641 } else { 624 type->function->idList = ids; 625 } 626 return type; 627 } else { 628 TypeData *newtype = new TypeData( TypeData::Function ); 629 newtype->function->idList = ids; 630 return newtype; 631 } 632 } 633 642 TypeData *newtype = new TypeData( TypeData::Function ); 643 newtype->function->idList = ids; 644 return newtype; 645 } 646 } 647 634 648 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 635 636 649 type = addIdListToType( type, ids ); 650 return this; 637 651 } 638 652 639 653 DeclarationNode *DeclarationNode::addInitializer( InitializerNode *init ) { 640 641 642 654 //assert 655 initializer = init; 656 return this; 643 657 } 644 658 645 659 DeclarationNode *DeclarationNode::cloneBaseType( string *newName ) { 646 DeclarationNode *newnode = new DeclarationNode; 647 TypeData *srcType = type; 648 while( srcType->base ) { 649 srcType = srcType->base; 650 } 651 newnode->type = maybeClone( srcType ); 652 if ( newnode->type->kind == TypeData::AggregateInst ) { 653 // don't duplicate members 654 if ( newnode->type->aggInst->aggregate->kind == TypeData::Enum ) { 655 delete newnode->type->aggInst->aggregate->enumeration->constants; 656 newnode->type->aggInst->aggregate->enumeration->constants = 0; 660 DeclarationNode *newnode = new DeclarationNode; 661 TypeData *srcType = type; 662 while( srcType->base ) { 663 srcType = srcType->base; 664 } 665 newnode->type = maybeClone( srcType ); 666 if ( newnode->type->kind == TypeData::AggregateInst ) { 667 // don't duplicate members 668 if ( newnode->type->aggInst->aggregate->kind == TypeData::Enum ) { 669 delete newnode->type->aggInst->aggregate->enumeration->constants; 670 newnode->type->aggInst->aggregate->enumeration->constants = 0; 671 } else { 672 assert( newnode->type->aggInst->aggregate->kind == TypeData::Aggregate ); 673 delete newnode->type->aggInst->aggregate->aggregate->members; 674 newnode->type->aggInst->aggregate->aggregate->members = 0; 675 } 676 } 677 newnode->type->forall = maybeClone( type->forall ); 678 newnode->storageClasses = storageClasses; 679 newnode->name = assign_strptr( newName ); 680 return newnode; 681 } 682 683 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 684 if ( o ) { 685 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 686 if ( type ) { 687 TypeData *srcType = type; 688 while( srcType->base ) { 689 srcType = srcType->base; 690 } 691 TypeData *newType = srcType->clone(); 692 if ( newType->kind == TypeData::AggregateInst ) { 693 // don't duplicate members 694 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) { 695 delete newType->aggInst->aggregate->enumeration->constants; 696 newType->aggInst->aggregate->enumeration->constants = 0; 697 } else { 698 assert( newType->aggInst->aggregate->kind == TypeData::Aggregate ); 699 delete newType->aggInst->aggregate->aggregate->members; 700 newType->aggInst->aggregate->aggregate->members = 0; 701 } 702 } 703 newType->forall = maybeClone( type->forall ); 704 if ( ! o->type ) { 705 o->type = newType; 706 } else { 707 addTypeToType( newType, o->type ); 708 delete newType; 709 } 710 } 711 } 712 return o; 713 } 714 715 DeclarationNode *DeclarationNode::cloneType( string *newName ) { 716 DeclarationNode *newnode = new DeclarationNode; 717 newnode->type = maybeClone( type ); 718 newnode->storageClasses = storageClasses; 719 newnode->name = assign_strptr( newName ); 720 return newnode; 721 } 722 723 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 724 if ( o ) { 725 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 726 if ( type ) { 727 TypeData *newType = type->clone(); 728 if ( ! o->type ) { 729 o->type = newType; 730 } else { 731 addTypeToType( newType, o->type ); 732 delete newType; 733 } 734 } 735 } 736 return o; 737 } 738 739 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) { 740 if ( node != 0 ) { 741 set_link( node ); 742 } 743 return this; 744 } 745 746 DeclarationNode *DeclarationNode::extractAggregate() const { 747 if ( type ) { 748 TypeData *ret = type->extractAggregate(); 749 if ( ret ) { 750 DeclarationNode *newnode = new DeclarationNode; 751 newnode->type = ret; 752 return newnode; 753 } else { 754 return 0; 755 } 657 756 } else { 658 assert( newnode->type->aggInst->aggregate->kind == TypeData::Aggregate ); 659 delete newnode->type->aggInst->aggregate->aggregate->members; 660 newnode->type->aggInst->aggregate->aggregate->members = 0; 661 } 662 } 663 newnode->type->forall = maybeClone( type->forall ); 664 newnode->storageClasses = storageClasses; 665 newnode->name = assign_strptr( newName ); 666 return newnode; 667 } 668 669 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) { 670 if ( o ) { 671 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 672 if ( type ) { 673 TypeData *srcType = type; 674 while( srcType->base ) { 675 srcType = srcType->base; 676 } 677 TypeData *newType = srcType->clone(); 678 if ( newType->kind == TypeData::AggregateInst ) { 679 // don't duplicate members 680 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) { 681 delete newType->aggInst->aggregate->enumeration->constants; 682 newType->aggInst->aggregate->enumeration->constants = 0; 683 } else { 684 assert( newType->aggInst->aggregate->kind == TypeData::Aggregate ); 685 delete newType->aggInst->aggregate->aggregate->members; 686 newType->aggInst->aggregate->aggregate->members = 0; 687 } 688 } 689 newType->forall = maybeClone( type->forall ); 690 if ( ! o->type ) { 691 o->type = newType; 692 } else { 693 addTypeToType( newType, o->type ); 694 delete newType; 695 } 696 } 697 } 698 return o; 699 } 700 701 DeclarationNode *DeclarationNode::cloneType( string *newName ) { 702 DeclarationNode *newnode = new DeclarationNode; 703 newnode->type = maybeClone( type ); 704 newnode->storageClasses = storageClasses; 705 newnode->name = assign_strptr( newName ); 706 return newnode; 707 } 708 709 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) { 710 if ( o ) { 711 o->storageClasses.insert( o->storageClasses.end(), storageClasses.begin(), storageClasses.end() ); 712 if ( type ) { 713 TypeData *newType = type->clone(); 714 if ( ! o->type ) { 715 o->type = newType; 716 } else { 717 addTypeToType( newType, o->type ); 718 delete newType; 719 } 720 } 721 } 722 return o; 723 } 724 725 DeclarationNode *DeclarationNode::appendList( DeclarationNode *node ) { 726 if ( node != 0 ) { 727 set_link( node ); 728 } 729 return this; 730 } 731 732 DeclarationNode *DeclarationNode::extractAggregate() const { 733 if ( type ) { 734 TypeData *ret = type->extractAggregate(); 735 if ( ret ) { 736 DeclarationNode *newnode = new DeclarationNode; 737 newnode->type = ret; 738 return newnode; 739 } else { 740 return 0; 741 } 742 } else { 743 return 0; 744 } 757 return 0; 758 } 745 759 } 746 760 747 761 void buildList( const DeclarationNode *firstNode, std::list< Declaration* > &outputList ) { 748 SemanticError errors; 749 std::back_insert_iterator< std::list< Declaration* > > out( outputList ); 750 const DeclarationNode *cur = firstNode; 751 while( cur ) { 752 try { 753 if ( DeclarationNode *extr = cur->extractAggregate() ) { 754 // handle the case where a structure declaration is contained within an object or type 755 // declaration 756 Declaration *decl = extr->build(); 757 if ( decl ) { 758 *out++ = decl; 759 } 760 } 761 Declaration *decl = cur->build(); 762 if ( decl ) { 763 *out++ = decl; 764 } 765 } catch( SemanticError &e ) { 766 errors.append( e ); 767 } 768 cur = dynamic_cast< DeclarationNode* >( cur->get_link() ); 769 } 770 if ( ! errors.isEmpty() ) { 771 throw errors; 772 } 762 SemanticError errors; 763 std::back_insert_iterator< std::list< Declaration* > > out( outputList ); 764 const DeclarationNode *cur = firstNode; 765 while( cur ) { 766 try { 767 if ( DeclarationNode *extr = cur->extractAggregate() ) { 768 // handle the case where a structure declaration is contained within an object or type declaration 769 Declaration *decl = extr->build(); 770 if ( decl ) { 771 *out++ = decl; 772 } 773 } 774 Declaration *decl = cur->build(); 775 if ( decl ) { 776 *out++ = decl; 777 } 778 } catch( SemanticError &e ) { 779 errors.append( e ); 780 } 781 cur = dynamic_cast< DeclarationNode* >( cur->get_link() ); 782 } 783 if ( ! errors.isEmpty() ) { 784 throw errors; 785 } 773 786 } 774 787 775 788 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType* > &outputList ) { 776 777 778 779 780 try {789 SemanticError errors; 790 std::back_insert_iterator< std::list< DeclarationWithType* > > out( outputList ); 791 const DeclarationNode *cur = firstNode; 792 while( cur ) { 793 try { 781 794 /// if ( DeclarationNode *extr = cur->extractAggregate() ) { 782 795 /// // handle the case where a structure declaration is contained within an object or type … … 787 800 /// } 788 801 /// } 789 790 791 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {792 793 } else if ( StructDecl *agg = dynamic_cast< StructDecl* >( decl ) ) {794 795 796 797 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl* >( decl ) ) {798 799 800 }801 802 } catch( SemanticError &e ) {803 804 }805 cur = dynamic_cast< DeclarationNode* >( cur->get_link() );806 807 808 throw errors;809 802 Declaration *decl = cur->build(); 803 if ( decl ) { 804 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) { 805 *out++ = dwt; 806 } else if ( StructDecl *agg = dynamic_cast< StructDecl* >( decl ) ) { 807 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 808 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 ); 809 delete agg; 810 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl* >( decl ) ) { 811 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 812 *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 ); 813 } 814 } 815 } catch( SemanticError &e ) { 816 errors.append( e ); 817 } 818 cur = dynamic_cast< DeclarationNode* >( cur->get_link() ); 819 } 820 if ( ! errors.isEmpty() ) { 821 throw errors; 822 } 810 823 } 811 824 812 825 void buildTypeList( const DeclarationNode *firstNode, std::list< Type* > &outputList ) { 813 814 815 816 817 try {818 819 } catch( SemanticError &e ) {820 821 }822 cur = dynamic_cast< DeclarationNode* >( cur->get_link() );823 824 825 throw errors;826 826 SemanticError errors; 827 std::back_insert_iterator< std::list< Type* > > out( outputList ); 828 const DeclarationNode *cur = firstNode; 829 while( cur ) { 830 try { 831 *out++ = cur->buildType(); 832 } catch( SemanticError &e ) { 833 errors.append( e ); 834 } 835 cur = dynamic_cast< DeclarationNode* >( cur->get_link() ); 836 } 837 if ( ! errors.isEmpty() ) { 838 throw errors; 839 } 827 840 } 828 841 829 842 Declaration *DeclarationNode::build() const { 830 843 831 if ( ! type ) { 832 if ( buildInline() ) { 833 throw SemanticError( "invalid inline specification in declaration of ", this ); 844 if ( ! type ) { 845 if ( buildInline() ) { 846 throw SemanticError( "invalid inline specification in declaration of ", this ); 847 } else { 848 return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ); 849 } 834 850 } else { 835 return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ); 836 } 837 } else { 838 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildInline(), linkage, maybeBuild< Initializer >(initializer) ); 839 return newDecl; 840 } 841 // we should never get here 842 assert( false ); 843 return 0; 851 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildInline(), linkage, maybeBuild< Initializer >(initializer) ); 852 return newDecl; 853 } 854 // we should never get here 855 assert( false ); 856 return 0; 844 857 } 845 858 846 859 Type *DeclarationNode::buildType() const { 847 860 assert( type ); 848 861 849 850 851 return new EnumInstType( type->buildQualifiers(), type->enumeration->name );852 853 ReferenceToType *ret;854 switch ( type->aggregate->kind ) {855 856 857 858 859 860 861 862 863 864 865 866 } // switch867 buildList( type->aggregate->actuals, ret->get_parameters() );868 return ret;869 870 871 TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false );872 buildList( type->symbolic->actuals, ret->get_parameters() );873 return ret;874 875 876 return type->build();877 862 switch ( type->kind ) { 863 case TypeData::Enum: 864 return new EnumInstType( type->buildQualifiers(), type->enumeration->name ); 865 case TypeData::Aggregate: { 866 ReferenceToType *ret; 867 switch ( type->aggregate->kind ) { 868 case DeclarationNode::Struct: 869 ret = new StructInstType( type->buildQualifiers(), type->aggregate->name ); 870 break; 871 case DeclarationNode::Union: 872 ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name ); 873 break; 874 case DeclarationNode::Context: 875 ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name ); 876 break; 877 default: 878 assert( false ); 879 } // switch 880 buildList( type->aggregate->actuals, ret->get_parameters() ); 881 return ret; 882 } 883 case TypeData::Symbolic: { 884 TypeInstType *ret = new TypeInstType( type->buildQualifiers(), type->symbolic->name, false ); 885 buildList( type->symbolic->actuals, ret->get_parameters() ); 886 return ret; 887 } 888 default: 889 return type->build(); 890 } // switch 878 891 } 879 892 880 893 Declaration::StorageClass DeclarationNode::buildStorageClass() const { 881 882 Declaration::Extern,883 Declaration::Static,884 Declaration::Auto,885 Declaration::Register,886 Declaration::Inline,887 Declaration::Fortran888 894 static const Declaration::StorageClass scMap[] = { 895 Declaration::Extern, 896 Declaration::Static, 897 Declaration::Auto, 898 Declaration::Register, 899 Declaration::Inline, 900 Declaration::Fortran 901 }; 889 902 890 Declaration::StorageClass ret = Declaration::NoStorageClass; 891 for ( std::list< StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 892 assert( unsigned( *i ) < sizeof( scMap ) / sizeof( scMap[0] ) ); 893 if ( *i == Inline ) continue; 894 if ( ret == Declaration::NoStorageClass ) { 895 ret = scMap[ *i ]; 903 Declaration::StorageClass ret = Declaration::NoStorageClass; 904 for ( std::list< StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 905 assert( unsigned( *i ) < sizeof( scMap ) / sizeof( scMap[0] ) ); 906 if ( *i == Inline ) continue; 907 if ( ret == Declaration::NoStorageClass ) { 908 ret = scMap[ *i ]; 909 } else { 910 throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 911 } 912 } 913 return ret; 914 } 915 916 bool DeclarationNode::buildInline() const { 917 std::list< StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), Inline ); 918 if ( first == storageClasses.end() ) { 919 return false; 896 920 } else { 897 throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 898 } 899 } 900 return ret; 901 } 902 903 bool DeclarationNode::buildInline() const { 904 std::list< StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), Inline ); 905 if ( first == storageClasses.end() ) { 921 std::list< StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(), Inline ); 922 if ( next == storageClasses.end() ) { 923 return true; 924 } else { 925 throw SemanticError( "duplicate inline specification in declaration of ", this ); 926 } 927 } 928 // we should never get here 906 929 return false; 907 } else { 908 std::list< StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(), Inline ); 909 if ( next == storageClasses.end() ) { 910 return true; 911 } else { 912 throw SemanticError( "duplicate inline specification in declaration of ", this ); 913 } 914 } 915 // we should never get here 916 return false; 917 } 930 } 931 932 // Local Variables: // 933 // tab-width: 4 // 934 // mode: c++ // 935 // compile-command: "make install" // 936 // End: //
Note: See TracChangeset
for help on using the changeset viewer.