source: src/SymTab/Validate.cc @ d997f8e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since d997f8e was 11ab8ea8, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

add checks for generic type parameter length

  • Property mode set to 100644
File size: 35.3 KB
RevLine 
[0dd3a2f]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//
[9cb8e88d]7// Validate.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 21:50:04 2015
[4e06c1e]11// Last Modified By : Peter A. Buhr
[fbcde64]12// Last Modified On : Thu Mar 30 16:50:13 2017
13// Update Count     : 357
[0dd3a2f]14//
15
16// The "validate" phase of translation is used to take a syntax tree and convert it into a standard form that aims to be
17// as regular in structure as possible.  Some assumptions can be made regarding the state of the tree after this pass is
18// complete, including:
19//
20// - No nested structure or union definitions; any in the input are "hoisted" to the level of the containing struct or
21//   union.
22//
23// - All enumeration constants have type EnumInstType.
24//
[3c13c03]25// - The type "void" never occurs in lists of function parameter or return types.  A function
26//   taking no arguments has no argument types.
[0dd3a2f]27//
28// - No context instances exist; they are all replaced by the set of declarations signified by the context, instantiated
29//   by the particular set of type arguments.
30//
31// - Every declaration is assigned a unique id.
32//
33// - No typedef declarations or instances exist; the actual type is substituted for each instance.
34//
35// - Each type, struct, and union definition is followed by an appropriate assignment operator.
36//
37// - Each use of a struct or union is connected to a complete definition of that struct or union, even if that
38//   definition occurs later in the input.
[51b7345]39
40#include <list>
41#include <iterator>
[e491159]42#include "Common/ScopedMap.h"
[630a82a]43#include "Common/utility.h"
44#include "Common/UniqueName.h"
[bcda04c]45#include "Concurrency/Keywords.h"
[51b7345]46#include "Validate.h"
47#include "SynTree/Visitor.h"
48#include "SynTree/Mutator.h"
49#include "SynTree/Type.h"
[630a82a]50#include "SynTree/Expression.h"
[51b7345]51#include "SynTree/Statement.h"
52#include "SynTree/TypeSubstitution.h"
[68cd1ce]53#include "Indexer.h"
[51b7345]54#include "FixFunction.h"
[cc79d97]55// #include "ImplementationType.h"
[630a82a]56#include "GenPoly/DeclMutator.h"
[51b7345]57#include "AddVisit.h"
[f6d7e0f]58#include "MakeLibCfa.h"
[cc79d97]59#include "TypeEquality.h"
[620cb95]60#include "Autogen.h"
[1cbca6e]61#include "ResolvExpr/typeops.h"
[79970ed]62#include <algorithm>
[d1969a6]63#include "InitTweak/InitTweak.h"
[9facf3b]64#include "CodeGen/CodeGenerator.h"
[51b7345]65
[c8ffe20b]66#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
[51b7345]67
68namespace SymTab {
[9facf3b]69        class HoistStruct final : public Visitor {
[c0aa336]70                template< typename Visitor >
71                friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
72            template< typename Visitor >
73            friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor );
[a08ba92]74          public:
[82dd287]75                /// Flattens nested struct types
[0dd3a2f]76                static void hoistStruct( std::list< Declaration * > &translationUnit );
[9cb8e88d]77
[0dd3a2f]78                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
[9cb8e88d]79
[c0aa336]80                virtual void visit( EnumInstType *enumInstType );
81                virtual void visit( StructInstType *structInstType );
82                virtual void visit( UnionInstType *unionInstType );
[0dd3a2f]83                virtual void visit( StructDecl *aggregateDecl );
84                virtual void visit( UnionDecl *aggregateDecl );
[c8ffe20b]85
[0dd3a2f]86                virtual void visit( CompoundStmt *compoundStmt );
87                virtual void visit( SwitchStmt *switchStmt );
[a08ba92]88          private:
[0dd3a2f]89                HoistStruct();
[c8ffe20b]90
[0dd3a2f]91                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
[c8ffe20b]92
[c0aa336]93                std::list< Declaration * > declsToAdd, declsToAddAfter;
[0dd3a2f]94                bool inStruct;
[a08ba92]95        };
[c8ffe20b]96
[cce9429]97        /// Fix return types so that every function returns exactly one value
[9facf3b]98        class ReturnTypeFixer final : public Visitor {
[cce9429]99          public:
[9facf3b]100                typedef Visitor Parent;
101                using Parent::visit;
102
[cce9429]103                static void fix( std::list< Declaration * > &translationUnit );
104
[9facf3b]105                virtual void visit( FunctionDecl * functionDecl );
[cce9429]106                virtual void visit( FunctionType * ftype );
107        };
108
[de91427b]109        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
[9facf3b]110        class EnumAndPointerDecayPass final : public Visitor {
[0dd3a2f]111                typedef Visitor Parent;
112                virtual void visit( EnumDecl *aggregateDecl );
113                virtual void visit( FunctionType *func );
[a08ba92]114        };
[82dd287]115
116        /// Associates forward declarations of aggregates with their definitions
[cce9429]117        class LinkReferenceToTypes final : public Indexer {
[0dd3a2f]118                typedef Indexer Parent;
[a08ba92]119          public:
[cce9429]120                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
[a08ba92]121          private:
[4a9ccc3]122                using Parent::visit;
[c0aa336]123                void visit( EnumInstType *enumInst ) final;
[62e5546]124                void visit( StructInstType *structInst ) final;
125                void visit( UnionInstType *unionInst ) final;
126                void visit( TraitInstType *contextInst ) final;
[c0aa336]127                void visit( EnumDecl *enumDecl ) final;
[62e5546]128                void visit( StructDecl *structDecl ) final;
129                void visit( UnionDecl *unionDecl ) final;
130                void visit( TypeInstType *typeInst ) final;
[0dd3a2f]131
132                const Indexer *indexer;
[9cb8e88d]133
[c0aa336]134                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
[0dd3a2f]135                typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
136                typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
[c0aa336]137                ForwardEnumsType forwardEnums;
[0dd3a2f]138                ForwardStructsType forwardStructs;
139                ForwardUnionsType forwardUnions;
[a08ba92]140        };
[c8ffe20b]141
[82dd287]142        /// Replaces array and function types in forall lists by appropriate pointer type
[4a9ccc3]143        class Pass3 final : public Indexer {
[0dd3a2f]144                typedef Indexer Parent;
[a08ba92]145          public:
[4a9ccc3]146                using Parent::visit;
[0dd3a2f]147                Pass3( const Indexer *indexer );
[a08ba92]148          private:
[4a9ccc3]149                virtual void visit( ObjectDecl *object ) override;
150                virtual void visit( FunctionDecl *func ) override;
[c8ffe20b]151
[0dd3a2f]152                const Indexer *indexer;
[a08ba92]153        };
[c8ffe20b]154
[de91427b]155        class ReturnChecker : public Visitor {
156          public:
157                /// Checks that return statements return nothing if their return type is void
158                /// and return something if the return type is non-void.
159                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
160          private:
161                virtual void visit( FunctionDecl * functionDecl );
162                virtual void visit( ReturnStmt * returnStmt );
163
164                std::list< DeclarationWithType * > returnVals;
165        };
166
[a08ba92]167        class EliminateTypedef : public Mutator {
168          public:
[de91427b]169                EliminateTypedef() : scopeLevel( 0 ) {}
170                /// Replaces typedefs by forward declarations
[0dd3a2f]171                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
[a08ba92]172          private:
[0dd3a2f]173                virtual Declaration *mutate( TypedefDecl *typeDecl );
174                virtual TypeDecl *mutate( TypeDecl *typeDecl );
175                virtual DeclarationWithType *mutate( FunctionDecl *funcDecl );
[1db21619]176                virtual DeclarationWithType *mutate( ObjectDecl *objDecl );
[0dd3a2f]177                virtual CompoundStmt *mutate( CompoundStmt *compoundStmt );
178                virtual Type *mutate( TypeInstType *aggregateUseType );
179                virtual Expression *mutate( CastExpr *castExpr );
[cc79d97]180
[85c4ef0]181                virtual Declaration *mutate( StructDecl * structDecl );
182                virtual Declaration *mutate( UnionDecl * unionDecl );
183                virtual Declaration *mutate( EnumDecl * enumDecl );
[4040425]184                virtual Declaration *mutate( TraitDecl * contextDecl );
[85c4ef0]185
186                template<typename AggDecl>
187                AggDecl *handleAggregate( AggDecl * aggDecl );
188
[45161b4d]189                template<typename AggDecl>
190                void addImplicitTypedef( AggDecl * aggDecl );
[70a06f6]191
[46f6134]192                typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr;
[e491159]193                typedef ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap;
[679864e1]194                typedef std::map< std::string, TypeDecl * > TypeDeclMap;
[cc79d97]195                TypedefMap typedefNames;
[679864e1]196                TypeDeclMap typedeclNames;
[cc79d97]197                int scopeLevel;
[a08ba92]198        };
[c8ffe20b]199
[d1969a6]200        class VerifyCtorDtorAssign : public Visitor {
[9cb8e88d]201        public:
[d1969a6]202                /// ensure that constructors, destructors, and assignment have at least one
203                /// parameter, the first of which must be a pointer, and that ctor/dtors have no
[9cb8e88d]204                /// return values.
205                static void verify( std::list< Declaration * > &translationUnit );
206
207                virtual void visit( FunctionDecl *funcDecl );
[5f98ce5]208        };
[70a06f6]209
[11ab8ea8]210        /// ensure that generic types have the correct number of type arguments
211        class ValidateGenericParameters : public Visitor {
212        public:
213                typedef Visitor Parent;
214                virtual void visit( StructInstType * inst ) final override;
215                virtual void visit( UnionInstType * inst ) final override;
216        };
217
[fbd7ad6]218        class ArrayLength : public Visitor {
219        public:
220                /// for array types without an explicit length, compute the length and store it so that it
221                /// is known to the rest of the phases. For example,
222                ///   int x[] = { 1, 2, 3 };
223                ///   int y[][2] = { { 1, 2, 3 }, { 1, 2, 3 } };
224                /// here x and y are known at compile-time to have length 3, so change this into
225                ///   int x[3] = { 1, 2, 3 };
226                ///   int y[3][2] = { { 1, 2, 3 }, { 1, 2, 3 } };
227                static void computeLength( std::list< Declaration * > & translationUnit );
228
229                virtual void visit( ObjectDecl * objDecl );
230        };
231
[62e5546]232        class CompoundLiteral final : public GenPoly::DeclMutator {
[68fe077a]233                Type::StorageClasses storageClasses;
[630a82a]234
[62e5546]235                using GenPoly::DeclMutator::mutate;
236                DeclarationWithType * mutate( ObjectDecl *objectDecl ) final;
237                Expression *mutate( CompoundLiteralExpr *compLitExpr ) final;
[9cb8e88d]238        };
239
[a08ba92]240        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
[bda58ad]241                EnumAndPointerDecayPass epc;
[cce9429]242                LinkReferenceToTypes lrt( doDebug, 0 );
[0dd3a2f]243                Pass3 pass3( 0 );
[630a82a]244                CompoundLiteral compoundliteral;
[11ab8ea8]245                ValidateGenericParameters genericParams;
[630a82a]246
[fbcde64]247                EliminateTypedef::eliminateTypedef( translationUnit );
[11ab8ea8]248                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
[cce9429]249                ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
[861799c]250                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
[11ab8ea8]251                acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes
[ed8a0d2]252                acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
253                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
[bcda04c]254                Concurrency::applyKeywords( translationUnit );
[bda58ad]255                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
[bcda04c]256                Concurrency::implementMutexFuncs( translationUnit );
257                Concurrency::implementThreadStarter( translationUnit );
[de91427b]258                ReturnChecker::checkFunctionReturns( translationUnit );
[40e636a]259                compoundliteral.mutateDeclarationList( translationUnit );
[0dd3a2f]260                acceptAll( translationUnit, pass3 );
[fbd7ad6]261                ArrayLength::computeLength( translationUnit );
[a08ba92]262        }
[9cb8e88d]263
[a08ba92]264        void validateType( Type *type, const Indexer *indexer ) {
[bda58ad]265                EnumAndPointerDecayPass epc;
[cce9429]266                LinkReferenceToTypes lrt( false, indexer );
[0dd3a2f]267                Pass3 pass3( indexer );
[bda58ad]268                type->accept( epc );
[cce9429]269                type->accept( lrt );
[0dd3a2f]270                type->accept( pass3 );
[a08ba92]271        }
[c8ffe20b]272
[a08ba92]273        void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
[0dd3a2f]274                HoistStruct hoister;
[c0aa336]275                acceptAndAdd( translationUnit, hoister );
[a08ba92]276        }
[c8ffe20b]277
[a08ba92]278        HoistStruct::HoistStruct() : inStruct( false ) {
279        }
[c8ffe20b]280
[a08ba92]281        void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {
[0dd3a2f]282                std::list< Declaration * >::iterator i = declList.begin();
283                while ( i != declList.end() ) {
284                        std::list< Declaration * >::iterator next = i;
285                        ++next;
286                        if ( pred( *i ) ) {
287                                if ( doDelete ) {
288                                        delete *i;
289                                } // if
290                                declList.erase( i );
291                        } // if
292                        i = next;
293                } // while
[a08ba92]294        }
[c8ffe20b]295
[a08ba92]296        bool isStructOrUnion( Declaration *decl ) {
[0dd3a2f]297                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
[a08ba92]298        }
[c0aa336]299
[a08ba92]300        template< typename AggDecl >
301        void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
[0dd3a2f]302                if ( inStruct ) {
303                        // Add elements in stack order corresponding to nesting structure.
304                        declsToAdd.push_front( aggregateDecl );
305                        Visitor::visit( aggregateDecl );
306                } else {
307                        inStruct = true;
308                        Visitor::visit( aggregateDecl );
309                        inStruct = false;
310                } // if
311                // Always remove the hoisted aggregate from the inner structure.
312                filter( aggregateDecl->get_members(), isStructOrUnion, false );
[a08ba92]313        }
[c8ffe20b]314
[c0aa336]315        void HoistStruct::visit( EnumInstType *structInstType ) {
316                if ( structInstType->get_baseEnum() ) {
317                        declsToAdd.push_front( structInstType->get_baseEnum() );
318                }
319        }
320
321        void HoistStruct::visit( StructInstType *structInstType ) {
322                if ( structInstType->get_baseStruct() ) {
323                        declsToAdd.push_front( structInstType->get_baseStruct() );
324                }
325        }
326
327        void HoistStruct::visit( UnionInstType *structInstType ) {
328                if ( structInstType->get_baseUnion() ) {
329                        declsToAdd.push_front( structInstType->get_baseUnion() );
330                }
331        }
332
[a08ba92]333        void HoistStruct::visit( StructDecl *aggregateDecl ) {
[0dd3a2f]334                handleAggregate( aggregateDecl );
[a08ba92]335        }
[c8ffe20b]336
[a08ba92]337        void HoistStruct::visit( UnionDecl *aggregateDecl ) {
[0dd3a2f]338                handleAggregate( aggregateDecl );
[a08ba92]339        }
[c8ffe20b]340
[a08ba92]341        void HoistStruct::visit( CompoundStmt *compoundStmt ) {
[0dd3a2f]342                addVisit( compoundStmt, *this );
[a08ba92]343        }
[c8ffe20b]344
[a08ba92]345        void HoistStruct::visit( SwitchStmt *switchStmt ) {
[0dd3a2f]346                addVisit( switchStmt, *this );
[a08ba92]347        }
[c8ffe20b]348
[bda58ad]349        void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
[0dd3a2f]350                // Set the type of each member of the enumeration to be EnumConstant
351                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
[f6d7e0f]352                        ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i );
[0dd3a2f]353                        assert( obj );
[f2e40a9f]354                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
[0dd3a2f]355                } // for
356                Parent::visit( enumDecl );
[a08ba92]357        }
[51b7345]358
[a08ba92]359        namespace {
[83de11e]360                template< typename DWTList >
361                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
[0dd3a2f]362                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
363                        // entirely other fix ups are handled by the FixFunction class
[83de11e]364                        typedef typename DWTList::iterator DWTIterator;
365                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
[0dd3a2f]366                        if ( begin == end ) return;
367                        FixFunction fixer;
368                        DWTIterator i = begin;
[83de11e]369                        *i = (*i)->acceptMutator( fixer );
[0dd3a2f]370                        if ( fixer.get_isVoid() ) {
371                                DWTIterator j = i;
372                                ++i;
[bda58ad]373                                delete *j;
[83de11e]374                                dwts.erase( j );
[9cb8e88d]375                                if ( i != end ) {
[0dd3a2f]376                                        throw SemanticError( "invalid type void in function type ", func );
377                                } // if
378                        } else {
379                                ++i;
380                                for ( ; i != end; ++i ) {
381                                        FixFunction fixer;
382                                        *i = (*i )->acceptMutator( fixer );
383                                        if ( fixer.get_isVoid() ) {
384                                                throw SemanticError( "invalid type void in function type ", func );
385                                        } // if
386                                } // for
387                        } // if
388                }
[a08ba92]389        }
[c8ffe20b]390
[bda58ad]391        void EnumAndPointerDecayPass::visit( FunctionType *func ) {
[0dd3a2f]392                // Fix up parameters and return types
[83de11e]393                fixFunctionList( func->get_parameters(), func );
394                fixFunctionList( func->get_returnVals(), func );
[0dd3a2f]395                Visitor::visit( func );
[a08ba92]396        }
[c8ffe20b]397
[cce9429]398        LinkReferenceToTypes::LinkReferenceToTypes( bool doDebug, const Indexer *other_indexer ) : Indexer( doDebug ) {
[0dd3a2f]399                if ( other_indexer ) {
400                        indexer = other_indexer;
401                } else {
402                        indexer = this;
403                } // if
[a08ba92]404        }
[c8ffe20b]405
[c0aa336]406        void LinkReferenceToTypes::visit( EnumInstType *enumInst ) {
407                Parent::visit( enumInst );
408                EnumDecl *st = indexer->lookupEnum( enumInst->get_name() );
409                // it's not a semantic error if the enum is not found, just an implicit forward declaration
410                if ( st ) {
411                        //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() );
412                        enumInst->set_baseEnum( st );
413                } // if
414                if ( ! st || st->get_members().empty() ) {
415                        // use of forward declaration
416                        forwardEnums[ enumInst->get_name() ].push_back( enumInst );
417                } // if
418        }
419
[cce9429]420        void LinkReferenceToTypes::visit( StructInstType *structInst ) {
[0dd3a2f]421                Parent::visit( structInst );
422                StructDecl *st = indexer->lookupStruct( structInst->get_name() );
423                // it's not a semantic error if the struct is not found, just an implicit forward declaration
424                if ( st ) {
[98735ef]425                        //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
[0dd3a2f]426                        structInst->set_baseStruct( st );
427                } // if
428                if ( ! st || st->get_members().empty() ) {
429                        // use of forward declaration
430                        forwardStructs[ structInst->get_name() ].push_back( structInst );
431                } // if
[a08ba92]432        }
[c8ffe20b]433
[cce9429]434        void LinkReferenceToTypes::visit( UnionInstType *unionInst ) {
[0dd3a2f]435                Parent::visit( unionInst );
436                UnionDecl *un = indexer->lookupUnion( unionInst->get_name() );
437                // it's not a semantic error if the union is not found, just an implicit forward declaration
438                if ( un ) {
439                        unionInst->set_baseUnion( un );
440                } // if
441                if ( ! un || un->get_members().empty() ) {
442                        // use of forward declaration
443                        forwardUnions[ unionInst->get_name() ].push_back( unionInst );
444                } // if
[a08ba92]445        }
[c8ffe20b]446
[4a9ccc3]447        void LinkReferenceToTypes::visit( TraitInstType *traitInst ) {
448                Parent::visit( traitInst );
449                if ( traitInst->get_name() == "sized" ) {
[2c57025]450                        // "sized" is a special trait with no members - just flick the sized status on for the type variable
[4a9ccc3]451                        if ( traitInst->get_parameters().size() != 1 ) {
452                                throw SemanticError( "incorrect number of trait parameters: ", traitInst );
[2c57025]453                        }
[4a9ccc3]454                        TypeExpr * param = safe_dynamic_cast< TypeExpr * > ( traitInst->get_parameters().front() );
[2c57025]455                        TypeInstType * inst = safe_dynamic_cast< TypeInstType * > ( param->get_type() );
456                        TypeDecl * decl = inst->get_baseType();
457                        decl->set_sized( true );
458                        // since "sized" is special, the next few steps don't apply
459                        return;
460                }
[4a9ccc3]461                TraitDecl *traitDecl = indexer->lookupTrait( traitInst->get_name() );
462                if ( ! traitDecl ) {
463                        throw SemanticError( "use of undeclared trait " + traitInst->get_name() );
[17cd4eb]464                } // if
[4a9ccc3]465                if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) {
466                        throw SemanticError( "incorrect number of trait parameters: ", traitInst );
467                } // if
468
469                for ( TypeDecl * td : traitDecl->get_parameters() ) {
470                        for ( DeclarationWithType * assert : td->get_assertions() ) {
471                                traitInst->get_members().push_back( assert->clone() );
[0dd3a2f]472                        } // for
473                } // for
[51b986f]474
[4a9ccc3]475                // need to clone members of the trait for ownership purposes
[79970ed]476                std::list< Declaration * > members;
[4a9ccc3]477                std::transform( traitDecl->get_members().begin(), traitDecl->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } );
478
479                applySubstitution( traitDecl->get_parameters().begin(), traitDecl->get_parameters().end(), traitInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( traitInst->get_members() ) );
[79970ed]480
[4a9ccc3]481                // need to carry over the 'sized' status of each decl in the instance
482                for ( auto p : group_iterate( traitDecl->get_parameters(), traitInst->get_parameters() ) ) {
483                        TypeExpr * expr = safe_dynamic_cast< TypeExpr * >( std::get<1>(p) );
484                        if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
485                                TypeDecl * formalDecl = std::get<0>(p);
486                                TypeDecl * instDecl = inst->get_baseType();
487                                if ( formalDecl->get_sized() ) instDecl->set_sized( true );
488                        }
489                }
[a08ba92]490        }
[c8ffe20b]491
[c0aa336]492        void LinkReferenceToTypes::visit( EnumDecl *enumDecl ) {
493                // visit enum members first so that the types of self-referencing members are updated properly
494                Parent::visit( enumDecl );
495                if ( ! enumDecl->get_members().empty() ) {
496                        ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() );
497                        if ( fwds != forwardEnums.end() ) {
498                                for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
499                                        (*inst )->set_baseEnum( enumDecl );
500                                } // for
501                                forwardEnums.erase( fwds );
502                        } // if
503                } // if
504        }
505
[cce9429]506        void LinkReferenceToTypes::visit( StructDecl *structDecl ) {
[677c1be]507                // visit struct members first so that the types of self-referencing members are updated properly
508                Parent::visit( structDecl );
[0dd3a2f]509                if ( ! structDecl->get_members().empty() ) {
510                        ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
511                        if ( fwds != forwardStructs.end() ) {
512                                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
513                                        (*inst )->set_baseStruct( structDecl );
514                                } // for
515                                forwardStructs.erase( fwds );
516                        } // if
517                } // if
[a08ba92]518        }
[c8ffe20b]519
[cce9429]520        void LinkReferenceToTypes::visit( UnionDecl *unionDecl ) {
[677c1be]521                Parent::visit( unionDecl );
[0dd3a2f]522                if ( ! unionDecl->get_members().empty() ) {
523                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
524                        if ( fwds != forwardUnions.end() ) {
525                                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
526                                        (*inst )->set_baseUnion( unionDecl );
527                                } // for
528                                forwardUnions.erase( fwds );
529                        } // if
530                } // if
[a08ba92]531        }
[c8ffe20b]532
[cce9429]533        void LinkReferenceToTypes::visit( TypeInstType *typeInst ) {
[0dd3a2f]534                if ( NamedTypeDecl *namedTypeDecl = lookupType( typeInst->get_name() ) ) {
535                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
536                                typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
537                        } // if
538                } // if
[a08ba92]539        }
[c8ffe20b]540
[a08ba92]541        Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
[0dd3a2f]542                if ( other_indexer ) {
543                        indexer = other_indexer;
544                } else {
545                        indexer = this;
546                } // if
[a08ba92]547        }
[c8ffe20b]548
[4a9ccc3]549        /// Fix up assertions - flattens assertion lists, removing all trait instances
550        void forallFixer( Type * func ) {
551                for ( TypeDecl * type : func->get_forall() ) {
[0dd3a2f]552                        std::list< DeclarationWithType * > toBeDone, nextRound;
[4a9ccc3]553                        toBeDone.splice( toBeDone.end(), type->get_assertions() );
[0dd3a2f]554                        while ( ! toBeDone.empty() ) {
[4a9ccc3]555                                for ( DeclarationWithType * assertion : toBeDone ) {
556                                        if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
557                                                // expand trait instance into all of its members
558                                                for ( Declaration * member : traitInst->get_members() ) {
559                                                        DeclarationWithType *dwt = safe_dynamic_cast< DeclarationWithType * >( member );
[0dd3a2f]560                                                        nextRound.push_back( dwt->clone() );
561                                                }
[4a9ccc3]562                                                delete traitInst;
[0dd3a2f]563                                        } else {
[4a9ccc3]564                                                // pass assertion through
[0dd3a2f]565                                                FixFunction fixer;
[4a9ccc3]566                                                assertion = assertion->acceptMutator( fixer );
[0dd3a2f]567                                                if ( fixer.get_isVoid() ) {
568                                                        throw SemanticError( "invalid type void in assertion of function ", func );
569                                                }
[4a9ccc3]570                                                type->get_assertions().push_back( assertion );
[0dd3a2f]571                                        } // if
572                                } // for
573                                toBeDone.clear();
574                                toBeDone.splice( toBeDone.end(), nextRound );
575                        } // while
576                } // for
[a08ba92]577        }
[c8ffe20b]578
[a08ba92]579        void Pass3::visit( ObjectDecl *object ) {
[0dd3a2f]580                forallFixer( object->get_type() );
581                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
582                        forallFixer( pointer->get_base() );
583                } // if
584                Parent::visit( object );
585                object->fixUniqueId();
[a08ba92]586        }
[c8ffe20b]587
[a08ba92]588        void Pass3::visit( FunctionDecl *func ) {
[0dd3a2f]589                forallFixer( func->get_type() );
590                Parent::visit( func );
591                func->fixUniqueId();
[a08ba92]592        }
[c8ffe20b]593
[de91427b]594        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
595                ReturnChecker checker;
596                acceptAll( translationUnit, checker );
597        }
598
599        void ReturnChecker::visit( FunctionDecl * functionDecl ) {
600                std::list< DeclarationWithType * > oldReturnVals = returnVals;
601                returnVals = functionDecl->get_functionType()->get_returnVals();
602                Visitor::visit( functionDecl );
603                returnVals = oldReturnVals;
604        }
605
606        void ReturnChecker::visit( ReturnStmt * returnStmt ) {
[74d1804]607                // Previously this also checked for the existence of an expr paired with no return values on
608                // the  function return type. This is incorrect, since you can have an expression attached to
609                // a return statement in a void-returning function in C. The expression is treated as if it
610                // were cast to void.
[de91427b]611                if ( returnStmt->get_expr() == NULL && returnVals.size() != 0 ) {
612                        throw SemanticError( "Non-void function returns no values: " , returnStmt );
613                }
614        }
615
616
[a08ba92]617        bool isTypedef( Declaration *decl ) {
[0dd3a2f]618                return dynamic_cast< TypedefDecl * >( decl );
[a08ba92]619        }
[c8ffe20b]620
[a08ba92]621        void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
[0dd3a2f]622                EliminateTypedef eliminator;
623                mutateAll( translationUnit, eliminator );
[5f98ce5]624                if ( eliminator.typedefNames.count( "size_t" ) ) {
625                        // grab and remember declaration of size_t
626                        SizeType = eliminator.typedefNames["size_t"].first->get_base()->clone();
627                } else {
[40e636a]628                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
629                        // eventually should have a warning for this case.
630                        SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
[5f98ce5]631                }
[0dd3a2f]632                filter( translationUnit, isTypedef, true );
[5f98ce5]633
[a08ba92]634        }
[c8ffe20b]635
[85c4ef0]636        Type *EliminateTypedef::mutate( TypeInstType * typeInst ) {
[9cb8e88d]637                // instances of typedef types will come here. If it is an instance
[cc79d97]638                // of a typdef type, link the instance to its actual type.
639                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
[0dd3a2f]640                if ( def != typedefNames.end() ) {
[cc79d97]641                        Type *ret = def->second.first->get_base()->clone();
[6f95000]642                        ret->get_qualifiers() |= typeInst->get_qualifiers();
[0215a76f]643                        // place instance parameters on the typedef'd type
644                        if ( ! typeInst->get_parameters().empty() ) {
645                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
646                                if ( ! rtt ) {
647                                        throw SemanticError("cannot apply type parameters to base type of " + typeInst->get_name());
648                                }
649                                rtt->get_parameters().clear();
[b644d6f]650                                cloneAll( typeInst->get_parameters(), rtt->get_parameters() );
651                                mutateAll( rtt->get_parameters(), *this );  // recursively fix typedefs on parameters
[1db21619]652                        } // if
[0dd3a2f]653                        delete typeInst;
654                        return ret;
[679864e1]655                } else {
656                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
[43c89a7]657                        assertf( base != typedeclNames.end(), "Can't find typedecl name %s", typeInst->get_name().c_str() );
[1e8b02f5]658                        typeInst->set_baseType( base->second );
[0dd3a2f]659                } // if
660                return typeInst;
[a08ba92]661        }
[c8ffe20b]662
[85c4ef0]663        Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
[0dd3a2f]664                Declaration *ret = Mutator::mutate( tyDecl );
[5f98ce5]665
[cc79d97]666                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
[9cb8e88d]667                        // typedef to the same name from the same scope
[cc79d97]668                        // must be from the same type
669
670                        Type * t1 = tyDecl->get_base();
671                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
[1cbca6e]672                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
[cc79d97]673                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
[85c4ef0]674                        }
[cc79d97]675                } else {
[46f6134]676                        typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );
[cc79d97]677                } // if
678
[0dd3a2f]679                // When a typedef is a forward declaration:
680                //    typedef struct screen SCREEN;
681                // the declaration portion must be retained:
682                //    struct screen;
683                // because the expansion of the typedef is:
684                //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
685                // hence the type-name "screen" must be defined.
686                // Note, qualifiers on the typedef are superfluous for the forward declaration.
[6f95000]687
688                Type *designatorType = tyDecl->get_base()->stripDeclarator();
689                if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
[dd020c0]690                        return new StructDecl( aggDecl->get_name() );
[6f95000]691                } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
[dd020c0]692                        return new UnionDecl( aggDecl->get_name() );
[6f95000]693                } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
[956a9c7]694                        return new EnumDecl( enumDecl->get_name() );
[0dd3a2f]695                } else {
[46f6134]696                        return ret->clone();
[0dd3a2f]697                } // if
[a08ba92]698        }
[c8ffe20b]699
[85c4ef0]700        TypeDecl *EliminateTypedef::mutate( TypeDecl * typeDecl ) {
[cc79d97]701                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
[0dd3a2f]702                if ( i != typedefNames.end() ) {
703                        typedefNames.erase( i ) ;
704                } // if
[679864e1]705
706                typedeclNames[ typeDecl->get_name() ] = typeDecl;
[2c57025]707                return Mutator::mutate( typeDecl );
[a08ba92]708        }
[c8ffe20b]709
[85c4ef0]710        DeclarationWithType *EliminateTypedef::mutate( FunctionDecl * funcDecl ) {
[46f6134]711                typedefNames.beginScope();
[0dd3a2f]712                DeclarationWithType *ret = Mutator::mutate( funcDecl );
[46f6134]713                typedefNames.endScope();
[0dd3a2f]714                return ret;
[a08ba92]715        }
[c8ffe20b]716
[1db21619]717        DeclarationWithType *EliminateTypedef::mutate( ObjectDecl * objDecl ) {
[46f6134]718                typedefNames.beginScope();
[1db21619]719                DeclarationWithType *ret = Mutator::mutate( objDecl );
[46f6134]720                typedefNames.endScope();
[dd020c0]721
722                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) { // function type?
[02e5ab6]723                        // replace the current object declaration with a function declaration
[a7c90d4]724                        FunctionDecl * newDecl = new FunctionDecl( ret->get_name(), ret->get_storageClasses(), ret->get_linkage(), funtype, 0, objDecl->get_attributes(), ret->get_funcSpec() );
[0a86a30]725                        objDecl->get_attributes().clear();
[dbe8f244]726                        objDecl->set_type( nullptr );
[0a86a30]727                        delete objDecl;
728                        return newDecl;
[1db21619]729                } // if
[0dd3a2f]730                return ret;
[a08ba92]731        }
[c8ffe20b]732
[85c4ef0]733        Expression *EliminateTypedef::mutate( CastExpr * castExpr ) {
[46f6134]734                typedefNames.beginScope();
[0dd3a2f]735                Expression *ret = Mutator::mutate( castExpr );
[46f6134]736                typedefNames.endScope();
[0dd3a2f]737                return ret;
[a08ba92]738        }
[c8ffe20b]739
[85c4ef0]740        CompoundStmt *EliminateTypedef::mutate( CompoundStmt * compoundStmt ) {
[46f6134]741                typedefNames.beginScope();
[cc79d97]742                scopeLevel += 1;
[0dd3a2f]743                CompoundStmt *ret = Mutator::mutate( compoundStmt );
[cc79d97]744                scopeLevel -= 1;
[0dd3a2f]745                std::list< Statement * >::iterator i = compoundStmt->get_kids().begin();
746                while ( i != compoundStmt->get_kids().end() ) {
[85c4ef0]747                        std::list< Statement * >::iterator next = i+1;
[0dd3a2f]748                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( *i ) ) {
749                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
750                                        delete *i;
751                                        compoundStmt->get_kids().erase( i );
752                                } // if
753                        } // if
754                        i = next;
755                } // while
[46f6134]756                typedefNames.endScope();
[0dd3a2f]757                return ret;
[a08ba92]758        }
[85c4ef0]759
[43c89a7]760        // there may be typedefs nested within aggregates. in order for everything to work properly, these should be removed
[45161b4d]761        // as well
[85c4ef0]762        template<typename AggDecl>
763        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
764                std::list<Declaration *>::iterator it = aggDecl->get_members().begin();
765                for ( ; it != aggDecl->get_members().end(); ) {
766                        std::list< Declaration * >::iterator next = it+1;
767                        if ( dynamic_cast< TypedefDecl * >( *it ) ) {
768                                delete *it;
769                                aggDecl->get_members().erase( it );
770                        } // if
771                        it = next;
772                }
773                return aggDecl;
774        }
775
[45161b4d]776        template<typename AggDecl>
777        void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
778                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
[62e5546]779                        Type *type = nullptr;
[45161b4d]780                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
781                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
782                        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) {
783                                type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() );
784                        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl )  ) {
785                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
786                        } // if
[68fe077a]787                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type ) );
[46f6134]788                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
[45161b4d]789                } // if
790        }
[4e06c1e]791
[85c4ef0]792        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
[45161b4d]793                addImplicitTypedef( structDecl );
[85c4ef0]794                Mutator::mutate( structDecl );
795                return handleAggregate( structDecl );
796        }
797
798        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
[45161b4d]799                addImplicitTypedef( unionDecl );
[85c4ef0]800                Mutator::mutate( unionDecl );
801                return handleAggregate( unionDecl );
802        }
803
804        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
[45161b4d]805                addImplicitTypedef( enumDecl );
[85c4ef0]806                Mutator::mutate( enumDecl );
807                return handleAggregate( enumDecl );
808        }
809
[45161b4d]810        Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
[85c4ef0]811                Mutator::mutate( contextDecl );
812                return handleAggregate( contextDecl );
813        }
814
[d1969a6]815        void VerifyCtorDtorAssign::verify( std::list< Declaration * > & translationUnit ) {
816                VerifyCtorDtorAssign verifier;
[9cb8e88d]817                acceptAll( translationUnit, verifier );
818        }
819
[d1969a6]820        void VerifyCtorDtorAssign::visit( FunctionDecl * funcDecl ) {
[9cb8e88d]821                FunctionType * funcType = funcDecl->get_functionType();
822                std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
823                std::list< DeclarationWithType * > &params = funcType->get_parameters();
824
[d1969a6]825                if ( InitTweak::isCtorDtorAssign( funcDecl->get_name() ) ) {
[9cb8e88d]826                        if ( params.size() == 0 ) {
[d1969a6]827                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
[9cb8e88d]828                        }
[ed8a0d2]829                        PointerType * ptrType = dynamic_cast< PointerType * >( params.front()->get_type() );
830                        if ( ! ptrType || ptrType->is_array() ) {
[d1969a6]831                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl );
[9cb8e88d]832                        }
[d1969a6]833                        if ( InitTweak::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
[9cb8e88d]834                                throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
835                        }
836                }
837
838                Visitor::visit( funcDecl );
839        }
[70a06f6]840
[11ab8ea8]841        template< typename Aggr >
842        void validateGeneric( Aggr * inst ) {
843                std::list< TypeDecl * > * params = inst->get_baseParameters();
844                if ( params != NULL ) {
845                        std::list< Expression * > & args = inst->get_parameters();
846                        if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
847                        if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
848                }
849        }
850
851        void ValidateGenericParameters::visit( StructInstType * inst ) {
852                validateGeneric( inst );
853                Parent::visit( inst );
854        }
855
856        void ValidateGenericParameters::visit( UnionInstType * inst ) {
857                validateGeneric( inst );
858                Parent::visit( inst );
859        }
860
[630a82a]861        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
[a7c90d4]862                storageClasses = objectDecl->get_storageClasses();
[630a82a]863                DeclarationWithType * temp = Mutator::mutate( objectDecl );
864                return temp;
865        }
866
867        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
868                // transform [storage_class] ... (struct S){ 3, ... };
869                // into [storage_class] struct S temp =  { 3, ... };
870                static UniqueName indexName( "_compLit" );
871
[fbcde64]872                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() );
873                compLitExpr->set_result( 0 );
[630a82a]874                compLitExpr->set_initializer( 0 );
875                delete compLitExpr;
876                DeclarationWithType * newtempvar = mutate( tempvar );
877                addDeclaration( newtempvar );                                   // add modified temporary to current block
878                return new VariableExpr( newtempvar );
879        }
[cce9429]880
881        void ReturnTypeFixer::fix( std::list< Declaration * > &translationUnit ) {
882                ReturnTypeFixer fixer;
883                acceptAll( translationUnit, fixer );
884        }
885
[9facf3b]886        void ReturnTypeFixer::visit( FunctionDecl * functionDecl ) {
887                Parent::visit( functionDecl );
888                FunctionType * ftype = functionDecl->get_functionType();
889                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
890                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %d", functionDecl->get_name().c_str(), retVals.size() );
891                if ( retVals.size() == 1 ) {
[861799c]892                        // ensure all function return values have a name - use the name of the function to disambiguate (this also provides a nice bit of help for debugging).
893                        // ensure other return values have a name.
[9facf3b]894                        DeclarationWithType * ret = retVals.front();
895                        if ( ret->get_name() == "" ) {
896                                ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) );
897                        }
898                }
899        }
[cce9429]900
[9facf3b]901        void ReturnTypeFixer::visit( FunctionType * ftype ) {
[cce9429]902                // xxx - need to handle named return values - this information needs to be saved somehow
903                // so that resolution has access to the names.
904                // Note that this pass needs to happen early so that other passes which look for tuple types
905                // find them in all of the right places, including function return types.
906                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
907                if ( retVals.size() > 1 ) {
908                        // generate a single return parameter which is the tuple of all of the return values
909                        TupleType * tupleType = safe_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
910                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
[68fe077a]911                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
[cce9429]912                        deleteAll( retVals );
913                        retVals.clear();
914                        retVals.push_back( newRet );
915                }
916        }
[fbd7ad6]917
918        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
919                ArrayLength len;
920                acceptAll( translationUnit, len );
921        }
922
923        void ArrayLength::visit( ObjectDecl * objDecl ) {
924                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
925                        if ( at->get_dimension() != nullptr ) return;
926                        if ( ListInit * init = dynamic_cast< ListInit * >( objDecl->get_init() ) ) {
927                                at->set_dimension( new ConstantExpr( Constant::from_ulong( init->get_initializers().size() ) ) );
928                        }
929                }
930        }
[51b7345]931} // namespace SymTab
[0dd3a2f]932
933// Local Variables: //
934// tab-width: 4 //
935// mode: c++ //
936// compile-command: "make install" //
937// End: //
Note: See TracBrowser for help on using the repository browser.