Last sync 2016.04.01
[deliverable/titan.core.git] / compiler2 / ttcn3 / PatternString.hh
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
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Baranyi, Botond
11 * Delic, Adam
12 * Forstner, Matyas
13 * Raduly, Csaba
14 * Szabo, Janos Zoltan – initial implementation
15 * Zalanyi, Balazs Andor
16 *
17 ******************************************************************************/
18 #ifndef _Ttcn_PatternString_HH
19 #define _Ttcn_PatternString_HH
20
21 #include "../vector.hh"
22 #include "../Setting.hh"
23 #include "AST_ttcn3.hh"
24
25 #include "../Value.hh"
26
27 namespace Ttcn {
28
29 class Module;
30 using namespace Common;
31
32 /**
33 * The instances of this class can represent a TTCN pattern
34 * string. It can built up from different kinds of elements:
35 * "regular" RE-elements and "reference" elements ({reference} and
36 * \\N{reference}).
37 */
38 class PatternString : public Node {
39 public:
40 enum pstr_type_t {
41 CSTR_PATTERN,
42 USTR_PATTERN
43 };
44 private:
45 Scope *my_scope;
46 struct ps_elem_t;
47 vector<ps_elem_t> elems;
48 PatternString(const PatternString& p);
49 /** returns the last element if it contains a regular string or NULL
50 * otherwise */
51 ps_elem_t *get_last_elem() const;
52
53 Value* cstr_value;
54
55 pstr_type_t pattern_type;
56
57 public:
58 PatternString(): Node(), my_scope(0), cstr_value(0),
59 pattern_type(CSTR_PATTERN) { }
60 virtual ~PatternString();
61 virtual PatternString* clone() const;
62 virtual void set_fullname(const string& p_fullname);
63 virtual void set_my_scope(Scope *p_scope);
64 void set_code_section(GovernedSimple::code_section_t p_code_section);
65 void addChar(char c);
66 void addString(const char *p_str);
67 void addString(const string& p_str);
68 void addRef(Ttcn::Reference *p_ref);
69 void addRefdCharSet(Ttcn::Reference *p_ref);
70 string get_full_str() const;
71
72 void set_pattern_type(pstr_type_t p_type);
73 pstr_type_t get_pattern_type() const;
74
75 /** Returns whether the pattern contains embedded references */
76 bool has_refs() const;
77 /** Checks the embedded referenced values */
78 void chk_refs(Type::expected_value_t expected_value=Type::EXPECTED_DYNAMIC_VALUE);
79 void chk_recursions(ReferenceChain& refch);
80 /** Checks the pattern by translating it to POSIX regexp */
81 void chk_pattern();
82 bool chk_self_ref(Common::Assignment *lhs);
83 /** Joins adjacent string components into one for more efficient code
84 * generation. */
85 void join_strings();
86 /** Temporary hack... */
87 string create_charstring_literals(Common::Module *p_mod);
88 virtual void dump(unsigned level) const;
89
90 /** Called by Value::get_value_refd_last() */
91 Value* get_value();
92
93 /** Converts this string pattern into a JSON schema string pattern. */
94 char* convert_to_json();
95 };
96
97 } // namespace Ttcn
98
99 #endif // _Ttcn_PatternString_HH
This page took 0.058433 seconds and 5 git commands to generate.