Ignore:
Timestamp:
Aug 25, 2017, 10:38:34 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
800d275
Parents:
af08051 (diff), 3eab308c (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    raf08051 r28e58fd  
    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
     
    821830                std::list< DeclarationWithType * > &params = funcType->get_parameters();
    822831
    823                 if ( InitTweak::isCtorDtorAssign( funcDecl->get_name() ) ) {
     832                if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc.
    824833                        if ( params.size() == 0 ) {
    825834                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
    826835                        }
    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 );
     836                        ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() );
     837                        if ( ! refType ) {
     838                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a reference ", funcDecl );
    830839                        }
    831                         if ( InitTweak::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
     840                        if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    832841                                throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
    833842                        }
     
    945954                }
    946955        }
     956
     957        void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
     958                if ( ! dereferenceOperator ) {
     959                        if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
     960                                FunctionType * ftype = funcDecl->get_functionType();
     961                                if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
     962                                        dereferenceOperator = funcDecl;
     963                                }
     964                        }
     965                }
     966        }
    947967} // namespace SymTab
    948968
Note: See TracChangeset for help on using the changeset viewer.