Commit 7b8bbc87 authored by Kenton Varda's avatar Kenton Varda

Refactor grammar.capnp to use unnamed unions.

parent 4288dd27
...@@ -67,11 +67,11 @@ public: ...@@ -67,11 +67,11 @@ public:
Node(const Node& parent, const Declaration::Reader& declaration); Node(const Node& parent, const Declaration::Reader& declaration);
// Create a child node. // Create a child node.
Node(kj::StringPtr name, Declaration::Body::Which kind); Node(kj::StringPtr name, Declaration::Which kind);
// Create a dummy node representing a built-in declaration, like "Int32" or "true". // Create a dummy node representing a built-in declaration, like "Int32" or "true".
uint64_t getId() const { return id; } uint64_t getId() const { return id; }
Declaration::Body::Which getKind() const { return kind; } Declaration::Which getKind() const { return kind; }
kj::Maybe<const Node&> lookupMember(kj::StringPtr name) const; kj::Maybe<const Node&> lookupMember(kj::StringPtr name) const;
// Find a direct member of this node with the given name. // Find a direct member of this node with the given name.
...@@ -115,7 +115,7 @@ private: ...@@ -115,7 +115,7 @@ private:
// Fully-qualified display name for this node. For files, this is just the file name, otherwise // Fully-qualified display name for this node. For files, this is just the file name, otherwise
// it is "filename:Path.To.Decl". // it is "filename:Path.To.Decl".
Declaration::Body::Which kind; Declaration::Which kind;
// Kind of node. // Kind of node.
bool isBuiltin; bool isBuiltin;
...@@ -337,7 +337,7 @@ Compiler::Node::Node(CompiledModule& module) ...@@ -337,7 +337,7 @@ Compiler::Node::Node(CompiledModule& module)
declaration(module.getParsedFile().getRoot()), declaration(module.getParsedFile().getRoot()),
id(generateId(0, declaration.getName().getValue(), declaration.getId())), id(generateId(0, declaration.getName().getValue(), declaration.getId())),
displayName(module.getSourceName()), displayName(module.getSourceName()),
kind(declaration.getBody().which()), kind(declaration.which()),
isBuiltin(false) { isBuiltin(false) {
auto name = declaration.getName(); auto name = declaration.getName();
if (name.getValue().size() > 0) { if (name.getValue().size() > 0) {
...@@ -358,7 +358,7 @@ Compiler::Node::Node(const Node& parent, const Declaration::Reader& declaration) ...@@ -358,7 +358,7 @@ Compiler::Node::Node(const Node& parent, const Declaration::Reader& declaration)
id(generateId(parent.id, declaration.getName().getValue(), declaration.getId())), id(generateId(parent.id, declaration.getName().getValue(), declaration.getId())),
displayName(joinDisplayName(parent.module->getCompiler().getNodeArena(), displayName(joinDisplayName(parent.module->getCompiler().getNodeArena(),
parent, declaration.getName().getValue())), parent, declaration.getName().getValue())),
kind(declaration.getBody().which()), kind(declaration.which()),
isBuiltin(false) { isBuiltin(false) {
auto name = declaration.getName(); auto name = declaration.getName();
if (name.getValue().size() > 0) { if (name.getValue().size() > 0) {
...@@ -372,7 +372,7 @@ Compiler::Node::Node(const Node& parent, const Declaration::Reader& declaration) ...@@ -372,7 +372,7 @@ Compiler::Node::Node(const Node& parent, const Declaration::Reader& declaration)
id = module->getCompiler().addNode(id, *this); id = module->getCompiler().addNode(id, *this);
} }
Compiler::Node::Node(kj::StringPtr name, Declaration::Body::Which kind) Compiler::Node::Node(kj::StringPtr name, Declaration::Which kind)
: module(nullptr), : module(nullptr),
parent(nullptr), parent(nullptr),
id(0), id(0),
...@@ -421,13 +421,13 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum ...@@ -421,13 +421,13 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
auto& arena = module->getCompiler().getNodeArena(); auto& arena = module->getCompiler().getNodeArena();
for (auto nestedDecl: declaration.getNestedDecls()) { for (auto nestedDecl: declaration.getNestedDecls()) {
switch (nestedDecl.getBody().which()) { switch (nestedDecl.which()) {
case Declaration::Body::FILE_DECL: case Declaration::FILE:
case Declaration::Body::CONST_DECL: case Declaration::CONST:
case Declaration::Body::ANNOTATION_DECL: case Declaration::ANNOTATION:
case Declaration::Body::ENUM_DECL: case Declaration::ENUM:
case Declaration::Body::STRUCT_DECL: case Declaration::STRUCT:
case Declaration::Body::INTERFACE_DECL: { case Declaration::INTERFACE: {
kj::Own<Node> subNode = arena.allocateOwn<Node>(*this, nestedDecl); kj::Own<Node> subNode = arena.allocateOwn<Node>(*this, nestedDecl);
kj::StringPtr name = nestedDecl.getName().getValue(); kj::StringPtr name = nestedDecl.getName().getValue();
locked->orderedNestedNodes.add(subNode); locked->orderedNestedNodes.add(subNode);
...@@ -435,20 +435,20 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum ...@@ -435,20 +435,20 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
break; break;
} }
case Declaration::Body::USING_DECL: { case Declaration::USING: {
kj::Own<Alias> alias = arena.allocateOwn<Alias>( kj::Own<Alias> alias = arena.allocateOwn<Alias>(
*this, nestedDecl.getBody().getUsingDecl().getTarget()); *this, nestedDecl.getUsing().getTarget());
kj::StringPtr name = nestedDecl.getName().getValue(); kj::StringPtr name = nestedDecl.getName().getValue();
locked->aliases.insert(std::make_pair(name, kj::mv(alias))); locked->aliases.insert(std::make_pair(name, kj::mv(alias)));
break; break;
} }
case Declaration::Body::ENUMERANT_DECL: case Declaration::ENUMERANT:
case Declaration::Body::FIELD_DECL: case Declaration::FIELD:
case Declaration::Body::UNION_DECL: case Declaration::UNION:
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
case Declaration::Body::METHOD_DECL: case Declaration::METHOD:
case Declaration::Body::NAKED_ID: case Declaration::NAKED_ID:
case Declaration::Body::NAKED_ANNOTATION: case Declaration::NAKED_ANNOTATION:
// Not a node. Skip. // Not a node. Skip.
break; break;
default: default:
...@@ -841,18 +841,18 @@ static void findImports(TypeExpression::Reader type, std::set<kj::StringPtr>& ou ...@@ -841,18 +841,18 @@ static void findImports(TypeExpression::Reader type, std::set<kj::StringPtr>& ou
} }
static void findImports(Declaration::Reader decl, std::set<kj::StringPtr>& output) { static void findImports(Declaration::Reader decl, std::set<kj::StringPtr>& output) {
switch (decl.getBody().which()) { switch (decl.which()) {
case Declaration::Body::USING_DECL: case Declaration::USING:
findImports(decl.getBody().getUsingDecl().getTarget(), output); findImports(decl.getUsing().getTarget(), output);
break; break;
case Declaration::Body::CONST_DECL: case Declaration::CONST:
findImports(decl.getBody().getConstDecl().getType(), output); findImports(decl.getConst().getType(), output);
break; break;
case Declaration::Body::FIELD_DECL: case Declaration::FIELD:
findImports(decl.getBody().getFieldDecl().getType(), output); findImports(decl.getField().getType(), output);
break; break;
case Declaration::Body::METHOD_DECL: { case Declaration::METHOD: {
auto method = decl.getBody().getMethodDecl(); auto method = decl.getMethod();
for (auto param: method.getParams()) { for (auto param: method.getParams()) {
findImports(param.getType(), output); findImports(param.getType(), output);
for (auto ann: param.getAnnotations()) { for (auto ann: param.getAnnotations()) {
...@@ -905,22 +905,22 @@ Compiler::Impl::Impl(AnnotationFlag annotationFlag) ...@@ -905,22 +905,22 @@ Compiler::Impl::Impl(AnnotationFlag annotationFlag)
// defines a builtin declaration visible in the global scope. // defines a builtin declaration visible in the global scope.
#warning "temporary hack for schema transition" #warning "temporary hack for schema transition"
builtinDecls["Void"] = nodeArena.allocateOwn<Node>("Void", Declaration::Body::BUILTIN_VOID); builtinDecls["Void"] = nodeArena.allocateOwn<Node>("Void", Declaration::BUILTIN_VOID);
builtinDecls["Bool"] = nodeArena.allocateOwn<Node>("Bool", Declaration::Body::BUILTIN_BOOL); builtinDecls["Bool"] = nodeArena.allocateOwn<Node>("Bool", Declaration::BUILTIN_BOOL);
builtinDecls["Int8"] = nodeArena.allocateOwn<Node>("Int8", Declaration::Body::BUILTIN_INT8); builtinDecls["Int8"] = nodeArena.allocateOwn<Node>("Int8", Declaration::BUILTIN_INT8);
builtinDecls["Int16"] = nodeArena.allocateOwn<Node>("Int16", Declaration::Body::BUILTIN_INT16); builtinDecls["Int16"] = nodeArena.allocateOwn<Node>("Int16", Declaration::BUILTIN_INT16);
builtinDecls["Int32"] = nodeArena.allocateOwn<Node>("Int32", Declaration::Body::BUILTIN_INT32); builtinDecls["Int32"] = nodeArena.allocateOwn<Node>("Int32", Declaration::BUILTIN_INT32);
builtinDecls["Int64"] = nodeArena.allocateOwn<Node>("Int64", Declaration::Body::BUILTIN_INT64); builtinDecls["Int64"] = nodeArena.allocateOwn<Node>("Int64", Declaration::BUILTIN_INT64);
builtinDecls["UInt8"] = nodeArena.allocateOwn<Node>("UInt8", Declaration::Body::BUILTIN_U_INT8); builtinDecls["UInt8"] = nodeArena.allocateOwn<Node>("UInt8", Declaration::BUILTIN_U_INT8);
builtinDecls["UInt16"] = nodeArena.allocateOwn<Node>("UInt16", Declaration::Body::BUILTIN_U_INT16); builtinDecls["UInt16"] = nodeArena.allocateOwn<Node>("UInt16", Declaration::BUILTIN_U_INT16);
builtinDecls["UInt32"] = nodeArena.allocateOwn<Node>("UInt32", Declaration::Body::BUILTIN_U_INT32); builtinDecls["UInt32"] = nodeArena.allocateOwn<Node>("UInt32", Declaration::BUILTIN_U_INT32);
builtinDecls["UInt64"] = nodeArena.allocateOwn<Node>("UInt64", Declaration::Body::BUILTIN_U_INT64); builtinDecls["UInt64"] = nodeArena.allocateOwn<Node>("UInt64", Declaration::BUILTIN_U_INT64);
builtinDecls["Float32"] = nodeArena.allocateOwn<Node>("Float32", Declaration::Body::BUILTIN_FLOAT32); builtinDecls["Float32"] = nodeArena.allocateOwn<Node>("Float32", Declaration::BUILTIN_FLOAT32);
builtinDecls["Float64"] = nodeArena.allocateOwn<Node>("Float64", Declaration::Body::BUILTIN_FLOAT64); builtinDecls["Float64"] = nodeArena.allocateOwn<Node>("Float64", Declaration::BUILTIN_FLOAT64);
builtinDecls["Text"] = nodeArena.allocateOwn<Node>("Text", Declaration::Body::BUILTIN_TEXT); builtinDecls["Text"] = nodeArena.allocateOwn<Node>("Text", Declaration::BUILTIN_TEXT);
builtinDecls["Data"] = nodeArena.allocateOwn<Node>("Data", Declaration::Body::BUILTIN_DATA); builtinDecls["Data"] = nodeArena.allocateOwn<Node>("Data", Declaration::BUILTIN_DATA);
builtinDecls["List"] = nodeArena.allocateOwn<Node>("List", Declaration::Body::BUILTIN_LIST); builtinDecls["List"] = nodeArena.allocateOwn<Node>("List", Declaration::BUILTIN_LIST);
builtinDecls["Object"] = nodeArena.allocateOwn<Node>("Object", Declaration::Body::BUILTIN_OBJECT); builtinDecls["Object"] = nodeArena.allocateOwn<Node>("Object", Declaration::BUILTIN_OBJECT);
#if 0 #if 0
StructSchema::Union declBodySchema = StructSchema::Union declBodySchema =
...@@ -930,7 +930,7 @@ Compiler::Impl::Impl(AnnotationFlag annotationFlag) ...@@ -930,7 +930,7 @@ Compiler::Impl::Impl(AnnotationFlag annotationFlag)
if (name.startsWith("builtin")) { if (name.startsWith("builtin")) {
kj::StringPtr symbolName = name.slice(strlen("builtin")); kj::StringPtr symbolName = name.slice(strlen("builtin"));
builtinDecls[symbolName] = nodeArena.allocateOwn<Node>( builtinDecls[symbolName] = nodeArena.allocateOwn<Node>(
symbolName, static_cast<Declaration::Body::Which>(member.getIndex())); symbolName, static_cast<Declaration::Which>(member.getIndex()));
} }
} }
#endif #endif
......
...@@ -59,19 +59,19 @@ struct DeclName { ...@@ -59,19 +59,19 @@ struct DeclName {
# * `.absolute.path.to.SomeType` # * `.absolute.path.to.SomeType`
# * `import "foo.capnp"` # * `import "foo.capnp"`
base @0 union { base :union {
# The first element of the name. # The first element of the name.
absoluteName @1 :LocatedText; # A symbol at the global scope. absoluteName @0 :LocatedText; # A symbol at the global scope.
relativeName @2 :LocatedText; # A symbol that should be looked up lexically. relativeName @1 :LocatedText; # A symbol that should be looked up lexically.
importName @3 :LocatedText; # A file name to import. importName @2 :LocatedText; # A file name to import.
} }
memberPath @4 :List(LocatedText); memberPath @3 :List(LocatedText);
# List of `.member` suffixes. # List of `.member` suffixes.
startByte @5 :UInt32; startByte @4 :UInt32;
endByte @6 :UInt32; endByte @5 :UInt32;
} }
struct TypeExpression { struct TypeExpression {
...@@ -92,28 +92,24 @@ struct TypeExpression { ...@@ -92,28 +92,24 @@ struct TypeExpression {
struct ValueExpression { struct ValueExpression {
# An expression evaluating to a value. # An expression evaluating to a value.
body @0 union { union {
unknown @1 :Void; # e.g. parse error; downstream should ignore unknown @0 :Void; # e.g. parse error; downstream should ignore
positiveInt @2 :UInt64; positiveInt @1 :UInt64;
negativeInt @3 :UInt64; negativeInt @2 :UInt64;
float @4 :Float64; float @3 :Float64;
string @5 :Text; string @4 :Text;
name @6 :DeclName; name @5 :DeclName;
list @7 :List(ValueExpression); list @6 :List(ValueExpression);
structValue @8 :List(FieldAssignment); struct @7 :List(FieldAssignment);
} }
struct FieldAssignment { struct FieldAssignment {
fieldName @0 :LocatedText; fieldName @0 :LocatedText;
union { value @1 :ValueExpression;
notUnion @1 :Void;
union @2 :LocatedText; # Name of union member being assigned.
}
value @3 :ValueExpression;
} }
startByte @9 :UInt32; startByte @8 :UInt32;
endByte @10 :UInt32; endByte @9 :UInt32;
} }
struct Declaration { struct Declaration {
...@@ -121,133 +117,116 @@ struct Declaration { ...@@ -121,133 +117,116 @@ struct Declaration {
name @0 :LocatedText; name @0 :LocatedText;
id @1 union { id :union {
unspecified @2 :Void; unspecified @1 :Void;
uid @3 :LocatedInteger; uid @2 :LocatedInteger;
ordinal @4 :LocatedInteger; # limited to 16 bits ordinal @3 :LocatedInteger; # limited to 16 bits
} }
nestedDecls @17 :List(Declaration); nestedDecls @4 :List(Declaration);
annotations @5 :List(AnnotationApplication); annotations @5 :List(AnnotationApplication);
struct AnnotationApplication { struct AnnotationApplication {
name @0 :DeclName; name @0 :DeclName;
value @1 union { value :union {
none @2 :Void; # None specified; implies void value. none @1 :Void; # None specified; implies void value.
expression @3 :ValueExpression; expression @2 :ValueExpression;
} }
} }
startByte @18 :UInt32; startByte @6 :UInt32;
endByte @19 :UInt32; endByte @7 :UInt32;
docComment @20 :Text;
body @6 union {
fileDecl @24 :File;
usingDecl @7 :Using;
constDecl @8 :Const;
enumDecl @9 :Enum;
enumerantDecl @10 :Enumerant;
structDecl @11 :Struct;
fieldDecl @12 :Field;
unionDecl @13 :Union;
groupDecl @23 :Group;
interfaceDecl @14 :Interface;
methodDecl @15 :Method;
annotationDecl @16 :Annotation;
nakedId @21 :LocatedInteger;
nakedAnnotation @22 :AnnotationApplication;
# A floating UID or annotation (allowed at the file top level).
# The following declaration types are not produced by the parser, but are declared here
# so that the compiler can handle symbol name lookups more uniformly.
#
# New union members added here will magically become visible in the global scope.
# E.g. "builtinFoo" becomes visible as "Foo".
builtinVoid @25 :Void;
builtinBool @26 :Void;
builtinInt8 @27 :Void;
builtinInt16 @28 :Void;
builtinInt32 @29 :Void;
builtinInt64 @30 :Void;
builtinUInt8 @31 :Void;
builtinUInt16 @32 :Void;
builtinUInt32 @33 :Void;
builtinUInt64 @34 :Void;
builtinFloat32 @35 :Void;
builtinFloat64 @36 :Void;
builtinText @37 :Void;
builtinData @38 :Void;
builtinList @39 :Void;
builtinObject @40 :Void;
}
struct File {}
struct Using {
target @0 :DeclName;
}
struct Const {
type @0 :TypeExpression;
value @1 :ValueExpression;
}
struct Enum {} docComment @8 :Text;
struct Enumerant {} union {
file @9 :Void;
struct Struct {} using :group {
target @10 :DeclName;
struct Field {
type @0 :TypeExpression;
defaultValue @1 union {
none @2 :Void;
value @3 :ValueExpression;
} }
}
struct Union {} const :group {
type @11 :TypeExpression;
struct Group {} value @12 :ValueExpression;
}
struct Interface {} enum @13 :Void;
enumerant @14 :Void;
struct Method { struct @15 :Void;
params @0 :List(Param); field :group {
struct Param { type @16 :TypeExpression;
name @0 :LocatedText; # If null, param failed to parse. defaultValue :union {
type @1 :TypeExpression; none @17 :Void;
annotations @2 :List(AnnotationApplication); value @18 :ValueExpression;
defaultValue @3 union { }
none @4 :Void; }
value @5 :ValueExpression; union @19 :Void;
group @20 :Void;
interface @21 :Void;
method :group {
params @22 :List(Param);
returnType :union {
none @23 :Void;
expression @24 :TypeExpression;
} }
} }
returnType @1 union { annotation :group {
none @2 :Void; # No return type specified; implied Void. type @25 :TypeExpression;
expression @3 :TypeExpression;
targetsFile @26 :Bool;
targetsConst @27 :Bool;
targetsEnum @28 :Bool;
targetsEnumerant @29 :Bool;
targetsStruct @30 :Bool;
targetsField @31 :Bool;
targetsUnion @32 :Bool;
targetsGroup @33 :Bool;
targetsInterface @34 :Bool;
targetsMethod @35 :Bool;
targetsParam @36 :Bool;
targetsAnnotation @37 :Bool;
} }
nakedId @38 :LocatedInteger;
nakedAnnotation @39 :AnnotationApplication;
# A floating UID or annotation (allowed at the file top level).
# The following declaration types are not produced by the parser, but are declared here
# so that the compiler can handle symbol name lookups more uniformly.
#
# New union members added here will magically become visible in the global scope.
# E.g. "builtinFoo" becomes visible as "Foo".
builtinVoid @40 :Void;
builtinBool @41 :Void;
builtinInt8 @42 :Void;
builtinInt16 @43 :Void;
builtinInt32 @44 :Void;
builtinInt64 @45 :Void;
builtinUInt8 @46 :Void;
builtinUInt16 @47 :Void;
builtinUInt32 @48 :Void;
builtinUInt64 @49 :Void;
builtinFloat32 @50 :Void;
builtinFloat64 @51 :Void;
builtinText @52 :Void;
builtinData @53 :Void;
builtinList @54 :Void;
builtinObject @55 :Void;
} }
struct Annotation { struct Param {
type @0 :TypeExpression; name @0 :LocatedText; # If null, param failed to parse.
type @1 :TypeExpression;
targetsFile @1 :Bool; annotations @2 :List(AnnotationApplication);
targetsConst @2 :Bool; defaultValue @3 union {
targetsEnum @3 :Bool; none @4 :Void;
targetsEnumerant @4 :Bool; value @5 :ValueExpression;
targetsStruct @5 :Bool; }
targetsField @6 :Bool;
targetsUnion @7 :Bool;
targetsInterface @8 :Bool;
targetsMethod @9 :Bool;
targetsParam @10 :Bool;
targetsAnnotation @11 :Bool;
} }
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -555,7 +555,7 @@ class NodeTranslator::DuplicateNameDetector { ...@@ -555,7 +555,7 @@ class NodeTranslator::DuplicateNameDetector {
public: public:
inline explicit DuplicateNameDetector(const ErrorReporter& errorReporter) inline explicit DuplicateNameDetector(const ErrorReporter& errorReporter)
: errorReporter(errorReporter) {} : errorReporter(errorReporter) {}
void check(List<Declaration>::Reader nestedDecls, Declaration::Body::Which parentKind); void check(List<Declaration>::Reader nestedDecls, Declaration::Which parentKind);
private: private:
const ErrorReporter& errorReporter; const ErrorReporter& errorReporter;
...@@ -564,32 +564,32 @@ private: ...@@ -564,32 +564,32 @@ private:
void NodeTranslator::compileNode(Declaration::Reader decl, schema2::Node::Builder builder) { void NodeTranslator::compileNode(Declaration::Reader decl, schema2::Node::Builder builder) {
DuplicateNameDetector(errorReporter) DuplicateNameDetector(errorReporter)
.check(decl.getNestedDecls(), decl.getBody().which()); .check(decl.getNestedDecls(), decl.which());
kj::StringPtr targetsFlagName; kj::StringPtr targetsFlagName;
switch (decl.getBody().which()) { switch (decl.which()) {
case Declaration::Body::FILE_DECL: case Declaration::FILE:
targetsFlagName = "targetsFile"; targetsFlagName = "targetsFile";
break; break;
case Declaration::Body::CONST_DECL: case Declaration::CONST:
compileConst(decl.getBody().getConstDecl(), builder.initConst()); compileConst(decl.getConst(), builder.initConst());
targetsFlagName = "targetsConst"; targetsFlagName = "targetsConst";
break; break;
case Declaration::Body::ANNOTATION_DECL: case Declaration::ANNOTATION:
compileAnnotation(decl.getBody().getAnnotationDecl(), builder.initAnnotation()); compileAnnotation(decl.getAnnotation(), builder.initAnnotation());
targetsFlagName = "targetsAnnotation"; targetsFlagName = "targetsAnnotation";
break; break;
case Declaration::Body::ENUM_DECL: case Declaration::ENUM:
compileEnum(decl.getBody().getEnumDecl(), decl.getNestedDecls(), builder); compileEnum(decl.getEnum(), decl.getNestedDecls(), builder);
targetsFlagName = "targetsEnum"; targetsFlagName = "targetsEnum";
break; break;
case Declaration::Body::STRUCT_DECL: case Declaration::STRUCT:
compileStruct(decl.getBody().getStructDecl(), decl.getNestedDecls(), builder); compileStruct(decl.getStruct(), decl.getNestedDecls(), builder);
targetsFlagName = "targetsStruct"; targetsFlagName = "targetsStruct";
break; break;
case Declaration::Body::INTERFACE_DECL: case Declaration::INTERFACE:
compileInterface(decl.getBody().getInterfaceDecl(), decl.getNestedDecls(), builder); compileInterface(decl.getInterface(), decl.getNestedDecls(), builder);
targetsFlagName = "targetsInterface"; targetsFlagName = "targetsInterface";
break; break;
...@@ -602,14 +602,14 @@ void NodeTranslator::compileNode(Declaration::Reader decl, schema2::Node::Builde ...@@ -602,14 +602,14 @@ void NodeTranslator::compileNode(Declaration::Reader decl, schema2::Node::Builde
} }
void NodeTranslator::DuplicateNameDetector::check( void NodeTranslator::DuplicateNameDetector::check(
List<Declaration>::Reader nestedDecls, Declaration::Body::Which parentKind) { List<Declaration>::Reader nestedDecls, Declaration::Which parentKind) {
for (auto decl: nestedDecls) { for (auto decl: nestedDecls) {
{ {
auto name = decl.getName(); auto name = decl.getName();
auto nameText = name.getValue(); auto nameText = name.getValue();
auto insertResult = names.insert(std::make_pair(nameText, name)); auto insertResult = names.insert(std::make_pair(nameText, name));
if (!insertResult.second) { if (!insertResult.second) {
if (nameText.size() == 0 && decl.getBody().which() == Declaration::Body::UNION_DECL) { if (nameText.size() == 0 && decl.which() == Declaration::UNION) {
errorReporter.addErrorOn( errorReporter.addErrorOn(
name, kj::str("An unnamed union is already defined in this scope.")); name, kj::str("An unnamed union is already defined in this scope."));
errorReporter.addErrorOn( errorReporter.addErrorOn(
...@@ -623,17 +623,17 @@ void NodeTranslator::DuplicateNameDetector::check( ...@@ -623,17 +623,17 @@ void NodeTranslator::DuplicateNameDetector::check(
} }
} }
switch (decl.getBody().which()) { switch (decl.which()) {
case Declaration::Body::USING_DECL: case Declaration::USING:
case Declaration::Body::CONST_DECL: case Declaration::CONST:
case Declaration::Body::ENUM_DECL: case Declaration::ENUM:
case Declaration::Body::STRUCT_DECL: case Declaration::STRUCT:
case Declaration::Body::INTERFACE_DECL: case Declaration::INTERFACE:
case Declaration::Body::ANNOTATION_DECL: case Declaration::ANNOTATION:
switch (parentKind) { switch (parentKind) {
case Declaration::Body::FILE_DECL: case Declaration::FILE:
case Declaration::Body::STRUCT_DECL: case Declaration::STRUCT:
case Declaration::Body::INTERFACE_DECL: case Declaration::INTERFACE:
// OK. // OK.
break; break;
default: default:
...@@ -642,23 +642,23 @@ void NodeTranslator::DuplicateNameDetector::check( ...@@ -642,23 +642,23 @@ void NodeTranslator::DuplicateNameDetector::check(
} }
break; break;
case Declaration::Body::ENUMERANT_DECL: case Declaration::ENUMERANT:
if (parentKind != Declaration::Body::ENUM_DECL) { if (parentKind != Declaration::ENUM) {
errorReporter.addErrorOn(decl, "Enumerants can only appear in enums."); errorReporter.addErrorOn(decl, "Enumerants can only appear in enums.");
} }
break; break;
case Declaration::Body::METHOD_DECL: case Declaration::METHOD:
if (parentKind != Declaration::Body::INTERFACE_DECL) { if (parentKind != Declaration::INTERFACE) {
errorReporter.addErrorOn(decl, "Methods can only appear in interfaces."); errorReporter.addErrorOn(decl, "Methods can only appear in interfaces.");
} }
break; break;
case Declaration::Body::FIELD_DECL: case Declaration::FIELD:
case Declaration::Body::UNION_DECL: case Declaration::UNION:
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
switch (parentKind) { switch (parentKind) {
case Declaration::Body::STRUCT_DECL: case Declaration::STRUCT:
case Declaration::Body::UNION_DECL: case Declaration::UNION:
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
// OK. // OK.
break; break;
default: default:
...@@ -670,11 +670,11 @@ void NodeTranslator::DuplicateNameDetector::check( ...@@ -670,11 +670,11 @@ void NodeTranslator::DuplicateNameDetector::check(
// is going to do it. // is going to do it.
if (decl.getName().getValue().size() == 0) { if (decl.getName().getValue().size() == 0) {
// Unnamed union. Check members as if they are in the same scope. // Unnamed union. Check members as if they are in the same scope.
check(decl.getNestedDecls(), decl.getBody().which()); check(decl.getNestedDecls(), decl.which());
} else { } else {
// Children are in their own scope. // Children are in their own scope.
DuplicateNameDetector(errorReporter) DuplicateNameDetector(errorReporter)
.check(decl.getNestedDecls(), decl.getBody().which()); .check(decl.getNestedDecls(), decl.which());
} }
break; break;
...@@ -751,7 +751,7 @@ private: ...@@ -751,7 +751,7 @@ private:
kj::Maybe<LocatedInteger::Reader> lastOrdinalLocation; kj::Maybe<LocatedInteger::Reader> lastOrdinalLocation;
}; };
void NodeTranslator::compileEnum(Declaration::Enum::Reader decl, void NodeTranslator::compileEnum(Void decl,
List<Declaration>::Reader members, List<Declaration>::Reader members,
schema2::Node::Builder builder) { schema2::Node::Builder builder) {
// maps ordinal -> (code order, declaration) // maps ordinal -> (code order, declaration)
...@@ -759,7 +759,7 @@ void NodeTranslator::compileEnum(Declaration::Enum::Reader decl, ...@@ -759,7 +759,7 @@ void NodeTranslator::compileEnum(Declaration::Enum::Reader decl,
uint codeOrder = 0; uint codeOrder = 0;
for (auto member: members) { for (auto member: members) {
if (member.getBody().which() == Declaration::Body::ENUMERANT_DECL) { if (member.which() == Declaration::ENUMERANT) {
enumerants.insert( enumerants.insert(
std::make_pair(member.getId().getOrdinal().getValue(), std::make_pair(member.getId().getOrdinal().getValue(),
std::make_pair(codeOrder++, member))); std::make_pair(codeOrder++, member)));
...@@ -792,8 +792,7 @@ public: ...@@ -792,8 +792,7 @@ public:
: translator(translator), errorReporter(translator.errorReporter) {} : translator(translator), errorReporter(translator.errorReporter) {}
KJ_DISALLOW_COPY(StructTranslator); KJ_DISALLOW_COPY(StructTranslator);
void translate(Declaration::Struct::Reader decl, List<Declaration>::Reader members, void translate(Void decl, List<Declaration>::Reader members, schema2::Node::Builder builder) {
schema2::Node::Builder builder) {
auto structBuilder = builder.initStruct(); auto structBuilder = builder.initStruct();
// Build the member-info-by-ordinal map. // Build the member-info-by-ordinal map.
...@@ -812,9 +811,9 @@ public: ...@@ -812,9 +811,9 @@ public:
schema2::Field::Builder fieldBuilder = member.getSchema(); schema2::Field::Builder fieldBuilder = member.getSchema();
fieldBuilder.getOrdinal().setExplicit(entry.first); fieldBuilder.getOrdinal().setExplicit(entry.first);
switch (member.decl.getBody().which()) { switch (member.decl.which()) {
case Declaration::Body::FIELD_DECL: { case Declaration::FIELD: {
auto fieldReader = member.decl.getBody().getFieldDecl(); auto fieldReader = member.decl.getField();
auto regularField = fieldBuilder.initRegular(); auto regularField = fieldBuilder.initRegular();
auto typeBuilder = regularField.initType(); auto typeBuilder = regularField.initType();
if (translator.compileType(fieldReader.getType(), typeBuilder)) { if (translator.compileType(fieldReader.getType(), typeBuilder)) {
...@@ -868,7 +867,7 @@ public: ...@@ -868,7 +867,7 @@ public:
break; break;
} }
case Declaration::Body::UNION_DECL: case Declaration::UNION:
if (!member.unionScope->addDiscriminant()) { if (!member.unionScope->addDiscriminant()) {
errorReporter.addErrorOn(member.decl.getId().getOrdinal(), errorReporter.addErrorOn(member.decl.getId().getOrdinal(),
"Union ordinal, if specified, must be greater than no more than one of its " "Union ordinal, if specified, must be greater than no more than one of its "
...@@ -876,7 +875,7 @@ public: ...@@ -876,7 +875,7 @@ public:
} }
break; break;
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
KJ_FAIL_ASSERT("Groups don't have ordinals."); KJ_FAIL_ASSERT("Groups don't have ordinals.");
break; break;
...@@ -891,17 +890,17 @@ public: ...@@ -891,17 +890,17 @@ public:
root.finishGroup(); root.finishGroup();
for (auto member: allMembers) { for (auto member: allMembers) {
kj::StringPtr targetsFlagName; kj::StringPtr targetsFlagName;
switch (member->decl.getBody().which()) { switch (member->decl.which()) {
case Declaration::Body::FIELD_DECL: case Declaration::FIELD:
targetsFlagName = "targetsField"; targetsFlagName = "targetsField";
break; break;
case Declaration::Body::UNION_DECL: case Declaration::UNION:
member->finishGroup(); member->finishGroup();
targetsFlagName = "targetsUnion"; targetsFlagName = "targetsUnion";
break; break;
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
member->finishGroup(); member->finishGroup();
targetsFlagName = "targetsGroup"; targetsFlagName = "targetsGroup";
break; break;
...@@ -1080,8 +1079,8 @@ private: ...@@ -1080,8 +1079,8 @@ private:
kj::Maybe<uint> ordinal; kj::Maybe<uint> ordinal;
MemberInfo* memberInfo = nullptr; MemberInfo* memberInfo = nullptr;
switch (member.getBody().which()) { switch (member.which()) {
case Declaration::Body::FIELD_DECL: { case Declaration::FIELD: {
parent.childCount++; parent.childCount++;
// For layout purposes, pretend this field is enclosed in a one-member group. // For layout purposes, pretend this field is enclosed in a one-member group.
StructLayout::Group& singletonGroup = StructLayout::Group& singletonGroup =
...@@ -1093,11 +1092,11 @@ private: ...@@ -1093,11 +1092,11 @@ private:
break; break;
} }
case Declaration::Body::UNION_DECL: case Declaration::UNION:
errorReporter.addErrorOn(member, "Unions cannot contain unions."); errorReporter.addErrorOn(member, "Unions cannot contain unions.");
break; break;
case Declaration::Body::GROUP_DECL: { case Declaration::GROUP: {
parent.childCount++; parent.childCount++;
StructLayout::Group& group = arena.allocate<StructLayout::Group>(layout); StructLayout::Group& group = arena.allocate<StructLayout::Group>(layout);
memberInfo = &arena.allocate<MemberInfo>( memberInfo = &arena.allocate<MemberInfo>(
...@@ -1137,8 +1136,8 @@ private: ...@@ -1137,8 +1136,8 @@ private:
kj::Maybe<uint> ordinal; kj::Maybe<uint> ordinal;
MemberInfo* memberInfo = nullptr; MemberInfo* memberInfo = nullptr;
switch (member.getBody().which()) { switch (member.which()) {
case Declaration::Body::FIELD_DECL: { case Declaration::FIELD: {
parent.childCount++; parent.childCount++;
memberInfo = &arena.allocate<MemberInfo>( memberInfo = &arena.allocate<MemberInfo>(
parent, codeOrder++, member, layout, false); parent, codeOrder++, member, layout, false);
...@@ -1147,7 +1146,7 @@ private: ...@@ -1147,7 +1146,7 @@ private:
break; break;
} }
case Declaration::Body::UNION_DECL: { case Declaration::UNION: {
StructLayout::Union& unionLayout = arena.allocate<StructLayout::Union>(layout); StructLayout::Union& unionLayout = arena.allocate<StructLayout::Union>(layout);
uint independentSubCodeOrder = 0; uint independentSubCodeOrder = 0;
...@@ -1171,7 +1170,7 @@ private: ...@@ -1171,7 +1170,7 @@ private:
break; break;
} }
case Declaration::Body::GROUP_DECL: case Declaration::GROUP:
parent.childCount++; parent.childCount++;
memberInfo = &arena.allocate<MemberInfo>( memberInfo = &arena.allocate<MemberInfo>(
parent, codeOrder++, member, parent, codeOrder++, member,
...@@ -1214,16 +1213,14 @@ private: ...@@ -1214,16 +1213,14 @@ private:
} }
}; };
void NodeTranslator::compileStruct(Declaration::Struct::Reader decl, void NodeTranslator::compileStruct(Void decl, List<Declaration>::Reader members,
List<Declaration>::Reader members,
schema2::Node::Builder builder) { schema2::Node::Builder builder) {
StructTranslator(*this).translate(decl, members, builder); StructTranslator(*this).translate(decl, members, builder);
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
void NodeTranslator::compileInterface(Declaration::Interface::Reader decl, void NodeTranslator::compileInterface(Void decl, List<Declaration>::Reader members,
List<Declaration>::Reader members,
schema2::Node::Builder builder) { schema2::Node::Builder builder) {
KJ_FAIL_ASSERT("TODO: compile interfaces"); KJ_FAIL_ASSERT("TODO: compile interfaces");
} }
...@@ -1263,11 +1260,11 @@ bool NodeTranslator::compileType(TypeExpression::Reader source, schema2::Type::B ...@@ -1263,11 +1260,11 @@ bool NodeTranslator::compileType(TypeExpression::Reader source, schema2::Type::B
bool handledParams = false; bool handledParams = false;
switch (base->kind) { switch (base->kind) {
case Declaration::Body::ENUM_DECL: target.setEnum(base->id); break; case Declaration::ENUM: target.setEnum(base->id); break;
case Declaration::Body::STRUCT_DECL: target.setStruct(base->id); break; case Declaration::STRUCT: target.setStruct(base->id); break;
case Declaration::Body::INTERFACE_DECL: target.setInterface(base->id); break; case Declaration::INTERFACE: target.setInterface(base->id); break;
case Declaration::Body::BUILTIN_LIST: { case Declaration::BUILTIN_LIST: {
auto params = source.getParams(); auto params = source.getParams();
if (params.size() != 1) { if (params.size() != 1) {
errorReporter.addErrorOn(source, "'List' requires exactly one parameter."); errorReporter.addErrorOn(source, "'List' requires exactly one parameter.");
...@@ -1290,21 +1287,21 @@ bool NodeTranslator::compileType(TypeExpression::Reader source, schema2::Type::B ...@@ -1290,21 +1287,21 @@ bool NodeTranslator::compileType(TypeExpression::Reader source, schema2::Type::B
break; break;
} }
case Declaration::Body::BUILTIN_VOID: target.setVoid(); break; case Declaration::BUILTIN_VOID: target.setVoid(); break;
case Declaration::Body::BUILTIN_BOOL: target.setBool(); break; case Declaration::BUILTIN_BOOL: target.setBool(); break;
case Declaration::Body::BUILTIN_INT8: target.setInt8(); break; case Declaration::BUILTIN_INT8: target.setInt8(); break;
case Declaration::Body::BUILTIN_INT16: target.setInt16(); break; case Declaration::BUILTIN_INT16: target.setInt16(); break;
case Declaration::Body::BUILTIN_INT32: target.setInt32(); break; case Declaration::BUILTIN_INT32: target.setInt32(); break;
case Declaration::Body::BUILTIN_INT64: target.setInt64(); break; case Declaration::BUILTIN_INT64: target.setInt64(); break;
case Declaration::Body::BUILTIN_U_INT8: target.setUint8(); break; case Declaration::BUILTIN_U_INT8: target.setUint8(); break;
case Declaration::Body::BUILTIN_U_INT16: target.setUint16(); break; case Declaration::BUILTIN_U_INT16: target.setUint16(); break;
case Declaration::Body::BUILTIN_U_INT32: target.setUint32(); break; case Declaration::BUILTIN_U_INT32: target.setUint32(); break;
case Declaration::Body::BUILTIN_U_INT64: target.setUint64(); break; case Declaration::BUILTIN_U_INT64: target.setUint64(); break;
case Declaration::Body::BUILTIN_FLOAT32: target.setFloat32(); break; case Declaration::BUILTIN_FLOAT32: target.setFloat32(); break;
case Declaration::Body::BUILTIN_FLOAT64: target.setFloat64(); break; case Declaration::BUILTIN_FLOAT64: target.setFloat64(); break;
case Declaration::Body::BUILTIN_TEXT: target.setText(); break; case Declaration::BUILTIN_TEXT: target.setText(); break;
case Declaration::Body::BUILTIN_DATA: target.setData(); break; case Declaration::BUILTIN_DATA: target.setData(); break;
case Declaration::Body::BUILTIN_OBJECT: target.setObject(); break; case Declaration::BUILTIN_OBJECT: target.setObject(); break;
default: default:
errorReporter.addErrorOn(source, kj::str("'", declNameString(name), "' is not a type.")); errorReporter.addErrorOn(source, kj::str("'", declNameString(name), "' is not a type."));
...@@ -1522,25 +1519,6 @@ void NodeTranslator::compileBootstrapValue(ValueExpression::Reader source, ...@@ -1522,25 +1519,6 @@ void NodeTranslator::compileBootstrapValue(ValueExpression::Reader source,
void NodeTranslator::compileValue(ValueExpression::Reader source, schema2::Type::Reader type, void NodeTranslator::compileValue(ValueExpression::Reader source, schema2::Type::Reader type,
schema2::Value::Builder target, bool isBootstrap) { schema2::Value::Builder target, bool isBootstrap) {
#warning "temporary hack for schema transition"
switch (type.which()) {
case schema2::Type::TEXT:
target.setText(source.getBody().getString());
break;
case schema2::Type::UINT16:
target.setUint16(source.getBody().getPositiveInt());
break;
default:
#if 0
KJ_FAIL_ASSERT("Need to compile value type:", (uint)type.which(),
wipNode.getReader().getDisplayName());
}
#else
break;
}
auto valueUnion = toDynamic(target); auto valueUnion = toDynamic(target);
auto field = valueUnion.getSchema().getFieldByName( auto field = valueUnion.getSchema().getFieldByName(
getValueUnionFieldNameFor(type.which())); getValueUnionFieldNameFor(type.which()));
...@@ -1568,7 +1546,6 @@ void NodeTranslator::compileValue(ValueExpression::Reader source, schema2::Type: ...@@ -1568,7 +1546,6 @@ void NodeTranslator::compileValue(ValueExpression::Reader source, schema2::Type:
compileValue(source, slot, isBootstrap); compileValue(source, slot, isBootstrap);
break; break;
} }
#endif
} }
void NodeTranslator::compileValue(ValueExpression::Reader src, DynamicSlot& dst, bool isBootstrap) { void NodeTranslator::compileValue(ValueExpression::Reader src, DynamicSlot& dst, bool isBootstrap) {
...@@ -1585,9 +1562,9 @@ void NodeTranslator::compileValue(ValueExpression::Reader src, DynamicSlot& dst, ...@@ -1585,9 +1562,9 @@ void NodeTranslator::compileValue(ValueExpression::Reader src, DynamicSlot& dst,
void NodeTranslator::compileValueInner( void NodeTranslator::compileValueInner(
ValueExpression::Reader src, DynamicSlot& dst, bool isBootstrap) { ValueExpression::Reader src, DynamicSlot& dst, bool isBootstrap) {
switch (src.getBody().which()) { switch (src.which()) {
case ValueExpression::Body::NAME: { case ValueExpression::NAME: {
auto name = src.getBody().getName(); auto name = src.getName();
bool isBare = name.getBase().which() == DeclName::Base::RELATIVE_NAME && bool isBare = name.getBase().which() == DeclName::Base::RELATIVE_NAME &&
name.getMemberPath().size() == 0; name.getMemberPath().size() == 0;
bool wasSet = false; bool wasSet = false;
...@@ -1630,19 +1607,19 @@ void NodeTranslator::compileValueInner( ...@@ -1630,19 +1607,19 @@ void NodeTranslator::compileValueInner(
if (!wasSet) { if (!wasSet) {
// Haven't resolved the name yet. Try looking up a constant. // Haven't resolved the name yet. Try looking up a constant.
KJ_IF_MAYBE(constValue, readConstant(src.getBody().getName(), isBootstrap, src)) { KJ_IF_MAYBE(constValue, readConstant(src.getName(), isBootstrap, src)) {
dst.set(*constValue); dst.set(*constValue);
} }
} }
break; break;
} }
case ValueExpression::Body::POSITIVE_INT: case ValueExpression::POSITIVE_INT:
dst.set(src.getBody().getPositiveInt()); dst.set(src.getPositiveInt());
break; break;
case ValueExpression::Body::NEGATIVE_INT: { case ValueExpression::NEGATIVE_INT: {
uint64_t nValue = src.getBody().getNegativeInt(); uint64_t nValue = src.getNegativeInt();
if (nValue > (std::numeric_limits<uint64_t>::max() >> 1) + 1) { if (nValue > (std::numeric_limits<uint64_t>::max() >> 1) + 1) {
errorReporter.addErrorOn(src, "Integer is too big to be negative."); errorReporter.addErrorOn(src, "Integer is too big to be negative.");
} else { } else {
...@@ -1651,16 +1628,16 @@ void NodeTranslator::compileValueInner( ...@@ -1651,16 +1628,16 @@ void NodeTranslator::compileValueInner(
break; break;
} }
case ValueExpression::Body::FLOAT: case ValueExpression::FLOAT:
dst.set(src.getBody().getFloat()); dst.set(src.getFloat());
break; break;
case ValueExpression::Body::STRING: case ValueExpression::STRING:
dst.set(src.getBody().getString()); dst.set(src.getString());
break; break;
case ValueExpression::Body::LIST: { case ValueExpression::LIST: {
auto srcList = src.getBody().getList(); auto srcList = src.getList();
auto dstList = dst.initList(srcList.size()); auto dstList = dst.initList(srcList.size());
for (uint i = 0; i < srcList.size(); i++) { for (uint i = 0; i < srcList.size(); i++) {
DynamicSlot slot(dstList, i); DynamicSlot slot(dstList, i);
...@@ -1669,34 +1646,24 @@ void NodeTranslator::compileValueInner( ...@@ -1669,34 +1646,24 @@ void NodeTranslator::compileValueInner(
break; break;
} }
case ValueExpression::Body::STRUCT_VALUE: { case ValueExpression::STRUCT: {
auto srcStruct = src.getBody().getStructValue(); auto srcStruct = src.getStruct();
auto dstStruct = dst.initStruct(); auto dstStruct = dst.initStruct();
auto dstSchema = dstStruct.getSchema(); auto dstSchema = dstStruct.getSchema();
for (auto assignment: srcStruct) { for (auto assignment: srcStruct) {
auto fieldName = assignment.getFieldName(); auto fieldName = assignment.getFieldName();
KJ_IF_MAYBE(field, dstSchema.findFieldByName(fieldName.getValue())) {
switch (assignment.which()) { DynamicSlot slot(dstStruct, *field);
case ValueExpression::FieldAssignment::NOT_UNION: compileValue(assignment.getValue(), slot, isBootstrap);
KJ_IF_MAYBE(field, dstSchema.findFieldByName(fieldName.getValue())) { } else {
DynamicSlot slot(dstStruct, *field); errorReporter.addErrorOn(fieldName, kj::str(
compileValue(assignment.getValue(), slot, isBootstrap); "Struct has no field named '", fieldName.getValue(), "'."));
} else {
errorReporter.addErrorOn(fieldName, kj::str(
"Struct has no field named '", fieldName.getValue(), "'."));
}
break;
case ValueExpression::FieldAssignment::UNION: {
KJ_FAIL_ASSERT("Union literal syntax is obsolete.");
break;
}
} }
} }
break; break;
} }
case ValueExpression::Body::UNKNOWN: case ValueExpression::UNKNOWN:
// Ignore earlier error. // Ignore earlier error.
break; break;
} }
...@@ -1705,7 +1672,7 @@ void NodeTranslator::compileValueInner( ...@@ -1705,7 +1672,7 @@ void NodeTranslator::compileValueInner(
kj::Maybe<DynamicValue::Reader> NodeTranslator::readConstant( kj::Maybe<DynamicValue::Reader> NodeTranslator::readConstant(
DeclName::Reader name, bool isBootstrap, ValueExpression::Reader errorLocation) { DeclName::Reader name, bool isBootstrap, ValueExpression::Reader errorLocation) {
KJ_IF_MAYBE(resolved, resolver.resolve(name)) { KJ_IF_MAYBE(resolved, resolver.resolve(name)) {
if (resolved->kind != Declaration::Body::CONST_DECL) { if (resolved->kind != Declaration::CONST) {
errorReporter.addErrorOn(errorLocation, errorReporter.addErrorOn(errorLocation,
kj::str("'", declNameString(name), "' does not refer to a constant.")); kj::str("'", declNameString(name), "' does not refer to a constant."));
return nullptr; return nullptr;
...@@ -1838,7 +1805,7 @@ Orphan<List<schema2::Annotation>> NodeTranslator::compileAnnotationApplications( ...@@ -1838,7 +1805,7 @@ Orphan<List<schema2::Annotation>> NodeTranslator::compileAnnotationApplications(
auto name = annotation.getName(); auto name = annotation.getName();
KJ_IF_MAYBE(decl, resolver.resolve(name)) { KJ_IF_MAYBE(decl, resolver.resolve(name)) {
if (decl->kind != Declaration::Body::ANNOTATION_DECL) { if (decl->kind != Declaration::ANNOTATION) {
errorReporter.addErrorOn(name, kj::str( errorReporter.addErrorOn(name, kj::str(
"'", declNameString(name), "' is not an annotation.")); "'", declNameString(name), "' is not an annotation."));
} else { } else {
......
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
public: public:
struct ResolvedName { struct ResolvedName {
uint64_t id; uint64_t id;
Declaration::Body::Which kind; Declaration::Which kind;
}; };
virtual kj::Maybe<ResolvedName> resolve(const DeclName::Reader& name) const = 0; virtual kj::Maybe<ResolvedName> resolve(const DeclName::Reader& name) const = 0;
...@@ -143,11 +143,11 @@ private: ...@@ -143,11 +143,11 @@ private:
class StructLayout; class StructLayout;
class StructTranslator; class StructTranslator;
void compileEnum(Declaration::Enum::Reader decl, List<Declaration>::Reader members, void compileEnum(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder); schema2::Node::Builder builder);
void compileStruct(Declaration::Struct::Reader decl, List<Declaration>::Reader members, void compileStruct(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder); schema2::Node::Builder builder);
void compileInterface(Declaration::Interface::Reader decl, List<Declaration>::Reader members, void compileInterface(Void decl, List<Declaration>::Reader members,
schema2::Node::Builder builder); schema2::Node::Builder builder);
// The `members` arrays contain only members with ordinal numbers, in code order. Other members // The `members` arrays contain only members with ordinal numbers, in code order. Other members
// are handled elsewhere. // are handled elsewhere.
......
...@@ -103,26 +103,25 @@ void parseFile(List<Statement>::Reader statements, ParsedFile::Builder result, ...@@ -103,26 +103,25 @@ void parseFile(List<Statement>::Reader statements, ParsedFile::Builder result,
kj::Vector<Orphan<Declaration::AnnotationApplication>> annotations; kj::Vector<Orphan<Declaration::AnnotationApplication>> annotations;
auto fileDecl = result.getRoot(); auto fileDecl = result.getRoot();
fileDecl.getBody().initFileDecl(); fileDecl.setFile(Void::VOID);
for (auto statement: statements) { for (auto statement: statements) {
KJ_IF_MAYBE(decl, parser.parseStatement(statement, parser.getParsers().fileLevelDecl)) { KJ_IF_MAYBE(decl, parser.parseStatement(statement, parser.getParsers().fileLevelDecl)) {
Declaration::Builder builder = decl->get(); Declaration::Builder builder = decl->get();
auto body = builder.getBody(); switch (builder.which()) {
switch (body.which()) { case Declaration::NAKED_ID:
case Declaration::Body::NAKED_ID:
if (fileDecl.getId().which() == Declaration::Id::UID) { if (fileDecl.getId().which() == Declaration::Id::UID) {
errorReporter.addError(builder.getStartByte(), builder.getEndByte(), errorReporter.addError(builder.getStartByte(), builder.getEndByte(),
"File can only have one ID."); "File can only have one ID.");
} else { } else {
fileDecl.getId().adoptUid(body.disownNakedId()); fileDecl.getId().adoptUid(builder.disownNakedId());
if (builder.hasDocComment()) { if (builder.hasDocComment()) {
fileDecl.adoptDocComment(builder.disownDocComment()); fileDecl.adoptDocComment(builder.disownDocComment());
} }
} }
break; break;
case Declaration::Body::NAKED_ANNOTATION: case Declaration::NAKED_ANNOTATION:
annotations.add(body.disownNakedAnnotation()); annotations.add(builder.disownNakedAnnotation());
break; break;
default: default:
decls.add(kj::mv(*decl)); decls.add(kj::mv(*decl));
...@@ -421,40 +420,20 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -421,40 +420,20 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
return result; return result;
})); }));
// Matches "value" or "unionName(value)".
auto& fieldValue = arena.copy(p::oneOf(
p::transform(p::sequence(identifier, parsers.parenthesizedValueExpression),
[this](Located<Text::Reader>&& name, Orphan<ValueExpression>&& value)
-> Orphan<ValueExpression::FieldAssignment> {
auto result = orphanage.newOrphan<ValueExpression::FieldAssignment>();
auto builder = result.get();
name.copyTo(builder.initUnion());
builder.adoptValue(kj::mv(value));
return result;
}),
p::transform(parsers.valueExpression,
[this](Orphan<ValueExpression>&& value)
-> Orphan<ValueExpression::FieldAssignment> {
auto result = orphanage.newOrphan<ValueExpression::FieldAssignment>();
auto builder = result.get();
builder.setNotUnion();
builder.adoptValue(kj::mv(value));
return result;
})));
// Parser for a "name = value" pair. Also matches "name = unionMember(value)", // Parser for a "name = value" pair. Also matches "name = unionMember(value)",
// "unionMember(value)" (unnamed union), and just "value" (which is not actually a valid field // "unionMember(value)" (unnamed union), and just "value" (which is not actually a valid field
// assigment, but simplifies the parser for parenthesizedValueExpression). // assigment, but simplifies the parser for parenthesizedValueExpression).
auto& fieldAssignment = arena.copy(p::transform( auto& fieldAssignment = arena.copy(p::transform(
p::sequence(p::optional(p::sequence(identifier, op("="))), fieldValue), p::sequence(p::optional(p::sequence(identifier, op("="))), parsers.valueExpression),
[this](kj::Maybe<Located<Text::Reader>>&& fieldName, [this](kj::Maybe<Located<Text::Reader>>&& fieldName, Orphan<ValueExpression>&& fieldValue)
Orphan<ValueExpression::FieldAssignment>&& assignment)
-> Orphan<ValueExpression::FieldAssignment> { -> Orphan<ValueExpression::FieldAssignment> {
auto builder = assignment.get(); auto result = orphanage.newOrphan<ValueExpression::FieldAssignment>();
auto builder = result.get();
KJ_IF_MAYBE(fn, fieldName) { KJ_IF_MAYBE(fn, fieldName) {
fn->copyTo(builder.initFieldName()); fn->copyTo(builder.initFieldName());
} }
return kj::mv(assignment); builder.adoptValue(kj::mv(fieldValue));
return kj::mv(result);
})); }));
parsers.parenthesizedValueExpression = arena.copy(p::transform( parsers.parenthesizedValueExpression = arena.copy(p::transform(
...@@ -464,9 +443,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -464,9 +443,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
if (value.value.size() == 1) { if (value.value.size() == 1) {
KJ_IF_MAYBE(firstVal, value.value[0]) { KJ_IF_MAYBE(firstVal, value.value[0]) {
auto reader = firstVal->getReader(); auto reader = firstVal->getReader();
if (reader.getFieldName().getValue().size() == 0 && if (reader.getFieldName().getValue().size() == 0) {
reader.which() == ValueExpression::FieldAssignment::NOT_UNION) { // There is only one value and it isn't an assignment, therefore the value is
// There is only one value and it isn't an assignment or union, therefore the value is
// not a struct. // not a struct.
return firstVal->get().disownValue(); return firstVal->get().disownValue();
} }
...@@ -474,7 +452,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -474,7 +452,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
// There is only one value and it failed to parse. // There is only one value and it failed to parse.
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setUnknown(); builder.setUnknown();
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
} }
...@@ -487,12 +465,11 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -487,12 +465,11 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
auto builder = result.get(); auto builder = result.get();
value.copyLocationTo(builder); value.copyLocationTo(builder);
auto structBuilder = builder.getBody().initStructValue(value.value.size()); auto structBuilder = builder.initStruct(value.value.size());
for (uint i = 0; i < value.value.size(); i++) { for (uint i = 0; i < value.value.size(); i++) {
KJ_IF_MAYBE(field, value.value[i]) { KJ_IF_MAYBE(field, value.value[i]) {
auto reader = field->getReader(); auto reader = field->getReader();
if (reader.getFieldName().getValue().size() > 0 || if (reader.getFieldName().getValue().size() > 0) {
reader.which() == ValueExpression::FieldAssignment::UNION) {
structBuilder.adoptWithCaveats(i, kj::mv(*field)); structBuilder.adoptWithCaveats(i, kj::mv(*field));
} else { } else {
errorReporter.addErrorOn(reader.getValue(), "Missing field name."); errorReporter.addErrorOn(reader.getValue(), "Missing field name.");
...@@ -508,7 +485,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -508,7 +485,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<uint64_t>&& value) -> Orphan<ValueExpression> { [this](Located<uint64_t>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setPositiveInt(value.value); builder.setPositiveInt(value.value);
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
}), }),
...@@ -516,7 +493,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -516,7 +493,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<uint64_t>&& value) -> Orphan<ValueExpression> { [this](Located<uint64_t>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setNegativeInt(value.value); builder.setNegativeInt(value.value);
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
}), }),
...@@ -524,7 +501,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -524,7 +501,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<double>&& value) -> Orphan<ValueExpression> { [this](Located<double>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setFloat(value.value); builder.setFloat(value.value);
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
}), }),
...@@ -532,7 +509,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -532,7 +509,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<double>&& value) -> Orphan<ValueExpression> { [this](Located<double>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setFloat(-value.value); builder.setFloat(-value.value);
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
}), }),
...@@ -541,7 +518,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -541,7 +518,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
-> Orphan<ValueExpression> { -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setFloat(-std::numeric_limits<double>::infinity()); builder.setFloat(-std::numeric_limits<double>::infinity());
initLocation(location, builder); initLocation(location, builder);
return result; return result;
}), }),
...@@ -549,7 +526,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -549,7 +526,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<Text::Reader>&& value) -> Orphan<ValueExpression> { [this](Located<Text::Reader>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().setString(value.value); builder.setString(value.value);
value.copyLocationTo(builder); value.copyLocationTo(builder);
return result; return result;
}), }),
...@@ -558,7 +535,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -558,7 +535,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
Orphan<DeclName>&& value) -> Orphan<ValueExpression> { Orphan<DeclName>&& value) -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
builder.getBody().adoptName(kj::mv(value)); builder.adoptName(kj::mv(value));
initLocation(location, builder); initLocation(location, builder);
return result; return result;
}), }),
...@@ -567,7 +544,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -567,7 +544,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
-> Orphan<ValueExpression> { -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
auto listBuilder = builder.getBody().initList(value.value.size()); auto listBuilder = builder.initList(value.value.size());
for (uint i = 0; i < value.value.size(); i++) { for (uint i = 0; i < value.value.size(); i++) {
KJ_IF_MAYBE(element, value.value[i]) { KJ_IF_MAYBE(element, value.value[i]) {
listBuilder.adoptWithCaveats(i, kj::mv(*element)); listBuilder.adoptWithCaveats(i, kj::mv(*element));
...@@ -581,12 +558,11 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -581,12 +558,11 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
-> Orphan<ValueExpression> { -> Orphan<ValueExpression> {
auto result = orphanage.newOrphan<ValueExpression>(); auto result = orphanage.newOrphan<ValueExpression>();
auto builder = result.get(); auto builder = result.get();
auto structBuilder = builder.getBody().initStructValue(value.value.size()); auto structBuilder = builder.initStruct(value.value.size());
for (uint i = 0; i < value.value.size(); i++) { for (uint i = 0; i < value.value.size(); i++) {
KJ_IF_MAYBE(field, value.value[i]) { KJ_IF_MAYBE(field, value.value[i]) {
auto reader = field->get(); auto reader = field->get();
if (reader.getFieldName().getValue().size() > 0 || if (reader.getFieldName().getValue().size() > 0) {
reader.which() == ValueExpression::FieldAssignment::UNION) {
structBuilder.adoptWithCaveats(i, kj::mv(*field)); structBuilder.adoptWithCaveats(i, kj::mv(*field));
} else { } else {
auto fieldValue = field->get().getValue(); auto fieldValue = field->get().getValue();
...@@ -656,7 +632,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -656,7 +632,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
} }
} }
// no id, no annotations for using decl // no id, no annotations for using decl
builder.getBody().initUsingDecl().adoptTarget(kj::mv(target)); builder.initUsing().adoptTarget(kj::mv(target));
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
})); }));
...@@ -670,8 +646,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -670,8 +646,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
auto builder = initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)) auto builder =
.getBody().initConstDecl(); initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)).initConst();
builder.adoptType(kj::mv(type)); builder.adoptType(kj::mv(type));
builder.adoptValue(kj::mv(value)); builder.adoptValue(kj::mv(value));
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
...@@ -684,8 +660,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -684,8 +660,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)) initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)).setEnum();
.getBody().initEnumDecl();
return DeclParserResult(kj::mv(decl), parsers.enumLevelDecl); return DeclParserResult(kj::mv(decl), parsers.enumLevelDecl);
})); }));
...@@ -696,7 +671,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -696,7 +671,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations)) initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations))
.getBody().initEnumerantDecl(); .setEnumerant();
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
})); }));
...@@ -707,8 +682,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -707,8 +682,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)) initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)).setStruct();
.getBody().initStructDecl();
return DeclParserResult(kj::mv(decl), parsers.structLevelDecl); return DeclParserResult(kj::mv(decl), parsers.structLevelDecl);
})); }));
...@@ -723,7 +697,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -723,7 +697,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
auto builder = auto builder =
initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations)) initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations))
.getBody().initFieldDecl(); .initField();
builder.adoptType(kj::mv(type)); builder.adoptType(kj::mv(type));
KJ_IF_MAYBE(val, defaultValue) { KJ_IF_MAYBE(val, defaultValue) {
builder.getDefaultValue().adoptValue(kj::mv(*val)); builder.getDefaultValue().adoptValue(kj::mv(*val));
...@@ -769,7 +743,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -769,7 +743,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
for (uint i = 0; i < annotations.size(); i++) { for (uint i = 0; i < annotations.size(); i++) {
list.adoptWithCaveats(i, kj::mv(annotations[i])); list.adoptWithCaveats(i, kj::mv(annotations[i]));
} }
builder.getBody().initUnionDecl(); builder.setUnion();
return DeclParserResult(kj::mv(decl), parsers.structLevelDecl); return DeclParserResult(kj::mv(decl), parsers.structLevelDecl);
})); }));
...@@ -787,7 +761,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -787,7 +761,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
for (uint i = 0; i < annotations.size(); i++) { for (uint i = 0; i < annotations.size(); i++) {
list.adoptWithCaveats(i, kj::mv(annotations[i])); list.adoptWithCaveats(i, kj::mv(annotations[i]));
} }
builder.getBody().initGroupDecl(); builder.setGroup();
return DeclParserResult(kj::mv(decl), parsers.structLevelDecl); return DeclParserResult(kj::mv(decl), parsers.structLevelDecl);
})); }));
...@@ -798,8 +772,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -798,8 +772,7 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)) initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)).setInterface();
.getBody().initInterfaceDecl();
return DeclParserResult(kj::mv(decl), parsers.interfaceLevelDecl); return DeclParserResult(kj::mv(decl), parsers.interfaceLevelDecl);
})); }));
...@@ -810,8 +783,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -810,8 +783,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
[this](Located<Text::Reader>&& name, Orphan<TypeExpression>&& type, [this](Located<Text::Reader>&& name, Orphan<TypeExpression>&& type,
kj::Maybe<Orphan<ValueExpression>>&& defaultValue, kj::Maybe<Orphan<ValueExpression>>&& defaultValue,
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> Orphan<Declaration::Method::Param> { -> Orphan<Declaration::Param> {
auto result = orphanage.newOrphan<Declaration::Method::Param>(); auto result = orphanage.newOrphan<Declaration::Param>();
auto builder = result.get(); auto builder = result.get();
name.copyTo(builder.initName()); name.copyTo(builder.initName());
...@@ -832,14 +805,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -832,14 +805,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
p::optional(p::sequence(op(":"), parsers.typeExpression)), p::optional(p::sequence(op(":"), parsers.typeExpression)),
p::many(parsers.annotation)), p::many(parsers.annotation)),
[this](Located<Text::Reader>&& name, Orphan<LocatedInteger>&& ordinal, [this](Located<Text::Reader>&& name, Orphan<LocatedInteger>&& ordinal,
Located<kj::Array<kj::Maybe<Orphan<Declaration::Method::Param>>>>&& params, Located<kj::Array<kj::Maybe<Orphan<Declaration::Param>>>>&& params,
kj::Maybe<Orphan<TypeExpression>>&& returnType, kj::Maybe<Orphan<TypeExpression>>&& returnType,
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
auto builder = auto builder =
initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations)) initMemberDecl(decl.get(), kj::mv(name), kj::mv(ordinal), kj::mv(annotations))
.getBody().initMethodDecl(); .initMethod();
auto paramsBuilder = builder.initParams(params.value.size()); auto paramsBuilder = builder.initParams(params.value.size());
for (uint i = 0; i < params.value.size(); i++) { for (uint i = 0; i < params.value.size(); i++) {
...@@ -877,8 +850,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -877,8 +850,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations) kj::Array<Orphan<Declaration::AnnotationApplication>>&& annotations)
-> DeclParserResult { -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
auto builder = initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)) auto builder =
.getBody().initAnnotationDecl(); initDecl(decl.get(), kj::mv(name), kj::mv(id), kj::mv(annotations)).initAnnotation();
builder.adoptType(kj::mv(type)); builder.adoptType(kj::mv(type));
DynamicStruct::Builder dynamicBuilder = builder; DynamicStruct::Builder dynamicBuilder = builder;
for (auto& maybeTarget: targets.value) { for (auto& maybeTarget: targets.value) {
...@@ -930,14 +903,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep ...@@ -930,14 +903,14 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, const ErrorReporter& errorRep
auto& nakedId = arena.copy(p::transform(parsers.uid, auto& nakedId = arena.copy(p::transform(parsers.uid,
[this](Orphan<LocatedInteger>&& value) -> DeclParserResult { [this](Orphan<LocatedInteger>&& value) -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
decl.get().getBody().adoptNakedId(kj::mv(value)); decl.get().adoptNakedId(kj::mv(value));
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
})); }));
auto& nakedAnnotation = arena.copy(p::transform(parsers.annotation, auto& nakedAnnotation = arena.copy(p::transform(parsers.annotation,
[this](Orphan<Declaration::AnnotationApplication>&& value) -> DeclParserResult { [this](Orphan<Declaration::AnnotationApplication>&& value) -> DeclParserResult {
auto decl = orphanage.newOrphan<Declaration>(); auto decl = orphanage.newOrphan<Declaration>();
decl.get().getBody().adoptNakedAnnotation(kj::mv(value)); decl.get().adoptNakedAnnotation(kj::mv(value));
return DeclParserResult(kj::mv(decl)); return DeclParserResult(kj::mv(decl));
})); }));
......
...@@ -117,7 +117,7 @@ public: ...@@ -117,7 +117,7 @@ public:
Parser<Orphan<Declaration::AnnotationApplication>> annotation; Parser<Orphan<Declaration::AnnotationApplication>> annotation;
Parser<Orphan<LocatedInteger>> uid; Parser<Orphan<LocatedInteger>> uid;
Parser<Orphan<LocatedInteger>> ordinal; Parser<Orphan<LocatedInteger>> ordinal;
Parser<Orphan<Declaration::Method::Param>> param; Parser<Orphan<Declaration::Param>> param;
DeclParser usingDecl; DeclParser usingDecl;
DeclParser constDecl; DeclParser constDecl;
......
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