diff --git a/include/vast/Dialect/HighLevel/HighLevelOps.hpp b/include/vast/Dialect/HighLevel/HighLevelOps.hpp index a22fbff157..85bff6e749 100644 --- a/include/vast/Dialect/HighLevel/HighLevelOps.hpp +++ b/include/vast/Dialect/HighLevel/HighLevelOps.hpp @@ -24,6 +24,7 @@ VAST_UNRELAX_WARNINGS #include "vast/Interfaces/TypeTraitExprInterface.hpp" #include "vast/Interfaces/AST/DeclInterface.hpp" +#include "vast/Dialect/Core/Interfaces/DeclStorageInterface.hpp" #define GET_OP_CLASSES #include "vast/Dialect/HighLevel/HighLevel.h.inc" diff --git a/include/vast/Dialect/HighLevel/HighLevelVar.td b/include/vast/Dialect/HighLevel/HighLevelVar.td index eecbd9c7cd..44202040bc 100644 --- a/include/vast/Dialect/HighLevel/HighLevelVar.td +++ b/include/vast/Dialect/HighLevel/HighLevelVar.td @@ -9,8 +9,7 @@ include "vast/Dialect/Core/Interfaces/DeclStorageInterface.td" // Variable Operation def HighLevel_VarDeclOp - : HighLevel_Op< "var", [Core_VarSymbol] > - , HighLevel_StorageSpecifiers + : HighLevel_Op< "var", [Core_VarSymbol, Core_DeclStorageInterface, DeclareOpInterfaceMethods< Core_DeclStorageInterface >,] > { let summary = "VAST variable declaration"; let description = [{ VAST variable declaration }]; diff --git a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp index 7c5af38276..41f3275abf 100644 --- a/lib/vast/Dialect/HighLevel/HighLevelVar.cpp +++ b/lib/vast/Dialect/HighLevel/HighLevelVar.cpp @@ -9,89 +9,4 @@ namespace vast::hl { - bool isFileContext(DeclContextKind kind) { - return kind == DeclContextKind::dc_translation_unit - || kind == DeclContextKind::dc_namespace; - } - - bool VarDeclOp::isInFileContext() { return isFileContext(getDeclContextKind()); } - - bool isFunctionOrMethodContext(DeclContextKind kind) { - return kind == DeclContextKind::dc_function - || kind == DeclContextKind::dc_method - || kind == DeclContextKind::dc_capture; - } - - bool VarDeclOp::isInFunctionOrMethodContext() { - return isFunctionOrMethodContext(getDeclContextKind()); - } - - bool isRecordContext(DeclContextKind kind) { return kind == DeclContextKind::dc_record; } - - bool VarDeclOp::isInRecordContext() { return isRecordContext(getDeclContextKind()); } - - DeclContextKind VarDeclOp::getDeclContextKind() { - auto st = core::get_effective_symbol_table_for< core::var_symbol >(*this)->get_defining_operation(); - if (mlir::isa< mlir::FunctionOpInterface >(st)) - return DeclContextKind::dc_function; - if (st->hasTrait< core::ScopeLikeTrait >()) - return DeclContextKind::dc_function; - if (mlir::isa< core::ModuleOp >(st)) - return DeclContextKind::dc_translation_unit; - if (mlir::isa< StructDeclOp >(st)) - return DeclContextKind::dc_record; - if (mlir::isa< EnumDeclOp >(st)) - return DeclContextKind::dc_enum; - VAST_UNIMPLEMENTED_MSG("unknown declaration context"); - } - - bool VarDeclOp::isStaticDataMember() { - // If it wasn't static, it would be a FieldDecl. - return isInRecordContext(); - } - - bool VarDeclOp::isFileVarDecl() { - return isInFileContext() || isStaticDataMember(); - } - - bool VarDeclOp::isLocalVarDecl() { return isInFunctionOrMethodContext(); } - - bool VarDeclOp::hasLocalStorage() { - switch (getStorageClass()) { - case StorageClass::sc_none: - return !isFileVarDecl() && getThreadStorageClass() == TSClass::tsc_none; - case StorageClass::sc_register: return isLocalVarDecl(); - case StorageClass::sc_auto: return true; - case StorageClass::sc_extern: - case StorageClass::sc_static: - case StorageClass::sc_private_extern: return false; - } - - VAST_UNIMPLEMENTED_MSG("unknown starage class"); - } - - bool VarDeclOp::isStaticLocal() { - if (isFileVarDecl()) - return false; - auto sc = getStorageClass(); - if (sc == StorageClass::sc_static) - return true; - auto tsc = getThreadStorageClass(); - return sc == StorageClass::sc_none && tsc == TSClass::tsc_cxx_thread; - } - - bool VarDeclOp::hasExternalStorage() { - auto sc = getStorageClass(); - return sc == StorageClass::sc_extern || sc == StorageClass::sc_private_extern; - } - - bool VarDeclOp::hasGlobalStorage() { return !hasLocalStorage(); } - - StorageDuration VarDeclOp::getStorageDuration() { - if (hasLocalStorage()) - return StorageDuration::sd_automatic; - if (getThreadStorageClass() != TSClass::tsc_none) - return StorageDuration::sd_thread; - return StorageDuration::sd_static; - } } // namespace vast::hl