Skip to content

Commit

Permalink
Merge branch 'attrCommonInfo' into p3385
Browse files Browse the repository at this point in the history
  • Loading branch information
zebullon committed Oct 14, 2024
2 parents c6b54dd + 75be9e4 commit ff97c21
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
4 changes: 2 additions & 2 deletions clang/include/clang/AST/APValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ template <typename T> class BasicReaderBase;

class AddrLabelExpr;
class ASTContext;
class AttributeCommonInfo;
class CharUnits;
class CXX26AnnotationAttr;
class CXXRecordDecl;
Expand All @@ -40,7 +41,6 @@ template <typename T> class BasicReaderBase;
class Expr;
class FieldDecl;
class NamespaceDecl;
class ParsedAttr;
struct PrintingPolicy;
class Type;
class ValueDecl;
Expand Down Expand Up @@ -683,7 +683,7 @@ class APValue {
CXXBaseSpecifier *getReflectedBaseSpecifier() const;
TagDataMemberSpec *getReflectedDataMemberSpec() const;
CXX26AnnotationAttr *getReflectedAnnotation() const;
ParsedAttr *getReflectedAttribute() const;
AttributeCommonInfo *getReflectedAttribute() const;

void setInt(APSInt I) {
assert(isInt() && "Invalid accessor");
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticMetafnKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def metafn_result_not_representable : Note<
"provided %select{value|object}0 cannot be represented by a reflection">;
def metafn_p3385_trace_execution_checkpoint : Note<
"(p3385-metafn) trace_execution_checkpoint %0">;
def metafn_p3385_non_standard_attribute : Warning<
"(p3385-metafn) Non standard attribute discovered %0">;

// Class definition.
def metafn_name_invalid_identifier : Note<
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/AttrSubjectMatchRules.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CapturedStmt.h"
#include "clang/Basic/Cuda.h"
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/AST/APValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/LocInfoType.h"
#include "clang/AST/Type.h"
#include "clang/Basic/AttributeCommonInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
Expand Down Expand Up @@ -943,10 +944,10 @@ CXX26AnnotationAttr *APValue::getReflectedAnnotation() const {
const_cast<void *>(getOpaqueReflectionData()));
}

ParsedAttr *APValue::getReflectedAttribute() const {
AttributeCommonInfo *APValue::getReflectedAttribute() const {
assert(getReflectionKind() == ReflectionKind::Attribute &&
"not a reflection of an attribute");
return reinterpret_cast<ParsedAttr *>(
return reinterpret_cast<AttributeCommonInfo *>(
const_cast<void *>(getOpaqueReflectionData()));
}

Expand Down
41 changes: 12 additions & 29 deletions clang/lib/AST/ExprConstantMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/ParsedAttr.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -769,7 +768,7 @@ static APValue makeReflection(CXX26AnnotationAttr *A) {
return APValue(ReflectionKind::Annotation, A);
}

static APValue makeReflection(ParsedAttr *Attr) {
static APValue makeReflection(AttributeCommonInfo *Attr) {
return APValue(ReflectionKind::Attribute, Attr);
}

Expand Down Expand Up @@ -1444,13 +1443,6 @@ bool DiagnoseReflectionKind(DiagFn Diagnoser, SourceRange Range,
// Metafunction implementations
// -----------------------------------------------------------------------------

// FIXME Reconciliate Attr and Attribute by just storing AttributeCommonInfo
struct AttributeScratchpad {
AttributeFactory factory;
ParsedAttributes attributes;
AttributeScratchpad() : factory(), attributes(factory) {}
};

bool get_ith_attribute_of(APValue &Result, ASTContext &C,
MetaActions &Meta, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
Expand All @@ -1477,8 +1469,11 @@ bool get_ith_attribute_of(APValue &Result, ASTContext &C,
// We don't allow ^^[[ attribute, attribute]], so when reflected type is
// attribute idx must be 0
if (idx == 0) {
ParsedAttr *Attr = RV.getReflectedAttribute();
return SetAndSucceed(Result, makeReflection(Attr));
AttributeCommonInfo *attr = RV.getReflectedAttribute();
if (attr->getForm().getSyntax() == AttributeCommonInfo::Syntax::AS_CXX11) {
return SetAndSucceed(Result, makeReflection(attr));
}
Diagnoser(Range.getBegin(), diag::metafn_p3385_non_standard_attribute) << attr->getAttrName();
}
return SetAndSucceed(Result, Sentinel);
}
Expand All @@ -1493,23 +1488,11 @@ bool get_ith_attribute_of(APValue &Result, ASTContext &C,
}

Attr* attr = attrs[idx];
static AttributeScratchpad scratchpad;

if (attr->getForm().getSyntax() != AttributeCommonInfo::Syntax::AS_CXX11) {
// FIXME Filter them instead of erroring...
// or we can filter with "| std::filter" on arrival
return DiagnoseReflectionKind(Diagnoser, Range, "a standard CXX11 attribute",
DescriptionOf(RV));
}
scratchpad.attributes.addNew(
const_cast<IdentifierInfo*>(attr->getAttrName()), // FIXME...
attr->getRange(),
nullptr,
attr->getLocation(),
nullptr, nullptr, nullptr,
attr->getForm());

return SetAndSucceed(Result, makeReflection(&scratchpad.attributes[0]));
if (attr->getForm().getSyntax() == AttributeCommonInfo::Syntax::AS_CXX11) {
return SetAndSucceed(Result, makeReflection(attr));
}
Diagnoser(Range.getBegin(), diag::metafn_p3385_non_standard_attribute) << attr->getAttrName();
return SetAndSucceed(Result, Sentinel);
}
case ReflectionKind::Type:
case ReflectionKind::Null:
Expand Down Expand Up @@ -1988,7 +1971,7 @@ bool identifier_of(APValue &Result, ASTContext &C, MetaActions &Meta,
break;
}
case ReflectionKind::Attribute: {
ParsedAttr* attr = RV.getReflectedAttribute();
AttributeCommonInfo* attr = RV.getReflectedAttribute();
Name = attr->getAttrName()->getName();
break;
}
Expand Down

0 comments on commit ff97c21

Please sign in to comment.