Changeset 490fb92e for src/SymTab


Ignore:
Timestamp:
Oct 23, 2020, 9:06:16 PM (4 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
37b7d95
Parents:
41b8ea4
Message:

move FixInit? to new ast

Location:
src/SymTab
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r41b8ea4 r490fb92e  
    233233        }
    234234
     235        // shallow copy the pointer list for return
     236        std::vector<ast::ptr<ast::TypeDecl>> getGenericParams (const ast::Type * t) {
     237                if (auto structInst = dynamic_cast<const ast::StructInstType*>(t)) {
     238                        return structInst->base->params;
     239                }
     240                if (auto unionInst = dynamic_cast<const ast::UnionInstType*>(t)) {
     241                        return unionInst->base->params;
     242                }
     243                return {};
     244        }
     245
    235246        /// given type T, generate type of default ctor/dtor, i.e. function type void (*) (T *)
    236247        FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic ) {
     
    244255                ftype->parameters.push_back( dstParam );
    245256                return ftype;
     257        }
     258
     259        ///
     260        ast::FunctionDecl * genDefaultFunc(const CodeLocation loc, const std::string fname, const ast::Type * paramType, bool maybePolymorphic) {
     261                std::vector<ast::ptr<ast::TypeDecl>> typeParams;
     262                if (maybePolymorphic) typeParams = getGenericParams(paramType);
     263                auto dstParam = new ast::ObjectDecl(loc, "_dst", new ast::ReferenceType(paramType), nullptr, {}, ast::Linkage::Cforall);
     264                return new ast::FunctionDecl(loc, fname, std::move(typeParams), {dstParam}, {}, new ast::CompoundStmt(loc));
    246265        }
    247266
  • src/SymTab/Autogen.h

    r41b8ea4 r490fb92e  
    5555        /// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
    5656        FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic = true );
     57
     58        ast::FunctionDecl * genDefaultFunc(const CodeLocation loc, const std::string fname, const ast::Type * paramType, bool maybePolymorphic = true);
    5759
    5860        /// generate the type of a copy constructor for paramType.
Note: See TracChangeset for help on using the changeset viewer.