Namespace display options

This commit is contained in:
caheckman 2020-06-26 16:48:00 -04:00
parent 05c3358fe4
commit e339d91ffd
12 changed files with 129 additions and 75 deletions

View file

@ -81,6 +81,7 @@ OptionDatabase::OptionDatabase(Architecture *g)
registerOption(new OptionToggleRule());
registerOption(new OptionAliasBlock());
registerOption(new OptionMaxInstruction());
registerOption(new OptionNamespaceStrategy());
}
OptionDatabase::~OptionDatabase(void)
@ -833,3 +834,23 @@ string OptionMaxInstruction::apply(Architecture *glb,const string &p1,const stri
glb->max_instructions = newMax;
return "Maximum instructions per function set";
}
/// \class OptionNamespaceStrategy
/// \brief How should namespace tokens be displayed
///
/// The first parameter gives the strategy identifier, mapping to PrintLanguage::namespace_strategy.
string OptionNamespaceStrategy::apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const
{
PrintLanguage::namespace_strategy strategy;
if (p1 == "minimal")
strategy = PrintLanguage::MINIMAL_NAMESPACES;
else if (p1 == "all")
strategy = PrintLanguage::ALL_NAMESPACES;
else if (p1 == "none")
strategy = PrintLanguage::NO_NAMESPACES;
else
throw ParseError("Must specify a valid strategy");
glb->print->setNamespaceStrategy(strategy);
return "Namespace strategy set";
}

View file

@ -270,4 +270,10 @@ public:
virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const;
};
class OptionNamespaceStrategy : public ArchOption {
public:
OptionNamespaceStrategy(void) { name = "namespacestrategy"; } ///< Constructor
virtual string apply(Architecture *glb,const string &p1,const string &p2,const string &p3) const;
};
#endif

View file

@ -174,7 +174,17 @@ void PrintC::pushPrototypeInputs(const FuncProto *proto)
void PrintC::pushSymbolScope(const Symbol *symbol)
{
int4 scopedepth = symbol->getResolutionDepth(curscope);
int4 scopedepth;
if (namespc_strategy == MINIMAL_NAMESPACES)
scopedepth = symbol->getResolutionDepth(curscope);
else if (namespc_strategy == ALL_NAMESPACES) {
if (symbol->getScope() == curscope)
scopedepth = 0;
else
scopedepth = symbol->getResolutionDepth((const Scope *)0);
}
else
scopedepth = 0;
if (scopedepth != 0) {
vector<const Scope *> scopeList;
const Scope *point = symbol->getScope();
@ -195,7 +205,17 @@ void PrintC::pushSymbolScope(const Symbol *symbol)
void PrintC::emitSymbolScope(const Symbol *symbol)
{
int4 scopedepth = symbol->getResolutionDepth(curscope);
int4 scopedepth;
if (namespc_strategy == MINIMAL_NAMESPACES)
scopedepth = symbol->getResolutionDepth(curscope);
else if (namespc_strategy == ALL_NAMESPACES) {
if (symbol->getScope() == curscope)
scopedepth = 0;
else
scopedepth = symbol->getResolutionDepth((const Scope *)0);
}
else
scopedepth = 0;
if (scopedepth != 0) {
vector<const Scope *> scopeList;
const Scope *point = symbol->getScope();

View file

@ -575,6 +575,7 @@ void PrintLanguage::resetDefaultsInternal(void)
mods = 0;
head_comment_type = Comment::header | Comment::warningheader;
line_commentindent = 20;
namespc_strategy = MINIMAL_NAMESPACES;
instr_comment_type = Comment::user2 | Comment::warning;
}

View file

@ -162,6 +162,13 @@ public:
blanktoken ///< For anonymous types
};
/// \brief Strategies for displaying namespace tokens
enum namespace_strategy {
MINIMAL_NAMESPACES = 0, ///< (default) Print just enough namespace info to fully resolve symbol
NO_NAMESPACES = 1, ///< Never print namespace information
ALL_NAMESPACES = 2 ///< Always print all namespace information
};
/// \brief An entry on the reverse polish notation (RPN) stack
struct ReversePolish {
const OpToken *tok; ///< The operator token
@ -245,6 +252,7 @@ protected:
uint4 mods; ///< Currently active printing modifications
uint4 instr_comment_type; ///< Type of instruction comments to display
uint4 head_comment_type; ///< Type of header comments to display
namespace_strategy namespc_strategy; ///< How should namespace tokens be displayed
#ifdef CPUI_DEBUG
bool isStackEmpty(void) const { return (nodepend.empty()&&revpol.empty()); } ///< Return \b true if the RPN stack is empty
bool isModStackEmpty(void) const { return modstack.empty(); } ///< Return \b true if the printing modification stack is empty
@ -412,6 +420,7 @@ public:
bool usecommentfill); ///< Establish comment delimiters for the language
uint4 getInstructionComment(void) const { return instr_comment_type; } ///< Get the type of comments suitable within the body of a function
void setInstructionComment(uint4 val) { instr_comment_type = val; } ///< Set the type of comments suitable within the body of a function
void setNamespaceStrategy(namespace_strategy strat) { namespc_strategy = strat; } ///< Set how namespace tokens are displayed
uint4 getHeaderComment(void) const { return head_comment_type; } ///< Get the type of comments suitable for a function header
void setHeaderComment(uint4 val) { head_comment_type = val; } ///< Set the type of comments suitable for a function header
bool emitsXml(void) const { return emit->emitsXml(); } ///< Does the low-level emitter, emit XML markup