Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r4559b34 r7c919559  
    194194        };
    195195
     196        // These structs are the sub-sub-passes of ForallPointerDecay_old.
     197
     198        struct TraitExpander_old final {
     199                void previsit( FunctionType * );
     200                void previsit( StructDecl * );
     201                void previsit( UnionDecl * );
     202        };
     203
     204        struct AssertionFixer_old final {
     205                void previsit( FunctionType * );
     206                void previsit( StructDecl * );
     207                void previsit( UnionDecl * );
     208        };
     209
     210        struct CheckOperatorTypes_old final {
     211                void previsit( ObjectDecl * );
     212        };
     213
     214        struct FixUniqueIds_old final {
     215                void previsit( DeclarationWithType * );
     216        };
     217
    196218        struct ReturnChecker : public WithGuards {
    197219                /// Checks that return statements return nothing if their return type is void
     
    373395                                TranslateDimensionGenericParameters::translateDimensions( translationUnit );
    374396                        });
     397                        if (!useNewAST) {
    375398                        Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() {
    376399                                acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling
    377400                        });
     401                        }
    378402                        Stats::Time::TimeBlock("Check Function Returns", [&]() {
    379403                                ReturnChecker::checkFunctionReturns( translationUnit );
     
    385409        }
    386410
     411        static void decayForallPointers( std::list< Declaration * > & translationUnit ) {
     412                PassVisitor<TraitExpander_old> te;
     413                acceptAll( translationUnit, te );
     414                PassVisitor<AssertionFixer_old> af;
     415                acceptAll( translationUnit, af );
     416                PassVisitor<CheckOperatorTypes_old> cot;
     417                acceptAll( translationUnit, cot );
     418                PassVisitor<FixUniqueIds_old> fui;
     419                acceptAll( translationUnit, fui );
     420        }
     421
    387422        void validate_D( std::list< Declaration * > & translationUnit ) {
    388                 PassVisitor<ForallPointerDecay_old> fpd;
    389423                {
    390424                        Stats::Heap::newPass("validate-D");
     
    394428                        });
    395429                        Stats::Time::TimeBlock("Forall Pointer Decay", [&]() {
    396                                 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
     430                                decayForallPointers( translationUnit ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
    397431                        });
    398432                        Stats::Time::TimeBlock("Hoist Control Declarations", [&]() {
     
    453487        }
    454488
    455         void decayForallPointers( std::list< Declaration * > & translationUnit ) {
    456                 PassVisitor<ForallPointerDecay_old> fpd;
    457                 acceptAll( translationUnit, fpd );
    458         }
    459 
    460489        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    461490                validate_A( translationUnit );
     
    470499                PassVisitor<EnumAndPointerDecay_old> epc;
    471500                PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
    472                 PassVisitor<ForallPointerDecay_old> fpd;
     501                PassVisitor<TraitExpander_old> te;
     502                PassVisitor<AssertionFixer_old> af;
     503                PassVisitor<CheckOperatorTypes_old> cot;
     504                PassVisitor<FixUniqueIds_old> fui;
    473505                type->accept( epc );
    474506                type->accept( lrt );
    475                 type->accept( fpd );
     507                type->accept( te );
     508                type->accept( af );
     509                type->accept( cot );
     510                type->accept( fui );
    476511        }
    477512
     
    939974                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
    940975                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
    941                                         if ( !enumDecl->base || dynamic_cast<BasicType *>(enumDecl->base))
    942                                                 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
    943                                         else {
    944                                                 if (dynamic_cast<PointerType *>(enumDecl->base)) {
    945                                                         auto typePtr = dynamic_cast<PointerType *>(enumDecl->base);
    946                                                         ResolvExpr::findSingleExpression( init->value,
    947                                                          new PointerType( Type::Qualifiers(), typePtr->base ), indexer );
    948                                                 } else {
    949                                                         ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
    950                                                 }
    951                                         }
    952                                        
     976                                        ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
    953977                                }
    954978                        }
    955 
    956979                } // if
    957980        }
     
    9841007        }
    9851008
     1009        /// Replace all traits in assertion lists with their assertions.
     1010        void expandTraits( std::list< TypeDecl * > & forall ) {
     1011                for ( TypeDecl * type : forall ) {
     1012                        std::list< DeclarationWithType * > asserts;
     1013                        asserts.splice( asserts.end(), type->assertions );
     1014                        // expand trait instances into their members
     1015                        for ( DeclarationWithType * assertion : asserts ) {
     1016                                if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
     1017                                        // expand trait instance into all of its members
     1018                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     1019                                        delete traitInst;
     1020                                } else {
     1021                                        // pass other assertions through
     1022                                        type->assertions.push_back( assertion );
     1023                                } // if
     1024                        } // for
     1025                }
     1026        }
     1027
     1028        /// Fix each function in the assertion list and check for invalid void type.
     1029        void fixAssertions(
     1030                        std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {
     1031                for ( TypeDecl * type : forall ) {
     1032                        for ( DeclarationWithType *& assertion : type->assertions ) {
     1033                                bool isVoid = fixFunction( assertion );
     1034                                if ( isVoid ) {
     1035                                        SemanticError( node, "invalid type void in assertion of function " );
     1036                                } // if
     1037                        } // for
     1038                }
     1039        }
     1040
    9861041        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    9871042                // ensure that operator names only apply to functions or function pointers
     
    10061061        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    10071062                forallFixer( aggrDecl->parameters, aggrDecl );
     1063        }
     1064
     1065        void TraitExpander_old::previsit( FunctionType * ftype ) {
     1066                expandTraits( ftype->forall );
     1067        }
     1068
     1069        void TraitExpander_old::previsit( StructDecl * aggrDecl ) {
     1070                expandTraits( aggrDecl->parameters );
     1071        }
     1072
     1073        void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {
     1074                expandTraits( aggrDecl->parameters );
     1075        }
     1076
     1077        void AssertionFixer_old::previsit( FunctionType * ftype ) {
     1078                fixAssertions( ftype->forall, ftype );
     1079        }
     1080
     1081        void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {
     1082                fixAssertions( aggrDecl->parameters, aggrDecl );
     1083        }
     1084
     1085        void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {
     1086                fixAssertions( aggrDecl->parameters, aggrDecl );
     1087        }
     1088
     1089        void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {
     1090                // ensure that operator names only apply to functions or function pointers
     1091                if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
     1092                        SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
     1093                }
     1094        }
     1095
     1096        void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {
     1097                decl->fixUniqueId();
    10081098        }
    10091099
     
    11501240                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    11511241                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    1152                         // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
    1153                         if (enumDecl->baseEnum) {
    1154                                 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
    1155                         } else {
    1156                                 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
    1157                         }
     1242                        declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
    11581243                } // if
    11591244                return tyDecl->clone();
Note: See TracChangeset for help on using the changeset viewer.