|
|
@@ -42,6 +42,7 @@ static int add_template (struct desugar_state *state, NCDBlock block, NCDValue *
|
|
|
static int desugar_block (struct desugar_state *state, NCDBlock *block);
|
|
|
static int desugar_if (struct desugar_state *state, NCDBlock *block, NCDStatement *stmt, NCDStatement **out_next);
|
|
|
static int desugar_foreach (struct desugar_state *state, NCDBlock *block, NCDStatement *stmt, NCDStatement **out_next);
|
|
|
+static int desugar_blockstmt (struct desugar_state *state, NCDBlock *block, NCDStatement *stmt, NCDStatement **out_next);
|
|
|
|
|
|
static int add_template (struct desugar_state *state, NCDBlock block, NCDValue *out_name_val)
|
|
|
{
|
|
|
@@ -97,7 +98,15 @@ static int desugar_block (struct desugar_state *state, NCDBlock *block)
|
|
|
}
|
|
|
} break;
|
|
|
|
|
|
- default: ASSERT(0);
|
|
|
+ case NCDSTATEMENT_BLOCK: {
|
|
|
+ if (!desugar_blockstmt(state, block, stmt, &stmt)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ } break;
|
|
|
+
|
|
|
+ default: {
|
|
|
+ return 0;
|
|
|
+ } break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -231,6 +240,40 @@ fail:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static int desugar_blockstmt (struct desugar_state *state, NCDBlock *block, NCDStatement *stmt, NCDStatement **out_next)
|
|
|
+{
|
|
|
+ ASSERT(NCDStatement_Type(stmt) == NCDSTATEMENT_BLOCK)
|
|
|
+
|
|
|
+ NCDValue args;
|
|
|
+ NCDValue_InitList(&args);
|
|
|
+
|
|
|
+ NCDBlock block_block = NCDStatement_BlockGrabBlock(stmt);
|
|
|
+
|
|
|
+ NCDValue template_arg;
|
|
|
+ if (!add_template(state, block_block, &template_arg)) {
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!NCDValue_ListAppend(&args, template_arg)) {
|
|
|
+ NCDValue_Free(&template_arg);
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
+ NCDStatement new_stmt;
|
|
|
+ if (!NCDStatement_InitReg(&new_stmt, NCDStatement_Name(stmt), NULL, "inline_code", args)) {
|
|
|
+ goto fail;
|
|
|
+ }
|
|
|
+
|
|
|
+ stmt = NCDBlock_ReplaceStatement(block, stmt, new_stmt);
|
|
|
+
|
|
|
+ *out_next = NCDBlock_NextStatement(block, stmt);
|
|
|
+ return 1;
|
|
|
+
|
|
|
+fail:
|
|
|
+ NCDValue_Free(&args);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int NCDSugar_Desugar (NCDProgram *prog)
|
|
|
{
|
|
|
ASSERT(!NCDProgram_ContainsElemType(prog, NCDPROGRAMELEM_INCLUDE))
|