trick/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp

79 lines
3.0 KiB
C++
Raw Normal View History

2015-02-26 15:02:31 +00:00
#include <sys/stat.h>
#include <libgen.h>
#include <string.h>
#include <iomanip>
2016-10-20 19:53:21 +00:00
#include <sstream>
2015-02-26 15:02:31 +00:00
#include "llvm/Support/CommandLine.h"
2015-02-26 15:02:31 +00:00
#include "PrintFileContentsBase.hh"
#include "FieldDescription.hh"
#include "ClassValues.hh"
#include "EnumValues.hh"
extern llvm::cl::opt< bool > global_compat15 ;
2015-02-26 15:02:31 +00:00
PrintFileContentsBase::PrintFileContentsBase() {}
// provide empty default implementation of these routines.
2016-10-20 19:53:21 +00:00
void PrintFileContentsBase::printClassMapHeader(std::ostream & ostream, std::string function_name ) {}
void PrintFileContentsBase::printClassMap(std::ostream & ostream, ClassValues * cv) {}
void PrintFileContentsBase::printClassMapFooter(std::ostream & ostream) {}
2015-02-26 15:02:31 +00:00
2016-10-20 19:53:21 +00:00
void PrintFileContentsBase::printEnumMapHeader(std::ostream & ostream, std::string function_name ) {}
void PrintFileContentsBase::printEnumMap(std::ostream & ostream, EnumValues * ev) {}
void PrintFileContentsBase::printEnumMapFooter(std::ostream & ostream) {}
2015-02-26 15:02:31 +00:00
2016-10-20 19:53:21 +00:00
void PrintFileContentsBase::print_units_map(std::ostream & ostream, ClassValues * cv ) {
const std::string name = cv->getFullyQualifiedMangledTypeName("__");
ostream << "struct UnitsMap" << name << " {\n" ;
auto fields = getPrintableFields(*cv);
if (fields.size()) {
ostream << " UnitsMap" << name << "() {\n"
<< " Trick::UnitsMap* units_map_ptr = Trick::UnitsMap::units_map();\n" ;
for (auto& field : fields) {
ostream << " units_map_ptr->add_param(\"" ;
cv->printContainerClasses(ostream, "__");
ostream << cv->getName() << "_" << field->getName() << "\", \"" << field->getUnits() << "\") ;\n" ;
2015-02-26 15:02:31 +00:00
}
2016-10-20 19:53:21 +00:00
ostream << " }\n" ;
}
ostream << "} um" << name << ";\n" ;
2015-02-26 15:02:31 +00:00
}
/* Utility routines for printing */
2016-10-20 19:53:21 +00:00
void PrintFileContentsBase::print_open_extern_c(std::ostream & ostream) {
ostream << "extern \"C\" {\n\n" ;
2015-02-26 15:02:31 +00:00
}
2016-10-20 19:53:21 +00:00
void PrintFileContentsBase::print_close_extern_c(std::ostream & ostream) {
ostream << "\n} //extern \"C\"\n\n" ;
2015-02-26 15:02:31 +00:00
}
/* internal function determines if a particular field is printable based
on access to the field and the presense of init_attr friends.
*/
bool PrintFileContentsBase::determinePrintAttr( ClassValues * c , FieldDescription * fdes ) {
if ( !fdes->getTypeName().compare("void") or !fdes->getChkpntIO() or !fdes->getEnumString().compare("TRICK_VOID")) {
return false;
}
if ( fdes->getAccess() == clang::AS_public or (!fdes->isStatic() and !global_compat15 and !c->isCompat15())) {
return true;
2015-02-26 15:02:31 +00:00
}
return c->getHasInitAttrFriend() && ( !fdes->isInherited() || fdes->getAccess() == clang::AS_protected ) ;
2015-02-26 15:02:31 +00:00
}
std::vector<FieldDescription*> PrintFileContentsBase::getPrintableFields(ClassValues& classValues) {
std::vector<FieldDescription*> results;
for (auto& field : classValues.getFieldDescriptions()) {
if (determinePrintAttr(&classValues, field) and field->getUnits().compare("1")) {
results.push_back(field);
}
2015-02-26 15:02:31 +00:00
}
return results;
2015-02-26 15:02:31 +00:00
}