d07c837e092b2f7311fb8c0310170085aa6c6a96
[deliverable/titan.core.git] / compiler2 / CodeGenHelper.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #ifndef _Common_CodeGenHelper_HH
9 #define _Common_CodeGenHelper_HH
10
11 #include "ttcn3/compiler.h"
12 #include "map.hh"
13 #include "vector.hh"
14 #include "string.hh"
15 #include "ttcn3/AST_ttcn3.hh"
16 #include "Type.hh"
17
18 namespace Ttcn {
19 class Definition;
20 }
21
22 namespace Common {
23
24 class CodeGenHelper {
25 public:
26 enum split_type {
27 SPLIT_NONE, ///< original code generation
28 SPLIT_BY_KIND, ///< place different kind of types in their own file
29 SPLIT_BY_NAME, ///< place all definitions/assignments in their own file
30 SPLIT_BY_HEURISTICS ///< heuristic function will decide the structure
31 };
32
33 private:
34 struct generated_output_t {
35
36 generated_output_t();
37 ~generated_output_t();
38
39 output_struct os;
40 string modulename;
41 string module_dispname;
42 string filename;
43 bool is_module;
44 bool is_ttcn;
45 bool has_circular_import;
46 };
47
48 static const char* const typetypemap[];
49
50 typedef map<string, generated_output_t> output_map_t;
51
52 output_map_t generated_code;
53 split_type split_mode;
54
55 struct module_names_t {
56 string name;
57 string dispname;
58 };
59
60 vector<module_names_t> modules;
61 string current_module;
62
63 static CodeGenHelper* instance;
64
65 public:
66 CodeGenHelper();
67
68 static CodeGenHelper& GetInstance();
69
70 void set_split_mode(split_type st);
71 bool set_split_mode(const char* type);
72 split_type get_split_mode() const;
73
74 void add_module(const string& name, const string& dispname, bool is_ttcn,
75 bool has_circular_import);
76 output_struct* get_outputstruct(const string& name);
77 output_struct* get_outputstruct(Ttcn::Definition* def);
78 output_struct* get_outputstruct(Type* type);
79 output_struct* get_current_outputstruct();
80 void finalize_generation(Type* type);
81
82 void set_current_module(const string& name);
83
84 void write_output();
85
86 ~CodeGenHelper();
87
88 private:
89 string get_key(Ttcn::Definition& def) const;
90 string get_key(Type& type) const;
91 static void transfer_value(char* &dst, char* &src);
92 };
93
94 }
95
96 #endif /* _Common_CodeGenHelper_HH */
This page took 0.06443 seconds and 5 git commands to generate.