Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r7c919559 r4559b34  
    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 
    218196        struct ReturnChecker : public WithGuards {
    219197                /// Checks that return statements return nothing if their return type is void
     
    395373                                TranslateDimensionGenericParameters::translateDimensions( translationUnit );
    396374                        });
    397                         if (!useNewAST) {
    398375                        Stats::Time::TimeBlock("Resolve Enum Initializers", [&]() {
    399376                                acceptAll( translationUnit, rei ); // must happen after translateDimensions because rei needs identifier lookup, which needs name mangling
    400377                        });
    401                         }
    402378                        Stats::Time::TimeBlock("Check Function Returns", [&]() {
    403379                                ReturnChecker::checkFunctionReturns( translationUnit );
     
    409385        }
    410386
    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 
    422387        void validate_D( std::list< Declaration * > & translationUnit ) {
     388                PassVisitor<ForallPointerDecay_old> fpd;
    423389                {
    424390                        Stats::Heap::newPass("validate-D");
     
    428394                        });
    429395                        Stats::Time::TimeBlock("Forall Pointer Decay", [&]() {
    430                                 decayForallPointers( translationUnit ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
     396                                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
    431397                        });
    432398                        Stats::Time::TimeBlock("Hoist Control Declarations", [&]() {
     
    487453        }
    488454
     455        void decayForallPointers( std::list< Declaration * > & translationUnit ) {
     456                PassVisitor<ForallPointerDecay_old> fpd;
     457                acceptAll( translationUnit, fpd );
     458        }
     459
    489460        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    490461                validate_A( translationUnit );
     
    499470                PassVisitor<EnumAndPointerDecay_old> epc;
    500471                PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
    501                 PassVisitor<TraitExpander_old> te;
    502                 PassVisitor<AssertionFixer_old> af;
    503                 PassVisitor<CheckOperatorTypes_old> cot;
    504                 PassVisitor<FixUniqueIds_old> fui;
     472                PassVisitor<ForallPointerDecay_old> fpd;
    505473                type->accept( epc );
    506474                type->accept( lrt );
    507                 type->accept( te );
    508                 type->accept( af );
    509                 type->accept( cot );
    510                 type->accept( fui );
     475                type->accept( fpd );
    511476        }
    512477
     
    974939                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
    975940                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
    976                                         ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     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                                       
    977953                                }
    978954                        }
     955
    979956                } // if
    980957        }
     
    1007984        }
    1008985
    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 
    1041986        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    1042987                // ensure that operator names only apply to functions or function pointers
     
    10611006        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    10621007                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();
    10981008        }
    10991009
     
    12401150                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    12411151                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    1242                         declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
     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                        }
    12431158                } // if
    12441159                return tyDecl->clone();
Note: See TracChangeset for help on using the changeset viewer.