Add simplistic class support with many restrictions, see manual, #377.

This commit is contained in:
Wilson Snyder
2020-04-05 09:30:23 -04:00
parent f6048cc9c1
commit 6eadb8e771
101 changed files with 2258 additions and 66 deletions
+23
View File
@@ -96,6 +96,15 @@ private:
insertCast(nodep->lhsp(), VL_IDATASIZE);
}
}
void ensureNullChecked(AstNode* nodep) {
// TODO optimize to track null checked values and avoid where possible
if (!VN_IS(nodep->backp(), NullCheck)) {
AstNRelinker relinkHandle;
nodep->unlinkFrBack(&relinkHandle);
AstNode* newp = new AstNullCheck(nodep->fileline(), nodep);
relinkHandle.relink(newp);
}
}
// VISITORS
virtual void visit(AstNodeUniop* nodep) VL_OVERRIDE {
@@ -156,6 +165,20 @@ private:
nodep->user1(nodep->isQuad() || nodep->isWide());
}
// Null dereference protection
virtual void visit(AstNullCheck* nodep) VL_OVERRIDE {
iterateChildren(nodep);
nodep->user1(nodep->lhsp()->user1());
}
virtual void visit(AstCMethodCall* nodep) VL_OVERRIDE {
iterateChildren(nodep);
ensureNullChecked(nodep->fromp());
}
virtual void visit(AstMemberSel* nodep) VL_OVERRIDE {
iterateChildren(nodep);
ensureNullChecked(nodep->fromp());
}
// NOPs
virtual void visit(AstVar*) VL_OVERRIDE {}