@@ -261,8 +261,17 @@ function firm_instruction_cop_read ( context, instruccionAux, all_ones_co )
261
261
262
262
function firm_instruction_field_read ( context , instruccionAux , camposInsertados )
263
263
{
264
- // match mandatory FIELD
265
264
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
266
275
if ( instruccionAux . fields [ camposInsertados ] . name != tmp_name ) {
267
276
return frm_langError ( context ,
268
277
i18n_get_TagFor ( 'compiler' , 'UNEXPECTED FIELD' ) +
@@ -292,19 +301,14 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
292
301
i18n_get_TagFor ( 'compiler' , 'OPEN PAREN. NOT FOUND' ) ) ;
293
302
}
294
303
304
+ // for future (semantic) checkings: keep track of the current context
305
+ instruccionAux . fields [ camposInsertados ] . context = Object . assign ( { } , context ) ;
306
+
295
307
frm_nextToken ( context ) ;
296
308
// match mandatory START_BIT
297
309
instruccionAux . fields [ camposInsertados ] . startbit = frm_getToken ( context ) ;
298
310
instruccionAux . fields [ camposInsertados ] . bits_start = [ parseInt ( frm_getToken ( context ) ) ] ;
299
311
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
-
308
312
frm_nextToken ( context ) ;
309
313
// match mandatory ,
310
314
if ( ! frm_isToken ( context , "," ) ) {
@@ -317,26 +321,6 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
317
321
instruccionAux . fields [ camposInsertados ] . stopbit = frm_getToken ( context ) ;
318
322
instruccionAux . fields [ camposInsertados ] . bits_stop = [ parseInt ( frm_getToken ( context ) ) ] ;
319
323
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
-
340
324
frm_nextToken ( context ) ;
341
325
// match mandatory )
342
326
if ( ! frm_isToken ( context , ")" ) ) {
@@ -382,7 +366,7 @@ function firm_instruction_field_read ( context, instruccionAux, camposInsertados
382
366
tmp_fields . bits_stop = [ tmp_fields . stopbit ] ;
383
367
instruccionAux . fields_all . push ( tmp_fields ) ;
384
368
// </new>
385
-
369
+
386
370
return { } ;
387
371
}
388
372
@@ -498,6 +482,38 @@ function firm_instruction_read_flexible_fields ( context, instruccionAux, xr_inf
498
482
instruccionAux . fields = campos ;
499
483
instruccionAux . signatureRaw = firmaUsuario ;
500
484
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
+
501
517
// semantic check: co must exist
502
518
if ( 1 != co_inserted )
503
519
{
0 commit comments