Exemplo n.º 1
0
 public FunctionInfo(string name, Type returnType, string body, bool isTemplateFunction, SyntaxEditorHelper.ScriptLanguageTypes scriptLanguage, string description, string templateReturnLanguage, string category)
 {
     Name                   = name;
     ReturnType             = returnType;
     Parameters             = new List <ParamInfo>();
     Body                   = body;
     IsTemplateFunction     = isTemplateFunction;
     ScriptLanguage         = scriptLanguage;
     Description            = description;
     TemplateReturnLanguage = templateReturnLanguage;
     Category               = category;
 }
        public static string ScriptLanguageNameFromEnum(SyntaxEditorHelper.ScriptLanguageTypes scriptLanguage)
        {
            switch (scriptLanguage)
            {
            case SyntaxEditorHelper.ScriptLanguageTypes.CSharp: return("C#");

            case SyntaxEditorHelper.ScriptLanguageTypes.VbNet: return("VB.Net");

            default:
                throw new NotImplementedException("Output language not handled yet: " + scriptLanguage);
            }
        }
Exemplo n.º 3
0
 public FunctionInfo(string name, Type returnType, string body, bool isTemplateFunction, SyntaxEditorHelper.ScriptLanguageTypes scriptLanguage, string description, string templateReturnLanguage, string category)
 {
     Name = name;
     ReturnType = returnType;
     Parameters = new List<ParamInfo>();
     Body = body;
     IsTemplateFunction = isTemplateFunction;
     ScriptLanguage = scriptLanguage;
     Description = description;
     TemplateReturnLanguage = templateReturnLanguage;
     Category = category;
 }
Exemplo n.º 4
0
        private static string AddDebugSymbols(string code, string functionName, SyntaxEditorHelper.ScriptLanguageTypes language)
        {
            if (code.IndexOf("¬") < 0)
            {
                code = code.Replace("\n", "¬");
            }
            else
            {
                throw new Exception("Special substitution character (¬) has been used in code. Line end substitutions can't be performed.");
            }
            string[] lines = code.Split('¬');

            // Add a 10-space buffer to the start of every line, so that we can determine correct column offsets
            // even when "Write(" is prepended to certain calls
            for (int i = 0; i < lines.Length; i++)
            {
                lines[i] = "          " + lines[i];
            }

            var sb2 = new StringBuilder(code.Length + lines.Length * 15);

            for (int lineCounter = 1; lineCounter <= lines.Length; lineCounter++)
            {
                switch (language)
                {
                case SyntaxEditorHelper.ScriptLanguageTypes.CSharp:                         // TODO: Investigate whether inserting at end is faster than appending, also whether using string.format is faster, also use AppendLine rather
                    sb2.AppendFormat("{0}/*DEBUG:{1}:{2}*/\n", lines[lineCounter - 1], functionName, lineCounter);
                    break;

                case SyntaxEditorHelper.ScriptLanguageTypes.VbNet:
                    sb2.AppendFormat("{0}'DEBUG:{1}:{2}*/\n", lines[lineCounter - 1], functionName, lineCounter);
                    break;

                default:
                    throw new NotImplementedException("Language not catered for yet.");
                }
            }
            // Remove the last linebreak;
            if (sb2[sb2.Length - 1] == '\n')
            {
                sb2.Remove(sb2.Length - 1, 1);

                if (sb2[sb2.Length - 1] == '\r')
                {
                    sb2.Remove(sb2.Length - 1, 1);
                }
            }
            else if (sb2[sb2.Length - 1] == '\r')
            {
                sb2.Remove(sb2.Length - 1, 1);
            }
            return(sb2.ToString());
        }
Exemplo n.º 5
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="o"></param>
 public FunctionInfo(FunctionInfo o)
 {
     Name                   = o.Name;
     ReturnType             = o.ReturnType;
     Parameters             = o.Parameters;
     Body                   = o.Body;
     IsTemplateFunction     = o.IsTemplateFunction;
     ScriptLanguage         = o.ScriptLanguage;
     Description            = o.Description;
     TemplateReturnLanguage = o.TemplateReturnLanguage;
     Category               = o.Category;
     IsExtensionMethod      = o.IsExtensionMethod;
     ExtendedType           = o.ExtendedType;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="o"></param>
 public FunctionInfo(FunctionInfo o)
 {
     Name = o.Name;
     ReturnType = o.ReturnType;
     Parameters = o.Parameters;
     Body = o.Body;
     IsTemplateFunction = o.IsTemplateFunction;
     ScriptLanguage = o.ScriptLanguage;
     Description = o.Description;
     TemplateReturnLanguage = o.TemplateReturnLanguage;
     Category = o.Category;
     IsExtensionMethod = o.IsExtensionMethod;
     ExtendedType = o.ExtendedType;
 }
        private static void ReadXmlFunctionNode(Project project, ICollection <string> missingTypesMessages, XPathNavigator funcNode)
        {
            string funcName = funcNode.SelectSingleNode("@name").Value;

            SyntaxEditorHelper.ScriptLanguageTypes scriptLanguage = funcNode.SelectSingleNode("@scriptlanguage") == null ? SyntaxEditorHelper.ScriptLanguageTypes.CSharp : (SyntaxEditorHelper.ScriptLanguageTypes)Enum.Parse(typeof(SyntaxEditorHelper.ScriptLanguageTypes), funcNode.SelectSingleNode("@scriptlanguage").Value, true);
            string description        = funcNode.SelectSingleNode("@description") == null ? "" : funcNode.SelectSingleNode("@description").Value;
            string category           = funcNode.SelectSingleNode("@category") == null ? "" : funcNode.SelectSingleNode("@category").Value;
            bool   isTemplateFunction = false;

            if (funcNode.SelectSingleNode("@istemplatefunction") != null)
            {
                isTemplateFunction = Boolean.Parse(funcNode.SelectSingleNode("@istemplatefunction").Value);
            }
            string templateReturnLanguage = isTemplateFunction ? funcNode.SelectSingleNode("@returntype").Value : "";

            XPathNavigator tempnode          = funcNode.SelectSingleNode("@isextensionmethod");
            bool           isExtensionMethod = tempnode == null ? false : Boolean.Parse(tempnode.Value);
            string         extendedtype      = isExtensionMethod ? funcNode.SelectSingleNode("@extendedtype").Value : "";

            Type dataType;

            if (isTemplateFunction)
            {
                dataType = typeof(string);
            }
            else
            {
                if (funcNode.SelectSingleNode("@returntype").Value != "void")
                {
                    dataType = Project.Instance.GetTypeFromReferencedAssemblies(funcNode.SelectSingleNode("@returntype").Value, false);

                    if (dataType == null)
                    {
                        missingTypesMessages.Add(String.Format("Function ({0}): The return-type ({1}) cannot be found in the referenced files. The return-type will be changed to 'void'.", funcName, funcNode.SelectSingleNode("@returntype").Value));
                    }
                }
                else
                {
                    dataType = null;
                }
            }
            project.Functions.Add(new FunctionInfo(funcName, dataType, funcNode.Value, isTemplateFunction, scriptLanguage, description, templateReturnLanguage, category, isExtensionMethod, extendedtype));
            XPathNodeIterator paramNodes = funcNode.Select("parameter");

            project.Functions[project.Functions.Count - 1].Parameters.Clear();

            if (paramNodes.Count > 0)
            {
                foreach (XPathNavigator paramNode in paramNodes)
                {
                    Type paramType = Project.Instance.GetTypeFromReferencedAssemblies(paramNode.SelectSingleNode("@type").Value, false);

                    if (paramType == null)
                    {
                        missingTypesMessages.Add(String.Format("Function ({0}): The parameter named '{1}' of type ({2}) cannot be found in the referenced files. It will be changed to type 'object'.", funcName, paramNode.SelectSingleNode("@name").Value, paramNode.SelectSingleNode("@type").Value));
                        paramType = typeof(object);
                    }
                    ParamInfo param = new ParamInfo(paramNode.SelectSingleNode("@name").Value, paramType);
                    param.Modifiers = paramNode.SelectSingleNode("@modifiers") != null?paramNode.SelectSingleNode("@modifiers").Value : "";

                    project.Functions[project.Functions.Count - 1].Parameters.Add(param);
                }
            }
        }
Exemplo n.º 8
0
 public FunctionInfo(string name, Type returnType, string body, bool isTemplateFunction, SyntaxEditorHelper.ScriptLanguageTypes scriptLanguage, string description, string templateReturnLanguage, string category, bool isExtensionMethod, string extendedType)
     : this(name, returnType, body, isTemplateFunction, scriptLanguage, description, templateReturnLanguage, category)
 {
     IsExtensionMethod = isExtensionMethod;
     ExtendedType      = extendedType;
 }