[51b7345] | 1 | #include <cassert> |
---|
| 2 | #include <algorithm> |
---|
| 3 | #include <iterator> |
---|
| 4 | #include "utility.h" |
---|
| 5 | #include "TypeData.h" |
---|
| 6 | #include "SynTree/Type.h" |
---|
| 7 | #include "SynTree/Declaration.h" |
---|
| 8 | #include "SynTree/Expression.h" |
---|
| 9 | #include "SynTree/Statement.h" |
---|
| 10 | |
---|
| 11 | |
---|
[c8ffe20b] | 12 | TypeData::TypeData( Kind k ) : kind( k ), base( 0 ), forall( 0 ) { |
---|
| 13 | switch ( kind ) { |
---|
| 14 | case Unknown: |
---|
| 15 | case Pointer: |
---|
| 16 | case EnumConstant: |
---|
| 17 | // nothing else to initialize |
---|
| 18 | break; |
---|
| 19 | case Basic: |
---|
| 20 | basic = new Basic_t; |
---|
| 21 | break; |
---|
| 22 | case Array: |
---|
| 23 | array = new Array_t; |
---|
| 24 | array->dimension = 0; |
---|
| 25 | array->isVarLen = false; |
---|
| 26 | array->isStatic = false; |
---|
| 27 | break; |
---|
| 28 | case Function: |
---|
| 29 | function = new Function_t; |
---|
| 30 | function->params = 0; |
---|
| 31 | function->idList = 0; |
---|
| 32 | function->oldDeclList = 0; |
---|
| 33 | function->body = 0; |
---|
| 34 | function->hasBody = false; |
---|
[0b8cd722] | 35 | function->newStyle = false; |
---|
[c8ffe20b] | 36 | break; |
---|
| 37 | case Aggregate: |
---|
| 38 | aggregate = new Aggregate_t; |
---|
| 39 | aggregate->params = 0; |
---|
| 40 | aggregate->actuals = 0; |
---|
| 41 | aggregate->members = 0; |
---|
| 42 | break; |
---|
| 43 | case AggregateInst: |
---|
| 44 | aggInst = new AggInst_t; |
---|
| 45 | aggInst->aggregate = 0; |
---|
| 46 | aggInst->params = 0; |
---|
| 47 | break; |
---|
| 48 | case Enum: |
---|
| 49 | enumeration = new Enumeration_t; |
---|
| 50 | enumeration->constants = 0; |
---|
| 51 | break; |
---|
| 52 | case Symbolic: |
---|
| 53 | case SymbolicInst: |
---|
| 54 | symbolic = new Symbolic_t; |
---|
| 55 | symbolic->params = 0; |
---|
| 56 | symbolic->actuals = 0; |
---|
| 57 | symbolic->assertions = 0; |
---|
| 58 | break; |
---|
| 59 | case Variable: |
---|
| 60 | variable = new Variable_t; |
---|
| 61 | variable->tyClass = DeclarationNode::Type; |
---|
| 62 | variable->assertions = 0; |
---|
| 63 | break; |
---|
| 64 | case Tuple: |
---|
| 65 | tuple = new Tuple_t; |
---|
| 66 | tuple->members = 0; |
---|
| 67 | break; |
---|
[51b7345] | 68 | |
---|
[c8ffe20b] | 69 | case Typeof: |
---|
| 70 | typeexpr = new Typeof_t; |
---|
| 71 | typeexpr->expr = 0; |
---|
| 72 | break; |
---|
[51b7345] | 73 | |
---|
[c8ffe20b] | 74 | case Attr: |
---|
| 75 | attr = new Attr_t; |
---|
| 76 | attr->expr = 0; |
---|
| 77 | attr->type = 0; |
---|
| 78 | break; |
---|
| 79 | } |
---|
[51b7345] | 80 | } |
---|
| 81 | |
---|
[c8ffe20b] | 82 | TypeData::~TypeData() { |
---|
| 83 | delete base; |
---|
| 84 | delete forall; |
---|
[51b7345] | 85 | |
---|
[c8ffe20b] | 86 | switch ( kind ) { |
---|
| 87 | case Unknown: |
---|
| 88 | case Pointer: |
---|
| 89 | case EnumConstant: |
---|
| 90 | // nothing to destroy |
---|
| 91 | break; |
---|
| 92 | case Basic: |
---|
| 93 | delete basic; |
---|
| 94 | break; |
---|
| 95 | case Array: |
---|
| 96 | delete array->dimension; |
---|
| 97 | delete array; |
---|
| 98 | break; |
---|
| 99 | case Function: |
---|
| 100 | delete function->params; |
---|
| 101 | delete function->idList; |
---|
| 102 | delete function->oldDeclList; |
---|
| 103 | delete function->body; |
---|
| 104 | delete function; |
---|
| 105 | break; |
---|
| 106 | case Aggregate: |
---|
| 107 | delete aggregate->params; |
---|
| 108 | delete aggregate->actuals; |
---|
| 109 | delete aggregate->members; |
---|
| 110 | delete aggregate; |
---|
| 111 | break; |
---|
| 112 | case AggregateInst: |
---|
| 113 | delete aggInst->aggregate; |
---|
| 114 | delete aggInst->params; |
---|
| 115 | delete aggInst; |
---|
| 116 | break; |
---|
| 117 | case Enum: |
---|
| 118 | delete enumeration->constants; |
---|
| 119 | delete enumeration; |
---|
| 120 | break; |
---|
| 121 | case Symbolic: |
---|
| 122 | case SymbolicInst: |
---|
| 123 | delete symbolic->params; |
---|
| 124 | delete symbolic->actuals; |
---|
| 125 | delete symbolic->assertions; |
---|
| 126 | delete symbolic; |
---|
| 127 | break; |
---|
| 128 | case Variable: |
---|
| 129 | delete variable->assertions; |
---|
| 130 | delete variable; |
---|
| 131 | break; |
---|
| 132 | case Tuple: |
---|
| 133 | delete tuple->members; |
---|
| 134 | delete tuple; |
---|
| 135 | break; |
---|
[51b7345] | 136 | |
---|
[c8ffe20b] | 137 | case Typeof: |
---|
| 138 | delete typeexpr->expr; |
---|
| 139 | delete typeexpr; |
---|
| 140 | break; |
---|
[51b7345] | 141 | |
---|
[c8ffe20b] | 142 | case Attr: |
---|
| 143 | delete attr->expr; |
---|
| 144 | delete attr->type; |
---|
| 145 | delete attr; |
---|
| 146 | break; |
---|
| 147 | } |
---|
[51b7345] | 148 | } |
---|
| 149 | |
---|
[c8ffe20b] | 150 | TypeData *TypeData::clone() const { |
---|
| 151 | TypeData *newtype = new TypeData( kind ); |
---|
| 152 | newtype->qualifiers = qualifiers; |
---|
| 153 | newtype->base = maybeClone( base ); |
---|
| 154 | newtype->forall = maybeClone( forall ); |
---|
| 155 | |
---|
| 156 | switch ( kind ) { |
---|
| 157 | case Unknown: |
---|
| 158 | case EnumConstant: |
---|
| 159 | case Pointer: |
---|
| 160 | // nothing else to copy |
---|
| 161 | break; |
---|
| 162 | case Basic: |
---|
| 163 | newtype->basic->typeSpec = basic->typeSpec; |
---|
| 164 | newtype->basic->modifiers = basic->modifiers; |
---|
| 165 | break; |
---|
| 166 | case Array: |
---|
| 167 | newtype->array->dimension = maybeClone( array->dimension ); |
---|
| 168 | newtype->array->isVarLen = array->isVarLen; |
---|
| 169 | newtype->array->isStatic = array->isStatic; |
---|
| 170 | break; |
---|
| 171 | case Function: |
---|
| 172 | newtype->function->params = maybeClone( function->params ); |
---|
| 173 | newtype->function->idList = maybeClone( function->idList ); |
---|
| 174 | newtype->function->oldDeclList = maybeClone( function->oldDeclList ); |
---|
| 175 | newtype->function->body = maybeClone( function->body ); |
---|
| 176 | newtype->function->hasBody = function->hasBody; |
---|
| 177 | newtype->function->newStyle = function->newStyle; |
---|
| 178 | break; |
---|
| 179 | case Aggregate: |
---|
| 180 | newtype->aggregate->params = maybeClone( aggregate->params ); |
---|
| 181 | newtype->aggregate->actuals = maybeClone( aggregate->actuals ); |
---|
| 182 | newtype->aggregate->members = maybeClone( aggregate->members ); |
---|
| 183 | newtype->aggregate->name = aggregate->name; |
---|
| 184 | newtype->aggregate->kind = aggregate->kind; |
---|
| 185 | break; |
---|
| 186 | case AggregateInst: |
---|
| 187 | newtype->aggInst->aggregate = maybeClone( aggInst->aggregate ); |
---|
| 188 | newtype->aggInst->params = maybeClone( aggInst->params ); |
---|
| 189 | break; |
---|
| 190 | case Enum: |
---|
| 191 | newtype->enumeration->name = enumeration->name; |
---|
| 192 | newtype->enumeration->constants = maybeClone( enumeration->constants ); |
---|
| 193 | break; |
---|
| 194 | case Symbolic: |
---|
| 195 | case SymbolicInst: |
---|
| 196 | newtype->symbolic->params = maybeClone( symbolic->params ); |
---|
| 197 | newtype->symbolic->actuals = maybeClone( symbolic->actuals ); |
---|
| 198 | newtype->symbolic->assertions = maybeClone( symbolic->assertions ); |
---|
| 199 | newtype->symbolic->isTypedef = symbolic->isTypedef; |
---|
| 200 | newtype->symbolic->name = symbolic->name; |
---|
| 201 | break; |
---|
| 202 | case Variable: |
---|
| 203 | newtype->variable->assertions = maybeClone( variable->assertions ); |
---|
| 204 | newtype->variable->name = variable->name; |
---|
| 205 | newtype->variable->tyClass = variable->tyClass; |
---|
| 206 | break; |
---|
| 207 | case Tuple: |
---|
| 208 | newtype->tuple->members = maybeClone( tuple->members ); |
---|
| 209 | break; |
---|
[51b7345] | 210 | |
---|
[c8ffe20b] | 211 | case Typeof: |
---|
| 212 | newtype->typeexpr->expr = maybeClone( typeexpr->expr ); |
---|
| 213 | break; |
---|
[51b7345] | 214 | |
---|
[c8ffe20b] | 215 | case Attr: |
---|
| 216 | newtype->attr->expr = maybeClone( attr->expr ); |
---|
| 217 | newtype->attr->type = maybeClone( attr->type ); |
---|
| 218 | break; |
---|
[51b7345] | 219 | } |
---|
[c8ffe20b] | 220 | return newtype; |
---|
| 221 | } |
---|
[51b7345] | 222 | |
---|
[c8ffe20b] | 223 | void TypeData::print( std::ostream &os, int indent ) const { |
---|
| 224 | using std::endl; |
---|
| 225 | using std::string; |
---|
[51b7345] | 226 | |
---|
[c8ffe20b] | 227 | printEnums( qualifiers.begin(), qualifiers.end(), DeclarationNode::qualifierName, os ); |
---|
[51b7345] | 228 | |
---|
[c8ffe20b] | 229 | if ( forall ) { |
---|
| 230 | os << "forall " << endl; |
---|
| 231 | forall->printList( os, indent+4 ); |
---|
[51b7345] | 232 | } |
---|
| 233 | |
---|
[c8ffe20b] | 234 | switch ( kind ) { |
---|
| 235 | case Unknown: |
---|
| 236 | os << "entity of unknown type "; |
---|
| 237 | break; |
---|
| 238 | case Pointer: |
---|
| 239 | os << "pointer "; |
---|
| 240 | if ( base ) { |
---|
| 241 | os << "to "; |
---|
| 242 | base->print( os, indent ); |
---|
| 243 | } |
---|
| 244 | break; |
---|
| 245 | case EnumConstant: |
---|
| 246 | os << "enumeration constant "; |
---|
| 247 | break; |
---|
| 248 | case Basic: |
---|
| 249 | printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os ); |
---|
| 250 | printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os ); |
---|
| 251 | break; |
---|
| 252 | case Array: |
---|
| 253 | if ( array->isStatic ) { |
---|
| 254 | os << "static "; |
---|
| 255 | } |
---|
| 256 | if ( array->dimension ) { |
---|
| 257 | os << "array of "; |
---|
| 258 | array->dimension->printOneLine( os, indent ); |
---|
| 259 | } else if ( array->isVarLen ) { |
---|
| 260 | os << "variable-length array of "; |
---|
| 261 | } else { |
---|
| 262 | os << "open array of "; |
---|
| 263 | } |
---|
| 264 | if ( base ) { |
---|
| 265 | base->print( os, indent ); |
---|
| 266 | } |
---|
| 267 | break; |
---|
| 268 | case Function: |
---|
| 269 | os << "function" << endl; |
---|
| 270 | if ( function->params ) { |
---|
| 271 | os << string( indent+2, ' ' ) << "with parameters " << endl; |
---|
| 272 | function->params->printList( os, indent+4 ); |
---|
| 273 | } else { |
---|
| 274 | os << string( indent+2, ' ' ) << "with no parameters " << endl; |
---|
| 275 | } |
---|
| 276 | if ( function->idList ) { |
---|
| 277 | os << string( indent+2, ' ' ) << "with old-style identifier list " << endl; |
---|
| 278 | function->idList->printList( os, indent+4 ); |
---|
| 279 | } |
---|
| 280 | if ( function->oldDeclList ) { |
---|
| 281 | os << string( indent+2, ' ' ) << "with old-style declaration list " << endl; |
---|
| 282 | function->oldDeclList->printList( os, indent+4 ); |
---|
| 283 | } |
---|
| 284 | os << string( indent+2, ' ' ) << "returning "; |
---|
| 285 | if ( base ) { |
---|
| 286 | base->print( os, indent+4 ); |
---|
| 287 | } else { |
---|
| 288 | os << "nothing "; |
---|
| 289 | } |
---|
| 290 | os << endl; |
---|
| 291 | if ( function->hasBody ) { |
---|
| 292 | os << string( indent+2, ' ' ) << "with body " << endl; |
---|
| 293 | } |
---|
| 294 | if ( function->body ) { |
---|
| 295 | function->body->printList( os, indent+2 ); |
---|
| 296 | } |
---|
| 297 | break; |
---|
| 298 | case Aggregate: |
---|
| 299 | os << DeclarationNode::tyConName[ aggregate->kind ] << ' ' << aggregate->name << endl; |
---|
| 300 | if ( aggregate->params ) { |
---|
| 301 | os << string( indent+2, ' ' ) << "with type parameters " << endl; |
---|
| 302 | aggregate->params->printList( os, indent+4 ); |
---|
| 303 | } |
---|
| 304 | if ( aggregate->actuals ) { |
---|
| 305 | os << string( indent+2, ' ' ) << "instantiated with actual parameters " << endl; |
---|
| 306 | aggregate->actuals->printList( os, indent+4 ); |
---|
| 307 | } |
---|
| 308 | if ( aggregate->members ) { |
---|
| 309 | os << string( indent+2, ' ' ) << "with members " << endl; |
---|
| 310 | aggregate->members->printList( os, indent+4 ); |
---|
[51b7345] | 311 | /// } else { |
---|
| 312 | /// os << string( indent+2, ' ' ) << "with no members " << endl; |
---|
[c8ffe20b] | 313 | } |
---|
| 314 | break; |
---|
| 315 | case AggregateInst: |
---|
| 316 | if ( aggInst->aggregate ) { |
---|
| 317 | os << "instance of " ; |
---|
| 318 | aggInst->aggregate->print( os, indent ); |
---|
| 319 | } else { |
---|
| 320 | os << "instance of an unspecified aggregate "; |
---|
| 321 | } |
---|
| 322 | if ( aggInst->params ) { |
---|
| 323 | os << string( indent+2, ' ' ) << "with parameters " << endl; |
---|
| 324 | aggInst->params->printList( os, indent+2 ); |
---|
| 325 | } |
---|
| 326 | break; |
---|
| 327 | case Enum: |
---|
| 328 | os << "enumeration "; |
---|
| 329 | if ( enumeration->constants ) { |
---|
| 330 | os << "with constants" << endl; |
---|
| 331 | enumeration->constants->printList( os, indent+2 ); |
---|
| 332 | } |
---|
| 333 | break; |
---|
| 334 | case SymbolicInst: |
---|
| 335 | os << "instance of type " << symbolic->name; |
---|
| 336 | if ( symbolic->actuals ) { |
---|
| 337 | os << " with parameters" << endl; |
---|
| 338 | symbolic->actuals->printList( os, indent + 2 ); |
---|
| 339 | } |
---|
| 340 | break; |
---|
| 341 | case Symbolic: |
---|
| 342 | if ( symbolic->isTypedef ) { |
---|
| 343 | os << "typedef definition "; |
---|
| 344 | } else { |
---|
| 345 | os << "type definition "; |
---|
| 346 | } |
---|
| 347 | if ( symbolic->params ) { |
---|
| 348 | os << endl << string( indent+2, ' ' ) << "with parameters" << endl; |
---|
| 349 | symbolic->params->printList( os, indent + 2 ); |
---|
| 350 | } |
---|
| 351 | if ( symbolic->assertions ) { |
---|
| 352 | os << endl << string( indent+2, ' ' ) << "with assertions" << endl; |
---|
| 353 | symbolic->assertions->printList( os, indent + 4 ); |
---|
| 354 | os << string( indent+2, ' ' ); |
---|
| 355 | } |
---|
| 356 | if ( base ) { |
---|
| 357 | os << "for "; |
---|
| 358 | base->print( os, indent + 2 ); |
---|
| 359 | } |
---|
| 360 | break; |
---|
| 361 | case Variable: |
---|
| 362 | os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable "; |
---|
| 363 | if ( variable->assertions ) { |
---|
| 364 | os << endl << string( indent+2, ' ' ) << "with assertions" << endl; |
---|
| 365 | variable->assertions->printList( os, indent + 4 ); |
---|
| 366 | os << string( indent+2, ' ' ); |
---|
| 367 | } |
---|
| 368 | break; |
---|
| 369 | case Tuple: |
---|
| 370 | os << "tuple "; |
---|
| 371 | if ( tuple->members ) { |
---|
| 372 | os << "with members " << endl; |
---|
| 373 | tuple->members->printList( os, indent + 2 ); |
---|
| 374 | } |
---|
| 375 | break; |
---|
[51b7345] | 376 | |
---|
[c8ffe20b] | 377 | case Typeof: |
---|
| 378 | os << "type-of expression "; |
---|
| 379 | if ( typeexpr->expr ) { |
---|
| 380 | typeexpr->expr->print( os, indent + 2 ); |
---|
| 381 | } |
---|
| 382 | break; |
---|
[51b7345] | 383 | |
---|
[c8ffe20b] | 384 | case Attr: |
---|
| 385 | os << "attribute type decl " << attr->name << " applied to "; |
---|
| 386 | if ( attr->expr ) { |
---|
| 387 | attr->expr->print( os, indent + 2 ); |
---|
| 388 | } |
---|
| 389 | if ( attr->type ) { |
---|
| 390 | attr->type->print( os, indent + 2 ); |
---|
| 391 | } |
---|
| 392 | break; |
---|
[51b7345] | 393 | } |
---|
| 394 | } |
---|
| 395 | |
---|
[c8ffe20b] | 396 | TypeData *TypeData::extractAggregate( bool toplevel ) const { |
---|
| 397 | TypeData *ret = 0; |
---|
[51b7345] | 398 | |
---|
[c8ffe20b] | 399 | switch ( kind ) { |
---|
| 400 | case Aggregate: |
---|
| 401 | if ( !toplevel && aggregate->members ) { |
---|
| 402 | ret = clone(); |
---|
| 403 | ret->qualifiers.clear(); |
---|
| 404 | } |
---|
| 405 | break; |
---|
| 406 | case Enum: |
---|
| 407 | if ( !toplevel && enumeration->constants ) { |
---|
| 408 | ret = clone(); |
---|
| 409 | ret->qualifiers.clear(); |
---|
| 410 | } |
---|
| 411 | break; |
---|
| 412 | case AggregateInst: |
---|
| 413 | if ( aggInst->aggregate ) { |
---|
| 414 | ret = aggInst->aggregate->extractAggregate( false ); |
---|
| 415 | } |
---|
| 416 | break; |
---|
| 417 | default: |
---|
| 418 | if ( base ) { |
---|
| 419 | ret = base->extractAggregate( false ); |
---|
| 420 | } |
---|
[51b7345] | 421 | } |
---|
[c8ffe20b] | 422 | return ret; |
---|
[51b7345] | 423 | } |
---|
| 424 | |
---|
[c8ffe20b] | 425 | void buildForall( const DeclarationNode *firstNode, std::list< TypeDecl* > &outputList ) { |
---|
[51b7345] | 426 | |
---|
[c8ffe20b] | 427 | buildList( firstNode, outputList ); |
---|
| 428 | for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) { |
---|
| 429 | if ( (*i)->get_kind() == TypeDecl::Any ) { |
---|
| 430 | FunctionType *assignType = new FunctionType( Type::Qualifiers(), false ); |
---|
| 431 | assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) ); |
---|
| 432 | assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) ); |
---|
| 433 | assignType->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) ); |
---|
| 434 | (*i)->get_assertions().push_front( new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false ) ); |
---|
| 435 | } |
---|
[51b7345] | 436 | } |
---|
| 437 | } |
---|
| 438 | |
---|
[c8ffe20b] | 439 | Declaration *TypeData::buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init ) const { |
---|
| 440 | if ( kind == TypeData::Function ) { |
---|
| 441 | FunctionDecl *decl; |
---|
| 442 | if ( function->hasBody ) { |
---|
| 443 | if ( function->body ) { |
---|
| 444 | Statement *stmt = function->body->build(); |
---|
| 445 | CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt ); |
---|
| 446 | assert( body ); |
---|
| 447 | decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline ); |
---|
| 448 | } else { |
---|
| 449 | // std::list<Label> ls; |
---|
| 450 | decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline ); |
---|
| 451 | } |
---|
| 452 | } else { |
---|
| 453 | decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline ); |
---|
| 454 | } |
---|
| 455 | for ( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_link() ) ) { |
---|
| 456 | if ( cur->get_name() != "" ) { |
---|
| 457 | decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | buildList( function->oldDeclList, decl->get_oldDecls() ); |
---|
| 461 | return decl; |
---|
| 462 | } else if ( kind == TypeData::Aggregate ) { |
---|
| 463 | return buildAggregate(); |
---|
| 464 | } else if ( kind == TypeData::Enum ) { |
---|
| 465 | return buildEnum(); |
---|
| 466 | } else if ( kind == TypeData::Symbolic ) { |
---|
| 467 | return buildSymbolic( name, sc ); |
---|
| 468 | } else if ( kind == TypeData::Variable ) { |
---|
| 469 | return buildVariable(); |
---|
[51b7345] | 470 | } else { |
---|
[c8ffe20b] | 471 | if ( isInline ) { |
---|
| 472 | throw SemanticError( "invalid inline specification in declaration of ", this ); |
---|
| 473 | } else { |
---|
| 474 | return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init ); |
---|
| 475 | } |
---|
[51b7345] | 476 | } |
---|
[c8ffe20b] | 477 | return 0; |
---|
[51b7345] | 478 | } |
---|
| 479 | |
---|
[c8ffe20b] | 480 | Type *TypeData::build() const { |
---|
[51b7345] | 481 | |
---|
[c8ffe20b] | 482 | switch ( kind ) { |
---|
| 483 | case Unknown: |
---|
| 484 | // fill in implicit int |
---|
| 485 | return new BasicType( buildQualifiers(), BasicType::SignedInt ); |
---|
[51b7345] | 486 | |
---|
[c8ffe20b] | 487 | case Basic: |
---|
| 488 | return buildBasicType(); |
---|
[51b7345] | 489 | |
---|
[c8ffe20b] | 490 | case Pointer: |
---|
| 491 | return buildPointer(); |
---|
[51b7345] | 492 | |
---|
[c8ffe20b] | 493 | case Array: |
---|
| 494 | return buildArray(); |
---|
[51b7345] | 495 | |
---|
[c8ffe20b] | 496 | case Function: |
---|
| 497 | return buildFunction(); |
---|
[51b7345] | 498 | |
---|
[c8ffe20b] | 499 | case AggregateInst: |
---|
| 500 | return buildAggInst(); |
---|
[51b7345] | 501 | |
---|
[c8ffe20b] | 502 | case EnumConstant: |
---|
| 503 | // the name gets filled in later -- by SymTab::Validate |
---|
| 504 | return new EnumInstType( buildQualifiers(), "" ); |
---|
[51b7345] | 505 | |
---|
[c8ffe20b] | 506 | case SymbolicInst: |
---|
| 507 | return buildSymbolicInst();; |
---|
[51b7345] | 508 | |
---|
[c8ffe20b] | 509 | case Tuple: |
---|
| 510 | return buildTuple(); |
---|
[51b7345] | 511 | |
---|
[c8ffe20b] | 512 | case Typeof: |
---|
| 513 | return buildTypeof(); |
---|
[51b7345] | 514 | |
---|
[c8ffe20b] | 515 | case Attr: |
---|
| 516 | return buildAttr(); |
---|
[51b7345] | 517 | |
---|
[c8ffe20b] | 518 | case Symbolic: |
---|
| 519 | case Enum: |
---|
| 520 | case Aggregate: |
---|
| 521 | case Variable: |
---|
| 522 | assert( false ); |
---|
[51b7345] | 523 | } |
---|
| 524 | |
---|
[c8ffe20b] | 525 | return 0; |
---|
| 526 | } |
---|
[51b7345] | 527 | |
---|
[c8ffe20b] | 528 | Type::Qualifiers TypeData::buildQualifiers() const { |
---|
| 529 | Type::Qualifiers q; |
---|
| 530 | for ( std::list< DeclarationNode::Qualifier >::const_iterator i = qualifiers.begin(); i != qualifiers.end(); ++i ) { |
---|
| 531 | switch ( *i ) { |
---|
| 532 | case DeclarationNode::Const: |
---|
| 533 | q.isConst = true; |
---|
[51b7345] | 534 | break; |
---|
[c8ffe20b] | 535 | case DeclarationNode::Volatile: |
---|
| 536 | q.isVolatile = true; |
---|
| 537 | break; |
---|
| 538 | case DeclarationNode::Restrict: |
---|
| 539 | q.isRestrict = true; |
---|
| 540 | break; |
---|
| 541 | case DeclarationNode::Lvalue: |
---|
| 542 | q.isLvalue = true; |
---|
[51b7345] | 543 | break; |
---|
[bdd516a] | 544 | case DeclarationNode::Atomic: |
---|
| 545 | q.isAtomic = true; |
---|
| 546 | break; |
---|
[51b7345] | 547 | } |
---|
[c8ffe20b] | 548 | } |
---|
| 549 | return q; |
---|
| 550 | } |
---|
[51b7345] | 551 | |
---|
[c8ffe20b] | 552 | Type *TypeData::buildBasicType() const { |
---|
| 553 | static const BasicType::Kind kindMap[] = { BasicType::Char, BasicType::SignedInt, BasicType::Float, BasicType::Double, |
---|
| 554 | BasicType::Char /* void */, BasicType::Bool, BasicType::DoubleComplex, |
---|
| 555 | BasicType::DoubleImaginary }; |
---|
| 556 | bool init = false; |
---|
| 557 | bool sawDouble = false; |
---|
| 558 | bool sawSigned = false; |
---|
| 559 | BasicType::Kind ret; |
---|
| 560 | |
---|
| 561 | for ( std::list< DeclarationNode::BasicType >::const_iterator i = basic->typeSpec.begin(); i != basic->typeSpec.end(); ++i ) { |
---|
| 562 | if ( !init ) { |
---|
| 563 | init = true; |
---|
| 564 | if ( *i == DeclarationNode::Void ) { |
---|
| 565 | if ( basic->typeSpec.size() != 1 || !basic->modifiers.empty() ) { |
---|
[17cd4eb] | 566 | throw SemanticError( "invalid type specifier \"void\" in type: ", this ); |
---|
[c8ffe20b] | 567 | } else { |
---|
| 568 | return new VoidType( buildQualifiers() ); |
---|
| 569 | } |
---|
| 570 | } else { |
---|
| 571 | ret = kindMap[ *i ]; |
---|
| 572 | } |
---|
[51b7345] | 573 | } else { |
---|
[c8ffe20b] | 574 | switch ( *i ) { |
---|
| 575 | case DeclarationNode::Float: |
---|
| 576 | if ( sawDouble ) { |
---|
[17cd4eb] | 577 | throw SemanticError( "invalid type specifier \"float\" in type: ", this ); |
---|
[c8ffe20b] | 578 | } else { |
---|
| 579 | switch ( ret ) { |
---|
| 580 | case BasicType::DoubleComplex: |
---|
| 581 | ret = BasicType::FloatComplex; |
---|
| 582 | break; |
---|
| 583 | case BasicType::DoubleImaginary: |
---|
| 584 | ret = BasicType::FloatImaginary; |
---|
| 585 | break; |
---|
| 586 | default: |
---|
[17cd4eb] | 587 | throw SemanticError( "invalid type specifier \"float\" in type: ", this ); |
---|
[c8ffe20b] | 588 | } |
---|
| 589 | } |
---|
| 590 | break; |
---|
| 591 | case DeclarationNode::Double: |
---|
| 592 | if ( sawDouble ) { |
---|
[17cd4eb] | 593 | throw SemanticError( "duplicate type specifier \"double\" in type: ", this ); |
---|
[c8ffe20b] | 594 | } else { |
---|
| 595 | switch ( ret ) { |
---|
| 596 | case BasicType::DoubleComplex: |
---|
| 597 | case BasicType::DoubleImaginary: |
---|
| 598 | break; |
---|
| 599 | default: |
---|
[17cd4eb] | 600 | throw SemanticError( "invalid type specifier \"double\" in type: ", this ); |
---|
[c8ffe20b] | 601 | } |
---|
| 602 | } |
---|
| 603 | break; |
---|
[51b7345] | 604 | |
---|
[c8ffe20b] | 605 | case DeclarationNode::Complex: |
---|
| 606 | switch ( ret ) { |
---|
| 607 | case BasicType::Float: |
---|
| 608 | ret = BasicType::FloatComplex; |
---|
| 609 | break; |
---|
[51b7345] | 610 | |
---|
[c8ffe20b] | 611 | case BasicType::Double: |
---|
| 612 | ret = BasicType::DoubleComplex; |
---|
| 613 | break; |
---|
| 614 | default: |
---|
[17cd4eb] | 615 | throw SemanticError( "invalid type specifier \"_Complex\" in type: ", this ); |
---|
[c8ffe20b] | 616 | } |
---|
| 617 | break; |
---|
[51b7345] | 618 | |
---|
[c8ffe20b] | 619 | case DeclarationNode::Imaginary: |
---|
| 620 | switch ( ret ) { |
---|
| 621 | case BasicType::Float: |
---|
| 622 | ret = BasicType::FloatImaginary; |
---|
| 623 | break; |
---|
[51b7345] | 624 | |
---|
[c8ffe20b] | 625 | case BasicType::Double: |
---|
| 626 | ret = BasicType::DoubleImaginary; |
---|
| 627 | break; |
---|
| 628 | default: |
---|
[17cd4eb] | 629 | throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", this ); |
---|
[c8ffe20b] | 630 | } |
---|
| 631 | break; |
---|
[51b7345] | 632 | |
---|
[c8ffe20b] | 633 | default: |
---|
[17cd4eb] | 634 | throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", this ); |
---|
[c8ffe20b] | 635 | } |
---|
[51b7345] | 636 | } |
---|
[c8ffe20b] | 637 | if ( *i == DeclarationNode::Double ) { |
---|
| 638 | sawDouble = true; |
---|
[51b7345] | 639 | } |
---|
[c8ffe20b] | 640 | } |
---|
[51b7345] | 641 | |
---|
[c8ffe20b] | 642 | for ( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i != basic->modifiers.end(); ++i ) { |
---|
| 643 | switch ( *i ) { |
---|
| 644 | case DeclarationNode::Long: |
---|
| 645 | if ( !init ) { |
---|
| 646 | init = true; |
---|
| 647 | ret = BasicType::LongSignedInt; |
---|
| 648 | } else { |
---|
| 649 | switch ( ret ) { |
---|
| 650 | case BasicType::SignedInt: |
---|
| 651 | ret = BasicType::LongSignedInt; |
---|
| 652 | break; |
---|
| 653 | case BasicType::UnsignedInt: |
---|
| 654 | ret = BasicType::LongUnsignedInt; |
---|
| 655 | break; |
---|
| 656 | case BasicType::LongSignedInt: |
---|
| 657 | ret = BasicType::LongLongSignedInt; |
---|
| 658 | break; |
---|
| 659 | case BasicType::LongUnsignedInt: |
---|
| 660 | ret = BasicType::LongLongUnsignedInt; |
---|
| 661 | break; |
---|
| 662 | case BasicType::Double: |
---|
| 663 | ret = BasicType::LongDouble; |
---|
| 664 | break; |
---|
| 665 | case BasicType::DoubleComplex: |
---|
| 666 | ret = BasicType::LongDoubleComplex; |
---|
| 667 | break; |
---|
| 668 | case BasicType::DoubleImaginary: |
---|
| 669 | ret = BasicType::LongDoubleImaginary; |
---|
| 670 | break; |
---|
| 671 | default: |
---|
[17cd4eb] | 672 | throw SemanticError( "invalid type modifier \"long\" in type: ", this ); |
---|
[c8ffe20b] | 673 | } |
---|
| 674 | } |
---|
| 675 | break; |
---|
| 676 | case DeclarationNode::Short: |
---|
| 677 | if ( !init ) { |
---|
| 678 | init = true; |
---|
| 679 | ret = BasicType::ShortSignedInt; |
---|
| 680 | } else { |
---|
| 681 | switch ( ret ) { |
---|
| 682 | case BasicType::SignedInt: |
---|
| 683 | ret = BasicType::ShortSignedInt; |
---|
| 684 | break; |
---|
| 685 | case BasicType::UnsignedInt: |
---|
| 686 | ret = BasicType::ShortUnsignedInt; |
---|
| 687 | break; |
---|
| 688 | default: |
---|
[17cd4eb] | 689 | throw SemanticError( "invalid type modifier \"short\" in type: ", this ); |
---|
[c8ffe20b] | 690 | } |
---|
| 691 | } |
---|
| 692 | break; |
---|
| 693 | case DeclarationNode::Signed: |
---|
| 694 | if ( !init ) { |
---|
| 695 | init = true; |
---|
| 696 | ret = BasicType::SignedInt; |
---|
| 697 | } else if ( sawSigned ) { |
---|
[17cd4eb] | 698 | throw SemanticError( "duplicate type modifer \"signed\" in type: ", this ); |
---|
[c8ffe20b] | 699 | } else { |
---|
| 700 | switch ( ret ) { |
---|
[6c3744e] | 701 | case BasicType::LongLongSignedInt: // PAB |
---|
| 702 | ret = BasicType::LongLongUnsignedInt; |
---|
| 703 | break; |
---|
| 704 | case BasicType::LongSignedInt: |
---|
| 705 | ret = BasicType::LongUnsignedInt; |
---|
| 706 | break; |
---|
[c8ffe20b] | 707 | case BasicType::SignedInt: |
---|
| 708 | case BasicType::ShortSignedInt: |
---|
| 709 | break; |
---|
| 710 | case BasicType::Char: |
---|
| 711 | ret = BasicType::SignedChar; |
---|
| 712 | break; |
---|
| 713 | default: |
---|
[17cd4eb] | 714 | throw SemanticError( "invalid type modifer \"signed\" in type: ", this ); |
---|
[c8ffe20b] | 715 | } |
---|
| 716 | } |
---|
| 717 | break; |
---|
| 718 | case DeclarationNode::Unsigned: |
---|
| 719 | if ( !init ) { |
---|
| 720 | init = true; |
---|
| 721 | ret = BasicType::UnsignedInt; |
---|
| 722 | } else if ( sawSigned ) { |
---|
[17cd4eb] | 723 | throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this ); |
---|
[c8ffe20b] | 724 | } else { |
---|
| 725 | switch ( ret ) { |
---|
[6c3744e] | 726 | case BasicType::LongLongSignedInt: // PAB |
---|
| 727 | ret = BasicType::LongLongUnsignedInt; |
---|
| 728 | break; |
---|
[c8ffe20b] | 729 | case BasicType::LongSignedInt: |
---|
| 730 | ret = BasicType::LongUnsignedInt; |
---|
| 731 | break; |
---|
| 732 | case BasicType::SignedInt: |
---|
| 733 | ret = BasicType::UnsignedInt; |
---|
| 734 | break; |
---|
| 735 | case BasicType::ShortSignedInt: |
---|
| 736 | ret = BasicType::ShortUnsignedInt; |
---|
| 737 | break; |
---|
| 738 | case BasicType::Char: |
---|
| 739 | ret = BasicType::UnsignedChar; |
---|
| 740 | break; |
---|
| 741 | default: |
---|
[17cd4eb] | 742 | throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this ); |
---|
[c8ffe20b] | 743 | } |
---|
| 744 | } |
---|
| 745 | break; |
---|
[51b7345] | 746 | } |
---|
| 747 | |
---|
[c8ffe20b] | 748 | if ( *i == DeclarationNode::Signed ) { |
---|
| 749 | sawSigned = true; |
---|
[51b7345] | 750 | } |
---|
| 751 | } |
---|
| 752 | |
---|
[c8ffe20b] | 753 | BasicType *bt; |
---|
| 754 | if ( !init ) { |
---|
| 755 | bt = new BasicType( buildQualifiers(), BasicType::SignedInt ); |
---|
| 756 | } else { |
---|
| 757 | bt = new BasicType( buildQualifiers(), ret ); |
---|
[51b7345] | 758 | } |
---|
[c8ffe20b] | 759 | buildForall( forall, bt->get_forall() ); |
---|
| 760 | return bt; |
---|
[51b7345] | 761 | } |
---|
| 762 | |
---|
| 763 | |
---|
[c8ffe20b] | 764 | PointerType *TypeData::buildPointer() const { |
---|
| 765 | PointerType *pt; |
---|
| 766 | if ( base ) { |
---|
| 767 | pt = new PointerType( buildQualifiers(), base->build() ); |
---|
| 768 | } else { |
---|
| 769 | pt = new PointerType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); |
---|
| 770 | } |
---|
| 771 | buildForall( forall, pt->get_forall() ); |
---|
| 772 | return pt; |
---|
[51b7345] | 773 | } |
---|
| 774 | |
---|
[c8ffe20b] | 775 | ArrayType *TypeData::buildArray() const { |
---|
[51b7345] | 776 | |
---|
[c8ffe20b] | 777 | ArrayType *at; |
---|
| 778 | if ( base ) { |
---|
| 779 | at = new ArrayType( buildQualifiers(), base->build(), maybeBuild< Expression >( array->dimension ), |
---|
| 780 | array->isVarLen, array->isStatic ); |
---|
| 781 | } else { |
---|
| 782 | at = new ArrayType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), |
---|
| 783 | maybeBuild< Expression >( array->dimension ), array->isVarLen, array->isStatic ); |
---|
| 784 | } |
---|
| 785 | buildForall( forall, at->get_forall() ); |
---|
| 786 | return at; |
---|
[51b7345] | 787 | } |
---|
| 788 | |
---|
[c8ffe20b] | 789 | FunctionType *TypeData::buildFunction() const { |
---|
| 790 | assert( kind == Function ); |
---|
| 791 | bool hasEllipsis = function->params ? function->params->get_hasEllipsis() : true; |
---|
| 792 | if ( !function->params ) hasEllipsis = !function->newStyle; |
---|
| 793 | FunctionType *ft = new FunctionType( buildQualifiers(), hasEllipsis ); |
---|
| 794 | buildList( function->params, ft->get_parameters() ); |
---|
| 795 | buildForall( forall, ft->get_forall() ); |
---|
| 796 | if ( base ) { |
---|
| 797 | switch ( base->kind ) { |
---|
| 798 | case Tuple: |
---|
| 799 | buildList( base->tuple->members, ft->get_returnVals() ); |
---|
| 800 | break; |
---|
| 801 | default: |
---|
| 802 | ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", Declaration::NoStorageClass, 0, false, LinkageSpec::Cforall ) ) ); |
---|
| 803 | } |
---|
| 804 | } else { |
---|
| 805 | ft->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) ); |
---|
[51b7345] | 806 | } |
---|
[c8ffe20b] | 807 | return ft; |
---|
[51b7345] | 808 | } |
---|
| 809 | |
---|
[c8ffe20b] | 810 | AggregateDecl *TypeData::buildAggregate() const { |
---|
| 811 | assert( kind == Aggregate ); |
---|
| 812 | AggregateDecl *at; |
---|
| 813 | switch ( aggregate->kind ) { |
---|
| 814 | case DeclarationNode::Struct: |
---|
| 815 | at = new StructDecl( aggregate->name ); |
---|
| 816 | break; |
---|
[51b7345] | 817 | |
---|
[c8ffe20b] | 818 | case DeclarationNode::Union: |
---|
| 819 | at = new UnionDecl( aggregate->name ); |
---|
| 820 | break; |
---|
[51b7345] | 821 | |
---|
[c8ffe20b] | 822 | case DeclarationNode::Context: |
---|
| 823 | at = new ContextDecl( aggregate->name ); |
---|
| 824 | break; |
---|
[51b7345] | 825 | |
---|
[c8ffe20b] | 826 | default: |
---|
| 827 | assert( false ); |
---|
| 828 | } |
---|
[51b7345] | 829 | |
---|
[c8ffe20b] | 830 | buildList( aggregate->params, at->get_parameters() ); |
---|
| 831 | buildList( aggregate->members, at->get_members() ); |
---|
[51b7345] | 832 | |
---|
[c8ffe20b] | 833 | return at; |
---|
[51b7345] | 834 | } |
---|
| 835 | |
---|
| 836 | /// namespace { |
---|
| 837 | /// Type* |
---|
| 838 | /// makeType( Declaration* decl ) |
---|
| 839 | /// { |
---|
[c8ffe20b] | 840 | /// if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) { |
---|
[51b7345] | 841 | /// return dwt->get_type()->clone(); |
---|
| 842 | /// } else { |
---|
| 843 | /// return 0; |
---|
| 844 | /// } |
---|
| 845 | /// } |
---|
| 846 | /// } |
---|
| 847 | |
---|
[c8ffe20b] | 848 | ReferenceToType *TypeData::buildAggInst() const { |
---|
| 849 | assert( kind == AggregateInst ); |
---|
| 850 | std::string name; |
---|
[51b7345] | 851 | |
---|
[c8ffe20b] | 852 | ReferenceToType *ret; |
---|
| 853 | if ( aggInst->aggregate->kind == Enum ) { |
---|
| 854 | ret = new EnumInstType( buildQualifiers(), aggInst->aggregate->enumeration->name ); |
---|
| 855 | } else { |
---|
| 856 | assert( aggInst->aggregate->kind == Aggregate ); |
---|
| 857 | switch ( aggInst->aggregate->aggregate->kind ) { |
---|
| 858 | case DeclarationNode::Struct: |
---|
| 859 | ret = new StructInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); |
---|
| 860 | break; |
---|
| 861 | case DeclarationNode::Union: |
---|
| 862 | ret = new UnionInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); |
---|
| 863 | break; |
---|
| 864 | case DeclarationNode::Context: |
---|
| 865 | ret = new ContextInstType( buildQualifiers(), aggInst->aggregate->aggregate->name ); |
---|
| 866 | break; |
---|
| 867 | default: |
---|
| 868 | assert( false ); |
---|
| 869 | } |
---|
[51b7345] | 870 | } |
---|
[c8ffe20b] | 871 | buildList( aggInst->params, ret->get_parameters() ); |
---|
| 872 | buildForall( forall, ret->get_forall() ); |
---|
| 873 | return ret; |
---|
[51b7345] | 874 | } |
---|
| 875 | |
---|
[c8ffe20b] | 876 | NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const { |
---|
| 877 | assert( kind == Symbolic ); |
---|
| 878 | NamedTypeDecl *ret; |
---|
| 879 | if ( symbolic->isTypedef ) { |
---|
| 880 | ret = new TypedefDecl( name, sc, maybeBuild< Type >( base ) ); |
---|
| 881 | } else { |
---|
| 882 | ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any ); |
---|
| 883 | } |
---|
| 884 | buildList( symbolic->params, ret->get_parameters() ); |
---|
| 885 | buildList( symbolic->assertions, ret->get_assertions() ); |
---|
| 886 | return ret; |
---|
[51b7345] | 887 | } |
---|
| 888 | |
---|
[c8ffe20b] | 889 | TypeDecl *TypeData::buildVariable() const { |
---|
| 890 | assert( kind == Variable ); |
---|
| 891 | static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; |
---|
[51b7345] | 892 | |
---|
[c8ffe20b] | 893 | TypeDecl *ret = new TypeDecl( variable->name, Declaration::NoStorageClass, 0, kindMap[ variable->tyClass ] ); |
---|
| 894 | buildList( variable->assertions, ret->get_assertions() ); |
---|
[51b7345] | 895 | |
---|
[c8ffe20b] | 896 | return ret; |
---|
[51b7345] | 897 | } |
---|
| 898 | |
---|
[c8ffe20b] | 899 | EnumDecl *TypeData::buildEnum() const { |
---|
| 900 | assert( kind == Enum ); |
---|
| 901 | EnumDecl *ret = new EnumDecl( enumeration->name ); |
---|
| 902 | buildList( enumeration->constants, ret->get_members() ); |
---|
[51b7345] | 903 | |
---|
[c8ffe20b] | 904 | return ret; |
---|
[51b7345] | 905 | } |
---|
| 906 | |
---|
[c8ffe20b] | 907 | TypeInstType *TypeData::buildSymbolicInst() const { |
---|
| 908 | assert( kind == SymbolicInst ); |
---|
[51b7345] | 909 | |
---|
| 910 | |
---|
[c8ffe20b] | 911 | TypeInstType *ret = new TypeInstType( buildQualifiers(), symbolic->name, false ); |
---|
| 912 | buildList( symbolic->actuals, ret->get_parameters() ); |
---|
| 913 | buildForall( forall, ret->get_forall() ); |
---|
[51b7345] | 914 | |
---|
[c8ffe20b] | 915 | return ret; |
---|
[51b7345] | 916 | } |
---|
| 917 | |
---|
[c8ffe20b] | 918 | TupleType *TypeData::buildTuple() const { |
---|
| 919 | assert( kind == Tuple ); |
---|
[51b7345] | 920 | |
---|
| 921 | |
---|
[c8ffe20b] | 922 | TupleType *ret = new TupleType( buildQualifiers() ); |
---|
| 923 | buildTypeList( tuple->members, ret->get_types() ); |
---|
| 924 | buildForall( forall, ret->get_forall() ); |
---|
[51b7345] | 925 | |
---|
[c8ffe20b] | 926 | return ret; |
---|
[51b7345] | 927 | } |
---|
| 928 | |
---|
[c8ffe20b] | 929 | TypeofType *TypeData::buildTypeof() const { |
---|
| 930 | assert( kind == Typeof ); |
---|
| 931 | assert( typeexpr ); |
---|
| 932 | assert( typeexpr->expr ); |
---|
| 933 | TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() ); |
---|
[51b7345] | 934 | |
---|
[c8ffe20b] | 935 | return ret; |
---|
[51b7345] | 936 | } |
---|
| 937 | |
---|
[c8ffe20b] | 938 | AttrType *TypeData::buildAttr() const { |
---|
| 939 | assert( kind == Attr ); |
---|
| 940 | assert( attr ); |
---|
| 941 | AttrType *ret; |
---|
| 942 | if ( attr->expr ) { |
---|
| 943 | ret = new AttrType( buildQualifiers(), attr->name, attr->expr->build() ); |
---|
| 944 | } else { |
---|
| 945 | assert( attr->type ); |
---|
| 946 | ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() ); |
---|
| 947 | } |
---|
[51b7345] | 948 | |
---|
[c8ffe20b] | 949 | return ret; |
---|
[51b7345] | 950 | } |
---|