diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerSourceBuilder.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerSourceBuilder.cs index 2e571f30..964e6ce3 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerSourceBuilder.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Onliner/CsOnlinerSourceBuilder.cs @@ -55,6 +55,11 @@ public void CreateFile(IFileSyntax fileSyntax, IxNodeVisitor visitor) AddToSource("using System.Collections.Generic;"); AddToSource("using AXSharp.Connector.Localizations;"); + foreach (var fileSyntaxUsingDirective in fileSyntax.UsingDirectives) + { + AddToSource($"using {fileSyntaxUsingDirective.QualifiedIdentifierList.GetText()};"); + } + fileSyntax.Declarations.ToList().ForEach(p => p.Visit(visitor, this)); } diff --git a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Plain/CsPlainSourceBuilder.cs b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Plain/CsPlainSourceBuilder.cs index fb532a3c..0ed3172a 100644 --- a/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Plain/CsPlainSourceBuilder.cs +++ b/src/AXSharp.compiler/src/AXSharp.Cs.Compiler/Plain/CsPlainSourceBuilder.cs @@ -179,6 +179,12 @@ public virtual void CreateNamedValueTypeDeclaration(INamedValueTypeDeclaration n public void CreateFile(IFileSyntax fileSyntax, IxNodeVisitor visitor) { AddToSource("using System;"); + + foreach (var fileSyntaxUsingDirective in fileSyntax.UsingDirectives) + { + AddToSource($"using Pocos.{fileSyntaxUsingDirective.QualifiedIdentifierList.GetText()};"); + } + AddToSource("namespace Pocos {"); fileSyntax.Declarations.ToList().ForEach(p => p.Visit(visitor, this)); AddToSource("}"); diff --git a/src/AXSharp.compiler/src/ixr/Program.cs b/src/AXSharp.compiler/src/ixr/Program.cs index c9cc0794..a0129977 100644 --- a/src/AXSharp.compiler/src/ixr/Program.cs +++ b/src/AXSharp.compiler/src/ixr/Program.cs @@ -93,35 +93,35 @@ void Generate(Options o) void IterateSyntaxTreeForStringLiterals(ISyntaxNode root, LocalizedStringWrapper lw, string fileName) { - foreach (var literalSyntax in GetChildNodesRecursive(root).OfType()) - { - var token = literalSyntax.Tokens.First(); - //literalSyntax.Location - AddToDictionaryIfLocalizedString(token,lw,fileName); - } + //foreach (var literalSyntax in GetChildNodesRecursive(root).OfType()) + //{ + // var token = literalSyntax.Tokens.First(); + // //literalSyntax.Location + // AddToDictionaryIfLocalizedString(token,lw,fileName); + //} } void IterateSyntaxTreeForPragmas(ISyntaxNode root, LocalizedStringWrapper lw, string fileName) { - //foreach (var pragmaSyntax in GetChildNodesRecursive(root).OfType()) - //{ - // var token = pragmaSyntax.PragmaToken; - // if(lw.IsAttributeNamePragmaToken(token.Text)) - // { - // AddToDictionaryIfLocalizedString(token,lw,fileName); - // } - //} + foreach (var pragmaSyntax in GetChildNodesRecursive(root).OfType()) + { + var token = pragmaSyntax; + if (lw.IsAttributeNamePragmaToken(token.PragmaContent)) + { + AddToDictionaryIfLocalizedString(token, lw, fileName); + } + } } -void AddToDictionaryIfLocalizedString(ISyntaxToken token, LocalizedStringWrapper lw, string fileName) +void AddToDictionaryIfLocalizedString(PragmaSyntax token, LocalizedStringWrapper lw, string fileName) { // if is valid token if(IsStringToken(token) || IsPragmaToken(token)) { // try to acquire localized string - var localizedStringList = lw.TryToGetLocalizedStrings(token.Text); + var localizedStringList = lw.TryToGetLocalizedStrings(token.PragmaContent); if(localizedStringList == null) { @@ -139,7 +139,7 @@ void AddToDictionaryIfLocalizedString(ISyntaxToken token, LocalizedStringWrapper //check if identifier is valid if(lw.IsValidId(id)) { - var pos = token.Location.GetLineSpan().StartLinePosition; + var pos = token.SourceText.GetLineSpan(token.Span).StartLinePosition; var wrapper = new StringValueWrapper(rawText, fileName, pos.Line); // add id and wrapper to dictionary lw.LocalizedStringsDictionary.TryAdd(id, wrapper); @@ -147,7 +147,7 @@ void AddToDictionaryIfLocalizedString(ISyntaxToken token, LocalizedStringWrapper } } } -bool IsPragmaToken(ISyntaxToken token) +bool IsPragmaToken(PragmaSyntax token) { //if(token.SyntaxKind == SyntaxKind.PragmaToken) //{ @@ -156,7 +156,7 @@ bool IsPragmaToken(ISyntaxToken token) return false; } -bool IsStringToken(ISyntaxToken token) +bool IsStringToken(PragmaSyntax token) { if(token.SyntaxKind == SyntaxKind.TypedStringDToken || token.SyntaxKind == SyntaxKind.TypedStringSToken || diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/class_extended_by_known_type.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/class_extended_by_known_type.g.cs index e296c211..da3314b6 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/class_extended_by_known_type.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/class_extended_by_known_type.g.cs @@ -3,6 +3,8 @@ using AXSharp.Connector.ValueTypes; using System.Collections.Generic; using AXSharp.Connector.Localizations; +using Simatic.Ax.Stateframework; +using Simatic.Ax.StatePattern; namespace Simatic.Ax.StateFramework { diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/file_with_usings.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/file_with_usings.g.cs index 1f3ba8e0..7960acb2 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/file_with_usings.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/Onliners/file_with_usings.g.cs @@ -3,6 +3,9 @@ using AXSharp.Connector.ValueTypes; using System.Collections.Generic; using AXSharp.Connector.Localizations; +using FileWithUsingsSimpleFirstLevelNamespace; +using FileWithUsingsSimpleQualifiedNamespace.Qualified; +using FileWithUsingsHelloLevelOne.FileWithUsingsHelloLevelTwo; namespace FileWithUsingsSimpleFirstLevelNamespace { diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/class_extended_by_known_type.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/class_extended_by_known_type.g.cs index d0264b84..c2efaa77 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/class_extended_by_known_type.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/class_extended_by_known_type.g.cs @@ -1,4 +1,6 @@ using System; +using Pocos.Simatic.Ax.Stateframework; +using Pocos.Simatic.Ax.StatePattern; namespace Pocos { diff --git a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/file_with_usings.g.cs b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/file_with_usings.g.cs index cd26fc5e..0d64ca0c 100644 --- a/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/file_with_usings.g.cs +++ b/src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/samples/units/expected/.g/POCO/file_with_usings.g.cs @@ -1,4 +1,7 @@ using System; +using Pocos.FileWithUsingsSimpleFirstLevelNamespace; +using Pocos.FileWithUsingsSimpleQualifiedNamespace.Qualified; +using Pocos.FileWithUsingsHelloLevelOne.FileWithUsingsHelloLevelTwo; namespace Pocos {