/// <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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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)));
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 7
0
 public NamespaceDefinition(string typeName, FileSpan fileLocation, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(typeName, fileLocation, parent, currentCodeFile)
 {
 }
Ejemplo n.º 8
0
 internal MemberProperty(string name, FileSpan loc, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, loc, parent, currentCodeFile)
 {
 }
Ejemplo n.º 9
0
 protected AbstractSyntaxEntity(string name, FileSpan location, ISyntaxEntity parent, CodeFile currentCodeFile)
     : this(name, location, parent)
 {
     this.CurrentCodeFile = currentCodeFile;
 }
Ejemplo n.º 10
0
 private AbstractSyntaxEntity(string name, FileSpan location, ISyntaxEntity parent)
     : this(name, location)
 {
     this.Parent = parent;             //OK if the parent is null.
 }
Ejemplo n.º 11
0
 public FormalParameter(string typeName, string parameterName, ParameterModifiers modifiers, FileSpan location)
     : this(typeName, parameterName)
 {
     this.Modifiers = modifiers;
     this.Location  = location;
 }
Ejemplo n.º 12
0
 internal CodeFile(string name, FileSpan location, ILanguage language)
     : base(name, location, null, null)
 {
     base.CurrentCodeFile = this;
     Language             = language;
 }
Ejemplo n.º 13
0
 protected Variable(string name, FileSpan location, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(name, location, parent, currentCodeFile)
 {
 }
Ejemplo n.º 14
0
 public UserDefinedType(string text, FileSpan fileSpan, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(text, fileSpan, parent, currentCodeFile)
 {
 }
Ejemplo n.º 15
0
 public IfBlock(string typeName, FileSpan fileLocation, ISyntaxEntity parent, CodeFile currentCodeFile)
     : base(typeName, fileLocation, parent, currentCodeFile)
 {
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 18
0
 public CompileError(string errorText, FileSpan location)
 {
     this.ErrorText = errorText;
     this.Location  = location;
     this.Name      = errorText;
 }