Skip to content

Commit

Permalink
Revert "Various fixes after udpate to stc v6 (#304)" (#307)
Browse files Browse the repository at this point in the history
This reverts commit 0df9240.
  • Loading branch information
PTKu authored May 6, 2024
1 parent 90c982a commit 4f7ad6a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ 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("}");
Expand Down
38 changes: 19 additions & 19 deletions src/AXSharp.compiler/src/ixr/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,35 @@ void Generate(Options o)

void IterateSyntaxTreeForStringLiterals(ISyntaxNode root, LocalizedStringWrapper lw, string fileName)
{
//foreach (var literalSyntax in GetChildNodesRecursive(root).OfType<ILiteralSyntax>())
//{
// var token = literalSyntax.Tokens.First();
// //literalSyntax.Location
// AddToDictionaryIfLocalizedString(token,lw,fileName);
//}
foreach (var literalSyntax in GetChildNodesRecursive(root).OfType<ILiteralSyntax>())
{
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<PragmaSyntax>())
{
var token = pragmaSyntax;
if (lw.IsAttributeNamePragmaToken(token.PragmaContent))
{
AddToDictionaryIfLocalizedString(token, lw, fileName);
}
}
//foreach (var pragmaSyntax in GetChildNodesRecursive(root).OfType<PragmaSyntax>())
//{
// var token = pragmaSyntax.PragmaToken;
// if(lw.IsAttributeNamePragmaToken(token.Text))
// {
// AddToDictionaryIfLocalizedString(token,lw,fileName);
// }
//}
}

void AddToDictionaryIfLocalizedString(PragmaSyntax token, LocalizedStringWrapper lw, string fileName)
void AddToDictionaryIfLocalizedString(ISyntaxToken token, LocalizedStringWrapper lw, string fileName)
{
// if is valid token
if(IsStringToken(token) || IsPragmaToken(token))
{
// try to acquire localized string
var localizedStringList = lw.TryToGetLocalizedStrings(token.PragmaContent);
var localizedStringList = lw.TryToGetLocalizedStrings(token.Text);

if(localizedStringList == null)
{
Expand All @@ -139,15 +139,15 @@ void AddToDictionaryIfLocalizedString(PragmaSyntax token, LocalizedStringWrapper
//check if identifier is valid
if(lw.IsValidId(id))
{
var pos = token.SourceText.GetLineSpan(token.Span).StartLinePosition;
var pos = token.Location.GetLineSpan().StartLinePosition;
var wrapper = new StringValueWrapper(rawText, fileName, pos.Line);
// add id and wrapper to dictionary
lw.LocalizedStringsDictionary.TryAdd(id, wrapper);
}
}
}
}
bool IsPragmaToken(PragmaSyntax token)
bool IsPragmaToken(ISyntaxToken token)
{
//if(token.SyntaxKind == SyntaxKind.PragmaToken)
//{
Expand All @@ -156,7 +156,7 @@ bool IsPragmaToken(PragmaSyntax token)
return false;
}

bool IsStringToken(PragmaSyntax token)
bool IsStringToken(ISyntaxToken token)
{
if(token.SyntaxKind == SyntaxKind.TypedStringDToken ||
token.SyntaxKind == SyntaxKind.TypedStringSToken ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using AXSharp.Connector.ValueTypes;
using System.Collections.Generic;
using AXSharp.Connector.Localizations;
using Simatic.Ax.Stateframework;
using Simatic.Ax.StatePattern;

namespace Simatic.Ax.StateFramework
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using AXSharp.Connector.ValueTypes;
using System.Collections.Generic;
using AXSharp.Connector.Localizations;
using FileWithUsingsSimpleFirstLevelNamespace;
using FileWithUsingsSimpleQualifiedNamespace.Qualified;
using FileWithUsingsHelloLevelOne.FileWithUsingsHelloLevelTwo;

namespace FileWithUsingsSimpleFirstLevelNamespace
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using Pocos.Simatic.Ax.Stateframework;
using Pocos.Simatic.Ax.StatePattern;

namespace Pocos
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using Pocos.FileWithUsingsSimpleFirstLevelNamespace;
using Pocos.FileWithUsingsSimpleQualifiedNamespace.Qualified;
using Pocos.FileWithUsingsHelloLevelOne.FileWithUsingsHelloLevelTwo;

namespace Pocos
{
Expand Down

0 comments on commit 4f7ad6a

Please sign in to comment.