Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/ix.compiler/src/ixd/Helpers/YamlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string[] GetInheritedMembers(IClassDeclaration classDeclaration)
.Select(p => ((IClassDeclaration)p).Fields.Where(f => CanBeFieldInherited(f, classDeclaration, p))).ToList()
.ForEach(member => extendedFields = extendedFields.Concat(member));

return extendedFields.Select(f => f.FullyQualifiedName)
return extendedFields.Select(f => GetBaseUid(f))
.Concat(extendedMethods.Select(m => GetMethodUId(m))).ToArray();
}
// check if field can be inherited
Expand Down Expand Up @@ -174,35 +174,43 @@ private string GetTextFromXml(XmlNode element, PropertyInfo? prop)
return(inputParams, fullDeclaration.ToString());
}

//get uid of method
public string GetMethodUId(IMethodDeclaration methodDeclaration)
{
StringBuilder typeDeclaration = new StringBuilder();
var inputParamsDeclaration = methodDeclaration.Variables.Where(v => v.Section == Section.Input).ToList();
foreach (var p in inputParamsDeclaration)
private string GetMethodTypeDeclaration(IList<IVariableDeclaration> inputParams)
{
StringBuilder typeDeclaration = new StringBuilder();

foreach (var p in inputParams)
{
typeDeclaration.Append(p.Type);
if(inputParamsDeclaration.Last() != p)
if(inputParams.Last() != p)
{
typeDeclaration.Append(",");
}
}
return $"{methodDeclaration.FullyQualifiedName}({typeDeclaration.ToString()})";
}
return typeDeclaration.ToString();
}

//get uid of method
public string GetMethodUId(IMethodDeclaration methodDeclaration)
{
var inputParamsDeclaration = methodDeclaration.Variables.Where(v => v.Section == Section.Input).ToList();
var declaration=GetMethodTypeDeclaration(inputParamsDeclaration);
return $"plc.{methodDeclaration.FullyQualifiedName}({declaration})";
}
// get base uid of field
public string GetBaseUid(IDeclaration declaration) => $"plc.{declaration.FullyQualifiedName}";
//get id of method
public string GetMethodId(IMethodDeclaration methodDeclaration)
{
var inputParamsDeclaration = methodDeclaration.Variables.Where(v => v.Section == Section.Input).ToList();
var declaration=GetMethodTypeDeclaration(inputParamsDeclaration);
return $"plc.{methodDeclaration.Name}({declaration})";
}

public string GetMethodUId(IMethodPrototypeDeclaration methodDeclaration)
{
StringBuilder typeDeclaration = new StringBuilder();
var inputParamsDeclaration = methodDeclaration.Variables.Where(v => v.Section == Section.Input).ToList();
foreach (var p in inputParamsDeclaration)
{
typeDeclaration.Append(p.Type);
if (inputParamsDeclaration.Last() != p)
{
typeDeclaration.Append(",");
}
}
return $"{methodDeclaration.FullyQualifiedName}({typeDeclaration.ToString()})";
var declaration=GetMethodTypeDeclaration(inputParamsDeclaration);
return $"plc.{methodDeclaration.FullyQualifiedName}({declaration.ToString()})";
}


Expand Down Expand Up @@ -276,11 +284,11 @@ public void AddInheritedMembersReferences(Item item, MyNodeVisitor v)
//add references for namespace
public void AddNamespaceReference(IDeclaration declaration, MyNodeVisitor v)
{
if (v.YamlHelper.NamespaceReferences.Where(a => a.Uid == declaration.FullyQualifiedName).Count() > 0)
if (v.YamlHelper.NamespaceReferences.Where(a => a.Uid == GetBaseUid(declaration)).Count() > 0)
return;
var reference = new Reference
{
Uid = declaration.FullyQualifiedName,
Uid = GetBaseUid(declaration),
Name = declaration.Name,
FullName = declaration.FullyQualifiedName,
NameWithType = declaration.Name
Expand All @@ -290,11 +298,11 @@ public void AddNamespaceReference(IDeclaration declaration, MyNodeVisitor v)
//add general reference
public void AddReference(IDeclaration declaration, MyNodeVisitor v)
{
if (v.YamlHelper.References.Where(a => a.Uid == declaration.FullyQualifiedName).Count() > 0)
if (v.YamlHelper.References.Where(a => a.Uid == GetBaseUid(declaration)).Count() > 0)
return;
var reference = new Reference
{
Uid = declaration.FullyQualifiedName,
Uid = GetBaseUid(declaration),
Name = declaration.Name,
FullName = declaration.FullyQualifiedName,
NameWithType = declaration.Name
Expand Down
2 changes: 1 addition & 1 deletion src/ix.compiler/src/ixd/Ix.ixd.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
10 changes: 6 additions & 4 deletions src/ix.compiler/src/ixd/Mapper/CodeToYamlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CommandLine;
using Ix.ixc_doc.Helpers;
using Ix.ixc_doc.Schemas;
using System.Xml.Linq;


namespace Ix.ixc_doc.Mapper
Expand All @@ -20,8 +21,8 @@ public Item PopulateItem(IDeclaration declaration)
{
return new Item
{
Uid = declaration.FullyQualifiedName,
Id = declaration.Name,
Uid = _yh.GetBaseUid(declaration),
Id = declaration.Name,
Name = declaration.Name,
FullName = declaration.Name,
Namespace = declaration.ContainingNamespace?.Name,
Expand All @@ -32,7 +33,7 @@ public Item PopulateItem(IDeclaration declaration)

public Item PopulateItem(INamespaceDeclaration namespaceDeclaration)
{
var children = namespaceDeclaration.Declarations.Select(p => p.FullyQualifiedName);
var children = namespaceDeclaration.Declarations.Select(p => _yh.GetBaseUid(p));

var item = PopulateItem((IDeclaration)namespaceDeclaration);
item.Children = children.ToArray();
Expand All @@ -43,7 +44,7 @@ public Item PopulateItem(INamespaceDeclaration namespaceDeclaration)

public Item PopulateItem(IClassDeclaration classDeclaration)
{
var children = classDeclaration.Fields.Select(p => p.FullyQualifiedName);
var children = classDeclaration.Fields.Select(p => _yh.GetBaseUid(p));
var methods = classDeclaration.Methods.Select(p => _yh.GetMethodUId(p));

List<IFieldDeclaration> extendedFields = new List<IFieldDeclaration>();
Expand Down Expand Up @@ -93,6 +94,7 @@ public Item PopulateItem(IMethodDeclaration methodDeclaration)

var item = PopulateItem((IDeclaration)methodDeclaration);
item.Uid = _yh.GetMethodUId(methodDeclaration);
item.Id = _yh.GetMethodId(methodDeclaration);
item.Parent = methodDeclaration.ContainingClass.FullyQualifiedName;
item.Type = "Method";
item.Syntax = new Syntax
Expand Down
2 changes: 1 addition & 1 deletion src/ix.compiler/src/ixd/Visitors/YamlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public virtual void CreateNamespaceYaml(INamespaceDeclaration namespaceDeclarati
//populate item of namepsace
var item = _mp.PopulateItem(namespaceDeclaration);
// create toc item
var tocSchemaItem = new TocSchema.Item(namespaceDeclaration.FullyQualifiedName, namespaceDeclaration.Name);
var tocSchemaItem = new TocSchema.Item(_yh.GetBaseUid(namespaceDeclaration), namespaceDeclaration.Name);

// add to namespace group if is not global
if (namespaceDeclaration.FullyQualifiedName != "$GLOBAL")
Expand Down