From 9bde23011f1ce369684d472a0b982c40f3eed1b8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 14 Sep 2019 09:22:14 -0400 Subject: [PATCH] Global: Make SeekOrigin an enum class Makes the enumeration strongly typed and also allows forward declaring the enumeration type as well. --- atdna/main.cpp | 9 ++++++--- include/athena/Global.hpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/atdna/main.cpp b/atdna/main.cpp index 7acd2c2..5b13d2e 100644 --- a/atdna/main.cpp +++ b/atdna/main.cpp @@ -629,7 +629,7 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor { } else if (!tsDecl->getName().compare("Seek")) { size_t idx = 0; std::string offsetExprStr; - llvm::APSInt direction(64, 0); + llvm::APSInt direction(64, false); const clang::Expr* directionExpr = nullptr; bool bad = false; for (const clang::TemplateArgument& arg : *tsType) { @@ -649,8 +649,11 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor { offsetExprStr = offsetLiteral.toString(10); } } else { - directionExpr = expr; - if (!expr->isIntegerConstantExpr(direction, context)) { + clang::APValue result; + if (expr->isCXX11ConstantExpr(context, &result)) { + directionExpr = expr; + direction = result.getInt(); + } else { clang::DiagnosticBuilder diag = context.getDiagnostics().Report(expr->getExprLoc(), AthenaError); diag.AddString("Unable to use non-constant direction expression in Athena"); diag.AddSourceRange(clang::CharSourceRange(expr->getSourceRange(), true)); diff --git a/include/athena/Global.hpp b/include/athena/Global.hpp index 502291a..1f0f58a 100644 --- a/include/athena/Global.hpp +++ b/include/athena/Global.hpp @@ -123,7 +123,7 @@ namespace athena { namespace error { enum class Level { Message, Warning, Error, Fatal }; } -enum SeekOrigin { Begin, Current, End }; +enum class SeekOrigin { Begin, Current, End }; enum Endian { Little, Big };