tests/syntax/identifier/identifier_as_variable1.test
changeset 108 f9e001952488
child 267 0a1204bcc9af
equal deleted inserted replaced
107:ff5c92df0c78 108:f9e001952488
       
     1 (* Test whether the keyword XXXX may be used as an identifier for:
       
     2  * variable name/identifier
       
     3  *
       
     4  * The XXXX names in the following code are merely a placeholder.
       
     5  * They will be replaced by several identifiers before actual testing
       
     6  * of the compiler.
       
     7  *)
       
     8 
       
     9 (* The identifiers that will replace the XXXX
       
    10  * must be placed on a line starting with #
       
    11  * All identifiers preceded by # are ignored!
       
    12  * The identifier list must be placed inside an IEC 61131-3 comment.
       
    13  *)
       
    14 (*
       
    15 #IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN
       
    16 #SFC_qualifiers D DS L N P #R #S SD SL
       
    17      NOTE: R and S are identical to IL operators!!
       
    18 #Task_initialisers PRIORITY SINGLE INTERVAL
       
    19 *)
       
    20 
       
    21 (* NOTE: The identifier as a variable test has some special cases.
       
    22  *       Namely, when using IL operators as variable names.
       
    23  *       Even though the syntax of the IL language would not result
       
    24  *       in ambiguities in the above case, our parser does not currently
       
    25  *       allow the use of variables (with names identical to IL
       
    26  *       operators) within IL code.
       
    27  *
       
    28  *       The following test code must therefore consider two possibilities:
       
    29  *        - if the identifier under test is an IL operator
       
    30  *        - if the identifier under test is not an IL operator
       
    31  * 
       
    32  *       The test code in this file should be valid for all identifiers.
       
    33  *       Test code that is only valid for identifiers not identical to IL operators 
       
    34  *        is placed in another test file (identifier_as_variable2.test).
       
    35  *)
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 (* A helper FUNCTION BLOCK declaration *)
       
    41 function_block foo_fb
       
    42  var_input
       
    43   a_1, b_1: int;
       
    44  end_var
       
    45  var_output
       
    46   c_1, d_1: int;
       
    47  end_var
       
    48   c_1 := 10 + b_1;
       
    49 end_function_block
       
    50 
       
    51 
       
    52 (* A helper FUNCTION declaration *)
       
    53 function foo_f1 : int
       
    54  var_input
       
    55   a_1, b_1: int;
       
    56  end_var
       
    57  var_output
       
    58   c_1, d_1: int;
       
    59  end_var
       
    60   c_1 := 10 + b_1;
       
    61 end_function
       
    62 
       
    63 (* Another helper FUNCTION declaration *)
       
    64 function foo_f2 : int
       
    65  var_input
       
    66   a_1, b_1: foo_fb;
       
    67  end_var
       
    68  var_output
       
    69   c_1, d_1: int;
       
    70  end_var
       
    71   c_1 := 10;
       
    72 end_function
       
    73 
       
    74 
       
    75 
       
    76 (*********************************************************************)
       
    77 (* Testing use of XXXX in several locations of variable declarations *)
       
    78 (*********************************************************************)
       
    79 
       
    80 function bar01 : int
       
    81  var_input
       
    82   XXXX, a_1, b_1: int;
       
    83  end_var
       
    84  a_1 := 1;
       
    85 end_function
       
    86 
       
    87 function_block bar02
       
    88  var_input
       
    89    a_1, XXXX, b_1: int;
       
    90  end_var
       
    91  a_1 := 1;
       
    92 end_function_block
       
    93 
       
    94 function_block bar03
       
    95  var_input
       
    96    a_1, b_1, XXXX: int;
       
    97  end_var
       
    98  a_1 := 1;
       
    99 end_function_block
       
   100 
       
   101 
       
   102 function_block bar04
       
   103  var_output
       
   104   XXXX, a_1, b_1: int;
       
   105  end_var
       
   106  a_1 := 1;
       
   107 end_function_block
       
   108 
       
   109 function_block bar05
       
   110  var_output
       
   111    a_1, XXXX, b_1: int;
       
   112  end_var
       
   113  a_1 := 1;
       
   114 end_function_block
       
   115 
       
   116 function_block bar06
       
   117  var_output
       
   118    a_1, b_1, XXXX: int;
       
   119  end_var
       
   120  a_1 := 1;
       
   121 end_function_block
       
   122 
       
   123 
       
   124 function_block bar07
       
   125  var_in_out
       
   126   XXXX, a_1, b_1: int;
       
   127  end_var
       
   128  a_1 := 1;
       
   129 end_function_block
       
   130 
       
   131 function_block bar08
       
   132  var_in_out
       
   133    a_1, XXXX, b_1: int;
       
   134  end_var
       
   135  a_1 := 1;
       
   136 end_function_block
       
   137 
       
   138 function_block bar09
       
   139  var_in_out
       
   140    a_1, b_1, XXXX: int;
       
   141  end_var
       
   142  a_1 := 1;
       
   143 end_function_block
       
   144 
       
   145 function_block bar10
       
   146  var_external
       
   147    XXXX: int;
       
   148    a_1 : int;
       
   149  end_var
       
   150  a_1 := 1;
       
   151 end_function_block
       
   152 
       
   153 function_block bar11
       
   154  var_external
       
   155    a_1 : int;
       
   156    XXXX : int;
       
   157  end_var
       
   158  a_1 := 1;
       
   159 end_function_block
       
   160 
       
   161 function_block bar12
       
   162  var
       
   163   XXXX, a_1, b_1: int;
       
   164  end_var
       
   165  a_1 := 1;
       
   166 end_function_block
       
   167 
       
   168 function_block bar13
       
   169  var
       
   170    a_1, XXXX, b_1: int;
       
   171  end_var
       
   172  a_1 := 1;
       
   173 end_function_block
       
   174 
       
   175 function_block bar14
       
   176  var
       
   177    a_1, b_1, XXXX: int;
       
   178  end_var
       
   179  a_1 := 1;
       
   180 end_function_block
       
   181 
       
   182 
       
   183 
       
   184 (************************************************)
       
   185 (* Using XXXX as a standard variable name in ST *)
       
   186 (************************************************)
       
   187 
       
   188 function_block bar90
       
   189  var
       
   190   e_1, f_1 : int;
       
   191   XXXX : int;
       
   192   fb : foo_fb;
       
   193  end_var
       
   194   e_1 := bar01 (XXXX := 10);
       
   195   e_1 := bar01 (a_1 := XXXX);
       
   196   e_1 := bar01 (XXXX := XXXX);
       
   197   fb(XXXX, 20);
       
   198   fb (10, XXXX, e_1, f_1);
       
   199   fb (a_1 := XXXX, b_1:=XXXX, c_1=>XXXX, d_1=>f_1);
       
   200   fb(a_1 := 10, b_1:=20, c_1=>e_1, d_1=>XXXX);
       
   201   fb (c_1=>XXXX, a_1:=20, d_1=>f_1);
       
   202   XXXX := fb.c_1;
       
   203   fb.a_1 := XXXX + XXXX * 2 * (XXXX) / foo_f1(XXXX, 10, XXXX, e_1) MOD XXXX MOD XXXX ** XXXX;
       
   204   IF (XXXX >= 10) THEN XXXX := 10; END_IF;
       
   205   CASE (XXXX + 10) OF
       
   206     10: XXXX := 10; 
       
   207     10..20:XXXX := 20;
       
   208     ELSE XXXX := 20;
       
   209   END_CASE;
       
   210   FOR XXXX := 10 TO 20 BY 2 DO
       
   211     XXXX := XXXX + 1;
       
   212   END_FOR;
       
   213   FOR e_1 := XXXX TO 20 DO
       
   214     XXXX := XXXX + 1;
       
   215   END_FOR;
       
   216   FOR e_1 := 10 TO XXXX BY 2 DO
       
   217     XXXX := XXXX + 1;
       
   218   END_FOR;
       
   219   FOR e_1 := 10 TO XXXX DO
       
   220     XXXX := XXXX + 1;
       
   221   END_FOR;
       
   222   FOR e_1 := 10 TO 20 BY XXXX DO
       
   223     XXXX := XXXX + 1;
       
   224   END_FOR;
       
   225   WHILE (XXXX >= 10) DO 
       
   226     XXXX := 10; 
       
   227   END_WHILE;
       
   228   REPEAT XXXX := 10; UNTIL (XXXX >= 10) END_REPEAT;
       
   229 end_function_block
       
   230 
       
   231 
       
   232 
       
   233 (* Using XXXX as a function block instance/variable name in ST *)
       
   234 
       
   235 function_block bar91
       
   236  var
       
   237   e_1, f_1 : int;
       
   238   XXXX : foo_fb;
       
   239  end_var
       
   240   XXXX(e_1, 20);
       
   241   XXXX (10, e_1, e_1, f_1);
       
   242   XXXX (a_1 := e_1, b_1:=e_1 , c_1=>e_1, d_1=>f_1);
       
   243   XXXX(a_1 := 10, b_1:=20, c_1=>e_1, d_1=>e_1);
       
   244   XXXX (c_1=>e_1, a_1:=20, d_1=>f_1);
       
   245   e_1 := XXXX.c_1;
       
   246   XXXX.a_1 := e_1;
       
   247   e_1 := foo_f2(XXXX, XXXX, e_1, f_1);
       
   248   e_1 := foo_f2 (XXXX, XXXX);
       
   249   e_1 := foo_f2 (c_1 => e_1, b_1 := XXXX, d_1 := 10, a_1 := XXXX);
       
   250   e_1 := foo_f2 (b_1 := XXXX);
       
   251 end_function_block
       
   252 
       
   253 
       
   254 
       
   255 
       
   256 (************************************************)
       
   257 (* Using XXXX as a standard variable name in IL *)
       
   258 (************************************************)
       
   259 
       
   260 (* NOTE: Currently not supported for identifiers identical to IL operators.
       
   261  *       We therefore have two versions of this file, one with the following code
       
   262  *       commented out (used to test the identifiers that clash with IL operators)
       
   263  *       and a second with the following code included (used to test identifiers
       
   264  *       that do not clash with IL operators, such as PRIORITY, SINGLE, etc...)
       
   265  *)
       
   266 
       
   267 
       
   268 (*
       
   269 function_block bar93
       
   270  var
       
   271   e_1, f_1 : int;
       
   272  end_var
       
   273 
       
   274  (* Calling function with input parameter named XXXX **
       
   275  bar01 (
       
   276   XXXX := 10
       
   277  )
       
   278 end_function_block
       
   279 *)
       
   280 
       
   281 
       
   282 (*
       
   283 function_block bar99
       
   284 (...)
       
   285 end_function_block
       
   286 *)
       
   287 
       
   288 
       
   289 
       
   290 
       
   291 
       
   292 
       
   293 (*************************************************************************************)
       
   294 (* Using XXXX as a function block instance/variable/program name in a configuration. *)
       
   295 (*************************************************************************************)
       
   296 
       
   297 (* a helper program *)
       
   298 PROGRAM bar000
       
   299 VAR_INPUT
       
   300   a_1, XXXX : BOOL;
       
   301 END_VAR
       
   302 VAR_OUTPUT
       
   303   b_1 : BOOL;
       
   304 END_VAR
       
   305   a_1 := TRUE;
       
   306 END_PROGRAM
       
   307 
       
   308 
       
   309  (* using in program parameter *)
       
   310 CONFIGURATION config01
       
   311  TASK fast(PRIORITY := 4);
       
   312  PROGRAM foo WITH fast:
       
   313        bar000(a_1 := TRUE, XXXX := FALSE);
       
   314 END_CONFIGURATION
       
   315 
       
   316 
       
   317  (* using as a program name *)
       
   318 CONFIGURATION config02
       
   319  TASK fast(PRIORITY := 4);
       
   320  PROGRAM XXXX WITH fast:
       
   321        bar000(a_1 := TRUE, XXXX := FALSE);
       
   322 END_CONFIGURATION
       
   323 
       
   324 
       
   325  (* using as a resource name *)
       
   326 CONFIGURATION config03
       
   327  RESOURCE XXXX on processor_type_1
       
   328    TASK fast(PRIORITY := 4);
       
   329    PROGRAM foo WITH fast:
       
   330            bar000(a_1 := TRUE, XXXX := FALSE);
       
   331  END_RESOURCE
       
   332 END_CONFIGURATION
       
   333 
       
   334 
       
   335  (* using as a task name *)
       
   336 CONFIGURATION config11
       
   337  TASK XXXX(PRIORITY := 4);
       
   338  PROGRAM foo WITH XXXX:
       
   339        bar000(a_1 := TRUE, XXXX := FALSE);
       
   340 END_CONFIGURATION
       
   341 
       
   342 
       
   343 CONFIGURATION config12
       
   344  TASK XXXX(SINGLE := 3, PRIORITY := 4);
       
   345  PROGRAM P1 WITH XXXX:
       
   346        bar000(a_1 := TRUE, XXXX := FALSE);
       
   347 END_CONFIGURATION
       
   348 
       
   349 
       
   350 CONFIGURATION config13
       
   351  TASK XXXX(INTERVAL := T#1s, PRIORITY := 4);
       
   352  PROGRAM P1 WITH XXXX:
       
   353        bar000(a_1 := TRUE, XXXX := FALSE);
       
   354 END_CONFIGURATION
       
   355 
       
   356 
       
   357 CONFIGURATION config14
       
   358  TASK XXXX(SINGLE := 3, INTERVAL := T#1s, PRIORITY := 4);
       
   359  PROGRAM P1 WITH XXXX:
       
   360        bar000(a_1 := TRUE, XXXX := FALSE);
       
   361 END_CONFIGURATION
       
   362 
       
   363 
       
   364  (* using as a variable name *)
       
   365 CONFIGURATION config21
       
   366  VAR_GLOBAL
       
   367   XXXX : bool;
       
   368  END_VAR
       
   369  TASK fast(PRIORITY := 4);
       
   370  PROGRAM foo WITH fast:
       
   371        bar000(a_1 := XXXX, b_1 => XXXX, XXXX := XXXX);
       
   372 END_CONFIGURATION
       
   373 
       
   374 
       
   375 
       
   376 
       
   377 
       
   378 
       
   379 
       
   380 
       
   381 
       
   382 
       
   383 
       
   384 
       
   385 (* Checking whether the use of XXXX will confuse any other
       
   386  * normal and correct IL or ST code.
       
   387  *)
       
   388 {#include "basic_code.test" }
       
   389