Skip to content

[NFC] Reformat ClangASTPropertiesEmitter ASTPropsEmitter class #108275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 45 additions & 49 deletions clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,99 +88,98 @@ struct CasedTypeInfo {
};

class ASTPropsEmitter {
raw_ostream &Out;
RecordKeeper &Records;
std::map<HasProperties, NodeInfo> NodeInfos;
raw_ostream &Out;
RecordKeeper &Records;
std::map<HasProperties, NodeInfo> NodeInfos;
std::vector<PropertyType> AllPropertyTypes;
std::map<PropertyType, CasedTypeInfo> CasedTypeInfos;

public:
ASTPropsEmitter(RecordKeeper &records, raw_ostream &out)
: Out(out), Records(records) {

// Find all the properties.
for (Property property :
records.getAllDerivedDefinitions(PropertyClassName)) {
HasProperties node = property.getClass();
NodeInfos[node].Properties.push_back(property);
}
ASTPropsEmitter(RecordKeeper &records, raw_ostream &out)
: Out(out), Records(records) {

// Find all the properties.
for (Property property :
records.getAllDerivedDefinitions(PropertyClassName)) {
HasProperties node = property.getClass();
NodeInfos[node].Properties.push_back(property);
}

// Find all the creation rules.
for (CreationRule creationRule :
records.getAllDerivedDefinitions(CreationRuleClassName)) {
records.getAllDerivedDefinitions(CreationRuleClassName)) {
HasProperties node = creationRule.getClass();

auto &info = NodeInfos[node];
if (info.Creator) {
PrintFatalError(creationRule.getLoc(),
"multiple creator rules for \"" + node.getName()
+ "\"");
PrintFatalError(creationRule.getLoc(), "multiple creator rules for \"" +
node.getName() + "\"");
}
info.Creator = creationRule;
}

// Find all the override rules.
for (OverrideRule overrideRule :
records.getAllDerivedDefinitions(OverrideRuleClassName)) {
records.getAllDerivedDefinitions(OverrideRuleClassName)) {
HasProperties node = overrideRule.getClass();

auto &info = NodeInfos[node];
if (info.Override) {
PrintFatalError(overrideRule.getLoc(),
"multiple override rules for \"" + node.getName()
+ "\"");
"multiple override rules for \"" + node.getName() +
"\"");
}
info.Override = overrideRule;
}

// Find all the write helper rules.
for (ReadHelperRule helperRule :
records.getAllDerivedDefinitions(ReadHelperRuleClassName)) {
records.getAllDerivedDefinitions(ReadHelperRuleClassName)) {
HasProperties node = helperRule.getClass();

auto &info = NodeInfos[node];
if (info.ReadHelper) {
PrintFatalError(helperRule.getLoc(),
"multiple write helper rules for \"" + node.getName()
+ "\"");
"multiple write helper rules for \"" + node.getName() +
"\"");
}
info.ReadHelper = helperRule;
}

// Find all the concrete property types.
for (PropertyType type :
records.getAllDerivedDefinitions(PropertyTypeClassName)) {
records.getAllDerivedDefinitions(PropertyTypeClassName)) {
// Ignore generic specializations; they're generally not useful when
// emitting basic emitters etc.
if (type.isGenericSpecialization()) continue;
if (type.isGenericSpecialization())
continue;

AllPropertyTypes.push_back(type);
}

// Find all the type kind rules.
for (TypeKindRule kindRule :
records.getAllDerivedDefinitions(TypeKindClassName)) {
records.getAllDerivedDefinitions(TypeKindClassName)) {
PropertyType type = kindRule.getParentType();
auto &info = CasedTypeInfos[type];
if (info.KindRule) {
PrintFatalError(kindRule.getLoc(),
"multiple kind rules for \""
+ type.getCXXTypeName() + "\"");
PrintFatalError(kindRule.getLoc(), "multiple kind rules for \"" +
type.getCXXTypeName() + "\"");
}
info.KindRule = kindRule;
}

// Find all the type cases.
for (TypeCase typeCase :
records.getAllDerivedDefinitions(TypeCaseClassName)) {
records.getAllDerivedDefinitions(TypeCaseClassName)) {
CasedTypeInfos[typeCase.getParentType()].Cases.push_back(typeCase);
}

Validator(*this).validate();
}
}

void visitAllProperties(HasProperties derived, const NodeInfo &derivedInfo,
function_ref<void (Property)> visit) {
function_ref<void(Property)> visit) {
std::set<StringRef> ignoredProperties;

auto overrideRule = derivedInfo.Override;
Expand All @@ -195,20 +194,19 @@ class ASTPropsEmitter {

visitAllNodesWithInfo(derived, derivedInfo,
[&](HasProperties node, const NodeInfo &info) {
for (Property prop : info.Properties) {
if (ignoredProperties.count(prop.getName()))
continue;
for (Property prop : info.Properties) {
if (ignoredProperties.count(prop.getName()))
continue;

visit(prop);
}
});
visit(prop);
}
});
}

void visitAllNodesWithInfo(HasProperties derivedNode,
const NodeInfo &derivedNodeInfo,
llvm::function_ref<void (HasProperties node,
const NodeInfo &info)>
visit) {
void visitAllNodesWithInfo(
HasProperties derivedNode, const NodeInfo &derivedNodeInfo,
llvm::function_ref<void(HasProperties node, const NodeInfo &info)>
visit) {
visit(derivedNode, derivedNodeInfo);

// Also walk the bases if appropriate.
Expand All @@ -217,22 +215,21 @@ class ASTPropsEmitter {
auto it = NodeInfos.find(base);

// Ignore intermediate nodes that don't add interesting properties.
if (it == NodeInfos.end()) continue;
if (it == NodeInfos.end())
continue;
auto &baseInfo = it->second;

visit(base, baseInfo);
}
}
}

template <class NodeClass>
void emitNodeReaderClass() {
template <class NodeClass> void emitNodeReaderClass() {
auto info = ReaderWriterInfo::forReader<NodeClass>();
emitNodeReaderWriterClass<NodeClass>(info);
}

template <class NodeClass>
void emitNodeWriterClass() {
template <class NodeClass> void emitNodeWriterClass() {
auto info = ReaderWriterInfo::forWriter<NodeClass>();
emitNodeReaderWriterClass<NodeClass>(info);
}
Expand All @@ -241,8 +238,7 @@ class ASTPropsEmitter {
void emitNodeReaderWriterClass(const ReaderWriterInfo &info);

template <class NodeClass>
void emitNodeReaderWriterMethod(NodeClass node,
const ReaderWriterInfo &info);
void emitNodeReaderWriterMethod(NodeClass node, const ReaderWriterInfo &info);

void emitPropertiedReaderWriterBody(HasProperties node,
const ReaderWriterInfo &info);
Expand Down
Loading