Refactor ICG

Hey buddy. I wanted to tell you this before you heard it from someone
else...

I refactored ICG.

Now, it's gonna look a little scary at first. But I promise you'll like
it when you get used to it. It'll be fine. You can trust me. #341
This commit is contained in:
Derek Bankieris
2016-10-28 14:37:12 -05:00
parent ba75f6ff37
commit ef1405c3be
22 changed files with 365 additions and 1009 deletions

View File

@ -19,44 +19,37 @@ void PrintFileContents10::printIOHeader(std::ostream & ostream , std::string hea
} else {
header_file_name = almostRealPath(header_file_name.c_str()) ;
}
ostream <<
"/**\n"
" * This file was automatically generated by the ICG based on the file:\n"
" * " << header_file_name << "\n"
" * This file contains database parameter declarations specific to the\n"
" * data structures and enumerated types declared in the above file.\n"
" * These database parameters are used by the Trick input and\n"
" * data recording processors to gain access to important simulation\n"
" * variable information.\n"
" */\n"
"\n"
"#define TRICK_IN_IOSRC\n"
"#include <stdlib.h>\n"
"#include \"trick/MemoryManager.hh\"\n"
"#include \"trick/attributes.h\"\n"
"#include \"trick/parameter_types.h\"\n"
"#include \"trick/ClassSizeCheck.hh\"\n"
"#include \"trick/UnitsMap.hh\"\n"
"#include \"trick/checkpoint_stl.hh\"\n"
"#include \"" << header_file_name << "\"\n"
"\n" ;
ostream << "/**\n"
<< " * This file was automatically generated by the ICG based on the file:\n"
<< " * " << header_file_name << "\n"
<< " * This file contains database parameter declarations specific to the\n"
<< " * data structures and enumerated types declared in the above file.\n"
<< " * These database parameters are used by the Trick input and\n"
<< " * data recording processors to gain access to important simulation\n"
<< " * variable information.\n"
<< " */\n"
<< "\n"
<< "#define TRICK_IN_IOSRC\n"
<< "#include <stdlib.h>\n"
<< "#include \"trick/MemoryManager.hh\"\n"
<< "#include \"trick/attributes.h\"\n"
<< "#include \"trick/parameter_types.h\"\n"
<< "#include \"trick/ClassSizeCheck.hh\"\n"
<< "#include \"trick/UnitsMap.hh\"\n"
<< "#include \"trick/checkpoint_stl.hh\"\n"
<< "#include \"" << header_file_name << "\"\n"
<< "\n" ;
}
/** Prints enumeration attributes */
void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues * e ) {
print_open_extern_c(ostream) ;
ostream << "ENUM_ATTR enum" ;
printNamespaces( ostream, e , "__" ) ;
printContainerClasses( ostream, e , "__" ) ;
ostream << e->getName() << "[] = {\n" ;
for ( EnumValues::NameValueIterator nvit = e->begin() ; nvit != e->end() ; nvit++ ) {
ostream << "{\"";
printNamespaces( ostream, e , "::" ) ;
printContainerClasses( ostream, e , "::" ) ;
ostream << (*nvit).first << "\" , " << (*nvit).second << " , 0x0 } ,\n" ;
ostream << "ENUM_ATTR enum" << e->getFullyQualifiedTypeName("__") << "[] = {\n" ;
std::string name = e->getNamespacesAndContainerClasses();
for (auto& pair : e->getPairs()) {
ostream << "{\"" << name << pair.first << "\", " << pair.second << ", 0x0},\n" ;
}
ostream << "{\"\" , 0 , 0x0 }\n} ;\n" ;
ostream << "{\"\", 0, 0x0}\n};\n" ;
print_close_extern_c(ostream) ;
}
@ -64,29 +57,26 @@ void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues *
void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription * fdes ) {
int array_dim ;
ostream << "{ \"" << fdes->getName() << "\"" ; // name
ostream << ", \"" ; // start type_name
printNamespaces( ostream, fdes , "__" ) ;
printContainerClasses( ostream, fdes , "__" ) ;
ostream << fdes->getMangledTypeName() << "\""; // end type_name
ostream << ", \"" << fdes->getUnits() << "\"" ; // units
ostream << ", \"\", \"\"," << std::endl ; // alias , user_defined
ostream << " \"" << fdes->getDescription() << "\"," << std::endl ; // description
ostream << " " << fdes->getIO() ; // io
ostream << "," << fdes->getEnumString() ; // type
ostream << "{\"" << fdes->getName() << "\"" // name
<< ", \"" << fdes->getFullyQualifiedMangledTypeName("__") << "\"" // type_name
<< ", \"" << fdes->getUnits() << "\"" // units
<< ", \"\", \"\"," << std::endl // alias, user_defined
<< " \"" << fdes->getDescription() << "\"," << std::endl // description
<< " " << fdes->getIO() // io
<< "," << fdes->getEnumString() ; // type
// There are several cases when printing the size of a variable.
if ( fdes->isBitField() ) {
// bitfields are handled in 4 byte (32 bit) chunks
ostream << ",4" ;
ostream << ", 4" ;
} else if ( fdes->isRecord() or fdes->isEnum() or fdes->getTypeName().empty() ) {
// records enums use io_src_get_size. The sentinel has no typename
ostream << ",0" ;
ostream << ", 0" ;
} else {
// print size of the underlying type
ostream << ",sizeof(" << fdes->getTypeName() << ")" ;
ostream << ", sizeof(" << fdes->getTypeName() << ")" ;
}
ostream << ",0,0,Language_CPP" ; // range_min, range_max, language
ostream << "," << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
ostream << ", 0, 0, Language_CPP" ; // range_min, range_max, language
ostream << ", " << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
if ( fdes->isBitField() ) {
// For bitfields we need the offset to start on 4 byte boundaries because that is what our
// insert and extract bitfield routines work with.
@ -94,23 +84,23 @@ void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescri
} else {
ostream << " " << (fdes->getFieldOffset() / 8) ; // offset
}
ostream << ",NULL" ; // attr
ostream << "," << fdes->getNumDims() ; // num_index
ostream << ", NULL" ; // attr
ostream << ", " << fdes->getNumDims() ; // num_index
ostream << ",{" ;
ostream << ", {" ;
if ( fdes->isBitField() ) {
ostream << "{" << fdes->getBitFieldWidth() ; // size of bitfield
ostream << "," << 32 - (fdes->getFieldOffset() % 32) - fdes->getBitFieldWidth() << "}" ; // start bit
ostream << ", " << 32 - (fdes->getFieldOffset() % 32) - fdes->getBitFieldWidth() << "}" ; // start bit
} else {
array_dim = fdes->getArrayDim(0) ;
if ( array_dim < 0 ) array_dim = 0 ;
ostream << "{" << array_dim << ",0}" ; // index 0
ostream << "{" << array_dim << ", 0}" ; // index 0
}
unsigned int ii ;
for ( ii = 1 ; ii < 8 ; ii++ ) {
array_dim = fdes->getArrayDim(ii) ;
if ( array_dim < 0 ) array_dim = 0 ;
ostream << ",{" << array_dim << ",0}" ; // indexes 1 through 7
ostream << ", {" << array_dim << ", 0}" ; // indexes 1 through 7
}
ostream << "}," << std::endl ;
ostream << " NULL, NULL, NULL, NULL" ;
@ -120,19 +110,12 @@ void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescri
/** Prints class attributes */
void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues * c ) {
unsigned int ii ;
ClassValues::FieldIterator fit ;
print_open_extern_c(ostream) ;
ostream << "ATTRIBUTES attr" ;
printNamespaces( ostream, c , "__" ) ;
printContainerClasses( ostream, c , "__" ) ;
ostream << c->getMangledTypeName() ;
ostream << "[] = {" << std::endl ;
ostream << "ATTRIBUTES attr" << c->getFullyQualifiedMangledTypeName("__") << "[] = {" << std::endl ;
for ( fit = c->field_begin() ; fit != c->field_end() ; fit++ ) {
if ( determinePrintAttr(c , *fit) ) {
print_field_attr(ostream, *fit) ;
for (auto& fieldDescription : c->getFieldDescriptions()) {
if ( determinePrintAttr(c , fieldDescription) ) {
print_field_attr(ostream, fieldDescription) ;
ostream << "," << std::endl ;
}
}
@ -149,158 +132,80 @@ void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues
void PrintFileContents10::print_field_init_attr_stmts( std::ostream & ostream , FieldDescription * fdes ,
ClassValues * cv , unsigned int index ) {
// For static variables replace the offset field with the address of the static variable
if ( global_compat15 or cv->isCompat15()) {
if ( fdes->isStatic() ) {
// print a special offsetof statement if this is a static
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
ostream << cv->getName() << "::" << fdes->getName() << " ;\n" ;
} else if ( fdes->isBitField() ) {
// else if this is a bitfield
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = " ;
ostream << fdes->getBitFieldByteOffset() << " ;\n" ;
// All bitfield offsets are in terms of unsigned ints.
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].size = sizeof(unsigned int) ;\n" ;
} else if ( fdes->isVirtualInherited() ) {
// else if we have a virtually inherited class.
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = " << fdes->getBaseClassOffset() ;
ostream << " + offsetof(" ;
ostream << fdes->getContainerClass() << "," << fdes->getName() << ") ;\n" ;
} else if ( cv->getMangledTypeName() != cv->getName() ) {
// else if we have a template type where mangled_type_name is different then name.
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = offsetof(" ;
ostream << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ;
} else {
// else print an offsetof statement if this is not a special case
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = offsetof(" ;
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
ostream << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ;
const std::string className = cv->getName();
const std::string mangledClassName = cv->getMangledTypeName();
const std::string fieldName = fdes->getName();
const std::string fullyQualifiedClassNameColons = cv->getFullyQualifiedTypeName();
const std::string fullyQualifiedMangledClassNameColons = cv->getFullyQualifiedMangledTypeName();
const std::string fullyQualifiedMangledClassNameUnderscores = cv->getFullyQualifiedMangledTypeName("__");
std::ostringstream oss;
oss << " attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "].";
const std::string prefix = oss.str();
if ( fdes->isStatic() ) {
ostream << prefix << "offset = (long)(void *)&" << fullyQualifiedClassNameColons << "::" << fieldName << " ;\n" ;
}
else if ( global_compat15 or cv->isCompat15() ) {
if ( fdes->isBitField() ) {
ostream << prefix << "offset = " << fdes->getBitFieldByteOffset() << " ;\n" ;
ostream << prefix << "size = sizeof(unsigned int) ;\n" ;
}
} else {
if ( fdes->isStatic() ) {
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
ostream << cv->getName() << "::" << fdes->getName() << " ;\n" ;
else if ( fdes->isVirtualInherited() ) {
ostream << prefix << "offset = " << fdes->getBaseClassOffset() << " + offsetof(" << fdes->getContainerClass() << ", " << fieldName << ") ;\n" ;
}
else if ( mangledClassName != className ) {
ostream << prefix << "offset = " << "offsetof(" << mangledClassName << ", " << fieldName << ") ;\n" ;
}
else {
ostream << prefix << "offset = " << "offsetof(" << fullyQualifiedMangledClassNameColons << ", " << fieldName << ") ;\n" ;
}
}
if ( fdes->isSTL()) {
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].checkpoint_stl = checkpoint_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << " ;\n" ;
if ( fdes->isSTL() ) {
auto print = [&](const std::string& field) {
ostream << prefix << field << " = " << field << "_" << fullyQualifiedMangledClassNameUnderscores + "_" + fieldName + " ;\n";
};
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].post_checkpoint_stl = post_checkpoint_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << " ;\n" ;
print("checkpoint_stl");
print("post_checkpoint_stl");
print("restore_stl");
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].restore_stl = restore_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << " ;\n" ;
if (fdes->hasSTLClear()) {
ostream << " attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].clear_stl = clear_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << " ;\n" ;
if ( fdes->hasSTLClear() ) {
print("clear_stl");
}
}
if ( fdes->isRecord() or fdes->isEnum()) {
ostream << " trick_MM->add_attr_info(std::string(attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "].type_name) , &attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[" << index << "], __FILE__ , __LINE__ ) ;\n" ;
if ( fdes->isRecord() or fdes->isEnum() ) {
ostream << " trick_MM->add_attr_info(std::string(attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "].type_name) , &attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "], __FILE__ , __LINE__ ) ;\n" ;
}
}
/** Prints add_attr_info statements for each inherited class */
void PrintFileContents10::print_inherited_add_attr_info( std::ostream & ostream , ClassValues * cv ) {
ClassValues::InheritedClassesIterator cit ;
if ( cv->getNumInheritedClasses() > 0 ) {
auto inheritedClasses = cv->getInheritedClasses();
if ( inheritedClasses.size() > 0 ) {
ostream << "\n ATTRIBUTES temp_attr ;\n\n" ;
}
for ( cit = cv->inherit_classes_begin() ; cit != cv->inherit_classes_end() ; cit++ ) {
ostream << " trick_MM->add_attr_info( std::string(\"" << *cit << "\"), &temp_attr , __FILE__ , __LINE__ ) ;\n" ;
for ( auto& inheritedClass : inheritedClasses ) {
ostream << " trick_MM->add_attr_info( std::string(\"" << inheritedClass << "\"), &temp_attr , __FILE__ , __LINE__ ) ;\n" ;
}
}
/** Prints init_attr function for each class */
void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassValues * cv ) {
cv->printOpenNamespaceBlocks(ostream) ;
ostream << "\nvoid init_attr" << cv->getFullyQualifiedMangledTypeName("__") << "() {\n\n"
<< " static int initialized ;\n"
<< " if (initialized) {\n"
<< " return;\n"
<< " }\n"
<< " initialized = 1;\n\n" ;
ClassValues::FieldIterator fit ;
printOpenNamespaceBlocks(ostream, cv) ;
ostream << "\nvoid init_attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "() {\n\n"
" static int initialized ;\n"
" if ( initialized ) {\n"
" return ;\n"
" }\n"
" initialized = 1 ;\n\n" ;
#if 0
if ( cv->getMangledTypeName() != cv->getName() ) {
ostream << " typedef " << cv->getName() << " " << cv->getMangledTypeName() << " ;\n\n" ;
}
#if 0
if ( !global_compat15 and !cv->isCompat15()) {
ostream << " if ( sizeof(" ;
printNamespaces( ostream, cv , "::" ) ;
@ -317,296 +222,172 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa
}
#endif
unsigned int ii = 0 ;
for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
if ( determinePrintAttr(cv , *fit) ) {
print_field_init_attr_stmts(ostream, *fit, cv, ii) ;
ii++ ;
unsigned int ii = 0;
for ( auto field : cv->getFieldDescriptions() ) {
if ( determinePrintAttr(cv, field) ) {
print_field_init_attr_stmts(ostream, field, cv, ii++) ;
}
}
print_inherited_add_attr_info(ostream, cv ) ;
ostream << "}\n" ;
printCloseNamespaceBlocks(ostream, cv) ;
cv->printCloseNamespaceBlocks(ostream) ;
}
/** Prints the io_src_sizeof function for enumerations */
void PrintFileContents10::print_enum_io_src_sizeof( std::ostream & ostream , EnumValues * ev ) {
print_open_extern_c(ostream) ;
ostream << "size_t io_src_sizeof_" ;
printNamespaces( ostream, ev , "__" ) ;
printContainerClasses( ostream, ev , "__" ) ;
ostream << ev->getName() << "( void ) {\n" ;
ostream << "size_t io_src_sizeof_" << ev->getFullyQualifiedName("__") << "( void ) {\n" ;
if ( ev->getHasDefinition() ) {
ostream << " return( sizeof(" ;
printNamespaces( ostream, ev , "::" ) ;
printContainerClasses( ostream, ev , "::" ) ;
ostream << ev->getName() << "));\n}\n" ;
ostream << " return sizeof(" << ev->getFullyQualifiedName() << ")" ;
} else {
ostream << " return(sizeof(int)) ;\n}\n" ;
ostream << " return sizeof(int)" ;
}
ostream << ";\n}\n" ;
print_close_extern_c(ostream) ;
}
/** Prints the C linkage init_attr function */
void PrintFileContents10::print_init_attr_c_intf( std::ostream & ostream , ClassValues * cv ) {
ostream << "void init_attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "_c_intf() {\n " ;
printNamespaces( ostream, cv , "::" ) ;
ostream << "init_attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "() ;\n"
"}\n\n" ;
ostream << "void init_attr" << cv->getFullyQualifiedMangledTypeName("__") << "_c_intf() {\n " ;
cv->printNamespaces( ostream, "::" ) ;
ostream << "init_attr" << cv->getFullyQualifiedMangledTypeName("__") << "() ;\n"
<< "}\n\n" ;
}
/** Prints the io_src_sizeof function */
void PrintFileContents10::print_io_src_sizeof( std::ostream & ostream , ClassValues * cv ) {
ostream << "size_t io_src_sizeof_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "( void ) {\n" ;
ostream << " return( sizeof(" ;
// Template types
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << ") );\n}\n\n" ;
ostream << "size_t io_src_sizeof_" << cv->getFullyQualifiedMangledTypeName("__") << "() {\n" ;
ostream << " return sizeof(" << cv->getFullyQualifiedNameIfEqual() << ") ;\n}\n\n" ;
}
/** Prints the io_src_allocate function */
void PrintFileContents10::print_io_src_allocate( std::ostream & ostream , ClassValues * cv ) {
if ( cv->isPOD() or (! cv->isAbstract() and cv->getHasDefaultConstructor()) ) {
ostream << "void * io_src_allocate_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "( int num) {\n" ;
ostream << " " ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << " * temp = (" ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << " * )calloc( num, sizeof(" ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << "));\n" ;
if ( cv->isPOD() or ( !cv->isAbstract() and cv->getHasDefaultConstructor()) ) {
const std::string name = cv->getFullyQualifiedNameIfEqual();
ostream << "void* io_src_allocate_" << cv->getFullyQualifiedMangledTypeName("__") << "(int num) {\n" ;
ostream << " " << name << "* temp = (" << name << "*)calloc(num, sizeof(" << name << "));\n" ;
if ( ! cv->isPOD() ) {
ostream << " for (int ii=0 ; ii<num ; ii++) {\n" ;
ostream << " new( &temp[ii]) " ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << "();\n" << " }\n" ;
ostream << " for (int ii = 0; ii < num; ++ii) {\n" ;
ostream << " new(&temp[ii]) " << name << "();\n }\n" ;
}
ostream << " return ((void *)temp);\n" << "}\n\n" ;
ostream << " return (void*)temp;\n" << "}\n\n" ;
}
}
/** Prints the io_src_allocate function */
void PrintFileContents10::print_io_src_destruct( std::ostream & ostream , ClassValues * cv ) {
if ( cv->getHasPublicDestructor()) {
ostream << "void io_src_destruct_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "( void * addr __attribute__((unused)), int num __attribute__((unused)) ) {\n" ;
if ( cv->getHasPublicDestructor() ) {
ostream << "void io_src_destruct_" << cv->getFullyQualifiedMangledTypeName("__") << "(void* address __attribute__((unused)), int num __attribute__((unused))) {\n" ;
if ( ! cv->isPOD() ) {
// Add a using statement so we can call the destructor without fully qualifying it.
ClassValues::NamespaceIterator nsi = cv->namespace_begin() ;
if ( nsi != cv->namespace_end() ) {
auto namespaces = cv->getNamespaces();
if (namespaces.size()) {
ostream << " using namespace " ;
while ( nsi != cv->namespace_end() ) {
ostream << *nsi ;
nsi++ ;
if ( nsi != cv->namespace_end()) {
ostream << "::" ;
auto last = namespaces[namespaces.size() - 1];
for (auto& name : namespaces) {
ostream << name;
if (name != last) {
ostream << "::";
}
}
ostream << " ;\n" ;
ostream << ";\n " ;
}
ostream << " " ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
const std::string name = cv->getName();
const std::string qualifiedName = cv->getFullyQualifiedNameIfEqual();
ostream << qualifiedName << "* temp = (" << qualifiedName << "*)address;\n" ;
if ( cv->getMangledTypeName() == name ) {
ostream << " for (int ii = 0; ii < num; ++ii) {\n"
<< " temp[ii].~" << name << "();\n"
<< " }\n" ;
}
ostream << cv->getName() << " * temp = (" ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << " * )addr ;\n" ;
ostream << " for (int ii=0 ; ii<num ; ii++) {\n" ;
if ( cv->getMangledTypeName() == cv->getName() ) {
ostream << " temp[ii].~" ;
ostream << cv->getName() << "();\n" ;
}
ostream << " }\n" ;
}
ostream << "}\n\n" ;
}
}
void PrintFileContents10::print_io_src_delete( std::ostream & ostream , ClassValues * cv ) {
if ( cv->getHasPublicDestructor()) {
ostream << "void io_src_delete_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "( void * addr " ;
if ( cv->getHasPublicDestructor() ) {
ostream << "void io_src_delete_" << cv->getFullyQualifiedMangledTypeName("__") << "(void* address" ;
if ( ! cv->isPOD() ) {
ostream << ") {\n" ;
ostream << " delete (" ;
if ( cv->getMangledTypeName() == cv->getName() ) {
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
}
ostream << cv->getName() << "*)addr ;\n" ;
ostream << ") {\n delete (" << cv->getFullyQualifiedNameIfEqual() << "*)address;\n" ;
}
else {
ostream << "__attribute__((unused)) ) {" ;
ostream << " __attribute__((unused))) {" ;
}
ostream << "}\n" ;
}
}
void PrintFileContents10::print_stl_helper_proto(std::ostream & ostream , ClassValues * cv ) {
std::ostringstream oss;
auto& fieldDescriptions = cv->getFieldDescriptions();
for ( ClassValues::FieldIterator fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) {
oss << "void checkpoint_stl_" ;
printNamespaces( oss, cv , "__" ) ;
printContainerClasses( oss, cv , "__" ) ;
oss << cv->getMangledTypeName() ;
oss << "_" ;
oss << (*fit)->getName() ;
oss << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ;
if (!fieldDescriptions.size()) {
return;
}
oss << "void post_checkpoint_stl_" ;
printNamespaces( oss, cv , "__" ) ;
printContainerClasses( oss, cv , "__" ) ;
oss << cv->getMangledTypeName() ;
oss << "_" ;
oss << (*fit)->getName() ;
oss << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ;
print_open_extern_c(ostream) ;
oss << "void restore_stl_" ;
printNamespaces( oss, cv , "__" ) ;
printContainerClasses( oss, cv , "__" ) ;
oss << cv->getMangledTypeName() ;
oss << "_" ;
oss << (*fit)->getName() ;
oss << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ;
for (auto& field : cv->getFieldDescriptions()) {
if ( field->isSTL() and determinePrintAttr(cv, field) ) {
const std::string classAndFieldName = cv->getFullyQualifiedMangledTypeName("__") + "_" + field->getName();
if ((*fit)->hasSTLClear()) {
oss << "void clear_stl_" ;
printNamespaces( oss, cv , "__" ) ;
printContainerClasses( oss, cv , "__" ) ;
oss << cv->getMangledTypeName() ;
oss << "_" ;
oss << (*fit)->getName() ;
oss << "(void * start_address) ;" << std::endl ;
auto print = [&](const std::string& name) {
ostream << "void " << name << "_" << classAndFieldName
<< "(void* start_address, const char* obj_name , const char* var_name);" << std::endl ;
};
print("checkpoint_stl");
print("post_checkpoint_stl");
print("restore_checkpoint_stl");
if ( field->hasSTLClear() ) {
ostream << "void clear_stl_" << classAndFieldName << "(void* start_address);" << std::endl ;
}
}
}
std::string text = oss.str();
if (text.size()) {
print_open_extern_c(ostream) ;
ostream << text;
print_close_extern_c(ostream) ;
}
print_close_extern_c(ostream) ;
}
void PrintFileContents10::print_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
ostream << "void checkpoint_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ;
ostream << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ;
ostream << " " << "checkpoint_stl(*stl , obj_name , var_name) ;" << std::endl ;
ostream << "}" << std::endl ;
printStlFunction("checkpoint", "void* start_address, const char* obj_name , const char* var_name", "checkpoint_stl(*stl, obj_name, var_name)", ostream, *fdes, *cv);
}
void PrintFileContents10::print_post_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
ostream << "void post_checkpoint_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ;
ostream << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ;
ostream << " " << "delete_stl(*stl , obj_name , var_name) ;" << std::endl ;
ostream << "}" << std::endl ;
printStlFunction("post_checkpoint", "void* start_address, const char* obj_name , const char* var_name", "delete_stl(*stl, obj_name, var_name)", ostream, *fdes, *cv);
}
void PrintFileContents10::print_restore_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
ostream << "void restore_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << "(void * start_address, const char * obj_name , const char * var_name) {" << std::endl ;
ostream << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ;
ostream << " " << "restore_stl(*stl , obj_name , var_name) ;" << std::endl ;
ostream << "}" << std::endl ;
printStlFunction("restore", "void* start_address, const char* obj_name , const char* var_name", "restore_stl(*stl, obj_name, var_name)",ostream, *fdes, *cv);
}
void PrintFileContents10::print_clear_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
ostream << "void clear_stl_" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() ;
ostream << "_" ;
ostream << fdes->getName() ;
ostream << "(void * start_address) {" << std::endl ;
ostream << " " << fdes->getTypeName() << " * stl = reinterpret_cast<" << fdes->getTypeName() << " * >(start_address) ;" << std::endl ;
ostream << " " << "stl->clear() ;" << std::endl ;
ostream << "}" << std::endl ;
printStlFunction("clear", "void* start_address", "stl->clear()",ostream, *fdes, *cv);
}
void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues * cv ) {
std::ostringstream oss;
auto& fieldDescriptions = cv->getFieldDescriptions();
for ( ClassValues::FieldIterator fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) {
print_checkpoint_stl(oss , *fit, cv) ;
print_post_checkpoint_stl(oss , *fit, cv) ;
print_restore_stl(oss , *fit, cv) ;
if ((*fit)->hasSTLClear()) {
print_clear_stl(oss , *fit, cv) ;
if (!fieldDescriptions.size()) {
return;
}
print_open_extern_c(ostream) ;
for (auto& field : fieldDescriptions) {
if ( field->isSTL() and determinePrintAttr(cv, field) ) {
print_checkpoint_stl(ostream, field, cv) ;
print_post_checkpoint_stl(ostream, field, cv) ;
print_restore_stl(ostream, field, cv) ;
if (field->hasSTLClear()) {
print_clear_stl(ostream, field, cv) ;
}
}
}
std::string text = oss.str();
if (text.size()) {
print_open_extern_c(ostream) ;
ostream << text;
print_close_extern_c(ostream) ;
}
print_close_extern_c(ostream) ;
}
void PrintFileContents10::printClass( std::ostream & ostream , ClassValues * cv ) {
@ -646,19 +427,10 @@ void PrintFileContents10::printClassMapHeader( std::ostream & ostream , std::str
}
void PrintFileContents10::printClassMap( std::ostream & ostream , ClassValues * cv ) {
ostream << " // " << cv->getFileName() << std::endl ;
ostream << " extern ATTRIBUTES attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << "[] ;" << std::endl ;
ostream << " class_attribute_map->add_attr(\"" ;
printNamespaces( ostream, cv , "::" ) ;
printContainerClasses( ostream, cv , "::" ) ;
ostream << cv->getMangledTypeName() << "\" , attr" ;
printNamespaces( ostream, cv , "__" ) ;
printContainerClasses( ostream, cv , "__" ) ;
ostream << cv->getMangledTypeName() << ") ;" << std::endl ;
std::string name = cv->getFullyQualifiedMangledTypeName("__");
ostream << " // " << cv->getFileName() << std::endl
<< " extern ATTRIBUTES attr" << name << "[] ;" << std::endl
<< " class_attribute_map->add_attr(\"" << cv->getFullyQualifiedMangledTypeName() << "\" , attr" << name << ") ;" << std::endl ;
}
void PrintFileContents10::printClassMapFooter( std::ostream & ostream ) {
@ -666,26 +438,26 @@ void PrintFileContents10::printClassMapFooter( std::ostream & ostream ) {
}
void PrintFileContents10::printEnumMapHeader( std::ostream & ostream , std::string function_name ) {
ostream <<
"void " << function_name << "() {\n"
" Trick::EnumAttributesMap * enum_attribute_map __attribute__((unused)) = Trick::EnumAttributesMap::attributes_map();\n\n" ;
ostream << "void " << function_name << "() {\n"
<< " Trick::EnumAttributesMap* enum_attribute_map __attribute__((unused)) = Trick::EnumAttributesMap::attributes_map();\n\n" ;
}
void PrintFileContents10::printEnumMap( std::ostream & ostream , EnumValues * ev ) {
ostream << " extern ENUM_ATTR enum" ;
printNamespaces( ostream, ev , "__" ) ;
printContainerClasses( ostream, ev , "__" ) ;
ostream << ev->getName() << "[] ;" << std::endl ;
ostream << " enum_attribute_map->add_attr(\"" ;
printNamespaces( ostream, ev , "::" ) ;
printContainerClasses( ostream, ev , "::" ) ;
ostream << ev->getName() << "\" , enum" ;
printNamespaces( ostream, ev , "__" ) ;
printContainerClasses( ostream, ev , "__" ) ;
ostream << ev->getName() << ") ;" << std::endl ;
std::string name = ev->getFullyQualifiedTypeName("__");
ostream << " extern ENUM_ATTR enum" << name << "[];" << std::endl
<< " enum_attribute_map->add_attr(\"" << ev->getFullyQualifiedTypeName() << "\", enum" << name << ");" << std::endl ;
}
void PrintFileContents10::printEnumMapFooter( std::ostream & ostream ) {
ostream << "}" << std::endl << std::endl ;
}
void PrintFileContents10::printStlFunction(const std::string& name, const std::string& parameters, const std::string& call, std::ostream& ostream, FieldDescription& fieldDescription, ClassValues& classValues) {
const std::string typeName = fieldDescription.getTypeName();
const std::string functionName = name + "_stl";
ostream << "void " << functionName << "_" << classValues.getFullyQualifiedMangledTypeName("__") << "_" << fieldDescription.getName()
<< "(" << parameters << ") {" << std::endl
<< " " << typeName << "* stl = reinterpret_cast<" << typeName << "*>(start_address);" << std::endl
<< " " << call << ";" << std::endl
<< "}" << std::endl ;
}