Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r09867ec r095b99a  
    6464#include "Common/UniqueName.h"         // for UniqueName
    6565#include "Common/utility.h"            // for operator+, cloneAll, deleteAll
    66 #include "CompilationState.h"          // skip some passes in new-ast build
    6766#include "Concurrency/Keywords.h"      // for applyKeywords
    6867#include "FixFunction.h"               // for FixFunction
     
    271270        };
    272271
    273         struct InitializerLength {
     272        struct ArrayLength : public WithIndexer {
    274273                /// for array types without an explicit length, compute the length and store it so that it
    275274                /// is known to the rest of the phases. For example,
     
    282281
    283282                void previsit( ObjectDecl * objDecl );
    284         };
    285 
    286         struct ArrayLength : public WithIndexer {
    287                 static void computeLength( std::list< Declaration * > & translationUnit );
    288 
    289283                void previsit( ArrayType * arrayType );
    290284        };
     
    317311                        Stats::Heap::newPass("validate-A");
    318312                        Stats::Time::BlockGuard guard("validate-A");
    319                         VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    320313                        acceptAll( translationUnit, hoistDecls );
    321314                        ReplaceTypedef::replaceTypedef( translationUnit );
     
    343336                        Stats::Time::BlockGuard guard("validate-C");
    344337                        acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes_old
     338                        VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    345339                        ReturnChecker::checkFunctionReturns( translationUnit );
    346340                        InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen
     
    374368                                mutateAll( translationUnit, compoundliteral );
    375369                        });
    376                         if (!useNewAST) {
    377                                 Stats::Time::TimeBlock("Resolve With Expressions", [&]() {
    378                                         ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
    379                                 });
    380                         }
     370                        Stats::Time::TimeBlock("Resolve With Expressions", [&]() {
     371                                ResolvExpr::resolveWithExprs( translationUnit ); // must happen before FixObjectType because user-code is resolved and may contain with variables
     372                        });
    381373                }
    382374                {
    383375                        Stats::Heap::newPass("validate-F");
    384376                        Stats::Time::BlockGuard guard("validate-F");
    385                         if (!useNewAST) {
    386                                 Stats::Time::TimeCall("Fix Object Type",
    387                                         FixObjectType::fix, translationUnit);
    388                         }
    389                         Stats::Time::TimeCall("Initializer Length",
    390                                 InitializerLength::computeLength, translationUnit);
    391                         if (!useNewAST) {
    392                                 Stats::Time::TimeCall("Array Length",
    393                                         ArrayLength::computeLength, translationUnit);
    394                         }
     377                        Stats::Time::TimeCall("Fix Object Type",
     378                                FixObjectType::fix, translationUnit);
     379                        Stats::Time::TimeCall("Array Length",
     380                                ArrayLength::computeLength, translationUnit);
    395381                        Stats::Time::TimeCall("Find Special Declarations",
    396382                                Validate::findSpecialDecls, translationUnit);
    397383                        Stats::Time::TimeCall("Fix Label Address",
    398384                                mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer);
    399                         if (!useNewAST) {
    400                                 Stats::Time::TimeCall("Handle Attributes",
    401                                         Validate::handleAttributes, translationUnit);
    402                         }
     385                        Stats::Time::TimeCall("Handle Attributes",
     386                                Validate::handleAttributes, translationUnit);
    403387                }
    404388        }
     
    976960        }
    977961
    978         static bool isNonParameterAttribute( Attribute * attr ) {
    979                 static const std::vector<std::string> bad_names = {
    980                         "aligned", "__aligned__",
    981                 };
    982                 for ( auto name : bad_names ) {
    983                         if ( name == attr->name ) {
    984                                 return true;
    985                         }
    986                 }
    987                 return false;
    988         }
    989 
    990962        Type * ReplaceTypedef::postmutate( TypeInstType * typeInst ) {
    991963                // instances of typedef types will come here. If it is an instance
     
    996968                        ret->location = typeInst->location;
    997969                        ret->get_qualifiers() |= typeInst->get_qualifiers();
    998                         // GCC ignores certain attributes if they arrive by typedef, this mimics that.
    999                         if ( inFunctionType ) {
    1000                                 ret->attributes.remove_if( isNonParameterAttribute );
    1001                         }
    1002                         ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
     970                        // attributes are not carried over from typedef to function parameters/return values
     971                        if ( ! inFunctionType ) {
     972                                ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
     973                        } else {
     974                                deleteAll( ret->attributes );
     975                                ret->attributes.clear();
     976                        }
    1003977                        // place instance parameters on the typedef'd type
    1004978                        if ( ! typeInst->parameters.empty() ) {
     
    12081182                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    12091183                        if ( params.size() == 0 ) {
    1210                                 SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." );
     1184                                SemanticError( funcDecl, "Constructors, destructors, and assignment functions require at least one parameter " );
    12111185                        }
    12121186                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
    12131187                        if ( ! refType ) {
    1214                                 SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." );
     1188                                SemanticError( funcDecl, "First parameter of a constructor, destructor, or assignment function must be a reference " );
    12151189                        }
    12161190                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    1217                                 if(!returnVals.front()->get_type()->isVoid()) {
    1218                                         SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." );
    1219                                 }
     1191                                SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " );
    12201192                        }
    12211193                }
     
    13411313        }
    13421314
    1343         void InitializerLength::computeLength( std::list< Declaration * > & translationUnit ) {
    1344                 PassVisitor<InitializerLength> len;
    1345                 acceptAll( translationUnit, len );
    1346         }
    1347 
    13481315        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    13491316                PassVisitor<ArrayLength> len;
     
    13511318        }
    13521319
    1353         void InitializerLength::previsit( ObjectDecl * objDecl ) {
     1320        void ArrayLength::previsit( ObjectDecl * objDecl ) {
    13541321                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->type ) ) {
    13551322                        if ( at->dimension ) return;
     
    14051372        /// Replaces enum types by int, and function/array types in function parameter and return
    14061373        /// lists by appropriate pointers
    1407         /*
    14081374        struct EnumAndPointerDecay_new {
    14091375                const ast::EnumDecl * previsit( const ast::EnumDecl * enumDecl ) {
     
    14561422                }
    14571423        };
    1458         */
    14591424
    14601425        /// expand assertions from a trait instance, performing appropriate type variable substitutions
     
    14751440        }
    14761441
    1477         /*
    1478 
    14791442        /// Associates forward declarations of aggregates with their definitions
    14801443        class LinkReferenceToTypes_new final
     
    15431506                }
    15441507
    1545                 void checkGenericParameters( const ast::BaseInstType * inst ) {
     1508                void checkGenericParameters( const ast::ReferenceToType * inst ) {
    15461509                        for ( const ast::Expr * param : inst->params ) {
    15471510                                if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) {
     
    18071770                static const node_t * forallFixer(
    18081771                        const CodeLocation & loc, const node_t * node,
    1809                         ast::FunctionType::ForallList parent_t::* forallField
     1772                        ast::ParameterizedType::ForallList parent_t::* forallField
    18101773                ) {
    18111774                        for ( unsigned i = 0; i < (node->* forallField).size(); ++i ) {
     
    18581821                }
    18591822        };
    1860         */
    18611823} // anonymous namespace
    18621824
    1863 /*
    18641825const ast::Type * validateType(
    18651826                const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab ) {
    1866         // ast::Pass< EnumAndPointerDecay_new > epc;
     1827        ast::Pass< EnumAndPointerDecay_new > epc;
    18671828        ast::Pass< LinkReferenceToTypes_new > lrt{ loc, symtab };
    18681829        ast::Pass< ForallPointerDecay_new > fpd{ loc };
    18691830
    1870         return type->accept( lrt )->accept( fpd );
     1831        return type->accept( epc )->accept( lrt )->accept( fpd );
    18711832}
    1872 */
    18731833
    18741834} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.