Ignore:
Timestamp:
May 16, 2015, 3:36:19 PM (9 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:
a32b204
Parents:
b8508a2
Message:

licencing: first groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/TypeData.cc

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