[pkg-d-commits] [ldc] 141/211: Refactoring of UDA code (from dcompute branch) [NFC] (#1877)
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:17 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit fd73375f6863fec6b3bda5075cf77513867f1f3b
Author: Johan Engelen <jbc.engelen at gmail.com>
Date: Sun Nov 13 11:41:23 2016 +0100
Refactoring of UDA code (from dcompute branch) [NFC] (#1877)
Also see PR #1800 .
---
gen/uda.cpp | 71 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 35 insertions(+), 36 deletions(-)
diff --git a/gen/uda.cpp b/gen/uda.cpp
index 7c2184f..0aa9632 100644
--- a/gen/uda.cpp
+++ b/gen/uda.cpp
@@ -86,6 +86,28 @@ void checkStructElems(StructLiteralExp *sle, ArrayParam<Type *> elemTypes) {
}
}
+/// Returns the StructLiteralExp magic attribute with name `name` if it is
+/// applied to `sym`, otherwise returns nullptr.
+StructLiteralExp *getMagicAttribute(Dsymbol *sym, std::string name) {
+ if (!sym->userAttribDecl)
+ return nullptr;
+
+ // Loop over all UDAs and early return the expression if a match was found.
+ Expressions *attrs = sym->userAttribDecl->getAttributes();
+ expandTuples(attrs);
+ for (auto &attr : *attrs) {
+ auto sle = getLdcAttributesStruct(attr);
+ if (!sle)
+ continue;
+
+ if (name == sle->sd->ident->string) {
+ return sle;
+ }
+ }
+
+ return nullptr;
+}
+
/// Returns a null-terminated string
const char *getStringElem(StructLiteralExp *sle, size_t idx) {
auto arg = (*sle->elements)[idx];
@@ -252,19 +274,15 @@ void applyVarDeclUDAs(VarDeclaration *decl, llvm::GlobalVariable *gvar) {
auto name = sle->sd->ident->string;
if (name == attr::section) {
applyAttrSection(sle, gvar);
- } else if (name == attr::optStrategy) {
+ } else if (name == attr::optStrategy || name == attr::target) {
sle->error(
- "Special attribute 'ldc.attributes.optStrategy' is only valid for "
- "functions");
- } else if (name == attr::target) {
- sle->error("Special attribute 'ldc.attributes.target' is only valid for "
- "functions");
+ "Special attribute 'ldc.attributes.%s' is only valid for functions",
+ name);
} else if (name == attr::weak) {
// @weak is applied elsewhere
} else {
sle->warning(
- "Ignoring unrecognized special attribute 'ldc.attributes.%s'",
- sle->sd->ident->string);
+ "Ignoring unrecognized special attribute 'ldc.attributes.%s'", name);
}
}
}
@@ -298,40 +316,21 @@ void applyFuncDeclUDAs(FuncDeclaration *decl, IrFunction *irFunc) {
// @weak is applied elsewhere
} else {
sle->warning(
- "ignoring unrecognized special attribute 'ldc.attributes.%s'",
- sle->sd->ident->string);
+ "Ignoring unrecognized special attribute 'ldc.attributes.%s'", name);
}
}
}
/// Checks whether 'sym' has the @ldc.attributes._weak() UDA applied.
bool hasWeakUDA(Dsymbol *sym) {
- if (!sym->userAttribDecl)
+ auto sle = getMagicAttribute(sym, attr::weak);
+ if (!sle)
return false;
- // Loop over all UDAs and early return true if @weak was found.
- Expressions *attrs = sym->userAttribDecl->getAttributes();
- expandTuples(attrs);
- for (auto &attr : *attrs) {
- auto sle = getLdcAttributesStruct(attr);
- if (!sle)
- continue;
-
- auto name = sle->sd->ident->string;
- if (name == attr::weak) {
- // Check whether @weak can be applied to this symbol.
- // Because hasWeakUDA is currently only called for global symbols, this
- // check never errors.
- auto vd = sym->isVarDeclaration();
- if (!(vd && vd->isDataseg()) && !sym->isFuncDeclaration()) {
- sym->error("@ldc.attributes.weak can only be applied to functions or "
- "global variables");
- return false;
- }
-
- return true;
- }
- }
-
- return false;
+ checkStructElems(sle, {});
+ auto vd = sym->isVarDeclaration();
+ if (!(vd && vd->isDataseg()) && !sym->isFuncDeclaration())
+ sym->error("@ldc.attributes.weak can only be applied to functions or "
+ "global variables");
+ return true;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list