|
@@ -110,40 +110,74 @@ function functionsCode (function_obj) {
|
|
|
|
|
|
|
|
|
|
|
|
|
function commandsCode (command_obj, indentation = 2) {
|
|
function commandsCode (command_obj, indentation = 2) {
|
|
|
|
|
+ let code = "";
|
|
|
|
|
+
|
|
|
switch (command_obj.type) {
|
|
switch (command_obj.type) {
|
|
|
case Models.COMMAND_TYPES.break:
|
|
case Models.COMMAND_TYPES.break:
|
|
|
- return breaksCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = breaksCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.comment:
|
|
case Models.COMMAND_TYPES.comment:
|
|
|
- return commentsCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = commentsCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.reader:
|
|
case Models.COMMAND_TYPES.reader:
|
|
|
- return readersCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = readersCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.writer:
|
|
case Models.COMMAND_TYPES.writer:
|
|
|
- return writersCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = writersCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.functioncall:
|
|
case Models.COMMAND_TYPES.functioncall:
|
|
|
- return functioncallsCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = functioncallsCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.attribution:
|
|
case Models.COMMAND_TYPES.attribution:
|
|
|
- return attributionsCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = attributionsCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.whiletrue:
|
|
case Models.COMMAND_TYPES.whiletrue:
|
|
|
- return whiletruesCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = whiletruesCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.dowhiletrue:
|
|
case Models.COMMAND_TYPES.dowhiletrue:
|
|
|
- return doWhilesCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = doWhilesCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.iftrue:
|
|
case Models.COMMAND_TYPES.iftrue:
|
|
|
- return iftruesCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = iftruesCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.repeatNtimes:
|
|
case Models.COMMAND_TYPES.repeatNtimes:
|
|
|
- return repeatNtimesCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = repeatNtimesCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.switch:
|
|
case Models.COMMAND_TYPES.switch:
|
|
|
- return switchsCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = switchsCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
case Models.COMMAND_TYPES.return:
|
|
case Models.COMMAND_TYPES.return:
|
|
|
- return returnsCode(command_obj, indentation);
|
|
|
|
|
|
|
+ code = returnsCode(command_obj, indentation);
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // IMPORTANT: do NOT add inline comment here!
|
|
|
|
|
+ // Each specific function (whiletruesCode, etc) does this
|
|
|
|
|
+ // To add here implies to DOUBLE the comment!
|
|
|
|
|
+
|
|
|
|
|
+ // Add comment if, and only if, is a simple command (without blocks)
|
|
|
|
|
+ const simpleCommands = [
|
|
|
|
|
+ Models.COMMAND_TYPES.break,
|
|
|
|
|
+ Models.COMMAND_TYPES.reader,
|
|
|
|
|
+ Models.COMMAND_TYPES.writer,
|
|
|
|
|
+ Models.COMMAND_TYPES.functioncall,
|
|
|
|
|
+ Models.COMMAND_TYPES.attribution,
|
|
|
|
|
+ Models.COMMAND_TYPES.return,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if (simpleCommands.includes(command_obj.type)) {
|
|
|
|
|
+ code = addInlineComment(code, command_obj);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return code;
|
|
|
|
|
+ } // function commandsCode(command_obj, indentation = 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
function returnsCode (command_obj, indentation) {
|
|
function returnsCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_return");
|
|
ret += LocalizedStrings.getUI("text_return");
|
|
@@ -176,7 +210,7 @@ function switchsCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_code_switch") + "(";
|
|
ret += LocalizedStrings.getUI("text_code_switch") + "(";
|
|
@@ -191,7 +225,7 @@ function switchsCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
ret += "} ";
|
|
ret += "} ";
|
|
|
|
|
|
|
@@ -203,7 +237,7 @@ function switchcasesCode (switchcase, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_code_case") + " ";
|
|
ret += LocalizedStrings.getUI("text_code_case") + " ";
|
|
@@ -267,7 +301,7 @@ function repeatNtimesCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_for") + " ";
|
|
ret += LocalizedStrings.getUI("text_for") + " ";
|
|
@@ -285,18 +319,61 @@ function repeatNtimesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
if (command_obj.expression3) {
|
|
if (command_obj.expression3) {
|
|
|
ret += ` ${LocalizedStrings.getUI("text_code_for_pass")} `;
|
|
ret += ` ${LocalizedStrings.getUI("text_code_for_pass")} `;
|
|
|
- switch (command_obj.expression3.itens[1]) {
|
|
|
|
|
- case Models.ARITHMETIC_TYPES.plus:
|
|
|
|
|
- ret += " +";
|
|
|
|
|
- break;
|
|
|
|
|
- case Models.ARITHMETIC_TYPES.minus:
|
|
|
|
|
- ret += " -";
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // To fix the bug UNDEFINED
|
|
|
|
|
+ // The problem is inside the struture of expression3
|
|
|
|
|
+ console.log("DEBUG expression3:", command_obj.expression3);
|
|
|
|
|
+
|
|
|
|
|
+ // Try to access in more than one form
|
|
|
|
|
+ let operator = null;
|
|
|
|
|
+ let operand = null;
|
|
|
|
|
+
|
|
|
|
|
+ // Verify if is ExpressionElement with items
|
|
|
|
|
+ if (command_obj.expression3.itens) {
|
|
|
|
|
+ operator = command_obj.expression3.itens[1];
|
|
|
|
|
+ operand = command_obj.expression3.itens[2];
|
|
|
|
|
+ }
|
|
|
|
|
+ // Verify if has direct structure (what is "direct structure"?)
|
|
|
|
|
+ else if (command_obj.expression3.operator) {
|
|
|
|
|
+ operator = command_obj.expression3.operator;
|
|
|
|
|
+ operand = command_obj.expression3.operand || command_obj.expression3.value;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Try (directly) array
|
|
|
|
|
+ else if (Array.isArray(command_obj.expression3)) {
|
|
|
|
|
+ operator = command_obj.expression3[0];
|
|
|
|
|
+ operand = command_obj.expression3[1];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Render operator (build operator to be HTML presented)
|
|
|
|
|
+ if (operator) {
|
|
|
|
|
+ switch (operator) {
|
|
|
|
|
+ case Models.ARITHMETIC_TYPES.plus:
|
|
|
|
|
+ ret += "+";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case Models.ARITHMETIC_TYPES.minus:
|
|
|
|
|
+ ret += "-";
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ ret += "+"; // fallback
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ret += "+"; // fallback
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Render operand (build operand to be HTML presented)
|
|
|
|
|
+ if (operand) {
|
|
|
|
|
+ ret += variableValueMenuCode(operand);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ret += "1"; // fallback
|
|
|
}
|
|
}
|
|
|
- ret += variableValueMenuCode(command_obj.expression3.itens[2]);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ret += " { ";
|
|
|
|
|
|
|
+ ret += " {";
|
|
|
|
|
+
|
|
|
|
|
+ // Add inline comment ONLY ONCE HERE
|
|
|
|
|
+ if (command_obj.inlineComment) {
|
|
|
|
|
+ ret += " // " + command_obj.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (command_obj.commands_block) {
|
|
if (command_obj.commands_block) {
|
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
@@ -306,38 +383,42 @@ function repeatNtimesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "}";
|
|
ret += "}";
|
|
|
|
|
+ // here, do not add "another" inline comment!
|
|
|
|
|
+
|
|
|
return ret;
|
|
return ret;
|
|
|
- }
|
|
|
|
|
|
|
+ } // function repeatNtimesCode(command_obj, indentation)
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write IfElse code
|
|
// Write IfElse code
|
|
|
|
|
+// Whenever "click" to see "textual code"
|
|
|
function iftruesCode (command_obj, indentation) {
|
|
function iftruesCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
+ //D console.log("code_generator.js!iftruesCode(.): "); //leo
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_if");
|
|
ret += LocalizedStrings.getUI("text_if");
|
|
|
|
|
|
|
|
- if (!command_obj.expression) {
|
|
|
|
|
- Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression"));
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ if (command_obj.expression) {
|
|
|
ret += "(";
|
|
ret += "(";
|
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
|
ret += ")";
|
|
ret += ")";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //NOT necessary: Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*switch (command_obj.expression.expression.type) {
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_logic: ret += logicExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_arithmetic: ret += arithmeticExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ ret += " {";
|
|
|
|
|
|
|
|
- ret += " { ";
|
|
|
|
|
|
|
+ // Inline comment ONLY here
|
|
|
|
|
+ if (command_obj.inlineComment) {
|
|
|
|
|
+ ret += " // " + command_obj.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (command_obj.commands_block) {
|
|
if (command_obj.commands_block) {
|
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
@@ -347,7 +428,7 @@ function iftruesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "} " + LocalizedStrings.getUI("text_else") + " {";
|
|
ret += "} " + LocalizedStrings.getUI("text_else") + " {";
|
|
@@ -360,7 +441,7 @@ function iftruesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "}";
|
|
ret += "}";
|
|
@@ -373,10 +454,14 @@ function doWhilesCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ret += LocalizedStrings.getUI("text_code_do") + " { ";
|
|
|
|
|
|
|
+ ret += LocalizedStrings.getUI("text_code_do") + " {";
|
|
|
|
|
+
|
|
|
|
|
+ if (command_obj.inlineComment) {
|
|
|
|
|
+ ret += " // " + command_obj.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (command_obj.commands_block) {
|
|
if (command_obj.commands_block) {
|
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
@@ -386,19 +471,12 @@ function doWhilesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "} " + LocalizedStrings.getUI("text_code_do_until");
|
|
ret += "} " + LocalizedStrings.getUI("text_code_do_until");
|
|
|
|
|
|
|
|
- if (!command_obj.expression) {
|
|
|
|
|
- Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*switch (command_obj.expression.expression.type) {
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_logic: ret += logicExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_arithmetic: ret += arithmeticExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ //x if (!command_obj.expression) { Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression")); }
|
|
|
|
|
|
|
|
if (command_obj.expression) {
|
|
if (command_obj.expression) {
|
|
|
ret += "(";
|
|
ret += "(";
|
|
@@ -414,26 +492,23 @@ function whiletruesCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_code_while");
|
|
ret += LocalizedStrings.getUI("text_code_while");
|
|
|
|
|
|
|
|
- if (!command_obj.expression) {
|
|
|
|
|
- Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*switch (command_obj.expression.expression.type) {
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_logic: ret += logicExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- case Models.EXPRESSION_TYPES.exp_arithmetic: ret += arithmeticExpressionCode(command_obj.expression.expression); break;
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ //x if (!command_obj.expression) Utils.renderErrorMessage(command_obj.expression.dom_object, LocalizedStrings.getUI("inform_valid_expression"));
|
|
|
if (command_obj.expression) {
|
|
if (command_obj.expression) {
|
|
|
ret += "(";
|
|
ret += "(";
|
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
|
ret += ")";
|
|
ret += ")";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ret += " { ";
|
|
|
|
|
|
|
+ ret += " {";
|
|
|
|
|
+
|
|
|
|
|
+ if (command_obj.inlineComment) {
|
|
|
|
|
+ ret += " // " + command_obj.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (command_obj.commands_block) {
|
|
if (command_obj.commands_block) {
|
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
for (let i = 0; i < command_obj.commands_block.length; i++) {
|
|
@@ -443,7 +518,7 @@ function whiletruesCode (command_obj, indentation) {
|
|
|
|
|
|
|
|
ret += "\n";
|
|
ret += "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "}";
|
|
ret += "}";
|
|
@@ -551,10 +626,10 @@ function arithmeticExpressionCode (expression) {
|
|
|
function attributionsCode (command_obj, indentation) {
|
|
function attributionsCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
ret += variableValueMenuCode(command_obj.variable) + " <- ";
|
|
ret += variableValueMenuCode(command_obj.variable) + " <- ";
|
|
|
- /*for (var i = 0; i < command_obj.expression.length; i++) { ret += elementExpressionCode(command_obj.expression[i]); }*/
|
|
|
|
|
|
|
+ // for (var i = 0; i < command_obj.expression.length; i++) { ret += elementExpressionCode(command_obj.expression[i]); }
|
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
ret += elementExpressionCode(command_obj.expression);
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
@@ -612,21 +687,21 @@ export function elementExpressionCode (expression_obj) {
|
|
|
case Models.EXPRESSION_TYPES.write_sep:
|
|
case Models.EXPRESSION_TYPES.write_sep:
|
|
|
ret += ', " ", ';
|
|
ret += ', " ", ';
|
|
|
break;
|
|
break;
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
ret += " " + expression_obj[i] + " ";
|
|
ret += " " + expression_obj[i] + " ";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
-} // export function elementExpressionCode(expression_obj)
|
|
|
|
|
|
|
+ } // export function elementExpressionCode(expression_obj)
|
|
|
|
|
|
|
|
|
|
|
|
|
function functioncallsCode (command_obj, indentation) {
|
|
function functioncallsCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += variableValueMenuCode(command_obj.function_called);
|
|
ret += variableValueMenuCode(command_obj.function_called);
|
|
@@ -640,7 +715,7 @@ function readersCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += LocalizedStrings.getUI("text_command_read") + "("; // open
|
|
ret += LocalizedStrings.getUI("text_command_read") + "("; // open
|
|
@@ -676,10 +751,7 @@ export function variableValueMenuCode (variable_obj, is_return = false) {
|
|
|
} else if (variable_obj.content.type) {
|
|
} else if (variable_obj.content.type) {
|
|
|
ret += variable_obj.content.name;
|
|
ret += variable_obj.content.name;
|
|
|
|
|
|
|
|
- if (
|
|
|
|
|
- variable_obj.content.dimensions == 1 &&
|
|
|
|
|
- variable_obj.dimensions != 1
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ if (variable_obj.content.dimensions == 1 && variable_obj.dimensions != 1) {
|
|
|
ret += "[" + variableValueMenuCode(variable_obj.column) + "]"; // array
|
|
ret += "[" + variableValueMenuCode(variable_obj.column) + "]"; // array
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -709,6 +781,8 @@ export function variableValueMenuCode (variable_obj, is_return = false) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
|
|
+ var str = variable_obj==null || variable_obj==undefined ? "empty" : variable_obj.content; //D
|
|
|
|
|
+ console.log("js/visualUI/code_generator.js!variableValueMenuCode(.): Error, variable_obj.content=" + str); //D
|
|
|
if (!is_return) {
|
|
if (!is_return) {
|
|
|
Utils.renderErrorMessage(variable_obj.dom_object, LocalizedStrings.getUI("inform_valid_content"));
|
|
Utils.renderErrorMessage(variable_obj.dom_object, LocalizedStrings.getUI("inform_valid_content"));
|
|
|
throw err;
|
|
throw err;
|
|
@@ -723,7 +797,7 @@ export function variableValueMenuCode (variable_obj, is_return = false) {
|
|
|
function writersCode (command_obj, indentation) {
|
|
function writersCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
ret += LocalizedStrings.getUI("text_command_write") + "(";
|
|
ret += LocalizedStrings.getUI("text_command_write") + "(";
|
|
|
/*for (var i = 0; i < command_obj.content.length; i++) {
|
|
/*for (var i = 0; i < command_obj.content.length; i++) {
|
|
@@ -743,12 +817,28 @@ function commentsCode (command_obj, indentation) {
|
|
|
let ret = "\n";
|
|
let ret = "\n";
|
|
|
|
|
|
|
|
for (let i = 0; i < indentation; i++) {
|
|
for (let i = 0; i < indentation; i++) {
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret += "// ";
|
|
ret += "// ";
|
|
|
|
|
|
|
|
- ret += command_obj.comment_text.content;
|
|
|
|
|
|
|
+ //comment stars (Edilson)
|
|
|
|
|
+ let commentText = "";
|
|
|
|
|
+ if (command_obj.comment_text) {
|
|
|
|
|
+ if (typeof command_obj.comment_text === "object" && command_obj.comment_text.content) {
|
|
|
|
|
+ commentText = command_obj.comment_text.content;
|
|
|
|
|
+ } else if (typeof command_obj.comment_text === "string") {
|
|
|
|
|
+ commentText = command_obj.comment_text;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!commentText) {
|
|
|
|
|
+ commentText = command_obj.value || command_obj.comment || command_obj._text || "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret += commentText;
|
|
|
|
|
+ //comments ends (Edilson)
|
|
|
|
|
+
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -771,7 +861,7 @@ function parametersCode (parameter_obj) {
|
|
|
case Types.CHAR:
|
|
case Types.CHAR:
|
|
|
ret += " " + LocalizedStrings.getUI("type_char") + " ";
|
|
ret += " " + LocalizedStrings.getUI("type_char") + " ";
|
|
|
break;
|
|
break;
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
if (parameter_obj.reference)
|
|
if (parameter_obj.reference)
|
|
|
ret += "&";
|
|
ret += "&";
|
|
|
|
|
|
|
@@ -788,8 +878,11 @@ function parametersCode (parameter_obj) {
|
|
|
|
|
|
|
|
// Write variable declaration code
|
|
// Write variable declaration code
|
|
|
function variablesCode (variable_obj) {
|
|
function variablesCode (variable_obj) {
|
|
|
- let ret = "";
|
|
|
|
|
|
|
+ if (variable_obj.type === "comment" || variable_obj.constructor.name === "Comment") {
|
|
|
|
|
+ return commentsCode(variable_obj, 2);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ let ret = "";
|
|
|
const temp = variable_obj;
|
|
const temp = variable_obj;
|
|
|
|
|
|
|
|
ret += "\n "; // "\n\t\n" - using fixed space to indentation (adjust to the function indentation)
|
|
ret += "\n "; // "\n\t\n" - using fixed space to indentation (adjust to the function indentation)
|
|
@@ -815,7 +908,6 @@ function variablesCode (variable_obj) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
ret += temp.name + " ";
|
|
ret += temp.name + " ";
|
|
|
- //D console.log("********** code_generator.js: variablesCode(.): ret=|" + ret + "|"); //leo remover xxxxxxxxxxx
|
|
|
|
|
|
|
|
|
|
if (temp.dimensions == 1) {
|
|
if (temp.dimensions == 1) {
|
|
|
ret += "[" + temp.columns + "] ";
|
|
ret += "[" + temp.columns + "] ";
|
|
@@ -994,6 +1086,9 @@ function variablesCode (variable_obj) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ ret = addInlineComment(ret, temp); //comments (Edilson)
|
|
|
|
|
+
|
|
|
return ret;
|
|
return ret;
|
|
|
} // function variablesCode(variable_obj)
|
|
} // function variablesCode(variable_obj)
|
|
|
|
|
|
|
@@ -1005,7 +1100,7 @@ function globalsCode () {
|
|
|
for (let i = 0; i < window.program_obj.globals.length; i++) {
|
|
for (let i = 0; i < window.program_obj.globals.length; i++) {
|
|
|
const temp = window.program_obj.globals[i];
|
|
const temp = window.program_obj.globals[i];
|
|
|
|
|
|
|
|
- ret += " "; // "\t" - using fixed space to indentation
|
|
|
|
|
|
|
+ ret += " "; // do not use "\t" - better using 2 fixed spaces as indentation
|
|
|
|
|
|
|
|
if (temp.is_constant) {
|
|
if (temp.is_constant) {
|
|
|
ret += "const "; //TODO Internacionalizar - insert it in ./ivprog/i18n/ui.csv
|
|
ret += "const "; //TODO Internacionalizar - insert it in ./ivprog/i18n/ui.csv
|
|
@@ -1208,4 +1303,13 @@ function globalsCode () {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
|
- } // function globalsCode()
|
|
|
|
|
|
|
+ } // function globalsCode()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// Treat comments (Edilson)
|
|
|
|
|
+function addInlineComment (code, command_obj) {
|
|
|
|
|
+ if (command_obj.inlineComment) {
|
|
|
|
|
+ return code.trimEnd() + " // " + command_obj.inlineComment;
|
|
|
|
|
+ }
|
|
|
|
|
+ return code;
|
|
|
|
|
+ }
|