Exemplo n.º 1
0
        static void GenerateAnsiC(Files files, string designerDir, string outputDir)
        {
            ConstantsGenerator generator3 = new ConstantsGenerator(
                Language.AnsiC,
                designerDir + @"\Design\UA Attributes.xml",
                outputDir,
                files.NodeDictionaries);

            generator3.Generate(
                "OpcUa",
                "Attributes",
                designerDir + @"\Design\UA Attributes.csv",
                false);

            ConstantsGenerator generator4 = new ConstantsGenerator(
                Language.AnsiC,
                designerDir + @"\Design\UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries);

            generator4.Generate(
                "OpcUa",
                "StatusCodes",
                designerDir + @"\Design\UA Status Codes.csv",
                false);

            AnsiCGenerator generator7 = new AnsiCGenerator(
                designerDir + @"\Design\UA Core Services.xml",
                outputDir,
                files.TypeDictionaries);

            generator7.Generate("OpcUa", "Core", true);
        }
Exemplo n.º 2
0
        static void GenerateDotNet(Files files, string designerDir, string outputDir, string specificationVersion)
        {
            var resourcePath = "ModelCompiler.Design";

            if (!String.IsNullOrEmpty(specificationVersion))
            {
                resourcePath = $"ModelCompiler.Design.{specificationVersion}";
            }

            ConstantsGenerator generator7 = new ConstantsGenerator(
                Language.DotNet,
                $"{designerDir}UA Attributes.xml",
                outputDir,
                files.NodeDictionaries,
                resourcePath);

            generator7.Generate(
                "Opc.Ua",
                "Attributes",
                $"{designerDir}UA Attributes.csv",
                false);

            ConstantsGenerator generator8 = new ConstantsGenerator(
                Language.DotNet,
                $"{designerDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                resourcePath);

            generator8.Generate(
                "Opc.Ua",
                "StatusCodes",
                $"{designerDir}UA Status Codes.csv",
                false);

            ConstantsGenerator generator9 = new ConstantsGenerator(
                Language.CSV,
                $"{designerDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                resourcePath);

            generator9.Generate(
                "Opc.Ua",
                "StatusCodes",
                $"{designerDir}UA Status Codes.csv",
                false);

            DotNetGenerator generator10 = new DotNetGenerator(
                $"{designerDir}UA Core Services.xml",
                outputDir,
                files.TypeDictionaries,
                resourcePath);

            generator10.Generate("Opc.Ua", "Core", true);
        }
        static void GenerateDotNet(Files files, string modelDir, string csvDir, string outputDir, string specificationVersion)
        {
            ConstantsGenerator generator7 = new ConstantsGenerator(
                Language.DotNet,
                $"{modelDir}UA Attributes.xml",
                outputDir,
                files.NodeDictionaries,
                null);

            generator7.Generate(
                "Opc.Ua",
                "Attributes",
                $"{csvDir}UA Attributes.csv",
                false);

            ConstantsGenerator generator8 = new ConstantsGenerator(
                Language.DotNet,
                $"{modelDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                null);

            generator8.Generate(
                "Opc.Ua",
                "StatusCodes",
                $"{csvDir}UA Status Codes.csv",
                false);

            ConstantsGenerator generator9 = new ConstantsGenerator(
                Language.CSV,
                $"{modelDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                null);

            generator9.Generate(
                "Opc.Ua",
                "StatusCodes",
                $"{csvDir}UA Status Codes.csv",
                false);

            DotNetGenerator generator10 = new DotNetGenerator(
                $"{modelDir}UA Core Services.xml",
                outputDir,
                files.TypeDictionaries,
                null);

            generator10.Generate("Opc.Ua", "Core", true);
        }
Exemplo n.º 4
0
        static void GenerateDotNet(Files files, string designerDir, string outputDir)
        {
            ConstantsGenerator generator7 = new ConstantsGenerator(
                Language.DotNet,
                designerDir + @"\Design\UA Attributes.xml",
                outputDir,
                files.NodeDictionaries);

            generator7.Generate(
                "Opc.Ua",
                "Attributes",
                designerDir + @"\Design\UA Attributes.csv",
                false);

            ConstantsGenerator generator8 = new ConstantsGenerator(
                Language.DotNet,
                designerDir + @"\Design\UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries);

            generator8.Generate(
                "Opc.Ua",
                "StatusCodes",
                designerDir + @"\Design\UA Status Codes.csv",
                false);

            ConstantsGenerator generator9 = new ConstantsGenerator(
                Language.CSV,
                designerDir + @"\Design\UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries);

            generator9.Generate(
                "Opc.Ua",
                "StatusCodes",
                designerDir + @"\Design\UA Status Codes.csv",
                false);

            DotNetGenerator generator10 = new DotNetGenerator(
                designerDir + @"\Design\UA Core Services.xml",
                outputDir,
                files.TypeDictionaries);

            generator10.Generate("Opc.Ua", "Core", true);
        }
Exemplo n.º 5
0
        static void GenerateAnsiC(Files files, string designerDir, string outputDir, string specificationVersion)
        {
            var resourcePath = "Opc.Ua.ModelCompiler.Design";

            if (!String.IsNullOrEmpty(specificationVersion))
            {
                resourcePath = $"Opc.Ua.ModelCompiler.Design.{specificationVersion}";
            }

            ConstantsGenerator generator3 = new ConstantsGenerator(
                Language.AnsiC,
                $"{designerDir}UA Attributes.xml",
                outputDir,
                files.NodeDictionaries,
                resourcePath);

            generator3.Generate(
                "OpcUa",
                "Attributes",
                $"{designerDir}UA Attributes.csv",
                false);

            ConstantsGenerator generator4 = new ConstantsGenerator(
                Language.AnsiC,
                $"{designerDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                resourcePath);

            generator4.Generate(
                "OpcUa",
                "StatusCodes",
                $"{designerDir}UA Status Codes.csv",
                false);

            AnsiCGenerator generator7 = new AnsiCGenerator(
                $"{designerDir}UA Core Services.xml",
                outputDir,
                files.TypeDictionaries,
                resourcePath);

            generator7.Generate("OpcUa", "Core", true);
        }
        static void GenerateAnsiC(Files files, string modelDir, string csvDir, string outputDir, string specificationVersion)
        {
            ConstantsGenerator generator3 = new ConstantsGenerator(
                Language.AnsiC,
                $"{modelDir}UA Attributes.xml",
                outputDir,
                files.NodeDictionaries,
                null);

            generator3.Generate(
                "OpcUa",
                "Attributes",
                $"{csvDir}UA Attributes.csv",
                false);

            ConstantsGenerator generator4 = new ConstantsGenerator(
                Language.AnsiC,
                $"{modelDir}UA Status Codes.xml",
                outputDir,
                files.NodeDictionaries,
                null);

            generator4.Generate(
                "OpcUa",
                "StatusCodes",
                $"{csvDir}UA Status Codes.csv",
                false);

            AnsiCGenerator generator7 = new AnsiCGenerator(
                $"{modelDir}UA Core Services.xml",
                outputDir,
                files.TypeDictionaries,
                null);

            generator7.Generate("OpcUa", "Core", true);
        }
    /// <summary>
    /// Populates tables according to the currently-processed expression.
    /// </summary>
    /// <param name="processedExpression">The expression that is being processed.</param>
    /// <param name="constantsTable">The constants table.</param>
    /// <param name="reverseConstantsTable">The reverse-lookup constants table.</param>
    /// <param name="symbolTable">The symbols table.</param>
    /// <param name="reverseSymbolTable">The reverse-lookup symbols table.</param>
    /// <param name="parameterRegistry">The parameters registry.</param>
    /// <param name="interpreters">The constant interpreters.</param>
    /// <param name="originalExpression">The expression before processing.</param>
    /// <param name="openParenthesis">The symbol of an open parenthesis.</param>
    /// <param name="allSymbols">All symbols on which to split, in order.</param>
    internal static void PopulateTables(
        string processedExpression,
        Dictionary <string, ConstantNodeBase> constantsTable,
        Dictionary <string, string> reverseConstantsTable,
        Dictionary <string, ExpressionSymbol> symbolTable,
        Dictionary <string, string> reverseSymbolTable,
        IParameterRegistry parameterRegistry,
        LevelDictionary <Type, IConstantInterpreter> interpreters,
        string originalExpression,
        string openParenthesis,
        string[] allSymbols)
    {
        // Split expression by all symbols
        string[] expressions = processedExpression.Split(
            allSymbols,
            StringSplitOptions.RemoveEmptyEntries);

        foreach (var exp in expressions)
        {
            if (constantsTable.ContainsKey(exp))
            {
                // We have a constant
                continue;
            }

            if (reverseConstantsTable.ContainsKey(exp))
            {
                // We have a constant that has bee evaluated before
                continue;
            }

            if (parameterRegistry.Exists(exp))
            {
                // We have a parameter
                continue;
            }

            if (symbolTable.ContainsKey(exp))
            {
                // We have an already-existing symbol
                continue;
            }

            if (reverseSymbolTable.ContainsKey(exp))
            {
                // We have a symbol value that has been evaluated before
                continue;
            }

            if (exp.Contains(openParenthesis))
            {
                // We have a part of a function
                continue;
            }

            // Let's check whether it is a constant
            if (ConstantsGenerator.CheckAndAdd(
                    constantsTable,
                    reverseConstantsTable,
                    interpreters,
                    originalExpression,
                    exp) != null)
            {
                continue;
            }

            // It's not a constant, nor something ever encountered before
            // Therefore it should be a parameter
            _ = parameterRegistry.AdvertiseParameter(exp);
        }
    }
    public string ExtractAllConstants(
        string originalExpression,
        IDictionary <string, ConstantNodeBase> constantsTable,
        IDictionary <string, string> reverseConstantsTable,
        MathDefinition mathDefinition)
    {
        var stringIndicatorString = mathDefinition.StringIndicator;
        var stringIndicator       = mathDefinition.StringIndicator.AsSpan();
        var stringIndicatorLength = stringIndicator.Length;
        var escapeCharacter       = mathDefinition.EscapeCharacter.AsSpan();
        var escapeCharacterLength = escapeCharacter.Length;

        var           process = originalExpression.AsSpan();
        StringBuilder?sb      = null;

        while (true)
        {
            var openingPosition = process.IndexOf(
                stringIndicator,
                StringComparison.CurrentCulture);

            if (openingPosition == -1)
            {
                // No string opening
                break;
            }

            var header = process.Slice(
                0,
                openingPosition);

            var rest = process.Slice(openingPosition + stringIndicatorLength);

            int closingPosition;
            ReadOnlySpan <char> body;

            do
            {
                closingPosition = rest.IndexOf(stringIndicator, StringComparison.CurrentCulture);

                if (closingPosition != -1)
                {
                    body = rest.Slice(
                        0,
                        closingPosition);

                    int occurrences = 0;

                    while (body.EndsWith(escapeCharacter))
                    {
                        occurrences++;
                        body = body.Slice(
                            0,
                            body.Length - escapeCharacterLength);
                    }

                    rest = rest.Slice(closingPosition + stringIndicatorLength);

                    if (occurrences % 2 == 0)
                    {
                        break;
                    }
                }
            }while (closingPosition != -1);

            if (closingPosition == -1)
            {
                // No string closing
                break;
            }

            // We have a proper string
            body = process.Slice(
                openingPosition,
                process.Length - header.Length - rest.Length);

            var itemName = ConstantsGenerator.GenerateStringConstant(
                constantsTable,
                reverseConstantsTable,
                originalExpression,
                stringIndicatorString,
                body.ToString());

            sb ??= new StringBuilder(originalExpression.Length);

            #if NETSTANDARD21_OR_GREATER
            sb.Append(header);
            #else
            sb.Append(header.ToString());
            #endif

            sb.Append(itemName);

            process = rest;
        }

        if (sb == null)
        {
            return(originalExpression);
        }

        #if NETSTANDARD21_OR_GREATER
        sb.Append(process);
        #else
        sb.Append(process.ToString());
        #endif

        return(sb.ToString());
    }
Exemplo n.º 9
0
            static string?ReplaceFunctionsLocal(
                string source,
                string openParenthesisSymbol,
                string closeParenthesisSymbol,
                string parameterSeparatorSymbol,
                Dictionary <string, ConstantNodeBase> constantsTableReference,
                Dictionary <string, string> reverseConstantsTableReference,
                Dictionary <string, ExpressionSymbol> symbolTableReference,
                Dictionary <string, string> reverseSymbolTableReference,
                LevelDictionary <Type, IConstantInterpreter> interpretersReference,
                IParameterRegistry parametersTableReference,
                string expressionSymbol,
                string[] allSymbolsSymbols)
            {
                var op  = -1;
                var opl = openParenthesisSymbol.Length;
                var cpl = closeParenthesisSymbol.Length;

                while (true)
                {
                    op = source.InvariantCultureIndexOf(
                        openParenthesisSymbol,
                        op + opl);

                    if (op == -1)
                    {
                        return(null);
                    }

                    if (op == 0)
                    {
                        continue;
                    }

                    var functionHeaderCheck = source.Substring(
                        0,
                        op);

                    if (allSymbolsSymbols.Any(
                            (
                                p,
                                check) => check.InvariantCultureEndsWith(p),
                            functionHeaderCheck))
                    {
                        continue;
                    }

                    var functionHeader = functionHeaderCheck.Split(
                        allSymbolsSymbols,
                        StringSplitOptions.None).Last();

                    var oop = source.InvariantCultureIndexOf(
                        openParenthesisSymbol,
                        op + opl);
                    var cp = source.InvariantCultureIndexOf(
                        closeParenthesisSymbol,
                        op + cpl);

                    while (oop < cp && oop != -1 && cp != -1)
                    {
                        oop = source.InvariantCultureIndexOf(
                            openParenthesisSymbol,
                            oop + opl);
                        cp = source.InvariantCultureIndexOf(
                            closeParenthesisSymbol,
                            cp + cpl);
                    }

                    if (cp == -1)
                    {
                        continue;
                    }

                    var arguments = source.Substring(
                        op + opl,
                        cp - op - opl);
                    var originalArguments = arguments;

                    var q = arguments;
                    while (q != null)
                    {
                        arguments = q;
                        q         = ReplaceFunctionsLocal(
                            q,
                            openParenthesisSymbol,
                            closeParenthesisSymbol,
                            parameterSeparatorSymbol,
                            constantsTableReference,
                            reverseConstantsTableReference,
                            symbolTableReference,
                            reverseSymbolTableReference,
                            interpretersReference,
                            parametersTableReference,
                            expressionSymbol,
                            allSymbolsSymbols);
                    }

                    var argPlaceholders = new List <string>();
                    foreach (var s in arguments.Split(
                                 new[] { parameterSeparatorSymbol },
                                 StringSplitOptions.RemoveEmptyEntries))
                    {
                        TablePopulationGenerator.PopulateTables(
                            s,
                            constantsTableReference,
                            reverseConstantsTableReference,
                            symbolTableReference,
                            reverseSymbolTableReference,
                            parametersTableReference,
                            interpretersReference,
                            expressionSymbol,
                            openParenthesisSymbol,
                            allSymbolsSymbols);

                        // We check whether or not this is actually a constant
                        argPlaceholders.Add(
                            ConstantsGenerator.CheckAndAdd(
                                constantsTableReference,
                                reverseConstantsTableReference,
                                interpretersReference,
                                expressionSymbol,
                                s) ?? (!parametersTableReference.Exists(s)
                                ? SymbolExpressionGenerator.GenerateSymbolExpression(
                                           symbolTableReference,
                                           reverseSymbolTableReference,
                                           s,
                                           false)
                                : s));
                    }

                    var functionCallBody =
                        $"{functionHeader}{openParenthesisSymbol}{string.Join(parameterSeparatorSymbol, argPlaceholders)}{closeParenthesisSymbol}";
                    var functionCallToReplace =
                        $"{functionHeader}{openParenthesisSymbol}{originalArguments}{closeParenthesisSymbol}";
                    var functionCallItem = SymbolExpressionGenerator.GenerateSymbolExpression(
                        symbolTableReference,
                        reverseSymbolTableReference,
                        functionCallBody,
                        true);

                    return(source.Replace(
                               functionCallToReplace,
                               functionCallItem));
                }
            }