Internals: Refactor statement tracking. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-01-18 13:02:42 -05:00
parent 09199f79a6
commit 835f668aaa
2 changed files with 22 additions and 18 deletions

View File

@ -1723,12 +1723,15 @@ public:
class AstNodeStmt : public AstNode { class AstNodeStmt : public AstNode {
// Statement -- anything that's directly under a function // Statement -- anything that's directly under a function
bool m_statement; // Really a statement (e.g. not a function with return)
public: public:
explicit AstNodeStmt(FileLine* fl) explicit AstNodeStmt(FileLine* fl, bool statement = true)
: AstNode(fl) {} : AstNode(fl)
, m_statement(statement) {}
ASTNODE_BASE_FUNCS(NodeStmt) ASTNODE_BASE_FUNCS(NodeStmt)
// METHODS // METHODS
virtual bool isStatement() const { return true; } // Really a statement bool isStatement() const { return m_statement; } // Really a statement
void statement(bool flag) { m_statement = flag; }
virtual void addNextStmt(AstNode* newp, AstNode* belowp); // Stop statement searchback here virtual void addNextStmt(AstNode* newp, AstNode* belowp); // Stop statement searchback here
virtual void addBeforeStmt(AstNode* newp, AstNode* belowp); // Stop statement searchback here virtual void addBeforeStmt(AstNode* newp, AstNode* belowp); // Stop statement searchback here
}; };
@ -2170,13 +2173,13 @@ private:
string m_inlinedDots; // Dotted hierarchy flattened out string m_inlinedDots; // Dotted hierarchy flattened out
AstPackage* m_packagep; // Package hierarchy AstPackage* m_packagep; // Package hierarchy
public: public:
AstNodeFTaskRef(FileLine* fl, AstNode* namep, AstNode* pinsp) AstNodeFTaskRef(FileLine* fl, bool statement, AstNode* namep, AstNode* pinsp)
: AstNodeStmt(fl) : AstNodeStmt(fl, statement)
, m_taskp(NULL), m_packagep(NULL) { , m_taskp(NULL), m_packagep(NULL) {
setOp1p(namep); addNOp2p(pinsp); setOp1p(namep); addNOp2p(pinsp);
} }
AstNodeFTaskRef(FileLine* fl, const string& name, AstNode* pinsp) AstNodeFTaskRef(FileLine* fl, bool statement, const string& name, AstNode* pinsp)
: AstNodeStmt(fl) : AstNodeStmt(fl, statement)
, m_taskp(NULL), m_name(name), m_packagep(NULL) { , m_taskp(NULL), m_name(name), m_packagep(NULL) {
addNOp2p(pinsp); addNOp2p(pinsp);
} }

View File

@ -1373,17 +1373,19 @@ class AstCMethodCall : public AstNodeStmt {
private: private:
string m_name; // Name of method string m_name; // Name of method
bool m_pure; // Pure optimizable bool m_pure; // Pure optimizable
bool m_statement; // Is a statement (AstNodeMath-like) versus AstNodeStmt-like
public: public:
AstCMethodCall(FileLine* fl, AstNode* fromp, VFlagChildDType, const string& name, AstCMethodCall(FileLine* fl, AstNode* fromp, VFlagChildDType, const string& name,
AstNode* pinsp) AstNode* pinsp)
: AstNodeStmt(fl), m_name(name), m_pure(false), m_statement(false) { : AstNodeStmt(fl, false)
, m_name(name)
, m_pure(false) {
setOp1p(fromp); setOp1p(fromp);
dtypep(NULL); // V3Width will resolve dtypep(NULL); // V3Width will resolve
addNOp2p(pinsp); addNOp2p(pinsp);
} }
AstCMethodCall(FileLine* fl, AstNode* fromp, const string& name, AstNode* pinsp) AstCMethodCall(FileLine* fl, AstNode* fromp, const string& name, AstNode* pinsp)
: AstNodeStmt(fl), m_name(name), m_statement(false) { : AstNodeStmt(fl, false)
, m_name(name) {
setOp1p(fromp); setOp1p(fromp);
addNOp2p(pinsp); addNOp2p(pinsp);
} }
@ -1395,10 +1397,9 @@ public:
virtual bool same(const AstNode* samep) const { virtual bool same(const AstNode* samep) const {
const AstCMethodCall* asamep = static_cast<const AstCMethodCall*>(samep); const AstCMethodCall* asamep = static_cast<const AstCMethodCall*>(samep);
return (m_name == asamep->m_name); } return (m_name == asamep->m_name); }
virtual bool isStatement() const { return m_statement; }
virtual bool isPure() const { return m_pure; } virtual bool isPure() const { return m_pure; }
void pure(bool flag) { m_pure = flag; } void pure(bool flag) { m_pure = flag; }
void makeStatement() { m_statement = true; dtypeSetVoid(); } void makeStatement() { statement(true); dtypeSetVoid(); }
AstNode* fromp() const { return op1p(); } // op1 = Extracting what (NULL=TBD during parsing) AstNode* fromp() const { return op1p(); } // op1 = Extracting what (NULL=TBD during parsing)
void fromp(AstNode* nodep) { setOp1p(nodep); } void fromp(AstNode* nodep) { setOp1p(nodep); }
AstNode* pinsp() const { return op2p(); } // op2 = Pin interconnection list AstNode* pinsp() const { return op2p(); } // op2 = Pin interconnection list
@ -2431,22 +2432,22 @@ class AstTaskRef : public AstNodeFTaskRef {
// A reference to a task // A reference to a task
public: public:
AstTaskRef(FileLine* fl, AstParseRef* namep, AstNode* pinsp) AstTaskRef(FileLine* fl, AstParseRef* namep, AstNode* pinsp)
: AstNodeFTaskRef(fl, namep, pinsp) {} : AstNodeFTaskRef(fl, true, namep, pinsp) {
statement(true);
}
AstTaskRef(FileLine* fl, const string& name, AstNode* pinsp) AstTaskRef(FileLine* fl, const string& name, AstNode* pinsp)
: AstNodeFTaskRef(fl, name, pinsp) {} : AstNodeFTaskRef(fl, true, name, pinsp) {}
ASTNODE_NODE_FUNCS(TaskRef) ASTNODE_NODE_FUNCS(TaskRef)
virtual bool isStatement() const { return true; } // A statement, unlike FuncRef
}; };
class AstFuncRef : public AstNodeFTaskRef { class AstFuncRef : public AstNodeFTaskRef {
// A reference to a function // A reference to a function
public: public:
AstFuncRef(FileLine* fl, AstParseRef* namep, AstNode* pinsp) AstFuncRef(FileLine* fl, AstParseRef* namep, AstNode* pinsp)
: AstNodeFTaskRef(fl, namep, pinsp) {} : AstNodeFTaskRef(fl, false, namep, pinsp) {}
AstFuncRef(FileLine* fl, const string& name, AstNode* pinsp) AstFuncRef(FileLine* fl, const string& name, AstNode* pinsp)
: AstNodeFTaskRef(fl, name, pinsp) {} : AstNodeFTaskRef(fl, false, name, pinsp) {}
ASTNODE_NODE_FUNCS(FuncRef) ASTNODE_NODE_FUNCS(FuncRef)
virtual bool isStatement() const { return false; } // Not a statement, unlike TaskRef
virtual bool hasDType() const { return true; } virtual bool hasDType() const { return true; }
}; };