source: src/Parser/TypeData.cc @ 5cacf74

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 5cacf74 was 3d7e53b, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add anon flag to TypeData? and remove anonymous members for named aggregates

  • Property mode set to 100644
File size: 34.7 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[f1e012b]7// TypeData.cc --
[b87a5ed]8//
9// Author           : Rodolfo G. Esteves
10// Created On       : Sat May 16 15:12:51 2015
[e612146c]11// Last Modified By : Peter A. Buhr
[2ee0076]12// Last Modified On : Wed Jun  6 17:40:33 2018
13// Update Count     : 604
[b87a5ed]14//
15
[d180746]16#include <cassert>                 // for assert
17#include <ostream>                 // for operator<<, ostream, basic_ostream
18
19#include "Common/SemanticError.h"  // for SemanticError
20#include "Common/utility.h"        // for maybeClone, maybeBuild, maybeMoveB...
21#include "Parser/ParseNode.h"      // for DeclarationNode, ExpressionNode
22#include "SynTree/Declaration.h"   // for TypeDecl, ObjectDecl, FunctionDecl
23#include "SynTree/Expression.h"    // for Expression, ConstantExpr (ptr only)
24#include "SynTree/Initializer.h"   // for SingleInit, Initializer (ptr only)
25#include "SynTree/Statement.h"     // for CompoundStmt, Statement
26#include "SynTree/Type.h"          // for BasicType, Type, Type::ForallList
[51b7345]27#include "TypeData.h"
[d180746]28
29class Attribute;
30
[2298f728]31using namespace std;
[51b7345]32
[0b0f1dd]33TypeData::TypeData( Kind k ) : location( yylloc ), kind( k ), base( nullptr ), forall( nullptr ) /*, PTR1( (void*)(0xdeadbeefdeadbeef)), PTR2( (void*)(0xdeadbeefdeadbeef) ) */ {
[b87a5ed]34        switch ( kind ) {
35          case Unknown:
36          case Pointer:
[ce8c12f]37          case Reference:
[b87a5ed]38          case EnumConstant:
[47498bd]39          case GlobalScope:
[b87a5ed]40                // nothing else to initialize
41                break;
42          case Basic:
[8f6f47d7]43                // basic = new Basic_t;
[b87a5ed]44                break;
45          case Array:
[8f6f47d7]46                // array = new Array_t;
[2298f728]47                array.dimension = nullptr;
[8f6f47d7]48                array.isVarLen = false;
49                array.isStatic = false;
[b87a5ed]50                break;
51          case Function:
[8f6f47d7]52                // function = new Function_t;
[2298f728]53                function.params = nullptr;
54                function.idList = nullptr;
55                function.oldDeclList = nullptr;
56                function.body = nullptr;
[84276ba]57                function.withExprs = nullptr;
[b87a5ed]58                break;
[e496303]59                // Enum is an Aggregate, so both structures are initialized together.
60          case Enum:
61                // enumeration = new Enumeration_t;
62                enumeration.name = nullptr;
63                enumeration.constants = nullptr;
64                enumeration.body = false;
[3d7e53b]65                enumeration.anon = false;
[6926a6d]66                break;
[b87a5ed]67          case Aggregate:
[8f6f47d7]68                // aggregate = new Aggregate_t;
[d15a45d]69                aggregate.kind = DeclarationNode::NoAggregate;
[2298f728]70                aggregate.name = nullptr;
71                aggregate.params = nullptr;
72                aggregate.actuals = nullptr;
73                aggregate.fields = nullptr;
[4a9ccc3]74                aggregate.body = false;
[d15a45d]75                aggregate.tagged = false;
76                aggregate.parent = nullptr;
[3d7e53b]77                aggregate.anon = false;
[b87a5ed]78                break;
79          case AggregateInst:
[8f6f47d7]80                // aggInst = new AggInst_t;
[2298f728]81                aggInst.aggregate = nullptr;
82                aggInst.params = nullptr;
[43c89a7]83                aggInst.hoistType = false;;
[b87a5ed]84                break;
85          case Symbolic:
86          case SymbolicInst:
[8f6f47d7]87                // symbolic = new Symbolic_t;
[2298f728]88                symbolic.name = nullptr;
89                symbolic.params = nullptr;
90                symbolic.actuals = nullptr;
91                symbolic.assertions = nullptr;
[b87a5ed]92                break;
93          case Tuple:
[8f6f47d7]94                // tuple = new Tuple_t;
95                tuple = nullptr;
[b87a5ed]96                break;
97          case Typeof:
[8f6f47d7]98                // typeexpr = new Typeof_t;
99                typeexpr = nullptr;
[b87a5ed]100                break;
[28307be]101          case Builtin:
102                // builtin = new Builtin_t;
[c194661]103                case Qualified:
104                qualified.parent = nullptr;
105                qualified.child = nullptr;
[b87a5ed]106                break;
[68cd1ce]107        } // switch
[413ad05]108} // TypeData::TypeData
[51b7345]109
[201aeb9]110
[c8ffe20b]111TypeData::~TypeData() {
[b87a5ed]112        delete base;
113        delete forall;
114
115        switch ( kind ) {
116          case Unknown:
117          case Pointer:
[ce8c12f]118          case Reference:
[b87a5ed]119          case EnumConstant:
[47498bd]120          case GlobalScope:
[b87a5ed]121                // nothing to destroy
122                break;
123          case Basic:
[8f6f47d7]124                // delete basic;
[b87a5ed]125                break;
126          case Array:
[8f6f47d7]127                delete array.dimension;
128                // delete array;
[b87a5ed]129                break;
130          case Function:
[8f6f47d7]131                delete function.params;
132                delete function.idList;
133                delete function.oldDeclList;
134                delete function.body;
[84276ba]135                delete function.withExprs;
[8f6f47d7]136                // delete function;
[b87a5ed]137                break;
138          case Aggregate:
[2298f728]139                delete aggregate.name;
[8f6f47d7]140                delete aggregate.params;
141                delete aggregate.actuals;
142                delete aggregate.fields;
143                // delete aggregate;
[b87a5ed]144                break;
145          case AggregateInst:
[8f6f47d7]146                delete aggInst.aggregate;
147                delete aggInst.params;
148                // delete aggInst;
[b87a5ed]149                break;
150          case Enum:
[2298f728]151                delete enumeration.name;
[8f6f47d7]152                delete enumeration.constants;
153                // delete enumeration;
[b87a5ed]154                break;
155          case Symbolic:
156          case SymbolicInst:
[2298f728]157                delete symbolic.name;
[8f6f47d7]158                delete symbolic.params;
159                delete symbolic.actuals;
160                delete symbolic.assertions;
161                // delete symbolic;
[b87a5ed]162                break;
163          case Tuple:
[8f6f47d7]164                // delete tuple->members;
[b87a5ed]165                delete tuple;
166                break;
167          case Typeof:
[8f6f47d7]168                // delete typeexpr->expr;
[b87a5ed]169                delete typeexpr;
170                break;
[28307be]171          case Builtin:
172                // delete builtin;
173                break;
[c194661]174          case Qualified:
175                delete qualified.parent;
176                delete qualified.child;
[68cd1ce]177        } // switch
[413ad05]178} // TypeData::~TypeData
[51b7345]179
[201aeb9]180
[413ad05]181TypeData * TypeData::clone() const {
182        TypeData * newtype = new TypeData( kind );
[738e304]183        newtype->qualifiers = qualifiers;
[b87a5ed]184        newtype->base = maybeClone( base );
185        newtype->forall = maybeClone( forall );
186
187        switch ( kind ) {
188          case Unknown:
189          case EnumConstant:
190          case Pointer:
[ce8c12f]191          case Reference:
[47498bd]192          case GlobalScope:
[b87a5ed]193                // nothing else to copy
194                break;
195          case Basic:
[5b639ee]196                newtype->basictype = basictype;
197                newtype->complextype = complextype;
198                newtype->signedness = signedness;
199                newtype->length = length;
[b87a5ed]200                break;
201          case Array:
[8f6f47d7]202                newtype->array.dimension = maybeClone( array.dimension );
203                newtype->array.isVarLen = array.isVarLen;
204                newtype->array.isStatic = array.isStatic;
[b87a5ed]205                break;
206          case Function:
[8f6f47d7]207                newtype->function.params = maybeClone( function.params );
208                newtype->function.idList = maybeClone( function.idList );
209                newtype->function.oldDeclList = maybeClone( function.oldDeclList );
210                newtype->function.body = maybeClone( function.body );
[84276ba]211                newtype->function.withExprs = maybeClone( function.withExprs );
[b87a5ed]212                break;
213          case Aggregate:
[d15a45d]214                newtype->aggregate.kind = aggregate.kind;
[2298f728]215                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
[8f6f47d7]216                newtype->aggregate.params = maybeClone( aggregate.params );
217                newtype->aggregate.actuals = maybeClone( aggregate.actuals );
218                newtype->aggregate.fields = maybeClone( aggregate.fields );
219                newtype->aggregate.body = aggregate.body;
[3d7e53b]220                newtype->aggregate.anon = aggregate.anon;
[6ea87486]221                newtype->aggregate.tagged = aggregate.tagged;
222                newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
[b87a5ed]223                break;
224          case AggregateInst:
[8f6f47d7]225                newtype->aggInst.aggregate = maybeClone( aggInst.aggregate );
226                newtype->aggInst.params = maybeClone( aggInst.params );
[43c89a7]227                newtype->aggInst.hoistType = aggInst.hoistType;
[b87a5ed]228                break;
229          case Enum:
[2298f728]230                newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr;
[8f6f47d7]231                newtype->enumeration.constants = maybeClone( enumeration.constants );
[ca1a547]232                newtype->enumeration.body = enumeration.body;
[3d7e53b]233                newtype->enumeration.anon = enumeration.anon;
[b87a5ed]234                break;
235          case Symbolic:
236          case SymbolicInst:
[2298f728]237                newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr;
[8f6f47d7]238                newtype->symbolic.params = maybeClone( symbolic.params );
239                newtype->symbolic.actuals = maybeClone( symbolic.actuals );
240                newtype->symbolic.assertions = maybeClone( symbolic.assertions );
241                newtype->symbolic.isTypedef = symbolic.isTypedef;
[b87a5ed]242                break;
243          case Tuple:
[8f6f47d7]244                newtype->tuple = maybeClone( tuple );
[b87a5ed]245                break;
246          case Typeof:
[8f6f47d7]247                newtype->typeexpr = maybeClone( typeexpr );
[b87a5ed]248                break;
[90c3b1c]249          case Builtin:
[4cb935e]250                assert( builtintype == DeclarationNode::Zero || builtintype == DeclarationNode::One );
251                newtype->builtintype = builtintype;
[90c3b1c]252                break;
[c194661]253                case Qualified:
254                newtype->qualified.parent = maybeClone( qualified.parent );
255                newtype->qualified.child = maybeClone( qualified.child );
256                break;
[68cd1ce]257        } // switch
[b87a5ed]258        return newtype;
[413ad05]259} // TypeData::clone
[51b7345]260
[201aeb9]261
[2298f728]262void TypeData::print( ostream &os, int indent ) const {
[738e304]263        for ( int i = 0; i < Type::NumTypeQualifier; i += 1 ) {
[615a096]264                if ( qualifiers[i] ) os << Type::QualifiersNames[ i ] << ' ';
[c1c1112]265        } // for
[b87a5ed]266
267        if ( forall ) {
268                os << "forall " << endl;
[721f17a]269                forall->printList( os, indent + 4 );
[68cd1ce]270        } // if
[b87a5ed]271
272        switch ( kind ) {
273          case Unknown:
274                os << "entity of unknown type ";
275                break;
276          case Pointer:
277                os << "pointer ";
278                if ( base ) {
279                        os << "to ";
280                        base->print( os, indent );
[68cd1ce]281                } // if
[b87a5ed]282                break;
283          case EnumConstant:
284                os << "enumeration constant ";
285                break;
286          case Basic:
[dd020c0]287                if ( signedness != DeclarationNode::NoSignedness ) os << DeclarationNode::signednessNames[ signedness ] << " ";
288                if ( length != DeclarationNode::NoLength ) os << DeclarationNode::lengthNames[ length ] << " ";
[5b639ee]289                assert( basictype != DeclarationNode::NoBasicType );
[dd020c0]290                os << DeclarationNode::basicTypeNames[ basictype ] << " ";
291                if ( complextype != DeclarationNode::NoComplexType ) os << DeclarationNode::complexTypeNames[ complextype ] << " ";
[b87a5ed]292                break;
293          case Array:
[8f6f47d7]294                if ( array.isStatic ) {
[b87a5ed]295                        os << "static ";
[68cd1ce]296                } // if
[8f6f47d7]297                if ( array.dimension ) {
[b87a5ed]298                        os << "array of ";
[8f6f47d7]299                        array.dimension->printOneLine( os, indent );
300                } else if ( array.isVarLen ) {
[b87a5ed]301                        os << "variable-length array of ";
302                } else {
303                        os << "open array of ";
[68cd1ce]304                } // if
[b87a5ed]305                if ( base ) {
306                        base->print( os, indent );
[68cd1ce]307                } // if
[b87a5ed]308                break;
309          case Function:
310                os << "function" << endl;
[8f6f47d7]311                if ( function.params ) {
[721f17a]312                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
[8f6f47d7]313                        function.params->printList( os, indent + 4 );
[b87a5ed]314                } else {
[721f17a]315                        os << string( indent + 2, ' ' ) << "with no parameters " << endl;
[68cd1ce]316                } // if
[8f6f47d7]317                if ( function.idList ) {
[721f17a]318                        os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl;
[8f6f47d7]319                        function.idList->printList( os, indent + 4 );
[68cd1ce]320                } // if
[8f6f47d7]321                if ( function.oldDeclList ) {
[721f17a]322                        os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl;
[8f6f47d7]323                        function.oldDeclList->printList( os, indent + 4 );
[68cd1ce]324                } // if
[721f17a]325                os << string( indent + 2, ' ' ) << "returning ";
[b87a5ed]326                if ( base ) {
[721f17a]327                        base->print( os, indent + 4 );
[b87a5ed]328                } else {
329                        os << "nothing ";
[68cd1ce]330                } // if
[b87a5ed]331                os << endl;
[8f6f47d7]332                if ( function.body ) {
[ca1a547]333                        os << string( indent + 2, ' ' ) << "with body " << endl;
[8f6f47d7]334                        function.body->printList( os, indent + 2 );
[68cd1ce]335                } // if
[b87a5ed]336                break;
337          case Aggregate:
[dd020c0]338                os << DeclarationNode::aggregateNames[ aggregate.kind ] << ' ' << *aggregate.name << endl;
[8f6f47d7]339                if ( aggregate.params ) {
[721f17a]340                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
[8f6f47d7]341                        aggregate.params->printList( os, indent + 4 );
[68cd1ce]342                } // if
[8f6f47d7]343                if ( aggregate.actuals ) {
[721f17a]344                        os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl;
[8f6f47d7]345                        aggregate.actuals->printList( os, indent + 4 );
[68cd1ce]346                } // if
[8f6f47d7]347                if ( aggregate.fields ) {
[721f17a]348                        os << string( indent + 2, ' ' ) << "with members " << endl;
[8f6f47d7]349                        aggregate.fields->printList( os, indent + 4 );
[5d125e4]350                } // if
[8f6f47d7]351                if ( aggregate.body ) {
[5d125e4]352                        os << string( indent + 2, ' ' ) << " with body " << endl;
[68cd1ce]353                } // if
[b87a5ed]354                break;
355          case AggregateInst:
[8f6f47d7]356                if ( aggInst.aggregate ) {
[b87a5ed]357                        os << "instance of " ;
[8f6f47d7]358                        aggInst.aggregate->print( os, indent );
[b87a5ed]359                } else {
360                        os << "instance of an unspecified aggregate ";
[68cd1ce]361                } // if
[8f6f47d7]362                if ( aggInst.params ) {
[721f17a]363                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
[8f6f47d7]364                        aggInst.params->printList( os, indent + 2 );
[68cd1ce]365                } // if
[b87a5ed]366                break;
367          case Enum:
368                os << "enumeration ";
[8f6f47d7]369                if ( enumeration.constants ) {
[b87a5ed]370                        os << "with constants" << endl;
[8f6f47d7]371                        enumeration.constants->printList( os, indent + 2 );
[68cd1ce]372                } // if
[ca1a547]373                if ( enumeration.body ) {
374                        os << string( indent + 2, ' ' ) << " with body " << endl;
375                } // if
[b87a5ed]376                break;
377          case SymbolicInst:
[2298f728]378                os << "instance of type " << *symbolic.name;
[8f6f47d7]379                if ( symbolic.actuals ) {
[b87a5ed]380                        os << " with parameters" << endl;
[8f6f47d7]381                        symbolic.actuals->printList( os, indent + 2 );
[68cd1ce]382                } // if
[b87a5ed]383                break;
384          case Symbolic:
[8f6f47d7]385                if ( symbolic.isTypedef ) {
[b87a5ed]386                        os << "typedef definition ";
387                } else {
388                        os << "type definition ";
[68cd1ce]389                } // if
[8f6f47d7]390                if ( symbolic.params ) {
[721f17a]391                        os << endl << string( indent + 2, ' ' ) << "with parameters" << endl;
[8f6f47d7]392                        symbolic.params->printList( os, indent + 2 );
[68cd1ce]393                } // if
[8f6f47d7]394                if ( symbolic.assertions ) {
[721f17a]395                        os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
[8f6f47d7]396                        symbolic.assertions->printList( os, indent + 4 );
[721f17a]397                        os << string( indent + 2, ' ' );
[68cd1ce]398                } // if
[b87a5ed]399                if ( base ) {
400                        os << "for ";
401                        base->print( os, indent + 2 );
[68cd1ce]402                } // if
[b87a5ed]403                break;
404          case Tuple:
405                os << "tuple ";
[8f6f47d7]406                if ( tuple ) {
[b87a5ed]407                        os << "with members " << endl;
[8f6f47d7]408                        tuple->printList( os, indent + 2 );
[68cd1ce]409                } // if
[b87a5ed]410                break;
411          case Typeof:
412                os << "type-of expression ";
[8f6f47d7]413                if ( typeexpr ) {
414                        typeexpr->print( os, indent + 2 );
[68cd1ce]415                } // if
[b87a5ed]416                break;
[90c3b1c]417          case Builtin:
[9dc31c10]418                os << DeclarationNode::builtinTypeNames[builtintype];
[90c3b1c]419                break;
[1db21619]420          default:
[5b639ee]421                os << "internal error: TypeData::print " << kind << endl;
[1db21619]422                assert( false );
[68cd1ce]423        } // switch
[413ad05]424} // TypeData::print
[51b7345]425
[201aeb9]426
[8c49c0e]427template< typename ForallList >
428void buildForall( const DeclarationNode * firstNode, ForallList &outputList ) {
[b87a5ed]429        buildList( firstNode, outputList );
[f0ecf9b]430        auto n = firstNode;
431        for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i, n = (DeclarationNode*)n->get_next() ) {
[a7c90d4]432                TypeDecl * td = static_cast<TypeDecl *>(*i);
[f0ecf9b]433                if ( n->variable.tyClass == DeclarationNode::Otype ) {
[6943f051]434                        // add assertion parameters to `type' tyvars in reverse order
435                        // add dtor:  void ^?{}(T *)
[413ad05]436                        FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );
[cda7889]437                        dtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
[68fe077a]438                        td->get_assertions().push_front( new FunctionDecl( "^?{}", Type::StorageClasses(), LinkageSpec::Cforall, dtorType, nullptr ) );
[4cc4286]439
[a9a259c]440                        // add copy ctor:  void ?{}(T *, T)
[413ad05]441                        FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );
[cda7889]442                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
[68fe077a]443                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
444                        td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, copyCtorType, nullptr ) );
[a9a259c]445
[6943f051]446                        // add default ctor:  void ?{}(T *)
[413ad05]447                        FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );
[cda7889]448                        ctorType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
[68fe077a]449                        td->get_assertions().push_front( new FunctionDecl( "?{}", Type::StorageClasses(), LinkageSpec::Cforall, ctorType, nullptr ) );
[6943f051]450
451                        // add assignment operator:  T * ?=?(T *, T)
[413ad05]452                        FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );
[cda7889]453                        assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), td->get_name(), *i ) ), nullptr ) );
[68fe077a]454                        assignType->get_parameters().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
455                        assignType->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), td->get_name(), *i ), nullptr ) );
456                        td->get_assertions().push_front( new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Cforall, assignType, nullptr ) );
[68cd1ce]457                } // if
458        } // for
[201aeb9]459} // buildForall
460
[51b7345]461
[413ad05]462Type * typebuild( const TypeData * td ) {
463        assert( td );
464        switch ( td->kind ) {
465          case TypeData::Unknown:
[b87a5ed]466                // fill in implicit int
[413ad05]467                return new BasicType( buildQualifiers( td ), BasicType::SignedInt );
468          case TypeData::Basic:
469                return buildBasicType( td );
470          case TypeData::Pointer:
471                return buildPointer( td );
472          case TypeData::Array:
473                return buildArray( td );
[ce8c12f]474          case TypeData::Reference:
475                return buildReference( td );
[413ad05]476          case TypeData::Function:
477                return buildFunction( td );
478          case TypeData::AggregateInst:
479                return buildAggInst( td );
480          case TypeData::EnumConstant:
[b87a5ed]481                // the name gets filled in later -- by SymTab::Validate
[413ad05]482                return new EnumInstType( buildQualifiers( td ), "" );
483          case TypeData::SymbolicInst:
[c194661]484                return buildSymbolicInst( td );
[413ad05]485          case TypeData::Tuple:
486                return buildTuple( td );
487          case TypeData::Typeof:
488                return buildTypeof( td );
489          case TypeData::Builtin:
[148f7290]490                if(td->builtintype == DeclarationNode::Zero) {
[ac10576]491                        return new ZeroType( noQualifiers );
[148f7290]492                }
493                else if(td->builtintype == DeclarationNode::One) {
[ac10576]494                        return new OneType( noQualifiers );
[148f7290]495                }
496                else {
497                        return new VarArgsType( buildQualifiers( td ) );
498                }
[c194661]499          case TypeData::GlobalScope:
500                return new GlobalScopeType();
501                case TypeData::Qualified:
502                return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) );
[413ad05]503          case TypeData::Symbolic:
504          case TypeData::Enum:
505          case TypeData::Aggregate:
[b87a5ed]506                assert( false );
[68cd1ce]507        } // switch
[c194661]508
[2298f728]509        return nullptr;
[413ad05]510} // typebuild
511
[201aeb9]512
[413ad05]513TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) {
[2298f728]514        TypeData * ret = nullptr;
[51b7345]515
[413ad05]516        switch ( td->kind ) {
517          case TypeData::Aggregate:
[b2da0574]518                if ( ! toplevel && td->aggregate.body ) {
[413ad05]519                        ret = td->clone();
520                } // if
521                break;
522          case TypeData::Enum:
[b2da0574]523                if ( ! toplevel && td->enumeration.body ) {
[413ad05]524                        ret = td->clone();
525                } // if
526                break;
527          case TypeData::AggregateInst:
[8f6f47d7]528                if ( td->aggInst.aggregate ) {
529                        ret = typeextractAggregate( td->aggInst.aggregate, false );
[413ad05]530                } // if
531                break;
532          default:
533                if ( td->base ) {
534                        ret = typeextractAggregate( td->base, false );
535                } // if
536        } // switch
537        return ret;
538} // typeextractAggregate
539
[201aeb9]540
[413ad05]541Type::Qualifiers buildQualifiers( const TypeData * td ) {
[738e304]542        return td->qualifiers;
[413ad05]543} // buildQualifiers
[51b7345]544
[201aeb9]545
546static string genTSError( string msg, DeclarationNode::BasicType basictype ) {
[a16764a6]547        SemanticError( yylloc, string( "invalid type specifier \"" ) + msg + "\" for type \"" + DeclarationNode::basicTypeNames[basictype] + "\"." );
[201aeb9]548} // genTSError
549
[413ad05]550Type * buildBasicType( const TypeData * td ) {
[b87a5ed]551        BasicType::Kind ret;
552
[5b639ee]553        switch ( td->basictype ) {
554          case DeclarationNode::Void:
[201aeb9]555                if ( td->signedness != DeclarationNode::NoSignedness ) {
556                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
557                } // if
558                if ( td->length != DeclarationNode::NoLength ) {
559                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
[68cd1ce]560                } // if
[5b639ee]561                return new VoidType( buildQualifiers( td ) );
562                break;
563
564          case DeclarationNode::Bool:
565                if ( td->signedness != DeclarationNode::NoSignedness ) {
[201aeb9]566                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
[5b639ee]567                } // if
568                if ( td->length != DeclarationNode::NoLength ) {
[201aeb9]569                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
[68cd1ce]570                } // if
[51b7345]571
[5b639ee]572                ret = BasicType::Bool;
573                break;
574
575          case DeclarationNode::Char:
576                // C11 Standard 6.2.5.15: The three types char, signed char, and unsigned char are collectively called the
577                // character types. The implementation shall define char to have the same range, representation, and behavior as
578                // either signed char or unsigned char.
[8c49c0e]579                static BasicType::Kind chartype[] = { BasicType::SignedChar, BasicType::UnsignedChar, BasicType::Char };
[5b639ee]580
581                if ( td->length != DeclarationNode::NoLength ) {
[201aeb9]582                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
[5b639ee]583                } // if
584
585                ret = chartype[ td->signedness ];
586                break;
587
588          case DeclarationNode::Int:
589                static BasicType::Kind inttype[2][4] = {
590                        { BasicType::ShortSignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt, BasicType::SignedInt },
591                        { BasicType::ShortUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::UnsignedInt },
592                };
593
594          Integral: ;
595                if ( td->signedness == DeclarationNode::NoSignedness ) {
596                        const_cast<TypeData *>(td)->signedness = DeclarationNode::Signed;
597                } // if
598                ret = inttype[ td->signedness ][ td->length ];
599                break;
600
[201aeb9]601          case DeclarationNode::Int128:
[4ee3b0c1]602                ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
[201aeb9]603                if ( td->length != DeclarationNode::NoLength ) {
604                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
605                } // if
606                break;
607
[5b639ee]608          case DeclarationNode::Float:
[201aeb9]609          case DeclarationNode::Float80:
610          case DeclarationNode::Float128:
[5b639ee]611          case DeclarationNode::Double:
612          case DeclarationNode::LongDouble:                                     // not set until below
613                static BasicType::Kind floattype[3][3] = {
614                        { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex },
615                        { BasicType::FloatImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary },
616                        { BasicType::Float, BasicType::Double, BasicType::LongDouble },
617                };
618
619          FloatingPoint: ;
620                if ( td->signedness != DeclarationNode::NoSignedness ) {
[201aeb9]621                        genTSError( DeclarationNode::signednessNames[ td->signedness ], td->basictype );
[5b639ee]622                } // if
623                if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {
[201aeb9]624                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
[5b639ee]625                } // if
[4ee3b0c1]626                if ( td->basictype != DeclarationNode::Double && td->length == DeclarationNode::Long ) {
[201aeb9]627                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
[5b639ee]628                } // if
629                if ( td->length == DeclarationNode::Long ) {
630                        const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble;
631                } // if
632
[4ee3b0c1]633                if ( td->basictype == DeclarationNode::Float80 || td->basictype == DeclarationNode::Float128 ) {
[2ee0076]634                        // if ( td->complextype != DeclarationNode::NoComplexType ) {
635                        //      genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype );
636                        // }
[4ee3b0c1]637                        if ( td->basictype == DeclarationNode::Float80 ) ret = BasicType::Float80;
638                        else ret = BasicType::Float128;
639                        break;
640                }
641
[5b639ee]642                ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ];
643                break;
644
645          case DeclarationNode::NoBasicType:
646                // No basic type in declaration => default double for Complex/Imaginary and int type for integral types
647                if ( td->complextype == DeclarationNode::Complex || td->complextype == DeclarationNode::Imaginary ) {
648                        const_cast<TypeData *>(td)->basictype = DeclarationNode::Double;
649                        goto FloatingPoint;
650                } // if
651
652                const_cast<TypeData *>(td)->basictype = DeclarationNode::Int;
653                goto Integral;
[2ee5426]654          default:
[201aeb9]655                assertf( false, "unknown basic type" );
[2ee5426]656                return nullptr;
[5b639ee]657        } // switch
658
659        BasicType * bt = new BasicType( buildQualifiers( td ), ret );
[413ad05]660        buildForall( td->forall, bt->get_forall() );
[b87a5ed]661        return bt;
[413ad05]662} // buildBasicType
[51b7345]663
[201aeb9]664
[413ad05]665PointerType * buildPointer( const TypeData * td ) {
666        PointerType * pt;
667        if ( td->base ) {
668                pt = new PointerType( buildQualifiers( td ), typebuild( td->base ) );
[b87a5ed]669        } else {
[413ad05]670                pt = new PointerType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
[68cd1ce]671        } // if
[413ad05]672        buildForall( td->forall, pt->get_forall() );
[b87a5ed]673        return pt;
[413ad05]674} // buildPointer
[51b7345]675
[201aeb9]676
[413ad05]677ArrayType * buildArray( const TypeData * td ) {
678        ArrayType * at;
679        if ( td->base ) {
[8f6f47d7]680                at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ),
681                                                        td->array.isVarLen, td->array.isStatic );
[b87a5ed]682        } else {
[413ad05]683                at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
[8f6f47d7]684                                                        maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic );
[68cd1ce]685        } // if
[413ad05]686        buildForall( td->forall, at->get_forall() );
[b87a5ed]687        return at;
[ce8c12f]688} // buildArray
689
[201aeb9]690
[ce8c12f]691ReferenceType * buildReference( const TypeData * td ) {
692        ReferenceType * rt;
693        if ( td->base ) {
694                rt = new ReferenceType( buildQualifiers( td ), typebuild( td->base ) );
695        } else {
696                rt = new ReferenceType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
697        } // if
698        buildForall( td->forall, rt->get_forall() );
699        return rt;
700} // buildReference
[51b7345]701
[201aeb9]702
[fa4805f]703AggregateDecl * buildAggregate( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
[413ad05]704        assert( td->kind == TypeData::Aggregate );
705        AggregateDecl * at;
[8f6f47d7]706        switch ( td->aggregate.kind ) {
[b87a5ed]707          case DeclarationNode::Struct:
[409433da]708          case DeclarationNode::Coroutine:
709          case DeclarationNode::Monitor:
710          case DeclarationNode::Thread:
[fa4805f]711                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage );
[8f6f47d7]712                buildForall( td->aggregate.params, at->get_parameters() );
[b87a5ed]713                break;
714          case DeclarationNode::Union:
[bd46af4]715                at = new UnionDecl( *td->aggregate.name, attributes, linkage );
[8f6f47d7]716                buildForall( td->aggregate.params, at->get_parameters() );
[b87a5ed]717                break;
[4040425]718          case DeclarationNode::Trait:
[bd46af4]719                at = new TraitDecl( *td->aggregate.name, attributes, linkage );
[8f6f47d7]720                buildList( td->aggregate.params, at->get_parameters() );
[b87a5ed]721                break;
722          default:
723                assert( false );
[68cd1ce]724        } // switch
[4e06c1e]725
[8f6f47d7]726        buildList( td->aggregate.fields, at->get_members() );
727        at->set_body( td->aggregate.body );
[b87a5ed]728
729        return at;
[413ad05]730} // buildAggregate
[51b7345]731
[201aeb9]732
[fa4805f]733ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
[43c89a7]734        switch ( type->kind ) {
735          case TypeData::Enum: {
736                  if ( type->enumeration.body ) {
[bd46af4]737                          EnumDecl * typedecl = buildEnum( type, attributes, linkage );
[43c89a7]738                          return new EnumInstType( buildQualifiers( type ), typedecl );
739                  } else {
740                          return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
741                  } // if
742          }
743          case TypeData::Aggregate: {
744                  ReferenceToType * ret;
745                  if ( type->aggregate.body ) {
[fa4805f]746                          AggregateDecl * typedecl = buildAggregate( type, attributes, linkage );
[43c89a7]747                          switch ( type->aggregate.kind ) {
748                                case DeclarationNode::Struct:
[409433da]749                                case DeclarationNode::Coroutine:
750                                case DeclarationNode::Monitor:
751                                case DeclarationNode::Thread:
[43c89a7]752                                  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
753                                  break;
754                                case DeclarationNode::Union:
755                                  ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
756                                  break;
757                                case DeclarationNode::Trait:
758                                  assert( false );
759                                  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
760                                  break;
761                                default:
762                                  assert( false );
763                          } // switch
764                  } else {
765                          switch ( type->aggregate.kind ) {
766                                case DeclarationNode::Struct:
[409433da]767                                case DeclarationNode::Coroutine:
768                                case DeclarationNode::Monitor:
769                                case DeclarationNode::Thread:
[43c89a7]770                                  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
771                                  break;
772                                case DeclarationNode::Union:
773                                  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
774                                  break;
775                                case DeclarationNode::Trait:
776                                  ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
777                                  break;
778                                default:
779                                  assert( false );
780                          } // switch
781                  } // if
782                  return ret;
783          }
784          default:
785                assert( false );
786        } // switch
787} // buildAggInst
788
[201aeb9]789
[413ad05]790ReferenceToType * buildAggInst( const TypeData * td ) {
791        assert( td->kind == TypeData::AggregateInst );
[b87a5ed]792
[43c89a7]793        // ReferenceToType * ret = buildComAggInst( td->aggInst.aggregate, std::list< Attribute * >() );
794        ReferenceToType * ret = nullptr;
795        TypeData * type = td->aggInst.aggregate;
796        switch ( type->kind ) {
797          case TypeData::Enum: {
798                  return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
799          }
800          case TypeData::Aggregate: {
801                  switch ( type->aggregate.kind ) {
802                        case DeclarationNode::Struct:
[409433da]803                        case DeclarationNode::Coroutine:
804                        case DeclarationNode::Monitor:
805                        case DeclarationNode::Thread:
[43c89a7]806                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
807                          break;
808                        case DeclarationNode::Union:
809                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
810                          break;
811                        case DeclarationNode::Trait:
812                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
813                          break;
814                        default:
815                          assert( false );
816                  } // switch
817          }
818          break;
819          default:
820                assert( false );
821        } // switch
822
823        ret->set_hoistType( td->aggInst.hoistType );
[8f6f47d7]824        buildList( td->aggInst.params, ret->get_parameters() );
[413ad05]825        buildForall( td->forall, ret->get_forall() );
[b87a5ed]826        return ret;
[413ad05]827} // buildAggInst
828
[201aeb9]829
[1f370451]830NamedTypeDecl * buildSymbolic( const TypeData * td, std::list< Attribute * > attributes, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) {
[413ad05]831        assert( td->kind == TypeData::Symbolic );
832        NamedTypeDecl * ret;
833        assert( td->base );
[8f6f47d7]834        if ( td->symbolic.isTypedef ) {
[0b0f1dd]835                ret = new TypedefDecl( name, td->location, scs, typebuild( td->base ), linkage );
[b87a5ed]836        } else {
[f0ecf9b]837                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Dtype, true );
[68cd1ce]838        } // if
[8f6f47d7]839        buildList( td->symbolic.params, ret->get_parameters() );
840        buildList( td->symbolic.assertions, ret->get_assertions() );
[1f370451]841        ret->base->attributes.splice( ret->base->attributes.end(), attributes );
[b87a5ed]842        return ret;
[413ad05]843} // buildSymbolic
[51b7345]844
[201aeb9]845
[bd46af4]846EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) {
[413ad05]847        assert( td->kind == TypeData::Enum );
[bd46af4]848        EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage );
[8f6f47d7]849        buildList( td->enumeration.constants, ret->get_members() );
[2298f728]850        list< Declaration * >::iterator members = ret->get_members().begin();
[8f6f47d7]851        for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
[4f147cc]852                if ( cur->has_enumeratorValue() ) {
[413ad05]853                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
[e4d829b]854                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) );
[90c3b1c]855                } // if
856        } // for
[ca1a547]857        ret->set_body( td->enumeration.body );
[b87a5ed]858        return ret;
[413ad05]859} // buildEnum
[51b7345]860
[201aeb9]861
[413ad05]862TypeInstType * buildSymbolicInst( const TypeData * td ) {
863        assert( td->kind == TypeData::SymbolicInst );
[2298f728]864        TypeInstType * ret = new TypeInstType( buildQualifiers( td ), *td->symbolic.name, false );
[8f6f47d7]865        buildList( td->symbolic.actuals, ret->get_parameters() );
[413ad05]866        buildForall( td->forall, ret->get_forall() );
[b87a5ed]867        return ret;
[413ad05]868} // buildSymbolicInst
[51b7345]869
[201aeb9]870
[413ad05]871TupleType * buildTuple( const TypeData * td ) {
872        assert( td->kind == TypeData::Tuple );
[62423350]873        std::list< Type * > types;
874        buildTypeList( td->tuple, types );
875        TupleType * ret = new TupleType( buildQualifiers( td ), types );
[413ad05]876        buildForall( td->forall, ret->get_forall() );
[b87a5ed]877        return ret;
[413ad05]878} // buildTuple
879
[201aeb9]880
[413ad05]881TypeofType * buildTypeof( const TypeData * td ) {
882        assert( td->kind == TypeData::Typeof );
883        assert( td->typeexpr );
[8f6f47d7]884        // assert( td->typeexpr->expr );
885        return new TypeofType( buildQualifiers( td ), td->typeexpr->build() );
[413ad05]886} // buildTypeof
887
[201aeb9]888
[e612146c]889Declaration * buildDecl( const TypeData * td, const string &name, Type::StorageClasses scs, Expression * bitfieldWidth, Type::FuncSpecifiers funcSpec, LinkageSpec::Spec linkage, Expression *asmName, Initializer * init, std::list< Attribute * > attributes ) {
[413ad05]890        if ( td->kind == TypeData::Function ) {
[ca1a547]891                if ( td->function.idList ) {                                    // KR function ?
892                        buildKRFunction( td->function );                        // transform into C11 function
[3a5131ed]893                } // if
894
[413ad05]895                FunctionDecl * decl;
[ca1a547]896                Statement * stmt = maybeBuild<Statement>( td->function.body );
[a7c90d4]897                CompoundStmt * body = dynamic_cast< CompoundStmt * >( stmt );
898                decl = new FunctionDecl( name, scs, linkage, buildFunction( td ), body, attributes, funcSpec );
[c453ac4]899                buildList( td->function.withExprs, decl->withExprs );
[58dd019]900                return decl->set_asmName( asmName );
[413ad05]901        } else if ( td->kind == TypeData::Aggregate ) {
[fa4805f]902                return buildAggregate( td, attributes, linkage );
[413ad05]903        } else if ( td->kind == TypeData::Enum ) {
[bd46af4]904                return buildEnum( td, attributes, linkage );
[413ad05]905        } else if ( td->kind == TypeData::Symbolic ) {
[1f370451]906                return buildSymbolic( td, attributes, name, scs, linkage );
[413ad05]907        } else {
[a7c90d4]908                return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName );
[413ad05]909        } // if
[2298f728]910        return nullptr;
[413ad05]911} // buildDecl
912
[201aeb9]913
[413ad05]914FunctionType * buildFunction( const TypeData * td ) {
915        assert( td->kind == TypeData::Function );
[2a8427c6]916        FunctionType * ft = new FunctionType( buildQualifiers( td ), ! td->function.params || td->function.params->hasEllipsis );
[704d11e]917        buildList( td->function.params, ft->parameters );
918        buildForall( td->forall, ft->forall );
[413ad05]919        if ( td->base ) {
920                switch ( td->base->kind ) {
921                  case TypeData::Tuple:
[704d11e]922                        buildList( td->base->tuple, ft->returnVals );
[413ad05]923                        break;
924                  default:
[ddfd945]925                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType * >( buildDecl( td->base, "", Type::StorageClasses(), nullptr, Type::FuncSpecifiers(), LinkageSpec::Cforall, nullptr ) ) );
[413ad05]926                } // switch
927        } else {
[68fe077a]928                ft->get_returnVals().push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
[413ad05]929        } // if
930        return ft;
931} // buildFunction
[b87a5ed]932
[201aeb9]933
[a7c4921]934// Transform KR routine declarations into C99 routine declarations:
935//
936//    rtn( a, b, c ) int a, c; double b {}  =>  int rtn( int a, double c, int b ) {}
937//
938// The type information for each post-declaration is moved to the corresponding pre-parameter and the post-declaration
939// is deleted. Note, the order of the parameter names may not be the same as the declaration names. Duplicate names and
940// extra names are disallowed.
941//
942// Note, there is no KR routine-prototype syntax:
943//
944//    rtn( a, b, c ) int a, c; double b; // invalid KR prototype
945//    rtn(); // valid KR prototype
946
[3a5131ed]947void buildKRFunction( const TypeData::Function_t & function ) {
948        assert( ! function.params );
[a7c4921]949        // loop over declaration first as it is easier to spot errors
950        for ( DeclarationNode * decl = function.oldDeclList; decl != nullptr; decl = dynamic_cast< DeclarationNode * >( decl->get_next() ) ) {
951                // scan ALL parameter names for each declaration name to check for duplicates
[a7c90d4]952                for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode * >( param->get_next() ) ) {
[3a5131ed]953                        if ( *decl->name == *param->name ) {
[a7c4921]954                                // type set => parameter name already transformed by a declaration names so there is a duplicate
955                                // declaration name attempting a second transformation
[a16764a6]956                                if ( param->type ) SemanticError( param->location, string( "duplicate declaration name " ) + *param->name );
[a7c4921]957                                // declaration type reset => declaration already transformed by a parameter name so there is a duplicate
958                                // parameter name attempting a second transformation
[a16764a6]959                                if ( ! decl->type ) SemanticError( param->location, string( "duplicate parameter name " ) + *param->name );
[a7c4921]960                                param->type = decl->type;                               // set copy declaration type to parameter type
961                                decl->type = nullptr;                                   // reset declaration type
962                                param->attributes.splice( param->attributes.end(), decl->attributes ); // copy and reset attributes from declaration to parameter
[3a5131ed]963                        } // if
964                } // for
[a7c4921]965                // declaration type still set => type not moved to a matching parameter so there is a missing parameter name
[a16764a6]966                if ( decl->type ) SemanticError( decl->location, string( "missing name in parameter list " ) + *decl->name );
[3a5131ed]967        } // for
[a7c4921]968
969        // Parameter names without a declaration default to type int:
970        //
971        //    rtb( a, b, c ) const char * b; {} => int rtn( int a, const char * b, int c ) {}
972
[a7c90d4]973        for ( DeclarationNode * param = function.idList; param != nullptr; param = dynamic_cast< DeclarationNode * >( param->get_next() ) ) {
[ca1a547]974                if ( ! param->type ) {                                                  // generate type int for empty parameter type
[3a5131ed]975                        param->type = new TypeData( TypeData::Basic );
976                        param->type->basictype = DeclarationNode::Int;
977                } // if
978        } // for
979
[a7c4921]980        function.params = function.idList;                                      // newly modified idList becomes parameters
981        function.idList = nullptr;                                                      // idList now empty
982        delete function.oldDeclList;                                            // deletes entire list
983        function.oldDeclList = nullptr;                                         // reset
[3a5131ed]984} // buildKRFunction
985
[b87a5ed]986// Local Variables: //
987// tab-width: 4 //
988// mode: c++ //
989// compile-command: "make install" //
990// End: //
Note: See TracBrowser for help on using the repository browser.