Skip to content

Commit

Permalink
hl: Make VarDeclOp use DeclStorageInterface instead of local methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jezurko committed Sep 23, 2024
1 parent 66e5138 commit 1a77c75
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 87 deletions.
1 change: 1 addition & 0 deletions include/vast/Dialect/HighLevel/HighLevelOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions include/vast/Dialect/HighLevel/HighLevelVar.td
Original file line number Diff line number Diff line change
Expand Up @@ -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 }];
Expand Down
85 changes: 0 additions & 85 deletions lib/vast/Dialect/HighLevel/HighLevelVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1a77c75

Please sign in to comment.