Ignore:
Timestamp:
Apr 10, 2022, 2:53:18 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
d8e2a09
Parents:
4559b34 (diff), 6256891 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Resolve conflict

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r4559b34 r92538ab  
    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
     
    9841019        }
    9851020
     1021        /// Replace all traits in assertion lists with their assertions.
     1022        void expandTraits( std::list< TypeDecl * > & forall ) {
     1023                for ( TypeDecl * type : forall ) {
     1024                        std::list< DeclarationWithType * > asserts;
     1025                        asserts.splice( asserts.end(), type->assertions );
     1026                        // expand trait instances into their members
     1027                        for ( DeclarationWithType * assertion : asserts ) {
     1028                                if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
     1029                                        // expand trait instance into all of its members
     1030                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     1031                                        delete traitInst;
     1032                                } else {
     1033                                        // pass other assertions through
     1034                                        type->assertions.push_back( assertion );
     1035                                } // if
     1036                        } // for
     1037                }
     1038        }
     1039
     1040        /// Fix each function in the assertion list and check for invalid void type.
     1041        void fixAssertions(
     1042                        std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {
     1043                for ( TypeDecl * type : forall ) {
     1044                        for ( DeclarationWithType *& assertion : type->assertions ) {
     1045                                bool isVoid = fixFunction( assertion );
     1046                                if ( isVoid ) {
     1047                                        SemanticError( node, "invalid type void in assertion of function " );
     1048                                } // if
     1049                        } // for
     1050                }
     1051        }
     1052
    9861053        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    9871054                // ensure that operator names only apply to functions or function pointers
     
    10061073        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    10071074                forallFixer( aggrDecl->parameters, aggrDecl );
     1075        }
     1076
     1077        void TraitExpander_old::previsit( FunctionType * ftype ) {
     1078                expandTraits( ftype->forall );
     1079        }
     1080
     1081        void TraitExpander_old::previsit( StructDecl * aggrDecl ) {
     1082                expandTraits( aggrDecl->parameters );
     1083        }
     1084
     1085        void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {
     1086                expandTraits( aggrDecl->parameters );
     1087        }
     1088
     1089        void AssertionFixer_old::previsit( FunctionType * ftype ) {
     1090                fixAssertions( ftype->forall, ftype );
     1091        }
     1092
     1093        void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {
     1094                fixAssertions( aggrDecl->parameters, aggrDecl );
     1095        }
     1096
     1097        void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {
     1098                fixAssertions( aggrDecl->parameters, aggrDecl );
     1099        }
     1100
     1101        void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {
     1102                // ensure that operator names only apply to functions or function pointers
     1103                if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
     1104                        SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
     1105                }
     1106        }
     1107
     1108        void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {
     1109                decl->fixUniqueId();
    10081110        }
    10091111
Note: See TracChangeset for help on using the changeset viewer.