| 1187 | } |
| 1188 | |
| 1189 | Expression * ast_lpipe ( yyscan_t scanner, Expression * fncall, Expression * arg, const LineInfo & locAt, bool markPiped ) { |
| 1190 | Expression * pipeCall = fncall->tail(); |
| 1191 | if ( pipeCall->rtti_isCallLikeExpr() ) { |
| 1192 | auto pCall = (ExprLooksLikeCall *) pipeCall; |
| 1193 | pCall->arguments.push_back(arg); |
| 1194 | if ( markPiped && arg->rtti_isMakeBlock() ) { |
| 1195 | pCall->pipedCallArgument = true; |
| 1196 | } |
| 1197 | return fncall; |
| 1198 | } else if ( pipeCall->rtti_isVar() ) { |
| 1199 | // a += b <| c |
| 1200 | auto pVar = (ExprVar *) pipeCall; |
| 1201 | auto pCall = yyextra->g_Program->makeCall(pVar->at,pVar->name); |
| 1202 | pCall->arguments.push_back(arg); |
| 1203 | if ( markPiped && arg->rtti_isMakeBlock() ) { |
| 1204 | pCall->pipedCallArgument = true; |
| 1205 | } |
| 1206 | if ( !fncall->swap_tail(pVar,pCall) ) { |
| 1207 | // gc_node — don't delete Expression |
| 1208 | return pCall; |
| 1209 | } else { |
| 1210 | return fncall; |
| 1211 | } |
| 1212 | } else if ( pipeCall->rtti_isMakeStruct() ) { |
| 1213 | auto pMS = (ExprMakeStruct *) pipeCall; |
| 1214 | if ( pMS->block ) { |
| 1215 | if ( pMS->type ) { |
| 1216 | das_yyerror(scanner,"can't pipe into make " + pMS->type->describe() + ". it already has where closure", |
| 1217 | locAt,CompilationError::cant_expression); |
| 1218 | } else { |
| 1219 | das_yyerror(scanner,"can't pipe into make struct. it already has where closure", |
| 1220 | locAt,CompilationError::cant_expression); |
| 1221 | } |
| 1222 | delete arg; |
| 1223 | } else if ( !arg->rtti_isMakeBlock() ) { |
| 1224 | das_yyerror(scanner,"can't pipe into make struct. argument must be a block", |
| 1225 | locAt,CompilationError::cant_expression); |
| 1226 | delete arg; |
| 1227 | } else { |
| 1228 | auto mkb = (ExprMakeBlock *) arg; |
| 1229 | auto blk = (ExprBlock *) mkb->block; |
| 1230 | if ( blk->arguments.size() != 1 ) { |
| 1231 | das_yyerror(scanner,"can't pipe into make struct. block must have exactly one argument (that structure itself)", |
| 1232 | locAt,CompilationError::cant_expression); |
| 1233 | delete arg; |
| 1234 | } else { |
| 1235 | pMS->block = arg; |
| 1236 | } |
| 1237 | } |
| 1238 | return fncall; |
| 1239 | } else { |
| 1240 | das_yyerror(scanner,"can only pipe into function call or make type", |
| 1241 | locAt,CompilationError::cant_expression); |
| 1242 | delete arg; |
| 1243 | return fncall; |
| 1244 | } |
| 1245 | } |
| 1246 | |