Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rbe9288a rb128d3e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Aug  8 13:27:00 2017
    13 // Update Count     : 358
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Aug 28 13:47:23 2017
     13// Update Count     : 359
    1414//
    1515
     
    4747
    4848#include "CodeGen/CodeGenerator.h"     // for genName
     49#include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
    4950#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    5051#include "Common/ScopedMap.h"          // for ScopedMap
     
    239240        };
    240241
     242
     243        FunctionDecl * dereferenceOperator = nullptr;
     244        struct FindSpecialDeclarations final {
     245                void previsit( FunctionDecl * funcDecl );
     246        };
     247
    241248        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    242249                PassVisitor<EnumAndPointerDecay> epc;
     
    245252                PassVisitor<CompoundLiteral> compoundliteral;
    246253                PassVisitor<ValidateGenericParameters> genericParams;
     254                PassVisitor<FindSpecialDeclarations> finder;
    247255
    248256                EliminateTypedef::eliminateTypedef( translationUnit );
     
    261269                acceptAll( translationUnit, fpd );
    262270                ArrayLength::computeLength( translationUnit );
     271                acceptAll( translationUnit, finder );
    263272        }
    264273
     
    458467                        return;
    459468                }
     469
     470                // handle other traits
    460471                TraitDecl *traitDecl = indexer->lookupTrait( traitInst->get_name() );
    461472                if ( ! traitDecl ) {
     
    653664                } else {
    654665                        TypeDeclMap::const_iterator base = typedeclNames.find( typeInst->get_name() );
    655                         assertf( base != typedeclNames.end(), "Can't find typedecl name %s", typeInst->get_name().c_str() );
     666                        assertf( base != typedeclNames.end(), "Cannot find typedecl name %s", typeInst->get_name().c_str() );
    656667                        typeInst->set_baseType( base->second );
    657668                } // if
     
    821832                std::list< DeclarationWithType * > &params = funcType->get_parameters();
    822833
    823                 if ( InitTweak::isCtorDtorAssign( funcDecl->get_name() ) ) {
     834                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    824835                        if ( params.size() == 0 ) {
    825836                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
    826837                        }
    827                         PointerType * ptrType = dynamic_cast< PointerType * >( params.front()->get_type() );
    828                         if ( ! ptrType || ptrType->is_array() ) {
    829                                 throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl );
     838                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
     839                        if ( ! refType ) {
     840                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a reference ", funcDecl );
    830841                        }
    831                         if ( InitTweak::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
     842                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    832843                                throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
    833844                        }
     
    945956                }
    946957        }
     958
     959        void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
     960                if ( ! dereferenceOperator ) {
     961                        if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
     962                                FunctionType * ftype = funcDecl->get_functionType();
     963                                if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
     964                                        dereferenceOperator = funcDecl;
     965                                }
     966                        }
     967                }
     968        }
    947969} // namespace SymTab
    948970
Note: See TracChangeset for help on using the changeset viewer.