Changeset 020fa10 for src/Validate
- Timestamp:
- Feb 1, 2024, 5:28:18 PM (12 months ago)
- Branches:
- master
- Children:
- a55ebcc, bd67442
- Parents:
- 9ddcee1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/Autogen.cpp
r9ddcee1 r020fa10 198 198 bool shouldAutogen() const final { return true; } 199 199 void genAttrFuncForward(); 200 void __attribute__ ((unused)) genDualFuncs();201 200 private: 202 201 void genFuncBody( ast::FunctionDecl * decl ) final; … … 204 203 const ast::Decl * getDecl() const final { return decl; } 205 204 206 ast::ObjectDecl * dualDstParam() const;207 208 205 ast::FunctionDecl * genPosProto() const; 209 206 ast::FunctionDecl * genLabelProto() const; 210 207 ast::FunctionDecl * genValueProto() const; 211 212 ast::FunctionDecl * genCopyEnumToDualProto() const;213 ast::FunctionDecl * genAssignEnumToDualProto() const;214 215 void genDualBody( ast::FunctionDecl * decl );216 208 }; 217 209 … … 258 250 if ( enumDecl->base ) { 259 251 gen.genAttrFuncForward(); 260 // gen.genDualFuncs();261 252 } 262 253 gen.generateAndAppendFunctions( declsToAddAfter ); … … 810 801 } 811 802 812 ast::ObjectDecl * EnumFuncGenerator::dualDstParam() const {813 auto base = decl->base;814 assert( base );815 return new ast::ObjectDecl( getLocation(), "_dst",816 new ast::ReferenceType( ast::deepCopy( base ) ) );817 }818 819 // void ?{}(T & _dst, enum E _src )820 ast::FunctionDecl * EnumFuncGenerator::genCopyEnumToDualProto() const {821 return genProto( "?{}", { dualDstParam(), srcParam() }, {} );822 }823 824 // T ?{}(T & _dst, enum E _src )825 ast::FunctionDecl * EnumFuncGenerator::genAssignEnumToDualProto() const {826 auto retval = dualDstParam();827 retval->name = "_ret";828 return genProto( "?=?", { dualDstParam(), srcParam() }, { retval });829 }830 831 void EnumFuncGenerator::genDualBody( ast::FunctionDecl * functionDecl ) {832 assert( decl->base );833 const CodeLocation& location = functionDecl->location;834 auto & params = functionDecl->params;835 836 assert( 2 == params.size() );837 auto dstParam = params.front().strict_as<ast::ObjectDecl>();838 auto srcParam = params.back().strict_as<ast::ObjectDecl>();839 840 auto dstExpr = new ast::VariableExpr( location, dstParam );841 842 auto srcExpr = new ast::ApplicationExpr( location,843 ast::VariableExpr::functionPointer( location, genValueProto() ),844 {845 new ast::VariableExpr( location, srcParam )846 });847 auto callExpr = new ast::ApplicationExpr( location,848 ast::VariableExpr::functionPointer( location, functionDecl ),849 { dstExpr, srcExpr } );850 functionDecl->stmts = new ast::CompoundStmt( location,851 { new ast::ExprStmt( location, callExpr)} );852 }853 854 void EnumFuncGenerator::genDualFuncs() {855 assert( decl->base );856 ast::FunctionDecl *(EnumFuncGenerator::*dualProtos[2])() const = {857 &EnumFuncGenerator::genCopyEnumToDualProto,858 &EnumFuncGenerator::genAssignEnumToDualProto };859 for ( auto & generator : dualProtos ) {860 ast::FunctionDecl * decl = (this->*generator)();861 produceForwardDecl( decl );862 genDualBody( decl );863 if ( CodeGen::isAssignment( decl->name ) ) {864 appendReturnThis( decl );865 }866 produceDecl( decl );867 }868 }869 870 803 void TypeFuncGenerator::genFieldCtors() { 871 804 // Opaque types do not have field constructors.
Note: See TracChangeset
for help on using the changeset viewer.