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

Refactor grammar.capnp to use unnamed unions.

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