From 5cba12444aae709b54fc8f8d9fc3a610ad84ae11 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 2 Jul 2020 14:28:28 -0700 Subject: [PATCH] GH-786: fix Stmt::As methods casting incomplete types --- src/Stmt.cc | 18 ++++++++++++++++++ src/Stmt.h | 19 +++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index a7919e52b2..98bcfb0bf5 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -51,6 +51,24 @@ Stmt::~Stmt() { } +StmtList* Stmt::AsStmtList() + { + CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name) + return (StmtList*) this; + } + +const StmtList* Stmt::AsStmtList() const + { + CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name) + return (const StmtList*) this; + } + +ForStmt* Stmt::AsForStmt() + { + CHECK_TAG(tag, STMT_FOR, "Stmt::AsForStmt", stmt_name) + return (ForStmt*) this; + } + bool Stmt::SetLocationInfo(const Location* start, const Location* end) { if ( ! BroObj::SetLocationInfo(start, end) ) diff --git a/src/Stmt.h b/src/Stmt.h index b39872aee8..dc744c9b4b 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -40,23 +40,10 @@ public: // True if the statement has no side effects, false otherwise. virtual bool IsPure() const; - StmtList* AsStmtList() - { - CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name) - return (StmtList*) this; - } + StmtList* AsStmtList(); + const StmtList* AsStmtList() const; - const StmtList* AsStmtList() const - { - CHECK_TAG(tag, STMT_LIST, "Stmt::AsStmtList", stmt_name) - return (const StmtList*) this; - } - - ForStmt* AsForStmt() - { - CHECK_TAG(tag, STMT_FOR, "Stmt::AsForStmt", stmt_name) - return (ForStmt*) this; - } + ForStmt* AsForStmt(); void RegisterAccess() const { last_access = network_time; access_count++; } void AccessStats(ODesc* d) const;