/// including its syntax and spelling.
class Form {
public:
- constexpr Form(Syntax SyntaxUsed,
- unsigned SpellingIndex = SpellingNotCalculated)
+ constexpr Form(Syntax SyntaxUsed, unsigned SpellingIndex)
: SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingIndex) {}
constexpr Form(tok::TokenKind)
: SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated) {}
Syntax getSyntax() const { return Syntax(SyntaxUsed); }
unsigned getSpellingIndex() const { return SpellingIndex; }
+ static Form GNU() { return AS_GNU; }
+ static Form CXX11() { return AS_CXX11; }
+ static Form C2x() { return AS_C2x; }
+ static Form Declspec() { return AS_Declspec; }
+ static Form Microsoft() { return AS_Microsoft; }
+ static Form Keyword() { return AS_Keyword; }
+ static Form Pragma() { return AS_Pragma; }
+ static Form ContextSensitiveKeyword() { return AS_ContextSensitiveKeyword; }
+ static Form HLSLSemantic() { return AS_HLSLSemantic; }
+ static Form Implicit() { return AS_Implicit; }
+
private:
+ constexpr Form(Syntax SyntaxUsed)
+ : SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingNotCalculated) {}
+
unsigned SyntaxUsed : 4;
unsigned SpellingIndex : 4;
};
}
ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr,
- nullptr, SourceLocation(), ParsedAttr::AS_GNU,
+ nullptr, SourceLocation(), ParsedAttr::Form::GNU(),
nullptr);
if (HasFunScope)
// If there are multiple decls, then the decl cannot be within the
// function scope.
ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr,
- nullptr, SourceLocation(), ParsedAttr::AS_GNU,
+ nullptr, SourceLocation(), ParsedAttr::Form::GNU(),
nullptr);
}
} else {
if (Tok.isNot(tok::l_paren)) {
Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_GNU);
+ ParsedAttr::Form::GNU());
continue;
}
// Handle "parameterized" attributes
if (!LateAttrs || !isAttributeLateParsed(*AttrName)) {
ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, &EndLoc, nullptr,
- SourceLocation(), ParsedAttr::AS_GNU, D);
+ SourceLocation(), ParsedAttr::Form::GNU(), D);
continue;
}
if (!HasInvalidAccessor)
Attrs.addNewPropertyAttr(AttrName, AttrNameLoc, nullptr, SourceLocation(),
AccessorNames[AK_Get], AccessorNames[AK_Put],
- ParsedAttr::AS_Declspec);
+ ParsedAttr::Form::Declspec());
T.skipToEnd();
return !HasInvalidAccessor;
}
unsigned NumArgs =
ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, nullptr, nullptr,
- SourceLocation(), ParsedAttr::AS_Declspec);
+ SourceLocation(), ParsedAttr::Form::Declspec());
// If this attribute's args were parsed, and it was expected to have
// arguments but none were provided, emit a diagnostic.
if (!AttrHandled)
Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_Declspec);
+ ParsedAttr::Form::Declspec());
}
T.consumeClose();
EndLoc = T.getCloseLocation();
assert(Tok.is(tok::l_paren) && "Not a C++11 attribute argument list");
SourceLocation LParenLoc = Tok.getLocation();
const LangOptions &LO = getLangOpts();
- ParsedAttr::Syntax Syntax =
- LO.CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x;
+ ParsedAttr::Form Form =
+ LO.CPlusPlus ? ParsedAttr::Form::CXX11() : ParsedAttr::Form::C2x();
// Try parsing microsoft attributes
if (getLangOpts().MicrosoftExt || getLangOpts().HLSL) {
if (hasAttribute(AttributeCommonInfo::Syntax::AS_Microsoft, ScopeName,
AttrName, getTargetInfo(), getLangOpts()))
- Syntax = ParsedAttr::AS_Microsoft;
+ Form = ParsedAttr::Form::Microsoft();
}
// If the attribute isn't known, we will not attempt to parse any
// arguments.
- if (Syntax != ParsedAttr::AS_Microsoft &&
+ if (Form.getSyntax() != ParsedAttr::AS_Microsoft &&
!hasAttribute(LO.CPlusPlus ? AttributeCommonInfo::Syntax::AS_CXX11
: AttributeCommonInfo::Syntax::AS_C2x,
ScopeName, AttrName, getTargetInfo(), getLangOpts())) {
// GNU-scoped attributes have some special cases to handle GNU-specific
// behaviors.
ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
- ScopeLoc, Syntax, nullptr);
+ ScopeLoc, Form, nullptr);
return true;
}
// Some Clang-scoped attributes have some special parsing behavior.
if (ScopeName && (ScopeName->isStr("clang") || ScopeName->isStr("_Clang")))
NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc,
- ScopeName, ScopeLoc, Syntax);
+ ScopeName, ScopeLoc, Form);
else
NumArgs = ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
- ScopeName, ScopeLoc, Syntax);
+ ScopeName, ScopeLoc, Form);
if (!Attrs.empty() &&
IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName)) {
AttrName,
SourceRange(ScopeLoc.isValid() ? ScopeLoc : AttrLoc, AttrLoc),
ScopeName, ScopeLoc, nullptr, 0,
- getLangOpts().CPlusPlus ? ParsedAttr::AS_CXX11 : ParsedAttr::AS_C2x);
+ getLangOpts().CPlusPlus ? ParsedAttr::Form::CXX11()
+ : ParsedAttr::Form::C2x());
AttrParsed = true;
}
if (!T.consumeClose()) {
Attrs.addNew(UuidIdent, SourceRange(UuidLoc, T.getCloseLocation()), nullptr,
SourceLocation(), ArgExprs.data(), ArgExprs.size(),
- ParsedAttr::AS_Microsoft);
+ ParsedAttr::Form::Microsoft());
}
}
}
if (!AttrParsed) {
Attrs.addNew(II, NameLoc, nullptr, SourceLocation(), nullptr, 0,
- ParsedAttr::AS_Microsoft);
+ ParsedAttr::Form::Microsoft());
}
}
}
}
Attrs.addNew(II, Loc, nullptr, SourceLocation(), ArgExprs.data(),
- ArgExprs.size(), ParsedAttr::AS_HLSLSemantic);
+ ArgExprs.size(), ParsedAttr::Form::HLSLSemantic());
}
auto getNullabilityAttr = [&](AttributePool &Pool) -> ParsedAttr * {
return Pool.create(P.getNullabilityKeyword(nullability),
SourceRange(nullabilityLoc), nullptr, SourceLocation(),
- nullptr, 0, ParsedAttr::AS_ContextSensitiveKeyword);
+ nullptr, 0, ParsedAttr::Form::ContextSensitiveKeyword());
};
if (D.getNumTypeObjects() > 0) {
if (Tok.isNot(tok::l_paren))
Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
- ParsedAttr::AS_GNU);
+ ParsedAttr::Form::GNU());
else
ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, /*EndLoc=*/nullptr,
/*ScopeName=*/nullptr,
- /*ScopeLoc=*/SourceLocation(), ParsedAttr::AS_GNU,
+ /*ScopeLoc=*/SourceLocation(),
+ ParsedAttr::Form::GNU(),
/*Declarator=*/nullptr);
} while (TryConsumeToken(tok::comma));
ArgsUnion(Hint.ValueExpr)};
TempAttrs.addNew(Hint.PragmaNameLoc->Ident, Hint.Range, nullptr,
Hint.PragmaNameLoc->Loc, ArgHints, 4,
- ParsedAttr::AS_Pragma);
+ ParsedAttr::Form::Pragma());
}
// Get the next statement.
return;
AttributeCommonInfo Info(Ident, SourceRange(Loc),
- AttributeCommonInfo::AS_Pragma);
+ AttributeCommonInfo::Form::Pragma());
D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
}
NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
LookupOrdinaryName);
AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc),
- AttributeCommonInfo::AS_Pragma);
+ AttributeCommonInfo::Form::Pragma());
AsmLabelAttr *Attr = AsmLabelAttr::CreateImplicit(
Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info);
// If we're supposed to infer nullability, do so now.
if (inferNullability && !inferNullabilityInnerOnlyComplete) {
- ParsedAttr::Syntax syntax = inferNullabilityCS
- ? ParsedAttr::AS_ContextSensitiveKeyword
- : ParsedAttr::AS_Keyword;
+ ParsedAttr::Form form = inferNullabilityCS
+ ? ParsedAttr::Form::ContextSensitiveKeyword()
+ : ParsedAttr::Form::Keyword();
ParsedAttr *nullabilityAttr = Pool.create(
S.getNullabilityKeyword(*inferNullability), SourceRange(pointerLoc),
- nullptr, SourceLocation(), nullptr, 0, syntax);
+ nullptr, SourceLocation(), nullptr, 0, form);
attrs.addAtEnd(nullabilityAttr);
ParsedAttr *attr = D.getAttributePool().create(
&S.Context.Idents.get("objc_ownership"), SourceLocation(),
/*scope*/ nullptr, SourceLocation(),
- /*args*/ &Args, 1, ParsedAttr::AS_GNU);
+ /*args*/ &Args, 1, ParsedAttr::Form::GNU());
chunk.getAttrs().addAtEnd(attr);
// TODO: mark whether we did this inference?
}
OS << "NoSemaHandlerAttribute";
if (Spellings.size() == 0) {
- OS << ", AttributeCommonInfo::AS_Implicit";
+ OS << ", AttributeCommonInfo::Form::Implicit()";
} else if (Spellings.size() == 1) {
OS << ", ";
emitFormInitializer(OS, Spellings[0], "0");