aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ConstantGen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/ConstantGen.cc')
-rw-r--r--lib/CodeGen/ConstantGen.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/CodeGen/ConstantGen.cc b/lib/CodeGen/ConstantGen.cc
index 12bf4b1..58913e4 100644
--- a/lib/CodeGen/ConstantGen.cc
+++ b/lib/CodeGen/ConstantGen.cc
@@ -1,4 +1,5 @@
#include "cps/CodeGen.h"
+#include <cstdio>
using namespace llvm;
using namespace cps;
@@ -15,6 +16,16 @@ void CodeGen::emitScopedBlock(const std::vector<std::unique_ptr<StmtAST>> &Body)
ConstantScopes.pop_back();
}
+void CodeGen::warnMemberShadow(const std::string &Name, int Line) const {
+ if (CurrentClass.empty()) return;
+ const TypeInfo *Class = resolveType(CurrentClass);
+ const RecordPayload *Record = Class ? Class->asRecord() : nullptr;
+ if (Record && Record->findField(Name)) {
+ fprintf(stderr, "warning: Declaration of %s shadows a field of class %s at line %d\n",
+ Name.c_str(), CurrentClass.c_str(), Line);
+ }
+}
+
bool CodeGen::prepareSymbolDeclaration(const std::string &Name, bool IsConstant) {
if (!CurrentClass.empty() && sameIdentifier(Name, "this")) {
reportError("Cannot redeclare this inside a method");
@@ -31,6 +42,7 @@ bool CodeGen::prepareSymbolDeclaration(const std::string &Name, bool IsConstant)
} else if (IsConstant) {
Scope.Saved.emplace(Name, std::nullopt);
}
+ warnMemberShadow(Name, DiagnosticLine);
return true;
}