Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/ForallPointerDecay.cpp

    r14c0f7b r9feb34b  
    2323#include "Common/CodeLocation.h"
    2424#include "Common/ToString.hpp"
    25 #include "Common/utility.h"
    2625#include "SymTab/FixFunction.h"
     26
     27#include "AST/Print.hpp"
    2728
    2829namespace Validate {
     
    5051}
    5152
    52 ast::FunctionDecl * updateAssertions( ast::FunctionDecl * decl ) {
    53         auto type = ast::mutate( decl->type.get() );
    54         type->assertions.clear();
    55         type->assertions.reserve( decl->assertions.size() );
    56         for ( auto & assertion : decl->assertions ) {
    57                 type->assertions.emplace_back(
    58                         new ast::VariableExpr( decl->location, assertion ) );
    59         }
    60         decl->type = type;
    61         return decl;
     53template<typename T>
     54void append( std::vector<T> & dst, std::vector<T> & src ) {
     55        dst.reserve( dst.size() + src.size() );
     56        for ( auto el : src ) {
     57                dst.emplace_back( std::move( el ) );
     58        }
     59        src.clear();
    6260}
    6361
     
    9896                                        decl->get_type() ) ) {
    9997                                auto moreAsserts = expandTrait( traitInst );
    100                                 splice( assertions, moreAsserts );
     98                                append( assertions, moreAsserts );
    10199                        } else {
    102100                                assertions.push_back( decl );
     
    110108        static TypeDeclVec expandTypeDecls( const TypeDeclVec & old ) {
    111109                TypeDeclVec typeDecls;
    112                 typeDecls.reserve( old.size() );
    113110                for ( const ast::TypeDecl * typeDecl : old ) {
    114111                        typeDecls.push_back( ast::mutate_field( typeDecl,
     
    126123                mut->assertions = expandAssertions( decl->assertions );
    127124                // Update the assertion list on the type as well.
    128                 return updateAssertions( mut );
     125                auto mutType = ast::mutate( mut->type.get() );
     126                mutType->assertions.clear();
     127                for ( auto & assertion : mut->assertions ) {
     128                        mutType->assertions.emplace_back(
     129                                new ast::VariableExpr( mut->location, assertion ) );
     130                }
     131                mut->type = mutType;
     132                return mut;
    129133        }
    130134
     
    150154                const std::vector<ast::ptr<ast::DeclWithType>> & assertions ) {
    151155        std::vector<ast::ptr<ast::DeclWithType>> ret;
    152         ret.reserve( assertions.size() );
    153156        for ( const auto & assn : assertions ) {
    154157                bool isVoid = false;
     
    184187        }
    185188
    186         const ast::FunctionDecl * postvisit( const ast::FunctionDecl * decl ) {
    187                 if ( decl->assertions.empty() ) {
    188                         return decl;
    189                 }
    190                 return updateAssertions( mutate( decl ) );
    191         }
    192 
    193189        const ast::StructDecl * previsit( const ast::StructDecl * decl ) {
    194190                if ( decl->params.empty() ) {
     
    208204};
    209205
    210 struct OperatorChecker final {
     206struct OberatorChecker final {
    211207        void previsit( const ast::ObjectDecl * obj ) {
    212                 if ( !CodeGen::isOperator( obj->name ) ) return;
    213                 auto type = obj->type->stripDeclarator();
    214                 if ( dynamic_cast< const ast::FunctionType * >( type ) ) return;
    215                 SemanticError( obj->location,
    216                         toCString( "operator ", obj->name.c_str(),
    217                         " is not a function or function pointer." ) );
     208                if ( CodeGen::isOperator( obj->name ) ) {
     209                        auto type = obj->type->stripDeclarator();
     210                        if ( ! dynamic_cast< const ast::FunctionType * >( type ) ) {
     211                                SemanticError( obj->location,
     212                                        toCString( "operator ", obj->name.c_str(), " is not "
     213                                        "a function or function pointer." ) );
     214                        }
     215                }
    218216        }
    219217};
     
    236234        ast::Pass<TraitExpander>::run( transUnit );
    237235        ast::Pass<AssertionFunctionFixer>::run( transUnit );
    238         ast::Pass<OperatorChecker>::run( transUnit );
    239 }
    240 
    241 void fixUniqueIds( ast::TranslationUnit & transUnit ) {
     236        ast::Pass<OberatorChecker>::run( transUnit );
    242237        ast::Pass<UniqueFixCore>::run( transUnit );
    243238}
Note: See TracChangeset for help on using the changeset viewer.