mirror of
https://github.com/nasa/trick.git
synced 2024-12-19 21:27:54 +00:00
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:
parent
ba75f6ff37
commit
ef1405c3be
@ -175,10 +175,6 @@ void ClassValues::clearAmbiguousVariables() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<FieldDescription *> ClassValues::getFieldDescription() {
|
|
||||||
return field_descripts ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClassValues::clearFieldDescription() {
|
void ClassValues::clearFieldDescription() {
|
||||||
field_descripts.clear() ;
|
field_descripts.clear() ;
|
||||||
}
|
}
|
||||||
@ -239,20 +235,6 @@ bool ClassValues::getHasPublicDestructor() {
|
|||||||
return has_public_destructor ;
|
return has_public_destructor ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClassValues::getFullyQualifiedTypeName() {
|
|
||||||
std::ostringstream oss ;
|
|
||||||
NamespaceIterator ni ;
|
|
||||||
|
|
||||||
for ( ni = namespace_begin() ; ni != namespace_end() ; ni++ ) {
|
|
||||||
oss << (*ni) << "::" ;
|
|
||||||
}
|
|
||||||
for ( ni = container_class_begin() ; ni != container_class_end() ; ni++ ) {
|
|
||||||
oss << (*ni) << "::" ;
|
|
||||||
}
|
|
||||||
oss << name ;
|
|
||||||
return oss.str() ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClassValues::setMangledTypeName( std::string in_val ) {
|
void ClassValues::setMangledTypeName( std::string in_val ) {
|
||||||
mangled_type_name = in_val ;
|
mangled_type_name = in_val ;
|
||||||
}
|
}
|
||||||
@ -264,20 +246,23 @@ std::string ClassValues::getMangledTypeName() {
|
|||||||
return mangled_type_name ;
|
return mangled_type_name ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ClassValues::getFullyQualifiedMangledTypeName() {
|
std::string ClassValues::getFullyQualifiedMangledTypeName(const std::string& delimiter) {
|
||||||
std::ostringstream oss ;
|
std::ostringstream oss ;
|
||||||
NamespaceIterator ni ;
|
printNamespacesAndContainerClasses(oss, delimiter) ;
|
||||||
|
|
||||||
for ( ni = namespace_begin() ; ni != namespace_end() ; ni++ ) {
|
|
||||||
oss << (*ni) << "::" ;
|
|
||||||
}
|
|
||||||
for ( ni = container_class_begin() ; ni != container_class_end() ; ni++ ) {
|
|
||||||
oss << (*ni) << "::" ;
|
|
||||||
}
|
|
||||||
oss << getMangledTypeName() ;
|
oss << getMangledTypeName() ;
|
||||||
return oss.str() ;
|
return oss.str() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ClassValues::getFullyQualifiedNameIfEqual() {
|
||||||
|
std::string result;
|
||||||
|
if (getName() == getMangledTypeName()) {
|
||||||
|
result += getNamespacesAndContainerClasses();
|
||||||
|
}
|
||||||
|
result += getName();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ClassValues::setCompat15(bool in_val) {
|
void ClassValues::setCompat15(bool in_val) {
|
||||||
compat15 = in_val ;
|
compat15 = in_val ;
|
||||||
}
|
}
|
||||||
@ -286,38 +271,6 @@ bool ClassValues::isCompat15() {
|
|||||||
return compat15 ;
|
return compat15 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClassValues::print_namespaces(std::ostream & os, const char * delimiter) {
|
bool ClassValues::isInStandardNamespace() {
|
||||||
unsigned int ii ;
|
return namespaces.size() && !namespaces[0].compare("std");
|
||||||
for ( ii = 0 ; ii < namespaces.size() ; ii++ ) {
|
|
||||||
os << namespaces[ii] << delimiter ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & os , ClassValues & cv ) {
|
|
||||||
os << " name = " << cv.name << std::endl ;
|
|
||||||
os << " mangled_name = " << cv.mangled_type_name << std::endl ;
|
|
||||||
os << " file_name = " << cv.file_name << std::endl ;
|
|
||||||
os << " namespaces =" ;
|
|
||||||
ConstructValues::NamespaceIterator it ;
|
|
||||||
for ( it = cv.namespace_begin() ; it != cv.namespace_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " parent classes =" ;
|
|
||||||
for ( it = cv.container_class_begin() ; it != cv.container_class_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " has_init_attr_friend = " << cv.has_init_attr_friend << std::endl ;
|
|
||||||
os << " is_pod = " << cv.is_pod << std::endl ;
|
|
||||||
os << " is_abstract = " << cv.is_abstract << std::endl ;
|
|
||||||
os << " has_default_constructor = " << cv.has_default_constructor << std::endl ;
|
|
||||||
os << " has_public_destructor = " << cv.has_public_destructor << std::endl ;
|
|
||||||
|
|
||||||
ClassValues::FieldIterator fit ;
|
|
||||||
for ( fit = cv.field_begin() ; fit != cv.field_end() ; fit++ ) {
|
|
||||||
os << **fit << std::endl ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return os ;
|
|
||||||
}
|
}
|
||||||
|
@ -40,28 +40,26 @@ class ClassValues : public ConstructValues {
|
|||||||
unsigned int class_offset, bool virtual_inherited) ;
|
unsigned int class_offset, bool virtual_inherited) ;
|
||||||
|
|
||||||
/** Gets the list of fields in this class */
|
/** Gets the list of fields in this class */
|
||||||
std::vector<FieldDescription *> getFieldDescription() ;
|
const std::vector<FieldDescription*>& getFieldDescriptions() {
|
||||||
|
return field_descripts ;
|
||||||
|
}
|
||||||
|
|
||||||
void clearFieldDescription() ;
|
void clearFieldDescription() ;
|
||||||
|
|
||||||
typedef std::vector< FieldDescription * >::iterator FieldIterator ;
|
|
||||||
FieldIterator field_begin() { return field_descripts.begin() ; } ;
|
|
||||||
FieldIterator field_end() { return field_descripts.end() ; } ;
|
|
||||||
|
|
||||||
/** Appends an inherited class name to the list this class inherits from */
|
/** Appends an inherited class name to the list this class inherits from */
|
||||||
void addInheritedClass( std::string class_name ) ;
|
void addInheritedClass( std::string class_name ) ;
|
||||||
|
|
||||||
|
/** Gets the list of inherited classes */
|
||||||
|
const std::vector<std::string>& getInheritedClasses() {
|
||||||
|
return inherited_classes ;
|
||||||
|
}
|
||||||
|
|
||||||
void saveInheritAncestry( ClassValues * in_cv ) ;
|
void saveInheritAncestry( ClassValues * in_cv ) ;
|
||||||
void setContainerClassForFields() ;
|
void setContainerClassForFields() ;
|
||||||
void clearAmbiguousVariables() ;
|
void clearAmbiguousVariables() ;
|
||||||
|
|
||||||
void clearInheritedClass() ;
|
void clearInheritedClass() ;
|
||||||
|
|
||||||
typedef std::vector< std::string >::iterator InheritedClassesIterator ;
|
|
||||||
InheritedClassesIterator inherit_classes_begin() { return inherited_classes.begin() ; } ;
|
|
||||||
InheritedClassesIterator inherit_classes_end() { return inherited_classes.end() ; } ;
|
|
||||||
unsigned int getNumInheritedClasses() { return inherited_classes.size() ; } ;
|
|
||||||
|
|
||||||
void setVirtualInherited(bool in_inh) ;
|
void setVirtualInherited(bool in_inh) ;
|
||||||
bool isVirtualInherited() ;
|
bool isVirtualInherited() ;
|
||||||
void setHasInitAttrFriend(bool in_val) ;
|
void setHasInitAttrFriend(bool in_val) ;
|
||||||
@ -76,19 +74,15 @@ class ClassValues : public ConstructValues {
|
|||||||
bool getHasDefaultConstructor() ;
|
bool getHasDefaultConstructor() ;
|
||||||
void setHasPublicDestructor(bool in_val) ;
|
void setHasPublicDestructor(bool in_val) ;
|
||||||
bool getHasPublicDestructor() ;
|
bool getHasPublicDestructor() ;
|
||||||
std::string getFullyQualifiedTypeName() ;
|
|
||||||
void setMangledTypeName( std::string in_val ) ;
|
void setMangledTypeName( std::string in_val ) ;
|
||||||
std::string getMangledTypeName() ;
|
std::string getMangledTypeName() ;
|
||||||
std::string getFullyQualifiedMangledTypeName() ;
|
std::string getFullyQualifiedMangledTypeName(const std::string& delimiter = "::") ;
|
||||||
|
std::string getFullyQualifiedNameIfEqual();
|
||||||
void setCompat15(bool in_val) ;
|
void setCompat15(bool in_val) ;
|
||||||
bool isCompat15() ;
|
bool isCompat15() ;
|
||||||
|
bool isInStandardNamespace();
|
||||||
void print_namespaces(std::ostream & os, const char * delimiter) ;
|
|
||||||
|
|
||||||
friend std::ostream & operator << (std::ostream & os , ClassValues & cv ) ;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** List of fields (data members) contained in the class */
|
|
||||||
std::vector< FieldDescription * > field_descripts ;
|
std::vector< FieldDescription * > field_descripts ;
|
||||||
|
|
||||||
std::map< std::string , FieldDescription * > field_name_to_info_map ;
|
std::map< std::string , FieldDescription * > field_name_to_info_map ;
|
||||||
|
@ -209,7 +209,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
||||||
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
||||||
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
||||||
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(),
|
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(),
|
||||||
inherit_class_offset, false) ;
|
inherit_class_offset, false) ;
|
||||||
// clear the field list in the inherited class so they are not freed when inherit_cvis
|
// clear the field list in the inherited class so they are not freed when inherit_cvis
|
||||||
// goes out of scope.
|
// goes out of scope.
|
||||||
@ -260,7 +260,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
||||||
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
||||||
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
||||||
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(), inherit_class_offset, true) ;
|
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescriptions(), inherit_class_offset, true) ;
|
||||||
// clear the field list in the inherited class so they are not freed when inherit_cvis goes out of scope.
|
// clear the field list in the inherited class so they are not freed when inherit_cvis goes out of scope.
|
||||||
inherit_cvis.get_class_data()->clearFieldDescription() ;
|
inherit_cvis.get_class_data()->clearFieldDescription() ;
|
||||||
// If we are inheriting from a template specialization, don't save the inherited class. This list
|
// If we are inheriting from a template specialization, don't save the inherited class. This list
|
||||||
@ -300,7 +300,7 @@ bool CXXRecordVisitor::VisitFriendDecl( clang::FriendDecl *fd ) {
|
|||||||
//nd->dump() ;
|
//nd->dump() ;
|
||||||
std::string init_func = std::string("init_attr") ;
|
std::string init_func = std::string("init_attr") ;
|
||||||
std::stringstream name_sp ;
|
std::stringstream name_sp ;
|
||||||
cval.print_namespaces( name_sp , "__") ;
|
cval.printNamespaces( name_sp , "__") ;
|
||||||
init_func += name_sp.str() + cval.getName() ;
|
init_func += name_sp.str() + cval.getName() ;
|
||||||
std::string friend_str = nd->getName().str() ;
|
std::string friend_str = nd->getName().str() ;
|
||||||
if ( ! friend_str.find(init_func) ) {
|
if ( ! friend_str.find(init_func) ) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <clang/AST/DeclTemplate.h>
|
||||||
|
|
||||||
#include "ConstructValues.hh"
|
#include "ConstructValues.hh"
|
||||||
|
|
||||||
@ -39,7 +40,6 @@ void ConstructValues::getNamespacesAndClasses( const clang::DeclContext * Ctx )
|
|||||||
for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend(); I != E; ++I) {
|
for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend(); I != E; ++I) {
|
||||||
if (const clang::NamespaceDecl *nd = clang::dyn_cast<clang::NamespaceDecl>(*I)) {
|
if (const clang::NamespaceDecl *nd = clang::dyn_cast<clang::NamespaceDecl>(*I)) {
|
||||||
if (! nd->isAnonymousNamespace()) {
|
if (! nd->isAnonymousNamespace()) {
|
||||||
//std::cout << "namespace " << nd->getIdentifier()->getName().str() << std::endl ;
|
|
||||||
std::string temp_name = nd->getIdentifier()->getName().str() ;
|
std::string temp_name = nd->getIdentifier()->getName().str() ;
|
||||||
if ( temp_name.compare("std") and temp_name.compare("__1")) {
|
if ( temp_name.compare("std") and temp_name.compare("__1")) {
|
||||||
addNamespace(nd->getIdentifier()->getName().str()) ;
|
addNamespace(nd->getIdentifier()->getName().str()) ;
|
||||||
@ -47,8 +47,23 @@ void ConstructValues::getNamespacesAndClasses( const clang::DeclContext * Ctx )
|
|||||||
}
|
}
|
||||||
} else if (const clang::RecordDecl *rd = clang::dyn_cast<clang::RecordDecl>(*I)) {
|
} else if (const clang::RecordDecl *rd = clang::dyn_cast<clang::RecordDecl>(*I)) {
|
||||||
if (rd->getIdentifier()) {
|
if (rd->getIdentifier()) {
|
||||||
//std::cout << "in class " << rd->getName().str() << std::endl ;
|
if (const clang::ClassTemplateSpecializationDecl *td = clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(*I)) {
|
||||||
addContainerClass(rd->getName().str()) ;
|
std::string text;
|
||||||
|
llvm::raw_string_ostream stream(text);
|
||||||
|
stream << td->getName().str() << "<";
|
||||||
|
const clang::TemplateArgumentList& arguments = td->getTemplateArgs();
|
||||||
|
unsigned end = arguments.size() - 1;
|
||||||
|
for (unsigned i = 0; i < end; ++i) {
|
||||||
|
arguments[i].print(printingPolicy, stream);
|
||||||
|
stream << ", ";
|
||||||
|
}
|
||||||
|
arguments[end].print(printingPolicy, stream);
|
||||||
|
stream << ">";
|
||||||
|
addContainerClass(stream.str());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addContainerClass(rd->getName().str()) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,16 +77,57 @@ void ConstructValues::addContainerClass( std::string in_name ) {
|
|||||||
container_classes.push_back(in_name) ;
|
container_classes.push_back(in_name) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ConstructValues::getFullyQualifiedName() {
|
std::string ConstructValues::getFullyQualifiedName(const std::string& delimiter) {
|
||||||
std::ostringstream oss ;
|
std::ostringstream oss;
|
||||||
NamespaceIterator ni ;
|
printNamespaces(oss, delimiter);
|
||||||
|
printContainerClasses(oss, delimiter);
|
||||||
|
oss << name;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
for ( ni = namespace_begin() ; ni != namespace_end() ; ni++ ) {
|
void ConstructValues::printOpenNamespaceBlocks(std::ostream& ostream) {
|
||||||
oss << (*ni) << "::" ;
|
for (auto name : namespaces) {
|
||||||
|
ostream << "namespace " << name << " {" << std::endl;
|
||||||
}
|
}
|
||||||
for ( ni = container_class_begin() ; ni != container_class_end() ; ni++ ) {
|
}
|
||||||
oss << (*ni) << "::" ;
|
|
||||||
|
void ConstructValues::printCloseNamespaceBlocks(std::ostream& ostream) {
|
||||||
|
for (auto name : namespaces) {
|
||||||
|
ostream << "}" << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstructValues::printNamespaces(std::ostream& ostream, const std::string& delimiter) {
|
||||||
|
for (auto name : namespaces) {
|
||||||
|
ostream << name << delimiter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstructValues::printContainerClasses(std::ostream& ostream, const std::string& delimiter) {
|
||||||
|
for (auto clazz : container_classes) {
|
||||||
|
ostream << clazz << delimiter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstructValues::printNamespacesAndContainerClasses(std::ostream& ostream, const std::string& delimiter) {
|
||||||
|
printNamespaces(ostream, delimiter);
|
||||||
|
printContainerClasses(ostream, delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ConstructValues::getNamespacesAndContainerClasses(const std::string& delimiter) {
|
||||||
|
std::string result = "";
|
||||||
|
for (auto name : namespaces) {
|
||||||
|
result += name + delimiter;
|
||||||
|
}
|
||||||
|
for (auto clazz : container_classes) {
|
||||||
|
result += clazz + delimiter;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ConstructValues::getFullyQualifiedTypeName(const std::string& delimiter) {
|
||||||
|
std::ostringstream oss ;
|
||||||
|
printNamespacesAndContainerClasses(oss, delimiter) ;
|
||||||
oss << name ;
|
oss << name ;
|
||||||
return oss.str() ;
|
return oss.str() ;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "clang/AST/Decl.h"
|
#include "clang/AST/Decl.h"
|
||||||
|
#include <clang/AST/PrettyPrinter.h>
|
||||||
|
#include <clang/Basic/LangOptions.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
@ -39,17 +41,26 @@ class ConstructValues {
|
|||||||
|
|
||||||
void addNamespace(std::string in_name) ;
|
void addNamespace(std::string in_name) ;
|
||||||
|
|
||||||
typedef std::vector< std::string >::iterator NamespaceIterator ;
|
const std::vector<std::string>& getNamespaces() {
|
||||||
NamespaceIterator namespace_begin() { return namespaces.begin() ; } ;
|
return namespaces;
|
||||||
NamespaceIterator namespace_end() { return namespaces.end() ; } ;
|
}
|
||||||
|
|
||||||
|
|
||||||
void addContainerClass(std::string in_name) ;
|
void addContainerClass(std::string in_name) ;
|
||||||
|
|
||||||
typedef std::vector< std::string >::iterator ContainerClassIterator ;
|
const std::vector<std::string>& getContainerClasses() {
|
||||||
ContainerClassIterator container_class_begin() { return container_classes.begin() ; } ;
|
return container_classes;
|
||||||
ContainerClassIterator container_class_end() { return container_classes.end() ; } ;
|
}
|
||||||
|
|
||||||
std::string getFullyQualifiedName() ;
|
std::string getFullyQualifiedName(const std::string& delimiter = "::") ;
|
||||||
|
|
||||||
|
void printOpenNamespaceBlocks(std::ostream& ostream);
|
||||||
|
void printCloseNamespaceBlocks(std::ostream& ostream);
|
||||||
|
void printNamespaces(std::ostream& ostream, const std::string& delimiter = "::") ;
|
||||||
|
void printContainerClasses(std::ostream& ostream, const std::string& delimiter = "::") ;
|
||||||
|
void printNamespacesAndContainerClasses(std::ostream& ostream, const std::string& delimiter = "::") ;
|
||||||
|
std::string getNamespacesAndContainerClasses(const std::string& delimiter = "::") ;
|
||||||
|
std::string getFullyQualifiedTypeName(const std::string& delimiter = "::") ;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -65,6 +76,8 @@ class ConstructValues {
|
|||||||
/** File where construct is defined */
|
/** File where construct is defined */
|
||||||
std::string file_name ;
|
std::string file_name ;
|
||||||
|
|
||||||
|
const clang::PrintingPolicy printingPolicy = clang::PrintingPolicy(clang::LangOptions());
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,26 +17,3 @@ void EnumValues::setHasDefinition( bool in ) {
|
|||||||
bool EnumValues::getHasDefinition() {
|
bool EnumValues::getHasDefinition() {
|
||||||
return has_definition ;
|
return has_definition ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & os , EnumValues & ev ) {
|
|
||||||
os << " name = " << ev.name << std::endl ;
|
|
||||||
os << " file_name = " << ev.file_name << std::endl ;
|
|
||||||
os << " namespaces =" ;
|
|
||||||
ConstructValues::NamespaceIterator it ;
|
|
||||||
for ( it = ev.namespace_begin() ; it != ev.namespace_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " parent classes =" ;
|
|
||||||
for ( it = ev.container_class_begin() ; it != ev.container_class_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
|
|
||||||
EnumValues::NameValueIterator eit ;
|
|
||||||
for ( eit = ev.begin() ; eit != ev.end() ; eit++ ) {
|
|
||||||
os << " " << (*eit).first << " " << (*eit).second << std::endl ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return os ;
|
|
||||||
}
|
|
||||||
|
@ -32,15 +32,13 @@ class EnumValues : public ConstructValues {
|
|||||||
|
|
||||||
void addEnum(std::string in_name , long long in_val) ;
|
void addEnum(std::string in_name , long long in_val) ;
|
||||||
|
|
||||||
typedef std::vector< NameValuePair >::iterator NameValueIterator ;
|
|
||||||
NameValueIterator begin() { return enum_values.begin() ; } ;
|
|
||||||
NameValueIterator end() { return enum_values.end() ; } ;
|
|
||||||
|
|
||||||
friend std::ostream & operator << (std::ostream & os , EnumValues & ev ) ;
|
|
||||||
|
|
||||||
void setHasDefinition( bool in ) ;
|
void setHasDefinition( bool in ) ;
|
||||||
bool getHasDefinition() ;
|
bool getHasDefinition() ;
|
||||||
|
|
||||||
|
const std::vector<NameValuePair>& getPairs() {
|
||||||
|
return enum_values;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** List of enums and their values */
|
/** List of enums and their values */
|
||||||
|
@ -375,6 +375,13 @@ std::string FieldDescription::getMangledTypeName() {
|
|||||||
return mangled_type_name ;
|
return mangled_type_name ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FieldDescription::getFullyQualifiedMangledTypeName(const std::string& delimiter) {
|
||||||
|
std::ostringstream oss ;
|
||||||
|
printNamespacesAndContainerClasses(oss, delimiter) ;
|
||||||
|
oss << getMangledTypeName() ;
|
||||||
|
return oss.str() ;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FieldDescription::getUnits() {
|
std::string FieldDescription::getUnits() {
|
||||||
return units ;
|
return units ;
|
||||||
}
|
}
|
||||||
@ -517,43 +524,3 @@ int FieldDescription::getArrayDim(unsigned int dim_num) {
|
|||||||
void FieldDescription::addArrayDim( int in_dim ) {
|
void FieldDescription::addArrayDim( int in_dim ) {
|
||||||
array_sizes[num_dims++] = in_dim ;
|
array_sizes[num_dims++] = in_dim ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & os , FieldDescription & fdes ) {
|
|
||||||
os << " name = " << fdes.name << std::endl ;
|
|
||||||
os << " file_name = " << fdes.file_name << std::endl ;
|
|
||||||
os << " namespaces =" ;
|
|
||||||
ConstructValues::NamespaceIterator it ;
|
|
||||||
for ( it = fdes.namespace_begin() ; it != fdes.namespace_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " parent classes =" ;
|
|
||||||
for ( it = fdes.container_class_begin() ; it != fdes.container_class_end() ; it++ ) {
|
|
||||||
os << " " << *it ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " line_no = " << fdes.line_no << std::endl ;
|
|
||||||
os << " container_class = " << fdes.container_class << std::endl ;
|
|
||||||
os << " type_name = " << fdes.type_name << std::endl ;
|
|
||||||
os << " mangled_type_name = " << fdes.mangled_type_name << std::endl ;
|
|
||||||
os << " type_enum_string = " << fdes.type_enum_string << std::endl ;
|
|
||||||
os << " units = " << fdes.units << std::endl ;
|
|
||||||
os << " io = " << fdes.io << std::endl ;
|
|
||||||
os << " description = " << fdes.description << std::endl ;
|
|
||||||
os << " access = " << fdes.access << std::endl ;
|
|
||||||
os << " is_bitfield = " << fdes.is_bitfield << std::endl ;
|
|
||||||
os << " bitfield_width = " << fdes.bitfield_width << std::endl ;
|
|
||||||
os << " bitfield_start_bit = " << fdes.bitfield_start_bit << std::endl ;
|
|
||||||
os << " bitfield_word_offset = " << fdes.bitfield_word_offset << std::endl ;
|
|
||||||
os << " num_dims = " << fdes.num_dims << std::endl ;
|
|
||||||
os << " array_sizes =" ;
|
|
||||||
for( unsigned int ii = 0 ; ii < 8 ; ii++ ) {
|
|
||||||
os << " " << fdes.array_sizes[ii] ;
|
|
||||||
}
|
|
||||||
os << std::endl ;
|
|
||||||
os << " is_enum = " << fdes.is_enum << std::endl ;
|
|
||||||
os << " is_record = " << fdes.is_record << std::endl ;
|
|
||||||
os << " is_static = " << fdes.is_static << std::endl ;
|
|
||||||
|
|
||||||
return os ;
|
|
||||||
}
|
|
||||||
|
@ -53,6 +53,7 @@ class FieldDescription : public ConstructValues {
|
|||||||
unsigned int getLineNo() ;
|
unsigned int getLineNo() ;
|
||||||
void setMangledTypeName( std::string in_val ) ;
|
void setMangledTypeName( std::string in_val ) ;
|
||||||
std::string getMangledTypeName() ;
|
std::string getMangledTypeName() ;
|
||||||
|
std::string getFullyQualifiedMangledTypeName(const std::string& delimiter = "::") ;
|
||||||
std::string getUnits() ;
|
std::string getUnits() ;
|
||||||
bool isDashDashUnits() ;
|
bool isDashDashUnits() ;
|
||||||
void setIO(unsigned int) ;
|
void setIO(unsigned int) ;
|
||||||
@ -92,8 +93,6 @@ class FieldDescription : public ConstructValues {
|
|||||||
/** Adds an array dimension to the field */
|
/** Adds an array dimension to the field */
|
||||||
void addArrayDim( int in_dim ) ;
|
void addArrayDim( int in_dim ) ;
|
||||||
|
|
||||||
friend std::ostream & operator << (std::ostream & os , FieldDescription & cv ) ;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Line number in current file where field is */
|
/** Line number in current file where field is */
|
||||||
|
@ -296,7 +296,7 @@ bool FieldVisitor::ProcessTemplate(std::string in_name , clang::CXXRecordDecl *
|
|||||||
if ( debug_level >= 4 ) {
|
if ( debug_level >= 4 ) {
|
||||||
std::cout << "Added template class from FieldVisitor ProcessTemplate " ;
|
std::cout << "Added template class from FieldVisitor ProcessTemplate " ;
|
||||||
std::cout << in_name << std::endl ;
|
std::cout << in_name << std::endl ;
|
||||||
std::cout << *fdes << std::endl ;
|
//std::cout << *fdes << std::endl ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#include "PrintAttributes.hh"
|
#include "PrintAttributes.hh"
|
||||||
#include "PrintFileContentsBase.hh"
|
#include "PrintFileContentsBase.hh"
|
||||||
#include "PrintAttributesFactory.hh"
|
#include "PrintFileContents10.hh"
|
||||||
#include "HeaderSearchDirs.hh"
|
#include "HeaderSearchDirs.hh"
|
||||||
#include "CommentSaver.hh"
|
#include "CommentSaver.hh"
|
||||||
#include "ClassValues.hh"
|
#include "ClassValues.hh"
|
||||||
@ -30,7 +30,7 @@ PrintAttributes::PrintAttributes(int in_attr_version , HeaderSearchDirs & in_hsd
|
|||||||
sim_services_flag( in_sim_services_flag ) ,
|
sim_services_flag( in_sim_services_flag ) ,
|
||||||
output_dir( in_output_dir )
|
output_dir( in_output_dir )
|
||||||
{
|
{
|
||||||
printer = createFileContents(in_attr_version) ;
|
printer = new PrintFileContents10() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "PrintFileContentsBase.hh"
|
|
||||||
#include "PrintFileContents10.hh"
|
|
||||||
#include "PrintFileContents13.hh"
|
|
||||||
|
|
||||||
/** returns true if the command line attributes version is supported */
|
|
||||||
bool validAttributesVersion( int attr_version ) {
|
|
||||||
switch (attr_version) {
|
|
||||||
case 10:
|
|
||||||
case 13:
|
|
||||||
return true ;
|
|
||||||
default:
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns a PrintFileContentsBase pointer to a version specific
|
|
||||||
print class based on attribute version
|
|
||||||
*/
|
|
||||||
PrintFileContentsBase * createFileContents( int attr_version ) {
|
|
||||||
switch (attr_version) {
|
|
||||||
case 10:
|
|
||||||
return new PrintFileContents10() ;
|
|
||||||
case 13:
|
|
||||||
return new PrintFileContents13() ;
|
|
||||||
default:
|
|
||||||
std::cout << "OK, how did you get here with an invalid attributes version " << attr_version << std::endl ;
|
|
||||||
exit(-1) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
#ifndef PRINTATTRIBUTESFACTORY_HH
|
|
||||||
#define PRINTATTRIBUTESFACTORY_HH
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
class PrintFileContentsBase ;
|
|
||||||
|
|
||||||
/** returns true if the command line attributes version is supported */
|
|
||||||
bool validAttributesVersion( int attr_version ) ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns a PrintFileContentsBase pointer to a version specific
|
|
||||||
print class based on attribute version
|
|
||||||
*/
|
|
||||||
PrintFileContentsBase * createFileContents( int attr_version ) ;
|
|
||||||
|
|
||||||
#endif
|
|
@ -19,44 +19,37 @@ void PrintFileContents10::printIOHeader(std::ostream & ostream , std::string hea
|
|||||||
} else {
|
} else {
|
||||||
header_file_name = almostRealPath(header_file_name.c_str()) ;
|
header_file_name = almostRealPath(header_file_name.c_str()) ;
|
||||||
}
|
}
|
||||||
ostream <<
|
ostream << "/**\n"
|
||||||
"/**\n"
|
<< " * This file was automatically generated by the ICG based on the file:\n"
|
||||||
" * This file was automatically generated by the ICG based on the file:\n"
|
<< " * " << header_file_name << "\n"
|
||||||
" * " << header_file_name << "\n"
|
<< " * This file contains database parameter declarations specific to the\n"
|
||||||
" * This file contains database parameter declarations specific to the\n"
|
<< " * data structures and enumerated types declared in the above file.\n"
|
||||||
" * data structures and enumerated types declared in the above file.\n"
|
<< " * These database parameters are used by the Trick input and\n"
|
||||||
" * These database parameters are used by the Trick input and\n"
|
<< " * data recording processors to gain access to important simulation\n"
|
||||||
" * data recording processors to gain access to important simulation\n"
|
<< " * variable information.\n"
|
||||||
" * variable information.\n"
|
<< " */\n"
|
||||||
" */\n"
|
<< "\n"
|
||||||
"\n"
|
<< "#define TRICK_IN_IOSRC\n"
|
||||||
"#define TRICK_IN_IOSRC\n"
|
<< "#include <stdlib.h>\n"
|
||||||
"#include <stdlib.h>\n"
|
<< "#include \"trick/MemoryManager.hh\"\n"
|
||||||
"#include \"trick/MemoryManager.hh\"\n"
|
<< "#include \"trick/attributes.h\"\n"
|
||||||
"#include \"trick/attributes.h\"\n"
|
<< "#include \"trick/parameter_types.h\"\n"
|
||||||
"#include \"trick/parameter_types.h\"\n"
|
<< "#include \"trick/ClassSizeCheck.hh\"\n"
|
||||||
"#include \"trick/ClassSizeCheck.hh\"\n"
|
<< "#include \"trick/UnitsMap.hh\"\n"
|
||||||
"#include \"trick/UnitsMap.hh\"\n"
|
<< "#include \"trick/checkpoint_stl.hh\"\n"
|
||||||
"#include \"trick/checkpoint_stl.hh\"\n"
|
<< "#include \"" << header_file_name << "\"\n"
|
||||||
"#include \"" << header_file_name << "\"\n"
|
<< "\n" ;
|
||||||
"\n" ;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints enumeration attributes */
|
/** Prints enumeration attributes */
|
||||||
void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues * e ) {
|
void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues * e ) {
|
||||||
print_open_extern_c(ostream) ;
|
print_open_extern_c(ostream) ;
|
||||||
ostream << "ENUM_ATTR enum" ;
|
ostream << "ENUM_ATTR enum" << e->getFullyQualifiedTypeName("__") << "[] = {\n" ;
|
||||||
printNamespaces( ostream, e , "__" ) ;
|
std::string name = e->getNamespacesAndContainerClasses();
|
||||||
printContainerClasses( ostream, e , "__" ) ;
|
for (auto& pair : e->getPairs()) {
|
||||||
ostream << e->getName() << "[] = {\n" ;
|
ostream << "{\"" << name << pair.first << "\", " << pair.second << ", 0x0},\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 << "{\"\" , 0 , 0x0 }\n} ;\n" ;
|
ostream << "{\"\", 0, 0x0}\n};\n" ;
|
||||||
print_close_extern_c(ostream) ;
|
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 ) {
|
void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription * fdes ) {
|
||||||
int array_dim ;
|
int array_dim ;
|
||||||
|
|
||||||
ostream << "{ \"" << fdes->getName() << "\"" ; // name
|
ostream << "{\"" << fdes->getName() << "\"" // name
|
||||||
ostream << ", \"" ; // start type_name
|
<< ", \"" << fdes->getFullyQualifiedMangledTypeName("__") << "\"" // type_name
|
||||||
printNamespaces( ostream, fdes , "__" ) ;
|
<< ", \"" << fdes->getUnits() << "\"" // units
|
||||||
printContainerClasses( ostream, fdes , "__" ) ;
|
<< ", \"\", \"\"," << std::endl // alias, user_defined
|
||||||
ostream << fdes->getMangledTypeName() << "\""; // end type_name
|
<< " \"" << fdes->getDescription() << "\"," << std::endl // description
|
||||||
ostream << ", \"" << fdes->getUnits() << "\"" ; // units
|
<< " " << fdes->getIO() // io
|
||||||
ostream << ", \"\", \"\"," << std::endl ; // alias , user_defined
|
<< "," << fdes->getEnumString() ; // type
|
||||||
ostream << " \"" << fdes->getDescription() << "\"," << std::endl ; // description
|
|
||||||
ostream << " " << fdes->getIO() ; // io
|
|
||||||
ostream << "," << fdes->getEnumString() ; // type
|
|
||||||
// There are several cases when printing the size of a variable.
|
// There are several cases when printing the size of a variable.
|
||||||
if ( fdes->isBitField() ) {
|
if ( fdes->isBitField() ) {
|
||||||
// bitfields are handled in 4 byte (32 bit) chunks
|
// bitfields are handled in 4 byte (32 bit) chunks
|
||||||
ostream << ",4" ;
|
ostream << ", 4" ;
|
||||||
} else if ( fdes->isRecord() or fdes->isEnum() or fdes->getTypeName().empty() ) {
|
} else if ( fdes->isRecord() or fdes->isEnum() or fdes->getTypeName().empty() ) {
|
||||||
// records enums use io_src_get_size. The sentinel has no typename
|
// records enums use io_src_get_size. The sentinel has no typename
|
||||||
ostream << ",0" ;
|
ostream << ", 0" ;
|
||||||
} else {
|
} else {
|
||||||
// print size of the underlying type
|
// 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 << ", 0, 0, Language_CPP" ; // range_min, range_max, language
|
||||||
ostream << "," << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
|
ostream << ", " << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
|
||||||
if ( fdes->isBitField() ) {
|
if ( fdes->isBitField() ) {
|
||||||
// For bitfields we need the offset to start on 4 byte boundaries because that is what our
|
// For bitfields we need the offset to start on 4 byte boundaries because that is what our
|
||||||
// insert and extract bitfield routines work with.
|
// insert and extract bitfield routines work with.
|
||||||
@ -94,23 +84,23 @@ void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescri
|
|||||||
} else {
|
} else {
|
||||||
ostream << " " << (fdes->getFieldOffset() / 8) ; // offset
|
ostream << " " << (fdes->getFieldOffset() / 8) ; // offset
|
||||||
}
|
}
|
||||||
ostream << ",NULL" ; // attr
|
ostream << ", NULL" ; // attr
|
||||||
ostream << "," << fdes->getNumDims() ; // num_index
|
ostream << ", " << fdes->getNumDims() ; // num_index
|
||||||
|
|
||||||
ostream << ",{" ;
|
ostream << ", {" ;
|
||||||
if ( fdes->isBitField() ) {
|
if ( fdes->isBitField() ) {
|
||||||
ostream << "{" << fdes->getBitFieldWidth() ; // size of bitfield
|
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 {
|
} else {
|
||||||
array_dim = fdes->getArrayDim(0) ;
|
array_dim = fdes->getArrayDim(0) ;
|
||||||
if ( array_dim < 0 ) array_dim = 0 ;
|
if ( array_dim < 0 ) array_dim = 0 ;
|
||||||
ostream << "{" << array_dim << ",0}" ; // index 0
|
ostream << "{" << array_dim << ", 0}" ; // index 0
|
||||||
}
|
}
|
||||||
unsigned int ii ;
|
unsigned int ii ;
|
||||||
for ( ii = 1 ; ii < 8 ; ii++ ) {
|
for ( ii = 1 ; ii < 8 ; ii++ ) {
|
||||||
array_dim = fdes->getArrayDim(ii) ;
|
array_dim = fdes->getArrayDim(ii) ;
|
||||||
if ( array_dim < 0 ) array_dim = 0 ;
|
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 << "}," << std::endl ;
|
||||||
ostream << " NULL, NULL, NULL, NULL" ;
|
ostream << " NULL, NULL, NULL, NULL" ;
|
||||||
@ -120,19 +110,12 @@ void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescri
|
|||||||
/** Prints class attributes */
|
/** Prints class attributes */
|
||||||
void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues * c ) {
|
void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues * c ) {
|
||||||
|
|
||||||
unsigned int ii ;
|
|
||||||
ClassValues::FieldIterator fit ;
|
|
||||||
|
|
||||||
print_open_extern_c(ostream) ;
|
print_open_extern_c(ostream) ;
|
||||||
ostream << "ATTRIBUTES attr" ;
|
ostream << "ATTRIBUTES attr" << c->getFullyQualifiedMangledTypeName("__") << "[] = {" << std::endl ;
|
||||||
printNamespaces( ostream, c , "__" ) ;
|
|
||||||
printContainerClasses( ostream, c , "__" ) ;
|
|
||||||
ostream << c->getMangledTypeName() ;
|
|
||||||
ostream << "[] = {" << std::endl ;
|
|
||||||
|
|
||||||
for ( fit = c->field_begin() ; fit != c->field_end() ; fit++ ) {
|
for (auto& fieldDescription : c->getFieldDescriptions()) {
|
||||||
if ( determinePrintAttr(c , *fit) ) {
|
if ( determinePrintAttr(c , fieldDescription) ) {
|
||||||
print_field_attr(ostream, *fit) ;
|
print_field_attr(ostream, fieldDescription) ;
|
||||||
ostream << "," << std::endl ;
|
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 ,
|
void PrintFileContents10::print_field_init_attr_stmts( std::ostream & ostream , FieldDescription * fdes ,
|
||||||
ClassValues * cv , unsigned int index ) {
|
ClassValues * cv , unsigned int index ) {
|
||||||
|
|
||||||
// For static variables replace the offset field with the address of the static variable
|
const std::string className = cv->getName();
|
||||||
if ( global_compat15 or cv->isCompat15()) {
|
const std::string mangledClassName = cv->getMangledTypeName();
|
||||||
if ( fdes->isStatic() ) {
|
const std::string fieldName = fdes->getName();
|
||||||
// print a special offsetof statement if this is a static
|
const std::string fullyQualifiedClassNameColons = cv->getFullyQualifiedTypeName();
|
||||||
ostream << " attr" ;
|
const std::string fullyQualifiedMangledClassNameColons = cv->getFullyQualifiedMangledTypeName();
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
const std::string fullyQualifiedMangledClassNameUnderscores = cv->getFullyQualifiedMangledTypeName("__");
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
std::ostringstream oss;
|
||||||
ostream << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
|
oss << " attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "].";
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
const std::string prefix = oss.str();
|
||||||
printContainerClasses( ostream, cv , "::" ) ;
|
|
||||||
ostream << cv->getName() << "::" << fdes->getName() << " ;\n" ;
|
if ( fdes->isStatic() ) {
|
||||||
} else if ( fdes->isBitField() ) {
|
ostream << prefix << "offset = (long)(void *)&" << fullyQualifiedClassNameColons << "::" << fieldName << " ;\n" ;
|
||||||
// else if this is a bitfield
|
}
|
||||||
ostream << " attr" ;
|
else if ( global_compat15 or cv->isCompat15() ) {
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
if ( fdes->isBitField() ) {
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
ostream << prefix << "offset = " << fdes->getBitFieldByteOffset() << " ;\n" ;
|
||||||
ostream << cv->getMangledTypeName() << "[" << index << "].offset = " ;
|
ostream << prefix << "size = sizeof(unsigned int) ;\n" ;
|
||||||
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" ;
|
|
||||||
}
|
}
|
||||||
} else {
|
else if ( fdes->isVirtualInherited() ) {
|
||||||
if ( fdes->isStatic() ) {
|
ostream << prefix << "offset = " << fdes->getBaseClassOffset() << " + offsetof(" << fdes->getContainerClass() << ", " << fieldName << ") ;\n" ;
|
||||||
ostream << " attr" ;
|
}
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
else if ( mangledClassName != className ) {
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
ostream << prefix << "offset = " << "offsetof(" << mangledClassName << ", " << fieldName << ") ;\n" ;
|
||||||
ostream << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
|
}
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
else {
|
||||||
printContainerClasses( ostream, cv , "::" ) ;
|
ostream << prefix << "offset = " << "offsetof(" << fullyQualifiedMangledClassNameColons << ", " << fieldName << ") ;\n" ;
|
||||||
ostream << cv->getName() << "::" << fdes->getName() << " ;\n" ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fdes->isSTL()) {
|
if ( fdes->isSTL() ) {
|
||||||
ostream << " attr" ;
|
auto print = [&](const std::string& field) {
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
ostream << prefix << field << " = " << field << "_" << fullyQualifiedMangledClassNameUnderscores + "_" + fieldName + " ;\n";
|
||||||
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" ;
|
|
||||||
|
|
||||||
ostream << " attr" ;
|
print("checkpoint_stl");
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
print("post_checkpoint_stl");
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
print("restore_stl");
|
||||||
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" ;
|
|
||||||
|
|
||||||
ostream << " attr" ;
|
if ( fdes->hasSTLClear() ) {
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
print("clear_stl");
|
||||||
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->isRecord() or fdes->isEnum()) {
|
if ( fdes->isRecord() or fdes->isEnum() ) {
|
||||||
ostream << " trick_MM->add_attr_info(std::string(attr" ;
|
ostream << " trick_MM->add_attr_info(std::string(attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "].type_name) , &attr" << fullyQualifiedMangledClassNameUnderscores << "[" << index << "], __FILE__ , __LINE__ ) ;\n" ;
|
||||||
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" ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints add_attr_info statements for each inherited class */
|
/** Prints add_attr_info statements for each inherited class */
|
||||||
void PrintFileContents10::print_inherited_add_attr_info( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_inherited_add_attr_info( std::ostream & ostream , ClassValues * cv ) {
|
||||||
ClassValues::InheritedClassesIterator cit ;
|
auto inheritedClasses = cv->getInheritedClasses();
|
||||||
if ( cv->getNumInheritedClasses() > 0 ) {
|
if ( inheritedClasses.size() > 0 ) {
|
||||||
ostream << "\n ATTRIBUTES temp_attr ;\n\n" ;
|
ostream << "\n ATTRIBUTES temp_attr ;\n\n" ;
|
||||||
}
|
}
|
||||||
for ( cit = cv->inherit_classes_begin() ; cit != cv->inherit_classes_end() ; cit++ ) {
|
for ( auto& inheritedClass : inheritedClasses ) {
|
||||||
ostream << " trick_MM->add_attr_info( std::string(\"" << *cit << "\"), &temp_attr , __FILE__ , __LINE__ ) ;\n" ;
|
ostream << " trick_MM->add_attr_info( std::string(\"" << inheritedClass << "\"), &temp_attr , __FILE__ , __LINE__ ) ;\n" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints init_attr function for each class */
|
/** Prints init_attr function for each class */
|
||||||
void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassValues * cv ) {
|
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 ;
|
#if 0
|
||||||
|
|
||||||
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 ( cv->getMangledTypeName() != cv->getName() ) {
|
if ( cv->getMangledTypeName() != cv->getName() ) {
|
||||||
ostream << " typedef " << cv->getName() << " " << cv->getMangledTypeName() << " ;\n\n" ;
|
ostream << " typedef " << cv->getName() << " " << cv->getMangledTypeName() << " ;\n\n" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ( !global_compat15 and !cv->isCompat15()) {
|
if ( !global_compat15 and !cv->isCompat15()) {
|
||||||
ostream << " if ( sizeof(" ;
|
ostream << " if ( sizeof(" ;
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
printNamespaces( ostream, cv , "::" ) ;
|
||||||
@ -317,296 +222,172 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned int ii = 0 ;
|
unsigned int ii = 0;
|
||||||
for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
|
for ( auto field : cv->getFieldDescriptions() ) {
|
||||||
if ( determinePrintAttr(cv , *fit) ) {
|
if ( determinePrintAttr(cv, field) ) {
|
||||||
print_field_init_attr_stmts(ostream, *fit, cv, ii) ;
|
print_field_init_attr_stmts(ostream, field, cv, ii++) ;
|
||||||
ii++ ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print_inherited_add_attr_info(ostream, cv ) ;
|
print_inherited_add_attr_info(ostream, cv ) ;
|
||||||
ostream << "}\n" ;
|
ostream << "}\n" ;
|
||||||
printCloseNamespaceBlocks(ostream, cv) ;
|
cv->printCloseNamespaceBlocks(ostream) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints the io_src_sizeof function for enumerations */
|
/** Prints the io_src_sizeof function for enumerations */
|
||||||
void PrintFileContents10::print_enum_io_src_sizeof( std::ostream & ostream , EnumValues * ev ) {
|
void PrintFileContents10::print_enum_io_src_sizeof( std::ostream & ostream , EnumValues * ev ) {
|
||||||
print_open_extern_c(ostream) ;
|
print_open_extern_c(ostream) ;
|
||||||
ostream << "size_t io_src_sizeof_" ;
|
ostream << "size_t io_src_sizeof_" << ev->getFullyQualifiedName("__") << "( void ) {\n" ;
|
||||||
printNamespaces( ostream, ev , "__" ) ;
|
|
||||||
printContainerClasses( ostream, ev , "__" ) ;
|
|
||||||
ostream << ev->getName() << "( void ) {\n" ;
|
|
||||||
if ( ev->getHasDefinition() ) {
|
if ( ev->getHasDefinition() ) {
|
||||||
ostream << " return( sizeof(" ;
|
ostream << " return sizeof(" << ev->getFullyQualifiedName() << ")" ;
|
||||||
printNamespaces( ostream, ev , "::" ) ;
|
|
||||||
printContainerClasses( ostream, ev , "::" ) ;
|
|
||||||
ostream << ev->getName() << "));\n}\n" ;
|
|
||||||
} else {
|
} else {
|
||||||
ostream << " return(sizeof(int)) ;\n}\n" ;
|
ostream << " return sizeof(int)" ;
|
||||||
}
|
}
|
||||||
|
ostream << ";\n}\n" ;
|
||||||
print_close_extern_c(ostream) ;
|
print_close_extern_c(ostream) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints the C linkage init_attr function */
|
/** Prints the C linkage init_attr function */
|
||||||
void PrintFileContents10::print_init_attr_c_intf( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_init_attr_c_intf( std::ostream & ostream , ClassValues * cv ) {
|
||||||
ostream << "void init_attr" ;
|
ostream << "void init_attr" << cv->getFullyQualifiedMangledTypeName("__") << "_c_intf() {\n " ;
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
cv->printNamespaces( ostream, "::" ) ;
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
ostream << "init_attr" << cv->getFullyQualifiedMangledTypeName("__") << "() ;\n"
|
||||||
ostream << cv->getMangledTypeName() << "_c_intf() {\n " ;
|
<< "}\n\n" ;
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
|
||||||
ostream << "init_attr" ;
|
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
|
||||||
ostream << cv->getMangledTypeName() << "() ;\n"
|
|
||||||
"}\n\n" ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints the io_src_sizeof function */
|
/** Prints the io_src_sizeof function */
|
||||||
void PrintFileContents10::print_io_src_sizeof( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_io_src_sizeof( std::ostream & ostream , ClassValues * cv ) {
|
||||||
ostream << "size_t io_src_sizeof_" ;
|
ostream << "size_t io_src_sizeof_" << cv->getFullyQualifiedMangledTypeName("__") << "() {\n" ;
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
ostream << " return sizeof(" << cv->getFullyQualifiedNameIfEqual() << ") ;\n}\n\n" ;
|
||||||
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" ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints the io_src_allocate function */
|
/** Prints the io_src_allocate function */
|
||||||
void PrintFileContents10::print_io_src_allocate( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_io_src_allocate( std::ostream & ostream , ClassValues * cv ) {
|
||||||
if ( cv->isPOD() or (! cv->isAbstract() and cv->getHasDefaultConstructor()) ) {
|
if ( cv->isPOD() or ( !cv->isAbstract() and cv->getHasDefaultConstructor()) ) {
|
||||||
ostream << "void * io_src_allocate_" ;
|
const std::string name = cv->getFullyQualifiedNameIfEqual();
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
ostream << "void* io_src_allocate_" << cv->getFullyQualifiedMangledTypeName("__") << "(int num) {\n" ;
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
ostream << " " << name << "* temp = (" << name << "*)calloc(num, sizeof(" << name << "));\n" ;
|
||||||
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() ) {
|
if ( ! cv->isPOD() ) {
|
||||||
ostream << " for (int ii=0 ; ii<num ; ii++) {\n" ;
|
ostream << " for (int ii = 0; ii < num; ++ii) {\n" ;
|
||||||
ostream << " new( &temp[ii]) " ;
|
ostream << " new(&temp[ii]) " << name << "();\n }\n" ;
|
||||||
if ( cv->getMangledTypeName() == cv->getName() ) {
|
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "::" ) ;
|
|
||||||
}
|
|
||||||
ostream << cv->getName() << "();\n" << " }\n" ;
|
|
||||||
}
|
}
|
||||||
ostream << " return ((void *)temp);\n" << "}\n\n" ;
|
ostream << " return (void*)temp;\n" << "}\n\n" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints the io_src_allocate function */
|
/** Prints the io_src_allocate function */
|
||||||
void PrintFileContents10::print_io_src_destruct( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_io_src_destruct( std::ostream & ostream , ClassValues * cv ) {
|
||||||
if ( cv->getHasPublicDestructor()) {
|
if ( cv->getHasPublicDestructor() ) {
|
||||||
ostream << "void io_src_destruct_" ;
|
ostream << "void io_src_destruct_" << cv->getFullyQualifiedMangledTypeName("__") << "(void* address __attribute__((unused)), int num __attribute__((unused))) {\n" ;
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
|
||||||
ostream << cv->getMangledTypeName() << "( void * addr __attribute__((unused)), int num __attribute__((unused)) ) {\n" ;
|
|
||||||
if ( ! cv->isPOD() ) {
|
if ( ! cv->isPOD() ) {
|
||||||
// Add a using statement so we can call the destructor without fully qualifying it.
|
// Add a using statement so we can call the destructor without fully qualifying it.
|
||||||
ClassValues::NamespaceIterator nsi = cv->namespace_begin() ;
|
auto namespaces = cv->getNamespaces();
|
||||||
if ( nsi != cv->namespace_end() ) {
|
if (namespaces.size()) {
|
||||||
ostream << " using namespace " ;
|
ostream << " using namespace " ;
|
||||||
while ( nsi != cv->namespace_end() ) {
|
auto last = namespaces[namespaces.size() - 1];
|
||||||
ostream << *nsi ;
|
for (auto& name : namespaces) {
|
||||||
nsi++ ;
|
ostream << name;
|
||||||
if ( nsi != cv->namespace_end()) {
|
if (name != last) {
|
||||||
ostream << "::" ;
|
ostream << "::";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ostream << " ;\n" ;
|
ostream << ";\n " ;
|
||||||
}
|
}
|
||||||
ostream << " " ;
|
|
||||||
if ( cv->getMangledTypeName() == cv->getName() ) {
|
const std::string name = cv->getName();
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
const std::string qualifiedName = cv->getFullyQualifiedNameIfEqual();
|
||||||
printContainerClasses( ostream, cv , "::" ) ;
|
|
||||||
|
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" ;
|
ostream << "}\n\n" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_io_src_delete( std::ostream & ostream , ClassValues * cv ) {
|
void PrintFileContents10::print_io_src_delete( std::ostream & ostream , ClassValues * cv ) {
|
||||||
if ( cv->getHasPublicDestructor()) {
|
if ( cv->getHasPublicDestructor() ) {
|
||||||
ostream << "void io_src_delete_" ;
|
ostream << "void io_src_delete_" << cv->getFullyQualifiedMangledTypeName("__") << "(void* address" ;
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
|
||||||
ostream << cv->getMangledTypeName() << "( void * addr " ;
|
|
||||||
if ( ! cv->isPOD() ) {
|
if ( ! cv->isPOD() ) {
|
||||||
ostream << ") {\n" ;
|
ostream << ") {\n delete (" << cv->getFullyQualifiedNameIfEqual() << "*)address;\n" ;
|
||||||
ostream << " delete (" ;
|
|
||||||
if ( cv->getMangledTypeName() == cv->getName() ) {
|
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "::" ) ;
|
|
||||||
}
|
|
||||||
ostream << cv->getName() << "*)addr ;\n" ;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ostream << "__attribute__((unused)) ) {" ;
|
ostream << " __attribute__((unused))) {" ;
|
||||||
}
|
}
|
||||||
ostream << "}\n" ;
|
ostream << "}\n" ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_stl_helper_proto(std::ostream & ostream , ClassValues * cv ) {
|
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 (!fieldDescriptions.size()) {
|
||||||
if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) {
|
return;
|
||||||
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 ;
|
|
||||||
|
|
||||||
oss << "void post_checkpoint_stl_" ;
|
print_open_extern_c(ostream) ;
|
||||||
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 ;
|
|
||||||
|
|
||||||
oss << "void restore_stl_" ;
|
for (auto& field : cv->getFieldDescriptions()) {
|
||||||
printNamespaces( oss, cv , "__" ) ;
|
if ( field->isSTL() and determinePrintAttr(cv, field) ) {
|
||||||
printContainerClasses( oss, cv , "__" ) ;
|
const std::string classAndFieldName = cv->getFullyQualifiedMangledTypeName("__") + "_" + field->getName();
|
||||||
oss << cv->getMangledTypeName() ;
|
|
||||||
oss << "_" ;
|
|
||||||
oss << (*fit)->getName() ;
|
|
||||||
oss << "(void * start_address, const char * obj_name , const char * var_name) ;" << std::endl ;
|
|
||||||
|
|
||||||
if ((*fit)->hasSTLClear()) {
|
auto print = [&](const std::string& name) {
|
||||||
oss << "void clear_stl_" ;
|
ostream << "void " << name << "_" << classAndFieldName
|
||||||
printNamespaces( oss, cv , "__" ) ;
|
<< "(void* start_address, const char* obj_name , const char* var_name);" << std::endl ;
|
||||||
printContainerClasses( oss, cv , "__" ) ;
|
};
|
||||||
oss << cv->getMangledTypeName() ;
|
|
||||||
oss << "_" ;
|
print("checkpoint_stl");
|
||||||
oss << (*fit)->getName() ;
|
print("post_checkpoint_stl");
|
||||||
oss << "(void * start_address) ;" << std::endl ;
|
print("restore_checkpoint_stl");
|
||||||
|
|
||||||
|
if ( field->hasSTLClear() ) {
|
||||||
|
ostream << "void clear_stl_" << classAndFieldName << "(void* start_address);" << std::endl ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string text = oss.str();
|
print_close_extern_c(ostream) ;
|
||||||
if (text.size()) {
|
|
||||||
print_open_extern_c(ostream) ;
|
|
||||||
ostream << text;
|
|
||||||
print_close_extern_c(ostream) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
void PrintFileContents10::print_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
||||||
ostream << "void checkpoint_stl_" ;
|
printStlFunction("checkpoint", "void* start_address, const char* obj_name , const char* var_name", "checkpoint_stl(*stl, obj_name, var_name)", ostream, *fdes, *cv);
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_post_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
void PrintFileContents10::print_post_checkpoint_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
||||||
ostream << "void post_checkpoint_stl_" ;
|
printStlFunction("post_checkpoint", "void* start_address, const char* obj_name , const char* var_name", "delete_stl(*stl, obj_name, var_name)", ostream, *fdes, *cv);
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_restore_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
void PrintFileContents10::print_restore_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
||||||
ostream << "void restore_stl_" ;
|
printStlFunction("restore", "void* start_address, const char* obj_name , const char* var_name", "restore_stl(*stl, obj_name, var_name)",ostream, *fdes, *cv);
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_clear_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
void PrintFileContents10::print_clear_stl(std::ostream & ostream , FieldDescription * fdes , ClassValues * cv ) {
|
||||||
ostream << "void clear_stl_" ;
|
printStlFunction("clear", "void* start_address", "stl->clear()",ostream, *fdes, *cv);
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues * 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 (!fieldDescriptions.size()) {
|
||||||
if ( (*fit)->isSTL() and determinePrintAttr(cv , *fit) ) {
|
return;
|
||||||
print_checkpoint_stl(oss , *fit, cv) ;
|
}
|
||||||
print_post_checkpoint_stl(oss , *fit, cv) ;
|
|
||||||
print_restore_stl(oss , *fit, cv) ;
|
print_open_extern_c(ostream) ;
|
||||||
if ((*fit)->hasSTLClear()) {
|
|
||||||
print_clear_stl(oss , *fit, cv) ;
|
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();
|
print_close_extern_c(ostream) ;
|
||||||
if (text.size()) {
|
|
||||||
print_open_extern_c(ostream) ;
|
|
||||||
ostream << text;
|
|
||||||
print_close_extern_c(ostream) ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::printClass( std::ostream & ostream , ClassValues * cv ) {
|
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 ) {
|
void PrintFileContents10::printClassMap( std::ostream & ostream , ClassValues * cv ) {
|
||||||
ostream << " // " << cv->getFileName() << std::endl ;
|
std::string name = cv->getFullyQualifiedMangledTypeName("__");
|
||||||
ostream << " extern ATTRIBUTES attr" ;
|
ostream << " // " << cv->getFileName() << std::endl
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
<< " extern ATTRIBUTES attr" << name << "[] ;" << std::endl
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
<< " class_attribute_map->add_attr(\"" << cv->getFullyQualifiedMangledTypeName() << "\" , attr" << name << ") ;" << std::endl ;
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::printClassMapFooter( std::ostream & ostream ) {
|
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 ) {
|
void PrintFileContents10::printEnumMapHeader( std::ostream & ostream , std::string function_name ) {
|
||||||
ostream <<
|
ostream << "void " << function_name << "() {\n"
|
||||||
"void " << function_name << "() {\n"
|
<< " Trick::EnumAttributesMap* enum_attribute_map __attribute__((unused)) = Trick::EnumAttributesMap::attributes_map();\n\n" ;
|
||||||
" Trick::EnumAttributesMap * enum_attribute_map __attribute__((unused)) = Trick::EnumAttributesMap::attributes_map();\n\n" ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::printEnumMap( std::ostream & ostream , EnumValues * ev ) {
|
void PrintFileContents10::printEnumMap( std::ostream & ostream , EnumValues * ev ) {
|
||||||
ostream << " extern ENUM_ATTR enum" ;
|
std::string name = ev->getFullyQualifiedTypeName("__");
|
||||||
printNamespaces( ostream, ev , "__" ) ;
|
ostream << " extern ENUM_ATTR enum" << name << "[];" << std::endl
|
||||||
printContainerClasses( ostream, ev , "__" ) ;
|
<< " enum_attribute_map->add_attr(\"" << ev->getFullyQualifiedTypeName() << "\", enum" << name << ");" << std::endl ;
|
||||||
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 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintFileContents10::printEnumMapFooter( std::ostream & ostream ) {
|
void PrintFileContents10::printEnumMapFooter( std::ostream & ostream ) {
|
||||||
ostream << "}" << std::endl << std::endl ;
|
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 ;
|
||||||
|
}
|
||||||
|
@ -103,6 +103,8 @@ class PrintFileContents10 : public PrintFileContentsBase {
|
|||||||
|
|
||||||
/** Prints stl clear function */
|
/** Prints stl clear function */
|
||||||
void print_clear_stl(std::ostream & outfile , FieldDescription * fdes , ClassValues * in_class) ;
|
void print_clear_stl(std::ostream & outfile , FieldDescription * fdes , ClassValues * in_class) ;
|
||||||
|
|
||||||
|
void printStlFunction(const std::string& name, const std::string& parameters, const std::string& call, std::ostream& ostream, FieldDescription& fieldDescription, ClassValues& classValues);
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,209 +0,0 @@
|
|||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include "PrintFileContents13.hh"
|
|
||||||
#include "FieldDescription.hh"
|
|
||||||
#include "ClassValues.hh"
|
|
||||||
#include "EnumValues.hh"
|
|
||||||
|
|
||||||
PrintFileContents13::PrintFileContents13() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
void PrintFileContents13::printIOHeader(std::ostream & ostream , std::string header_file_name) {
|
|
||||||
if ( ! header_file_name.compare("S_source.hh") ) {
|
|
||||||
header_file_name = "../S_source.hh" ;
|
|
||||||
}
|
|
||||||
ostream << "\n"
|
|
||||||
"/*\n"
|
|
||||||
" * This file was automatically generated by the ICG based on the file:\n"
|
|
||||||
" * " << header_file_name << "\n"
|
|
||||||
" */\n"
|
|
||||||
"#include \"" << header_file_name << "\"\n"
|
|
||||||
"#include <stddef.h>\n" // for offsetof()
|
|
||||||
"#include \"TypeDictionary.hh\"\n"
|
|
||||||
"#include \"EnumDataType.hh\"\n"
|
|
||||||
"#include \"CompositeDataType.hh\"\n"
|
|
||||||
"\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string PrintFileContents13::enumeration_identifier( EnumValues * e ) {
|
|
||||||
|
|
||||||
std::ostringstream oss;
|
|
||||||
EnumValues::NamespaceIterator nsi ;
|
|
||||||
for ( nsi = e->namespace_begin() ; nsi != e->namespace_end() ; nsi++ ) {
|
|
||||||
oss << *nsi << "__" ;
|
|
||||||
}
|
|
||||||
EnumValues::ContainerClassIterator ci ;
|
|
||||||
for ( ci = e->container_class_begin() ; ci != e->container_class_end() ; ci++ ) {
|
|
||||||
oss << *ci << "__" ;
|
|
||||||
}
|
|
||||||
oss << e->getName();
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints enumeration attributes */
|
|
||||||
void PrintFileContents13::print_enum_attr(std::ostream & ostream , EnumValues * e ) {
|
|
||||||
EnumValues::NameValueIterator nvit ;
|
|
||||||
|
|
||||||
ostream << "class type_" << enumeration_identifier(e) << " {\n"
|
|
||||||
<< "public:\n"
|
|
||||||
<< " type_" << enumeration_identifier(e) << "() {\n"
|
|
||||||
<< " TypeDictionary * type_dict = TypeDictionary::getInstance();\n"
|
|
||||||
<< " EnumDataType * dataType = new EnumDataType( sizeof(enum " << e->getName() << "));\n"
|
|
||||||
<< " try {\n"
|
|
||||||
;
|
|
||||||
|
|
||||||
for ( nvit = e->begin() ; nvit != e->end() ; nvit++ ) {
|
|
||||||
ostream << " dataType->addEnumerator(\"" << (*nvit).first << "\" , " << (*nvit).second << ");\n" ;
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream << " typeDictionary->addTypeDefinition( \"" << e->getName() << "\", dataType );\n"
|
|
||||||
<< " } catch ( std::logic_error e ) {\n"
|
|
||||||
<< " std::cerr << e.what();\n"
|
|
||||||
<< " }\n"
|
|
||||||
<< " }\n"
|
|
||||||
<< "};\n"
|
|
||||||
<< "type_" << enumeration_identifier(e) << " __" << enumeration_identifier(e) << ";\n"
|
|
||||||
<< "\n"
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** */
|
|
||||||
std::string PrintFileContents13::class_identifier( ClassValues * c ) {
|
|
||||||
|
|
||||||
std::ostringstream oss;
|
|
||||||
ClassValues::NamespaceIterator nsi ;
|
|
||||||
for ( nsi = c->namespace_begin() ; nsi != c->namespace_end() ; nsi++ ) {
|
|
||||||
oss << *nsi << "__" ;
|
|
||||||
}
|
|
||||||
ClassValues::ContainerClassIterator ci ;
|
|
||||||
for ( ci = c->container_class_begin() ; ci != c->container_class_end() ; ci++ ) {
|
|
||||||
oss << *ci << "__" ;
|
|
||||||
}
|
|
||||||
oss << c->getName();
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string PrintFileContents13::bit_field_getter_name(ClassValues * c, FieldDescription * f) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << " get_" << class_identifier(c) << "__" << f->getName();
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string PrintFileContents13::bit_field_setter_name(ClassValues * c, FieldDescription * f) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << " set_" << class_identifier(c) << "__" << f->getName();
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints attributes for a field */
|
|
||||||
void PrintFileContents13::print_field_attr(std::ostream & ostream , ClassValues * c, FieldDescription * fv ) {
|
|
||||||
|
|
||||||
if (fv->isBitField()) {
|
|
||||||
ostream << " " ;
|
|
||||||
ostream << "dataType->addBitFieldMember(\"" << fv->getName() << "\", "
|
|
||||||
<< bit_field_getter_name(c,fv) << ", "
|
|
||||||
<< bit_field_setter_name(c,fv) << ");\n"
|
|
||||||
;
|
|
||||||
} else {
|
|
||||||
int ndims = fv->getNumDims();
|
|
||||||
|
|
||||||
// For arrays and/or pointers, generate a dimension-size array.
|
|
||||||
if (ndims) {
|
|
||||||
ostream << " " ;
|
|
||||||
ostream << "unsigned int dim_" << fv->getName() << "[] = {";
|
|
||||||
for ( unsigned int ii = 0 ; ii < ndims ; ii++ ) {
|
|
||||||
if (ii) {
|
|
||||||
ostream << ",";
|
|
||||||
}
|
|
||||||
ostream << fv->getArrayDim(ii) ;
|
|
||||||
}
|
|
||||||
ostream << "};\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream << " " ;
|
|
||||||
if (fv->isStatic()) {
|
|
||||||
ostream << "dataType->addStaticMember( \"";
|
|
||||||
ostream << fv->getName()
|
|
||||||
<< "\", &" << c->getName() << "::" << fv->getName() << ", \"" << fv->getTypeName() << "\", ";
|
|
||||||
} else {
|
|
||||||
ostream << "dataType->addRegularMember( \"";
|
|
||||||
ostream << fv->getName() << "\", offsetof(" << c->getName() << ", " << fv->getName() << "), \"" << fv->getTypeName() << "\", ";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (ndims) {
|
|
||||||
ostream << ndims << ", " << "dim_" << fv->getName() ;
|
|
||||||
} else {
|
|
||||||
ostream << "0, NULL" ;
|
|
||||||
}
|
|
||||||
ostream <<");\n" ;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints class attributes */
|
|
||||||
void PrintFileContents13::print_class_attr(std::ostream & ostream , ClassValues * c ) {
|
|
||||||
|
|
||||||
ClassValues::FieldIterator fit ;
|
|
||||||
|
|
||||||
// Create setters and getters for any bitfields we may have.
|
|
||||||
for ( fit = c->field_begin() ; fit != c->field_end() ; fit++ ) {
|
|
||||||
|
|
||||||
FieldDescription * f = *fit;
|
|
||||||
|
|
||||||
if ( f->isBitField()) {
|
|
||||||
|
|
||||||
// Create bitfield getter.
|
|
||||||
ostream << "static " << f->getTypeName() << " " << bit_field_getter_name(c,f) << "()(void* addr) {\n"
|
|
||||||
<< " return ((" << class_identifier(c) << "*)addr)->" << f->getName() << ";\n"
|
|
||||||
<< "}\n"
|
|
||||||
;
|
|
||||||
|
|
||||||
// Create bitfield setter.
|
|
||||||
ostream << "static void " << bit_field_setter_name(c,f) << "(void* addr, "<< f->getTypeName() << " v) {\n"
|
|
||||||
<< " ((" << class_identifier(c) << "*)addr)->" << f->getName() << " = v;\n"
|
|
||||||
<< "}\n"
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream << "class type_" << class_identifier(c) << " {\n"
|
|
||||||
<< "public:\n"
|
|
||||||
<< " type_" << class_identifier(c) << "() {\n"
|
|
||||||
<< " TypeDictionary * type_dict = TypeDictionary::getInstance();\n"
|
|
||||||
<< " CompositeDataType * dataType = new CompositeDataType( sizeof( " << c->getName() << "));\n"
|
|
||||||
<< " try {\n"
|
|
||||||
;
|
|
||||||
|
|
||||||
for ( fit = c->field_begin() ; fit != c->field_end() ; fit++ ) {
|
|
||||||
FieldDescription * field = *fit;
|
|
||||||
if ( determinePrintAttr(c , field) ) {
|
|
||||||
print_field_attr( ostream, c, field) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream << " typeDictionary->addTypeDefinition( \"" << c->getName() << "\", dataType );\n"
|
|
||||||
<< " } catch ( std::logic_error e ) {\n"
|
|
||||||
<< " std::cerr << e.what();\n"
|
|
||||||
<< " }\n"
|
|
||||||
<< " }\n"
|
|
||||||
<< "};\n"
|
|
||||||
<< "type_" << class_identifier(c) << " __" << class_identifier(c) << ";\n\n"
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Prints io_src for a class */
|
|
||||||
void PrintFileContents13::printClass( std::ostream & ostream , ClassValues * cv ) {
|
|
||||||
print_class_attr(ostream, cv) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints io_src for an enum */
|
|
||||||
void PrintFileContents13::printEnum( std::ostream & ostream , EnumValues * ev ) {
|
|
||||||
print_enum_attr(ostream, ev) ;
|
|
||||||
}
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
|||||||
|
|
||||||
#ifndef PRINTFILECONTENTS13_HH
|
|
||||||
#define PRINTFILECONTENTS13_HH
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "PrintFileContentsBase.hh"
|
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
This class prints Trick 13 style io_src code. The print command is called when
|
|
||||||
the container class has added all of the classes and enumerations to this class
|
|
||||||
to print.
|
|
||||||
|
|
||||||
@author somebody
|
|
||||||
|
|
||||||
@date July 2012
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class PrintFileContents13 : public PrintFileContentsBase {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
PrintFileContents13() ;
|
|
||||||
|
|
||||||
/** Prints the io_src header information */
|
|
||||||
virtual void printIOHeader(std::ostream & ostream , std::string header_file_name) ;
|
|
||||||
|
|
||||||
std::string enumeration_identifier( EnumValues * e );
|
|
||||||
/** Prints enumeration attributes */
|
|
||||||
void print_enum_attr(std::ostream & ostream , EnumValues * in_enum) ;
|
|
||||||
|
|
||||||
|
|
||||||
std::string bit_field_getter_name(ClassValues * c, FieldDescription * f);
|
|
||||||
std::string bit_field_setter_name(ClassValues * c, FieldDescription * f);
|
|
||||||
|
|
||||||
std::string class_identifier( ClassValues * c ) ;
|
|
||||||
|
|
||||||
/** Prints attributes for a field */
|
|
||||||
void print_field_attr(std::ostream & ostream , ClassValues * c, FieldDescription * fv ) ;
|
|
||||||
|
|
||||||
/** Prints class attributes */
|
|
||||||
void print_class_attr(std::ostream & ostream , ClassValues * in_class) ;
|
|
||||||
|
|
||||||
/** Prints attributes for a class */
|
|
||||||
virtual void printClass(std::ostream & ostream , ClassValues * cv) ;
|
|
||||||
|
|
||||||
/** Prints attributes for an enum */
|
|
||||||
virtual void printEnum(std::ostream & ostream , EnumValues * ev) ;
|
|
||||||
|
|
||||||
} ;
|
|
||||||
|
|
||||||
#endif
|
|
@ -26,41 +26,22 @@ void PrintFileContentsBase::printEnumMap(std::ostream & ostream, EnumValues * ev
|
|||||||
void PrintFileContentsBase::printEnumMapFooter(std::ostream & ostream) {}
|
void PrintFileContentsBase::printEnumMapFooter(std::ostream & ostream) {}
|
||||||
|
|
||||||
void PrintFileContentsBase::print_units_map(std::ostream & ostream, ClassValues * cv ) {
|
void PrintFileContentsBase::print_units_map(std::ostream & ostream, ClassValues * cv ) {
|
||||||
ClassValues::FieldIterator fit ;
|
const std::string name = cv->getFullyQualifiedMangledTypeName("__");
|
||||||
unsigned int ii ;
|
ostream << "struct UnitsMap" << name << " {\n" ;
|
||||||
|
|
||||||
ostream << "struct UnitsMap" ;
|
auto fields = getPrintableFields(*cv);
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
if (fields.size()) {
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
ostream << " UnitsMap" << name << "() {\n"
|
||||||
ostream << cv->getMangledTypeName() ;
|
<< " Trick::UnitsMap* units_map_ptr = Trick::UnitsMap::units_map();\n" ;
|
||||||
ostream << " {\n" ;
|
for (auto& field : fields) {
|
||||||
|
ostream << " units_map_ptr->add_param(\"" ;
|
||||||
std::ostringstream text;
|
cv->printContainerClasses(ostream, "__");
|
||||||
|
ostream << cv->getName() << "_" << field->getName() << "\", \"" << field->getUnits() << "\") ;\n" ;
|
||||||
for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
|
|
||||||
if ( determinePrintAttr(cv , *fit) and (*fit)->getUnits().compare("1")) {
|
|
||||||
FieldDescription * fdes = *fit ;
|
|
||||||
text << " units_map_ptr->add_param(\"" ;
|
|
||||||
printContainerClasses( text, cv , "__" ) ;
|
|
||||||
text << cv->getName() << "_" << fdes->getName() << "\", \"" << fdes->getUnits() << "\") ;\n" ;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (text.str().size()) {
|
|
||||||
ostream << " UnitsMap" ;
|
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
|
||||||
ostream << cv->getMangledTypeName() ;
|
|
||||||
ostream << "() {\n" ;
|
|
||||||
ostream << " Trick::UnitsMap * units_map_ptr = Trick::UnitsMap::units_map() ;\n" ;
|
|
||||||
ostream << text.str() ;
|
|
||||||
ostream << " }\n" ;
|
ostream << " }\n" ;
|
||||||
}
|
}
|
||||||
ostream << "} um" ;
|
|
||||||
printNamespaces( ostream, cv , "__" ) ;
|
ostream << "} um" << name << ";\n" ;
|
||||||
printContainerClasses( ostream, cv , "__" ) ;
|
|
||||||
ostream << cv->getMangledTypeName() ;
|
|
||||||
ostream << " ;\n" ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Utility routines for printing */
|
/* Utility routines for printing */
|
||||||
@ -103,31 +84,13 @@ bool PrintFileContentsBase::determinePrintAttr( ClassValues * c , FieldDescripti
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints namespace containers of a class delimited by delim */
|
std::vector<FieldDescription*> PrintFileContentsBase::getPrintableFields(ClassValues& classValues) {
|
||||||
void PrintFileContentsBase::printNamespaces( std::ostream & ostream , ConstructValues * c , const char * delim ) {
|
std::vector<FieldDescription*> results;
|
||||||
for ( ClassValues::NamespaceIterator nsi = c->namespace_begin() ; nsi != c->namespace_end() ; ++nsi ) {
|
for (auto& field : classValues.getFieldDescriptions()) {
|
||||||
ostream << *nsi << delim ;
|
if (determinePrintAttr(&classValues, field) and field->getUnits().compare("1")) {
|
||||||
}
|
results.push_back(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints namespace open block */
|
|
||||||
void PrintFileContentsBase::printOpenNamespaceBlocks( std::ostream & ostream , ClassValues * c ) {
|
|
||||||
for ( ClassValues::NamespaceIterator nsi = c->namespace_begin() ; nsi != c->namespace_end() ; ++nsi ) {
|
|
||||||
ostream << "namespace " << *nsi << " {\n" ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints namespace close block */
|
|
||||||
void PrintFileContentsBase::printCloseNamespaceBlocks( std::ostream & ostream , ClassValues * c ) {
|
|
||||||
for ( ClassValues::NamespaceIterator nsi = c->namespace_begin() ; nsi != c->namespace_end() ; ++nsi ) {
|
|
||||||
ostream << "}\n" ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prints class containers of a class delimited by delim */
|
|
||||||
void PrintFileContentsBase::printContainerClasses( std::ostream & ostream , ConstructValues * c , const char * delim ) {
|
|
||||||
for ( ClassValues::ContainerClassIterator ci = c->container_class_begin() ; ci != c->container_class_end() ; ci++ ) {
|
|
||||||
ostream << *ci << delim ;
|
|
||||||
}
|
}
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,21 +55,8 @@ class PrintFileContentsBase {
|
|||||||
/* internal function determines if a particular field is printable */
|
/* internal function determines if a particular field is printable */
|
||||||
bool determinePrintAttr(ClassValues * c , FieldDescription *fdes) ;
|
bool determinePrintAttr(ClassValues * c , FieldDescription *fdes) ;
|
||||||
|
|
||||||
/** Prints namespace containers of a class delimited by delim */
|
/* gets a vector of fields that can be printed */
|
||||||
void printNamespaces(std::ostream & ostream, ConstructValues * c , const char * delim ) ;
|
std::vector<FieldDescription*> getPrintableFields(ClassValues& classValues);
|
||||||
|
|
||||||
/** Prints namespace open block */
|
|
||||||
void printOpenNamespaceBlocks( std::ostream & ostream, ClassValues * c ) ;
|
|
||||||
|
|
||||||
/** Prints namespace close block */
|
|
||||||
void printCloseNamespaceBlocks( std::ostream & ostream, ClassValues * c ) ;
|
|
||||||
|
|
||||||
/* Note: There are no open/close namespace blocks for enums. The
|
|
||||||
enum attributes do not have anything that needs to be enclosed in
|
|
||||||
namespaces */
|
|
||||||
|
|
||||||
/** Prints class containers of a class delimited by delim */
|
|
||||||
void printContainerClasses(std::ostream & ostream, ConstructValues * c , const char * delim ) ;
|
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -107,20 +107,19 @@ bool TypedefVisitor::VisitTemplateSpecializationType(clang::TemplateSpecializati
|
|||||||
CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ;
|
CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ;
|
||||||
cvis.TraverseCXXRecordDecl(clang::cast<clang::CXXRecordDecl>(td)) ;
|
cvis.TraverseCXXRecordDecl(clang::cast<clang::CXXRecordDecl>(td)) ;
|
||||||
cval = cvis.get_class_data() ;
|
cval = cvis.get_class_data() ;
|
||||||
// Check to see if this typedef is to a STL. If it is we don't want it.
|
|
||||||
if ((cval->namespace_begin() == cval->namespace_end()) or
|
if (cval->isInStandardNamespace()) {
|
||||||
(cval->namespace_begin() != cval->namespace_end() and cval->namespace_begin()->compare("std")) ) {
|
if ( debug_level >= 4 ) {
|
||||||
|
std::cout << "\nTypedefVisitor VisitTemplateSpecializationType not adding class" << std::endl ;
|
||||||
|
}
|
||||||
|
cval = NULL ;
|
||||||
|
} else {
|
||||||
cval->setName(typedef_name) ;
|
cval->setName(typedef_name) ;
|
||||||
cval->clearNamespacesAndClasses() ;
|
cval->clearNamespacesAndClasses() ;
|
||||||
cval->getNamespacesAndClasses(typedef_decl_context) ;
|
cval->getNamespacesAndClasses(typedef_decl_context) ;
|
||||||
// Set the filename of the typedeffed target to the file where the typedef is.
|
// Set the filename of the typedeffed target to the file where the typedef is.
|
||||||
cval->setFileName(getFileName( ci , typedef_location.getBegin() , hsd )) ;
|
cval->setFileName(getFileName( ci , typedef_location.getBegin() , hsd )) ;
|
||||||
pa.printClass(cval) ;
|
pa.printClass(cval) ;
|
||||||
} else {
|
|
||||||
if ( debug_level >=4 ) {
|
|
||||||
std::cout << "\nTypedefVisitor VisitTemplateSpecializationType not adding class" << std::endl ;
|
|
||||||
}
|
|
||||||
cval = NULL ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +60,13 @@ bool VariableVisitor::VisitTemplateSpecializationType(clang::TemplateSpecializat
|
|||||||
CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ;
|
CXXRecordVisitor cvis(ci, cs, hsd, pa, true) ;
|
||||||
cval = cvis.get_class_data() ;
|
cval = cvis.get_class_data() ;
|
||||||
cvis.TraverseCXXRecordDecl(clang::cast<clang::CXXRecordDecl>(td)) ;
|
cvis.TraverseCXXRecordDecl(clang::cast<clang::CXXRecordDecl>(td)) ;
|
||||||
// Check to see if this typedef is to a STL. If it is we don't want it.
|
|
||||||
if ((cval->namespace_begin() == cval->namespace_end()) or
|
|
||||||
(cval->namespace_begin() != cval->namespace_end() and cval->namespace_begin()->compare("std")) ) {
|
|
||||||
|
|
||||||
|
if (cval->isInStandardNamespace()) {
|
||||||
|
if ( debug_level >=4 ) {
|
||||||
|
std::cout << "\nTypedefVisitor VisitTemplateSpecializationType not adding class" << std::endl ;
|
||||||
|
}
|
||||||
|
cval = NULL ;
|
||||||
|
} else {
|
||||||
std::string mangled_name = tst->desugar().getAsString() ;
|
std::string mangled_name = tst->desugar().getAsString() ;
|
||||||
size_t pos ;
|
size_t pos ;
|
||||||
if ((pos = mangled_name.find("class ")) != std::string::npos ) {
|
if ((pos = mangled_name.find("class ")) != std::string::npos ) {
|
||||||
@ -81,11 +84,6 @@ bool VariableVisitor::VisitTemplateSpecializationType(clang::TemplateSpecializat
|
|||||||
cval->setMangledTypeName(mangled_name) ;
|
cval->setMangledTypeName(mangled_name) ;
|
||||||
|
|
||||||
pa.printClass(cval) ;
|
pa.printClass(cval) ;
|
||||||
} else {
|
|
||||||
if ( debug_level >=4 ) {
|
|
||||||
std::cout << "\nTypedefVisitor VisitTemplateSpecializationType not adding class" << std::endl ;
|
|
||||||
}
|
|
||||||
cval = NULL ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "CommentSaver.hh"
|
#include "CommentSaver.hh"
|
||||||
#include "TranslationUnitVisitor.hh"
|
#include "TranslationUnitVisitor.hh"
|
||||||
#include "PrintAttributes.hh"
|
#include "PrintAttributes.hh"
|
||||||
#include "PrintAttributesFactory.hh"
|
|
||||||
#include "Utilities.hh"
|
#include "Utilities.hh"
|
||||||
|
|
||||||
/* Command line arguments. These work better as globals, as suggested in llvm/CommandLine documentation */
|
/* Command line arguments. These work better as globals, as suggested in llvm/CommandLine documentation */
|
||||||
@ -65,9 +64,9 @@ int main(int argc, char * argv[]) {
|
|||||||
*/
|
*/
|
||||||
llvm::cl::ParseCommandLineOptions(argc, argv);
|
llvm::cl::ParseCommandLineOptions(argc, argv);
|
||||||
|
|
||||||
if (!validAttributesVersion(attr_version)) {
|
/*if (!validAttributesVersion(attr_version)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (input_file_names.empty()) {
|
if (input_file_names.empty()) {
|
||||||
std::cerr << "No header file specified" << std::endl;
|
std::cerr << "No header file specified" << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user