/// DeclarationNameLoc - Additional source/type location info
/// for a declaration name. Needs a DeclarationName in order
/// to be interpreted correctly.
-struct DeclarationNameLoc {
+class DeclarationNameLoc {
// The source location for identifier stored elsewhere.
// struct {} Identifier;
struct CXXLitOpName CXXLiteralOperatorName;
};
- DeclarationNameLoc(DeclarationName Name);
+ void setNamedTypeLoc(TypeSourceInfo *TInfo) { NamedType.TInfo = TInfo; }
+
+ void setCXXOperatorNameRange(SourceRange Range) {
+ CXXOperatorName.BeginOpNameLoc = Range.getBegin().getRawEncoding();
+ CXXOperatorName.EndOpNameLoc = Range.getEnd().getRawEncoding();
+ }
+ void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
+ CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
+ }
+
+public:
+ DeclarationNameLoc(DeclarationName Name);
// FIXME: this should go away once all DNLocs are properly initialized.
DeclarationNameLoc() { memset((void*) this, 0, sizeof(*this)); }
+
+ /// Returns the source type info. Assumes that the object stores location
+ /// information of a constructor, destructor or conversion operator.
+ TypeSourceInfo *getNamedTypeInfo() const { return NamedType.TInfo; }
+
+ /// Return the beginning location of the getCXXOperatorNameRange() range.
+ SourceLocation getCXXOperatorNameBeginLoc() const {
+ return SourceLocation::getFromRawEncoding(CXXOperatorName.BeginOpNameLoc);
+ }
+
+ /// Return the end location of the getCXXOperatorNameRange() range.
+ SourceLocation getCXXOperatorNameEndLoc() const {
+ return SourceLocation::getFromRawEncoding(CXXOperatorName.EndOpNameLoc);
+ }
+
+ /// Return the range of the operator name (without the operator keyword).
+ /// Assumes that the object stores location information of a (non-literal)
+ /// operator.
+ SourceRange getCXXOperatorNameRange() const {
+ return SourceRange(getCXXOperatorNameBeginLoc(),
+ getCXXOperatorNameEndLoc());
+ }
+
+ /// Return the location of the literal operator name (without the operator
+ /// keyword). Assumes that the object stores location information of a literal
+ /// operator.
+ SourceLocation getCXXLiteralOperatorNameLoc() const {
+ return SourceLocation::getFromRawEncoding(CXXLiteralOperatorName.OpNameLoc);
+ }
+
+ /// Construct location information for a constructor, destructor or conversion
+ /// operator.
+ static DeclarationNameLoc makeNamedTypeLoc(TypeSourceInfo *TInfo) {
+ DeclarationNameLoc DNL;
+ DNL.setNamedTypeLoc(TInfo);
+ return DNL;
+ }
+
+ /// Construct location information for a non-literal C++ operator.
+ static DeclarationNameLoc makeCXXOperatorNameLoc(SourceLocation BeginLoc,
+ SourceLocation EndLoc) {
+ return makeCXXOperatorNameLoc(SourceRange(BeginLoc, EndLoc));
+ }
+
+ /// Construct location information for a non-literal C++ operator.
+ static DeclarationNameLoc makeCXXOperatorNameLoc(SourceRange Range) {
+ DeclarationNameLoc DNL;
+ DNL.setCXXOperatorNameRange(Range);
+ return DNL;
+ }
+
+ /// Construct location information for a literal C++ operator.
+ static DeclarationNameLoc makeCXXLiteralOperatorNameLoc(SourceLocation Loc) {
+ DeclarationNameLoc DNL;
+ DNL.setCXXLiteralOperatorNameLoc(Loc);
+ return DNL;
+ }
};
/// DeclarationNameInfo - A collector data type for bundling together
void setLoc(SourceLocation L) { NameLoc = L; }
const DeclarationNameLoc &getInfo() const { return LocInfo; }
- DeclarationNameLoc &getInfo() { return LocInfo; }
void setInfo(const DeclarationNameLoc &Info) { LocInfo = Info; }
/// getNamedTypeInfo - Returns the source type info associated to
Name.getNameKind() != DeclarationName::CXXDestructorName &&
Name.getNameKind() != DeclarationName::CXXConversionFunctionName)
return nullptr;
- return LocInfo.NamedType.TInfo;
+ return LocInfo.getNamedTypeInfo();
}
/// setNamedTypeInfo - Sets the source type info associated to
assert(Name.getNameKind() == DeclarationName::CXXConstructorName ||
Name.getNameKind() == DeclarationName::CXXDestructorName ||
Name.getNameKind() == DeclarationName::CXXConversionFunctionName);
- LocInfo.NamedType.TInfo = TInfo;
+ LocInfo = DeclarationNameLoc::makeNamedTypeLoc(TInfo);
}
/// getCXXOperatorNameRange - Gets the range of the operator name
SourceRange getCXXOperatorNameRange() const {
if (Name.getNameKind() != DeclarationName::CXXOperatorName)
return SourceRange();
- return SourceRange(
- SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.BeginOpNameLoc),
- SourceLocation::getFromRawEncoding(LocInfo.CXXOperatorName.EndOpNameLoc)
- );
+ return LocInfo.getCXXOperatorNameRange();
}
/// setCXXOperatorNameRange - Sets the range of the operator name
/// (without the operator keyword). Assumes it is a C++ operator.
void setCXXOperatorNameRange(SourceRange R) {
assert(Name.getNameKind() == DeclarationName::CXXOperatorName);
- LocInfo.CXXOperatorName.BeginOpNameLoc = R.getBegin().getRawEncoding();
- LocInfo.CXXOperatorName.EndOpNameLoc = R.getEnd().getRawEncoding();
+ LocInfo = DeclarationNameLoc::makeCXXOperatorNameLoc(R);
}
/// getCXXLiteralOperatorNameLoc - Returns the location of the literal
SourceLocation getCXXLiteralOperatorNameLoc() const {
if (Name.getNameKind() != DeclarationName::CXXLiteralOperatorName)
return SourceLocation();
- return SourceLocation::
- getFromRawEncoding(LocInfo.CXXLiteralOperatorName.OpNameLoc);
+ return LocInfo.getCXXLiteralOperatorNameLoc();
}
/// setCXXLiteralOperatorNameLoc - Sets the location of the literal
/// Assumes it is a literal operator.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc) {
assert(Name.getNameKind() == DeclarationName::CXXLiteralOperatorName);
- LocInfo.CXXLiteralOperatorName.OpNameLoc = Loc.getRawEncoding();
+ LocInfo = DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(Loc);
}
/// Determine whether this name involves a template parameter.
} else {
DName = DeclarationNames.getCXXOperatorName(DTN->getOperator());
// DNInfo work in progress: FIXME: source locations?
- DeclarationNameLoc DNLoc;
- DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding();
- DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding();
+ DeclarationNameLoc DNLoc =
+ DeclarationNameLoc::makeCXXOperatorNameLoc(SourceRange());
return DeclarationNameInfo(DName, NameLoc, DNLoc);
}
}
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- NamedType.TInfo = nullptr;
+ setNamedTypeLoc(nullptr);
break;
case DeclarationName::CXXOperatorName:
- CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding();
- CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding();
+ setCXXOperatorNameRange(SourceRange());
break;
case DeclarationName::CXXLiteralOperatorName:
- CXXLiteralOperatorName.OpNameLoc = SourceLocation().getRawEncoding();
+ setCXXLiteralOperatorNameLoc(SourceLocation());
break;
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::ObjCOneArgSelector:
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
+ if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo())
return TInfo->getType()->containsUnexpandedParameterPack();
return Name.getCXXNameType()->containsUnexpandedParameterPack();
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
+ if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo())
return TInfo->getType()->isInstantiationDependentType();
return Name.getCXXNameType()->isInstantiationDependentType();
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo) {
+ if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo()) {
if (Name.getNameKind() == DeclarationName::CXXDestructorName)
OS << '~';
else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
case DeclarationName::CXXDeductionGuideName:
return NameLoc;
- case DeclarationName::CXXOperatorName: {
- unsigned raw = LocInfo.CXXOperatorName.EndOpNameLoc;
- return SourceLocation::getFromRawEncoding(raw);
- }
+ case DeclarationName::CXXOperatorName:
+ return LocInfo.getCXXOperatorNameEndLoc();
- case DeclarationName::CXXLiteralOperatorName: {
- unsigned raw = LocInfo.CXXLiteralOperatorName.OpNameLoc;
- return SourceLocation::getFromRawEncoding(raw);
- }
+ case DeclarationName::CXXLiteralOperatorName:
+ return LocInfo.getCXXLiteralOperatorNameLoc();
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- if (TypeSourceInfo *TInfo = LocInfo.NamedType.TInfo)
+ if (TypeSourceInfo *TInfo = LocInfo.getNamedTypeInfo())
return TInfo->getTypeLoc().getEndLoc();
else
return NameLoc;
case UnqualifiedIdKind::IK_OperatorFunctionId:
NameInfo.setName(Context.DeclarationNames.getCXXOperatorName(
Name.OperatorFunctionId.Operator));
- NameInfo.getInfo().CXXOperatorName.BeginOpNameLoc =
- Name.OperatorFunctionId.SymbolLocations[0].getRawEncoding();
- NameInfo.getInfo().CXXOperatorName.EndOpNameLoc
- = Name.EndLocation.getRawEncoding();
+ NameInfo.setCXXOperatorNameRange(SourceRange(
+ Name.OperatorFunctionId.SymbolLocations[0], Name.EndLocation));
return NameInfo;
case UnqualifiedIdKind::IK_LiteralOperatorId:
// trailing-return-type respectively.
DeclarationName MethodName
= Context.DeclarationNames.getCXXOperatorName(OO_Call);
- DeclarationNameLoc MethodNameLoc;
- MethodNameLoc.CXXOperatorName.BeginOpNameLoc
- = IntroducerRange.getBegin().getRawEncoding();
- MethodNameLoc.CXXOperatorName.EndOpNameLoc
- = IntroducerRange.getEnd().getRawEncoding();
+ DeclarationNameLoc MethodNameLoc =
+ DeclarationNameLoc::makeCXXOperatorNameLoc(IntroducerRange);
CXXMethodDecl *Method = CXXMethodDecl::Create(
Context, Class, EndLoc,
DeclarationNameInfo(MethodName, IntroducerRange.getBegin(),
DeclarationName ConversionName
= S.Context.DeclarationNames.getCXXConversionFunctionName(
S.Context.getCanonicalType(PtrToFunctionTy));
- DeclarationNameLoc ConvNameLoc;
// Construct a TypeSourceInfo for the conversion function, and wire
// all the parameters appropriately for the FunctionProtoTypeLoc
// so that everything works during transformation/instantiation of
// operators ParmVarDecls below.
TypeSourceInfo *ConvNamePtrToFunctionTSI =
S.Context.getTrivialTypeSourceInfo(PtrToFunctionTy, Loc);
- ConvNameLoc.NamedType.TInfo = ConvNamePtrToFunctionTSI;
+ DeclarationNameLoc ConvNameLoc =
+ DeclarationNameLoc::makeNamedTypeLoc(ConvNamePtrToFunctionTSI);
// The conversion function is a conversion to a pointer-to-function.
TypeSourceInfo *ConvTSI = S.Context.getTrivialTypeSourceInfo(ConvTy, Loc);
DeclarationName Name
= S.Context.DeclarationNames.getCXXConversionFunctionName(
S.Context.getCanonicalType(BlockPtrTy));
- DeclarationNameLoc NameLoc;
- NameLoc.NamedType.TInfo = S.Context.getTrivialTypeSourceInfo(BlockPtrTy, Loc);
+ DeclarationNameLoc NameLoc = DeclarationNameLoc::makeNamedTypeLoc(
+ S.Context.getTrivialTypeSourceInfo(BlockPtrTy, Loc));
CXXConversionDecl *Conversion = CXXConversionDecl::Create(
S.Context, Class, Loc, DeclarationNameInfo(Name, Loc, NameLoc), ConvTy,
S.Context.getTrivialTypeSourceInfo(ConvTy, Loc),
SourceLocation RBrace;
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
- DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
- LBrace = SourceLocation::getFromRawEncoding(
- NameLoc.CXXOperatorName.BeginOpNameLoc);
- RBrace = SourceLocation::getFromRawEncoding(
- NameLoc.CXXOperatorName.EndOpNameLoc);
+ DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
+ LBrace = NameLoc.getCXXOperatorNameBeginLoc();
+ RBrace = NameLoc.getCXXOperatorNameEndLoc();
} else {
LBrace = Callee->getBeginLoc();
RBrace = OpLoc;
DeclarationNameLoc
ASTRecordReader::readDeclarationNameLoc(DeclarationName Name) {
- DeclarationNameLoc DNLoc;
switch (Name.getNameKind()) {
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- DNLoc.NamedType.TInfo = readTypeSourceInfo();
- break;
+ return DeclarationNameLoc::makeNamedTypeLoc(readTypeSourceInfo());
case DeclarationName::CXXOperatorName:
- DNLoc.CXXOperatorName.BeginOpNameLoc
- = readSourceLocation().getRawEncoding();
- DNLoc.CXXOperatorName.EndOpNameLoc
- = readSourceLocation().getRawEncoding();
- break;
+ return DeclarationNameLoc::makeCXXOperatorNameLoc(readSourceRange());
case DeclarationName::CXXLiteralOperatorName:
- DNLoc.CXXLiteralOperatorName.OpNameLoc
- = readSourceLocation().getRawEncoding();
- break;
+ return DeclarationNameLoc::makeCXXLiteralOperatorNameLoc(
+ readSourceLocation());
case DeclarationName::Identifier:
case DeclarationName::ObjCZeroArgSelector:
case DeclarationName::CXXDeductionGuideName:
break;
}
- return DNLoc;
+ return DeclarationNameLoc();
}
DeclarationNameInfo ASTRecordReader::readDeclarationNameInfo() {
case DeclarationName::CXXConstructorName:
case DeclarationName::CXXDestructorName:
case DeclarationName::CXXConversionFunctionName:
- AddTypeSourceInfo(DNLoc.NamedType.TInfo);
+ AddTypeSourceInfo(DNLoc.getNamedTypeInfo());
break;
case DeclarationName::CXXOperatorName:
- AddSourceLocation(SourceLocation::getFromRawEncoding(
- DNLoc.CXXOperatorName.BeginOpNameLoc));
- AddSourceLocation(
- SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc));
+ AddSourceRange(DNLoc.getCXXOperatorNameRange());
break;
case DeclarationName::CXXLiteralOperatorName:
- AddSourceLocation(SourceLocation::getFromRawEncoding(
- DNLoc.CXXLiteralOperatorName.OpNameLoc));
+ AddSourceLocation(DNLoc.getCXXLiteralOperatorNameLoc());
break;
case DeclarationName::Identifier:
Pieces.push_back(*TemplateArgsLoc);
if (Kind == DeclarationName::CXXOperatorName) {
- Pieces.push_back(SourceLocation::getFromRawEncoding(
- NI.getInfo().CXXOperatorName.BeginOpNameLoc));
- Pieces.push_back(SourceLocation::getFromRawEncoding(
- NI.getInfo().CXXOperatorName.EndOpNameLoc));
+ Pieces.push_back(NI.getInfo().getCXXOperatorNameBeginLoc());
+ Pieces.push_back(NI.getInfo().getCXXOperatorNameEndLoc());
}
if (WantSinglePiece) {