aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-04-24 05:37:28 +0000
committerDouglas Gregor <dgregor@apple.com>2011-04-24 05:37:28 +0000
commit312eadb832cab4497a069409954500d8192b8f0d (patch)
treef919e5f5b0f8f0e2092ee948b86f92a7171697a2 /lib/Sema/SemaExpr.cpp
parent1b6005285e234bc30698917b2d3abb2f1f98bc77 (diff)
Implement a new identifier-classification scheme where Sema
performs name lookup for an identifier and resolves it to a type/expression/template/etc. in the same step. This scheme is intended to improve both performance (by reducing the number of redundant name lookups for a given identifier token) and error recovery (by giving Sema a chance to correct type names before the parser has decided that the identifier isn't a type name). For example, this allows us to properly typo-correct type names at the beginning of a statement: t.c:6:3: error: use of undeclared identifier 'integer'; did you mean 'Integer'? integer *i = 0; ^~~~~~~ Integer t.c:1:13: note: 'Integer' declared here typedef int Integer; ^ Previously, we wouldn't give a Fix-It because the typo correction occurred after the parser had checked whether "integer" was a type name (via Sema::getTypeName(), which isn't allowed to typo-correct) and therefore decided to parse "integer * i = 0" as an expression. By typo-correcting earlier, we typo-correct to the type name Integer and parse this as a declaration. Moreover, in this context, we can also typo-correct identifiers to keywords, e.g., t.c:7:3: error: use of undeclared identifier 'vid'; did you mean 'void'? vid *p = i; ^~~ void and recover appropriately. Note that this is very much a work-in-progress. The new Sema::ClassifyName is only used for expression-or-declaration disambiguation in C at the statement level. The next steps will be to make this work for the same disambiguation in C++ (where functional-style casts make some trouble), then push it further into the parser to eliminate more redundant name lookups. Fixes <rdar://problem/7963833> for C and starts us down the path of <rdar://problem/8172000>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130082 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index da7619d0f4..1a8c4c9e04 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1708,11 +1708,10 @@ bool Sema::canSynthesizeProvisionalIvar(ObjCPropertyDecl *Property) {
return true;
}
-static ObjCIvarDecl *SynthesizeProvisionalIvar(Sema &SemaRef,
- LookupResult &Lookup,
- IdentifierInfo *II,
- SourceLocation NameLoc) {
- ObjCMethodDecl *CurMeth = SemaRef.getCurMethodDecl();
+ObjCIvarDecl *Sema::SynthesizeProvisionalIvar(LookupResult &Lookup,
+ IdentifierInfo *II,
+ SourceLocation NameLoc) {
+ ObjCMethodDecl *CurMeth = getCurMethodDecl();
bool LookForIvars;
if (Lookup.empty())
LookForIvars = true;
@@ -1732,7 +1731,7 @@ static ObjCIvarDecl *SynthesizeProvisionalIvar(Sema &SemaRef,
if (!ClassImpDecl)
return 0;
bool DynamicImplSeen = false;
- ObjCPropertyDecl *property = SemaRef.LookupPropertyDecl(IDecl, II);
+ ObjCPropertyDecl *property = LookupPropertyDecl(IDecl, II);
if (!property)
return 0;
if (ObjCPropertyImplDecl *PIDecl = ClassImpDecl->FindPropertyImplDecl(II)) {
@@ -1744,8 +1743,8 @@ static ObjCIvarDecl *SynthesizeProvisionalIvar(Sema &SemaRef,
return 0;
}
if (!DynamicImplSeen) {
- QualType PropType = SemaRef.Context.getCanonicalType(property->getType());
- ObjCIvarDecl *Ivar = ObjCIvarDecl::Create(SemaRef.Context, ClassImpDecl,
+ QualType PropType = Context.getCanonicalType(property->getType());
+ ObjCIvarDecl *Ivar = ObjCIvarDecl::Create(Context, ClassImpDecl,
NameLoc, NameLoc,
II, PropType, /*Dinfo=*/0,
ObjCIvarDecl::Private,
@@ -1848,7 +1847,7 @@ ExprResult Sema::ActOnIdExpression(Scope *S,
// Synthesize ivars lazily.
if (getLangOptions().ObjCDefaultSynthProperties &&
getLangOptions().ObjCNonFragileABI2) {
- if (SynthesizeProvisionalIvar(*this, R, II, NameLoc)) {
+ if (SynthesizeProvisionalIvar(R, II, NameLoc)) {
if (const ObjCPropertyDecl *Property =
canSynthesizeProvisionalIvar(II)) {
Diag(NameLoc, diag::warn_synthesized_ivar_access) << II;