#include <itl_generator.h>
Classes | |
struct | Close |
struct | Indent |
struct | Open |
Public Member Functions | |
itl_generator () | |
bool | do_included_files () const |
void | gen_prologue () |
void | gen_epilogue () |
bool | gen_enum (AST_Enum *, UTL_ScopedName *name, const std::vector< AST_EnumVal * > &contents, const char *repoid) |
bool | gen_struct (AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *repoid) |
bool | gen_typedef (AST_Typedef *, UTL_ScopedName *, AST_Type *, const char *) |
bool | gen_union (AST_Union *, UTL_ScopedName *, const std::vector< AST_UnionBranch * > &, AST_Type *, const char *) |
Public Attributes | |
int | level_ |
Private Member Functions | |
void | new_type () |
Private Attributes | |
size_t | count_ |
Definition at line 14 of file itl_generator.h.
itl_generator::itl_generator | ( | ) | [inline] |
Definition at line 16 of file itl_generator.h.
bool itl_generator::do_included_files | ( | ) | const [inline, virtual] |
Reimplemented from dds_generator.
Definition at line 21 of file itl_generator.h.
bool itl_generator::gen_enum | ( | AST_Enum * | , | |
UTL_ScopedName * | name, | |||
const std::vector< AST_EnumVal * > & | contents, | |||
const char * | repoid | |||
) | [virtual] |
Reimplemented from dds_generator.
Definition at line 153 of file itl_generator.cpp.
References be_global, and new_type().
00155 { 00156 if (!be_global->generate_itl()) 00157 return true; 00158 00159 new_type(); 00160 00161 be_global->itl_ << Open(this) 00162 << Indent(this) << "{\n" 00163 << Open(this) 00164 << Indent(this) << "\"kind\" : \"alias\",\n" 00165 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00166 << Indent(this) << "\"type\" :\n" 00167 << Open(this) 00168 << Indent(this) << "{\n" 00169 << Open(this) 00170 << Indent(this) << "\"kind\" : \"int\",\n" 00171 << Indent(this) << "\"bits\" : 32,\n" 00172 << Indent(this) << "\"unsigned\" : true,\n" 00173 << Indent(this) << "\"constrained\" : true,\n" 00174 << Indent(this) << "\"values\" : {"; 00175 00176 for (size_t i = 0; i < contents.size(); ++i) { 00177 if (i > 0) 00178 be_global->itl_ << ", "; 00179 be_global->itl_ << '"' << contents[i]->local_name()->get_string() << '"' 00180 << " : " 00181 << '"' << i << '"'; 00182 } 00183 00184 be_global->itl_ << "}\n"; 00185 be_global->itl_ << Close(this) 00186 << Indent(this) << "}\n" 00187 << Close(this); 00188 00189 be_global->itl_ << Close(this) 00190 << Indent(this) << "}\n" 00191 << Close(this); 00192 00193 return true; 00194 }
void itl_generator::gen_epilogue | ( | ) | [virtual] |
Reimplemented from dds_generator.
Definition at line 138 of file itl_generator.cpp.
References be_global.
00139 { 00140 be_global->itl_ << Indent(this) << "]\n" 00141 << Close(this) 00142 << Close(this) 00143 << Indent(this) << "}\n"; 00144 }
void itl_generator::gen_prologue | ( | ) | [virtual] |
Reimplemented from dds_generator.
Definition at line 129 of file itl_generator.cpp.
References be_global.
00130 { 00131 be_global->itl_ << Indent(this) << "{\n" 00132 << Open(this) 00133 << Indent(this) << "\"types\" :\n" 00134 << Open(this) 00135 << Indent(this) << "[\n"; 00136 }
bool itl_generator::gen_struct | ( | AST_Structure * | , | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | repoid | |||
) | [virtual] |
Implements dds_generator.
Definition at line 295 of file itl_generator.cpp.
References be_global, and new_type().
00298 { 00299 if (!be_global->generate_itl()) 00300 return true; 00301 00302 new_type(); 00303 be_global->itl_ << Open(this) 00304 << Indent(this) << "{\n" 00305 << Open(this) 00306 << Indent(this) << "\"kind\" : \"alias\",\n" 00307 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00308 00309 // Check if this is defined as a primary data type 00310 << Indent(this) << "\"note\" : { \"is_dcps_data_type\" : " 00311 << (idl_global->is_dcps_type(name) ? "true" : "false") 00312 << " },\n" 00313 00314 << Indent(this) << "\"type\" :\n" 00315 << Open(this) 00316 << Indent(this) << "{\n" 00317 << Open(this) 00318 << Indent(this) << "\"kind\" : \"record\",\n" 00319 << Indent(this) << "\"fields\" :\n" 00320 << Open(this) 00321 << Indent(this) << "[\n"; 00322 00323 bool comma_flag = false; 00324 for (std::vector<AST_Field*>::const_iterator pos = fields.begin(), limit = fields.end(); 00325 pos != limit; 00326 ++pos) { 00327 AST_Field* field = *pos; 00328 if (comma_flag) { 00329 be_global->itl_ << Indent(this) << ",\n"; 00330 } 00331 be_global->itl_ << Open(this) 00332 << Indent(this) << "{\n" 00333 << Open(this) 00334 << Indent(this) << "\"name\" : \"" << field->local_name()->get_string() << "\",\n" 00335 << Indent(this) << "\"type\" : " << InlineType(field->field_type()) << "\n" 00336 << Close(this) 00337 << Indent(this) << "}\n" 00338 << Close(this); 00339 comma_flag = true; 00340 } 00341 00342 be_global->itl_ << Indent(this) << "]\n" 00343 << Close(this) 00344 << Close(this) 00345 << Indent(this) << "}\n" 00346 << Close(this) 00347 << Close(this) 00348 << Indent(this) << "}\n" 00349 << Close(this); 00350 00351 00352 return true; 00353 }
bool itl_generator::gen_typedef | ( | AST_Typedef * | , | |
UTL_ScopedName * | , | |||
AST_Type * | base, | |||
const char * | repoid | |||
) | [virtual] |
Implements dds_generator.
Definition at line 196 of file itl_generator.cpp.
References be_global, and new_type().
00199 { 00200 if (!be_global->generate_itl()) 00201 return true; 00202 00203 new_type(); 00204 switch (base->node_type()) { 00205 case AST_Decl::NT_sequence: 00206 { 00207 AST_Sequence *seq = AST_Sequence::narrow_from_decl(base); 00208 be_global->itl_ << Open(this) 00209 << Indent(this) << "{\n" 00210 << Open(this) 00211 << Indent(this) << "\"kind\" : \"alias\",\n" 00212 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00213 << Indent(this) << "\"type\" :\n" 00214 << Open(this) 00215 << Indent(this) << "{\n" 00216 << Open(this) 00217 << Indent(this) << "\"kind\" : \"sequence\",\n"; 00218 if (!seq->unbounded()) { 00219 be_global->itl_ << Indent(this) << "\"capacity\" : " << seq->max_size()->ev()->u.ulval << ",\n"; 00220 } 00221 be_global->itl_ << Indent(this) << "\"type\" : " << InlineType(seq->base_type()) << "\n" 00222 << Close(this) 00223 << Indent(this) << "}\n" 00224 << Close(this) 00225 << Close(this) 00226 << Indent(this) << "}\n" 00227 << Close(this); 00228 break; 00229 } 00230 case AST_Decl::NT_array: 00231 { 00232 AST_Array* arr = AST_Array::narrow_from_decl(base); 00233 be_global->itl_ << Open(this) 00234 << Indent(this) << "{\n" 00235 << Open(this) 00236 << Indent(this) << "\"kind\" : \"alias\",\n" 00237 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00238 << Indent(this) << "\"type\" :\n" 00239 << Open(this) 00240 << Indent(this) << "{\n" 00241 << Open(this) 00242 << Indent(this) << "\"kind\" : \"sequence\",\n" 00243 << Indent(this) << "\"type\" : " << InlineType(arr->base_type()) << ",\n" 00244 << Indent(this) << "\"size\" : ["; 00245 ACE_CDR::ULong dims = arr->n_dims(); 00246 for (size_t i = 0; i < dims; ++i) { 00247 if (i > 0) 00248 be_global->itl_ << ", "; 00249 be_global->itl_ << arr->dims()[i]->ev()->u.ulval; 00250 } 00251 be_global->itl_ << "]\n" 00252 << Close(this) 00253 << Indent(this) << "}\n" 00254 << Close(this) 00255 << Close(this) 00256 << Indent(this) << "}\n" 00257 << Close(this); 00258 break; 00259 } 00260 case AST_Decl::NT_fixed: 00261 { 00262 AST_Fixed* fixed = AST_Fixed::narrow_from_decl(base); 00263 unsigned digits = fixed->digits()->ev()->u.ulval; 00264 unsigned scale = fixed->scale()->ev()->u.ulval; 00265 be_global->itl_ 00266 << Open(this) << Indent(this) << "{\n" << Open(this) 00267 << Indent(this) << "\"kind\" : \"alias\",\n" 00268 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00269 << Indent(this) << "\"type\" : { " 00270 << "\"kind\" : \"fixed\", " 00271 << "\"digits\" : " << digits << ", " 00272 << "\"scale\" : " << scale << ", " 00273 << "\"base\" : 10 }\n" 00274 << Close(this) << Indent(this) << "}\n" << Close(this); 00275 break; 00276 } 00277 default: 00278 { 00279 be_global->itl_ << Open(this) 00280 << Indent(this) << "{\n" 00281 << Open(this) 00282 << Indent(this) << "\"kind\" : \"alias\",\n" 00283 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00284 << Indent(this) << "\"type\" : " << InlineType(base) << "\n" 00285 << Close(this) 00286 << Indent(this) << "}\n" 00287 << Close(this); 00288 00289 return true; 00290 } 00291 } 00292 return true; 00293 }
bool itl_generator::gen_union | ( | AST_Union * | , | |
UTL_ScopedName * | , | |||
const std::vector< AST_UnionBranch * > & | cases, | |||
AST_Type * | _d, | |||
const char * | repoid | |||
) | [virtual] |
Implements dds_generator.
Definition at line 356 of file itl_generator.cpp.
References be_global, and new_type().
00360 { 00361 if (!be_global->generate_itl()) 00362 return true; 00363 00364 new_type(); 00365 be_global->itl_ << Open(this) 00366 << Indent(this) << "{\n" 00367 << Open(this) 00368 << Indent(this) << "\"kind\" : \"alias\",\n" 00369 << Indent(this) << "\"name\" : \"" << repoid << "\",\n" 00370 << Indent(this) << "\"type\" :\n" 00371 << Open(this) 00372 << Indent(this) << "{\n" 00373 << Open(this) 00374 << Indent(this) << "\"kind\" : \"union\",\n" 00375 << Indent(this) << "\"discriminator\" : " << InlineType(_d) << ",\n" 00376 << Indent(this) << "\"fields\" :\n" 00377 << Open(this) 00378 << Indent(this) << "[\n"; 00379 00380 for (std::vector<AST_UnionBranch*>::const_iterator pos = cases.begin(), limit = cases.end(); 00381 pos != limit; 00382 ++pos) { 00383 if (pos != cases.begin()) 00384 be_global->itl_ << Indent(this) << ",\n"; 00385 00386 AST_UnionBranch *branch = *pos; 00387 00388 be_global->itl_ << Open(this) 00389 << Indent(this) << "{\n" 00390 << Open(this) 00391 << Indent(this) << "\"name\" : \"" << branch->local_name()->get_string() << "\",\n" 00392 << Indent(this) << "\"type\" : " << InlineType(branch->field_type()) << ",\n" 00393 00394 << Indent(this) << "\"labels\" : ["; 00395 00396 00397 unsigned long count = branch->label_list_length(); 00398 for (unsigned long i = 0; i < count; i++) 00399 { 00400 if (i > 0) 00401 be_global->itl_ << ", "; 00402 AST_UnionLabel *label = branch->label(i); 00403 if (label->label_kind() == AST_UnionLabel::UL_default) 00404 { 00405 continue; 00406 } 00407 be_global->itl_ << "\"" << label->label_val()->n()->last_component()->get_string() << "\""; 00408 } 00409 00410 be_global->itl_ << "]\n" 00411 << Close(this) 00412 << Indent(this) << "}\n" 00413 << Close(this); 00414 } 00415 00416 be_global->itl_ << Indent(this) << "]\n" 00417 << Close(this) 00418 << Close(this) 00419 << Indent(this) << "}\n" 00420 << Close(this) 00421 << Close(this) 00422 << Indent(this) << "}\n" 00423 << Close(this); 00424 00425 return true; 00426 }
void itl_generator::new_type | ( | ) | [private] |
Definition at line 146 of file itl_generator.cpp.
References be_global, and count_.
Referenced by gen_enum(), gen_struct(), gen_typedef(), and gen_union().
00147 { 00148 if (count_ > 0) 00149 be_global->itl_ << Indent(this) << ",\n"; 00150 ++count_; 00151 }
size_t itl_generator::count_ [private] |
Definition at line 65 of file itl_generator.h.
Referenced by new_type().
Definition at line 62 of file itl_generator.h.
Referenced by operator<<().