Changeset 13d326ec


Ignore:
Timestamp:
Jul 26, 2022, 4:45:07 PM (21 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
2af1943
Parents:
1b97cc87
Message:

More clean-up, including some removing some duplicate functions.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/SpecializeNew.cpp

    r1b97cc87 r13d326ec  
    230230        if ( auto tuple = type.as<ast::TupleType>() ) {
    231231                std::vector<ast::ptr<ast::Expr>> exprs;
    232                 for ( const ast::Type * t : *tuple ) {
     232                for ( const ast::ptr<ast::Type> & t : *tuple ) {
    233233                        exprs.push_back( structureArg( location, t, begin, end ) );
    234234                }
     
    248248                        if (typeMap.count(typeInst->base)) {
    249249                                ast::TypeInstType * newInst = mutate(typeInst);
    250                                 newInst->expr_id = typeMap[typeInst->base].first;
    251                                 newInst->formal_usage = typeMap[typeInst->base].second;
     250                                auto const & pair = typeMap[typeInst->base];
     251                                newInst->expr_id = pair.first;
     252                                newInst->formal_usage = pair.second;
    252253                                return newInst;
    253254                        }
     
    462463        if ( specialized != expr->arg ) {
    463464                // Assume that the specialization incorporates the cast.
    464                 // std::cerr << expr <<std::endl;
    465465                return specialized;
    466466        } else {
  • src/InitTweak/InitTweak.cc

    r1b97cc87 r13d326ec  
    2727#include "AST/Stmt.hpp"
    2828#include "AST/Type.hpp"
     29#include "CodeGen/OperatorTable.h" // for isConstructor, isDestructor, isCto...
    2930#include "Common/PassVisitor.h"
    3031#include "Common/SemanticError.h"  // for SemanticError
     
    770771                        std::list< Expression * > callExprs;
    771772                        collectCtorDtorCalls( stmt, callExprs );
    772                         // if ( callExprs.empty() ) return false; // xxx - do I still need this check?
    773773                        return std::all_of( callExprs.begin(), callExprs.end(), pred);
    774774                }
     
    901901                        } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( func ) ) {
    902902                                return varExpr->get_var()->get_name();
    903                         }       else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( func ) ) {
     903                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( func ) ) {
    904904                                return funcName( castExpr->get_arg() );
    905905                        } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( func ) ) {
     
    923923                        } else if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( func ) ) {
    924924                                return varExpr->var->name;
    925                         }       else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( func ) ) {
     925                        } else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( func ) ) {
    926926                                return funcName( castExpr->arg );
    927927                        } else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( func ) ) {
     
    991991
    992992        Type * isPointerType( Type * type ) {
    993                 if ( getPointerBase( type ) ) return type;
    994                 else return nullptr;
     993                return getPointerBase( type ) ? type : nullptr;
    995994        }
    996995
     
    10141013                                src = new AddressExpr( src );
    10151014                        }
    1016                         // src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) );
    10171015                }
    10181016                return new ApplicationExpr( VariableExpr::functionPointer( assign ), { dst, src } );
     
    11671165        }
    11681166
    1169         bool isConstructor( const std::string & str ) { return str == "?{}"; }
    1170         bool isDestructor( const std::string & str ) { return str == "^?{}"; }
    1171         bool isAssignment( const std::string & str ) { return str == "?=?"; }
    1172         bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); }
    1173         bool isCtorDtorAssign( const std::string & str ) { return isCtorDtor( str ) || isAssignment( str ); }
    1174 
    11751167        const FunctionDecl * isCopyFunction( const Declaration * decl, const std::string & fname ) {
    11761168                const FunctionDecl * function = dynamic_cast< const FunctionDecl * >( decl );
     
    11921184
    11931185bool isAssignment( const ast::FunctionDecl * decl ) {
    1194         return isAssignment( decl->name ) && isCopyFunction( decl );
     1186        return CodeGen::isAssignment( decl->name ) && isCopyFunction( decl );
    11951187}
    11961188
    11971189bool isDestructor( const ast::FunctionDecl * decl ) {
    1198         return isDestructor( decl->name );
     1190        return CodeGen::isDestructor( decl->name );
    11991191}
    12001192
    12011193bool isDefaultConstructor( const ast::FunctionDecl * decl ) {
    1202         return isConstructor( decl->name ) && 1 == decl->params.size();
     1194        return CodeGen::isConstructor( decl->name ) && 1 == decl->params.size();
    12031195}
    12041196
    12051197bool isCopyConstructor( const ast::FunctionDecl * decl ) {
    1206         return isConstructor( decl->name ) && 2 == decl->params.size();
     1198        return CodeGen::isConstructor( decl->name ) && 2 == decl->params.size();
    12071199}
    12081200
     
    12221214        }
    12231215        const FunctionDecl * isDestructor( const Declaration * decl ) {
    1224                 if ( isDestructor( decl->name ) ) {
     1216                if ( CodeGen::isDestructor( decl->name ) ) {
    12251217                        return dynamic_cast< const FunctionDecl * >( decl );
    12261218                }
     
    12281220        }
    12291221        const FunctionDecl * isDefaultConstructor( const Declaration * decl ) {
    1230                 if ( isConstructor( decl->name ) ) {
     1222                if ( CodeGen::isConstructor( decl->name ) ) {
    12311223                        if ( const FunctionDecl * func = dynamic_cast< const FunctionDecl * >( decl ) ) {
    12321224                                if ( func->type->parameters.size() == 1 ) {
Note: See TracChangeset for help on using the changeset viewer.