Assert that non-file definitions must have a parent.

This commit is contained in:
Kuba Ober 2019-08-30 11:35:25 -04:00
parent e2cfb8aaf1
commit c296c0f63a
5 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,5 @@
 using System.Diagnostics;
namespace CapnpC.Model namespace CapnpC.Model
{ {
class Annotation : IDefinition class Annotation : IDefinition
@ -11,6 +12,7 @@ namespace CapnpC.Model
public Annotation(ulong id, IHasNestedDefinitions parent) public Annotation(ulong id, IHasNestedDefinitions parent)
{ {
Trace.Assert(parent != null);
Id = id; Id = id;
DeclaringElement = parent; DeclaringElement = parent;
parent.NestedDefinitions.Add(this); parent.NestedDefinitions.Add(this);

View File

@ -1,4 +1,5 @@
 using System.Diagnostics;
namespace CapnpC.Model namespace CapnpC.Model
{ {
class Constant : IDefinition class Constant : IDefinition
@ -11,6 +12,7 @@ namespace CapnpC.Model
public Constant(ulong id, IHasNestedDefinitions parent) public Constant(ulong id, IHasNestedDefinitions parent)
{ {
Trace.Assert(parent != null);
Id = id; Id = id;
DeclaringElement = parent; DeclaringElement = parent;
parent.NestedDefinitions.Add(this); parent.NestedDefinitions.Add(this);

View File

@ -6,7 +6,7 @@ namespace CapnpC.Model
{ {
public ulong Id { get; } public ulong Id { get; }
public TypeTag Tag { get => TypeTag.File; } public TypeTag Tag { get => TypeTag.File; }
public IHasNestedDefinitions DeclaringElement { get; } public IHasNestedDefinitions DeclaringElement { get => null; }
public string Name { get; set; } public string Name { get; set; }
public string[] Namespace { get; set; } public string[] Namespace { get; set; }

View File

@ -137,6 +137,7 @@ namespace CapnpC.Model
if (def == null) if (def == null)
{ {
Trace.Assert(state.parent != null, $"The {node.GetTypeTag().ToString()} node {node.StrId()} was expected to have a parent.");
var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent); var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent);
typeDef.Name = name; typeDef.Name = name;
def = typeDef; def = typeDef;

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
namespace CapnpC.Model namespace CapnpC.Model
{ {
@ -18,6 +19,7 @@ namespace CapnpC.Model
public TypeDefinition(TypeTag tag, ulong id, IHasNestedDefinitions parent) public TypeDefinition(TypeTag tag, ulong id, IHasNestedDefinitions parent)
{ {
Trace.Assert(parent != null);
Tag = tag; Tag = tag;
Id = id; Id = id;
DeclaringElement = parent; DeclaringElement = parent;