/// <summary>
 /// <summary>
 /// Constructor for Function type.
 /// </summary>
 /// <param name="name">The name of the function</param>
 /// <param name="location">The FileSpan location of the function</param>
 /// <param name="parent">the parent of the current CodeFile</param>
 /// <param name="currentCodeFile">The current CodeFile</param>
 public FunctionDefinition(string name, FileSpan location, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, location, parent, currentCodeFile)
 {
     Parameters = new List <FormalParameter>();
     IsOverride = false;
     ReturnType = String.Empty;
 }
Пример #2
0
        private AbstractSyntaxEntity(string name, FileSpan location)
            : this()
        {
            //Anonymous functions are AbstractSyntaxEntities but don't have names. So cannot
            //block empty/null name here.
            Debug.Assert(location != null, "Location of entity must be specified.");

            this.Name     = name;
            this.Location = location;
        }
Пример #3
0
 private static FileSpan processSpan(FileSpan current, FileLinePositionSpan toCombine)
 {
     if (current == null)
     {
         return(new FileSpan(toCombine));
     }
     else
     {
         return(FileSpan.Combine(current, new FileSpan(toCombine)));
     }
 }
Пример #4
0
        public IEnumerable <CompileError> GetDiagnostics(string programText)
        {
            SyntaxTree tree        = CSharpSyntaxTree.ParseText(programText);
            var        diagnostics = tree.GetDiagnostics();
            var        errorList   = new List <CompileError>();

            foreach (var diagnostic in diagnostics)
            {
                var span          = diagnostic.Location.GetMappedLineSpan();
                var errorLocation = new FileSpan(span);
                var error         = new CompileError(diagnostic.GetMessage(), errorLocation);
                errorList.Add(error);
            }

            return(errorList);
        }
Пример #5
0
        internal static Comment GetComment(ISyntaxEntity owner, CSharpSyntaxNode node, SyntaxTree tree, CodeFile currentCodeFile)
        {
            var trivias = node.GetLeadingTrivia().Where(t => t.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia ||
                                                        t.Kind() == SyntaxKind.MultiLineCommentTrivia ||
                                                        t.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia ||
                                                        t.Kind() == SyntaxKind.SingleLineCommentTrivia);

            if (trivias.Any())
            {
                string   commentText = String.Empty;
                FileSpan overallSpan = null;

                foreach (var trivia in trivias)
                {
                    if (trivia != null && trivia.Token.Value != null)
                    {
                        overallSpan = processSpan(overallSpan, tree.GetLineSpan(trivia.Span));

                        if (trivia.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia ||
                            trivia.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia)
                        {
                            var xml = trivia.GetStructure();
                            commentText += String.Join(Environment.NewLine, xml.GetText().Lines);
                        }
                        else
                        {
                            commentText += trivia.ToFullString();
                        }
                    }
                }

                var comment = new Comment(commentText, overallSpan, owner, currentCodeFile);
                comment.Parent = owner;

                currentCodeFile.AddComment(comment);
                return(comment);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        public static FileSpan Combine(FileSpan fileSpan1, FileSpan fileSpan2)
        {
            if (fileSpan1 == null)
            {
                return(fileSpan2);
            }
            if (fileSpan2 == null)
            {
                return(fileSpan1);
            }
            //Starting line of the new span is the lesser of the two line numbers
            //Starting column is the column of the 'earlier' span
            int startLine = fileSpan1.StartLineNumber <= fileSpan2.StartLineNumber ? fileSpan1.StartLineNumber : fileSpan2.StartLineNumber;
            int startCol  = fileSpan1.StartLineNumber <= fileSpan2.StartLineNumber ? fileSpan1.StartColumn : fileSpan2.StartColumn;
            //Ending line of the new span is the greater of the two line numbers
            //Ending column is the column of the 'later' span
            int endLine = fileSpan1.EndLineNumber >= fileSpan2.EndLineNumber ? fileSpan1.EndLineNumber : fileSpan2.EndLineNumber;
            int endCol  = fileSpan1.EndLineNumber >= fileSpan2.EndLineNumber ? fileSpan1.EndColumn : fileSpan2.EndColumn;

            return(new LanguageService.FileSpan(startLine, startCol, endLine, endCol));
        }
Пример #7
0
 public NamespaceDefinition(string typeName, FileSpan fileLocation, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(typeName, fileLocation, parent, currentCodeFile)
 {
 }
Пример #8
0
 internal MemberProperty(string name, FileSpan loc, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, loc, parent, currentCodeFile)
 {
 }
Пример #9
0
 protected AbstractSyntaxEntity(string name, FileSpan location, ISyntaxEntity parent, CodeFile currentCodeFile)
     : this(name, location, parent)
 {
     this.CurrentCodeFile = currentCodeFile;
 }
Пример #10
0
 private AbstractSyntaxEntity(string name, FileSpan location, ISyntaxEntity parent)
     : this(name, location)
 {
     this.Parent = parent;             //OK if the parent is null.
 }
Пример #11
0
 public FormalParameter(string typeName, string parameterName, ParameterModifiers modifiers, FileSpan location)
     : this(typeName, parameterName)
 {
     this.Modifiers = modifiers;
     this.Location  = location;
 }
Пример #12
0
 internal CodeFile(string name, FileSpan location, ILanguage language)
     : base(name, location, null, null)
 {
     base.CurrentCodeFile = this;
     Language             = language;
 }
Пример #13
0
 protected Variable(string name, FileSpan location, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, location, parent, currentCodeFile)
 {
 }
Пример #14
0
 public UserDefinedType(string text, FileSpan fileSpan, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(text, fileSpan, parent, currentCodeFile)
 {
 }
Пример #15
0
 public IfBlock(string typeName, FileSpan fileLocation, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(typeName, fileLocation, parent, currentCodeFile)
 {
 }
Пример #16
0
 public Comment(string text, FileSpan span, ISyntaxEntity belongsTo, CodeFile currentCodeFile)
     : base(text, span, belongsTo, currentCodeFile)
 {
 }
 internal AbstractAddressableEntity(string name, FileSpan loc, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, loc, parent, currentCodeFile)
 {
     init();
 }
Пример #18
0
 public CompileError(string errorText, FileSpan location)
 {
     this.ErrorText = errorText;
     this.Location  = location;
     this.Name      = errorText;
 }