예제 #1
0
 public DebuggerSyntaxTree(MetaSyntaxNode root, SourceText text, MetaParseOptions options)
     : base(
         text,
         text.Encoding,
         text.ChecksumAlgorithm,
         path: "",
         options: options,
         root: root,
         directives: DirectiveStack.Empty)
 {
 }
예제 #2
0
 /// <summary>
 /// <para>
 /// Internal helper for <see cref="MetaSyntaxNode"/> class to create a new syntax tree rooted at the given root node.
 /// This method does not create a clone of the given root, but instead preserves it's reference identity.
 /// </para>
 /// <para>NOTE: This method is only intended to be used from <see cref="MetaSyntaxNode.SyntaxTree"/> property.</para>
 /// <para>NOTE: Do not use this method elsewhere, instead use <see cref="Create(MetaSyntaxNode, CSharpParseOptions, string, Encoding)"/> method for creating a syntax tree.</para>
 /// </summary>
 internal static MetaSyntaxTree CreateWithoutClone(MetaSyntaxNode root)
 {
     Debug.Assert(root != null);
     return(new ParsedSyntaxTree(
                textOpt: null,
                encodingOpt: null,
                checksumAlgorithm: SourceHashAlgorithm.Sha1,
                path: "",
                options: MetaParseOptions.Default,
                root: root,
                directives: DirectiveStack.Empty,
                cloneRoot: false));
 }
예제 #3
0
 internal ParsedSyntaxTree(SourceText textOpt, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm, string path, MetaParseOptions options, MetaSyntaxNode root, DirectiveStack directives, bool cloneRoot = true)
 {
     Debug.Assert(root != null);
     Debug.Assert(options != null);
     Debug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm);
     _lazyText          = textOpt;
     _encodingOpt       = encodingOpt ?? textOpt?.Encoding;
     _checksumAlgorithm = checksumAlgorithm;
     _options           = options;
     _path = path ?? string.Empty;
     _root = cloneRoot ? this.CloneNodeAsRoot(root) : root;
     _hasCompilationUnitRoot = root.Kind == MetaSyntaxKind.Main;
     this.SetDirectiveStack(directives);
 }
예제 #4
0
        /// <summary>
        /// Creates a new syntax tree from a syntax node.
        /// </summary>
        public static MetaSyntaxTree Create(MetaSyntaxNode root, MetaParseOptions options = null, string path = "", Encoding encoding = null)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            var directives = root.Kind == MetaSyntaxKind.Main ?
                             ((ICompilationUnitRootSyntax)root).GetConditionalDirectivesStack() :
                             DirectiveStack.Empty;

            return(new ParsedSyntaxTree(
                       textOpt: null,
                       encodingOpt: encoding,
                       checksumAlgorithm: SourceHashAlgorithm.Sha1,
                       path: path,
                       options: options ?? MetaParseOptions.Default,
                       root: root,
                       directives: directives));
        }
예제 #5
0
 /// <summary>
 /// Gets the root node of the syntax tree if it is already available.
 /// </summary>
 public abstract bool TryGetRoot(out MetaSyntaxNode root);
예제 #6
0
 // REVIEW: I would prefer to not expose CloneAsRoot and make the functionality
 // internal to CaaS layer, to ensure that for a given SyntaxTree there can not
 // be multiple trees claiming to be its children.
 //
 // However, as long as we provide GetRoot extensibility point on SyntaxTree
 // the guarantee above cannot be implemented and we have to provide some way for
 // creating root nodes.
 //
 // Therefore I place CloneAsRoot API on SyntaxTree and make it protected to
 // at least limit its visibility to SyntaxTree extenders.
 /// <summary>
 /// Produces a clone of a <see cref="MetaSyntaxNode"/> which will have current syntax tree as its parent.
 ///
 /// Caller must guarantee that if the same instance of <see cref="MetaSyntaxNode"/> makes multiple calls
 /// to this function, only one result is observable.
 /// </summary>
 /// <typeparam name="T">Type of the syntax node.</typeparam>
 /// <param name="node">The original syntax node.</param>
 /// <returns>A clone of the original syntax node that has current <see cref="CSharpSyntaxTree"/> as its parent.</returns>
 protected T CloneNodeAsRoot <T>(T node) where T : MetaSyntaxNode
 {
     return(MetaSyntaxNode.CloneNodeAsRoot(node, this));
 }
예제 #7
0
 public override bool TryGetRoot(out MetaSyntaxNode root)
 {
     root = _root;
     return(true);
 }
예제 #8
0
 public DummySyntaxTree()
 {
     _node = this.CloneNodeAsRoot((MainSyntax)MainGreen.__Missing.CreateRed());
 }
예제 #9
0
 /// <summary>
 /// Creates a new syntax tree from a syntax node with text that should correspond to the syntax node.
 /// </summary>
 /// <remarks>This is used by the ExpressionEvaluator.</remarks>
 internal static MetaSyntaxTree CreateForDebugger(MetaSyntaxNode root, SourceText text, MetaParseOptions options)
 {
     Debug.Assert(root != null);
     return(new DebuggerSyntaxTree(root, text, options));
 }