source: src/SymTab/Validate.cc @ c0d00b6

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since c0d00b6 was b95fe40, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Add casts to dtype-static member expressions to prevent loss of type information [fixes #42] [fixes #59]

  • Property mode set to 100644
File size: 42.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Validate.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 21:50:04 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Aug 28 13:47:23 2017
13// Update Count     : 359
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//
25// - The type "void" never occurs in lists of function parameter or return types.  A function
26//   taking no arguments has no argument types.
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.
39
40#include "Validate.h"
41
42#include <cassert>                     // for assertf, assert
43#include <cstddef>                     // for size_t
44#include <list>                        // for list
45#include <string>                      // for string
46#include <utility>                     // for pair
47
48#include "CodeGen/CodeGenerator.h"     // for genName
49#include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
50#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
51#include "Common/ScopedMap.h"          // for ScopedMap
52#include "Common/SemanticError.h"      // for SemanticError
53#include "Common/UniqueName.h"         // for UniqueName
54#include "Common/utility.h"            // for operator+, cloneAll, deleteAll
55#include "Concurrency/Keywords.h"      // for applyKeywords
56#include "FixFunction.h"               // for FixFunction
57#include "Indexer.h"                   // for Indexer
58#include "InitTweak/GenInit.h"         // for fixReturnStatements
59#include "InitTweak/InitTweak.h"       // for isCtorDtorAssign
60#include "Parser/LinkageSpec.h"        // for C
61#include "ResolvExpr/typeops.h"        // for typesCompatible
62#include "SymTab/AddVisit.h"           // for addVisit
63#include "SymTab/Autogen.h"            // for SizeType
64#include "SynTree/Attribute.h"         // for noAttributes, Attribute
65#include "SynTree/Constant.h"          // for Constant
66#include "SynTree/Declaration.h"       // for ObjectDecl, DeclarationWithType
67#include "SynTree/Expression.h"        // for CompoundLiteralExpr, Expressio...
68#include "SynTree/Initializer.h"       // for ListInit, Initializer
69#include "SynTree/Label.h"             // for operator==, Label
70#include "SynTree/Mutator.h"           // for Mutator
71#include "SynTree/Type.h"              // for Type, TypeInstType, EnumInstType
72#include "SynTree/TypeSubstitution.h"  // for TypeSubstitution
73#include "SynTree/Visitor.h"           // for Visitor
74
75class CompoundStmt;
76class ReturnStmt;
77class SwitchStmt;
78
79
80#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
81
82namespace SymTab {
83        class HoistStruct final : public Visitor {
84                template< typename Visitor >
85                friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
86            template< typename Visitor >
87            friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor );
88          public:
89                /// Flattens nested struct types
90                static void hoistStruct( std::list< Declaration * > &translationUnit );
91
92                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
93
94                virtual void visit( EnumInstType *enumInstType );
95                virtual void visit( StructInstType *structInstType );
96                virtual void visit( UnionInstType *unionInstType );
97                virtual void visit( StructDecl *aggregateDecl );
98                virtual void visit( UnionDecl *aggregateDecl );
99
100                virtual void visit( CompoundStmt *compoundStmt );
101                virtual void visit( SwitchStmt *switchStmt );
102          private:
103                HoistStruct();
104
105                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
106
107                std::list< Declaration * > declsToAdd, declsToAddAfter;
108                bool inStruct;
109        };
110
111        /// Fix return types so that every function returns exactly one value
112        struct ReturnTypeFixer {
113                static void fix( std::list< Declaration * > &translationUnit );
114
115                void postvisit( FunctionDecl * functionDecl );
116                void postvisit( FunctionType * ftype );
117        };
118
119        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
120        struct EnumAndPointerDecay {
121                void previsit( EnumDecl *aggregateDecl );
122                void previsit( FunctionType *func );
123        };
124
125        /// Associates forward declarations of aggregates with their definitions
126        struct LinkReferenceToTypes final : public WithIndexer, public WithGuards {
127                LinkReferenceToTypes( const Indexer *indexer );
128                void postvisit( TypeInstType *typeInst );
129
130                void postvisit( EnumInstType *enumInst );
131                void postvisit( StructInstType *structInst );
132                void postvisit( UnionInstType *unionInst );
133                void postvisit( TraitInstType *traitInst );
134
135                void postvisit( EnumDecl *enumDecl );
136                void postvisit( StructDecl *structDecl );
137                void postvisit( UnionDecl *unionDecl );
138                void postvisit( TraitDecl * traitDecl );
139
140                void previsit( StructDecl *structDecl );
141                void previsit( UnionDecl *unionDecl );
142
143                void renameGenericParams( std::list< TypeDecl * > & params );
144
145          private:
146                const Indexer *local_indexer;
147
148                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
149                typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
150                typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
151                ForwardEnumsType forwardEnums;
152                ForwardStructsType forwardStructs;
153                ForwardUnionsType forwardUnions;
154                /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately
155                bool inGeneric = false;
156        };
157
158        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
159        struct ForallPointerDecay final {
160                void previsit( ObjectDecl * object );
161                void previsit( FunctionDecl * func );
162                void previsit( StructDecl * aggrDecl );
163                void previsit( UnionDecl * aggrDecl );
164        };
165
166        struct ReturnChecker : public WithGuards {
167                /// Checks that return statements return nothing if their return type is void
168                /// and return something if the return type is non-void.
169                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
170
171                void previsit( FunctionDecl * functionDecl );
172                void previsit( ReturnStmt * returnStmt );
173
174                typedef std::list< DeclarationWithType * > ReturnVals;
175                ReturnVals returnVals;
176        };
177
178        struct EliminateTypedef final : public WithVisitorRef<EliminateTypedef>, public WithGuards {
179                EliminateTypedef() : scopeLevel( 0 ) {}
180                /// Replaces typedefs by forward declarations
181                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
182
183                Type * postmutate( TypeInstType * aggregateUseType );
184                Declaration * postmutate( TypedefDecl * typeDecl );
185                void premutate( TypeDecl * typeDecl );
186                void premutate( FunctionDecl * funcDecl );
187                void premutate( ObjectDecl * objDecl );
188                DeclarationWithType * postmutate( ObjectDecl * objDecl );
189
190                void premutate( CastExpr * castExpr );
191
192                void premutate( CompoundStmt * compoundStmt );
193                CompoundStmt * postmutate( CompoundStmt * compoundStmt );
194
195                void premutate( StructDecl * structDecl );
196                Declaration * postmutate( StructDecl * structDecl );
197                void premutate( UnionDecl * unionDecl );
198                Declaration * postmutate( UnionDecl * unionDecl );
199                void premutate( EnumDecl * enumDecl );
200                Declaration * postmutate( EnumDecl * enumDecl );
201                Declaration * postmutate( TraitDecl * contextDecl );
202
203          private:
204                template<typename AggDecl>
205                AggDecl *handleAggregate( AggDecl * aggDecl );
206
207                template<typename AggDecl>
208                void addImplicitTypedef( AggDecl * aggDecl );
209
210                typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr;
211                typedef ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap;
212                typedef std::map< std::string, TypeDecl * > TypeDeclMap;
213                TypedefMap typedefNames;
214                TypeDeclMap typedeclNames;
215                int scopeLevel;
216        };
217
218        struct VerifyCtorDtorAssign {
219                /// ensure that constructors, destructors, and assignment have at least one
220                /// parameter, the first of which must be a pointer, and that ctor/dtors have no
221                /// return values.
222                static void verify( std::list< Declaration * > &translationUnit );
223
224                void previsit( FunctionDecl *funcDecl );
225        };
226
227        /// ensure that generic types have the correct number of type arguments
228        struct ValidateGenericParameters {
229                void previsit( StructInstType * inst );
230                void previsit( UnionInstType * inst );
231        };
232
233        struct ArrayLength {
234                /// for array types without an explicit length, compute the length and store it so that it
235                /// is known to the rest of the phases. For example,
236                ///   int x[] = { 1, 2, 3 };
237                ///   int y[][2] = { { 1, 2, 3 }, { 1, 2, 3 } };
238                /// here x and y are known at compile-time to have length 3, so change this into
239                ///   int x[3] = { 1, 2, 3 };
240                ///   int y[3][2] = { { 1, 2, 3 }, { 1, 2, 3 } };
241                static void computeLength( std::list< Declaration * > & translationUnit );
242
243                void previsit( ObjectDecl * objDecl );
244        };
245
246        struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral> {
247                Type::StorageClasses storageClasses;
248
249                void premutate( ObjectDecl *objectDecl );
250                Expression * postmutate( CompoundLiteralExpr *compLitExpr );
251        };
252
253        struct LabelAddressFixer final : public WithGuards {
254                std::set< Label > labels;
255
256                void premutate( FunctionDecl * funcDecl );
257                Expression * postmutate( AddressExpr * addrExpr );
258        };
259
260        FunctionDecl * dereferenceOperator = nullptr;
261        struct FindSpecialDeclarations final {
262                void previsit( FunctionDecl * funcDecl );
263        };
264
265        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
266                PassVisitor<EnumAndPointerDecay> epc;
267                PassVisitor<LinkReferenceToTypes> lrt( nullptr );
268                PassVisitor<ForallPointerDecay> fpd;
269                PassVisitor<CompoundLiteral> compoundliteral;
270                PassVisitor<ValidateGenericParameters> genericParams;
271                PassVisitor<FindSpecialDeclarations> finder;
272                PassVisitor<LabelAddressFixer> labelAddrFixer;
273
274                EliminateTypedef::eliminateTypedef( translationUnit );
275                HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
276                ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
277                acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes because it is an indexer and needs correct types for mangling
278                acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
279                acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes
280                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
281                ReturnChecker::checkFunctionReturns( translationUnit );
282                InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
283                Concurrency::applyKeywords( translationUnit );
284                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
285                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
286                Concurrency::implementMutexFuncs( translationUnit );
287                Concurrency::implementThreadStarter( translationUnit );
288                mutateAll( translationUnit, compoundliteral );
289                ArrayLength::computeLength( translationUnit );
290                acceptAll( translationUnit, finder ); // xxx - remove this pass soon
291                mutateAll( translationUnit, labelAddrFixer );
292        }
293
294        void validateType( Type *type, const Indexer *indexer ) {
295                PassVisitor<EnumAndPointerDecay> epc;
296                PassVisitor<LinkReferenceToTypes> lrt( indexer );
297                PassVisitor<ForallPointerDecay> fpd;
298                type->accept( epc );
299                type->accept( lrt );
300                type->accept( fpd );
301        }
302
303        void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
304                HoistStruct hoister;
305                acceptAndAdd( translationUnit, hoister );
306        }
307
308        HoistStruct::HoistStruct() : inStruct( false ) {
309        }
310
311        bool isStructOrUnion( Declaration *decl ) {
312                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
313        }
314
315        template< typename AggDecl >
316        void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
317                if ( inStruct ) {
318                        // Add elements in stack order corresponding to nesting structure.
319                        declsToAdd.push_front( aggregateDecl );
320                        Visitor::visit( aggregateDecl );
321                } else {
322                        inStruct = true;
323                        Visitor::visit( aggregateDecl );
324                        inStruct = false;
325                } // if
326                // Always remove the hoisted aggregate from the inner structure.
327                filter( aggregateDecl->get_members(), isStructOrUnion, false );
328        }
329
330        void HoistStruct::visit( EnumInstType *structInstType ) {
331                if ( structInstType->get_baseEnum() ) {
332                        declsToAdd.push_front( structInstType->get_baseEnum() );
333                }
334        }
335
336        void HoistStruct::visit( StructInstType *structInstType ) {
337                if ( structInstType->get_baseStruct() ) {
338                        declsToAdd.push_front( structInstType->get_baseStruct() );
339                }
340        }
341
342        void HoistStruct::visit( UnionInstType *structInstType ) {
343                if ( structInstType->get_baseUnion() ) {
344                        declsToAdd.push_front( structInstType->get_baseUnion() );
345                }
346        }
347
348        void HoistStruct::visit( StructDecl *aggregateDecl ) {
349                handleAggregate( aggregateDecl );
350        }
351
352        void HoistStruct::visit( UnionDecl *aggregateDecl ) {
353                handleAggregate( aggregateDecl );
354        }
355
356        void HoistStruct::visit( CompoundStmt *compoundStmt ) {
357                addVisit( compoundStmt, *this );
358        }
359
360        void HoistStruct::visit( SwitchStmt *switchStmt ) {
361                addVisit( switchStmt, *this );
362        }
363
364        void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
365                // Set the type of each member of the enumeration to be EnumConstant
366                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
367                        ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i );
368                        assert( obj );
369                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
370                } // for
371        }
372
373        namespace {
374                template< typename DWTList >
375                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
376                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
377                        // entirely. other fix ups are handled by the FixFunction class
378                        typedef typename DWTList::iterator DWTIterator;
379                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
380                        if ( begin == end ) return;
381                        PassVisitor<FixFunction> fixer;
382                        DWTIterator i = begin;
383                        *i = (*i)->acceptMutator( fixer );
384                        if ( fixer.pass.isVoid ) {
385                                DWTIterator j = i;
386                                ++i;
387                                delete *j;
388                                dwts.erase( j );
389                                if ( i != end ) {
390                                        throw SemanticError( "invalid type void in function type ", func );
391                                } // if
392                        } else {
393                                ++i;
394                                for ( ; i != end; ++i ) {
395                                        PassVisitor<FixFunction> fixer;
396                                        *i = (*i)->acceptMutator( fixer );
397                                        if ( fixer.pass.isVoid ) {
398                                                throw SemanticError( "invalid type void in function type ", func );
399                                        } // if
400                                } // for
401                        } // if
402                }
403        }
404
405        void EnumAndPointerDecay::previsit( FunctionType *func ) {
406                // Fix up parameters and return types
407                fixFunctionList( func->get_parameters(), func );
408                fixFunctionList( func->get_returnVals(), func );
409        }
410
411        LinkReferenceToTypes::LinkReferenceToTypes( const Indexer *other_indexer ) {
412                if ( other_indexer ) {
413                        local_indexer = other_indexer;
414                } else {
415                        local_indexer = &indexer;
416                } // if
417        }
418
419        void LinkReferenceToTypes::postvisit( EnumInstType *enumInst ) {
420                EnumDecl *st = local_indexer->lookupEnum( enumInst->get_name() );
421                // it's not a semantic error if the enum is not found, just an implicit forward declaration
422                if ( st ) {
423                        //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() );
424                        enumInst->set_baseEnum( st );
425                } // if
426                if ( ! st || st->get_members().empty() ) {
427                        // use of forward declaration
428                        forwardEnums[ enumInst->get_name() ].push_back( enumInst );
429                } // if
430        }
431
432        void checkGenericParameters( ReferenceToType * inst ) {
433                for ( Expression * param : inst->parameters ) {
434                        if ( ! dynamic_cast< TypeExpr * >( param ) ) {
435                                throw SemanticError( "Expression parameters for generic types are currently unsupported: ", inst );
436                        }
437                }
438        }
439
440        void LinkReferenceToTypes::postvisit( StructInstType *structInst ) {
441                StructDecl *st = local_indexer->lookupStruct( structInst->get_name() );
442                // it's not a semantic error if the struct is not found, just an implicit forward declaration
443                if ( st ) {
444                        //assert( ! structInst->get_baseStruct() || structInst->get_baseStruct()->get_members().empty() || ! st->get_members().empty() );
445                        structInst->set_baseStruct( st );
446                } // if
447                if ( ! st || st->get_members().empty() ) {
448                        // use of forward declaration
449                        forwardStructs[ structInst->get_name() ].push_back( structInst );
450                } // if
451                checkGenericParameters( structInst );
452        }
453
454        void LinkReferenceToTypes::postvisit( UnionInstType *unionInst ) {
455                UnionDecl *un = local_indexer->lookupUnion( unionInst->get_name() );
456                // it's not a semantic error if the union is not found, just an implicit forward declaration
457                if ( un ) {
458                        unionInst->set_baseUnion( un );
459                } // if
460                if ( ! un || un->get_members().empty() ) {
461                        // use of forward declaration
462                        forwardUnions[ unionInst->get_name() ].push_back( unionInst );
463                } // if
464                checkGenericParameters( unionInst );
465        }
466
467        template< typename Decl >
468        void normalizeAssertions( std::list< Decl * > & assertions ) {
469                // ensure no duplicate trait members after the clone
470                auto pred = [](Decl * d1, Decl * d2) {
471                        // only care if they're equal
472                        DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 );
473                        DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 );
474                        if ( dwt1 && dwt2 ) {
475                                if ( dwt1->get_name() == dwt2->get_name() && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) {
476                                        // std::cerr << "=========== equal:" << std::endl;
477                                        // std::cerr << "d1: " << d1 << std::endl;
478                                        // std::cerr << "d2: " << d2 << std::endl;
479                                        return false;
480                                }
481                        }
482                        return d1 < d2;
483                };
484                std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred );
485                // if ( unique_members.size() != assertions.size() ) {
486                //      std::cerr << "============different" << std::endl;
487                //      std::cerr << unique_members.size() << " " << assertions.size() << std::endl;
488                // }
489
490                std::list< Decl * > order;
491                order.splice( order.end(), assertions );
492                std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) {
493                        return unique_members.count( decl );
494                });
495        }
496
497        // expand assertions from trait instance, performing the appropriate type variable substitutions
498        template< typename Iterator >
499        void expandAssertions( TraitInstType * inst, Iterator out ) {
500                assertf( inst->baseTrait, "Trait instance not linked to base trait: %s", toString( inst ).c_str() );
501                std::list< DeclarationWithType * > asserts;
502                for ( Declaration * decl : inst->baseTrait->members ) {
503                        asserts.push_back( strict_dynamic_cast<DeclarationWithType *>( decl->clone() ) );
504                }
505                // substitute trait decl parameters for instance parameters
506                applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out );
507        }
508
509        void LinkReferenceToTypes::postvisit( TraitDecl * traitDecl ) {
510                if ( traitDecl->name == "sized" ) {
511                        // "sized" is a special trait - flick the sized status on for the type variable
512                        assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() );
513                        TypeDecl * td = traitDecl->parameters.front();
514                        td->set_sized( true );
515                }
516
517                // move assertions from type parameters into the body of the trait
518                for ( TypeDecl * td : traitDecl->parameters ) {
519                        for ( DeclarationWithType * assert : td->assertions ) {
520                                if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) {
521                                        expandAssertions( inst, back_inserter( traitDecl->members ) );
522                                } else {
523                                        traitDecl->members.push_back( assert->clone() );
524                                }
525                        }
526                        deleteAll( td->assertions );
527                        td->assertions.clear();
528                } // for
529        }
530
531        void LinkReferenceToTypes::postvisit( TraitInstType * traitInst ) {
532                // handle other traits
533                TraitDecl *traitDecl = local_indexer->lookupTrait( traitInst->name );
534                if ( ! traitDecl ) {
535                        throw SemanticError( "use of undeclared trait " + traitInst->name );
536                } // if
537                if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) {
538                        throw SemanticError( "incorrect number of trait parameters: ", traitInst );
539                } // if
540                traitInst->baseTrait = traitDecl;
541
542                // need to carry over the 'sized' status of each decl in the instance
543                for ( auto p : group_iterate( traitDecl->get_parameters(), traitInst->get_parameters() ) ) {
544                        TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );
545                        if ( ! expr ) {
546                                throw SemanticError( "Expression parameters for trait instances are currently unsupported: ", std::get<1>(p) );
547                        }
548                        if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
549                                TypeDecl * formalDecl = std::get<0>(p);
550                                TypeDecl * instDecl = inst->get_baseType();
551                                if ( formalDecl->get_sized() ) instDecl->set_sized( true );
552                        }
553                }
554                // normalizeAssertions( traitInst->members );
555        }
556
557        void LinkReferenceToTypes::postvisit( EnumDecl *enumDecl ) {
558                // visit enum members first so that the types of self-referencing members are updated properly
559                if ( ! enumDecl->get_members().empty() ) {
560                        ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() );
561                        if ( fwds != forwardEnums.end() ) {
562                                for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
563                                        (*inst )->set_baseEnum( enumDecl );
564                                } // for
565                                forwardEnums.erase( fwds );
566                        } // if
567                } // if
568        }
569
570        void LinkReferenceToTypes::renameGenericParams( std::list< TypeDecl * > & params ) {
571                // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.
572                //   forall(otype T)
573                //   struct Box {
574                //     T x;
575                //   };
576                //   forall(otype T)
577                //   void f(Box(T) b) {
578                //     ...
579                //   }
580                // The T in Box and the T in f are different, so internally the naming must reflect that.
581                GuardValue( inGeneric );
582                inGeneric = ! params.empty();
583                for ( TypeDecl * td : params ) {
584                        td->name = "__" + td->name + "_generic_";
585                }
586        }
587
588        void LinkReferenceToTypes::previsit( StructDecl * structDecl ) {
589                renameGenericParams( structDecl->parameters );
590        }
591
592        void LinkReferenceToTypes::previsit( UnionDecl * unionDecl ) {
593                renameGenericParams( unionDecl->parameters );
594        }
595
596        void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) {
597                // visit struct members first so that the types of self-referencing members are updated properly
598                // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)
599                if ( ! structDecl->get_members().empty() ) {
600                        ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->get_name() );
601                        if ( fwds != forwardStructs.end() ) {
602                                for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
603                                        (*inst )->set_baseStruct( structDecl );
604                                } // for
605                                forwardStructs.erase( fwds );
606                        } // if
607                } // if
608        }
609
610        void LinkReferenceToTypes::postvisit( UnionDecl *unionDecl ) {
611                if ( ! unionDecl->get_members().empty() ) {
612                        ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->get_name() );
613                        if ( fwds != forwardUnions.end() ) {
614                                for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
615                                        (*inst )->set_baseUnion( unionDecl );
616                                } // for
617                                forwardUnions.erase( fwds );
618                        } // if
619                } // if
620        }
621
622        void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) {
623                // ensure generic parameter instances are renamed like the base type
624                if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;
625                if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) {
626                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
627                                typeInst->set_isFtype( typeDecl->get_kind() == TypeDecl::Ftype );
628                        } // if
629                } // if
630        }
631
632        /// Fix up assertions - flattens assertion lists, removing all trait instances
633        void forallFixer( std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {
634                for ( TypeDecl * type : forall ) {
635                        std::list< DeclarationWithType * > asserts;
636                        asserts.splice( asserts.end(), type->assertions );
637                        // expand trait instances into their members
638                        for ( DeclarationWithType * assertion : asserts ) {
639                                if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
640                                        // expand trait instance into all of its members
641                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
642                                        delete traitInst;
643                                } else {
644                                        // pass other assertions through
645                                        type->assertions.push_back( assertion );
646                                } // if
647                        } // for
648                        // apply FixFunction to every assertion to check for invalid void type
649                        for ( DeclarationWithType *& assertion : type->assertions ) {
650                                PassVisitor<FixFunction> fixer;
651                                assertion = assertion->acceptMutator( fixer );
652                                if ( fixer.pass.isVoid ) {
653                                        throw SemanticError( "invalid type void in assertion of function ", node );
654                                } // if
655                        } // for
656                        // normalizeAssertions( type->assertions );
657                } // for
658        }
659
660        void ForallPointerDecay::previsit( ObjectDecl *object ) {
661                forallFixer( object->type->forall, object );
662                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->type ) ) {
663                        forallFixer( pointer->base->forall, object );
664                } // if
665                object->fixUniqueId();
666        }
667
668        void ForallPointerDecay::previsit( FunctionDecl *func ) {
669                forallFixer( func->type->forall, func );
670                func->fixUniqueId();
671        }
672
673        void ForallPointerDecay::previsit( StructDecl * aggrDecl ) {
674                forallFixer( aggrDecl->parameters, aggrDecl );
675        }
676
677        void ForallPointerDecay::previsit( UnionDecl * aggrDecl ) {
678                forallFixer( aggrDecl->parameters, aggrDecl );
679        }
680
681        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
682                PassVisitor<ReturnChecker> checker;
683                acceptAll( translationUnit, checker );
684        }
685
686        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
687                GuardValue( returnVals );
688                returnVals = functionDecl->get_functionType()->get_returnVals();
689        }
690
691        void ReturnChecker::previsit( ReturnStmt * returnStmt ) {
692                // Previously this also checked for the existence of an expr paired with no return values on
693                // the  function return type. This is incorrect, since you can have an expression attached to
694                // a return statement in a void-returning function in C. The expression is treated as if it
695                // were cast to void.
696                if ( ! returnStmt->get_expr() && returnVals.size() != 0 ) {
697                        throw SemanticError( "Non-void function returns no values: " , returnStmt );
698                }
699        }
700
701
702        bool isTypedef( Declaration *decl ) {
703                return dynamic_cast< TypedefDecl * >( decl );
704        }
705
706        void EliminateTypedef::eliminateTypedef( std::list< Declaration * > &translationUnit ) {
707                PassVisitor<EliminateTypedef> eliminator;
708                mutateAll( translationUnit, eliminator );
709                if ( eliminator.pass.typedefNames.count( "size_t" ) ) {
710                        // grab and remember declaration of size_t
711                        SizeType = eliminator.pass.typedefNames["size_t"].first->get_base()->clone();
712                } else {
713                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
714                        // eventually should have a warning for this case.
715                        SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
716                }
717                filter( translationUnit, isTypedef, true );
718        }
719
720        Type * EliminateTypedef::postmutate( TypeInstType * typeInst ) {
721                // instances of typedef types will come here. If it is an instance
722                // of a typdef type, link the instance to its actual type.
723                TypedefMap::const_iterator def = typedefNames.find( typeInst->get_name() );
724                if ( def != typedefNames.end() ) {
725                        Type *ret = def->second.first->base->clone();
726                        ret->get_qualifiers() |= typeInst->get_qualifiers();
727                        // place instance parameters on the typedef'd type
728                        if ( ! typeInst->parameters.empty() ) {
729                                ReferenceToType *rtt = dynamic_cast<ReferenceToType*>(ret);
730                                if ( ! rtt ) {
731                                        throw SemanticError("Cannot apply type parameters to base type of " + typeInst->name);
732                                }
733                                rtt->get_parameters().clear();
734                                cloneAll( typeInst->parameters, rtt->parameters );
735                                mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
736                        } // if
737                        delete typeInst;
738                        return ret;
739                } else {
740                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
741                        assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->name.c_str() );
742                        typeInst->set_baseType( base->second );
743                } // if
744                return typeInst;
745        }
746
747        struct VarLenChecker : WithShortCircuiting {
748                void previsit( FunctionType * ) { visit_children = false; }
749                void previsit( ArrayType * at ) {
750                        isVarLen |= at->isVarLen;
751                }
752                bool isVarLen = false;
753        };
754
755        bool isVariableLength( Type * t ) {
756                PassVisitor<VarLenChecker> varLenChecker;
757                maybeAccept( t, varLenChecker );
758                return varLenChecker.pass.isVarLen;
759        }
760
761        Declaration *EliminateTypedef::postmutate( TypedefDecl * tyDecl ) {
762                if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
763                        // typedef to the same name from the same scope
764                        // must be from the same type
765
766                        Type * t1 = tyDecl->get_base();
767                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
768                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
769                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
770                        }
771                        // cannot redefine VLA typedefs
772                        if ( isVariableLength( t1 ) || isVariableLength( t2 ) ) {
773                                throw SemanticError( "Cannot redefine typedef: " + tyDecl->name );
774                        }
775                } else {
776                        typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );
777                } // if
778
779                // When a typedef is a forward declaration:
780                //    typedef struct screen SCREEN;
781                // the declaration portion must be retained:
782                //    struct screen;
783                // because the expansion of the typedef is:
784                //    void rtn( SCREEN *p ) => void rtn( struct screen *p )
785                // hence the type-name "screen" must be defined.
786                // Note, qualifiers on the typedef are superfluous for the forward declaration.
787
788                Type *designatorType = tyDecl->get_base()->stripDeclarator();
789                if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
790                        return new StructDecl( aggDecl->get_name(), DeclarationNode::Struct, noAttributes, tyDecl->get_linkage() );
791                } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
792                        return new UnionDecl( aggDecl->get_name(), noAttributes, tyDecl->get_linkage() );
793                } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
794                        return new EnumDecl( enumDecl->get_name(), noAttributes, tyDecl->get_linkage() );
795                } else {
796                        return tyDecl->clone();
797                } // if
798        }
799
800        void EliminateTypedef::premutate( TypeDecl * typeDecl ) {
801                TypedefMap::iterator i = typedefNames.find( typeDecl->get_name() );
802                if ( i != typedefNames.end() ) {
803                        typedefNames.erase( i ) ;
804                } // if
805
806                typedeclNames[ typeDecl->get_name() ] = typeDecl;
807        }
808
809        void EliminateTypedef::premutate( FunctionDecl * ) {
810                GuardScope( typedefNames );
811        }
812
813        void EliminateTypedef::premutate( ObjectDecl * ) {
814                GuardScope( typedefNames );
815        }
816
817        DeclarationWithType *EliminateTypedef::postmutate( ObjectDecl * objDecl ) {
818                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->get_type() ) ) { // function type?
819                        // replace the current object declaration with a function declaration
820                        FunctionDecl * newDecl = new FunctionDecl( objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() );
821                        objDecl->get_attributes().clear();
822                        objDecl->set_type( nullptr );
823                        delete objDecl;
824                        return newDecl;
825                } // if
826                return objDecl;
827        }
828
829        void EliminateTypedef::premutate( CastExpr * ) {
830                GuardScope( typedefNames );
831        }
832
833        void EliminateTypedef::premutate( CompoundStmt * ) {
834                GuardScope( typedefNames );
835                scopeLevel += 1;
836                GuardAction( [this](){ scopeLevel -= 1; } );
837        }
838
839        CompoundStmt *EliminateTypedef::postmutate( CompoundStmt * compoundStmt ) {
840                // remove and delete decl stmts
841                filter( compoundStmt->kids, [](Statement * stmt) {
842                        if ( DeclStmt *declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
843                                if ( dynamic_cast< TypedefDecl * >( declStmt->get_decl() ) ) {
844                                        return true;
845                                } // if
846                        } // if
847                        return false;
848                }, true);
849                return compoundStmt;
850        }
851
852        // there may be typedefs nested within aggregates. in order for everything to work properly, these should be removed
853        // as well
854        template<typename AggDecl>
855        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
856                filter( aggDecl->members, isTypedef, true );
857                return aggDecl;
858        }
859
860        template<typename AggDecl>
861        void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
862                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
863                        Type *type = nullptr;
864                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
865                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
866                        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) {
867                                type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() );
868                        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl )  ) {
869                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
870                        } // if
871                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type, aggDecl->get_linkage() ) );
872                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
873                } // if
874        }
875
876        void EliminateTypedef::premutate( StructDecl * structDecl ) {
877                addImplicitTypedef( structDecl );
878        }
879
880
881        Declaration *EliminateTypedef::postmutate( StructDecl * structDecl ) {
882                return handleAggregate( structDecl );
883        }
884
885        void EliminateTypedef::premutate( UnionDecl * unionDecl ) {
886                addImplicitTypedef( unionDecl );
887        }
888
889        Declaration *EliminateTypedef::postmutate( UnionDecl * unionDecl ) {
890                return handleAggregate( unionDecl );
891        }
892
893        void EliminateTypedef::premutate( EnumDecl * enumDecl ) {
894                addImplicitTypedef( enumDecl );
895        }
896
897        Declaration *EliminateTypedef::postmutate( EnumDecl * enumDecl ) {
898                return handleAggregate( enumDecl );
899        }
900
901        Declaration *EliminateTypedef::postmutate( TraitDecl * traitDecl ) {
902                return handleAggregate( traitDecl );
903        }
904
905        void VerifyCtorDtorAssign::verify( std::list< Declaration * > & translationUnit ) {
906                PassVisitor<VerifyCtorDtorAssign> verifier;
907                acceptAll( translationUnit, verifier );
908        }
909
910        void VerifyCtorDtorAssign::previsit( FunctionDecl * funcDecl ) {
911                FunctionType * funcType = funcDecl->get_functionType();
912                std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
913                std::list< DeclarationWithType * > &params = funcType->get_parameters();
914
915                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
916                        if ( params.size() == 0 ) {
917                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
918                        }
919                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
920                        if ( ! refType ) {
921                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a reference ", funcDecl );
922                        }
923                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
924                                throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
925                        }
926                }
927        }
928
929        template< typename Aggr >
930        void validateGeneric( Aggr * inst ) {
931                std::list< TypeDecl * > * params = inst->get_baseParameters();
932                if ( params ) {
933                        std::list< Expression * > & args = inst->get_parameters();
934
935                        // insert defaults arguments when a type argument is missing (currently only supports missing arguments at the end of the list).
936                        // A substitution is used to ensure that defaults are replaced correctly, e.g.,
937                        //   forall(otype T, otype alloc = heap_allocator(T)) struct vector;
938                        //   vector(int) v;
939                        // after insertion of default values becomes
940                        //   vector(int, heap_allocator(T))
941                        // and the substitution is built with T=int so that after substitution, the result is
942                        //   vector(int, heap_allocator(int))
943                        TypeSubstitution sub;
944                        auto paramIter = params->begin();
945                        for ( size_t i = 0; paramIter != params->end(); ++paramIter, ++i ) {
946                                if ( i < args.size() ) {
947                                        TypeExpr * expr = strict_dynamic_cast< TypeExpr * >( *std::next( args.begin(), i ) );
948                                        sub.add( (*paramIter)->get_name(), expr->get_type()->clone() );
949                                } else if ( i == args.size() ) {
950                                        Type * defaultType = (*paramIter)->get_init();
951                                        if ( defaultType ) {
952                                                args.push_back( new TypeExpr( defaultType->clone() ) );
953                                                sub.add( (*paramIter)->get_name(), defaultType->clone() );
954                                        }
955                                }
956                        }
957
958                        sub.apply( inst );
959                        if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
960                        if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
961                }
962        }
963
964        void ValidateGenericParameters::previsit( StructInstType * inst ) {
965                validateGeneric( inst );
966        }
967
968        void ValidateGenericParameters::previsit( UnionInstType * inst ) {
969                validateGeneric( inst );
970        }
971
972        void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {
973                storageClasses = objectDecl->get_storageClasses();
974        }
975
976        Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) {
977                // transform [storage_class] ... (struct S){ 3, ... };
978                // into [storage_class] struct S temp =  { 3, ... };
979                static UniqueName indexName( "_compLit" );
980
981                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
982                compLitExpr->set_result( nullptr );
983                compLitExpr->set_initializer( nullptr );
984                delete compLitExpr;
985                declsToAddBefore.push_back( tempvar );                                  // add modified temporary to current block
986                return new VariableExpr( tempvar );
987        }
988
989        void ReturnTypeFixer::fix( std::list< Declaration * > &translationUnit ) {
990                PassVisitor<ReturnTypeFixer> fixer;
991                acceptAll( translationUnit, fixer );
992        }
993
994        void ReturnTypeFixer::postvisit( FunctionDecl * functionDecl ) {
995                FunctionType * ftype = functionDecl->get_functionType();
996                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
997                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() );
998                if ( retVals.size() == 1 ) {
999                        // 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).
1000                        // ensure other return values have a name.
1001                        DeclarationWithType * ret = retVals.front();
1002                        if ( ret->get_name() == "" ) {
1003                                ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) );
1004                        }
1005                        ret->get_attributes().push_back( new Attribute( "unused" ) );
1006                }
1007        }
1008
1009        void ReturnTypeFixer::postvisit( FunctionType * ftype ) {
1010                // xxx - need to handle named return values - this information needs to be saved somehow
1011                // so that resolution has access to the names.
1012                // Note that this pass needs to happen early so that other passes which look for tuple types
1013                // find them in all of the right places, including function return types.
1014                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
1015                if ( retVals.size() > 1 ) {
1016                        // generate a single return parameter which is the tuple of all of the return values
1017                        TupleType * tupleType = strict_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) );
1018                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
1019                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
1020                        deleteAll( retVals );
1021                        retVals.clear();
1022                        retVals.push_back( newRet );
1023                }
1024        }
1025
1026        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
1027                PassVisitor<ArrayLength> len;
1028                acceptAll( translationUnit, len );
1029        }
1030
1031        void ArrayLength::previsit( ObjectDecl * objDecl ) {
1032                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
1033                        if ( at->get_dimension() ) return;
1034                        if ( ListInit * init = dynamic_cast< ListInit * >( objDecl->get_init() ) ) {
1035                                at->set_dimension( new ConstantExpr( Constant::from_ulong( init->get_initializers().size() ) ) );
1036                        }
1037                }
1038        }
1039
1040        struct LabelFinder {
1041                std::set< Label > & labels;
1042                LabelFinder( std::set< Label > & labels ) : labels( labels ) {}
1043                void previsit( Statement * stmt ) {
1044                        for ( Label & l : stmt->labels ) {
1045                                labels.insert( l );
1046                        }
1047                }
1048        };
1049
1050        void LabelAddressFixer::premutate( FunctionDecl * funcDecl ) {
1051                GuardValue( labels );
1052                PassVisitor<LabelFinder> finder( labels );
1053                funcDecl->accept( finder );
1054        }
1055
1056        Expression * LabelAddressFixer::postmutate( AddressExpr * addrExpr ) {
1057                // convert &&label into label address
1058                if ( AddressExpr * inner = dynamic_cast< AddressExpr * >( addrExpr->arg ) ) {
1059                        if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) {
1060                                if ( labels.count( nameExpr->name ) ) {
1061                                        Label name = nameExpr->name;
1062                                        delete addrExpr;
1063                                        return new LabelAddressExpr( name );
1064                                }
1065                        }
1066                }
1067                return addrExpr;
1068        }
1069
1070        void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
1071                if ( ! dereferenceOperator ) {
1072                        if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
1073                                FunctionType * ftype = funcDecl->get_functionType();
1074                                if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
1075                                        dereferenceOperator = funcDecl;
1076                                }
1077                        }
1078                }
1079        }
1080} // namespace SymTab
1081
1082// Local Variables: //
1083// tab-width: 4 //
1084// mode: c++ //
1085// compile-command: "make install" //
1086// End: //
Note: See TracBrowser for help on using the repository browser.