Add some comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60119 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 94e3d71..f4695af 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -226,6 +226,10 @@
/// This simplifies handling of C++ scope specifiers and allows efficient
/// backtracking without the need to re-parse and resolve nested-names and
/// typenames.
+ /// It will mainly be called when we expect to treat identifiers as typenames
+ /// (if they are typenames). For example, in C we do not expect identifiers
+ /// inside expressions to be treated as typenames so it will not be called
+ /// for expressions in C.
void TryAnnotateTypeOrScopeToken();
/// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 17b14bd..66b1d18 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -424,7 +424,11 @@
Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) {
if (getLang().CPlusPlus) {
// Annotate typenames and C++ scope specifiers.
- // Used only in C++; in C let the typedef name be handled as an identifier.
+ // Used only in C++, where the typename can be considered as a functional
+ // style cast ("int(1)").
+ // In C we don't expect identifiers to be treated as typenames; if it's a
+ // typedef name, let it be handled as an identifier and
+ // Actions.ActOnIdentifierExpr will emit the proper diagnostic.
TryAnnotateTypeOrScopeToken();
}
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index ec07b42..42d95e7 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -700,6 +700,15 @@
/// This simplifies handling of C++ scope specifiers and allows efficient
/// backtracking without the need to re-parse and resolve nested-names and
/// typenames.
+/// It will mainly be called when we expect to treat identifiers as typenames
+/// (if they are typenames). For example, in C we do not expect identifiers
+/// inside expressions to be treated as typenames so it will not be called
+/// for expressions in C.
+/// The benefit for C/ObjC is that a typename will be annotated and
+/// Actions.isTypeName will not be needed to be called again (e.g. isTypeName
+/// will not be called twice, once to check whether we have a declaration
+/// specifier, and another one to get the actual type inside
+/// ParseDeclarationSpecifiers).
void Parser::TryAnnotateTypeOrScopeToken() {
if (Tok.is(tok::annot_qualtypename) || Tok.is(tok::annot_cxxscope))
return;