oop_SE.ttcn 21.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/******************************************************************************
 * Copyright (c) 2000-2020 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Baranyi, Botond
 *
 ******************************************************************************/

module oop_SE { //^In TTCN-3 module//

type component Comp {
  var integer cv_comp;
  const integer cc_comp := -1;
}

type port Port message {
  inout integer
}
with {
  extension "internal"
}

type record Rec {
  integer num,
  charstring str
}

const integer c := 3;

type class C0 { }

type class C1 extends Nonexistent { } //^In type definition// //^In superclass definition// //There is no local or imported definition with name `Nonexistent'//

type class C2 extends c { } //^In type definition// //^In superclass definition// //`c' is not a reference to a type//

type class C3 extends Rec { } //^In type definition// //^In superclass definition// //Class type expected instead of `@oop_SE.Rec'//


type class C4 {
  private var integer m_private_inherited;
  /*protected*/ var charstring m_protected_inherited;
  public var Rec m_public_inherited;
  private function f_private_inherited() {}
  /*protected*/ function f_protected_inherited() {}
  public function f_public_inherited() {}
}

type class C5 extends C4 { //^In type definition//
  private var boolean m_private_own;
  /*protected*/ var float m_protected_own;
  public var octetstring m_public_own;
  private function f_private_own() {}
  /*protected*/ function f_protected_own() {}
  public function f_public_own() {}
  
  public function f_member_access_inside() { //^In function definition//
    log(m_private_inherited); //^In log statement// //The member definition `m_private_inherited' in class type `C5' is not visible in this scope//
    log(m_protected_inherited);
    log(m_public_inherited);
    log(m_private_own);
    log(m_protected_own);
    log(m_public_own);
    log(m_nonexistent); //^In log statement// //There is no local or imported definition with name `m_nonexistent'//
    f_private_inherited(); //^In function or altstep instance// //The method definition `f_private_inherited' in class type `C5' is not visible in this scope//
    f_protected_inherited();
    f_public_inherited();
    f_private_own();
    f_protected_own();
    f_public_own();
    f_nonexistent(); //^In function or altstep instance// //There is no local or imported definition with name `f_nonexistent'//
  }
}

function f_member_access_outside() { //^In function definition//
  var C5 obj := C5.create(1, "a", { 2, "b" }, true, 0.1, '12'O);
  log(obj.m_private_inherited); //^In log statement// //The member definition `m_private_inherited' in class type `C5' is not visible in this scope//
  log(obj.m_protected_inherited); //^In log statement// //The member definition `m_protected_inherited' in class type `C5' is not visible in this scope//
  log(obj.m_public_inherited);
  log(obj.m_private_own); //^In log statement// //The member definition `m_private_own' in class type `C5' is not visible in this scope//
  log(obj.m_protected_own); //^In log statement// //The member definition `m_protected_own' in class type `C5' is not visible in this scope//
  log(obj.m_public_own);
  log(obj.m_nonexistent); //^In log statement// //Reference to non-existent member `m_nonexistent' in class type `@oop_SE.C5'//
  obj.f_private_inherited(); //^In function instance// //The method definition `f_private_inherited' in class type `C5' is not visible in this scope//
  obj.f_protected_inherited(); //^In function instance// //The method definition `f_protected_inherited' in class type `C5' is not visible in this scope//
  obj.f_public_inherited();
  obj.f_private_own(); //^In function instance// //The method definition `f_private_own' in class type `C5' is not visible in this scope//
  obj.f_protected_own(); //^In function instance// //The method definition `f_protected_own' in class type `C5' is not visible in this scope//
  obj.f_public_own();
  obj.f_nonexistent(); //^In function instance// //Reference to non-existent method `f_nonexistent' in class type `@oop_SE.C5'//
}

type class C6 { //^In type definition//
  public function f_member_access_other_class() { //^In function definition//
    var C5 obj := C5.create(1, "a", { 2, "b" }, true, 0.1, '12'O);
    log(obj.m_private_inherited); //^In log statement// //The member definition `m_private_inherited' in class type `C5' is not visible in this scope//
    log(obj.m_protected_inherited); //^In log statement// //The member definition `m_protected_inherited' in class type `C5' is not visible in this scope//
    log(obj.m_public_inherited);
    log(obj.m_private_own); //^In log statement// //The member definition `m_private_own' in class type `C5' is not visible in this scope//
    log(obj.m_protected_own); //^In log statement// //The member definition `m_protected_own' in class type `C5' is not visible in this scope//
    log(obj.m_public_own);
    log(obj.m_nonexistent); //^In log statement// //Reference to non-existent member `m_nonexistent' in class type `@oop_SE.C5'//
    obj.f_private_inherited(); //^In function instance// //The method definition `f_private_inherited' in class type `C5' is not visible in this scope//
    obj.f_protected_inherited(); //^In function instance// //The method definition `f_protected_inherited' in class type `C5' is not visible in this scope//
    obj.f_public_inherited();
    obj.f_private_own(); //^In function instance// //The method definition `f_private_own' in class type `C5' is not visible in this scope//
    obj.f_protected_own(); //^In function instance// //The method definition `f_protected_own' in class type `C5' is not visible in this scope//
    obj.f_public_own();
    obj.f_nonexistent(); //^In function instance// //Reference to non-existent method `f_nonexistent' in class type `@oop_SE.C5'//
  }
}


type class C7 extends C9 { //^In type definition// //^In superclass definition//
  public const integer x1 := 1;
}

type class C8 extends C7 { //^In type definition// //While checking embedded recursions\: Circular reference\: `@oop_SE.C8' -> `@oop_SE.C8.<superclass>' -> `@oop_SE.C7' -> `@oop_SE.C7.<superclass>' -> `@oop_SE.C9' -> `@oop_SE.C9.<superclass>' -> `@oop_SE.C8'//
  private var integer x2;
}

type class C9 extends C8 {} //^In type definition// //^In superclass definition//

127
128
129
130
131
132
external const C0 ec_c0; //^In external constant definition// //External constant cannot be defined for class type `@oop_SE.C0'//
external const object ec_obj; //^In external constant definition// //External constant cannot be defined for class type `object'//
modulepar C0 mp_c0; //^In module parameter definition// //Type of module parameter cannot be or embed class type `@oop_SE.C0'//
modulepar object mp_obj; //^In module parameter definition// //Type of module parameter cannot be or embed class type `object'//
modulepar template C0 mpt_c0; //^In template module parameter definition// //Type of template module parameter cannot be class type `@oop_SE.C0'//
modulepar template object mpt_obj; //^In template module parameter definition// //Type of template module parameter cannot be class type `object'//
133
134

function f_defs() { //^In function definition//
135
136
137
138
139
140
141
142
  const C0 c_c0 := null; //^In constant definition// //Constant cannot be defined for class type `@oop_SE.C0'//
  const object c_obj := null; //^In constant definition// //Constant cannot be defined for class type `object'//
  var C0 v_c0;
  var object v_obj;
  template C0 t_c0 := *; //^In template definition// //Template cannot be defined for class type `@oop_SE.C0'//
  template object t_obj := *; //^In template definition// //Template cannot be defined for class type `object'//
  var template C0 vt_c0; //^In template variable definition// //Template variable cannot be defined for class type `@oop_SE.C0'//
  var template object vt_obj; //^In template variable definition// //Template variable cannot be defined for class type `object'//
143
144
145
146
}


type record RecClass { //^In type definition//
147
148
  C0 x, //^In record field// //Class type `@oop_SE.C0' cannot be embedded into another type//
  object y //^In record field// //Class type `object' cannot be embedded into another type//
149
150
151
}

type set SetClass { //^In type definition//
152
153
  C0 x, //^In set field// //Class type `@oop_SE.C0' cannot be embedded into another type//
  object y //^In set field// //Class type `object' cannot be embedded into another type//
154
155
156
}

type record of C0 RecOfClass; //^In type definition// //^In embedded type of record of// //Class type `@oop_SE.C0' cannot be embedded into another type//
157
type record of object RecOfObject; //^In type definition// //^In embedded type of record of// //Class type `object' cannot be embedded into another type//
158
159

type set of C0 SetOfClass; //^In type definition// //^In embedded type of set of// //Class type `@oop_SE.C0' cannot be embedded into another type//
160
type set of object SetOfObject; //^In type definition// //^In embedded type of set of// //Class type `object' cannot be embedded into another type//
161
162

type union UniClass { //^In type definition//
163
164
  C0 x, //^In union field// //Class type `@oop_SE.C0' cannot be embedded into another type//
  object y //^In union field// //Class type `object' cannot be embedded into another type//
165
166
167
168
169
170
171
172
173
}

function f_embedded_types() { //^In function definition//
  var RecClass v_rec := { x := C0.create };
  var SetClass v_set := { x := C0.create };
  var RecOfClass v_recof := { C0.create };
  var SetOfClass v_setof := { C0.create };
  var UniClass v_uni := { x := C0.create };
  var anytype v_any; //^In variable definition// //^In type definition//
Botond Baranyi's avatar
Botond Baranyi committed
174
  v_any.C0 := C0.create;
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
}


function f_type_compatibility() { //^In function definition//
  var C4 x1 := C4.create(1, "a", { 2, "b" });
  var C5 y1 := C4.create(1, "a", { 2, "b" }); //^In variable definition// //Incompatible class types: operation `create' should refer to `@oop_SE.C5' instead of `@oop_SE.C4'//
  var C4 x2 := C5.create(1, "a", { 2, "b" }, true, 0.1, '12'O);
  var C5 y2 := C5.create(1, "a", { 2, "b" }, true, 0.1, '12'O);
  var C4 x3 := y1;
  var C5 y3 := x1; //^In variable definition// //Type mismatch: a value of type `@oop_SE.C5' was expected instead of `@oop_SE.C4'//
  x3 := y2;
  y3 := x2; //^In variable assignment// //Type mismatch: a value of type `@oop_SE.C5' was expected instead of `@oop_SE.C4'//
  log(x1.m_public_inherited);
  log(y1.m_public_inherited);
  log(x1.m_public_own); //^In log statement// //Reference to non-existent member `m_public_own' in class type `@oop_SE.C4'//
  log(y1.m_public_own);
  x1.f_public_inherited();
  y1.f_public_inherited();
  x1.f_public_own(); //^In function instance// //Reference to non-existent method `f_public_own' in class type `@oop_SE.C4'//
  y1.f_public_own();
}


type component CT_RunsOn {
  var integer cv_runs_on;
  const integer cc_runs_on := 0;
}

type component CT_Mtc {
  var integer cv_mtc;
  const integer cc_mtc := 1;
206
  port Port pt;
207
208
209
210
211
}

type component CT_System {
  var integer cv_system;
  const integer cc_system := 2;
212
213
214
215
216
217
218
219
220
221
222
223
224
  port Port pt;
}

type component CT_RunsOn2 extends CT_RunsOn {
  var template integer cvt_runs_on := *;
}

type component CT_Mtc2 extends CT_Mtc {
  var template integer cvt_mtc := ?;
}

type component CT_System2 extends CT_System {
  var template integer cvt_system := omit;
225
226
227
228
229
230
231
232
233
234
235
236
237
238
}

type class C10 runs on CT_RunsOn mtc CT_Mtc system CT_System { //^In type definition//
  public function f_comp_visibility(in integer p1 := cc_runs_on, //^In function definition// //^In formal parameter list//
                                    in integer p2 := cc_mtc,
                                    in integer p3 := cc_system,
                                    in integer p4 := cc_comp) { //^In parameter// //^In default value// //There is no local or imported definition with name `cc_comp'//
    log(cv_runs_on);
    log(cv_mtc);
    log(cv_system);
    log(cv_comp); //^In log statement// //There is no local or imported definition with name `cv_comp'//
  }
}

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
type class C11 extends C10 { //^In type definition//
  public function f_inherited_comp_visibility(in integer p1 := cc_runs_on, //^In function definition// //^In formal parameter list//
                                              in integer p2 := cc_mtc,
                                              in integer p3 := cc_system,
                                              in integer p4 := cc_comp) { //^In parameter// //^In default value// //There is no local or imported definition with name `cc_comp'//
    log(cv_runs_on);
    log(cv_mtc);
    log(cv_system);
    log(cv_comp); //^In log statement// //There is no local or imported definition with name `cv_comp'//
  }
}

type class C12 extends C10 runs on CT_RunsOn mtc CT_Mtc system CT_System { }

type class C13 extends C11 //^In type definition//
  runs on Comp //^In `runs on' clause// //The `runs on' component type of the subclass, `@oop_SE.Comp', is not compatible with the `runs on' component type of the superclass, `@oop_SE.CT_RunsOn'//
  mtc Comp //^In `mtc' clause// //The `mtc' component type of the subclass, `@oop_SE.Comp', is not compatible with the `mtc' component type of the superclass, `@oop_SE.CT_Mtc'//
  system Comp //^In `system' clause// //The `system' component type of the subclass, `@oop_SE.Comp', is not compatible with the `system' component type of the superclass, `@oop_SE.CT_System'//
  { }

type class C14 extends C11
  runs on CT_RunsOn2
  mtc CT_Mtc2
  system CT_System2
  { }

function f_good_comp_usage() runs on CT_RunsOn mtc CT_Mtc system CT_System {
  var C11 x := C11.create;
}

function f_bad_comp_usage() runs on Comp mtc Comp system Comp { //^In function definition//
  var C11 x := C11.create; //^In variable definition// //Runs on clause mismatch: A definition that runs on component type `@oop_SE.Comp' cannot create a value of class type `@oop_SE.C11', which runs on `@oop_SE.CT_RunsOn'// //Mtc clause mismatch: A definition that runs on component type `@oop_SE.Comp' cannot create a value of class type `@oop_SE.C11', which has `mtc' component type `@oop_SE.CT_Mtc'// //System clause mismatch: A definition that runs on component type `@oop_SE.Comp' cannot create a value of class type `@oop_SE.C11', which has `system' component type `@oop_SE.CT_System'//
}

function f_no_comp_usage() { //^In function definition//
  var C11 x := C11.create; //^In variable definition// //A definition without `runs on' clause cannot create a value of class type `@oop_SE.C11', which runs on component type `@oop_SE.CT_RunsOn'//
}


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
type class C15 {
  public var integer v;
  public function f() { }
  public function g() return boolean { return true; }
}

function f_access_with_class_name() { //^In function definition//
  log(C5.v); //^In log statement// //Reference to a value, template, timer, port or class object was expected instead of type `@oop_SE.C5'//
  log(C5.g()); //^In log statement// //Reference to a value, template, timer, port or class object was expected instead of type `@oop_SE.C5'//
  C5.f(); //Reference to a function or altstep was expected instead of type `@oop_SE.C5', which cannot be invoked//
  C5.g(); //Reference to a function or altstep was expected instead of type `@oop_SE.C5', which cannot be invoked//
  if (C5.g()) { log(1); } //^In if statement// //Reference to a value was expected instead of type `@oop_SE.C5'//
  if (C5.v == 1) { log(2); } //^In if statement// //Reference to a value was expected instead of type `@oop_SE.C5'//
  var integer x1 := C5.v + 1; //^In variable definition// //^In the left operand of operation// //Reference to a value was expected instead of type `@oop_SE.C5'//
  var boolean x2 := C5.g(); //^In variable definition// //Reference to a value was expected instead of type `@oop_SE.C5'//
}


function f_init_values() { //^In function definition//
  var integer v_int := 3;
  var template integer vt_int := (1..10);
  var C4 v1 := 1; //^In variable definition// //class value was expected//
  var C4 v2 := v_int; //^In variable definition// //Type mismatch\: a value of type `@oop_SE.C4' was expected instead of `integer'//
  var C4 v3 := valueof(vt_int) + v_int; //^In variable definition// //Incompatible value\: `@oop_SE.C4' value was expected//
  var C4 v4 := CT_RunsOn.create; //^In variable definition// //Incompatible value\: `@oop_SE.C4' value was expected//
  var C4 v5 := C11.create; //^In variable definition// //Incompatible class types\: operation `create' should refer to `@oop_SE.C4' instead of `@oop_SE.C11'//
}


type class C16 extends C15 { //^In type definition//
  create() : C15(1) { } //Previous definition of `create' is here//
  create(in integer p) : C15(p) { } //Duplicate definition with name `create'//
}

type class C17 { //^In type definition//
  create() : C15(1) { } //^In constructor definition// //^In super-constructor call// //Class type `@oop_SE.C17' does not have a superclass//
}

type class C18 extends C15 { //^In type definition//
  create() : C16() { } //^In constructor definition// //^In super-constructor call// //expected call to constructor of class type `@oop_SE.C15', instead of class type `@oop_SE.C16'//
}

type class C19 extends C15 { //^In type definition//
  create() { } //^In constructor definition// //Missing super-constructor call//
}

type class C20 extends C15 { //^In type definition//
  create() : f_embedded_types() { } //^In constructor definition// //^In super-constructor call// //Reference to constructor was expected instead of function//
}


type class @final @abstract C21 { } //^In type definition// //Final classes cannot be abstract//

type class @final C22 { }

type class C23 extends C22 { } //^In type definition// //^In superclass definition// //The superclass cannot be final//

type class @abstract C24 { //^In type definition//
  public function @abstract f1(in Nonexistent a); //^In abstract function definition// //^In formal parameter list// //^In parameter// //There is no local or imported definition with name `Nonexistent'//
  public function @abstract f2() return template Nonexistent; //^In abstract function definition// //^In return type// //There is no local or imported definition with name `Nonexistent'//
  public function @abstract f3() return Port; //^In abstract function definition// //^In return type// //Port type `@oop_SE.Port' cannot be the return type of an abstract function//
}

function f_inst_abstract() { //^In function definition//
  var C24 x := C24.create; //^In variable definition// //Cannot create an instance of abstract class type `@oop_SE.C24'//
}

type class @abstract C25 {
  public function @abstract f_abs() return integer;
}

type class @abstract C26 extends C25 {
  public function @abstract f_abs2(inout template integer p);
}

type class C27 extends C26 { } //^In type definition// //Missing implementation of abstract method `@oop_SE.C25.f_abs'// //Missing implementation of abstract method `@oop_SE.C26.f_abs2'//

type class C28 extends C25 { //^In type definition//
  public var integer f_abs; //variable `@oop_SE.C28.f_abs' shadows inherited abstract method `@oop_SE.C25.f_abs'//
}

type class C29 extends C26 { //^In type definition// //Missing implementation of abstract method `@oop_SE.C25.f_abs'//
  public function f_abs2(inout template integer p) { }
}

type class C30 extends C26 {
  public function f_abs() return integer { return 1; }
  public function f_abs2(inout template integer p) { }
}

type class C31 extends C25 { //^In type definition//
  public function f_abs(in template integer p) { } //The prototype of method `f_abs' is not identical to that of inherited abstract method `@oop_SE.C25.f_abs'//
}

type class C32 extends C25 { //^In type definition//
  public function f_abs(inout integer p) { } //The prototype of method `f_abs' is not identical to that of inherited abstract method `@oop_SE.C25.f_abs'//
}

type class C33 extends C25 { //^In type definition//
  public function f_abs(inout template integer q) { } //The prototype of method `f_abs' is not identical to that of inherited abstract method `@oop_SE.C25.f_abs'//
}

type class C34 extends C25 { //^In type definition//
  public function f_abs(inout template integer p) return boolean { return false; } //The prototype of method `f_abs' is not identical to that of inherited abstract method `@oop_SE.C25.f_abs'//
}

384
385
386
387
388
389
390
391
type class @abstract C35 {
  public function @abstract f(in object p) return object;
}

type class C36 extends C35 {
  public function f(in object p) return object { return p; }
}

392

393
type class C37 {
394
395
396
397
398
399
400
401
  public const integer c := 3;
  public template charstring t := "";
  public function f1() return Rec { return { 2, "a" }; }
  public function f2() return template charstring { return ?; }
  create() {}
}

function f_left_hand_side() { //^In function definition//
402
403
404
405
406
407
  var C37 x := C37.create;
  x.c := 2; //^In variable assignment// //Reference to a variable or template variable was expected instead of constant `@oop_SE.C37.c'//
  x.t := *; //^In variable assignment// //Reference to a variable or template variable was expected instead of template `@oop_SE.C37.t'//
  x.f1() := { 3, "b" }; //^In variable assignment// //Reference to a variable or template variable was expected instead of function `@oop_SE.C37.f1'//
  x.f1().num := 3; //^In variable assignment// //Reference to a variable or template variable was expected instead of function `@oop_SE.C37.f1'//
  x.f2() := "x"; //^In variable assignment// //Reference to a variable or template variable was expected instead of function `@oop_SE.C37.f2'//
408
409
410
}


411
412
413
control { //^In control part//
  var C11 x := C11.create; //^In variable definition// //A definition without `runs on' clause cannot create a value of class type `@oop_SE.C11', which runs on component type `@oop_SE.CT_RunsOn'// //Cannot create value of class type `@oop_SE.C11', which has an `mtc' clause, in the control part.// //Cannot create value of class type `@oop_SE.C11', which has a `system' clause, in the control part.//
}
414
415
416

}
with {
417
  extension "anytype C0, object" //^In anytype field// //Class type `@oop_SE.C0' cannot be embedded into another type// //Class type `object' cannot be added to the anytype//
418
}