2019-12-14 10:52:16 +08:00
|
|
|
//=== ClangASTPropsEmitter.cpp - Generate Clang AST properties --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits code for working with Clang AST properties.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ASTTableGen.h"
|
|
|
|
#include "TableGenBackends.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
|
|
|
#include <cctype>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::tblgen;
|
|
|
|
|
|
|
|
static StringRef getReaderResultType(TypeNode _) { return "QualType"; }
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct ReaderWriterInfo {
|
|
|
|
bool IsReader;
|
|
|
|
|
|
|
|
/// The name of the node hierarchy. Not actually sensitive to IsReader,
|
|
|
|
/// but useful to cache here anyway.
|
|
|
|
StringRef HierarchyName;
|
|
|
|
|
|
|
|
/// The suffix on classes: Reader/Writer
|
|
|
|
StringRef ClassSuffix;
|
|
|
|
|
|
|
|
/// The base name of methods: read/write
|
|
|
|
StringRef MethodPrefix;
|
|
|
|
|
|
|
|
/// The name of the property helper member: R/W
|
|
|
|
StringRef HelperVariable;
|
|
|
|
|
|
|
|
/// The result type of methods on the class.
|
|
|
|
StringRef ResultType;
|
|
|
|
|
|
|
|
template <class NodeClass>
|
|
|
|
static ReaderWriterInfo forReader() {
|
|
|
|
return ReaderWriterInfo{
|
|
|
|
true,
|
|
|
|
NodeClass::getASTHierarchyName(),
|
|
|
|
"Reader",
|
|
|
|
"read",
|
|
|
|
"R",
|
|
|
|
getReaderResultType(NodeClass())
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class NodeClass>
|
|
|
|
static ReaderWriterInfo forWriter() {
|
|
|
|
return ReaderWriterInfo{
|
|
|
|
false,
|
|
|
|
NodeClass::getASTHierarchyName(),
|
|
|
|
"Writer",
|
|
|
|
"write",
|
|
|
|
"W",
|
|
|
|
"void"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeInfo {
|
|
|
|
std::vector<Property> Properties;
|
|
|
|
CreationRule Creator = nullptr;
|
|
|
|
OverrideRule Override = nullptr;
|
2019-12-16 15:56:32 +08:00
|
|
|
ReadHelperRule ReadHelper = nullptr;
|
2019-12-14 10:52:16 +08:00
|
|
|
};
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
struct CasedTypeInfo {
|
|
|
|
TypeKindRule KindRule;
|
|
|
|
std::vector<TypeCase> Cases;
|
|
|
|
};
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
class ASTPropsEmitter {
|
|
|
|
raw_ostream &Out;
|
|
|
|
RecordKeeper &Records;
|
2019-12-16 15:10:15 +08:00
|
|
|
std::map<HasProperties, NodeInfo> NodeInfos;
|
2019-12-15 15:39:13 +08:00
|
|
|
std::vector<PropertyType> AllPropertyTypes;
|
2019-12-16 15:10:15 +08:00
|
|
|
std::map<PropertyType, CasedTypeInfo> CasedTypeInfos;
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
ASTPropsEmitter(RecordKeeper &records, raw_ostream &out)
|
|
|
|
: Out(out), Records(records) {
|
|
|
|
|
|
|
|
// Find all the properties.
|
|
|
|
for (Property property :
|
|
|
|
records.getAllDerivedDefinitions(PropertyClassName)) {
|
2019-12-16 15:56:32 +08:00
|
|
|
HasProperties node = property.getClass();
|
2019-12-14 10:52:16 +08:00
|
|
|
NodeInfos[node].Properties.push_back(property);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all the creation rules.
|
|
|
|
for (CreationRule creationRule :
|
|
|
|
records.getAllDerivedDefinitions(CreationRuleClassName)) {
|
2019-12-16 15:56:32 +08:00
|
|
|
HasProperties node = creationRule.getClass();
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
auto &info = NodeInfos[node];
|
|
|
|
if (info.Creator) {
|
|
|
|
PrintFatalError(creationRule.getLoc(),
|
|
|
|
"multiple creator rules for \"" + node.getName()
|
|
|
|
+ "\"");
|
|
|
|
}
|
|
|
|
info.Creator = creationRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all the override rules.
|
|
|
|
for (OverrideRule overrideRule :
|
|
|
|
records.getAllDerivedDefinitions(OverrideRuleClassName)) {
|
2019-12-16 15:56:32 +08:00
|
|
|
HasProperties node = overrideRule.getClass();
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
auto &info = NodeInfos[node];
|
|
|
|
if (info.Override) {
|
|
|
|
PrintFatalError(overrideRule.getLoc(),
|
|
|
|
"multiple override rules for \"" + node.getName()
|
|
|
|
+ "\"");
|
|
|
|
}
|
|
|
|
info.Override = overrideRule;
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:56:32 +08:00
|
|
|
// Find all the write helper rules.
|
|
|
|
for (ReadHelperRule helperRule :
|
|
|
|
records.getAllDerivedDefinitions(ReadHelperRuleClassName)) {
|
|
|
|
HasProperties node = helperRule.getClass();
|
|
|
|
|
|
|
|
auto &info = NodeInfos[node];
|
|
|
|
if (info.ReadHelper) {
|
|
|
|
PrintFatalError(helperRule.getLoc(),
|
|
|
|
"multiple write helper rules for \"" + node.getName()
|
|
|
|
+ "\"");
|
|
|
|
}
|
|
|
|
info.ReadHelper = helperRule;
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
// Find all the concrete property types.
|
2019-12-15 15:39:13 +08:00
|
|
|
for (PropertyType type :
|
|
|
|
records.getAllDerivedDefinitions(PropertyTypeClassName)) {
|
|
|
|
// Ignore generic specializations; they're generally not useful when
|
|
|
|
// emitting basic emitters etc.
|
|
|
|
if (type.isGenericSpecialization()) continue;
|
|
|
|
|
|
|
|
AllPropertyTypes.push_back(type);
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
// Find all the type kind rules.
|
|
|
|
for (TypeKindRule kindRule :
|
|
|
|
records.getAllDerivedDefinitions(TypeKindClassName)) {
|
|
|
|
PropertyType type = kindRule.getParentType();
|
|
|
|
auto &info = CasedTypeInfos[type];
|
|
|
|
if (info.KindRule) {
|
|
|
|
PrintFatalError(kindRule.getLoc(),
|
|
|
|
"multiple kind rules for \""
|
|
|
|
+ type.getCXXTypeName() + "\"");
|
|
|
|
}
|
|
|
|
info.KindRule = kindRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all the type cases.
|
|
|
|
for (TypeCase typeCase :
|
|
|
|
records.getAllDerivedDefinitions(TypeCaseClassName)) {
|
|
|
|
CasedTypeInfos[typeCase.getParentType()].Cases.push_back(typeCase);
|
|
|
|
}
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
Validator(*this).validate();
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void visitAllProperties(HasProperties derived, const NodeInfo &derivedInfo,
|
2019-12-14 10:52:16 +08:00
|
|
|
function_ref<void (Property)> visit) {
|
|
|
|
std::set<StringRef> ignoredProperties;
|
|
|
|
|
|
|
|
auto overrideRule = derivedInfo.Override;
|
|
|
|
if (overrideRule) {
|
|
|
|
auto list = overrideRule.getIgnoredProperties();
|
|
|
|
ignoredProperties.insert(list.begin(), list.end());
|
|
|
|
}
|
|
|
|
|
2019-12-16 16:51:16 +08:00
|
|
|
// TODO: we should sort the properties in various ways
|
|
|
|
// - put arrays at the end to enable abbreviations
|
|
|
|
// - put conditional properties after properties used in the condition
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
visitAllNodesWithInfo(derived, derivedInfo,
|
|
|
|
[&](HasProperties node, const NodeInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
for (Property prop : info.Properties) {
|
|
|
|
if (ignoredProperties.count(prop.getName()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
visit(prop);
|
|
|
|
}
|
2019-12-16 15:10:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (ASTNode base = derivedNode.getAs<ASTNode>()) {
|
|
|
|
for (base = base.getBase(); base; base = base.getBase()) {
|
|
|
|
auto it = NodeInfos.find(base);
|
|
|
|
|
|
|
|
// Ignore intermediate nodes that don't add interesting properties.
|
|
|
|
if (it == NodeInfos.end()) continue;
|
|
|
|
auto &baseInfo = it->second;
|
|
|
|
|
|
|
|
visit(base, baseInfo);
|
|
|
|
}
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class NodeClass>
|
2019-12-16 15:10:15 +08:00
|
|
|
void emitNodeReaderClass() {
|
2019-12-14 10:52:16 +08:00
|
|
|
auto info = ReaderWriterInfo::forReader<NodeClass>();
|
2019-12-16 15:10:15 +08:00
|
|
|
emitNodeReaderWriterClass<NodeClass>(info);
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class NodeClass>
|
2019-12-16 15:10:15 +08:00
|
|
|
void emitNodeWriterClass() {
|
2019-12-14 10:52:16 +08:00
|
|
|
auto info = ReaderWriterInfo::forWriter<NodeClass>();
|
2019-12-16 15:10:15 +08:00
|
|
|
emitNodeReaderWriterClass<NodeClass>(info);
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class NodeClass>
|
2019-12-16 15:10:15 +08:00
|
|
|
void emitNodeReaderWriterClass(const ReaderWriterInfo &info);
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
template <class NodeClass>
|
|
|
|
void emitNodeReaderWriterMethod(NodeClass node,
|
|
|
|
const ReaderWriterInfo &info);
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void emitPropertiedReaderWriterBody(HasProperties node,
|
|
|
|
const ReaderWriterInfo &info);
|
|
|
|
|
|
|
|
void emitReadOfProperty(StringRef readerName, Property property);
|
|
|
|
void emitReadOfProperty(StringRef readerName, StringRef name,
|
2019-12-16 16:51:16 +08:00
|
|
|
PropertyType type, StringRef condition = "");
|
2019-12-16 15:10:15 +08:00
|
|
|
|
|
|
|
void emitWriteOfProperty(StringRef writerName, Property property);
|
|
|
|
void emitWriteOfProperty(StringRef writerName, StringRef name,
|
2019-12-16 16:51:16 +08:00
|
|
|
PropertyType type, StringRef readCode,
|
|
|
|
StringRef condition = "");
|
2019-12-14 10:52:16 +08:00
|
|
|
|
2019-12-15 15:39:13 +08:00
|
|
|
void emitBasicReaderWriterFile(const ReaderWriterInfo &info);
|
|
|
|
void emitDispatcherTemplate(const ReaderWriterInfo &info);
|
|
|
|
void emitPackUnpackOptionalTemplate(const ReaderWriterInfo &info);
|
|
|
|
void emitBasicReaderWriterTemplate(const ReaderWriterInfo &info);
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void emitCasedReaderWriterMethodBody(PropertyType type,
|
|
|
|
const CasedTypeInfo &typeCases,
|
|
|
|
const ReaderWriterInfo &info);
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
private:
|
|
|
|
class Validator {
|
2019-12-16 15:10:15 +08:00
|
|
|
ASTPropsEmitter &Emitter;
|
|
|
|
std::set<HasProperties> ValidatedNodes;
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
public:
|
2019-12-16 15:10:15 +08:00
|
|
|
Validator(ASTPropsEmitter &emitter) : Emitter(emitter) {}
|
2019-12-14 10:52:16 +08:00
|
|
|
void validate();
|
|
|
|
|
|
|
|
private:
|
2019-12-16 15:10:15 +08:00
|
|
|
void validateNode(HasProperties node, const NodeInfo &nodeInfo);
|
2019-12-14 10:52:16 +08:00
|
|
|
void validateType(PropertyType type, WrappedRecord context);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
void ASTPropsEmitter::Validator::validate() {
|
|
|
|
for (auto &entry : Emitter.NodeInfos) {
|
|
|
|
validateNode(entry.first, entry.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ErrorsPrinted > 0) {
|
|
|
|
PrintFatalError("property validation failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::Validator::validateNode(HasProperties derivedNode,
|
|
|
|
const NodeInfo &derivedNodeInfo) {
|
|
|
|
if (!ValidatedNodes.insert(derivedNode).second) return;
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
// A map from property name to property.
|
|
|
|
std::map<StringRef, Property> allProperties;
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
Emitter.visitAllNodesWithInfo(derivedNode, derivedNodeInfo,
|
|
|
|
[&](HasProperties node,
|
|
|
|
const NodeInfo &nodeInfo) {
|
|
|
|
for (Property property : nodeInfo.Properties) {
|
2019-12-14 10:52:16 +08:00
|
|
|
validateType(property.getType(), property);
|
|
|
|
|
|
|
|
auto result = allProperties.insert(
|
|
|
|
std::make_pair(property.getName(), property));
|
|
|
|
|
|
|
|
// Diagnose non-unique properties.
|
|
|
|
if (!result.second) {
|
|
|
|
// The existing property is more likely to be associated with a
|
|
|
|
// derived node, so use it as the error.
|
|
|
|
Property existingProperty = result.first->second;
|
|
|
|
PrintError(existingProperty.getLoc(),
|
|
|
|
"multiple properties named \"" + property.getName()
|
2019-12-16 15:10:15 +08:00
|
|
|
+ "\" in hierarchy of " + derivedNode.getName());
|
2019-12-14 10:52:16 +08:00
|
|
|
PrintNote(property.getLoc(), "existing property");
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 15:10:15 +08:00
|
|
|
});
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPropsEmitter::Validator::validateType(PropertyType type,
|
|
|
|
WrappedRecord context) {
|
|
|
|
if (!type.isGenericSpecialization()) {
|
|
|
|
if (type.getCXXTypeName() == "") {
|
|
|
|
PrintError(type.getLoc(),
|
|
|
|
"type is not generic but has no C++ type name");
|
|
|
|
if (context) PrintNote(context.getLoc(), "type used here");
|
|
|
|
}
|
|
|
|
} else if (auto eltType = type.getArrayElementType()) {
|
|
|
|
validateType(eltType, context);
|
|
|
|
} else if (auto valueType = type.getOptionalElementType()) {
|
|
|
|
validateType(valueType, context);
|
|
|
|
|
|
|
|
if (valueType.getPackOptionalCode().empty()) {
|
|
|
|
PrintError(valueType.getLoc(),
|
|
|
|
"type doesn't provide optional-packing code");
|
|
|
|
if (context) PrintNote(context.getLoc(), "type used here");
|
|
|
|
} else if (valueType.getUnpackOptionalCode().empty()) {
|
|
|
|
PrintError(valueType.getLoc(),
|
|
|
|
"type doesn't provide optional-unpacking code");
|
|
|
|
if (context) PrintNote(context.getLoc(), "type used here");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintError(type.getLoc(), "unknown generic property type");
|
|
|
|
if (context) PrintNote(context.getLoc(), "type used here");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/**************************** AST READER/WRITERS ****************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
template <class NodeClass>
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::emitNodeReaderWriterClass(const ReaderWriterInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
StringRef suffix = info.ClassSuffix;
|
|
|
|
StringRef var = info.HelperVariable;
|
|
|
|
|
|
|
|
// Enter the class declaration.
|
|
|
|
Out << "template <class Property" << suffix << ">\n"
|
|
|
|
"class Abstract" << info.HierarchyName << suffix << " {\n"
|
|
|
|
"public:\n"
|
|
|
|
" Property" << suffix << " &" << var << ";\n\n";
|
|
|
|
|
|
|
|
// Emit the constructor.
|
|
|
|
Out << " Abstract" << info.HierarchyName << suffix
|
|
|
|
<< "(Property" << suffix << " &" << var << ") : "
|
|
|
|
<< var << "(" << var << ") {}\n\n";
|
|
|
|
|
|
|
|
// Emit a method that dispatches on a kind to the appropriate node-specific
|
|
|
|
// method.
|
|
|
|
Out << " " << info.ResultType << " " << info.MethodPrefix << "(";
|
|
|
|
if (info.IsReader)
|
|
|
|
Out << NodeClass::getASTIdTypeName() << " kind";
|
|
|
|
else
|
|
|
|
Out << "const " << info.HierarchyName << " *node";
|
|
|
|
Out << ") {\n"
|
|
|
|
" switch (";
|
|
|
|
if (info.IsReader)
|
|
|
|
Out << "kind";
|
|
|
|
else
|
|
|
|
Out << "node->" << NodeClass::getASTIdAccessorName() << "()";
|
|
|
|
Out << ") {\n";
|
|
|
|
visitASTNodeHierarchy<NodeClass>(Records, [&](NodeClass node, NodeClass _) {
|
|
|
|
if (node.isAbstract()) return;
|
|
|
|
Out << " case " << info.HierarchyName << "::" << node.getId() << ":\n"
|
|
|
|
" return " << info.MethodPrefix << node.getClassName() << "(";
|
|
|
|
if (!info.IsReader)
|
|
|
|
Out << "static_cast<const " << node.getClassName()
|
|
|
|
<< " *>(node)";
|
|
|
|
Out << ");\n";
|
|
|
|
});
|
|
|
|
Out << " }\n"
|
|
|
|
" llvm_unreachable(\"bad kind\");\n"
|
|
|
|
" }\n\n";
|
|
|
|
|
|
|
|
// Emit node-specific methods for all the concrete nodes.
|
|
|
|
visitASTNodeHierarchy<NodeClass>(Records,
|
|
|
|
[&](NodeClass node, NodeClass base) {
|
|
|
|
if (node.isAbstract()) return;
|
|
|
|
emitNodeReaderWriterMethod(node, info);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Finish the class.
|
|
|
|
Out << "};\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit a reader method for the given concrete AST node class.
|
|
|
|
template <class NodeClass>
|
|
|
|
void ASTPropsEmitter::emitNodeReaderWriterMethod(NodeClass node,
|
|
|
|
const ReaderWriterInfo &info) {
|
|
|
|
// Declare and start the method.
|
|
|
|
Out << " " << info.ResultType << " "
|
|
|
|
<< info.MethodPrefix << node.getClassName() << "(";
|
|
|
|
if (!info.IsReader)
|
|
|
|
Out << "const " << node.getClassName() << " *node";
|
|
|
|
Out << ") {\n";
|
|
|
|
if (info.IsReader)
|
|
|
|
Out << " auto &ctx = " << info.HelperVariable << ".getASTContext();\n";
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
emitPropertiedReaderWriterBody(node, info);
|
|
|
|
|
|
|
|
// Finish the method declaration.
|
|
|
|
Out << " }\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPropsEmitter::emitPropertiedReaderWriterBody(HasProperties node,
|
|
|
|
const ReaderWriterInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
// Find the information for this node.
|
|
|
|
auto it = NodeInfos.find(node);
|
|
|
|
if (it == NodeInfos.end())
|
|
|
|
PrintFatalError(node.getLoc(),
|
|
|
|
"no information about how to deserialize \""
|
|
|
|
+ node.getName() + "\"");
|
|
|
|
auto &nodeInfo = it->second;
|
|
|
|
|
|
|
|
StringRef creationCode;
|
|
|
|
if (info.IsReader) {
|
|
|
|
// We should have a creation rule.
|
|
|
|
if (!nodeInfo.Creator)
|
|
|
|
PrintFatalError(node.getLoc(),
|
|
|
|
"no " CreationRuleClassName " for \""
|
|
|
|
+ node.getName() + "\"");
|
|
|
|
|
|
|
|
creationCode = nodeInfo.Creator.getCreationCode();
|
|
|
|
}
|
|
|
|
|
2019-12-16 15:56:32 +08:00
|
|
|
// Emit the ReadHelper code, if present.
|
|
|
|
if (!info.IsReader && nodeInfo.ReadHelper) {
|
|
|
|
Out << " " << nodeInfo.ReadHelper.getHelperCode() << "\n";
|
|
|
|
}
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
// Emit code to read all the properties.
|
|
|
|
visitAllProperties(node, nodeInfo, [&](Property prop) {
|
|
|
|
// Verify that the creation code refers to this property.
|
|
|
|
if (info.IsReader && creationCode.find(prop.getName()) == StringRef::npos)
|
|
|
|
PrintFatalError(nodeInfo.Creator.getLoc(),
|
|
|
|
"creation code for " + node.getName()
|
|
|
|
+ " doesn't refer to property \""
|
|
|
|
+ prop.getName() + "\"");
|
|
|
|
|
|
|
|
// Emit code to read or write this property.
|
|
|
|
if (info.IsReader)
|
2019-12-16 15:10:15 +08:00
|
|
|
emitReadOfProperty(info.HelperVariable, prop);
|
2019-12-14 10:52:16 +08:00
|
|
|
else
|
2019-12-16 15:10:15 +08:00
|
|
|
emitWriteOfProperty(info.HelperVariable, prop);
|
2019-12-14 10:52:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Emit the final creation code.
|
|
|
|
if (info.IsReader)
|
|
|
|
Out << " " << creationCode << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emitBasicReaderWriterMethodSuffix(raw_ostream &out,
|
|
|
|
PropertyType type,
|
|
|
|
bool isForRead) {
|
|
|
|
if (!type.isGenericSpecialization()) {
|
|
|
|
out << type.getAbstractTypeName();
|
|
|
|
} else if (auto eltType = type.getArrayElementType()) {
|
|
|
|
out << "Array";
|
|
|
|
// We only include an explicit template argument for reads so that
|
|
|
|
// we don't cause spurious const mismatches.
|
|
|
|
if (isForRead) {
|
|
|
|
out << "<";
|
|
|
|
eltType.emitCXXValueTypeName(isForRead, out);
|
|
|
|
out << ">";
|
|
|
|
}
|
|
|
|
} else if (auto valueType = type.getOptionalElementType()) {
|
|
|
|
out << "Optional";
|
|
|
|
// We only include an explicit template argument for reads so that
|
|
|
|
// we don't cause spurious const mismatches.
|
|
|
|
if (isForRead) {
|
|
|
|
out << "<";
|
|
|
|
valueType.emitCXXValueTypeName(isForRead, out);
|
|
|
|
out << ">";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PrintFatalError(type.getLoc(), "unexpected generic property type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit code to read the given property in a node-reader method.
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::emitReadOfProperty(StringRef readerName,
|
|
|
|
Property property) {
|
2019-12-16 16:51:16 +08:00
|
|
|
emitReadOfProperty(readerName, property.getName(), property.getType(),
|
|
|
|
property.getCondition());
|
2019-12-16 15:10:15 +08:00
|
|
|
}
|
2019-12-14 10:52:16 +08:00
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::emitReadOfProperty(StringRef readerName,
|
|
|
|
StringRef name,
|
2019-12-16 16:51:16 +08:00
|
|
|
PropertyType type,
|
|
|
|
StringRef condition) {
|
2019-12-14 10:52:16 +08:00
|
|
|
// Declare all the necessary buffers.
|
|
|
|
auto bufferTypes = type.getBufferElementTypes();
|
|
|
|
for (size_t i = 0, e = bufferTypes.size(); i != e; ++i) {
|
|
|
|
Out << " llvm::SmallVector<";
|
|
|
|
PropertyType(bufferTypes[i]).emitCXXValueTypeName(/*for read*/ true, Out);
|
|
|
|
Out << ", 8> " << name << "_buffer_" << i << ";\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// T prop = R.find("prop").read##ValueType(buffers...);
|
|
|
|
// We intentionally ignore shouldPassByReference here: we're going to
|
|
|
|
// get a pr-value back from read(), and we should be able to forward
|
|
|
|
// that in the creation rule.
|
|
|
|
Out << " ";
|
2019-12-16 16:51:16 +08:00
|
|
|
if (!condition.empty()) Out << "llvm::Optional<";
|
2019-12-14 10:52:16 +08:00
|
|
|
type.emitCXXValueTypeName(true, Out);
|
2019-12-16 16:51:16 +08:00
|
|
|
if (!condition.empty()) Out << ">";
|
|
|
|
Out << " " << name;
|
|
|
|
|
|
|
|
if (condition.empty()) {
|
|
|
|
Out << " = ";
|
|
|
|
} else {
|
|
|
|
Out << ";\n"
|
|
|
|
" if (" << condition << ") {\n"
|
|
|
|
" " << name << ".emplace(";
|
|
|
|
}
|
|
|
|
|
|
|
|
Out << readerName << ".find(\"" << name << "\")."
|
2019-12-14 10:52:16 +08:00
|
|
|
<< (type.isGenericSpecialization() ? "template " : "") << "read";
|
|
|
|
emitBasicReaderWriterMethodSuffix(Out, type, /*for read*/ true);
|
|
|
|
Out << "(";
|
|
|
|
for (size_t i = 0, e = bufferTypes.size(); i != e; ++i) {
|
|
|
|
Out << (i > 0 ? ", " : "") << name << "_buffer_" << i;
|
|
|
|
}
|
2019-12-16 16:51:16 +08:00
|
|
|
Out << ")";
|
|
|
|
|
|
|
|
if (condition.empty()) {
|
|
|
|
Out << ";\n";
|
|
|
|
} else {
|
|
|
|
Out << ");\n"
|
|
|
|
" }\n";
|
|
|
|
}
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit code to write the given property in a node-writer method.
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::emitWriteOfProperty(StringRef writerName,
|
|
|
|
Property property) {
|
|
|
|
emitWriteOfProperty(writerName, property.getName(), property.getType(),
|
2019-12-16 16:51:16 +08:00
|
|
|
property.getReadCode(), property.getCondition());
|
2019-12-16 15:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPropsEmitter::emitWriteOfProperty(StringRef writerName,
|
|
|
|
StringRef name,
|
|
|
|
PropertyType type,
|
2019-12-16 16:51:16 +08:00
|
|
|
StringRef readCode,
|
|
|
|
StringRef condition) {
|
|
|
|
if (!condition.empty()) {
|
|
|
|
Out << " if (" << condition << ") {\n";
|
|
|
|
}
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
// Focus down to the property:
|
2019-12-16 16:51:16 +08:00
|
|
|
// T prop = <READ>;
|
|
|
|
// W.find("prop").write##ValueType(prop);
|
|
|
|
Out << " ";
|
|
|
|
type.emitCXXValueTypeName(false, Out);
|
|
|
|
Out << " " << name << " = (" << readCode << ");\n"
|
|
|
|
" " << writerName << ".find(\"" << name << "\").write";
|
2019-12-16 15:10:15 +08:00
|
|
|
emitBasicReaderWriterMethodSuffix(Out, type, /*for read*/ false);
|
2019-12-16 16:51:16 +08:00
|
|
|
Out << "(" << name << ");\n";
|
|
|
|
|
|
|
|
if (!condition.empty()) {
|
|
|
|
Out << " }\n";
|
|
|
|
}
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit an .inc file that defines the AbstractFooReader class
|
|
|
|
/// for the given AST class hierarchy.
|
|
|
|
template <class NodeClass>
|
|
|
|
static void emitASTReader(RecordKeeper &records, raw_ostream &out,
|
|
|
|
StringRef description) {
|
|
|
|
emitSourceFileHeader(description, out);
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
ASTPropsEmitter(records, out).emitNodeReaderClass<NodeClass>();
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void clang::EmitClangTypeReader(RecordKeeper &records, raw_ostream &out) {
|
|
|
|
emitASTReader<TypeNode>(records, out, "A CRTP reader for Clang Type nodes");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit an .inc file that defines the AbstractFooWriter class
|
|
|
|
/// for the given AST class hierarchy.
|
|
|
|
template <class NodeClass>
|
|
|
|
static void emitASTWriter(RecordKeeper &records, raw_ostream &out,
|
|
|
|
StringRef description) {
|
|
|
|
emitSourceFileHeader(description, out);
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
ASTPropsEmitter(records, out).emitNodeWriterClass<NodeClass>();
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void clang::EmitClangTypeWriter(RecordKeeper &records, raw_ostream &out) {
|
|
|
|
emitASTWriter<TypeNode>(records, out, "A CRTP writer for Clang Type nodes");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/*************************** BASIC READER/WRITERS ***************************/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
2019-12-15 15:39:13 +08:00
|
|
|
void
|
|
|
|
ASTPropsEmitter::emitDispatcherTemplate(const ReaderWriterInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
// Declare the {Read,Write}Dispatcher template.
|
|
|
|
StringRef dispatcherPrefix = (info.IsReader ? "Read" : "Write");
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "template <class ValueType>\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
"struct " << dispatcherPrefix << "Dispatcher;\n";
|
|
|
|
|
|
|
|
// Declare a specific specialization of the dispatcher template.
|
|
|
|
auto declareSpecialization =
|
|
|
|
[&](StringRef specializationParameters,
|
|
|
|
const Twine &cxxTypeName,
|
|
|
|
StringRef methodSuffix) {
|
|
|
|
StringRef var = info.HelperVariable;
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "template " << specializationParameters << "\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
"struct " << dispatcherPrefix << "Dispatcher<"
|
|
|
|
<< cxxTypeName << "> {\n";
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " template <class Basic" << info.ClassSuffix << ", class... Args>\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
" static " << (info.IsReader ? cxxTypeName : "void") << " "
|
|
|
|
<< info.MethodPrefix
|
|
|
|
<< "(Basic" << info.ClassSuffix << " &" << var
|
|
|
|
<< ", Args &&... args) {\n"
|
|
|
|
" return " << var << "."
|
|
|
|
<< info.MethodPrefix << methodSuffix
|
|
|
|
<< "(std::forward<Args>(args)...);\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
// Declare explicit specializations for each of the concrete types.
|
2019-12-15 15:39:13 +08:00
|
|
|
for (PropertyType type : AllPropertyTypes) {
|
2019-12-14 10:52:16 +08:00
|
|
|
declareSpecialization("<>",
|
|
|
|
type.getCXXTypeName(),
|
|
|
|
type.getAbstractTypeName());
|
|
|
|
// Also declare a specialization for the const type when appropriate.
|
|
|
|
if (!info.IsReader && type.isConstWhenWriting()) {
|
|
|
|
declareSpecialization("<>",
|
|
|
|
"const " + type.getCXXTypeName(),
|
|
|
|
type.getAbstractTypeName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Declare partial specializations for ArrayRef and Optional.
|
|
|
|
declareSpecialization("<class T>",
|
|
|
|
"llvm::ArrayRef<T>",
|
|
|
|
"Array");
|
|
|
|
declareSpecialization("<class T>",
|
|
|
|
"llvm::Optional<T>",
|
|
|
|
"Optional");
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
2019-12-15 15:39:13 +08:00
|
|
|
void
|
|
|
|
ASTPropsEmitter::emitPackUnpackOptionalTemplate(const ReaderWriterInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
StringRef classPrefix = (info.IsReader ? "Unpack" : "Pack");
|
|
|
|
StringRef methodName = (info.IsReader ? "unpack" : "pack");
|
|
|
|
|
|
|
|
// Declare the {Pack,Unpack}OptionalValue template.
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "template <class ValueType>\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
"struct " << classPrefix << "OptionalValue;\n";
|
|
|
|
|
|
|
|
auto declareSpecialization = [&](const Twine &typeName,
|
|
|
|
StringRef code) {
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "template <>\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
"struct " << classPrefix << "OptionalValue<" << typeName << "> {\n"
|
|
|
|
" static " << (info.IsReader ? "Optional<" : "") << typeName
|
|
|
|
<< (info.IsReader ? "> " : " ") << methodName << "("
|
|
|
|
<< (info.IsReader ? "" : "Optional<") << typeName
|
|
|
|
<< (info.IsReader ? "" : ">") << " value) {\n"
|
|
|
|
" return " << code << ";\n"
|
|
|
|
" }\n"
|
|
|
|
"};\n";
|
|
|
|
};
|
|
|
|
|
2019-12-15 15:39:13 +08:00
|
|
|
for (PropertyType type : AllPropertyTypes) {
|
2019-12-14 10:52:16 +08:00
|
|
|
StringRef code = (info.IsReader ? type.getUnpackOptionalCode()
|
|
|
|
: type.getPackOptionalCode());
|
|
|
|
if (code.empty()) continue;
|
|
|
|
|
|
|
|
StringRef typeName = type.getCXXTypeName();
|
|
|
|
declareSpecialization(typeName, code);
|
|
|
|
if (type.isConstWhenWriting() && !info.IsReader)
|
|
|
|
declareSpecialization("const " + typeName, code);
|
|
|
|
}
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
2019-12-15 15:39:13 +08:00
|
|
|
void
|
|
|
|
ASTPropsEmitter::emitBasicReaderWriterTemplate(const ReaderWriterInfo &info) {
|
2019-12-14 10:52:16 +08:00
|
|
|
// Emit the Basic{Reader,Writer}Base template.
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "template <class Impl>\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
"class Basic" << info.ClassSuffix << "Base {\n";
|
|
|
|
if (info.IsReader)
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " ASTContext &C;\n";
|
|
|
|
Out << "protected:\n"
|
2019-12-14 10:52:16 +08:00
|
|
|
" Basic" << info.ClassSuffix << "Base"
|
|
|
|
<< (info.IsReader ? "(ASTContext &ctx) : C(ctx)" : "()")
|
|
|
|
<< " {}\n"
|
|
|
|
"public:\n";
|
|
|
|
if (info.IsReader)
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " ASTContext &getASTContext() { return C; }\n";
|
|
|
|
Out << " Impl &asImpl() { return static_cast<Impl&>(*this); }\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
|
|
|
|
auto enterReaderWriterMethod = [&](StringRef cxxTypeName,
|
|
|
|
StringRef abstractTypeName,
|
|
|
|
bool shouldPassByReference,
|
2019-12-16 15:10:15 +08:00
|
|
|
bool constWhenWriting,
|
|
|
|
StringRef paramName) {
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " " << (info.IsReader ? cxxTypeName : "void")
|
2019-12-14 10:52:16 +08:00
|
|
|
<< " " << info.MethodPrefix << abstractTypeName << "(";
|
|
|
|
if (!info.IsReader)
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << (shouldPassByReference || constWhenWriting ? "const " : "")
|
2019-12-14 10:52:16 +08:00
|
|
|
<< cxxTypeName
|
2019-12-16 15:10:15 +08:00
|
|
|
<< (shouldPassByReference ? " &" : "") << " " << paramName;
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << ") {\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Emit {read,write}ValueType methods for all the enum and subclass types
|
|
|
|
// that default to using the integer/base-class implementations.
|
2019-12-15 15:39:13 +08:00
|
|
|
for (PropertyType type : AllPropertyTypes) {
|
2019-12-16 15:10:15 +08:00
|
|
|
auto enterMethod = [&](StringRef paramName) {
|
2019-12-14 10:52:16 +08:00
|
|
|
enterReaderWriterMethod(type.getCXXTypeName(),
|
|
|
|
type.getAbstractTypeName(),
|
2019-12-16 15:10:15 +08:00
|
|
|
type.shouldPassByReference(),
|
|
|
|
type.isConstWhenWriting(),
|
|
|
|
paramName);
|
|
|
|
};
|
|
|
|
auto exitMethod = [&] {
|
|
|
|
Out << " }\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handled cased types.
|
|
|
|
auto casedIter = CasedTypeInfos.find(type);
|
|
|
|
if (casedIter != CasedTypeInfos.end()) {
|
|
|
|
enterMethod("node");
|
|
|
|
emitCasedReaderWriterMethodBody(type, casedIter->second, info);
|
|
|
|
exitMethod();
|
|
|
|
|
|
|
|
} else if (type.isEnum()) {
|
|
|
|
enterMethod("value");
|
2019-12-14 10:52:16 +08:00
|
|
|
if (info.IsReader)
|
2019-12-17 02:31:44 +08:00
|
|
|
Out << " return asImpl().template readEnum<"
|
|
|
|
<< type.getCXXTypeName() << ">();\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
else
|
2019-12-17 02:31:44 +08:00
|
|
|
Out << " asImpl().writeEnum(value);\n";
|
2019-12-16 15:10:15 +08:00
|
|
|
exitMethod();
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
} else if (PropertyType superclass = type.getSuperclassType()) {
|
2019-12-16 15:10:15 +08:00
|
|
|
enterMethod("value");
|
2019-12-14 10:52:16 +08:00
|
|
|
if (info.IsReader)
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " return cast_or_null<" << type.getSubclassClassName()
|
2019-12-14 10:52:16 +08:00
|
|
|
<< ">(asImpl().read"
|
|
|
|
<< superclass.getAbstractTypeName()
|
|
|
|
<< "());\n";
|
|
|
|
else
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << " asImpl().write" << superclass.getAbstractTypeName()
|
2019-12-14 10:52:16 +08:00
|
|
|
<< "(value);\n";
|
2019-12-16 15:10:15 +08:00
|
|
|
exitMethod();
|
|
|
|
|
2019-12-14 10:52:16 +08:00
|
|
|
} else {
|
|
|
|
// The other types can't be handled as trivially.
|
|
|
|
}
|
|
|
|
}
|
2019-12-15 15:39:13 +08:00
|
|
|
Out << "};\n\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
void ASTPropsEmitter::emitCasedReaderWriterMethodBody(PropertyType type,
|
|
|
|
const CasedTypeInfo &typeCases,
|
|
|
|
const ReaderWriterInfo &info) {
|
|
|
|
if (typeCases.Cases.empty()) {
|
|
|
|
assert(typeCases.KindRule);
|
|
|
|
PrintFatalError(typeCases.KindRule.getLoc(),
|
|
|
|
"no cases found for \"" + type.getCXXTypeName() + "\"");
|
|
|
|
}
|
|
|
|
if (!typeCases.KindRule) {
|
|
|
|
assert(!typeCases.Cases.empty());
|
|
|
|
PrintFatalError(typeCases.Cases.front().getLoc(),
|
|
|
|
"no kind rule for \"" + type.getCXXTypeName() + "\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto var = info.HelperVariable;
|
|
|
|
std::string subvar = ("sub" + var).str();
|
|
|
|
|
|
|
|
// Bind `ctx` for readers.
|
|
|
|
if (info.IsReader)
|
|
|
|
Out << " auto &ctx = asImpl().getASTContext();\n";
|
2019-12-14 10:52:16 +08:00
|
|
|
|
2019-12-16 15:10:15 +08:00
|
|
|
// Start an object.
|
|
|
|
Out << " auto &&" << subvar << " = asImpl()."
|
|
|
|
<< info.MethodPrefix << "Object();\n";
|
|
|
|
|
|
|
|
// Read/write the kind property;
|
|
|
|
TypeKindRule kindRule = typeCases.KindRule;
|
|
|
|
StringRef kindProperty = kindRule.getKindPropertyName();
|
|
|
|
PropertyType kindType = kindRule.getKindType();
|
|
|
|
if (info.IsReader) {
|
|
|
|
emitReadOfProperty(subvar, kindProperty, kindType);
|
|
|
|
} else {
|
2019-12-16 16:51:16 +08:00
|
|
|
// Write the property. Note that this will implicitly read the
|
|
|
|
// kind into a local variable with the right name.
|
|
|
|
emitWriteOfProperty(subvar, kindProperty, kindType,
|
|
|
|
kindRule.getReadCode());
|
2019-12-16 15:10:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare a ReaderWriterInfo with a helper variable that will use
|
|
|
|
// the sub-reader/writer.
|
|
|
|
ReaderWriterInfo subInfo = info;
|
|
|
|
subInfo.HelperVariable = subvar;
|
|
|
|
|
|
|
|
// Switch on the kind.
|
|
|
|
Out << " switch (" << kindProperty << ") {\n";
|
|
|
|
for (TypeCase typeCase : typeCases.Cases) {
|
|
|
|
Out << " case " << type.getCXXTypeName() << "::"
|
|
|
|
<< typeCase.getCaseName() << ": {\n";
|
|
|
|
emitPropertiedReaderWriterBody(typeCase, subInfo);
|
|
|
|
if (!info.IsReader)
|
|
|
|
Out << " return;\n";
|
|
|
|
Out << " }\n\n";
|
|
|
|
}
|
|
|
|
Out << " }\n"
|
|
|
|
" llvm_unreachable(\"bad " << kindType.getCXXTypeName()
|
|
|
|
<< "\");\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTPropsEmitter::emitBasicReaderWriterFile(const ReaderWriterInfo &info) {
|
2019-12-15 15:39:13 +08:00
|
|
|
emitDispatcherTemplate(info);
|
|
|
|
emitPackUnpackOptionalTemplate(info);
|
|
|
|
emitBasicReaderWriterTemplate(info);
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit an .inc file that defines some helper classes for reading
|
|
|
|
/// basic values.
|
|
|
|
void clang::EmitClangBasicReader(RecordKeeper &records, raw_ostream &out) {
|
|
|
|
emitSourceFileHeader("Helper classes for BasicReaders", out);
|
|
|
|
|
|
|
|
// Use any property, we won't be using those properties.
|
|
|
|
auto info = ReaderWriterInfo::forReader<TypeNode>();
|
2019-12-15 15:39:13 +08:00
|
|
|
ASTPropsEmitter(records, out).emitBasicReaderWriterFile(info);
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Emit an .inc file that defines some helper classes for writing
|
|
|
|
/// basic values.
|
|
|
|
void clang::EmitClangBasicWriter(RecordKeeper &records, raw_ostream &out) {
|
|
|
|
emitSourceFileHeader("Helper classes for BasicWriters", out);
|
|
|
|
|
|
|
|
// Use any property, we won't be using those properties.
|
|
|
|
auto info = ReaderWriterInfo::forWriter<TypeNode>();
|
2019-12-15 15:39:13 +08:00
|
|
|
ASTPropsEmitter(records, out).emitBasicReaderWriterFile(info);
|
2019-12-14 10:52:16 +08:00
|
|
|
}
|