Ejemplo n.º 1
0
 public static void SetCorrectColumn(List<Variable> refVar, Statement.StatementType type, int line)
 {
     if (refVar == null)
         return;
     if (type != Statement.StatementType.Expression)
     {
         foreach (Variable singleVar in refVar)
             singleVar.MoveColumnBack(line);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 ///     Returns the names of the variables that have been declared in the statement
 /// </summary>
 /// <param name="s"> Statement whose variable names to be got.</param>
 /// <param name="onlyTopLevel"> Bool to check if required to return reference variables in sub statements as well</param>
 /// <returns></returns>
 public static List<string> GetDefinedVariableNames(Statement s, bool onlyTopLevel)
 {
     var names = s.definedVariables.Select(refVar => refVar.Name).ToList();
     if (!onlyTopLevel)
     {
         foreach (Statement subStatement in s.subStatements)
             names.AddRange(GetReferencedVariableNames(subStatement, onlyTopLevel));
     }
     return names;
 }
Ejemplo n.º 3
0
        private void ProcessCode(ref string errorMessage, ref string warningMessage)
        {
            code = CodeBlockUtils.FormatUserText(code);
            codeStatements.Clear();

            if (string.IsNullOrEmpty(Code))
            {
                previewVariable = null;
            }

            try
            {
                ParseParam parseParam = new ParseParam(this.GUID, code);
                if (GraphToDSCompiler.GraphUtilities.PreCompileCodeBlock(parseParam))
                {
                    if (parseParam.ParsedNodes != null)
                    {
                        // Create an instance of statement for each code statement written by the user
                        foreach (var parsedNode in parseParam.ParsedNodes)
                        {
                            // Create a statement variable from the generated nodes
                            codeStatements.Add(Statement.CreateInstance(parsedNode));
                        }

                        SetPreviewVariable(parseParam.ParsedNodes);
                    }
                }

                if (parseParam.Errors != null && parseParam.Errors.Any())
                {
                    errorMessage = string.Join("\n", parseParam.Errors.Select(m => m.Message));
                    ProcessError();
                    CreateInputOutputPorts();
                    return;
                }

                if (parseParam.Warnings != null)
                {
                    // Unbound identifiers in CBN will have input slots.
                    //
                    // To check function redefinition, we need to check other
                    // CBN to find out if it has been defined yet. Now just
                    // skip this warning.
                    var warnings = parseParam.Warnings.Where((w) =>
                    {
                        return(w.ID != WarningID.kIdUnboundIdentifier &&
                               w.ID != WarningID.kFunctionAlreadyDefined);
                    });

                    if (warnings.Any())
                    {
                        warningMessage = string.Join("\n", warnings.Select(m => m.Message));
                    }
                }

                if (parseParam.UnboundIdentifiers != null)
                {
                    inputIdentifiers = new List <string>(parseParam.UnboundIdentifiers);
                }
                else
                {
                    inputIdentifiers.Clear();
                }
            }
            catch (Exception e)
            {
                errorMessage    = e.Message;
                previewVariable = null;
                ProcessError();
                return;
            }

            // Set the input and output ports based on the statements
            CreateInputOutputPorts();
        }