Changeset c8ffe20b for translator/Parser


Ignore:
Timestamp:
Nov 15, 2014, 10:46:42 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
1ead581
Parents:
8c17ab0
Message:

reformat files

Location:
translator/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/TypeData.cc

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

    r8c17ab0 rc8ffe20b  
    1010#include "LinkageSpec.h"
    1111
    12 struct TypeData
    13 {
    14   enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    15               Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Attr } kind;
     12struct TypeData {
     13    enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
     14                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Attr } kind;
    1615
    17   TypeData( Kind k = Unknown );
    18   ~TypeData();
    19   void print( std::ostream &, int indent = 0 ) const;
    20   TypeData *clone() const;
     16    TypeData( Kind k = Unknown );
     17    ~TypeData();
     18    void print( std::ostream &, int indent = 0 ) const;
     19    TypeData *clone() const;
    2120
    22   Type *build() const;
    23   FunctionType *buildFunction() const;
     21    Type *build() const;
     22    FunctionType *buildFunction() const;
    2423
    25   TypeData *base;
    26   std::list< DeclarationNode::Qualifier > qualifiers;
    27   DeclarationNode *forall;
     24    TypeData *base;
     25    std::list< DeclarationNode::Qualifier > qualifiers;
     26    DeclarationNode *forall;
    2827
    29   struct Basic_t {
    30     std::list< DeclarationNode::BasicType > typeSpec;
    31     std::list< DeclarationNode::Modifier > modifiers;
    32   };
     28    struct Basic_t {
     29        std::list< DeclarationNode::BasicType > typeSpec;
     30        std::list< DeclarationNode::Modifier > modifiers;
     31    };
    3332
    34   struct Aggregate_t {
    35     DeclarationNode::TyCon kind;
    36     std::string name;
    37     DeclarationNode *params;
    38     ExpressionNode *actuals;    // holds actual parameters that will later be applied to AggInst
    39     DeclarationNode *members;
    40   };
     33    struct Aggregate_t {
     34        DeclarationNode::TyCon kind;
     35        std::string name;
     36        DeclarationNode *params;
     37        ExpressionNode *actuals;                        // holds actual parameters later applied to AggInst
     38        DeclarationNode *members;
     39    };
    4140
    42   struct AggInst_t {
    43     TypeData *aggregate;
    44     ExpressionNode *params;
    45   };
     41    struct AggInst_t {
     42        TypeData *aggregate;
     43        ExpressionNode *params;
     44    };
    4645
    47   struct Array_t {
    48     ExpressionNode *dimension;
    49     bool isVarLen;
    50     bool isStatic;
    51   };
     46    struct Array_t {
     47        ExpressionNode *dimension;
     48        bool isVarLen;
     49        bool isStatic;
     50    };
    5251
    53   struct Enumeration_t {
    54     std::string name;
    55     DeclarationNode *constants;
    56   };
     52    struct Enumeration_t {
     53        std::string name;
     54        DeclarationNode *constants;
     55    };
    5756
    58   struct Function_t {
    59     DeclarationNode *params;
    60     DeclarationNode *idList; // old-style
    61     DeclarationNode *oldDeclList;
    62     StatementNode *body;
    63     bool hasBody;
    64     bool newStyle;
    65   };
     57    struct Function_t {
     58        DeclarationNode *params;
     59        DeclarationNode *idList;                        // old-style
     60        DeclarationNode *oldDeclList;
     61        StatementNode *body;
     62        bool hasBody;
     63        bool newStyle;
     64    };
    6665
    67   struct Symbolic_t {
    68     std::string name;
    69     bool isTypedef;
    70     DeclarationNode *params;
    71     ExpressionNode *actuals;
    72     DeclarationNode *assertions;
    73   };
     66    struct Symbolic_t {
     67        std::string name;
     68        bool isTypedef;
     69        DeclarationNode *params;
     70        ExpressionNode *actuals;
     71        DeclarationNode *assertions;
     72    };
    7473
    75   struct Variable_t {
    76     DeclarationNode::TypeClass tyClass;
    77     std::string name;
    78     DeclarationNode *assertions;
    79   };
     74    struct Variable_t {
     75        DeclarationNode::TypeClass tyClass;
     76        std::string name;
     77        DeclarationNode *assertions;
     78    };
    8079
    81   struct Tuple_t {
    82     DeclarationNode *members;
    83   };
     80    struct Tuple_t {
     81        DeclarationNode *members;
     82    };
    8483 
    85   struct Typeof_t {
    86     ExpressionNode *expr;
    87   };
     84    struct Typeof_t {
     85        ExpressionNode *expr;
     86    };
    8887
    89   struct Attr_t {
    90     std::string name;
    91     ExpressionNode *expr;
    92     DeclarationNode *type;
    93   };
     88    struct Attr_t {
     89        std::string name;
     90        ExpressionNode *expr;
     91        DeclarationNode *type;
     92    };
    9493
    95   union {
    96     Basic_t *basic;
    97     Aggregate_t *aggregate;
    98     AggInst_t *aggInst;
    99     Array_t *array;
    100     Enumeration_t *enumeration;
    101     Function_t *function;
    102     Symbolic_t *symbolic;
    103     Variable_t *variable;
    104     Tuple_t *tuple;
    105     Typeof_t *typeexpr;
    106     Attr_t *attr;
    107   };
     94    union {
     95        Basic_t *basic;
     96        Aggregate_t *aggregate;
     97        AggInst_t *aggInst;
     98        Array_t *array;
     99        Enumeration_t *enumeration;
     100        Function_t *function;
     101        Symbolic_t *symbolic;
     102        Variable_t *variable;
     103        Tuple_t *tuple;
     104        Typeof_t *typeexpr;
     105        Attr_t *attr;
     106    };
    108107
    109   TypeData *extractAggregate( bool toplevel = true ) const;
    110   /* helper function for DeclNodeImpl::build */
    111   Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
    112   /* helper functions for build() */
    113   Type::Qualifiers buildQualifiers() const;
    114   Type *buildBasicType() const;
    115   PointerType * buildPointer() const;
    116   ArrayType * buildArray() const;
    117   AggregateDecl * buildAggregate() const;
    118   ReferenceToType * buildAggInst() const;
    119   NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const;
    120   TypeDecl* buildVariable() const;
    121   EnumDecl* buildEnum() const;
    122   TypeInstType * buildSymbolicInst() const;
    123   TupleType * buildTuple() const;
    124   TypeofType * buildTypeof() const;
    125   AttrType * buildAttr() const;
     108    TypeData *extractAggregate( bool toplevel = true ) const;
     109    // helper function for DeclNodeImpl::build
     110    Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
     111    // helper functions for build()
     112    Type::Qualifiers buildQualifiers() const;
     113    Type *buildBasicType() const;
     114    PointerType * buildPointer() const;
     115    ArrayType * buildArray() const;
     116    AggregateDecl * buildAggregate() const;
     117    ReferenceToType * buildAggInst() const;
     118    NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const;
     119    TypeDecl* buildVariable() const;
     120    EnumDecl* buildEnum() const;
     121    TypeInstType * buildSymbolicInst() const;
     122    TupleType * buildTuple() const;
     123    TypeofType * buildTypeof() const;
     124    AttrType * buildAttr() const;
    126125};
    127126
    128 #endif /* #ifndef TYPEDATA_H */
     127#endif // TYPEDATA_H
  • translator/Parser/TypedefTable.h

    r8c17ab0 rc8ffe20b  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypedefTable.h,v 1.5 2003/05/11 15:24:05 rcbilson Exp $
    5  *
    6  */
    7 
    81#ifndef TYPEDEFTABLE_H
    92#define TYPEDEFTABLE_H
     
    147#include <stack>
    158
    16 class TypedefTable
    17 {
     9class TypedefTable {
    1810  public:
    1911    enum kind_t { ID, TD, TG };
    2012  private:
    21     struct Entry
    22     {
     13    struct Entry {
    2314        int scope;
    2415        kind_t kind;
    2516    };
    2617   
    27     struct DeferredEntry
    28     {
    29       std::string identifier;
    30       kind_t kind;
     18    struct DeferredEntry {
     19        std::string identifier;
     20        kind_t kind;
    3121    };
    3222
     
    4434    std::stack< std::string > nextIdentifiers;
    4535
    46     bool isKind(std::string identifier, kind_t kind) const;
    47     void addToScope(const std::string &identifier, kind_t kind, int scope);
     36    bool isKind( std::string identifier, kind_t kind ) const;
     37    void addToScope( const std::string &identifier, kind_t kind, int scope );
    4838  public:
    4939    TypedefTable();
    5040
    51     bool isIdentifier(std::string identifier) const;
    52     bool isTypedef(std::string identifier) const;
    53     bool isTypegen(std::string identifier) const;
     41    bool isIdentifier( std::string identifier ) const;
     42    bool isTypedef( std::string identifier ) const;
     43    bool isTypegen( std::string identifier ) const;
    5444   
    55     // "addToCurrentScope" adds the identifier/type pair to the current scope This does less
    56     // than you think it does, since each declaration is within its own scope.  Mostly useful for
    57     // type parameters.
    58     void addToCurrentScope(const std::string &identifier, kind_t kind);
    59     void addToCurrentScope(kind_t kind);   // use nextIdentifiers.top()
     45    // "addToCurrentScope" adds the identifier/type pair to the current scope This does less than you think it does,
     46    // since each declaration is within its own scope.  Mostly useful for type parameters.
     47    void addToCurrentScope( const std::string &identifier, kind_t kind );
     48    void addToCurrentScope( kind_t kind );              // use nextIdentifiers.top()
    6049
    61     // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current
    62     // one.  This is the right way to handle type and typedef names
    63     void addToEnclosingScope(const std::string &identifier, kind_t kind);
    64     void addToEnclosingScope(kind_t kind); // use nextIdentifiers.top()
     50    // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one.  This is the
     51    // right way to handle type and typedef names
     52    void addToEnclosingScope( const std::string &identifier, kind_t kind );
     53    void addToEnclosingScope( kind_t kind );            // use nextIdentifiers.top()
    6554   
    66     // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope
    67     // enclosing the the current one.  This is the right way to handle assertion names
    68     void addToEnclosingScope2(const std::string &identifier, kind_t kind);
    69     void addToEnclosingScope2(kind_t kind); // use nextIdentifiers.top()
     55    // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the
     56    // current one.  This is the right way to handle assertion names
     57    void addToEnclosingScope2( const std::string &identifier, kind_t kind );
     58    void addToEnclosingScope2( kind_t kind );           // use nextIdentifiers.top()
    7059   
    71     // set the next identifier to be used by an "add" operation without an identifier parameter
    72     // within the current scope
     60    // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope
    7361    void setNextIdentifier( const std::string &identifier );
    7462   
     
    7664    void openContext( std::string contextName );
    7765   
    78     void enterScope(void);
    79     void leaveScope(void);
     66    void enterScope( void );
     67    void leaveScope( void );
    8068    void enterContext( std::string contextName );
    81     void leaveContext(void);
     69    void leaveContext( void );
    8270
    83     void print(void) const;
     71    void print( void ) const;
    8472};
    8573
    86 #endif /* ifndef TYPEDEFTABLE_H */
     74#endif // TYPEDEFTABLE_H
Note: See TracChangeset for help on using the changeset viewer.