public void Visit(AstNamespace nameSpace) { Graph .AddNode(nameSpace.AccessName) .SetLabel(Graph.Table("Namespace", nameSpace.Name)) .AddEdgeFrom( nameSpace.HasParentNamespace ? nameSpace.ParentNamespace.AccessName : "GMacAST Root" ); AddConstants(nameSpace.AccessName, nameSpace.ChildConstants); AddStructures(nameSpace.AccessName, nameSpace.ChildStructures); AddMacros(nameSpace.AccessName, nameSpace.ChildMacros); foreach (var child in nameSpace.ChildNamespaces) { child.AcceptVisitor(this); } foreach (var child in nameSpace.ChildFrames) { child.AcceptVisitor(this); } var n = nameSpace.ParentSymbolsCount; _namespacesSubGraphs[n].AddNode(nameSpace.AccessName); }
public TreeNode Visit(AstNamespace item) { var node = new TreeNode(item.Name) { Tag = item, ImageKey = @"Namespace64.png", SelectedImageKey = @"Namespace64.png" }; node.Nodes.AddRange( item.ChildNamespaces.OrderBy(i => i.Name).Select(Visit).ToArray() ); node.Nodes.AddRange( item.ChildFrames.OrderBy(i => i.Name).Select(Visit).ToArray() ); node.Nodes.AddRange( item.ChildConstants.OrderBy(i => i.Name).Select(Visit).ToArray() ); node.Nodes.AddRange( item.ChildStructures.OrderBy(i => i.Name).Select(Visit).ToArray() ); node.Nodes.AddRange( item.ChildTransforms.OrderBy(i => i.Name).Select(Visit).ToArray() ); node.Nodes.AddRange( item.ChildMacros.OrderBy(i => i.Name).Select(Visit).ToArray() ); return(node); }
public AstNamespace CreateNamespace(AstNamespace parent) { if (Left == null) { return(new AstNamespace(parent, Name, Location)); } return(new AstNamespace(Left.CreateNamespace(parent), Name, Location)); }
/// <summary> /// Adds the child scope of the given namespace to the opened scopes /// </summary> /// <param name="symbol"></param> public void OpenScope(AstNamespace symbol) { if (symbol.IsNullOrInvalid()) { this.ReportNormal("Open Scope", ProgressEventArgsResult.Failure); return; } RefResContext.OpenScope(symbol); this.ReportNormal("Open Scope", symbol.AccessName, ProgressEventArgsResult.Success); }
/// <summary> /// Close the child scope of the given namespace /// </summary> /// <param name="symbol"></param> public void CloseScope(AstNamespace symbol) { if (symbol.IsNullOrInvalid()) { this.ReportNormal("Close Scope", ProgressEventArgsResult.Failure); return; } _symbolsCache.Clear(); RefResContext.CloseScope(symbol); this.ReportNormal("Close Scope", symbol.AccessName, ProgressEventArgsResult.Success); }
private void GenerateNamespaceCode(AstNamespace namespaceInfo) { _currentNamespace = namespaceInfo; CodeFilesComposer.DownFolder(namespaceInfo.Name); CodeFilesComposer.InitalizeFile(namespaceInfo.Name + "Utils.cs", GenerateCodeFileStartCode); ActiveFileTextComposer.AppendLineAtNewLine(@"public static class " + namespaceInfo.Name + "Utils"); ActiveFileTextComposer.AppendLineAtNewLine("{"); ActiveFileTextComposer.IncreaseIndentation(); foreach (var constantInfo in namespaceInfo.ChildConstants) { GenerateConstantCode(constantInfo); } foreach (var macroInfo in namespaceInfo.ChildMacros) { GenerateMacroCode(macroInfo); } ActiveFileTextComposer.DecreaseIndentation(); ActiveFileTextComposer.AppendLineAtNewLine("}"); CodeFilesComposer.UnselectActiveFile(GenerateCodeFileEndCode); foreach (var frameInfo in namespaceInfo.ChildFrames) { GenerateFrameCode(frameInfo); } foreach (var structureInfo in namespaceInfo.ChildStructures) { GenerateStructureCode(structureInfo); } foreach (var childNamespaceInfo in namespaceInfo.ChildNamespaces) { GenerateNamespaceCode(childNamespaceInfo); } CodeFilesComposer.UpFolder(); }
AstILNode CreateNode(AstNamespace ns, Namespace parent) { if (parent.UnoName != ns.Name.Symbol) { throw new FatalException(ns.Name.Source, ErrorCode.I3331, "Invalid namespace name"); } parent.Packages.Add(ns.Name.Source.Package); _astMap.Add(parent, ns); var result = new AstILNode(parent, ns); foreach (var e in ns.Namespaces) { result.Nodes.Add(CreateNode(e, _resolver.GetNamespace(parent, e.Name.Symbol))); } return(result); }
/// <summary> /// Find a namespace given a text reference starting at the current scope information /// </summary> /// <param name="symbolName"></param> /// <returns></returns> public AstNamespace Namespace(string symbolName) { symbolName = symbolName.Trim(); AstNamespace symbolInfo; LanguageSymbol symbol; if (_symbolsCache.TryGetValue(symbolName, out symbol)) { symbolInfo = new AstNamespace(symbol as GMacNamespace); } else { symbolInfo = _expressionCompiler.GetNamespace(symbolName); AddToSymbolsCache(symbolName, symbolInfo.AssociatedNamespace); } this.ReportNormal("Request Namespace " + symbolName.DoubleQuote(), symbolInfo.IsNotNullAndValid()); return(symbolInfo); }
void AddSourceFiles(SourcePackage upk, string arg, List <Task> tasks, List <IEnumerable <AstDocument> > files) { // 1) See if SourcePackage already has IL cached in memory, and skip the AST. // This is normally used to speed up `uno doctor`. if (_env.CanCacheIL && upk.Cache.ContainsKey(SourcePackage.ILKey)) { Log.UltraVerbose("Using IL from memory cache in " + upk); return; } // 2) See if SourcePackage already has AST cached in memory, // without any new source files added by UX compiler var upkSourceFileCount = !upk.IsCached || _env.Test(upk.Source, upk.BuildCondition) ? upk.SourceFiles.Count : 0; int cachedSourceFileCount; List <AstDocument> result; if (upk.TryGetCache(AstKey, out result) && upk.TryGetCache(SourceFileCountKey, out cachedSourceFileCount) && cachedSourceFileCount == upkSourceFileCount) { Log.UltraVerbose("Using AST from memory cache in " + upk); files.Add(result); return; } // 3) If no cache was available we must load from disk result = new List <AstDocument>(); upk.Cache[AstKey] = result; files.Add(result); if (upk.IsCached) { if (!_env.Test(upk.Source, upk.BuildCondition)) { // Add empty namespaces when skipping a package. // This is needed for not breaking any 'using <skipped-package>;' directives. var root = new AstDocument(upk.Source); lock (result) result.Add(root); foreach (var ns in upk.CachedNamespaces) { var parent = (AstNamespace)root; foreach (var p in ns.Split('.')) { var ast = new AstNamespace(new AstIdentifier(upk.Source, p)); parent.Namespaces.Add(ast); parent = ast; } } upk.Cache[SourceFileCountKey] = 0; return; } BeginTask(tasks, () => { try { AstCache.Deserialize(upk, Path.Combine(upk.CacheDirectory, "lib." + AstCache.MagicString), result); } catch (Exception e) { Log.Error(upk.Source, ErrorCode.E0000, "Failed to load AST cache: " + e.Message); } }); } else { foreach (var rf in upk.SourceFiles) { if (_env.Test(_upk.Source, rf.Condition)) { BeginTask(tasks, () => AstCache.Load(upk, rf.UnixPath, result)); } } } upk.Cache[SourceFileCountKey] = upk.SourceFiles.Count; }
public string Visit(AstNamespace item) { var composer = CreateColumnsComposer(); composer .AppendToColumns("Namespace Name:", item.AccessName) .AppendEmptyStringsToColumns() .AppendToColumns( "Namespaces:", item .Namespaces .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Frames:", item .Frames .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Multivector Types:", item .FrameMultivectors .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Subspaces:", item .Subspaces .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Structures:", item .Structures .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Constants:", item .Constants .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Transforms:", item .Transforms .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ) .AppendEmptyStringsToColumns() .AppendToColumns( "Macros:", item .Macros .Select(t => t.AccessName) .OrderBy(t => t) .Concatenate(Environment.NewLine) ); return composer.GenerateText(); }
public bool ContainsMainScope(AstNamespace scopeSymbol) { return(ContainsMainScope(scopeSymbol.AssociatedNamespace.ChildScope)); }
public GMacRefResContextInfo(AstNamespace scopeSymbol) { MainScope = scopeSymbol.AssociatedNamespace.ChildScope; }
public GMacRefResContextInfo CloseScope(AstNamespace scopeSymbol) { return(CloseScope(scopeSymbol.AssociatedNamespace.ChildScope)); }
public void Add(AstNamespace ns) { _nodes.Add(CreateNode(ns, _il)); }
/// <summary> /// Initialize this interpreter by: /// 1- Set the root AST of this interpreter to the given namespace's AST /// 2- Create a temp command block for this interpreter inside the given namespace /// 3- Initialize the scope information by setting the main scope to the command block with no /// opened scopes /// 4- Initialize the internal expression evaluator to dynamic evaluation mode on the command block /// </summary> /// <param name="symbol"></param> /// <returns></returns> public void Reset(AstNamespace symbol) { Reset((AstSymbol)symbol); }
public AstILNode(Namespace il, AstNamespace ast) { IL = il; Ast = ast; }