Browse Source

Work in progress

Igor 2 years ago
parent
commit
35beb80bcb
3 changed files with 49 additions and 7 deletions
  1. 42 0
      js/util/codeParser.js
  2. 6 6
      js/visualUI/code_generator.js
  3. 1 1
      js/visualUI/globals.js

+ 42 - 0
js/util/codeParser.js

@@ -16,7 +16,47 @@ function parseGlobal (global_obj) {
 	window.program_obj.addGlobal(new_global);
 }
 
+function parseParameter (parameter_obj) {
+
+  const new_parameter = new Models.Variable(
+    parameter_obj.type,
+    parameter_obj.name,
+    null,
+    parameter_obj.dimension,
+    parameter_obj.is_const,
+    parameter_obj.rows,
+    parameter_obj.columns,
+    parameter_obj.reference
+  );
+
+  return new_parameter;
+}
+
 function parseFunction (function_obj) {
+
+  console.log(function_obj)
+  
+  const new_function = new Models.Function(
+    function_obj.name, 
+    function_obj.return_type, 
+    function_obj.return_dimensions, 
+    [], 
+    false, 
+    false, 
+    []);
+  
+  if (!new_function.name) {
+    new_function.name = LocalizedStrings.getUI("start");
+    new_function.is_main = true;
+  }
+
+  if (function_obj.parameters_list) {
+    function_obj.parameters_list.forEach(function(el){
+      new_function.parameters_list.push(parseParameter(el));
+    });
+  }
+
+  window.program_obj.addFunction(new_function);
   
 }
 
@@ -26,9 +66,11 @@ export function parserCodeVisual (code_obj = null) {
   window.conteudo = code_obj
 
   // Globals:
+  window.program_obj.globals = [];
   code_obj.globals.forEach(parseGlobal);
 
   // Functions:
+  window.program_obj.functions = [];
   code_obj.functions.forEach(parseFunction);
 
 }

+ 6 - 6
js/visualUI/code_generator.js

@@ -884,7 +884,7 @@ function variablesCode (variable_obj) {
       case Types.REAL:
         ret += "<- {";
         for (let j = 0; j < temp.value.length; j++) {
-          ret += temp.value[j].toFixed(2);
+          ret += parseFloat(temp.value[j]).toFixed(2);
           if (j + 1 < temp.value.length) {
             ret += ", ";
           }
@@ -959,7 +959,7 @@ function variablesCode (variable_obj) {
           ret += "{";
 
           for (let k = 0; k < temp.columns; k++) {
-            ret += temp.value[j][k].toFixed(2);
+            ret += parseFloat(temp.value[j][k]).toFixed(2);
 
             if (k + 1 < temp.columns) {
               ret += ", ";
@@ -1047,7 +1047,7 @@ function variablesCode (variable_obj) {
         ret += "<- " + temp.value;
         break;
       case Types.REAL:
-        ret += "<- " + temp.value.toFixed(2);
+        ret += "<- " + parseFloat(temp.value).toFixed(2);
         break;
       case Types.TEXT:
         ret += '<- "' + temp.value + '"';
@@ -1117,7 +1117,7 @@ function globalsCode () {
           case Types.REAL:
             ret += "<- {";
             for (let j = 0; j < temp.value.length; j++) {
-              ret += temp.value[j].toFixed(2);
+              ret += parseFloat(temp.value[j]).toFixed(2);
               if (j + 1 < temp.value.length) {
                 ret += ", ";
               }
@@ -1192,7 +1192,7 @@ function globalsCode () {
               ret += "{";
 
               for (let k = 0; k < temp.columns; k++) {
-                ret += temp.value[j][k].toFixed(2);
+                ret += parseFloat(temp.value[j][k]).toFixed(2);
 
                 if (k + 1 < temp.columns) {
                   ret += ", ";
@@ -1280,7 +1280,7 @@ function globalsCode () {
             ret += "<- " + temp.value;
             break;
           case Types.REAL:
-            ret += "<- " + temp.value.toFixed(2);
+            ret += "<- " + parseFloat(temp.value).toFixed(2);
             break;
           case Types.TEXT:
             ret += '<- "' + temp.value + '"';

+ 1 - 1
js/visualUI/globals.js

@@ -295,7 +295,7 @@ function renderValues (global_var, global_container) {
 
 	if (global_var.dimensions == 0) {
 		if (global_var.type == Types.REAL) {
-			ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+global_var.value.toFixed(1)+'</span>  </div> ';
+			ret += '<div class="created_div_valor_var"><span class="span_value_variable simple_var">'+parseFloat(global_var.value).toFixed(1)+'</span>  </div> ';
 		} else {
 			if (global_var.type == Types.BOOLEAN) {
 				ret += '<div class="created_div_valor_var"><span class="span_value_variable boolean_simple_type">'+LocalizedStrings.getUI(`logic_value_${global_var.value}`)+'</span>  </div> ';