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