MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / generateLambdaMakeStruct

Function generateLambdaMakeStruct

src/ast/ast_generate.cpp:828–892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

826 }
827
828 ExpressionPtr generateLambdaMakeStruct ( const StructurePtr & ls, const FunctionPtr & lf, const FunctionPtr & lff,
829 const safe_var_set & capt, const vector<CaptureEntry> & capture,
830 const LineInfo & at, const LineInfo & captureAt, Program * thisProgram ) {
831 auto asc = new ExprAscend();
832 asc->at = at;
833 asc->needTypeInfo = true;
834 auto makeS = new ExprMakeStruct();
835 // makeS->useInitializer = true;
836 makeS->at = at;
837 makeS->makeType = new TypeDecl(ls);
838 auto ms = new MakeStruct();
839 auto atTHIS = new ExprAddr(lf->at, "_::" + lf->name);
840 // TODO: expand atTHIS->funcType, so that it points to correct function by type as well
841 auto mTHIS = new MakeFieldDecl(lf->at, "__lambda", atTHIS, false, false);
842 ms->push_back(mTHIS);
843 auto atTHISF = new ExprAddr(lff->at, "_::" + lff->name);
844 auto mTHISF = new MakeFieldDecl(lf->at, "__finalize", atTHISF, false, false);
845 ms->push_back(mTHISF);
846 for ( auto cV : capt ) {
847 CaptureMode mode = CaptureMode::capture_any;
848 auto it = find_if ( capture.begin(), capture.end(), [&] ( const auto & entry ){
849 return entry.name == cV->name;
850 });
851 if ( it != capture.end() ) {
852 mode = it->mode;
853 }
854 if ( isCaptureAsRef(cV) || mode==CaptureMode::capture_by_reference ) {
855 auto varV = new ExprVar(captureAt, cV->name);
856 auto addrV = new ExprRef2Ptr(captureAt, varV);
857 addrV->alwaysSafe = true;
858 auto mV = new MakeFieldDecl(captureAt, cV->name, addrV, false, false);
859 ms->push_back(mV);
860 } else {
861 bool moveS = false;
862 bool cloneS = false;
863 switch ( mode ) {
864 case CaptureMode::capture_by_clone: cloneS = true; break;
865 case CaptureMode::capture_by_move: moveS = true; break;
866 case CaptureMode::capture_any: moveS = !cV->type->canCopy(); break;
867 default: ;
868 }
869 auto varV = new ExprVar(captureAt, cV->name);
870 auto mV = new MakeFieldDecl(captureAt, cV->name, varV, moveS, cloneS);
871 ms->push_back(mV);
872 }
873 auto & lexpr = ms->back();
874 thisProgram->library.foreach([&](Module * mod){
875 for ( auto & cm : mod->captureMacros ) {
876 auto cexpr = cm->captureExpression(thisProgram, thisProgram->thisModule.get(), lexpr->value, cV->type);
877 if ( cexpr != nullptr ) {
878 lexpr->value = cexpr;
879 }
880 }
881 return true;
882 },"*");
883 }
884 makeS->structs.push_back(ms);
885 asc->subexpr = makeS;

Callers 2

visitMethod · 0.85
convertBlockToLambdaMethod · 0.85

Calls 10

isCaptureAsRefFunction · 0.85
verifyGeneratedFunction · 0.85
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
canCopyMethod · 0.45
foreachMethod · 0.45
captureExpressionMethod · 0.45
getMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected