1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
12 * Szabo, Janos Zoltan – initial implementation
14 ******************************************************************************/
15 #ifndef _Asn_Object_HH
16 #define _Asn_Object_HH
20 #include "../Value.hh"
25 using namespace Common;
30 class FieldSpec_Undef;
31 class FieldSpec_Error;
36 class FieldSpec_VS_FT;
37 class FieldSpec_VS_VT;
52 class FieldSetting_Type;
53 class FieldSetting_Value;
55 class FieldSetting_OS;
60 class OSE_Visitor; // in Object0.hh
68 * Class to represent ObjectClassDefinition
70 class OC_defn : public ObjectClass {
72 Block *block_fs; /**< field specs block */
73 Block *block_ws; /**< WITH SYNTAX block */
74 FieldSpecs *fss; /**< field specs */
75 OCS_root *ocs; /**< object class syntax */
79 OC_defn(const OC_defn& p);
82 OC_defn(Block *p_block_fs, Block *p_block_ws);
84 virtual OC_defn* clone() const {return new OC_defn(*this);}
85 virtual void set_fullname(const string& p_fullname);
86 virtual OC_defn* get_refd_last(ReferenceChain * =0) {return this;}
88 virtual void chk_this_obj(Object *obj);
89 virtual OCS_root* get_ocs();
90 virtual FieldSpecs* get_fss();
91 virtual void generate_code(output_struct *target);
92 virtual void dump(unsigned level) const;
94 void parse_block_fs();
98 * Class to represent a ReferencedObjectClass. It is a DefinedOC or
99 * OCFromObject or ValueSetFromObjects.
101 class OC_refd : public ObjectClass {
105 ObjectClass *oc_refd; /**< cache */
106 OC_defn *oc_defn; /**< cache */
108 OC_refd(const OC_refd& p);
110 OC_refd(Reference *p_ref);
112 virtual OC_refd* clone() const {return new OC_refd(*this);}
113 virtual void set_my_scope(Scope *p_scope);
114 virtual void set_fullname(const string& p_fullname);
115 ObjectClass* get_refd(ReferenceChain *refch=0);
116 virtual OC_defn* get_refd_last(ReferenceChain *refch=0);
118 virtual void chk_this_obj(Object *p_obj);
119 virtual OCS_root* get_ocs();
120 virtual FieldSpecs* get_fss();
121 virtual void generate_code(output_struct *target);
122 virtual void dump(unsigned level) const;
126 * Class to represent a FieldSpec of an ObjectClass.
128 class FieldSpec : public Node, public Location {
131 FS_UNDEF, /**< undefined */
132 FS_ERROR, /**< erroneous fieldspec */
133 FS_T, /**< type fieldspec */
134 FS_V_FT, /**< fixedtype value fieldspec */
135 FS_V_VT, /**< variabletype value fieldspec */
136 FS_VS_FT, /**< fixedtype valueset fieldspec */
137 FS_VS_VT, /**< variabletype valueset fieldspec */
138 FS_O, /**< object fieldspec */
139 FS_OS /**< objectset fieldspec */
141 protected: // Several derived classes need access
148 FieldSpec(const FieldSpec& p);
150 FieldSpec(fstype_t p_fstype, Identifier *p_id, bool p_is_optional);
151 virtual ~FieldSpec();
152 virtual FieldSpec* clone() const =0;
153 virtual void set_fullname(const string& p_fullname);
154 virtual const Identifier& get_id() const {return *id;}
155 virtual fstype_t get_fstype() {return fstype;}
156 virtual void set_my_oc(OC_defn *p_oc);
157 bool get_is_optional() {return is_optional;}
158 virtual bool has_default() =0;
159 virtual void chk() =0;
160 virtual Setting* get_default() =0;
161 virtual FieldSpec* get_last() {return this;}
162 virtual void generate_code(output_struct *target) =0;
166 * Class to represent an undefined FieldSpec.
168 class FieldSpec_Undef : public FieldSpec {
171 Node* defsetting; /**< default setting */
172 FieldSpec *fs; /**< the classified fieldspec */
174 void classify_fs(ReferenceChain *refch=0);
175 FieldSpec_Undef(const FieldSpec_Undef& p);
177 FieldSpec_Undef(Identifier *p_id, Ref_defd* p_govref,
178 bool p_is_optional, Node *p_defsetting);
179 virtual ~FieldSpec_Undef();
180 virtual FieldSpec* clone() const;
181 virtual void set_fullname(const string& p_fullname);
182 virtual fstype_t get_fstype();
183 virtual void set_my_oc(OC_defn *p_oc);
184 virtual bool has_default();
186 virtual Setting* get_default();
187 virtual FieldSpec* get_last();
188 virtual void generate_code(output_struct *target);
191 class FieldSpec_Error : public FieldSpec {
193 Setting *setting_error;
194 bool has_default_flag;
196 FieldSpec_Error(const FieldSpec_Error& p);
198 FieldSpec_Error(Identifier *p_id, bool p_is_optional,
200 virtual ~FieldSpec_Error();
201 virtual FieldSpec_Error* clone() const;
202 virtual bool has_default();
203 virtual Setting* get_default();
205 virtual void generate_code(output_struct *target);
209 * Class to represent a TypeFieldSpec.
211 class FieldSpec_T : public FieldSpec {
213 Type *deftype; /**< default type */
215 FieldSpec_T(const FieldSpec_T& p);
217 FieldSpec_T(Identifier *p_id, bool p_is_optional, Type *p_deftype);
218 virtual ~FieldSpec_T();
219 virtual FieldSpec_T* clone() const
220 {return new FieldSpec_T(*this);}
221 virtual void set_fullname(const string& p_fullname);
222 virtual void set_my_oc(OC_defn *p_oc);
223 virtual bool has_default() {return deftype;}
224 virtual Type* get_default();
226 virtual void generate_code(output_struct *target);
230 * Class to represent a FixedTypeValueFieldSpec.
232 class FieldSpec_V_FT : public FieldSpec {
234 Type *fixtype; /**< fixed type */
236 Value *defval; /**< default value */
238 FieldSpec_V_FT(const FieldSpec_V_FT& p);
240 FieldSpec_V_FT(Identifier *p_id, Type *p_fixtype, bool p_is_unique,
241 bool p_is_optional, Value *p_defval);
242 virtual ~FieldSpec_V_FT();
243 virtual FieldSpec_V_FT* clone() const
244 {return new FieldSpec_V_FT(*this);}
245 virtual void set_fullname(const string& p_fullname);
246 virtual void set_my_oc(OC_defn *p_oc);
247 virtual bool has_default() {return defval;}
248 virtual Value* get_default();
249 Type* get_type() {return fixtype;}
251 virtual void generate_code(output_struct *target);
257 * Class to represent a VariableTypeValueFieldSpec.
259 class FieldSpec_V_VT : public FieldSpec {
263 * Class to represent a FixedTypeValueSetFieldSpec.
265 class FieldSpec_VS_FT : public FieldSpec {
269 * Class to represent a VariableTypeValueSetFieldSpec.
271 class FieldSpec_VS_VT : public FieldSpec {
277 * Class to represent an ObjectFieldSpec.
279 class FieldSpec_O : public FieldSpec {
282 Object *defobj; /**< default object */
284 FieldSpec_O(const FieldSpec_O& p);
286 FieldSpec_O(Identifier *p_id, ObjectClass *p_oc,
287 bool p_is_optional, Object *p_defobj);
288 virtual ~FieldSpec_O();
289 virtual FieldSpec_O* clone() const
290 {return new FieldSpec_O(*this);}
291 virtual void set_fullname(const string& p_fullname);
292 virtual void set_my_oc(OC_defn *p_oc);
293 virtual bool has_default() {return defobj;}
294 virtual Object* get_default() {return defobj;}
295 ObjectClass* get_oc() {return oc;}
297 virtual void generate_code(output_struct *target);
301 * Class to represent an ObjectSetFieldSpec.
303 class FieldSpec_OS : public FieldSpec {
306 ObjectSet *defobjset; /**< default objectset */
308 FieldSpec_OS(const FieldSpec_OS& p);
310 FieldSpec_OS(Identifier *p_id, ObjectClass *p_oc,
311 bool p_is_optional, ObjectSet *p_defobjset);
312 virtual ~FieldSpec_OS();
313 virtual FieldSpec_OS* clone() const
314 {return new FieldSpec_OS(*this);}
315 virtual void set_fullname(const string& p_fullname);
316 virtual void set_my_oc(OC_defn *p_oc);
317 virtual bool has_default() {return defobjset;}
318 virtual ObjectSet* get_default() {return defobjset;}
319 ObjectClass* get_oc() {return oc;}
321 virtual void generate_code(output_struct *target);
325 * Class to represent FieldSpecs.
327 class FieldSpecs : public Node {
329 map<string, FieldSpec> fss; /**< the FieldSpecs */
330 vector<FieldSpec> fss_v;
331 FieldSpec_Error *fs_error;
334 FieldSpecs(const FieldSpecs& p);
337 virtual ~FieldSpecs();
338 virtual FieldSpecs* clone() const
339 {return new FieldSpecs(*this);}
340 virtual void set_fullname(const string& p_fullname);
341 void set_my_oc(OC_defn *p_oc);
342 void add_fs(FieldSpec *p_fs);
343 bool has_fs_withId(const Identifier& p_id);
344 FieldSpec* get_fs_byId(const Identifier& p_id);
345 FieldSpec* get_fs_byIndex(size_t p_i);
346 FieldSpec* get_fs_error();
347 size_t get_nof_fss() {return fss.size();}
349 void generate_code(output_struct *target);
350 virtual void dump(unsigned level) const;
354 * Abstract class for OCS visitors.
356 class OCS_Visitor : public Node {
358 OCS_Visitor(const OCS_Visitor& p);
360 OCS_Visitor() : Node() {}
361 virtual OCS_Visitor* clone() const;
362 virtual void visit_root(OCS_root& p) =0;
363 virtual void visit_seq(OCS_seq& p) =0;
364 virtual void visit_literal(OCS_literal& p) =0;
365 virtual void visit_setting(OCS_setting& p) =0;
369 * ObjectClass Syntax. Class to build, manage, ... ObjectClass
372 class OCS_Node : public Node, public Location {
376 /// Copy constructor disabled.
377 OCS_Node(const OCS_Node& p);
378 /// Assignment disabled.
379 OCS_Node& operator=(const OCS_Node& p);
381 OCS_Node() : Location(), is_builded(false) {}
382 virtual OCS_Node* clone() const;
383 virtual void accept(OCS_Visitor& v) =0;
384 bool get_is_builded() {return is_builded;}
385 void set_is_builded() {is_builded=true;}
386 virtual string get_dispname() const =0;
387 virtual void dump(unsigned level) const;
391 * Class to represent a (perhaps optional) sequence of OCS_Nodes.
393 class OCS_seq : public OCS_Node {
395 vector<OCS_Node> ocss;
397 /** This is used when default syntax is active. Then, if there is
398 * at least one parsed setting in the object, then the seq must
399 * begin with a comma (','). */
400 bool opt_first_comma;
402 /// Copy constructor disabled.
403 OCS_seq(const OCS_seq& p);
404 /// Assignment disabled.
405 OCS_seq& operator=(const OCS_seq& p);
407 OCS_seq(bool p_is_opt, bool p_opt_first_comma=false)
408 : OCS_Node(), is_opt(p_is_opt), opt_first_comma(p_opt_first_comma) {}
410 virtual void accept(OCS_Visitor& v)
411 {v.visit_seq(*this);}
412 void add_node(OCS_Node *p_node);
413 size_t get_nof_nodes() {return ocss.size();}
414 OCS_Node* get_nth_node(size_t p_i);
415 bool get_is_opt() {return is_opt;}
416 bool get_opt_first_comma() {return opt_first_comma;}
417 virtual string get_dispname() const;
418 virtual void dump(unsigned level) const;
422 * Class to represent the root of an OCS.
424 class OCS_root : public OCS_Node {
428 /// Copy constructor disabled.
429 OCS_root(const OCS_root& p);
430 /// Assignment disabled.
431 OCS_root& operator=(const OCS_root& p);
433 OCS_root() : OCS_Node(), seq(false) {}
434 virtual void accept(OCS_Visitor& v)
435 {v.visit_root(*this);}
436 OCS_seq& get_seq() {return seq;}
437 virtual string get_dispname() const;
438 virtual void dump(unsigned level) const;
442 * Class to represent a literal element in an OCS.
444 class OCS_literal : public OCS_Node {
449 /// Copy constructor disabled.
450 OCS_literal(const OCS_literal& p);
451 /// Assignment disabled.
452 OCS_literal& operator=(const OCS_literal& p);
454 OCS_literal(int p_keyword) : OCS_Node(), word(0), keyword(p_keyword) {}
455 OCS_literal(Identifier *p_word);
456 virtual ~OCS_literal();
457 virtual void accept(OCS_Visitor& v)
458 {v.visit_literal(*this);}
459 bool is_keyword() {return !word;}
460 int get_keyword() {return keyword;}
461 Identifier* get_word() {return word;}
462 virtual string get_dispname() const;
463 virtual void dump(unsigned level) const;
467 * Class to represent a Setting in the OCS.
469 class OCS_setting : public OCS_Node {
472 S_UNDEF, /**< undefined */
475 S_VS, /**< ValueSet */
477 S_OS /**< ObjectSet */
483 /// Copy constructor disabled.
484 OCS_setting(const OCS_setting& p);
485 /// Assignment disabled.
486 OCS_setting& operator=(const OCS_setting& p);
488 OCS_setting(settingtype_t p_st, Identifier *p_id);
489 virtual ~OCS_setting();
490 virtual void accept(OCS_Visitor& v)
491 {v.visit_setting(*this);}
492 settingtype_t get_st() {return st;}
493 Identifier* get_id() {return id;}
494 virtual string get_dispname() const;
495 virtual void dump(unsigned level) const;
499 * Class to represent FieldSettings.
501 class FieldSetting : public Node, public Location {
502 protected: // Several derived classes need access
506 FieldSetting(const FieldSetting& p);
508 FieldSetting(Identifier *p_name);
509 virtual ~FieldSetting();
510 virtual FieldSetting* clone() const =0;
511 virtual void set_fullname(const string& p_fullname);
512 Identifier& get_name() {return *name;}
513 virtual Setting* get_setting() =0;
514 void set_my_scope(Scope *p_scope);
515 void set_genname(const string& p_prefix,
516 const string& p_suffix);
517 virtual void chk(FieldSpec *p_fspec) =0;
518 virtual void generate_code(output_struct *target) =0;
519 virtual void dump(unsigned level) const =0;
523 * Class to represent type FieldSettings.
525 class FieldSetting_Type : public FieldSetting {
529 FieldSetting_Type(const FieldSetting_Type& p);
531 FieldSetting_Type(Identifier *p_name, Type *p_setting);
532 virtual ~FieldSetting_Type();
533 virtual FieldSetting_Type* clone() const
534 {return new FieldSetting_Type(*this);}
535 virtual Type* get_setting() {return setting;}
536 virtual void chk(FieldSpec *p_fspec);
537 virtual void generate_code(output_struct *target);
538 virtual void dump(unsigned level) const;
542 * Class to represent value FieldSettings.
544 class FieldSetting_Value : public FieldSetting {
548 FieldSetting_Value(const FieldSetting_Value& p);
550 FieldSetting_Value(Identifier *p_name, Value *p_setting);
551 virtual ~FieldSetting_Value();
552 virtual FieldSetting_Value* clone() const
553 {return new FieldSetting_Value(*this);}
554 virtual Value* get_setting() {return setting;}
555 virtual void chk(FieldSpec *p_fspec);
556 virtual void generate_code(output_struct *target);
557 virtual void dump(unsigned level) const;
561 * Class to represent object FieldSettings.
563 class FieldSetting_O : public FieldSetting {
567 FieldSetting_O(const FieldSetting_O& p);
569 FieldSetting_O(Identifier *p_name, Object *p_setting);
570 virtual ~FieldSetting_O();
571 virtual FieldSetting_O* clone() const
572 {return new FieldSetting_O(*this);}
573 virtual Object* get_setting() {return setting;}
574 virtual void chk(FieldSpec *p_fspec);
575 virtual void generate_code(output_struct *target);
576 virtual void dump(unsigned level) const;
580 * Class to represent objectset FieldSettings.
582 class FieldSetting_OS : public FieldSetting {
586 FieldSetting_OS(const FieldSetting_OS& p);
588 FieldSetting_OS(Identifier *p_name, ObjectSet *p_setting);
589 virtual ~FieldSetting_OS();
590 virtual FieldSetting_OS* clone() const
591 {return new FieldSetting_OS(*this);}
592 virtual ObjectSet* get_setting() {return setting;}
593 virtual void chk(FieldSpec *p_fspec);
594 virtual void generate_code(output_struct *target);
595 virtual void dump(unsigned level) const;
599 * Class to represent ObjectDefinition.
601 class Obj_defn : public Object {
604 map<string, FieldSetting> fss; /**< FieldSettings */
607 Obj_defn(const Obj_defn& p);
609 Obj_defn(Block *p_block);
612 virtual Obj_defn* clone() const {return new Obj_defn(*this);}
613 virtual void set_fullname(const string& p_fullname);
614 virtual void set_my_scope(Scope *p_scope);
615 virtual Obj_defn* get_refd_last(ReferenceChain * =0) {return this;}
617 void add_fs(FieldSetting *p_fs);
618 virtual size_t get_nof_fss() {return fss.size();}
619 virtual bool has_fs_withName(const Identifier& p_name);
620 virtual FieldSetting* get_fs_byName(const Identifier& p_name);
621 virtual bool has_fs_withName_dflt(const Identifier& p_name);
622 /** Returns the setting (or default if absent) */
623 virtual Setting* get_setting_byName_dflt(const Identifier& p_name);
624 virtual void generate_code(output_struct *target);
625 virtual void dump(unsigned level) const;
631 * Class to represent a ReferencedObject. It is a DefinedObject or
634 class Obj_refd : public Object {
638 Object *o_refd; /**< cache */
639 Obj_defn *o_defn; /**< cache */
641 Obj_refd(const Obj_refd& p);
643 Obj_refd(Reference *p_ref);
645 virtual Obj_refd* clone() const {return new Obj_refd(*this);}
646 virtual void set_my_scope(Scope *p_scope);
647 virtual void set_fullname(const string& p_fullname);
648 Object* get_refd(ReferenceChain *refch=0);
649 virtual Obj_defn* get_refd_last(ReferenceChain *refch=0);
651 virtual void generate_code(output_struct *target);
652 virtual void dump(unsigned level) const;
656 * ObjectSet elements (flat container). Warning: the objects are not
657 * owned by Objects, it stores only the pointers...
659 class Objects : public Node {
661 vector<Obj_defn> objs;
663 Objects(const Objects&);
665 Objects() : Node() {}
667 virtual Objects* clone() const {return new Objects(*this);}
668 void add_o(Obj_defn *p_o) {objs.add(p_o);}
669 void add_objs(Objects *p_objs);
670 size_t get_nof_objs() const {return objs.size();}
671 Obj_defn* get_obj_byIndex(size_t p_i) {return objs[p_i];}
672 virtual void dump(unsigned level) const;
676 * ObjectSetElement Visitor, checker.
678 class OSEV_checker : public OSE_Visitor {
680 ObjectClass *governor;
684 OSEV_checker(const Location *p_loc, ObjectClass *p_governor);
685 virtual void visit_Object(Object& p);
686 virtual void visit_OS_refd(OS_refd& p);
690 * ObjectSetElement Visitor, object collector.
692 class OSEV_objcollctr : public OSE_Visitor {
695 map<void*, void> visdes; /**< visited elements */
699 OSEV_objcollctr(ObjectSet& parent);
700 OSEV_objcollctr(const Location *p_loc, ObjectClass *p_governor);
701 virtual ~OSEV_objcollctr();
702 virtual void visit_Object(Object& p);
703 virtual void visit_OS_refd(OS_refd& p);
704 void visit_ObjectSet(ObjectSet& p, bool force=false);
705 Objects* get_objs() {return objs;}
706 Objects* give_objs();
710 * ObjectSetElement Visitor, code generator.
712 class OSEV_codegen : public OSE_Visitor {
714 output_struct *target;
716 OSEV_codegen(const Location *p_loc, output_struct *p_target)
717 : OSE_Visitor(p_loc), target(p_target) {}
718 virtual void visit_Object(Object& p);
719 virtual void visit_OS_refd(OS_refd& p);
723 * ObjectSet definition.
725 class OS_defn : public ObjectSet {
728 vector<OS_Element> *oses;
732 OS_defn(const OS_defn& p);
735 OS_defn(Block *p_block);
736 OS_defn(Objects *p_objs);
738 virtual OS_defn* clone() const {return new OS_defn(*this);}
739 void steal_oses(OS_defn *other_os);
740 virtual OS_defn* get_refd_last(ReferenceChain *refch=0);
741 virtual void set_fullname(const string& p_fullname);
742 virtual void set_my_scope(Scope *p_scope);
743 void add_ose(OS_Element *p_ose);
744 virtual size_t get_nof_objs();
745 virtual Object* get_obj_byIndex(size_t p_i);
746 virtual Objects* get_objs();
747 virtual void accept(OSEV_objcollctr& v) {v.visit_ObjectSet(*this);}
749 virtual void generate_code(output_struct *target);
750 virtual void dump(unsigned level) const;
757 * Referenced ObjectSet.
759 class OS_refd : public ObjectSet, public OS_Element {
763 ObjectSet *os_refd; /**< cache */
764 OS_defn *os_defn; /**< cache */
766 OS_refd(const OS_refd& p);
767 virtual string create_stringRepr();
769 OS_refd(Reference *p_ref);
771 virtual OS_refd* clone() const {return new OS_refd(*this);}
772 virtual void set_my_scope(Scope *p_scope);
773 ObjectSet* get_refd(ReferenceChain *refch=0);
774 virtual OS_defn* get_refd_last(ReferenceChain *refch=0);
775 virtual size_t get_nof_objs();
776 virtual Object* get_obj_byIndex(size_t p_i);
777 virtual void accept(OSE_Visitor& v) {v.visit_OS_refd(*this);}
778 virtual void accept(OSEV_objcollctr& v) {v.visit_ObjectSet(*this);}
780 virtual void generate_code(output_struct *target);
781 virtual void dump(unsigned level) const;
782 virtual OS_Element *clone_ose() const;
783 virtual void set_fullname_ose(const string& p_fullname);
784 virtual void set_genname_ose(const string& p_prefix,
785 const string& p_suffix);
786 virtual void set_my_scope_ose(Scope *p_scope);
791 #endif // _Asn_Object_HH