From 4dc055ae23c9e33e459b7b583a67f92b5972a062 Mon Sep 17 00:00:00 2001 From: Sunil Shetye Date: Thu, 30 Aug 2018 17:45:27 +0530 Subject: code for missing variables --- combined.js | 8 +++++--- js/Sinks/CSCOPE.js | 8 +++++--- js/Sinks/CSCOPE.pickle | 44 +++++++++++++++++++++++++------------------- missingvariables.py | 8 ++++++++ sci2jsyacc.py | 13 ++++++++++++- 5 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 missingvariables.py diff --git a/combined.js b/combined.js index 4d6c6b15..a2e7a168 100644 --- a/combined.js +++ b/combined.js @@ -19225,6 +19225,8 @@ function CMSCOPE() { /* autogenerated from "macros/Sinks/CSCOPE.sci" */ function CSCOPE() { CSCOPE.prototype.define = function CSCOPE() { + this.heritance = 0; + this.nom = ""; this.win = -1; this.wdim = [[600],[400]]; this.wpos = [[-1],[-1]]; @@ -19279,7 +19281,7 @@ function CSCOPE() { this.ymax = parseFloat(arguments[0]["ymax"]); this.per = parseFloat(arguments[0]["per"]); this.N = parseFloat(arguments[0]["N"]); - this.heritance = arguments[0]["heritance"]; + this.heritance = parseFloat(arguments[0]["heritance"]); this.nom = arguments[0]["nom"]; var exprs = [arguments[0]["clrs"], arguments[0]["win"], arguments[0]["wpos"], arguments[0]["wdim"], arguments[0]["ymin"], arguments[0]["ymax"], arguments[0]["per"], arguments[0]["N"], arguments[0]["heritance"], arguments[0]["nom"]]; if (!ok) { @@ -19336,8 +19338,8 @@ function CSCOPE() { this.model.rpar = new ScilabDouble(rpar); this.model.ipar = new ScilabDouble(ipar); this.model.evtin = new ScilabDouble([ones(1-this.heritance,1)]); - this.model.label = new ScilabDouble([this.nom]); - this.graphics.id = new ScilabDouble([this.nom]); + this.model.label = new ScilabString([this.nom]); + this.graphics.id = new ScilabString([this.nom]); this.graphics.exprs = new ScilabDouble([exprs]); this.x.graphics = this.graphics; this.x.model = this.model; diff --git a/js/Sinks/CSCOPE.js b/js/Sinks/CSCOPE.js index 6a97815d..2502f55d 100644 --- a/js/Sinks/CSCOPE.js +++ b/js/Sinks/CSCOPE.js @@ -1,6 +1,8 @@ /* autogenerated from "macros/Sinks/CSCOPE.sci" */ function CSCOPE() { CSCOPE.prototype.define = function CSCOPE() { + this.heritance = 0; + this.nom = ""; this.win = -1; this.wdim = [[600],[400]]; this.wpos = [[-1],[-1]]; @@ -55,7 +57,7 @@ function CSCOPE() { this.ymax = parseFloat(arguments[0]["ymax"]); this.per = parseFloat(arguments[0]["per"]); this.N = parseFloat(arguments[0]["N"]); - this.heritance = arguments[0]["heritance"]; + this.heritance = parseFloat(arguments[0]["heritance"]); this.nom = arguments[0]["nom"]; var exprs = [arguments[0]["clrs"], arguments[0]["win"], arguments[0]["wpos"], arguments[0]["wdim"], arguments[0]["ymin"], arguments[0]["ymax"], arguments[0]["per"], arguments[0]["N"], arguments[0]["heritance"], arguments[0]["nom"]]; if (!ok) { @@ -112,8 +114,8 @@ function CSCOPE() { this.model.rpar = new ScilabDouble(rpar); this.model.ipar = new ScilabDouble(ipar); this.model.evtin = new ScilabDouble([ones(1-this.heritance,1)]); - this.model.label = new ScilabDouble([this.nom]); - this.graphics.id = new ScilabDouble([this.nom]); + this.model.label = new ScilabString([this.nom]); + this.graphics.id = new ScilabString([this.nom]); this.graphics.exprs = new ScilabDouble([exprs]); this.x.graphics = this.graphics; this.x.model = this.model; diff --git a/js/Sinks/CSCOPE.pickle b/js/Sinks/CSCOPE.pickle index 66efc3a6..951864a4 100644 --- a/js/Sinks/CSCOPE.pickle +++ b/js/Sinks/CSCOPE.pickle @@ -94,41 +94,47 @@ g5 sS'wdim' p25 g2 -sS'model.ipar' +sS'nom' p26 -g2 -sS'typ' +S'string' p27 -S'vector' +sS'model.ipar' p28 -sS'ok' +g2 +sS'typ' p29 -S'boolean' +S'vector' p30 -sS'model.blocktype' +sS'heritance' p31 -S'string' +g5 +sS'ok' p32 -sS'model.dep_ut' +S'boolean' p33 -S'vector_boolean' +sS'model.blocktype' p34 -sS'exprs' +g27 +sS'model.dep_ut' p35 +S'vector_boolean' +p36 +sS'exprs' +p37 g2 sS'gr_i' -p36 -g28 +p38 +g30 sS'ipar' -p37 +p39 g2 sS'y' -p38 -g28 +p40 +g30 sS'x' -p39 -g28 +p41 +g30 sS'model' -p40 +p42 g12 s. \ No newline at end of file diff --git a/missingvariables.py b/missingvariables.py new file mode 100644 index 00000000..e447b71e --- /dev/null +++ b/missingvariables.py @@ -0,0 +1,8 @@ +from sci2jslex import BOOLEAN_TYPE, DOUBLE_TYPE, LIST_TYPE, MATRIX_TYPE, NULL_TYPE, OBJECT_TYPE, STRING_TYPE, VECTOR_TYPE, VECTOR_BOOLEAN_TYPE, VECTOR_STRING_TYPE + +MISSING_VARIABLES_MAP = { + 'CSCOPE' : [ + { 'var': 'heritance', 'vartype': DOUBLE_TYPE, 'defvalue': '0' }, + { 'var': 'nom', 'vartype': STRING_TYPE, 'defvalue': '""' }, + ], +} diff --git a/sci2jsyacc.py b/sci2jsyacc.py index a7449e39..347513d8 100755 --- a/sci2jsyacc.py +++ b/sci2jsyacc.py @@ -19,6 +19,7 @@ import ply.yacc as yacc from sci2jslex import tokens, JOBTYPES from sci2jslex import BOOLEAN_TYPE, DOUBLE_TYPE, LIST_TYPE, MATRIX_TYPE, NULL_TYPE, OBJECT_TYPE, STRING_TYPE, VECTOR_TYPE, VECTOR_BOOLEAN_TYPE, VECTOR_STRING_TYPE +from missingvariables import MISSING_VARIABLES_MAP # }}} @@ -129,6 +130,16 @@ def p_jobfunctionblock_jobfunctionstatement_statementblock_endfunction(p): indent2 = '%*s' % (INDENT_LEVEL * INDENT_SIZE, ' ') blocktype = getblocktype(fname) + missing_variables = MISSING_VARIABLES_MAP.get(fname, [ ]) + jmissing = '' + for vardetails in missing_variables: + var = vardetails['var'] + vartype = vardetails['vartype'] + defvalue = vardetails['defvalue'] + add_global_var(var) + add_var_vartype(var, vartype) + jmissing += '%*s%s = %s;\n' % (INDENT_LEVEL * INDENT_SIZE, ' ', print_var(var), defvalue) + jdefine = JOB_BLOCKS['"define"'] jtitle = JOB_BLOCKS['"title"'] if OPTIONS_BLOCK != '': @@ -143,7 +154,7 @@ def p_jobfunctionblock_jobfunctionstatement_statementblock_endfunction(p): jplot = JOB_BLOCKS['"plot"'] jset = JOB_BLOCKS['"set"'] - jdefine = '%s%s.prototype.define = function %s() {\n%s%sreturn new %s(%s);\n%s}\n' % (indent, fname, fname, jdefine, indent2, blocktype, print_var('x'), indent) + jdefine = '%s%s.prototype.define = function %s() {\n%s%s%sreturn new %s(%s);\n%s}\n' % (indent, fname, fname, jmissing, jdefine, indent2, blocktype, print_var('x'), indent) jdetails = '%s%s.prototype.details = function %s() {\n%sreturn %s;\n%s}\n' % (indent, fname, fname, indent2, print_var('x'), indent) jget = '%s%s.prototype.get = function %s() {\n%s%s}\n' % (indent, fname, fname, jget, indent) if jgetinputs != '': -- cgit