mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +01:00
Fix namespace generation in imported types.
This commit is contained in:
parent
dd83132b5d
commit
884040bd66
@ -147,18 +147,9 @@
|
||||
|
||||
internal string Transform(GenFile file)
|
||||
{
|
||||
if (file.Namespace != null)
|
||||
{
|
||||
_names.TopNamespace = IdentifierName(MakeCamel(file.Namespace[0]));
|
||||
NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace;
|
||||
|
||||
foreach (string name in file.Namespace.Skip(1))
|
||||
{
|
||||
var temp = IdentifierName(MakeCamel(name));
|
||||
_names.TopNamespace = QualifiedName(_names.TopNamespace, temp);
|
||||
}
|
||||
}
|
||||
|
||||
var ns = NamespaceDeclaration(_names.TopNamespace);
|
||||
var ns = NamespaceDeclaration(topNamespace);
|
||||
|
||||
foreach (var def in file.NestedTypes)
|
||||
{
|
||||
|
@ -213,28 +213,23 @@ namespace CapnpC.Generator
|
||||
}
|
||||
}
|
||||
|
||||
NameSyntax GetQName(TypeDefinition def)
|
||||
public static NameSyntax NamespaceName(string[] @namespace)
|
||||
{
|
||||
var stack = new Stack<SimpleNameSyntax>();
|
||||
|
||||
stack.Push(MakeGenericTypeName(def, NameUsage.Default));
|
||||
|
||||
while (def.DeclaringElement is TypeDefinition pdef)
|
||||
NameSyntax ident = null;
|
||||
if (@namespace != null)
|
||||
{
|
||||
stack.Push(MakeGenericTypeName(pdef, NameUsage.Namespace));
|
||||
def = pdef;
|
||||
ident = IdentifierName(SyntaxHelpers.MakeCamel(@namespace[0]));
|
||||
foreach (string name in @namespace.Skip(1))
|
||||
{
|
||||
var temp = IdentifierName(SyntaxHelpers.MakeCamel(name));
|
||||
ident = QualifiedName(ident, temp);
|
||||
}
|
||||
}
|
||||
|
||||
var qtype = TopNamespace;
|
||||
|
||||
foreach (var name in stack)
|
||||
{
|
||||
qtype = QualifiedName(qtype, name);
|
||||
}
|
||||
|
||||
return qtype;
|
||||
return ident;
|
||||
}
|
||||
|
||||
NameSyntax GetNamespaceFor(TypeDefinition def) => NamespaceName(def?.File?.Namespace);
|
||||
|
||||
internal NameSyntax GetQName(Model.Type type, TypeDefinition scope)
|
||||
{
|
||||
// FIXME: With the help of the 'scope' parameter we will be able to generate abbreviated
|
||||
@ -262,7 +257,10 @@ namespace CapnpC.Generator
|
||||
def = pdef;
|
||||
}
|
||||
|
||||
var qtype = TopNamespace;
|
||||
var qtype =
|
||||
GetNamespaceFor(type.Definition)
|
||||
?? GetNamespaceFor(scope)
|
||||
?? TopNamespace;
|
||||
|
||||
foreach (var name in stack)
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ namespace CapnpC.Model
|
||||
if (state.parent != null)
|
||||
throw new InvalidSchemaException("Did not expect file nodes to appear as nested nodes");
|
||||
file = new GenFile();
|
||||
file.Namespace = null; // TODO
|
||||
file.Namespace = GetNamespaceAnnotation(node);
|
||||
processNestedNodes = true;
|
||||
break;
|
||||
case NodeKind.Enum:
|
||||
@ -189,6 +189,18 @@ namespace CapnpC.Model
|
||||
return state.parent;
|
||||
}
|
||||
|
||||
string[] GetNamespaceAnnotation(Schema.Node.Reader fileNode)
|
||||
{
|
||||
foreach (var annotation in fileNode.Annotations)
|
||||
{
|
||||
if (annotation.Id == 0xb9c6f99ebf805f2c) // Cxx namespace
|
||||
{
|
||||
return annotation.Value.Text.Split(new string[1] { "::" }, default);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2nd pass: Generate types based on definitions
|
||||
|
||||
struct Pass2State
|
||||
@ -206,7 +218,6 @@ namespace CapnpC.Model
|
||||
{
|
||||
var node = IdToNode(file.Id);
|
||||
state.isGenerated = _request.RequestedFiles.Where(req => req.Id == file.Id).Any();
|
||||
ProcessFileAnnotations(node, file.File);
|
||||
ProcessNestedNodes(node.NestedNodes, state);
|
||||
}
|
||||
}
|
||||
@ -219,17 +230,6 @@ namespace CapnpC.Model
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessFileAnnotations(Schema.Node.Reader fileNode, GenFile fileElement)
|
||||
{
|
||||
foreach (var annotation in fileNode.Annotations)
|
||||
{
|
||||
if (annotation.Id == 0xb9c6f99ebf805f2c) // Cxx namespace
|
||||
{
|
||||
fileElement.Namespace = annotation.Value.Text.Split(new string[1] { "::" }, default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessBrand(Schema.Brand.Reader brandReader, Type type, Pass2State state)
|
||||
{
|
||||
foreach (var scopeReader in brandReader.Scopes)
|
||||
|
@ -54,6 +54,16 @@ namespace CapnpC.Model
|
||||
}
|
||||
}
|
||||
|
||||
public GenFile File
|
||||
{
|
||||
get
|
||||
{
|
||||
IHasNestedDefinitions cur = this;
|
||||
while (cur is TypeDefinition def) cur = def.DeclaringElement;
|
||||
return cur as GenFile;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<GenericParameter> AllTypeParameters
|
||||
{
|
||||
get
|
||||
|
Loading…
x
Reference in New Issue
Block a user