mirror of
https://github.com/nasa/trick.git
synced 2025-01-29 15:43:57 +00:00
Improve printable field detection
Renamed determinePrintAttr to isPrintable. Different callers need to filter on different IO specs, so I added an ioMask parameter. Additional refactoring. Refs #427
This commit is contained in:
parent
353905c1ed
commit
fe79aa81a5
@ -1,4 +1,4 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "PrintFileContents10.hh"
|
||||
@ -54,51 +54,51 @@ void PrintFileContents10::print_enum_attr(std::ostream & ostream , EnumValues *
|
||||
}
|
||||
|
||||
/** Prints attributes for a field */
|
||||
void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription * fdes ) {
|
||||
void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescription & fdes ) {
|
||||
int array_dim ;
|
||||
|
||||
ostream << "{\"" << fdes->getName() << "\"" // name
|
||||
<< ", \"" << fdes->getFullyQualifiedMangledTypeName("__") << "\"" // type_name
|
||||
<< ", \"" << fdes->getUnits() << "\"" // units
|
||||
ostream << "{\"" << fdes.getName() << "\"" // name
|
||||
<< ", \"" << fdes.getFullyQualifiedMangledTypeName("__") << "\"" // type_name
|
||||
<< ", \"" << fdes.getUnits() << "\"" // units
|
||||
<< ", \"\", \"\"," << std::endl // alias, user_defined
|
||||
<< " \"" << fdes->getDescription() << "\"," << std::endl // description
|
||||
<< " " << fdes->getIO() // io
|
||||
<< "," << fdes->getEnumString() ; // type
|
||||
<< " \"" << fdes.getDescription() << "\"," << std::endl // description
|
||||
<< " " << fdes.getIO() // io
|
||||
<< "," << fdes.getEnumString() ; // type
|
||||
// There are several cases when printing the size of a variable.
|
||||
if ( fdes->isBitField() ) {
|
||||
if ( fdes.isBitField() ) {
|
||||
// bitfields are handled in 4 byte (32 bit) chunks
|
||||
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
|
||||
ostream << ", 0" ;
|
||||
} else {
|
||||
// print size of the underlying type
|
||||
ostream << ", sizeof(" << fdes->getTypeName() << ")" ;
|
||||
ostream << ", sizeof(" << fdes.getTypeName() << ")" ;
|
||||
}
|
||||
ostream << ", 0, 0, Language_CPP" ; // range_min, range_max, language
|
||||
ostream << ", " << (fdes->isStatic() << 1) + (fdes->isDashDashUnits() << 2) << "," << std::endl ; // mods
|
||||
if ( fdes->isBitField() ) {
|
||||
ostream << ", " << (fdes.isStatic() << 1) + (fdes.isDashDashUnits() << 2) << "," << std::endl ; // mods
|
||||
if ( fdes.isBitField() ) {
|
||||
// For bitfields we need the offset to start on 4 byte boundaries because that is what our
|
||||
// insert and extract bitfield routines work with.
|
||||
ostream << " " << (fdes->getFieldOffset() - (fdes->getFieldOffset() % 32)) / 8 ; // offset
|
||||
ostream << " " << (fdes.getFieldOffset() - (fdes.getFieldOffset() % 32)) / 8 ; // offset
|
||||
} else {
|
||||
ostream << " " << (fdes->getFieldOffset() / 8) ; // offset
|
||||
ostream << " " << (fdes.getFieldOffset() / 8) ; // offset
|
||||
}
|
||||
ostream << ", NULL" ; // attr
|
||||
ostream << ", " << fdes->getNumDims() ; // num_index
|
||||
ostream << ", " << fdes.getNumDims() ; // num_index
|
||||
|
||||
ostream << ", {" ;
|
||||
if ( fdes->isBitField() ) {
|
||||
ostream << "{" << fdes->getBitFieldWidth() ; // size of bitfield
|
||||
ostream << ", " << 32 - (fdes->getFieldOffset() % 32) - fdes->getBitFieldWidth() << "}" ; // start bit
|
||||
if ( fdes.isBitField() ) {
|
||||
ostream << "{" << fdes.getBitFieldWidth() ; // size of bitfield
|
||||
ostream << ", " << 32 - (fdes.getFieldOffset() % 32) - fdes.getBitFieldWidth() << "}" ; // start bit
|
||||
} else {
|
||||
array_dim = fdes->getArrayDim(0) ;
|
||||
array_dim = fdes.getArrayDim(0) ;
|
||||
if ( array_dim < 0 ) array_dim = 0 ;
|
||||
ostream << "{" << array_dim << ", 0}" ; // index 0
|
||||
}
|
||||
unsigned int ii ;
|
||||
for ( ii = 1 ; ii < 8 ; ii++ ) {
|
||||
array_dim = fdes->getArrayDim(ii) ;
|
||||
array_dim = fdes.getArrayDim(ii) ;
|
||||
if ( array_dim < 0 ) array_dim = 0 ;
|
||||
ostream << ", {" << array_dim << ", 0}" ; // indexes 1 through 7
|
||||
}
|
||||
@ -113,17 +113,14 @@ void PrintFileContents10::print_class_attr(std::ostream & ostream , ClassValues
|
||||
print_open_extern_c(ostream) ;
|
||||
ostream << "ATTRIBUTES attr" << c->getFullyQualifiedMangledTypeName("__") << "[] = {" << std::endl ;
|
||||
|
||||
for (auto& fieldDescription : c->getFieldDescriptions()) {
|
||||
if ( determinePrintAttr(c , fieldDescription) ) {
|
||||
print_field_attr(ostream, fieldDescription) ;
|
||||
for (FieldDescription* fieldDescription : getPrintableFields(*c)) {
|
||||
print_field_attr(ostream, *fieldDescription) ;
|
||||
ostream << "," << std::endl ;
|
||||
}
|
||||
}
|
||||
// Print an empty sentinel attribute at the end of the class.
|
||||
FieldDescription * new_fdes = new FieldDescription(std::string("")) ;
|
||||
FieldDescription new_fdes(std::string("")) ;
|
||||
print_field_attr(ostream, new_fdes) ;
|
||||
ostream << " };" << std::endl ;
|
||||
delete new_fdes ;
|
||||
|
||||
print_close_extern_c(ostream) ;
|
||||
}
|
||||
@ -206,10 +203,8 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa
|
||||
<< " initialized = 1;\n\n" ;
|
||||
|
||||
unsigned int ii = 0;
|
||||
for ( auto field : cv->getFieldDescriptions() ) {
|
||||
if ( determinePrintAttr(cv, field) ) {
|
||||
print_field_init_attr_stmts(ostream, field, cv, ii++) ;
|
||||
}
|
||||
for ( FieldDescription* field : getPrintableFields(*cv) ) {
|
||||
print_field_init_attr_stmts(ostream, field, cv, ii++) ;
|
||||
}
|
||||
print_inherited_add_attr_info(ostream, cv ) ;
|
||||
ostream << "}\n" ;
|
||||
@ -320,7 +315,8 @@ void PrintFileContents10::print_clear_stl(std::ostream & ostream , FieldDescript
|
||||
}
|
||||
|
||||
void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues * cv ) {
|
||||
auto& fieldDescriptions = cv->getFieldDescriptions();
|
||||
std::vector<FieldDescription*> fieldDescriptions = getPrintableFields(*cv, 0x3 << 2);
|
||||
fieldDescriptions.erase(std::remove_if(fieldDescriptions.begin(), fieldDescriptions.end(), [](FieldDescription* field) {return !field->isSTL();}), fieldDescriptions.end());
|
||||
|
||||
if (!fieldDescriptions.size()) {
|
||||
return;
|
||||
@ -328,17 +324,15 @@ void PrintFileContents10::print_stl_helper(std::ostream & ostream , ClassValues
|
||||
|
||||
print_open_extern_c(ostream) ;
|
||||
|
||||
for (auto& field : fieldDescriptions) {
|
||||
if ( field->isSTL() and determinePrintAttr(cv, field) ) {
|
||||
if (field->isCheckpointable()) {
|
||||
print_checkpoint_stl(ostream, field, cv) ;
|
||||
print_post_checkpoint_stl(ostream, field, cv) ;
|
||||
}
|
||||
if (field->isRestorable()) {
|
||||
print_restore_stl(ostream, field, cv) ;
|
||||
if (field->hasSTLClear()) {
|
||||
print_clear_stl(ostream, field, cv) ;
|
||||
}
|
||||
for (FieldDescription* field : fieldDescriptions) {
|
||||
if (field->isCheckpointable()) {
|
||||
print_checkpoint_stl(ostream, field, cv) ;
|
||||
print_post_checkpoint_stl(ostream, field, cv) ;
|
||||
}
|
||||
if (field->isRestorable()) {
|
||||
print_restore_stl(ostream, field, cv) ;
|
||||
if (field->hasSTLClear()) {
|
||||
print_clear_stl(ostream, field, cv) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class PrintFileContents10 : public PrintFileContentsBase {
|
||||
void print_enum_attr(std::ostream & outfile , EnumValues * in_enum) ;
|
||||
|
||||
/** Prints attributes for a field */
|
||||
void print_field_attr(std::ostream & outfile , FieldDescription * fdes ) ;
|
||||
void print_field_attr(std::ostream & outfile , FieldDescription & fdes ) ;
|
||||
|
||||
/** Prints class attributes */
|
||||
void print_class_attr(std::ostream & outfile , ClassValues * in_class) ;
|
||||
|
@ -41,7 +41,7 @@ void PrintFileContentsBase::print_units_map(std::ostream & ostream, ClassValues
|
||||
ostream << " }\n" ;
|
||||
}
|
||||
|
||||
ostream << "} um" << name << ";\n" ;
|
||||
ostream << "} um" << name << ";\n\n" ;
|
||||
}
|
||||
|
||||
/* Utility routines for printing */
|
||||
@ -56,20 +56,20 @@ void PrintFileContentsBase::print_close_extern_c(std::ostream & ostream) {
|
||||
/* 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")) {
|
||||
bool PrintFileContentsBase::isPrintable( ClassValues * c , FieldDescription * fdes , unsigned int ioMask) {
|
||||
if ( !(fdes->getIO() & ioMask) || !fdes->getTypeName().compare("void") || !fdes->getEnumString().compare("TRICK_VOID")) {
|
||||
return false;
|
||||
}
|
||||
if ( fdes->getAccess() == clang::AS_public or (!fdes->isStatic() and !global_compat15 and !c->isCompat15())) {
|
||||
if ( fdes->getAccess() == clang::AS_public || (!fdes->isStatic() && !global_compat15 && !c->isCompat15())) {
|
||||
return true;
|
||||
}
|
||||
return c->getHasInitAttrFriend() && ( !fdes->isInherited() || fdes->getAccess() == clang::AS_protected ) ;
|
||||
}
|
||||
|
||||
std::vector<FieldDescription*> PrintFileContentsBase::getPrintableFields(ClassValues& classValues) {
|
||||
std::vector<FieldDescription*> PrintFileContentsBase::getPrintableFields(ClassValues& classValues, unsigned int ioMask) {
|
||||
std::vector<FieldDescription*> results;
|
||||
for (auto& field : classValues.getFieldDescriptions()) {
|
||||
if (determinePrintAttr(&classValues, field) and field->getUnits().compare("1")) {
|
||||
if (isPrintable(&classValues, field)) {
|
||||
results.push_back(field);
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ class PrintFileContentsBase {
|
||||
void print_close_extern_c(std::ostream & ostream) ;
|
||||
|
||||
/* internal function determines if a particular field is printable */
|
||||
bool determinePrintAttr(ClassValues * c , FieldDescription *fdes) ;
|
||||
bool isPrintable(ClassValues * c , FieldDescription *fdes , unsigned int ioMask = 0xFFFFFFF) ;
|
||||
|
||||
/* gets a vector of fields that can be printed */
|
||||
std::vector<FieldDescription*> getPrintableFields(ClassValues& classValues);
|
||||
std::vector<FieldDescription*> getPrintableFields(ClassValues& classValues, unsigned int ioMask = 0xFFFFFFF);
|
||||
|
||||
} ;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user