OpenDDS  Snapshot(2023/04/28-20:55)
be_util.cpp
Go to the documentation of this file.
1 
2 //=============================================================================
3 /**
4  * @file be_util.cpp
5  *
6  *
7  * Static helper methods used by multiple visitors.
8  *
9  *
10  * @author Gary Maxey
11  * @author Jeff Parsons
12  */
13 //=============================================================================
14 
15 #include "be_util.h"
16 
17 #include "be_extern.h"
18 
19 #include <ast_generator.h>
20 
21 #include <ace/OS_NS_strings.h>
22 
23 // Prepare an argument for a BE
24 void
25 be_util::prep_be_arg(char* arg)
26 {
27  static const char WB_EXPORT_MACRO[] = "export_macro=";
28  static const size_t SZ_WB_EXPORT_MACRO = sizeof(WB_EXPORT_MACRO) - 1;
29  static const char WB_EXPORT_INCLUDE[] = "export_include=";
30  static const size_t SZ_WB_EXPORT_INCLUDE = sizeof(WB_EXPORT_INCLUDE) - 1;
31  static const char WB_VERSIONING_NAME[] = "versioning_name=";
32  static const size_t SZ_WB_VERSIONING_NAME = sizeof(WB_VERSIONING_NAME) - 1;
33  static const char WB_VERSIONING_BEGIN[] = "versioning_begin=";
34  static const size_t SZ_WB_VERSIONING_BEGIN = sizeof(WB_VERSIONING_BEGIN) - 1;
35  static const char WB_VERSIONING_END[] = "versioning_end=";
36  static const size_t SZ_WB_VERSIONING_END = sizeof(WB_VERSIONING_END) - 1;
37  static const char WB_PCH_INCLUDE[] = "pch_include=";
38  static const size_t SZ_WB_PCH_INCLUDE = sizeof(WB_PCH_INCLUDE) - 1;
39  static const char WB_CPP_INCLUDE[] = "cpp_include=";
40  static const size_t SZ_WB_CPP_INCLUDE = sizeof(WB_CPP_INCLUDE) - 1;
41  static const char WB_JAVA[] = "java";
42  static const size_t SZ_WB_JAVA = sizeof(WB_JAVA) - 1;
43  static const char WB_TAO_INC_PRE[] = "tao_include_prefix=";
44  static const size_t SZ_WB_TAO_INC_PRE = sizeof(WB_TAO_INC_PRE) - 1;
45  static const char WB_TS_CPP_INCLUDE[] = "ts_cpp_include=";
46  static const size_t SZ_WB_TS_CPP_INCLUDE = sizeof(WB_TS_CPP_INCLUDE) - 1;
47  static const char WB_DDS_SEQ_SUFFIX[] = "opendds_sequence_suffix=";
48  static const size_t SZ_WB_DDS_SEQ_SUFFIX = sizeof(WB_DDS_SEQ_SUFFIX) - 1;
49 
50  if (0 == ACE_OS::strncasecmp(arg, WB_EXPORT_MACRO, SZ_WB_EXPORT_MACRO)) {
51  be_global->export_macro(arg + SZ_WB_EXPORT_MACRO);
52 
53  } else if (0 == ACE_OS::strncasecmp(arg, WB_EXPORT_INCLUDE,
54  SZ_WB_EXPORT_INCLUDE)) {
55  be_global->export_include(arg + SZ_WB_EXPORT_INCLUDE);
56 
57  } else if (0 == ACE_OS::strncasecmp(arg, WB_VERSIONING_NAME,
58  SZ_WB_VERSIONING_NAME)) {
59  be_global->versioning_name(arg + SZ_WB_VERSIONING_NAME);
60 
61  } else if (0 == ACE_OS::strncasecmp(arg, WB_VERSIONING_BEGIN,
62  SZ_WB_VERSIONING_BEGIN)) {
63  be_global->versioning_begin(arg + SZ_WB_VERSIONING_BEGIN);
64 
65  } else if (0 == ACE_OS::strncasecmp(arg, WB_VERSIONING_END,
66  SZ_WB_VERSIONING_END)) {
67  be_global->versioning_end(arg + SZ_WB_VERSIONING_END);
68 
69  } else if (0 == ACE_OS::strncasecmp(arg, WB_PCH_INCLUDE, SZ_WB_PCH_INCLUDE)) {
70  be_global->pch_include(arg + SZ_WB_PCH_INCLUDE);
71 
72  } else if (0 == ACE_OS::strncasecmp(arg, WB_CPP_INCLUDE, SZ_WB_CPP_INCLUDE)) {
73  be_global->add_cpp_include(arg + SZ_WB_CPP_INCLUDE);
74 
75  } else if (0 == ACE_OS::strncasecmp(arg, WB_JAVA, SZ_WB_JAVA)) {
76  be_global->java(true);
77  if (ACE_OS::strlen(arg + SZ_WB_JAVA)) {
78  be_global->java_arg(arg + SZ_WB_JAVA + 1 /* = */);
79  }
80 
81  } else if (0 == ACE_OS::strncasecmp(arg, WB_TAO_INC_PRE, SZ_WB_TAO_INC_PRE)) {
82  be_global->tao_inc_pre_ = arg + SZ_WB_TAO_INC_PRE;
83 
84  } else if (0 == ACE_OS::strncasecmp(arg, WB_TS_CPP_INCLUDE, SZ_WB_TS_CPP_INCLUDE)) {
85  be_global->add_include(arg + SZ_WB_TS_CPP_INCLUDE, BE_GlobalData::STREAM_CPP);
86 
87  } else if (0 == ACE_OS::strncasecmp(arg, WB_DDS_SEQ_SUFFIX, SZ_WB_DDS_SEQ_SUFFIX)) {
88  be_global->sequence_suffix(arg + SZ_WB_DDS_SEQ_SUFFIX);
89  }
90 }
91 
92 void
94 {
95 }
96 
97 void
99 {
100  // see be_global.cpp parse_args()
101  ACE_DEBUG((LM_DEBUG,
102  " -o <dir> set output directory for all files\n"
103  " -Lface generate FACE IDL to C++ mapping\n"
104  " -Lspcpp generate Safety Profile IDL to C++ mapping\n"
105  " -Lc++11 generate IDL to C++11 mapping\n"
106  " -SI suppress generation of *TypeSupport.idl\n"
107  " -Sa suppress IDL any (ignored, for tao_idl compatibility)\n"
108  " -St suppress IDL typecode when -L* option is present\n"
109  " -Sv suppress ValueReader and ValueWriter generation\n"
110  " -Sx suppress XTypes TypeObject and TypeIdentifier generation\n"
111  " -Sdefault exclude default TypeSupport generators from output\n"
112  " -Gitl generate ITL\n"
113  " -GfaceTS generate FACE TS API for DCPS data types\n"
114  " -Grapidjson generate TypeSupport for converting data samples to\n"
115  " RapidJSON JavaScript objects\n"
116  " -Gxtypes-complete generate XTypes complete TypeObject and TypeIdentifier\n"
117  " --filename-only-includes strip leading directories from generated\n"
118  " #include lines\n"
119  " --[no-]default-nested topic types must be declared\n"
120  " (true by default)\n"
121  " --no-dcps-data-type-warnings don't warn about #pragma DCPS_DATA_TYPE\n"
122  " --default-extensibility final|appendable|mutable\n"
123  " set the default XTypes extensibility\n"
124  " kind (appendable if not set)\n"
125  " --default-autoid sequential|hash set the default XTypes autoid approach\n"
126  " (sequential if not set)\n"
127  " --default-try-construct discard|use-default|trim\n"
128  " set the default XTypes try-construct\n"
129  " behavior (discard if not set)\n"
130  " --old-typeobject-encoding use the pre-3.18 encoding of TypeObjects\n"
131  " when deriving TypeIdentifiers\n"
132  " --old-typeobject-member-order use the pre-3.24 struct and union\n"
133  " member order for TypeObjects, which is\n"
134  " ordered by member id instead of\n"
135  " declared order\n"
136  " -Wb,export_macro=<macro name> set export macro for all files\n"
137  " --export=<macro name> Alias for -Wb,export_macro\n"
138  " -Wb,export_include=<include path> set export include file for all files\n"
139  " -Wb,versioning_name=<macro name> set versioning name macro for all files\n"
140  " -Wb,versioning_begin=<macro name> set versioning begin macro for all files\n"
141  " -Wb,versioning_end=<macro name> set versioning end macro for all files\n"
142  " -Wb,pch_include=<include path> set include file for precompiled header\n"
143  " mechanism\n"
144  " -Wb,cpp_include=<include path> set additional include file for cpp\n"
145  " files. Useful for 'after the fact'\n"
146  " typesupport generation with different\n"
147  " features enabled than in the first pass.\n"
148  " -Wb,java[=<output_file>] enable Java support for TypeSupport\n"
149  " files. Do not specify an 'output_file'\n"
150  " except for special cases.\n"
151  " -Wb,tao_include_prefix=<path> prefix for including the TAO-generated\n"
152  " header file.\n"
153  " -Wb,ts_cpp_include=<include> add <include> to *TypeSupportImpl.cpp\n"
154  " -Wb,opendds_sequence_suffix=<suffix> set the implied DDS sequence suffix\n"
155  " (default is 'Seq')\n"
156  ));
157 }
158 
159 AST_Generator*
161 {
162  AST_Generator* gen = 0;
163  ACE_NEW_RETURN(gen, AST_Generator, 0);
164  return gen;
165 }
166 
167 const char*
169 {
170  static const char* value = ACE_OS::getenv("DDS_ROOT");
171  if (!value || !value[0]) {
172  ACE_ERROR((LM_ERROR, "Error - The environment variable DDS_ROOT must be set.\n"));
173  BE_abort();
174  }
175  return value;
176 }
177 
178 void
179 be_util::misc_error_and_abort(const std::string& message, AST_Decl* node)
180 {
181  idl_global->err()->misc_error(message.c_str(), node);
182  BE_abort();
183 }
#define ACE_DEBUG(X)
#define ACE_ERROR(X)
const LogLevel::Value value
Definition: debug.cpp:61
static TAO_IFR_BE_Export AST_Generator * generator_init(void)
Definition: be_util.cpp:160
int strncasecmp(const char *s, const char *t, size_t len)
char * getenv(const char *symbol)
size_t strlen(const char *s)
static TAO_IFR_BE_Export void arg_post_proc(void)
Definition: be_util.cpp:93
static TAO_IFR_BE_Export void prep_be_arg(char *s)
Definition: be_util.cpp:25
const char * dds_root()
Get DDS_ROOT. It is a fatal error if it wasn&#39;t set.
BE_GlobalData * be_global
Definition: be_global.cpp:44
static TAO_IFR_BE_Export void usage(void)
Definition: be_util.cpp:98
#define ACE_NEW_RETURN(POINTER, CONSTRUCTOR, RET_VAL)
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
void BE_abort()
Definition: be_produce.cpp:103