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
|
|
|
|
2016-09-16 13:39:37 +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"
|
|
|
|
|
2016-10-21 14:30:55 +00:00
|
|
|
extern llvm::cl::opt< bool > global_compat15 ;
|
2016-09-16 13:39:37 +00:00
|
|
|
|
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 ) {
|
2016-10-28 19:37:12 +00:00
|
|
|
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" ;
|
|
|
|
}
|
2016-10-28 19:37:12 +00:00
|
|
|
|
|
|
|
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 ) {
|
2017-05-16 20:29:02 +00:00
|
|
|
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
|
|
|
}
|
2017-05-16 20:29:02 +00:00
|
|
|
return c->getHasInitAttrFriend() && ( !fdes->isInherited() || fdes->getAccess() == clang::AS_protected ) ;
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 19:37:12 +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
|
|
|
}
|
2016-10-28 19:37:12 +00:00
|
|
|
return results;
|
2015-02-26 15:02:31 +00:00
|
|
|
}
|
|
|
|
|