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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/******************************************************************************
* Copyright (c) 2000-2016 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Baji, Laszlo
* Balasko, Jeno
* Raduly, Csaba
*
******************************************************************************/
#ifndef COMPTYPE_HH_
#define COMPTYPE_HH_
#include "Setting.hh"
struct output_struct_t;
namespace Ttcn {
class Definition;
class WithAttribPath;
class Reference;
}
namespace Common {
class CompTypeRefList;
/** Class to represent the definition of a component type */
class ComponentTypeBody : public Scope, public Location {
public:
/** represents the check state of this component
* every check increments the value */
enum check_state_t {
CHECK_INITIAL, /**< initial state before checks */
CHECK_WITHATTRIB, /**< with attribute checked,
set by chk_extends_attr() */
CHECK_EXTENDS, /**< component extension checked,
set by chk_extends() */
CHECK_DEFUNIQ, /**< definitions id uniqueness checked,
set by chk_defs_uniq() */
CHECK_OWNDEFS, /**< own definitions checked,
set by chk_my_defs() */
CHECK_EXTDEFS, /**< definitions inherited by attribute checked,
set by chk_attr_ext_defs() */
CHECK_FINAL /**< everything was checked, set by chk() */
};
private:
/** Identifier of this component */
const Identifier *comp_id;
/** the Type that contains this, needed to reach w_attrib_path */
Type *my_type;
/** tells which checks have already been performed */
check_state_t check_state;
/** true when chk() is running */
bool checking;
/** Vector containing own definitions. Used for building. */
vector<Ttcn::Definition> def_v;
/** component references from the "extends" part or NULL if there were no */
CompTypeRefList *extends_refs;
/** component references from the extends attribute or NULL */
CompTypeRefList *attr_extends_refs;
/** map of own definitions equal to inherited by extension attribute
* needed to initialize the the value with own value,
* pointers to the defs are owned by def_v */
map<string, Ttcn::Definition> orig_defs_m;
/** map of my and inherited definitions */
map<string, Ttcn::Definition> all_defs_m;
/** compatibility map for is_compatible() function, filled in chk(),
* all components inherited along pure extends-keyword path have the value
* equal to the key, others have NULL value */
map<ComponentTypeBody*, ComponentTypeBody> compatible_m;
void init_compatibility(CompTypeRefList *crl, bool is_standard_extends);
private:
/** Copy constructor not implemented */
ComponentTypeBody(const ComponentTypeBody& p);
/** Assignment not implemented */
ComponentTypeBody& operator=(const ComponentTypeBody& p);
public:
ComponentTypeBody()
: Scope(), comp_id(0), my_type(0), check_state(CHECK_INITIAL),
checking(false), def_v(), extends_refs(0), attr_extends_refs(0),
orig_defs_m(), all_defs_m(), compatible_m() { }
~ComponentTypeBody();
ComponentTypeBody *clone() const;
void set_id(const Identifier *p_id) { comp_id = p_id; }
Identifier const * get_id() const { return comp_id; }
void set_my_type(Type *p_type) { my_type = p_type; }
Type* get_my_type() { return my_type; }
virtual void set_fullname(const string& p_fullname);
virtual void set_my_scope(Scope *p_scope);
bool has_local_ass_withId(const Identifier& p_id);
Assignment* get_local_ass_byId(const Identifier& p_id);
bool has_ass_withId(const Identifier& p_id);
bool is_own_assignment(const Assignment* p_ass);
size_t get_nof_asss();
Assignment* get_ass_byIndex(size_t p_i);
virtual Assignment *get_ass_bySRef(Ref_simple *p_ref);
void add_extends(CompTypeRefList *p_crl);
/** Returns if this component is compatible with the given other component.
* This component is compatible with other component if this extends the
* other component (with standard extends or with extension attribute)
* directly or this extends a component which is compatible with other */
bool is_compatible(ComponentTypeBody *other);
/** Adds the assignment p_ass and becomes the owner of it.
* The uniqueness of the identifier is not checked. */
void add_ass(Ttcn::Definition *p_ass);
/** Prints the contents of the component. */
void dump(unsigned level) const;
private:
void chk_extends_attr();
public:
/** Check component extends recursions (extends keyword and attribute) */
void chk_recursion(ReferenceChain& refch);
private:
void collect_defs_from_standard_extends();
void collect_defs_from_attribute_extends();
/** Checks the AST for correct component extensions. */
void chk_extends();
/** Checks definition id uniqueness */
void chk_defs_uniq();
/** Checks all own definitions */
void chk_my_defs();
/** Checks definitions inherited with attribute extends */
void chk_attr_ext_defs();
public:
/** perform all checks */
void chk(check_state_t required_check_state = CHECK_FINAL);
/** Sets the genname of embedded definitions using \a prefix. */
void set_genname(const string& prefix);
void generate_code(output_struct_t *target);
/** Generates a pair of C++ strings that contain the module name and name
* of the component type and appends them to \a str. */
char *generate_code_comptype_name(char *str);
void set_parent_path(Ttcn::WithAttribPath* p_path);
};
/** Class to represent a list of references to components */
class CompTypeRefList : public Node, public Location {
private:
bool checked;
vector<Ttcn::Reference> comp_ref_v;
/** Pointers to ComponentTypeBody objects in the AST, filled by chk() */
map<ComponentTypeBody*,Ttcn::Reference> comp_body_m;
/** Contains the keys of comp_body_m in the order determined by comp_ref_v,
* used to perform checks in deterministic order ( the order of keys in
* comp_body_m is platform dependent */
vector<ComponentTypeBody> comp_body_v;
/** Copy constructor not implemented */
CompTypeRefList(const CompTypeRefList& p);
/** Assignment disabled */
CompTypeRefList& operator=(const CompTypeRefList& p);
public:
CompTypeRefList()
: checked(false), comp_ref_v(), comp_body_m(), comp_body_v() { }
~CompTypeRefList();
CompTypeRefList *clone() const;
void add_ref(Ttcn::Reference *p_ref);
void dump(unsigned level) const;
virtual void set_fullname(const string& p_fullname);
void chk_uniq();
void chk(ComponentTypeBody::check_state_t required_check_state);
void chk_recursion(ReferenceChain& refch);
virtual void set_my_scope(Scope *p_scope);
/** utility functions to access comp_body_m */
size_t get_nof_comps();
ComponentTypeBody *get_nth_comp_body(size_t i);
Ttcn::Reference *get_nth_comp_ref(size_t i);
bool has_comp_body(ComponentTypeBody *cb);
};
} /* namespace Common */
#endif /* COMPTYPE_HH_ */
|