Recurse case ordering into nested switches

This commit is contained in:
caheckman 2020-07-16 17:28:24 -04:00
parent 4382d043f1
commit a4e360a3e5
3 changed files with 12 additions and 8 deletions

View file

@ -1254,12 +1254,13 @@ FlowBlock *BlockGraph::nextFlowAfter(const FlowBlock *bl) const
return nextbl; return nextbl;
} }
void BlockGraph::orderSwitchCases(void) const void BlockGraph::finalizePrinting(const Funcdata &data) const
{ {
// Recurse into all the substructures
vector<FlowBlock *>::const_iterator iter; vector<FlowBlock *>::const_iterator iter;
for(iter=list.begin();iter!=list.end();++iter) for(iter=list.begin();iter!=list.end();++iter)
(*iter)->orderSwitchCases(); (*iter)->finalizePrinting(data);
} }
void BlockGraph::saveXmlBody(ostream &s) const void BlockGraph::saveXmlBody(ostream &s) const
@ -3082,9 +3083,12 @@ void BlockSwitch::grabCaseBasic(FlowBlock *switchbl,const vector<FlowBlock *> &c
} }
} }
void BlockSwitch::orderSwitchCases(void) const void BlockSwitch::finalizePrinting(const Funcdata &data) const
{ {
BlockGraph::finalizePrinting(data); // Make sure to still recurse
// We need to order the cases based on the label
// First populate the label and depth fields of the CaseOrder objects
for(int4 i=0;i<caseblocks.size();++i) { // Construct the depth parameter, to sort fall-thru cases for(int4 i=0;i<caseblocks.size();++i) { // Construct the depth parameter, to sort fall-thru cases
CaseOrder &curcase( caseblocks[i] ); CaseOrder &curcase( caseblocks[i] );
int4 j = curcase.chain; int4 j = curcase.chain;
@ -3113,7 +3117,7 @@ void BlockSwitch::orderSwitchCases(void) const
else else
curcase.label = 0; // Should never happen curcase.label = 0; // Should never happen
} }
// Order case statements based on case labels // Do actual sort of the cases based on label
stable_sort(caseblocks.begin(),caseblocks.end(),CaseOrder::compare); stable_sort(caseblocks.begin(),caseblocks.end(),CaseOrder::compare);
} }

View file

@ -170,7 +170,7 @@ public:
virtual void flipInPlaceExecute(void); virtual void flipInPlaceExecute(void);
virtual bool isComplex(void) const { return true; } ///< Is \b this too complex to be a condition (BlockCondition) virtual bool isComplex(void) const { return true; } ///< Is \b this too complex to be a condition (BlockCondition)
virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const; virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const;
virtual void orderSwitchCases(void) const {} ///< Order \e case components of any contained BlockSwitch virtual void finalizePrinting(const Funcdata &data) const {} ///< Make any final configurations necessary to print the block
virtual void saveXmlHeader(ostream &s) const; ///< Save basic information as XML attributes virtual void saveXmlHeader(ostream &s) const; ///< Save basic information as XML attributes
virtual void restoreXmlHeader(const Element *el); ///< Restore basic information for XML attributes virtual void restoreXmlHeader(const Element *el); ///< Restore basic information for XML attributes
virtual void saveXmlBody(ostream &s) const {} ///< Save detail about components to an XML stream virtual void saveXmlBody(ostream &s) const {} ///< Save detail about components to an XML stream
@ -296,7 +296,7 @@ public:
virtual void printRaw(ostream &s) const; virtual void printRaw(ostream &s) const;
virtual void emit(PrintLanguage *lng) const { lng->emitBlockGraph(this); } virtual void emit(PrintLanguage *lng) const { lng->emitBlockGraph(this); }
virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const; virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const;
virtual void orderSwitchCases(void) const; virtual void finalizePrinting(const Funcdata &data) const;
virtual void saveXmlBody(ostream &s) const; virtual void saveXmlBody(ostream &s) const;
virtual void restoreXmlBody(List::const_iterator &iter,List::const_iterator enditer,BlockMap &resolver); virtual void restoreXmlBody(List::const_iterator &iter,List::const_iterator enditer,BlockMap &resolver);
void restoreXml(const Element *el,const AddrSpaceManager *m); ///< Restore \b this BlockGraph from an XML stream void restoreXml(const Element *el,const AddrSpaceManager *m); ///< Restore \b this BlockGraph from an XML stream
@ -674,7 +674,7 @@ public:
virtual void printHeader(ostream &s) const; virtual void printHeader(ostream &s) const;
virtual void emit(PrintLanguage *lng) const { lng->emitBlockSwitch(this); } virtual void emit(PrintLanguage *lng) const { lng->emitBlockSwitch(this); }
virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const; virtual FlowBlock *nextFlowAfter(const FlowBlock *bl) const;
virtual void orderSwitchCases(void) const; virtual void finalizePrinting(const Funcdata &data) const;
}; };
/// \brief Helper class for resolving cross-references while deserializing BlockGraph objects /// \brief Helper class for resolving cross-references while deserializing BlockGraph objects

View file

@ -2170,7 +2170,7 @@ int4 ActionFinalStructure::apply(Funcdata &data)
BlockGraph &graph(data.getStructure()); BlockGraph &graph(data.getStructure());
graph.orderBlocks(); graph.orderBlocks();
graph.orderSwitchCases(); graph.finalizePrinting(data);
graph.scopeBreak(-1,-1); // Put in \e break statements graph.scopeBreak(-1,-1); // Put in \e break statements
graph.markUnstructured(); // Put in \e gotos graph.markUnstructured(); // Put in \e gotos
graph.markLabelBumpUp(false); // Fix up labeling graph.markLabelBumpUp(false); // Fix up labeling