Commit 561f5ed2 authored by Kenton Varda's avatar Kenton Varda

Rename schema2 -> schema.

parent fd1f0a4d
......@@ -5,5 +5,5 @@ set -euo pipefail
export PATH=$PWD/bin:$PWD:$PATH
capnp compile -Isrc --no-standard-import --src-prefix=src -oc++:src \
src/capnp/c++.capnp src/capnp/schema.capnp src/capnp/schema2.capnp \
src/capnp/c++.capnp src/capnp/schema.capnp \
src/capnp/compiler/lexer.capnp src/capnp/compiler/grammar.capnp
......@@ -287,7 +287,7 @@ public:
}
MallocMessageBuilder message;
auto request = message.initRoot<schema2::CodeGeneratorRequest>();
auto request = message.initRoot<schema::CodeGeneratorRequest>();
auto schemas = compiler->getLoader().getAllLoaded();
auto nodes = request.initNodes(schemas.size());
......@@ -419,7 +419,7 @@ public:
}
Schema schema = compiler->getLoader().get(id);
if (schema.getProto().which() != schema2::Node::STRUCT) {
if (schema.getProto().which() != schema::Node::STRUCT) {
return "not a struct type";
}
rootType = schema.asStruct();
......
This diff is collapsed.
This diff is collapsed.
......@@ -84,7 +84,7 @@ public:
// Resolve an arbitrary DeclName to a Node.
kj::Maybe<Schema> getBootstrapSchema() const;
kj::Maybe<schema2::Node::Reader> getFinalSchema() const;
kj::Maybe<schema::Node::Reader> getFinalSchema() const;
void traverse(uint eagerness, std::unordered_map<const Node*, uint>& seen) const;
// Get the final schema for this node, and also possibly traverse the node's children and
......@@ -96,7 +96,7 @@ public:
// implements NodeTranslator::Resolver -----------------------------
kj::Maybe<ResolvedName> resolve(const DeclName::Reader& name) const override;
kj::Maybe<Schema> resolveBootstrapSchema(uint64_t id) const override;
kj::Maybe<schema2::Node::Reader> resolveFinalSchema(uint64_t id) const override;
kj::Maybe<schema::Node::Reader> resolveFinalSchema(uint64_t id) const override;
kj::Maybe<uint64_t> resolveImport(kj::StringPtr name) const override;
private:
......@@ -192,11 +192,11 @@ private:
// Advances the content to at least the given state and returns it. Does not lock if the content
// is already at or past the given state.
void traverseNodeDependencies(const schema2::Node::Reader& schemaNode, uint eagerness,
void traverseNodeDependencies(const schema::Node::Reader& schemaNode, uint eagerness,
std::unordered_map<const Node*, uint>& seen) const;
void traverseType(const schema2::Type::Reader& type, uint eagerness,
void traverseType(const schema::Type::Reader& type, uint eagerness,
std::unordered_map<const Node*, uint>& seen) const;
void traverseAnnotations(const List<schema2::Annotation>::Reader& annotations, uint eagerness,
void traverseAnnotations(const List<schema::Annotation>::Reader& annotations, uint eagerness,
std::unordered_map<const Node*, uint>& seen) const;
// Helpers for traverse().
};
......@@ -214,7 +214,7 @@ public:
kj::Maybe<const CompiledModule&> importRelative(kj::StringPtr importPath) const;
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
getFileImportTable(Orphanage orphanage) const;
private:
......@@ -232,7 +232,7 @@ public:
uint64_t add(const Module& module) const;
kj::Maybe<uint64_t> lookup(uint64_t parent, kj::StringPtr childName) const;
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
getFileImportTable(const Module& module, Orphanage orphanage) const;
void eagerlyCompile(uint64_t id, uint eagerness) const;
const CompiledModule& addInternal(const Module& parsedModule) const;
......@@ -467,7 +467,7 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
// Construct the NodeTranslator.
auto& workspace = module->getCompiler().getWorkspace();
auto schemaNode = workspace.orphanage.newOrphan<schema2::Node>();
auto schemaNode = workspace.orphanage.newOrphan<schema::Node>();
auto builder = schemaNode.get();
builder.setId(id);
builder.setDisplayName(displayName);
......@@ -656,7 +656,7 @@ kj::Maybe<Schema> Compiler::Node::getBootstrapSchema() const {
return content.bootstrapSchema;
}
}
kj::Maybe<schema2::Node::Reader> Compiler::Node::getFinalSchema() const {
kj::Maybe<schema::Node::Reader> Compiler::Node::getFinalSchema() const {
return getContent(Content::FINISHED).finalSchema.map(
[](const Schema& schema) { return schema.getProto(); });
}
......@@ -696,16 +696,16 @@ void Compiler::Node::traverse(uint eagerness, std::unordered_map<const Node*, ui
}
void Compiler::Node::traverseNodeDependencies(
const schema2::Node::Reader& schemaNode, uint eagerness,
const schema::Node::Reader& schemaNode, uint eagerness,
std::unordered_map<const Node*, uint>& seen) const {
switch (schemaNode.which()) {
case schema2::Node::STRUCT:
case schema::Node::STRUCT:
for (auto field: schemaNode.getStruct().getFields()) {
switch (field.which()) {
case schema2::Field::REGULAR:
case schema::Field::REGULAR:
traverseType(field.getRegular().getType(), eagerness, seen);
break;
case schema2::Field::GROUP:
case schema::Field::GROUP:
// Aux node will be scanned later.
break;
}
......@@ -714,13 +714,13 @@ void Compiler::Node::traverseNodeDependencies(
}
break;
case schema2::Node::ENUM:
case schema::Node::ENUM:
for (auto enumerant: schemaNode.getEnum()) {
traverseAnnotations(enumerant.getAnnotations(), eagerness, seen);
}
break;
case schema2::Node::INTERFACE:
case schema::Node::INTERFACE:
for (auto method: schemaNode.getInterface()) {
for (auto param: method.getParams()) {
traverseType(param.getType(), eagerness, seen);
......@@ -738,20 +738,20 @@ void Compiler::Node::traverseNodeDependencies(
traverseAnnotations(schemaNode.getAnnotations(), eagerness, seen);
}
void Compiler::Node::traverseType(const schema2::Type::Reader& type, uint eagerness,
void Compiler::Node::traverseType(const schema::Type::Reader& type, uint eagerness,
std::unordered_map<const Node*, uint>& seen) const {
uint64_t id = 0;
switch (type.which()) {
case schema2::Type::STRUCT:
case schema::Type::STRUCT:
id = type.getStruct();
break;
case schema2::Type::ENUM:
case schema::Type::ENUM:
id = type.getEnum();
break;
case schema2::Type::INTERFACE:
case schema::Type::INTERFACE:
id = type.getInterface();
break;
case schema2::Type::LIST:
case schema::Type::LIST:
traverseType(type.getList(), eagerness, seen);
return;
default:
......@@ -765,7 +765,7 @@ void Compiler::Node::traverseType(const schema2::Type::Reader& type, uint eagern
}
}
void Compiler::Node::traverseAnnotations(const List<schema2::Annotation>::Reader& annotations,
void Compiler::Node::traverseAnnotations(const List<schema::Annotation>::Reader& annotations,
uint eagerness,
std::unordered_map<const Node*, uint>& seen) const {
for (auto annotation: annotations) {
......@@ -795,7 +795,7 @@ kj::Maybe<Schema> Compiler::Node::resolveBootstrapSchema(uint64_t id) const {
}
}
kj::Maybe<schema2::Node::Reader> Compiler::Node::resolveFinalSchema(uint64_t id) const {
kj::Maybe<schema::Node::Reader> Compiler::Node::resolveFinalSchema(uint64_t id) const {
KJ_IF_MAYBE(node, module->getCompiler().findNode(id)) {
return node->getFinalSchema();
} else {
......@@ -877,12 +877,12 @@ static void findImports(Declaration::Reader decl, std::set<kj::StringPtr>& outpu
}
}
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
Compiler::CompiledModule::getFileImportTable(Orphanage orphanage) const {
std::set<kj::StringPtr> importNames;
findImports(content.getReader().getRoot(), importNames);
auto result = orphanage.newOrphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>(
auto result = orphanage.newOrphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>(
importNames.size());
auto builder = result.get();
......@@ -997,7 +997,7 @@ kj::Maybe<uint64_t> Compiler::Impl::lookup(uint64_t parent, kj::StringPtr childN
}
}
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
Compiler::Impl::getFileImportTable(const Module& module, Orphanage orphanage) const {
return addInternal(module).getFileImportTable(orphanage);
}
......@@ -1038,7 +1038,7 @@ kj::Maybe<uint64_t> Compiler::lookup(uint64_t parent, kj::StringPtr childName) c
return impl->lookup(parent, childName);
}
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
Compiler::getFileImportTable(const Module& module, Orphanage orphanage) const {
return impl->getFileImportTable(module, orphanage);
}
......
......@@ -25,7 +25,7 @@
#define CAPNP_COMPILER_COMPILER_H_
#include <capnp/compiler/grammar.capnp.h>
#include <capnp/schema2.capnp.h>
#include <capnp/schema.capnp.h>
#include <capnp/schema-loader.h>
#include "error-reporter.h"
......@@ -84,7 +84,7 @@ public:
// exception if the parent ID is not recognized; returns null if the parent has no child of the
// given name. Neither the parent nor the child schema node is actually compiled.
Orphan<List<schema2::CodeGeneratorRequest::RequestedFile::Import>>
Orphan<List<schema::CodeGeneratorRequest::RequestedFile::Import>>
getFileImportTable(const Module& module, Orphanage orphanage) const;
// Build the import table for the CodeGeneratorRequest for the given module.
......
This diff is collapsed.
......@@ -26,7 +26,7 @@
#include <capnp/orphan.h>
#include <capnp/compiler/grammar.capnp.h>
#include <capnp/schema2.capnp.h>
#include <capnp/schema.capnp.h>
#include <capnp/dynamic.h>
#include <kj/vector.h>
#include "error-reporter.h"
......@@ -62,7 +62,7 @@ public:
// traversing other schemas. Returns null if the ID is recognized, but the corresponding
// schema node failed to be built for reasons that were already reported.
virtual kj::Maybe<schema2::Node::Reader> resolveFinalSchema(uint64_t id) const = 0;
virtual kj::Maybe<schema::Node::Reader> resolveFinalSchema(uint64_t id) const = 0;
// Get the final schema for the given ID. A bootstrap schema is not acceptable. A raw
// node reader is returned rather than a Schema object because using a Schema object built
// by the final schema loader could trigger lazy initialization of dependencies which could
......@@ -77,17 +77,17 @@ public:
};
NodeTranslator(const Resolver& resolver, const ErrorReporter& errorReporter,
const Declaration::Reader& decl, Orphan<schema2::Node> wipNode,
const Declaration::Reader& decl, Orphan<schema::Node> wipNode,
bool compileAnnotations);
// Construct a NodeTranslator to translate the given declaration. The wipNode starts out with
// `displayName`, `id`, `scopeId`, and `nestedNodes` already initialized. The `NodeTranslator`
// fills in the rest.
struct NodeSet {
schema2::Node::Reader node;
schema::Node::Reader node;
// The main node.
kj::Array<schema2::Node::Reader> auxNodes;
kj::Array<schema::Node::Reader> auxNodes;
// Auxiliary nodes that were produced when translating this node and should be loaded along
// with it. In particular, structs that contain groups (or named unions) spawn extra nodes
// representing those.
......@@ -111,17 +111,17 @@ private:
const ErrorReporter& errorReporter;
bool compileAnnotations;
Orphan<schema2::Node> wipNode;
Orphan<schema::Node> wipNode;
// The work-in-progress schema node.
kj::Vector<Orphan<schema2::Node>> groups;
kj::Vector<Orphan<schema::Node>> groups;
// If this is a struct node and it contains groups, these are the nodes for those groups, which
// must be loaded together with the top-level node.
struct UnfinishedValue {
ValueExpression::Reader source;
schema2::Type::Reader type;
schema2::Value::Builder target;
schema::Type::Reader type;
schema::Value::Builder target;
};
kj::Vector<UnfinishedValue> unfinishedValues;
// List of values in `wipNode` which have not yet been interpreted, because they are structs
......@@ -129,14 +129,14 @@ private:
// of the dynamic API). Once bootstrap schemas have been built, they can be used to interpret
// these values.
void compileNode(Declaration::Reader decl, schema2::Node::Builder builder);
void compileNode(Declaration::Reader decl, schema::Node::Builder builder);
void disallowNested(List<Declaration>::Reader nestedDecls);
// Complain if the nested decl list is non-empty.
void compileConst(Declaration::Const::Reader decl, schema2::Node::Const::Builder builder);
void compileConst(Declaration::Const::Reader decl, schema::Node::Const::Builder builder);
void compileAnnotation(Declaration::Annotation::Reader decl,
schema2::Node::Annotation::Builder builder);
schema::Node::Annotation::Builder builder);
class DuplicateNameDetector;
class DuplicateOrdinalDetector;
......@@ -144,28 +144,28 @@ private:
class StructTranslator;
void compileEnum(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder);
schema::Node::Builder builder);
void compileStruct(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder);
schema::Node::Builder builder);
void compileInterface(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder);
schema::Node::Builder builder);
// The `members` arrays contain only members with ordinal numbers, in code order. Other members
// are handled elsewhere.
bool compileType(TypeExpression::Reader source, schema2::Type::Builder target);
bool compileType(TypeExpression::Reader source, schema::Type::Builder target);
// Returns false if there was a problem, in which case value expressions of this type should
// not be parsed.
void compileDefaultDefaultValue(schema2::Type::Reader type, schema2::Value::Builder target);
void compileDefaultDefaultValue(schema::Type::Reader type, schema::Value::Builder target);
// Initializes `target` to contain the "default default" value for `type`.
void compileBootstrapValue(ValueExpression::Reader source, schema2::Type::Reader type,
schema2::Value::Builder target);
void compileBootstrapValue(ValueExpression::Reader source, schema::Type::Reader type,
schema::Value::Builder target);
// Calls compileValue() if this value should be interpreted at bootstrap time. Otheriwse,
// adds the value to `unfinishedValues` for later evaluation.
void compileValue(ValueExpression::Reader source, schema2::Type::Reader type,
schema2::Value::Builder target, bool isBootstrap);
void compileValue(ValueExpression::Reader source, schema::Type::Reader type,
schema::Value::Builder target, bool isBootstrap);
// Interprets the value expression and initializes `target` with the result.
class DynamicSlot;
......@@ -182,11 +182,11 @@ private:
// Get the value of the given constant. May return null if some error occurs, which will already
// have been reported.
kj::Maybe<ListSchema> makeListSchemaOf(schema2::Type::Reader elementType);
kj::Maybe<ListSchema> makeListSchemaOf(schema::Type::Reader elementType);
// Construct a list schema representing a list of elements of the given type. May return null if
// some error occurs, which will already have been reported.
Orphan<List<schema2::Annotation>> compileAnnotationApplications(
Orphan<List<schema::Annotation>> compileAnnotationApplications(
List<Declaration::AnnotationApplication>::Reader annotations,
kj::StringPtr targetsFlagName);
};
......
This diff is collapsed.
......@@ -176,16 +176,16 @@ template <typename T>
Schema loadUnderAlternateTypeId(SchemaLoader& loader, uint64_t id) {
MallocMessageBuilder schemaBuilder;
schemaBuilder.setRoot(Schema::from<T>().getProto());
auto root = schemaBuilder.getRoot<schema2::Node>();
auto root = schemaBuilder.getRoot<schema::Node>();
root.setId(id);
if (root.which() == schema2::Node::STRUCT) {
if (root.which() == schema::Node::STRUCT) {
// If the struct contains any self-referential members, change their type IDs as well.
auto fields = root.getStruct().getFields();
for (auto field: fields) {
if (field.which() == schema2::Field::REGULAR) {
if (field.which() == schema::Field::REGULAR) {
auto type = field.getRegular().getType();
if (type.which() == schema2::Type::STRUCT &&
if (type.which() == schema::Type::STRUCT &&
type.getStruct() == typeId<T>()) {
type.setStruct(id);
}
......@@ -282,7 +282,7 @@ TEST(SchemaLoader, EnumerateNoPlaceholders) {
class FakeLoaderCallback: public SchemaLoader::LazyLoadCallback {
public:
FakeLoaderCallback(const schema2::Node::Reader node): node(node), loaded(false) {}
FakeLoaderCallback(const schema::Node::Reader node): node(node), loaded(false) {}
bool isLoaded() { return loaded; }
......@@ -299,7 +299,7 @@ public:
}
private:
const schema2::Node::Reader node;
const schema::Node::Reader node;
mutable bool loaded = false;
};
......
This diff is collapsed.
......@@ -76,7 +76,7 @@ public:
kj::Maybe<Schema> tryGet(uint64_t id) const;
// Like get() but doesn't throw.
Schema load(const schema2::Node::Reader& reader);
Schema load(const schema::Node::Reader& reader);
// Loads the given schema node. Validates the node and throws an exception if invalid. This
// makes a copy of the schema, so the object passed in can be destroyed after this returns.
//
......@@ -111,7 +111,7 @@ public:
// Also note that unknown types are not considered invalid. Instead, the dynamic API returns
// a DynamicValue with type UNKNOWN for these.
Schema loadOnce(const schema2::Node::Reader& reader) const;
Schema loadOnce(const schema::Node::Reader& reader) const;
// Like `load()` but does nothing if a schema with the same ID is already loaded. In contrast,
// `load()` would attempt to compare the schemas and take the newer one. `loadOnce()` is safe
// to call even while concurrently using schemas from this loader. It should be considered an
......
......@@ -151,20 +151,20 @@ TEST(Schema, Enums) {
// TODO(someday): Test interface schemas when interfaces are implemented.
TEST(Schema, Lists) {
EXPECT_EQ(schema2::Type::VOID, Schema::from<List<Void>>().whichElementType());
EXPECT_EQ(schema2::Type::BOOL, Schema::from<List<bool>>().whichElementType());
EXPECT_EQ(schema2::Type::INT8, Schema::from<List<int8_t>>().whichElementType());
EXPECT_EQ(schema2::Type::INT16, Schema::from<List<int16_t>>().whichElementType());
EXPECT_EQ(schema2::Type::INT32, Schema::from<List<int32_t>>().whichElementType());
EXPECT_EQ(schema2::Type::INT64, Schema::from<List<int64_t>>().whichElementType());
EXPECT_EQ(schema2::Type::UINT8, Schema::from<List<uint8_t>>().whichElementType());
EXPECT_EQ(schema2::Type::UINT16, Schema::from<List<uint16_t>>().whichElementType());
EXPECT_EQ(schema2::Type::UINT32, Schema::from<List<uint32_t>>().whichElementType());
EXPECT_EQ(schema2::Type::UINT64, Schema::from<List<uint64_t>>().whichElementType());
EXPECT_EQ(schema2::Type::FLOAT32, Schema::from<List<float>>().whichElementType());
EXPECT_EQ(schema2::Type::FLOAT64, Schema::from<List<double>>().whichElementType());
EXPECT_EQ(schema2::Type::TEXT, Schema::from<List<Text>>().whichElementType());
EXPECT_EQ(schema2::Type::DATA, Schema::from<List<Data>>().whichElementType());
EXPECT_EQ(schema::Type::VOID, Schema::from<List<Void>>().whichElementType());
EXPECT_EQ(schema::Type::BOOL, Schema::from<List<bool>>().whichElementType());
EXPECT_EQ(schema::Type::INT8, Schema::from<List<int8_t>>().whichElementType());
EXPECT_EQ(schema::Type::INT16, Schema::from<List<int16_t>>().whichElementType());
EXPECT_EQ(schema::Type::INT32, Schema::from<List<int32_t>>().whichElementType());
EXPECT_EQ(schema::Type::INT64, Schema::from<List<int64_t>>().whichElementType());
EXPECT_EQ(schema::Type::UINT8, Schema::from<List<uint8_t>>().whichElementType());
EXPECT_EQ(schema::Type::UINT16, Schema::from<List<uint16_t>>().whichElementType());
EXPECT_EQ(schema::Type::UINT32, Schema::from<List<uint32_t>>().whichElementType());
EXPECT_EQ(schema::Type::UINT64, Schema::from<List<uint64_t>>().whichElementType());
EXPECT_EQ(schema::Type::FLOAT32, Schema::from<List<float>>().whichElementType());
EXPECT_EQ(schema::Type::FLOAT64, Schema::from<List<double>>().whichElementType());
EXPECT_EQ(schema::Type::TEXT, Schema::from<List<Text>>().whichElementType());
EXPECT_EQ(schema::Type::DATA, Schema::from<List<Data>>().whichElementType());
EXPECT_ANY_THROW(Schema::from<List<uint16_t>>().getStructElementType());
EXPECT_ANY_THROW(Schema::from<List<uint16_t>>().getEnumElementType());
......@@ -173,7 +173,7 @@ TEST(Schema, Lists) {
{
ListSchema schema = Schema::from<List<TestAllTypes>>();
EXPECT_EQ(schema2::Type::STRUCT, schema.whichElementType());
EXPECT_EQ(schema::Type::STRUCT, schema.whichElementType());
EXPECT_TRUE(schema.getStructElementType() == Schema::from<TestAllTypes>());
EXPECT_ANY_THROW(schema.getEnumElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
......@@ -182,7 +182,7 @@ TEST(Schema, Lists) {
{
ListSchema schema = Schema::from<List<TestEnum>>();
EXPECT_EQ(schema2::Type::ENUM, schema.whichElementType());
EXPECT_EQ(schema::Type::ENUM, schema.whichElementType());
EXPECT_TRUE(schema.getEnumElementType() == Schema::from<TestEnum>());
EXPECT_ANY_THROW(schema.getStructElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
......@@ -193,36 +193,36 @@ TEST(Schema, Lists) {
{
ListSchema schema = Schema::from<List<List<int32_t>>>();
EXPECT_EQ(schema2::Type::LIST, schema.whichElementType());
EXPECT_EQ(schema::Type::LIST, schema.whichElementType());
EXPECT_ANY_THROW(schema.getStructElementType());
EXPECT_ANY_THROW(schema.getEnumElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
ListSchema inner = schema.getListElementType();
EXPECT_EQ(schema2::Type::INT32, inner.whichElementType());
EXPECT_EQ(schema::Type::INT32, inner.whichElementType());
}
{
ListSchema schema = Schema::from<List<List<TestAllTypes>>>();
EXPECT_EQ(schema2::Type::LIST, schema.whichElementType());
EXPECT_EQ(schema::Type::LIST, schema.whichElementType());
EXPECT_ANY_THROW(schema.getStructElementType());
EXPECT_ANY_THROW(schema.getEnumElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
ListSchema inner = schema.getListElementType();
EXPECT_EQ(schema2::Type::STRUCT, inner.whichElementType());
EXPECT_EQ(schema::Type::STRUCT, inner.whichElementType());
EXPECT_TRUE(inner.getStructElementType() == Schema::from<TestAllTypes>());
}
{
ListSchema schema = Schema::from<List<List<TestEnum>>>();
EXPECT_EQ(schema2::Type::LIST, schema.whichElementType());
EXPECT_EQ(schema::Type::LIST, schema.whichElementType());
EXPECT_ANY_THROW(schema.getStructElementType());
EXPECT_ANY_THROW(schema.getEnumElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
ListSchema inner = schema.getListElementType();
EXPECT_EQ(schema2::Type::ENUM, inner.whichElementType());
EXPECT_EQ(schema::Type::ENUM, inner.whichElementType());
EXPECT_TRUE(inner.getEnumElementType() == Schema::from<TestEnum>());
}
......@@ -231,7 +231,7 @@ TEST(Schema, Lists) {
auto type = context.getFieldByName("enumList").getProto().getRegular().getType();
ListSchema schema = ListSchema::of(type.getList(), context);
EXPECT_EQ(schema2::Type::ENUM, schema.whichElementType());
EXPECT_EQ(schema::Type::ENUM, schema.whichElementType());
EXPECT_TRUE(schema.getEnumElementType() == Schema::from<TestEnum>());
EXPECT_ANY_THROW(schema.getStructElementType());
EXPECT_ANY_THROW(schema.getInterfaceElementType());
......
......@@ -27,8 +27,8 @@
namespace capnp {
schema2::Node::Reader Schema::getProto() const {
return readMessageUnchecked<schema2::Node>(raw->encodedNode);
schema::Node::Reader Schema::getProto() const {
return readMessageUnchecked<schema::Node>(raw->encodedNode);
}
kj::ArrayPtr<const word> Schema::asUncheckedMessage() const {
......@@ -60,21 +60,21 @@ Schema Schema::getDependency(uint64_t id) const {
}
StructSchema Schema::asStruct() const {
KJ_REQUIRE(getProto().which() == schema2::Node::STRUCT,
KJ_REQUIRE(getProto().which() == schema::Node::STRUCT,
"Tried to use non-struct schema as a struct.",
getProto().getDisplayName());
return StructSchema(raw);
}
EnumSchema Schema::asEnum() const {
KJ_REQUIRE(getProto().which() == schema2::Node::ENUM,
KJ_REQUIRE(getProto().which() == schema::Node::ENUM,
"Tried to use non-enum schema as an enum.",
getProto().getDisplayName());
return EnumSchema(raw);
}
InterfaceSchema Schema::asInterface() const {
KJ_REQUIRE(getProto().which() == schema2::Node::INTERFACE,
KJ_REQUIRE(getProto().which() == schema::Node::INTERFACE,
"Tried to use non-interface schema as an interface.",
getProto().getDisplayName());
return InterfaceSchema(raw);
......@@ -163,19 +163,19 @@ uint32_t StructSchema::Field::getDefaultValueSchemaOffset() const {
const word* ptr;
switch (defaultValue.which()) {
case schema2::Value::TEXT:
case schema::Value::TEXT:
ptr = reinterpret_cast<const word*>(defaultValue.getText().begin());
break;
case schema2::Value::DATA:
case schema::Value::DATA:
ptr = reinterpret_cast<const word*>(defaultValue.getData().begin());
break;
case schema2::Value::STRUCT:
case schema::Value::STRUCT:
ptr = defaultValue.getStruct<_::UncheckedMessage>();
break;
case schema2::Value::LIST:
case schema::Value::LIST:
ptr = defaultValue.getList<_::UncheckedMessage>();
break;
case schema2::Value::OBJECT:
case schema::Value::OBJECT:
ptr = defaultValue.getObject<_::UncheckedMessage>();
break;
default:
......@@ -224,32 +224,32 @@ InterfaceSchema::Method InterfaceSchema::getMethodByName(kj::StringPtr name) con
// =======================================================================================
ListSchema ListSchema::of(schema2::Type::Which primitiveType) {
ListSchema ListSchema::of(schema::Type::Which primitiveType) {
switch (primitiveType) {
case schema2::Type::VOID:
case schema2::Type::BOOL:
case schema2::Type::INT8:
case schema2::Type::INT16:
case schema2::Type::INT32:
case schema2::Type::INT64:
case schema2::Type::UINT8:
case schema2::Type::UINT16:
case schema2::Type::UINT32:
case schema2::Type::UINT64:
case schema2::Type::FLOAT32:
case schema2::Type::FLOAT64:
case schema2::Type::TEXT:
case schema2::Type::DATA:
case schema::Type::VOID:
case schema::Type::BOOL:
case schema::Type::INT8:
case schema::Type::INT16:
case schema::Type::INT32:
case schema::Type::INT64:
case schema::Type::UINT8:
case schema::Type::UINT16:
case schema::Type::UINT32:
case schema::Type::UINT64:
case schema::Type::FLOAT32:
case schema::Type::FLOAT64:
case schema::Type::TEXT:
case schema::Type::DATA:
break;
case schema2::Type::STRUCT:
case schema2::Type::ENUM:
case schema2::Type::INTERFACE:
case schema2::Type::LIST:
case schema::Type::STRUCT:
case schema::Type::ENUM:
case schema::Type::INTERFACE:
case schema::Type::LIST:
KJ_FAIL_REQUIRE("Must use one of the other ListSchema::of() overloads for complex types.");
break;
case schema2::Type::OBJECT:
case schema::Type::OBJECT:
KJ_FAIL_REQUIRE("List(Object) not supported.");
break;
}
......@@ -257,37 +257,37 @@ ListSchema ListSchema::of(schema2::Type::Which primitiveType) {
return ListSchema(primitiveType);
}
ListSchema ListSchema::of(schema2::Type::Reader elementType, Schema context) {
ListSchema ListSchema::of(schema::Type::Reader elementType, Schema context) {
switch (elementType.which()) {
case schema2::Type::VOID:
case schema2::Type::BOOL:
case schema2::Type::INT8:
case schema2::Type::INT16:
case schema2::Type::INT32:
case schema2::Type::INT64:
case schema2::Type::UINT8:
case schema2::Type::UINT16:
case schema2::Type::UINT32:
case schema2::Type::UINT64:
case schema2::Type::FLOAT32:
case schema2::Type::FLOAT64:
case schema2::Type::TEXT:
case schema2::Type::DATA:
case schema::Type::VOID:
case schema::Type::BOOL:
case schema::Type::INT8:
case schema::Type::INT16:
case schema::Type::INT32:
case schema::Type::INT64:
case schema::Type::UINT8:
case schema::Type::UINT16:
case schema::Type::UINT32:
case schema::Type::UINT64:
case schema::Type::FLOAT32:
case schema::Type::FLOAT64:
case schema::Type::TEXT:
case schema::Type::DATA:
return of(elementType.which());
case schema2::Type::STRUCT:
case schema::Type::STRUCT:
return of(context.getDependency(elementType.getStruct()).asStruct());
case schema2::Type::ENUM:
case schema::Type::ENUM:
return of(context.getDependency(elementType.getEnum()).asEnum());
case schema2::Type::INTERFACE:
case schema::Type::INTERFACE:
return of(context.getDependency(elementType.getInterface()).asInterface());
case schema2::Type::LIST:
case schema::Type::LIST:
return of(of(elementType.getList(), context));
case schema2::Type::OBJECT:
case schema::Type::OBJECT:
KJ_FAIL_REQUIRE("List(Object) not supported.");
return ListSchema();
}
......@@ -297,19 +297,19 @@ ListSchema ListSchema::of(schema2::Type::Reader elementType, Schema context) {
}
StructSchema ListSchema::getStructElementType() const {
KJ_REQUIRE(nestingDepth == 0 && elementType == schema2::Type::STRUCT,
KJ_REQUIRE(nestingDepth == 0 && elementType == schema::Type::STRUCT,
"ListSchema::getStructElementType(): The elements are not structs.");
return elementSchema.asStruct();
}
EnumSchema ListSchema::getEnumElementType() const {
KJ_REQUIRE(nestingDepth == 0 && elementType == schema2::Type::ENUM,
KJ_REQUIRE(nestingDepth == 0 && elementType == schema::Type::ENUM,
"ListSchema::getEnumElementType(): The elements are not enums.");
return elementSchema.asEnum();
}
InterfaceSchema ListSchema::getInterfaceElementType() const {
KJ_REQUIRE(nestingDepth == 0 && elementType == schema2::Type::INTERFACE,
KJ_REQUIRE(nestingDepth == 0 && elementType == schema::Type::INTERFACE,
"ListSchema::getInterfaceElementType(): The elements are not interfaces.");
return elementSchema.asInterface();
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -99,19 +99,19 @@ private:
}
};
static schema2::Type::Which whichFieldType(const StructSchema::Field& field) {
static schema::Type::Which whichFieldType(const StructSchema::Field& field) {
auto proto = field.getProto();
switch (proto.which()) {
case schema2::Field::REGULAR:
case schema::Field::REGULAR:
return proto.getRegular().getType().which();
case schema2::Field::GROUP:
return schema2::Type::STRUCT;
case schema::Field::GROUP:
return schema::Type::STRUCT;
}
KJ_UNREACHABLE;
}
static kj::StringTree print(const DynamicValue::Reader& value,
schema2::Type::Which which, Indent indent,
schema::Type::Which which, Indent indent,
PrintMode mode) {
switch (value.getType()) {
case DynamicValue::UNKNOWN:
......@@ -125,7 +125,7 @@ static kj::StringTree print(const DynamicValue::Reader& value,
case DynamicValue::UINT:
return kj::strTree(value.as<uint64_t>());
case DynamicValue::FLOAT:
if (which == schema2::Type::FLOAT32) {
if (which == schema::Type::FLOAT32) {
return kj::strTree(value.as<float>());
} else {
return kj::strTree(value.as<double>());
......@@ -242,17 +242,17 @@ static kj::StringTree print(const DynamicValue::Reader& value,
}
kj::StringTree stringify(DynamicValue::Reader value) {
return print(value, schema2::Type::STRUCT, Indent(false), BARE);
return print(value, schema::Type::STRUCT, Indent(false), BARE);
}
} // namespace
kj::StringTree prettyPrint(DynamicStruct::Reader value) {
return print(value, schema2::Type::STRUCT, Indent(true), BARE);
return print(value, schema::Type::STRUCT, Indent(true), BARE);
}
kj::StringTree prettyPrint(DynamicList::Reader value) {
return print(value, schema2::Type::LIST, Indent(true), BARE);
return print(value, schema::Type::LIST, Indent(true), BARE);
}
kj::StringTree prettyPrint(DynamicStruct::Builder value) { return prettyPrint(value.asReader()); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment