Skip to content

Commit c4a7727

Browse files
committed
Merge branch '2.3.5'
2 parents 7d103c1 + 6bd95a8 commit c4a7727

File tree

5 files changed

+63
-45
lines changed

5 files changed

+63
-45
lines changed

sim_sw/firmware/firm_fields_v1.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,17 @@ function firm_instruction_cop_read ( context, instruccionAux, all_ones_co )
261261

262262
function firm_instruction_field_read ( context, instruccionAux, camposInsertados )
263263
{
264-
// match mandatory FIELD
265264
var tmp_name = frm_getToken(context) ;
265+
266+
// check number of fields
267+
if (camposInsertados > (instruccionAux.fields.length - 1)) {
268+
return frm_langError(context,
269+
i18n_get_TagFor('compiler', 'UNEXPECTED FIELD') +
270+
"'" + tmp_name + "'. " +
271+
i18n_get_TagFor('compiler', 'CHECK ORDER')) ;
272+
}
273+
274+
// match mandatory FIELD
266275
if (instruccionAux.fields[camposInsertados].name != tmp_name) {
267276
return frm_langError(context,
268277
i18n_get_TagFor('compiler', 'UNEXPECTED FIELD') +
@@ -292,19 +301,14 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
292301
i18n_get_TagFor('compiler', 'OPEN PAREN. NOT FOUND')) ;
293302
}
294303

304+
// for future (semantic) checkings: keep track of the current context
305+
instruccionAux.fields[camposInsertados].context = Object.assign({}, context);
306+
295307
frm_nextToken(context);
296308
// match mandatory START_BIT
297309
instruccionAux.fields[camposInsertados].startbit = frm_getToken(context) ;
298310
instruccionAux.fields[camposInsertados].bits_start = [ parseInt(frm_getToken(context)) ] ;
299311

300-
// check startbit range
301-
var start = parseInt(instruccionAux.fields[camposInsertados].startbit);
302-
if (start > 32*parseInt(instruccionAux.nwords)-1) {
303-
return frm_langError(context,
304-
i18n_get_TagFor('compiler', 'STARTBIT OoR') +
305-
"'" + frm_getToken(context) + "'") ;
306-
}
307-
308312
frm_nextToken(context);
309313
// match mandatory ,
310314
if (! frm_isToken(context,",")) {
@@ -317,26 +321,6 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
317321
instruccionAux.fields[camposInsertados].stopbit = frm_getToken(context) ;
318322
instruccionAux.fields[camposInsertados].bits_stop = [ parseInt(frm_getToken(context)) ] ;
319323

320-
// check stopbit range
321-
var stop = parseInt(instruccionAux.fields[camposInsertados].stopbit);
322-
if (stop > 32*parseInt(instruccionAux.nwords)) {
323-
return frm_langError(context,
324-
i18n_get_TagFor('compiler', 'STOPBIT OoR') +
325-
"'" + frm_getToken(context) + "'") ;
326-
}
327-
328-
// check overlapping
329-
for (i=stop; i<=start; i++)
330-
{
331-
if (typeof instruccionAux.overlapping[i] != "undefined") {
332-
return frm_langError(context,
333-
i18n_get_TagFor('compiler', 'OVERLAPPING FIELD') +
334-
instruccionAux.fields[camposInsertados].name) ;
335-
}
336-
337-
instruccionAux.overlapping[i] = 1;
338-
}
339-
340324
frm_nextToken(context);
341325
// match mandatory )
342326
if (! frm_isToken(context,")")) {
@@ -382,7 +366,7 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
382366
tmp_fields.bits_stop = [ tmp_fields.stopbit ] ;
383367
instruccionAux.fields_all.push(tmp_fields) ;
384368
// </new>
385-
369+
386370
return {} ;
387371
}
388372

@@ -498,6 +482,38 @@ function firm_instruction_read_flexible_fields ( context, instruccionAux, xr_inf
498482
instruccionAux.fields = campos;
499483
instruccionAux.signatureRaw = firmaUsuario;
500484

485+
// semantic check: ranges in fields
486+
for (var k=0; k<camposInsertados; k++)
487+
{
488+
// check startbit range
489+
var start = parseInt(instruccionAux.fields[k].startbit);
490+
if (start > 32*parseInt(instruccionAux.nwords)-1) {
491+
return frm_langError(instruccionAux.fields[k].context,
492+
i18n_get_TagFor('compiler', 'STARTBIT OoR') +
493+
"'" + start + "'") ;
494+
}
495+
496+
// check stopbit range
497+
var stop = parseInt(instruccionAux.fields[k].stopbit);
498+
if (stop > 32*parseInt(instruccionAux.nwords)) {
499+
return frm_langError(instruccionAux.fields[k].context,
500+
i18n_get_TagFor('compiler', 'STOPBIT OoR') +
501+
"'" + stop + "'") ;
502+
}
503+
504+
// check overlapping
505+
for (var o=stop; o<=start; o++)
506+
{
507+
if (typeof instruccionAux.overlapping[o] != "undefined") {
508+
return frm_langError(instruccionAux.fields[k].context,
509+
i18n_get_TagFor('compiler', 'OVERLAPPING FIELD') +
510+
instruccionAux.fields[k].name) ;
511+
}
512+
513+
instruccionAux.overlapping[o] = 1;
514+
}
515+
}
516+
501517
// semantic check: co must exist
502518
if (1 != co_inserted)
503519
{

sim_sw/firmware/lexical.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,35 @@ function frm_isToken_arr ( context, arr )
189189
function frm_langError ( context, msgError )
190190
{
191191
// detect lines
192-
var line2 = 0 ;
193-
if (context.newlines.length > 0)
194-
line2 = context.newlines[context.newlines.length - 1] + 1;
195-
196192
var line1 = 0 ;
197-
if (context.newlines.length > 1)
198-
line1 = context.newlines[context.newlines.length - 2] + 1;
193+
if (typeof context.newlines[context.line-3] != "undefined") {
194+
line1 = context.newlines[context.line-3] + 1 ;
195+
}
199196

200-
var lowI = line1 ;
197+
var line2 = 0 ;
198+
if (typeof context.newlines[context.line-2] != "undefined") {
199+
line2 = context.newlines[context.line-2] + 1 ;
200+
}
201+
202+
var lowI = line1 ;
203+
var highI = line2 ;
201204

202-
var highI = Math.min(context.t - 1, line2+32);
203205
for (; (typeof context.text[highI+1] != "undefined") && (context.text[highI+1] != '\n'); highI++) ;
204206
var line3 = highI + 2 ;
205207

206208
highI++;
207209
for (; (typeof context.text[highI+1] != "undefined") && (context.text[highI+1] != '\n'); highI++) ;
208-
highI++;
210+
highI = highI + 2 ;
209211

210212
// print lines
211213
context.error = "<br>" +
212214
"<pre class='border rounded p-3 bg-dark text-white'>" +
213215
"...\n" ;
214216
for (var i=lowI; i<highI; i++)
215217
{
216-
if (i == line1) context.error += " " + (context.line-1) + "\t" ;
217-
if (i == line2) context.error += "*" + context.line + "\t" ;
218-
if (i == line3) context.error += " " + (context.line+1) + "\t" ;
218+
if ((i == line1) && (i != line2)) context.error += " " + (context.line-1) + "\t" ;
219+
if (i == line2) context.error += "*" + (context.line+0) + "\t" ;
220+
if (i == line3) context.error += " " + (context.line+1) + "\t" ;
219221

220222
if (typeof context.text[i] != "undefined")
221223
context.error += context.text[i] ;

ws_dist/min.sim_all.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ws_dist/min.wepsim_node.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ws_dist/min.wepsim_web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)