From 44802cc435d5122701e4f1a9354381cff4b171c0 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 26 Nov 2008 21:51:07 +0000 Subject: [PATCH] Add some comments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60119 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Parse/Parser.h | 4 ++++ lib/Parse/ParseExpr.cpp | 6 +++++- lib/Parse/Parser.cpp | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 94e3d713d5..f4695af279 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -226,6 +226,10 @@ private: /// 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 17b14bd2a1..66b1d18078 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -424,7 +424,11 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) { 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 ec07b42319..42d95e7f02 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -700,6 +700,15 @@ Parser::ExprResult Parser::ParseSimpleAsm() { /// 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; -- 2.40.0