private protected NamedScopeImpl(CodeWorkspaceImpl workspace, INamedScope?parent) { _workspace = workspace; CodePart = new CodePart(this); Parent = parent; if (parent == null) { _name = String.Empty; _fullName = String.Empty; } }
public void MergeWith(CodeWorkspaceImpl ws, IFunctionDefinerScope h, FunctionDefiner other) { foreach (var kv in other._funcs) { if (!_funcs.TryGetValue(kv.Key, out var my)) { my = new FunctionScopeImpl(ws, h); _funcs.Add(kv.Key, my); } my.MergeWith(kv.Value); } }
internal NamespaceScopeImpl(CodeWorkspaceImpl ws, INamespaceScope?parent, string name) : base(ws, parent) { Debug.Assert((parent == null) == (name.Length == 0)); Debug.Assert(parent == null || parent is NamespaceScopeImpl); _usings = new Dictionary <string, KeyValuePair <string?, string?> >(); _subNamespaces = new List <NamespaceScopeImpl>(); _beforeNamespace = new CodePartRaw(); if (parent != null) { SetName(name); } }
/// <summary> /// Creates a root workspace. /// </summary> /// <param name="initialSource">Optional initial <see cref="ICodeWorkspace.Global"/> source code.</param> /// <param name="assembly">Optional initial <see cref="ICodeWorkspace.AssemblyReferences"/>.</param> /// <returns>A new workspace.</returns> public static ICodeWorkspace Create(string?initialSource = null, params Assembly[] assembly) { var w = new CodeWorkspaceImpl(); if (!String.IsNullOrWhiteSpace(initialSource)) { w.Global.Append(initialSource); } foreach (var a in assembly) { w.DoEnsureAssemblyReference(a); } return(w); }
public FunctionScopeImpl Create(CodeWorkspaceImpl ws, IFunctionDefinerScope h, Action <IFunctionScope> header) { if (header == null) { throw new ArgumentNullException(nameof(header)); } FunctionScopeImpl f = new FunctionScopeImpl(ws, h); header(f); f.Initialize(); _funcs.Add(f.Name, f); ws.OnFunctionCreated(f); return(f); }
public FunctionScopeImpl Create(CodeWorkspaceImpl ws, IFunctionDefinerScope h, FunctionDefinition def) { if (def == null) { throw new ArgumentNullException(nameof(def)); } if (_funcs.ContainsKey(def.Key)) { throw new ArgumentException($"Funcion or constructor with key {def.Key} already exists.", nameof(def)); } FunctionScopeImpl f = new FunctionScopeImpl(ws, h, def); _funcs.Add(f.Name, f); return(f); }
internal FunctionScopeImpl(CodeWorkspaceImpl ws, INamedScope parent) : base(ws, parent) { _funcs = new FunctionDefiner(true); INamedScope?p = parent; for (; ;) { if (p is ITypeScope t) { EnclosingType = t; break; } p = p.Parent; Debug.Assert(p != null, "We eventually reached a top level type."); } }
internal TypeScopeImpl(CodeWorkspaceImpl ws, INamedScope parent) : base(ws, parent) { UniqueId = ws.GetNextTypeScopeIdentifier(); _funcs = new FunctionDefiner(true); INamedScope?p = parent; for (; ;) { if (p is INamespaceScope ns) { Namespace = ns; break; } p = p.Parent; Debug.Assert(p != null, "We eventually reached the root namespace."); } }
internal FunctionScopeImpl(CodeWorkspaceImpl ws, INamedScope parent, FunctionDefinition def) : this(ws, parent) { _fDef = def; SetName(_fDef.Key); }
protected TypeDefinerScopeImpl(CodeWorkspaceImpl workspace, INamedScope?parent) : base(workspace, parent) { _types = new Dictionary <string, TypeScopeImpl>(); }