Skip to content

Commit 76d166b

Browse files
author
git apple-llvm automerger
committed
Merge commit '6404bd236240' from llvm.org/master into apple/master
2 parents 94ead13 + 6404bd2 commit 76d166b

File tree

11 files changed

+1059
-5
lines changed

11 files changed

+1059
-5
lines changed

clang/include/clang/AST/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ clang_tablegen(TypeNodes.inc -gen-clang-type-nodes
3535
SOURCE ../Basic/TypeNodes.td
3636
TARGET ClangTypeNodes)
3737

38+
clang_tablegen(AbstractBasicReader.inc -gen-clang-basic-reader
39+
SOURCE PropertiesBase.td
40+
TARGET ClangAbstractBasicReader)
41+
42+
clang_tablegen(AbstractBasicWriter.inc -gen-clang-basic-writer
43+
SOURCE PropertiesBase.td
44+
TARGET ClangAbstractBasicWriter)
45+
3846
clang_tablegen(CommentNodes.inc -gen-clang-comment-nodes
3947
SOURCE ../Basic/CommentNodes.td
4048
TARGET ClangCommentNodes)
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
//==--- PropertiesBase.td - Baseline definitions for AST properties -------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
class ASTNode;
10+
11+
/// The type of the property.
12+
class PropertyType<string typeName = ""> {
13+
/// The C++ type name for the type.
14+
string CXXName = !if(!ne(typeName, ""), typeName, NAME);
15+
16+
/// Whether the C++ type should generally be passed around by reference.
17+
bit PassByReference = 0;
18+
19+
/// Whether `const` should be prepended to the type when writing.
20+
bit ConstWhenWriting = 0;
21+
22+
/// Given a value of type Optional<CXXName> bound as 'value', yield a
23+
/// CXXName that can be serialized into a DataStreamTypeWriter.
24+
string PackOptional = "";
25+
26+
/// Given a value of type CXXName bound as 'value' that was deserialized
27+
/// by a DataStreamTypeReader, yield an Optional<CXXName>.
28+
string UnpackOptional = "";
29+
30+
/// A list of types for which buffeers must be passed to the read
31+
/// operations.
32+
list<PropertyType> BufferElementTypes = [];
33+
}
34+
35+
/// Property types that correspond to specific C++ enums.
36+
class EnumPropertyType<string typeName = ""> : PropertyType<typeName> {}
37+
38+
/// Property types that correspond to a specific C++ class.
39+
/// Supports optional values by using the null representation.
40+
class RefPropertyType<string className> : PropertyType<className # "*"> {
41+
let PackOptional =
42+
"value ? *value : nullptr";
43+
let UnpackOptional =
44+
"value ? llvm::Optional<" # CXXName # ">(value) : llvm::None";
45+
}
46+
47+
/// Property types that correspond to a specific subclass of another type.
48+
class SubclassPropertyType<string className, PropertyType base>
49+
: RefPropertyType<className> {
50+
PropertyType Base = base;
51+
string SubclassName = className;
52+
let ConstWhenWriting = base.ConstWhenWriting;
53+
}
54+
55+
/// Property types that support optional values by using their
56+
/// default value.
57+
class DefaultValuePropertyType<string typeName = ""> : PropertyType<typeName> {
58+
let PackOptional =
59+
"value ? *value : " # CXXName # "()";
60+
let UnpackOptional =
61+
"value.isNull() ? llvm::None : llvm::Optional<" # CXXName # ">(value)";
62+
}
63+
64+
/// Property types that correspond to integer types and support optional
65+
/// values by shifting the value over by 1.
66+
class CountPropertyType<string typeName = ""> : PropertyType<typeName> {
67+
let PackOptional =
68+
"value ? *value + 1 : 0";
69+
let UnpackOptional =
70+
"value ? llvm::Optional<" # CXXName # ">(value - 1) : llvm::None";
71+
}
72+
73+
def APInt : PropertyType<"llvm::APInt"> { let PassByReference = 1; }
74+
def APSInt : PropertyType<"llvm::APSInt"> { let PassByReference = 1; }
75+
def ArraySizeModifier : EnumPropertyType<"ArrayType::ArraySizeModifier">;
76+
def AttrKind : EnumPropertyType<"attr::Kind">;
77+
def AutoTypeKeyword : EnumPropertyType;
78+
def Bool : PropertyType<"bool">;
79+
def BuiltinTypeKind : EnumPropertyType<"BuiltinType::Kind">;
80+
def CallingConv : EnumPropertyType;
81+
def DeclarationName : PropertyType;
82+
def DeclarationNameKind : EnumPropertyType<"DeclarationName::NameKind">;
83+
def DeclRef : RefPropertyType<"Decl"> { let ConstWhenWriting = 1; }
84+
def CXXRecordDeclRef :
85+
SubclassPropertyType<"CXXRecordDecl", DeclRef>;
86+
def FunctionDeclRef :
87+
SubclassPropertyType<"FunctionDecl", DeclRef>;
88+
def NamedDeclRef :
89+
SubclassPropertyType<"NamedDecl", DeclRef>;
90+
def NamespaceDeclRef :
91+
SubclassPropertyType<"NamespaceDecl", DeclRef>;
92+
def NamespaceAliasDeclRef :
93+
SubclassPropertyType<"NamespaceAliasDecl", DeclRef>;
94+
def ObjCProtocolDeclRef :
95+
SubclassPropertyType<"ObjCProtocolDecl", DeclRef>;
96+
def ObjCTypeParamDeclRef :
97+
SubclassPropertyType<"ObjCTypeParamDecl", DeclRef>;
98+
def TagDeclRef :
99+
SubclassPropertyType<"TagDecl", DeclRef>;
100+
def TemplateDeclRef :
101+
SubclassPropertyType<"TemplateDecl", DeclRef>;
102+
def TemplateTypeParmDeclRef :
103+
SubclassPropertyType<"TemplateTypeParmDecl", DeclRef>;
104+
def TemplateTemplateParmDeclRef :
105+
SubclassPropertyType<"TemplateTemplateParmDecl", DeclRef>;
106+
def ValueDeclRef :
107+
SubclassPropertyType<"ValueDecl", DeclRef>;
108+
def ElaboratedTypeKeyword : EnumPropertyType;
109+
def ExtParameterInfo : PropertyType<"FunctionProtoType::ExtParameterInfo">;
110+
def Identifier : PropertyType<"IdentifierInfo*">;
111+
def NestedNameSpecifier : PropertyType<"NestedNameSpecifier *">;
112+
def NestedNameSpecifierKind :
113+
EnumPropertyType<"NestedNameSpecifier::SpecifierKind">;
114+
def OverloadedOperatorKind : EnumPropertyType;
115+
def Qualifiers : PropertyType;
116+
def QualType : DefaultValuePropertyType;
117+
def RefQualifierKind : EnumPropertyType;
118+
def Selector : PropertyType;
119+
def SourceLocation : PropertyType;
120+
def StmtRef : RefPropertyType<"Stmt"> { let ConstWhenWriting = 1; }
121+
def ExprRef : SubclassPropertyType<"Expr", StmtRef>;
122+
def TemplateArgument : PropertyType;
123+
def TemplateArgumentKind : EnumPropertyType<"TemplateArgument::ArgKind">;
124+
def TemplateName : DefaultValuePropertyType;
125+
def TemplateNameKind : EnumPropertyType<"TemplateName::NameKind">;
126+
def UInt32 : CountPropertyType<"uint32_t">;
127+
def UInt64 : CountPropertyType<"uint64_t">;
128+
def UnaryTypeTransformKind : EnumPropertyType<"UnaryTransformType::UTTKind">;
129+
def VectorKind : EnumPropertyType<"VectorType::VectorKind">;
130+
131+
def ExceptionSpecInfo : PropertyType<"FunctionProtoType::ExceptionSpecInfo"> {
132+
let BufferElementTypes = [ QualType ];
133+
}
134+
135+
/// Arrays. The corresponding C++ type is ArrayRef of the corresponding
136+
/// C++ type of the element.
137+
class Array<PropertyType element> : PropertyType {
138+
PropertyType Element = element;
139+
let BufferElementTypes = [ element ];
140+
}
141+
142+
/// llvm::Optional<T>. The corresponding C++ type is generally just the
143+
/// corresponding C++ type of the element.
144+
///
145+
/// Optional<Unsigned> may restrict the range of the operand for some
146+
/// serialization clients.
147+
class Optional<PropertyType element> : PropertyType {
148+
PropertyType Element = element;
149+
let PassByReference = element.PassByReference;
150+
}
151+
152+
/// A property of an AST node.
153+
class Property<string name, PropertyType type> {
154+
ASTNode Class;
155+
string Name = name;
156+
PropertyType Type = type;
157+
158+
/// A function for reading the property, expressed in terms of a variable
159+
/// "node".
160+
code Read;
161+
}
162+
163+
/// A rule for creating objects of this type.
164+
class Creator<code create> {
165+
ASTNode Class;
166+
167+
/// A function for creating values of this kind, expressed in terms of a
168+
/// variable `ctx` of type `ASTContext &`. Must also refer to all of the
169+
/// properties by name.
170+
code Create = create;
171+
}
172+
173+
/// A rule which overrides some of the normal rules.
174+
class Override {
175+
ASTNode Class;
176+
177+
/// Properties from base classes that should be ignored.
178+
list<string> IgnoredProperties = [];
179+
}

clang/include/clang/Basic/DeclNodes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
class ASTNode;
12
class AttrSubject;
23

34
class DeclNode<DeclNode base, string diagSpelling = "", bit abstract = 0>
4-
: AttrSubject {
5+
: ASTNode, AttrSubject {
56
DeclNode Base = base;
67
bit Abstract = abstract;
78
string DiagSpelling = diagSpelling;

clang/include/clang/Basic/StmtNodes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
class ASTNode;
12
class AttrSubject;
23

3-
class StmtNode<StmtNode base, bit abstract = 0> : AttrSubject {
4+
class StmtNode<StmtNode base, bit abstract = 0> : ASTNode, AttrSubject {
45
StmtNode Base = base;
56
bit Abstract = abstract;
67
}

clang/include/clang/Basic/TypeNodes.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
class TypeNode<TypeNode base, bit abstract = 0> {
1+
class ASTNode;
2+
3+
class TypeNode<TypeNode base, bit abstract = 0> : ASTNode {
24
TypeNode Base = base;
35
bit Abstract = abstract;
46
}

clang/utils/TableGen/ASTTableGen.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ std::string clang::tblgen::StmtNode::getId() const {
6060
return (Twine(getName()) + "Class").str();
6161
}
6262

63+
/// Emit a string spelling out the C++ value type.
64+
void PropertyType::emitCXXValueTypeName(bool forRead, raw_ostream &out) const {
65+
if (!isGenericSpecialization()) {
66+
if (!forRead && isConstWhenWriting())
67+
out << "const ";
68+
out << getCXXTypeName();
69+
} else if (auto elementType = getArrayElementType()) {
70+
out << "llvm::ArrayRef<";
71+
elementType.emitCXXValueTypeName(forRead, out);
72+
out << ">";
73+
} else if (auto valueType = getOptionalElementType()) {
74+
out << "llvm::Optional<";
75+
valueType.emitCXXValueTypeName(forRead, out);
76+
out << ">";
77+
} else {
78+
//PrintFatalError(getLoc(), "unexpected generic property type");
79+
abort();
80+
}
81+
}
82+
6383
// A map from a node to each of its child nodes.
6484
using ChildMap = std::multimap<ASTNode, ASTNode>;
6585

0 commit comments

Comments
 (0)