1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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
7 ///////////////////////////////////////////////////////////////////////////////
13 #include "../Value.hh"
18 using namespace Common;
23 class FieldSpec_Undef;
24 class FieldSpec_Error;
29 class FieldSpec_VS_FT;
30 class FieldSpec_VS_VT;
45 class FieldSetting_Type;
46 class FieldSetting_Value;
48 class FieldSetting_OS;
53 class OSE_Visitor; // in Object0.hh
61 * Class to represent ObjectClassDefinition
63 class OC_defn : public ObjectClass {
65 Block *block_fs; /**< field specs block */
66 Block *block_ws; /**< WITH SYNTAX block */
67 FieldSpecs *fss; /**< field specs */
68 OCS_root *ocs; /**< object class syntax */
72 OC_defn(const OC_defn& p);
75 OC_defn(Block *p_block_fs, Block *p_block_ws);
77 virtual OC_defn* clone() const {return new OC_defn(*this);}
78 virtual void set_fullname(const string& p_fullname);
79 virtual OC_defn* get_refd_last(ReferenceChain * =0) {return this;}
81 virtual void chk_this_obj(Object *obj);
82 virtual OCS_root* get_ocs();
83 virtual FieldSpecs* get_fss();
84 virtual void generate_code(output_struct *target);
85 virtual void dump(unsigned level) const;
87 void parse_block_fs();
91 * Class to represent a ReferencedObjectClass. It is a DefinedOC or
92 * OCFromObject or ValueSetFromObjects.
94 class OC_refd : public ObjectClass {
98 ObjectClass *oc_refd; /**< cache */
99 OC_defn *oc_defn; /**< cache */
101 OC_refd(const OC_refd& p);
103 OC_refd(Reference *p_ref);
105 virtual OC_refd* clone() const {return new OC_refd(*this);}
106 virtual void set_my_scope(Scope *p_scope);
107 virtual void set_fullname(const string& p_fullname);
108 ObjectClass* get_refd(ReferenceChain *refch=0);
109 virtual OC_defn* get_refd_last(ReferenceChain *refch=0);
111 virtual void chk_this_obj(Object *p_obj);
112 virtual OCS_root* get_ocs();
113 virtual FieldSpecs* get_fss();
114 virtual void generate_code(output_struct *target);
115 virtual void dump(unsigned level) const;
119 * Class to represent a FieldSpec of an ObjectClass.
121 class FieldSpec : public Node, public Location {
124 FS_UNDEF, /**< undefined */
125 FS_ERROR, /**< erroneous fieldspec */
126 FS_T, /**< type fieldspec */
127 FS_V_FT, /**< fixedtype value fieldspec */
128 FS_V_VT, /**< variabletype value fieldspec */
129 FS_VS_FT, /**< fixedtype valueset fieldspec */
130 FS_VS_VT, /**< variabletype valueset fieldspec */
131 FS_O, /**< object fieldspec */
132 FS_OS /**< objectset fieldspec */
134 protected: // Several derived classes need access
141 FieldSpec(const FieldSpec& p);
143 FieldSpec(fstype_t p_fstype, Identifier *p_id, bool p_is_optional);
144 virtual ~FieldSpec();
145 virtual FieldSpec* clone() const =0;
146 virtual void set_fullname(const string& p_fullname);
147 virtual const Identifier& get_id() const {return *id;}
148 virtual fstype_t get_fstype() {return fstype;}
149 virtual void set_my_oc(OC_defn *p_oc);
150 bool get_is_optional() {return is_optional;}
151 virtual bool has_default() =0;
152 virtual void chk() =0;
153 virtual Setting* get_default() =0;
154 virtual FieldSpec* get_last() {return this;}
155 virtual void generate_code(output_struct *target) =0;
159 * Class to represent an undefined FieldSpec.
161 class FieldSpec_Undef : public FieldSpec {
164 Node* defsetting; /**< default setting */
165 FieldSpec *fs; /**< the classified fieldspec */
167 void classify_fs(ReferenceChain *refch=0);
168 FieldSpec_Undef(const FieldSpec_Undef& p);
170 FieldSpec_Undef(Identifier *p_id, Ref_defd* p_govref,
171 bool p_is_optional, Node *p_defsetting);
172 virtual ~FieldSpec_Undef();
173 virtual FieldSpec* clone() const;
174 virtual void set_fullname(const string& p_fullname);
175 virtual fstype_t get_fstype();
176 virtual void set_my_oc(OC_defn *p_oc);
177 virtual bool has_default();
179 virtual Setting* get_default();
180 virtual FieldSpec* get_last();
181 virtual void generate_code(output_struct *target);
184 class FieldSpec_Error : public FieldSpec {
186 Setting *setting_error;
187 bool has_default_flag;
189 FieldSpec_Error(const FieldSpec_Error& p);
191 FieldSpec_Error(Identifier *p_id, bool p_is_optional,
193 virtual ~FieldSpec_Error();
194 virtual FieldSpec_Error* clone() const;
195 virtual bool has_default();
196 virtual Setting* get_default();
198 virtual void generate_code(output_struct *target);
202 * Class to represent a TypeFieldSpec.
204 class FieldSpec_T : public FieldSpec {
206 Type *deftype; /**< default type */
208 FieldSpec_T(const FieldSpec_T& p);
210 FieldSpec_T(Identifier *p_id, bool p_is_optional, Type *p_deftype);
211 virtual ~FieldSpec_T();
212 virtual FieldSpec_T* clone() const
213 {return new FieldSpec_T(*this);}
214 virtual void set_fullname(const string& p_fullname);
215 virtual void set_my_oc(OC_defn *p_oc);
216 virtual bool has_default() {return deftype;}
217 virtual Type* get_default();
219 virtual void generate_code(output_struct *target);
223 * Class to represent a FixedTypeValueFieldSpec.
225 class FieldSpec_V_FT : public FieldSpec {
227 Type *fixtype; /**< fixed type */
229 Value *defval; /**< default value */
231 FieldSpec_V_FT(const FieldSpec_V_FT& p);
233 FieldSpec_V_FT(Identifier *p_id, Type *p_fixtype, bool p_is_unique,
234 bool p_is_optional, Value *p_defval);
235 virtual ~FieldSpec_V_FT();
236 virtual FieldSpec_V_FT* clone() const
237 {return new FieldSpec_V_FT(*this);}
238 virtual void set_fullname(const string& p_fullname);
239 virtual void set_my_oc(OC_defn *p_oc);
240 virtual bool has_default() {return defval;}
241 virtual Value* get_default();
242 Type* get_type() {return fixtype;}
244 virtual void generate_code(output_struct *target);
250 * Class to represent a VariableTypeValueFieldSpec.
252 class FieldSpec_V_VT : public FieldSpec {
256 * Class to represent a FixedTypeValueSetFieldSpec.
258 class FieldSpec_VS_FT : public FieldSpec {
262 * Class to represent a VariableTypeValueSetFieldSpec.
264 class FieldSpec_VS_VT : public FieldSpec {
270 * Class to represent an ObjectFieldSpec.
272 class FieldSpec_O : public FieldSpec {
275 Object *defobj; /**< default object */
277 FieldSpec_O(const FieldSpec_O& p);
279 FieldSpec_O(Identifier *p_id, ObjectClass *p_oc,
280 bool p_is_optional, Object *p_defobj);
281 virtual ~FieldSpec_O();
282 virtual FieldSpec_O* clone() const
283 {return new FieldSpec_O(*this);}
284 virtual void set_fullname(const string& p_fullname);
285 virtual void set_my_oc(OC_defn *p_oc);
286 virtual bool has_default() {return defobj;}
287 virtual Object* get_default() {return defobj;}
288 ObjectClass* get_oc() {return oc;}
290 virtual void generate_code(output_struct *target);
294 * Class to represent an ObjectSetFieldSpec.
296 class FieldSpec_OS : public FieldSpec {
299 ObjectSet *defobjset; /**< default objectset */
301 FieldSpec_OS(const FieldSpec_OS& p);
303 FieldSpec_OS(Identifier *p_id, ObjectClass *p_oc,
304 bool p_is_optional, ObjectSet *p_defobjset);
305 virtual ~FieldSpec_OS();
306 virtual FieldSpec_OS* clone() const
307 {return new FieldSpec_OS(*this);}
308 virtual void set_fullname(const string& p_fullname);
309 virtual void set_my_oc(OC_defn *p_oc);
310 virtual bool has_default() {return defobjset;}
311 virtual ObjectSet* get_default() {return defobjset;}
312 ObjectClass* get_oc() {return oc;}
314 virtual void generate_code(output_struct *target);
318 * Class to represent FieldSpecs.
320 class FieldSpecs : public Node {
322 map<string, FieldSpec> fss; /**< the FieldSpecs */
323 vector<FieldSpec> fss_v;
324 FieldSpec_Error *fs_error;
327 FieldSpecs(const FieldSpecs& p);
330 virtual ~FieldSpecs();
331 virtual FieldSpecs* clone() const
332 {return new FieldSpecs(*this);}
333 virtual void set_fullname(const string& p_fullname);
334 void set_my_oc(OC_defn *p_oc);
335 void add_fs(FieldSpec *p_fs);
336 bool has_fs_withId(const Identifier& p_id);
337 FieldSpec* get_fs_byId(const Identifier& p_id);
338 FieldSpec* get_fs_byIndex(size_t p_i);
339 FieldSpec* get_fs_error();
340 size_t get_nof_fss() {return fss.size();}
342 void generate_code(output_struct *target);
343 virtual void dump(unsigned level) const;
347 * Abstract class for OCS visitors.
349 class OCS_Visitor : public Node {
351 OCS_Visitor(const OCS_Visitor& p);
353 OCS_Visitor() : Node() {}
354 virtual OCS_Visitor* clone() const;
355 virtual void visit_root(OCS_root& p) =0;
356 virtual void visit_seq(OCS_seq& p) =0;
357 virtual void visit_literal(OCS_literal& p) =0;
358 virtual void visit_setting(OCS_setting& p) =0;
362 * ObjectClass Syntax. Class to build, manage, ... ObjectClass
365 class OCS_Node : public Node, public Location {
369 /// Copy constructor disabled.
370 OCS_Node(const OCS_Node& p);
371 /// Assignment disabled.
372 OCS_Node& operator=(const OCS_Node& p);
374 OCS_Node() : Location(), is_builded(false) {}
375 virtual OCS_Node* clone() const;
376 virtual void accept(OCS_Visitor& v) =0;
377 bool get_is_builded() {return is_builded;}
378 void set_is_builded() {is_builded=true;}
379 virtual string get_dispname() const =0;
380 virtual void dump(unsigned level) const;
384 * Class to represent a (perhaps optional) sequence of OCS_Nodes.
386 class OCS_seq : public OCS_Node {
388 vector<OCS_Node> ocss;
390 /** This is used when default syntax is active. Then, if there is
391 * at least one parsed setting in the object, then the seq must
392 * begin with a comma (','). */
393 bool opt_first_comma;
395 /// Copy constructor disabled.
396 OCS_seq(const OCS_seq& p);
397 /// Assignment disabled.
398 OCS_seq& operator=(const OCS_seq& p);
400 OCS_seq(bool p_is_opt, bool p_opt_first_comma=false)
401 : OCS_Node(), is_opt(p_is_opt), opt_first_comma(p_opt_first_comma) {}
403 virtual void accept(OCS_Visitor& v)
404 {v.visit_seq(*this);}
405 void add_node(OCS_Node *p_node);
406 size_t get_nof_nodes() {return ocss.size();}
407 OCS_Node* get_nth_node(size_t p_i);
408 bool get_is_opt() {return is_opt;}
409 bool get_opt_first_comma() {return opt_first_comma;}
410 virtual string get_dispname() const;
411 virtual void dump(unsigned level) const;
415 * Class to represent the root of an OCS.
417 class OCS_root : public OCS_Node {
421 /// Copy constructor disabled.
422 OCS_root(const OCS_root& p);
423 /// Assignment disabled.
424 OCS_root& operator=(const OCS_root& p);
426 OCS_root() : OCS_Node(), seq(false) {}
427 virtual void accept(OCS_Visitor& v)
428 {v.visit_root(*this);}
429 OCS_seq& get_seq() {return seq;}
430 virtual string get_dispname() const;
431 virtual void dump(unsigned level) const;
435 * Class to represent a literal element in an OCS.
437 class OCS_literal : public OCS_Node {
442 /// Copy constructor disabled.
443 OCS_literal(const OCS_literal& p);
444 /// Assignment disabled.
445 OCS_literal& operator=(const OCS_literal& p);
447 OCS_literal(int p_keyword) : OCS_Node(), word(0), keyword(p_keyword) {}
448 OCS_literal(Identifier *p_word);
449 virtual ~OCS_literal();
450 virtual void accept(OCS_Visitor& v)
451 {v.visit_literal(*this);}
452 bool is_keyword() {return !word;}
453 int get_keyword() {return keyword;}
454 Identifier* get_word() {return word;}
455 virtual string get_dispname() const;
456 virtual void dump(unsigned level) const;
460 * Class to represent a Setting in the OCS.
462 class OCS_setting : public OCS_Node {
465 S_UNDEF, /**< undefined */
468 S_VS, /**< ValueSet */
470 S_OS /**< ObjectSet */
476 /// Copy constructor disabled.
477 OCS_setting(const OCS_setting& p);
478 /// Assignment disabled.
479 OCS_setting& operator=(const OCS_setting& p);
481 OCS_setting(settingtype_t p_st, Identifier *p_id);
482 virtual ~OCS_setting();
483 virtual void accept(OCS_Visitor& v)
484 {v.visit_setting(*this);}
485 settingtype_t get_st() {return st;}
486 Identifier* get_id() {return id;}
487 virtual string get_dispname() const;
488 virtual void dump(unsigned level) const;
492 * Class to represent FieldSettings.
494 class FieldSetting : public Node, public Location {
495 protected: // Several derived classes need access
499 FieldSetting(const FieldSetting& p);
501 FieldSetting(Identifier *p_name);
502 virtual ~FieldSetting();
503 virtual FieldSetting* clone() const =0;
504 virtual void set_fullname(const string& p_fullname);
505 Identifier& get_name() {return *name;}
506 virtual Setting* get_setting() =0;
507 void set_my_scope(Scope *p_scope);
508 void set_genname(const string& p_prefix,
509 const string& p_suffix);
510 virtual void chk(FieldSpec *p_fspec) =0;
511 virtual void generate_code(output_struct *target) =0;
512 virtual void dump(unsigned level) const =0;
516 * Class to represent type FieldSettings.
518 class FieldSetting_Type : public FieldSetting {
522 FieldSetting_Type(const FieldSetting_Type& p);
524 FieldSetting_Type(Identifier *p_name, Type *p_setting);
525 virtual ~FieldSetting_Type();
526 virtual FieldSetting_Type* clone() const
527 {return new FieldSetting_Type(*this);}
528 virtual Type* get_setting() {return setting;}
529 virtual void chk(FieldSpec *p_fspec);
530 virtual void generate_code(output_struct *target);
531 virtual void dump(unsigned level) const;
535 * Class to represent value FieldSettings.
537 class FieldSetting_Value : public FieldSetting {
541 FieldSetting_Value(const FieldSetting_Value& p);
543 FieldSetting_Value(Identifier *p_name, Value *p_setting);
544 virtual ~FieldSetting_Value();
545 virtual FieldSetting_Value* clone() const
546 {return new FieldSetting_Value(*this);}
547 virtual Value* get_setting() {return setting;}
548 virtual void chk(FieldSpec *p_fspec);
549 virtual void generate_code(output_struct *target);
550 virtual void dump(unsigned level) const;
554 * Class to represent object FieldSettings.
556 class FieldSetting_O : public FieldSetting {
560 FieldSetting_O(const FieldSetting_O& p);
562 FieldSetting_O(Identifier *p_name, Object *p_setting);
563 virtual ~FieldSetting_O();
564 virtual FieldSetting_O* clone() const
565 {return new FieldSetting_O(*this);}
566 virtual Object* get_setting() {return setting;}
567 virtual void chk(FieldSpec *p_fspec);
568 virtual void generate_code(output_struct *target);
569 virtual void dump(unsigned level) const;
573 * Class to represent objectset FieldSettings.
575 class FieldSetting_OS : public FieldSetting {
579 FieldSetting_OS(const FieldSetting_OS& p);
581 FieldSetting_OS(Identifier *p_name, ObjectSet *p_setting);
582 virtual ~FieldSetting_OS();
583 virtual FieldSetting_OS* clone() const
584 {return new FieldSetting_OS(*this);}
585 virtual ObjectSet* get_setting() {return setting;}
586 virtual void chk(FieldSpec *p_fspec);
587 virtual void generate_code(output_struct *target);
588 virtual void dump(unsigned level) const;
592 * Class to represent ObjectDefinition.
594 class Obj_defn : public Object {
597 map<string, FieldSetting> fss; /**< FieldSettings */
600 Obj_defn(const Obj_defn& p);
602 Obj_defn(Block *p_block);
605 virtual Obj_defn* clone() const {return new Obj_defn(*this);}
606 virtual void set_fullname(const string& p_fullname);
607 virtual void set_my_scope(Scope *p_scope);
608 virtual Obj_defn* get_refd_last(ReferenceChain * =0) {return this;}
610 void add_fs(FieldSetting *p_fs);
611 virtual size_t get_nof_fss() {return fss.size();}
612 virtual bool has_fs_withName(const Identifier& p_name);
613 virtual FieldSetting* get_fs_byName(const Identifier& p_name);
614 virtual bool has_fs_withName_dflt(const Identifier& p_name);
615 /** Returns the setting (or default if absent) */
616 virtual Setting* get_setting_byName_dflt(const Identifier& p_name);
617 virtual void generate_code(output_struct *target);
618 virtual void dump(unsigned level) const;
624 * Class to represent a ReferencedObject. It is a DefinedObject or
627 class Obj_refd : public Object {
631 Object *o_refd; /**< cache */
632 Obj_defn *o_defn; /**< cache */
634 Obj_refd(const Obj_refd& p);
636 Obj_refd(Reference *p_ref);
638 virtual Obj_refd* clone() const {return new Obj_refd(*this);}
639 virtual void set_my_scope(Scope *p_scope);
640 virtual void set_fullname(const string& p_fullname);
641 Object* get_refd(ReferenceChain *refch=0);
642 virtual Obj_defn* get_refd_last(ReferenceChain *refch=0);
644 virtual void generate_code(output_struct *target);
645 virtual void dump(unsigned level) const;
649 * ObjectSet elements (flat container). Warning: the objects are not
650 * owned by Objects, it stores only the pointers...
652 class Objects : public Node {
654 vector<Obj_defn> objs;
656 Objects(const Objects&);
658 Objects() : Node() {}
660 virtual Objects* clone() const {return new Objects(*this);}
661 void add_o(Obj_defn *p_o) {objs.add(p_o);}
662 void add_objs(Objects *p_objs);
663 size_t get_nof_objs() const {return objs.size();}
664 Obj_defn* get_obj_byIndex(size_t p_i) {return objs[p_i];}
665 virtual void dump(unsigned level) const;
669 * ObjectSetElement Visitor, checker.
671 class OSEV_checker : public OSE_Visitor {
673 ObjectClass *governor;
677 OSEV_checker(const Location *p_loc, ObjectClass *p_governor);
678 virtual void visit_Object(Object& p);
679 virtual void visit_OS_refd(OS_refd& p);
683 * ObjectSetElement Visitor, object collector.
685 class OSEV_objcollctr : public OSE_Visitor {
688 map<void*, void> visdes; /**< visited elements */
692 OSEV_objcollctr(ObjectSet& parent);
693 OSEV_objcollctr(const Location *p_loc, ObjectClass *p_governor);
694 virtual ~OSEV_objcollctr();
695 virtual void visit_Object(Object& p);
696 virtual void visit_OS_refd(OS_refd& p);
697 void visit_ObjectSet(ObjectSet& p, bool force=false);
698 Objects* get_objs() {return objs;}
699 Objects* give_objs();
703 * ObjectSetElement Visitor, code generator.
705 class OSEV_codegen : public OSE_Visitor {
707 output_struct *target;
709 OSEV_codegen(const Location *p_loc, output_struct *p_target)
710 : OSE_Visitor(p_loc), target(p_target) {}
711 virtual void visit_Object(Object& p);
712 virtual void visit_OS_refd(OS_refd& p);
716 * ObjectSet definition.
718 class OS_defn : public ObjectSet {
721 vector<OS_Element> *oses;
725 OS_defn(const OS_defn& p);
728 OS_defn(Block *p_block);
729 OS_defn(Objects *p_objs);
731 virtual OS_defn* clone() const {return new OS_defn(*this);}
732 void steal_oses(OS_defn *other_os);
733 virtual OS_defn* get_refd_last(ReferenceChain *refch=0);
734 virtual void set_fullname(const string& p_fullname);
735 virtual void set_my_scope(Scope *p_scope);
736 void add_ose(OS_Element *p_ose);
737 virtual size_t get_nof_objs();
738 virtual Object* get_obj_byIndex(size_t p_i);
739 virtual Objects* get_objs();
740 virtual void accept(OSEV_objcollctr& v) {v.visit_ObjectSet(*this);}
742 virtual void generate_code(output_struct *target);
743 virtual void dump(unsigned level) const;
750 * Referenced ObjectSet.
752 class OS_refd : public ObjectSet, public OS_Element {
756 ObjectSet *os_refd; /**< cache */
757 OS_defn *os_defn; /**< cache */
759 OS_refd(const OS_refd& p);
760 virtual string create_stringRepr();
762 OS_refd(Reference *p_ref);
764 virtual OS_refd* clone() const {return new OS_refd(*this);}
765 virtual void set_my_scope(Scope *p_scope);
766 ObjectSet* get_refd(ReferenceChain *refch=0);
767 virtual OS_defn* get_refd_last(ReferenceChain *refch=0);
768 virtual size_t get_nof_objs();
769 virtual Object* get_obj_byIndex(size_t p_i);
770 virtual void accept(OSE_Visitor& v) {v.visit_OS_refd(*this);}
771 virtual void accept(OSEV_objcollctr& v) {v.visit_ObjectSet(*this);}
773 virtual void generate_code(output_struct *target);
774 virtual void dump(unsigned level) const;
775 virtual OS_Element *clone_ose() const;
776 virtual void set_fullname_ose(const string& p_fullname);
777 virtual void set_genname_ose(const string& p_prefix,
778 const string& p_suffix);
779 virtual void set_my_scope_ose(Scope *p_scope);
784 #endif // _Asn_Object_HH