#include "clang/Parse/Parser.h"
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Scope.h"
#include "AstGuard.h"
#include "ExtensionRAIIObject.h"
using namespace clang;
Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context,
SourceLocation &DeclEnd) {
assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
SourceLocation NamespaceLoc = ConsumeToken();
SourceLocation IdentLoc;
IdentifierInfo *Ident = 0;
if (Tok.is(tok::identifier)) {
Ident = Tok.getIdentifierInfo();
IdentLoc = ConsumeToken(); }
Action::AttrTy *AttrList = 0;
if (Tok.is(tok::kw___attribute))
AttrList = ParseAttributes();
if (Tok.is(tok::equal))
return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
if (Tok.isNot(tok::l_brace)) {
Diag(Tok, Ident ? diag::err_expected_lbrace :
diag::err_expected_ident_lbrace);
return DeclPtrTy();
}
SourceLocation LBrace = ConsumeBrace();
ParseScope NamespaceScope(this, Scope::DeclScope);
DeclPtrTy NamespcDecl =
Actions.ActOnStartNamespaceDef(CurScope, IdentLoc, Ident, LBrace);
PrettyStackTraceActionsDecl CrashInfo(NamespcDecl, NamespaceLoc, Actions,
PP.getSourceManager(),
"parsing namespace");
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof))
ParseExternalDeclaration();
NamespaceScope.Exit();
SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBrace);
Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc);
DeclEnd = RBraceLoc;
return NamespcDecl;
}
Parser::DeclPtrTy Parser::ParseNamespaceAlias(SourceLocation NamespaceLoc,
SourceLocation AliasLoc,
IdentifierInfo *Alias,
SourceLocation &DeclEnd) {
assert(Tok.is(tok::equal) && "Not equal token");
ConsumeToken();
CXXScopeSpec SS;
ParseOptionalCXXScopeSpecifier(SS);
if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_namespace_name);
SkipUntil(tok::semi);
return DeclPtrTy();
}
IdentifierInfo *Ident = Tok.getIdentifierInfo();
SourceLocation IdentLoc = ConsumeToken();
DeclEnd = Tok.getLocation();
ExpectAndConsume(tok::semi, diag::err_expected_semi_after_namespace_name,
"", tok::semi);
return Actions.ActOnNamespaceAliasDef(CurScope, NamespaceLoc, AliasLoc, Alias,
SS, IdentLoc, Ident);
}
Parser::DeclPtrTy Parser::ParseLinkage(unsigned Context) {
assert(Tok.is(tok::string_literal) && "Not a string literal!");
llvm::SmallVector<char, 8> LangBuffer;
LangBuffer.resize(Tok.getLength());
const char *LangBufPtr = &LangBuffer[0];
unsigned StrSize = PP.getSpelling(Tok, LangBufPtr);
SourceLocation Loc = ConsumeStringToken();
ParseScope LinkageScope(this, Scope::DeclScope);
DeclPtrTy LinkageSpec
= Actions.ActOnStartLinkageSpecification(CurScope,
SourceLocation(),
Loc, LangBufPtr, StrSize,
Tok.is(tok::l_brace)? Tok.getLocation()
: SourceLocation());
if (Tok.isNot(tok::l_brace)) {
ParseDeclarationOrFunctionDefinition();
return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec,
SourceLocation());
}
SourceLocation LBrace = ConsumeBrace();
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
ParseExternalDeclaration();
}
SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, RBrace);
}
Parser::DeclPtrTy Parser::ParseUsingDirectiveOrDeclaration(unsigned Context,
SourceLocation &DeclEnd) {
assert(Tok.is(tok::kw_using) && "Not using token");
SourceLocation UsingLoc = ConsumeToken();
if (Tok.is(tok::kw_namespace))
return ParseUsingDirective(Context, UsingLoc, DeclEnd);
return ParseUsingDeclaration(Context, UsingLoc, DeclEnd);
}
Parser::DeclPtrTy Parser::ParseUsingDirective(unsigned Context,
SourceLocation UsingLoc,
SourceLocation &DeclEnd) {
assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token");
SourceLocation NamespcLoc = ConsumeToken();
CXXScopeSpec SS;
ParseOptionalCXXScopeSpecifier(SS);
AttributeList *AttrList = 0;
IdentifierInfo *NamespcName = 0;
SourceLocation IdentLoc = SourceLocation();
if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_namespace_name);
SkipUntil(tok::semi);
return DeclPtrTy();
}
NamespcName = Tok.getIdentifierInfo();
IdentLoc = ConsumeToken();
if (Tok.is(tok::kw___attribute))
AttrList = ParseAttributes();
DeclEnd = Tok.getLocation();
ExpectAndConsume(tok::semi,
AttrList ? diag::err_expected_semi_after_attribute_list :
diag::err_expected_semi_after_namespace_name, "", tok::semi);
return Actions.ActOnUsingDirective(CurScope, UsingLoc, NamespcLoc, SS,
IdentLoc, NamespcName, AttrList);
}
Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context,
SourceLocation UsingLoc,
SourceLocation &DeclEnd) {
assert(false && "Not implemented");
return DeclPtrTy();
}
Parser::DeclPtrTy Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
assert(Tok.is(tok::kw_static_assert) && "Not a static_assert declaration");
SourceLocation StaticAssertLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren)) {
Diag(Tok, diag::err_expected_lparen);
return DeclPtrTy();
}
SourceLocation LParenLoc = ConsumeParen();
OwningExprResult AssertExpr(ParseConstantExpression());
if (AssertExpr.isInvalid()) {
SkipUntil(tok::semi);
return DeclPtrTy();
}
if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", tok::semi))
return DeclPtrTy();
if (Tok.isNot(tok::string_literal)) {
Diag(Tok, diag::err_expected_string_literal);
SkipUntil(tok::semi);
return DeclPtrTy();
}
OwningExprResult AssertMessage(ParseStringLiteralExpression());
if (AssertMessage.isInvalid())
return DeclPtrTy();
MatchRHSPunctuation(tok::r_paren, LParenLoc);
DeclEnd = Tok.getLocation();
ExpectAndConsume(tok::semi, diag::err_expected_semi_after_static_assert);
return Actions.ActOnStaticAssertDeclaration(StaticAssertLoc, move(AssertExpr),
move(AssertMessage));
}
Parser::TypeResult Parser::ParseClassName(SourceLocation &EndLocation,
const CXXScopeSpec *SS) {
if (Tok.is(tok::annot_template_id)) {
TemplateIdAnnotation *TemplateId
= static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
if (TemplateId->Kind == TNK_Type_template) {
AnnotateTemplateIdTokenAsType(SS);
assert(Tok.is(tok::annot_typename) && "template-id -> type failed");
TypeTy *Type = Tok.getAnnotationValue();
EndLocation = Tok.getAnnotationEndLoc();
ConsumeToken();
if (Type)
return Type;
return true;
}
}
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_class_name);
return true;
}
TypeTy *Type = Actions.getTypeName(*Tok.getIdentifierInfo(),
Tok.getLocation(), CurScope, SS);
if (!Type) {
Diag(Tok, diag::err_expected_class_name);
return true;
}
EndLocation = ConsumeToken();
return Type;
}
void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
SourceLocation StartLoc, DeclSpec &DS,
TemplateParameterLists *TemplateParams,
AccessSpecifier AS) {
DeclSpec::TST TagType;
if (TagTokKind == tok::kw_struct)
TagType = DeclSpec::TST_struct;
else if (TagTokKind == tok::kw_class)
TagType = DeclSpec::TST_class;
else {
assert(TagTokKind == tok::kw_union && "Not a class specifier");
TagType = DeclSpec::TST_union;
}
AttributeList *Attr = 0;
if (Tok.is(tok::kw___attribute))
Attr = ParseAttributes();
if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft)
FuzzyParseMicrosoftDeclSpec();
CXXScopeSpec SS;
if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS))
if (Tok.isNot(tok::identifier) && Tok.isNot(tok::annot_template_id))
Diag(Tok, diag::err_expected_ident);
IdentifierInfo *Name = 0;
SourceLocation NameLoc;
TemplateIdAnnotation *TemplateId = 0;
if (Tok.is(tok::identifier)) {
Name = Tok.getIdentifierInfo();
NameLoc = ConsumeToken();
} else if (Tok.is(tok::annot_template_id)) {
TemplateId = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
NameLoc = ConsumeToken();
if (TemplateId->Kind != TNK_Type_template) {
SourceRange Range(NameLoc);
if (SS.isNotEmpty())
Range.setBegin(SS.getBeginLoc());
Diag(TemplateId->LAngleLoc, diag::err_template_spec_syntax_non_template)
<< Name << static_cast<int>(TemplateId->Kind) << Range;
DS.SetTypeSpecError();
SkipUntil(tok::semi, false, true);
TemplateId->Destroy();
return;
}
}
Action::TagKind TK;
if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon)))
TK = Action::TK_Definition;
else if (Tok.is(tok::semi))
TK = Action::TK_Declaration;
else
TK = Action::TK_Reference;
if (!Name && !TemplateId && TK != Action::TK_Definition) {
Diag(StartLoc, diag::err_anon_type_definition)
<< DeclSpec::getSpecifierName(TagType);
SkipUntil(tok::comma, true);
if (TemplateId)
TemplateId->Destroy();
return;
}
Action::DeclResult TagOrTempResult;
if (TemplateId && TK != Action::TK_Reference) {
ASTTemplateArgsPtr TemplateArgsPtr(Actions,
TemplateId->getTemplateArgs(),
TemplateId->getTemplateArgIsType(),
TemplateId->NumArgs);
TagOrTempResult
= Actions.ActOnClassTemplateSpecialization(CurScope, TagType, TK,
StartLoc, SS,
TemplateTy::make(TemplateId->Template),
TemplateId->TemplateNameLoc,
TemplateId->LAngleLoc,
TemplateArgsPtr,
TemplateId->getTemplateArgLocations(),
TemplateId->RAngleLoc,
Attr,
Action::MultiTemplateParamsArg(Actions,
TemplateParams? &(*TemplateParams)[0] : 0,
TemplateParams? TemplateParams->size() : 0));
TemplateId->Destroy();
} else if (TemplateParams && TK != Action::TK_Reference)
TagOrTempResult = Actions.ActOnClassTemplate(CurScope, TagType, TK,
StartLoc, SS, Name, NameLoc,
Attr,
Action::MultiTemplateParamsArg(Actions,
&(*TemplateParams)[0],
TemplateParams->size()),
AS);
else
TagOrTempResult = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, Name,
NameLoc, Attr, AS);
if (getLang().CPlusPlus && Tok.is(tok::colon))
ParseBaseClause(TagOrTempResult.get());
if (Tok.is(tok::l_brace))
if (getLang().CPlusPlus)
ParseCXXMemberSpecification(StartLoc, TagType, TagOrTempResult.get());
else
ParseStructUnionBody(StartLoc, TagType, TagOrTempResult.get());
else if (TK == Action::TK_Definition) {
Diag(Tok, diag::err_expected_lbrace);
}
const char *PrevSpec = 0;
if (TagOrTempResult.isInvalid())
DS.SetTypeSpecError();
else if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec,
TagOrTempResult.get().getAs<void>()))
Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
}
void Parser::ParseBaseClause(DeclPtrTy ClassDecl) {
assert(Tok.is(tok::colon) && "Not a base clause");
ConsumeToken();
llvm::SmallVector<BaseTy *, 8> BaseInfo;
while (true) {
BaseResult Result = ParseBaseSpecifier(ClassDecl);
if (Result.isInvalid()) {
SkipUntil(tok::comma, tok::l_brace, true, true);
} else {
BaseInfo.push_back(Result.get());
}
if (Tok.isNot(tok::comma)) break;
ConsumeToken();
}
Actions.ActOnBaseSpecifiers(ClassDecl, &BaseInfo[0], BaseInfo.size());
}
Parser::BaseResult Parser::ParseBaseSpecifier(DeclPtrTy ClassDecl) {
bool IsVirtual = false;
SourceLocation StartLoc = Tok.getLocation();
if (Tok.is(tok::kw_virtual)) {
ConsumeToken();
IsVirtual = true;
}
AccessSpecifier Access = getAccessSpecifierIfPresent();
if (Access)
ConsumeToken();
if (Tok.is(tok::kw_virtual)) {
SourceLocation VirtualLoc = ConsumeToken();
if (IsVirtual) {
Diag(VirtualLoc, diag::err_dup_virtual)
<< CodeModificationHint::CreateRemoval(SourceRange(VirtualLoc));
}
IsVirtual = true;
}
CXXScopeSpec SS;
ParseOptionalCXXScopeSpecifier(SS);
SourceLocation BaseLoc = Tok.getLocation();
SourceLocation EndLocation;
TypeResult BaseType = ParseClassName(EndLocation, &SS);
if (BaseType.isInvalid())
return true;
SourceRange Range(StartLoc, EndLocation);
return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access,
BaseType.get(), BaseLoc);
}
AccessSpecifier Parser::getAccessSpecifierIfPresent() const
{
switch (Tok.getKind()) {
default: return AS_none;
case tok::kw_private: return AS_private;
case tok::kw_protected: return AS_protected;
case tok::kw_public: return AS_public;
}
}
void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
if (Tok.is(tok::kw_static_assert)) {
SourceLocation DeclEnd;
ParseStaticAssertDeclaration(DeclEnd);
return;
}
if (Tok.is(tok::kw_template)) {
SourceLocation DeclEnd;
ParseTemplateDeclarationOrSpecialization(Declarator::MemberContext, DeclEnd,
AS);
return;
}
if (Tok.is(tok::kw___extension__)) {
ExtensionRAIIObject O(Diags); ConsumeToken();
return ParseCXXClassMemberDeclaration(AS);
}
SourceLocation DSStart = Tok.getLocation();
DeclSpec DS;
ParseDeclarationSpecifiers(DS, 0, AS);
if (Tok.is(tok::semi)) {
ConsumeToken();
switch (DS.getTypeSpecType()) {
case DeclSpec::TST_struct:
case DeclSpec::TST_union:
case DeclSpec::TST_class:
case DeclSpec::TST_enum:
Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
return;
default:
Diag(DSStart, diag::err_no_declarators);
return;
}
}
Declarator DeclaratorInfo(DS, Declarator::MemberContext);
if (Tok.isNot(tok::colon)) {
ParseDeclarator(DeclaratorInfo);
if (!DeclaratorInfo.hasName()) {
SkipUntil(tok::r_brace, true);
if (Tok.is(tok::semi))
ConsumeToken();
return;
}
if (Tok.is(tok::l_brace)
|| (DeclaratorInfo.isFunctionDeclarator() &&
(Tok.is(tok::colon) || Tok.is(tok::kw_try)))) {
if (!DeclaratorInfo.isFunctionDeclarator()) {
Diag(Tok, diag::err_func_def_no_params);
ConsumeBrace();
SkipUntil(tok::r_brace, true);
return;
}
if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
Diag(Tok, diag::err_function_declared_typedef);
ConsumeBrace();
SkipUntil(tok::r_brace, true);
return;
}
ParseCXXInlineMethodDef(AS, DeclaratorInfo);
return;
}
}
llvm::SmallVector<DeclPtrTy, 8> DeclsInGroup;
OwningExprResult BitfieldSize(Actions);
OwningExprResult Init(Actions);
bool Deleted = false;
while (1) {
if (Tok.is(tok::colon)) {
ConsumeToken();
BitfieldSize = ParseConstantExpression();
if (BitfieldSize.isInvalid())
SkipUntil(tok::comma, true, true);
}
if (Tok.is(tok::equal)) {
ConsumeToken();
if (getLang().CPlusPlus0x && Tok.is(tok::kw_delete)) {
ConsumeToken();
Deleted = true;
} else {
Init = ParseInitializer();
if (Init.isInvalid())
SkipUntil(tok::comma, true, true);
}
}
if (Tok.is(tok::kw___attribute)) {
SourceLocation Loc;
AttributeList *AttrList = ParseAttributes(&Loc);
DeclaratorInfo.AddAttributes(AttrList, Loc);
}
DeclPtrTy ThisDecl = Actions.ActOnCXXMemberDeclarator(CurScope, AS,
DeclaratorInfo,
BitfieldSize.release(),
Init.release(),
Deleted);
if (ThisDecl)
DeclsInGroup.push_back(ThisDecl);
if (DeclaratorInfo.isFunctionDeclarator() &&
DeclaratorInfo.getDeclSpec().getStorageClassSpec()
!= DeclSpec::SCS_typedef) {
LateParsedMethodDeclaration *LateMethod = 0;
DeclaratorChunk::FunctionTypeInfo &FTI
= DeclaratorInfo.getTypeObject(0).Fun;
for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
if (!LateMethod) {
getCurTopClassStack().MethodDecls.push_back(
LateParsedMethodDeclaration(ThisDecl));
LateMethod = &getCurTopClassStack().MethodDecls.back();
LateMethod->DefaultArgs.reserve(FTI.NumArgs);
for (unsigned I = 0; I < ParamIdx; ++I)
LateMethod->DefaultArgs.push_back(
LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param));
}
LateMethod->DefaultArgs.push_back(
LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
FTI.ArgInfo[ParamIdx].DefaultArgTokens));
}
}
}
if (Tok.isNot(tok::comma))
break;
ConsumeToken();
DeclaratorInfo.clear();
BitfieldSize = 0;
Init = 0;
Deleted = false;
if (Tok.is(tok::kw___attribute)) {
SourceLocation Loc;
AttributeList *AttrList = ParseAttributes(&Loc);
DeclaratorInfo.AddAttributes(AttrList, Loc);
}
if (Tok.isNot(tok::colon))
ParseDeclarator(DeclaratorInfo);
}
if (Tok.is(tok::semi)) {
ConsumeToken();
Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
DeclsInGroup.size());
return;
}
Diag(Tok, diag::err_expected_semi_decl_list);
SkipUntil(tok::r_brace, true, true);
if (Tok.is(tok::semi))
ConsumeToken();
return;
}
void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
unsigned TagType, DeclPtrTy TagDecl) {
assert((TagType == DeclSpec::TST_struct ||
TagType == DeclSpec::TST_union ||
TagType == DeclSpec::TST_class) && "Invalid TagType!");
PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions,
PP.getSourceManager(),
"parsing struct/union/class body");
SourceLocation LBraceLoc = ConsumeBrace();
if (!CurScope->isClassScope() && CurScope->isInCXXInlineMethodScope()) {
PushTopClassStack();
}
ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope);
if (TagDecl)
Actions.ActOnTagStartDefinition(CurScope, TagDecl);
else {
SkipUntil(tok::r_brace, false, false);
return;
}
AccessSpecifier CurAS;
if (TagType == DeclSpec::TST_class)
CurAS = AS_private;
else
CurAS = AS_public;
while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
if (Tok.is(tok::semi)) {
Diag(Tok, diag::ext_extra_struct_semi);
ConsumeToken();
continue;
}
AccessSpecifier AS = getAccessSpecifierIfPresent();
if (AS != AS_none) {
CurAS = AS;
ConsumeToken();
ExpectAndConsume(tok::colon, diag::err_expected_colon);
continue;
}
ParseCXXClassMemberDeclaration(CurAS);
}
SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
AttributeList *AttrList = 0;
if (Tok.is(tok::kw___attribute))
AttrList = ParseAttributes();
Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl,
LBraceLoc, RBraceLoc);
if (!CurScope->getParent()->isClassScope()) {
ParseLexedMethodDeclarations();
ParseLexedMethodDefs();
assert((CurScope->isInCXXInlineMethodScope() ||
TopClassStacks.size() == 1) &&
"MethodLexers not getting popped properly!");
if (CurScope->isInCXXInlineMethodScope())
PopTopClassStack();
}
ClassScope.Exit();
Actions.ActOnTagFinishDefinition(CurScope, TagDecl);
}
void Parser::ParseConstructorInitializer(DeclPtrTy ConstructorDecl) {
assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'");
SourceLocation ColonLoc = ConsumeToken();
llvm::SmallVector<MemInitTy*, 4> MemInitializers;
do {
MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
if (!MemInit.isInvalid())
MemInitializers.push_back(MemInit.get());
if (Tok.is(tok::comma))
ConsumeToken();
else if (Tok.is(tok::l_brace))
break;
else {
Diag(Tok.getLocation(), diag::err_expected_lbrace_or_comma);
SkipUntil(tok::l_brace, true, true);
break;
}
} while (true);
Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc,
&MemInitializers[0], MemInitializers.size());
}
Parser::MemInitResult Parser::ParseMemInitializer(DeclPtrTy ConstructorDecl) {
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_member_or_base_name);
return true;
}
IdentifierInfo *II = Tok.getIdentifierInfo();
SourceLocation IdLoc = ConsumeToken();
if (Tok.isNot(tok::l_paren)) {
Diag(Tok, diag::err_expected_lparen);
return true;
}
SourceLocation LParenLoc = ConsumeParen();
ExprVector ArgExprs(Actions);
CommaLocsTy CommaLocs;
if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
SkipUntil(tok::r_paren);
return true;
}
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
return Actions.ActOnMemInitializer(ConstructorDecl, CurScope, II, IdLoc,
LParenLoc, ArgExprs.take(),
ArgExprs.size(), &CommaLocs[0], RParenLoc);
}
bool Parser::ParseExceptionSpecification(SourceLocation &EndLoc,
std::vector<TypeTy*> &Exceptions,
bool &hasAnyExceptionSpec) {
assert(Tok.is(tok::kw_throw) && "expected throw");
SourceLocation ThrowLoc = ConsumeToken();
if (!Tok.is(tok::l_paren)) {
return Diag(Tok, diag::err_expected_lparen_after) << "throw";
}
SourceLocation LParenLoc = ConsumeParen();
if (Tok.is(tok::ellipsis)) {
hasAnyExceptionSpec = true;
SourceLocation EllipsisLoc = ConsumeToken();
if (!getLang().Microsoft)
Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
return false;
}
while (Tok.isNot(tok::r_paren)) {
TypeResult Res(ParseTypeName());
if (!Res.isInvalid())
Exceptions.push_back(Res.get());
if (Tok.is(tok::comma))
ConsumeToken();
else
break;
}
EndLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
return false;
}