llvm-project/clang/lib/Sema
Douglas Gregor 0e7dde535d 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>.

llvm-svn: 130082
2011-04-24 05:37:28 +00:00
..
AnalysisBasedWarnings.cpp Simplify the tracking of when to issue a fixit hint, making the helper 2011-04-05 18:27:05 +00:00
AttributeList.cpp Implement ARM pcs attribute. Basically it's another way of calling convention selection (AAPCS or 2011-04-14 20:06:49 +00:00
CMakeLists.txt Teach DelayedDiagnostic to copy its string, rather than hope that the 2011-03-23 15:13:44 +00:00
CodeCompleteConsumer.cpp Implement a new 'availability' attribute, that allows one to specify 2011-03-23 00:50:03 +00:00
DeclSpec.cpp Fix a bunch of major problems with __unknown_anytype and properly test 2011-04-09 22:50:59 +00:00
DelayedDiagnostic.cpp Teach DelayedDiagnostic to copy its string, rather than hope that the 2011-03-23 15:13:44 +00:00
IdentifierResolver.cpp Fix the insertion of label declarations into the identifier chain in 2011-03-24 10:35:39 +00:00
JumpDiagnostics.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
Makefile BUILD_ARCHIVE is the default for libraries, no need to set it. 2010-07-18 00:14:47 +00:00
Sema.cpp At the end of the translation unit, defining a vtable can introduce 2011-04-22 22:25:37 +00:00
SemaAccess.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
SemaAttr.cpp On Mac OS X, the presence of an 'availability' attribute for that 2011-03-26 12:10:19 +00:00
SemaCXXCast.cpp Exhaust the cases. 2011-04-23 01:10:24 +00:00
SemaCXXScopeSpec.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
SemaChecking.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
SemaCodeComplete.cpp When providing code completions of ivar names for a property 2011-04-18 14:40:46 +00:00
SemaDecl.cpp Implement a new identifier-classification scheme where Sema 2011-04-24 05:37:28 +00:00
SemaDeclAttr.cpp "note" location of forward class used as receiver of 2011-04-23 17:27:19 +00:00
SemaDeclCXX.cpp At the end of the translation unit, defining a vtable can introduce 2011-04-22 22:25:37 +00:00
SemaDeclObjC.cpp Diagnose C++ abstract parameters for Objective-C methods. 2011-04-23 02:46:06 +00:00
SemaExceptionSpec.cpp For consistency, change suffix from war_ to warn_ for some Microsoft warnings I introduced lately. 2011-04-22 08:25:24 +00:00
SemaExpr.cpp Implement a new identifier-classification scheme where Sema 2011-04-24 05:37:28 +00:00
SemaExprCXX.cpp Implement basic __is_trivial type-trait support, enough to close PR9472. 2011-04-23 10:47:28 +00:00
SemaExprObjC.cpp "note" location of forward class used as receiver of 2011-04-23 17:27:19 +00:00
SemaInit.cpp Use the ArrayFiller to fill out "holes" in the array initializer due to designated initializers, 2011-04-21 20:03:38 +00:00
SemaLookup.cpp Like the coding standards say, do not use "using namespace std". 2011-04-23 09:06:00 +00:00
SemaObjCProperty.cpp fix a bunch of comment typos found by codespell. Patch by 2011-04-15 05:22:18 +00:00
SemaOverload.cpp In IsUserDefinedConversion try to recover from RequireCompleteType returning true. 2011-04-22 17:45:37 +00:00
SemaStmt.cpp Fix PR9741. The implicit declarations created for range-based for loops weren't being added to the DeclContext (nor were they being marked as implicit). Also, the declarations were being emitted in the wrong order when building the CFG. 2011-04-18 15:49:25 +00:00
SemaTemplate.cpp Implement a new identifier-classification scheme where Sema 2011-04-24 05:37:28 +00:00
SemaTemplateDeduction.cpp Fix PR9488: 'auto' type substitution can fail (for instance, if it creates a reference-to-void type). Don't crash if it does. 2011-03-17 16:11:59 +00:00
SemaTemplateInstantiate.cpp Fixed source range for all DeclaratorDecl's. 2011-03-08 08:55:46 +00:00
SemaTemplateInstantiateDecl.cpp Remove unnecessary const away cast in LateTemplateParserCallback. 2011-04-23 11:52:20 +00:00
SemaTemplateVariadic.cpp Fix a bunch of major problems with __unknown_anytype and properly test 2011-04-09 22:50:59 +00:00
SemaType.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
TargetAttributesSema.cpp Support for C++11 (non-template) alias declarations. 2011-04-15 14:24:37 +00:00
TargetAttributesSema.h Remove Sema.h's dependency on DeclCXX.h. 2010-08-25 07:42:41 +00:00
TreeTransform.h Fix crashing rdar://9122854 & http://llvm.org/PR9461. 2011-04-22 01:18:40 +00:00
TypeLocBuilder.h Remove crash recovery cleanups from TypeLocBuilder. They were a bit error prone, only hit in rare cases. 2011-03-22 01:15:21 +00:00