// Ceptr menu events

/*
 *              protected void BuildSemanticTree(object sender, EventArgs args)
 *              {
 *                      CeptrInterface.CreateStructureAndSymbolNodes();
 *                      SemanticID floatID = CeptrInterface.GetFloat();
 *                      SemanticID latitude = CeptrInterface.DeclareSymbol(CeptrInterface.RootSymbolsNode, floatID, "latitude");
 *                      SemanticID longitude = CeptrInterface.DeclareSymbol(CeptrInterface.RootSymbolsNode, floatID, "longitude");
 *
 *                      // Structure latlong = _d_define_structure(structures,"latlong",RECEPTOR_CONTEXT, 2, lat, lon);
 *                      SemanticID latlong = CeptrInterface.DefineStructure(CeptrInterface.RootStructuresNode, "latlong", new SemanticID[] { latitude, longitude });
 *
 *                      string retSymbols = CeptrInterface.DumpSymbols(CeptrInterface.RootSymbolsNode, CeptrInterface.RootStructuresNode);
 *                      string retStructures = CeptrInterface.DumpStructures(CeptrInterface.RootSymbolsNode, CeptrInterface.RootStructuresNode);
 *              }
 */
        // Common helpers for symbol and structure controllers:

        // Recurse into a symbol, creating the child symbols first and then defining the structure composed of the child symbols.
        public SemanticID Recurse(Symbol symbol, Dictionary <string, SemanticID> structureMap, Dictionary <string, SemanticID> symbolMap)
        {
            List <SemanticID> syms      = new List <SemanticID>();
            SemanticID        structure = GetStructureID(symbol.Structure, structureMap);

            foreach (Symbol child in symbol.Symbols)
            {
                // We need to recurse to get to native types, from which more complex symbols are constructed.
                Recurse(child, structureMap, symbolMap);
                SemanticID uchild;

                if (!symbolMap.ContainsKey(child.Name))
                {
                    SemanticID id = GetStructureID(child.Structure, structureMap);
                    uchild = CeptrInterface.DeclareSymbol(CeptrInterface.RootSymbolsNode, id, child.Name);
                    syms.Add(uchild);
                    symbolMap[child.Name] = uchild;
                }
                else
                {
                    // Re-use the symbol ID.
                    uchild = symbolMap[child.Name];
                    syms.Add(uchild);
                }
            }

            if (syms.Count > 0)
            {
                structure = CeptrInterface.DefineStructure(CeptrInterface.RootStructuresNode, symbol.Structure, syms.ToArray());
                structureMap[symbol.Structure] = structure;
            }
            return(structure);
        }
Esempio n. 2
0
        public void CreateStructuresAndSymbols()
        {
            symbolMap    = new Dictionary <string, SemanticID>();
            structureMap = new Dictionary <string, SemanticID>();

            ApplicationController.CeptrInterface.CreateStructureAndSymbolNodes();

            foreach (string symbolName in ApplicationModel.SymbolRefCount.Keys)
            {
                if (!symbolMap.ContainsKey(symbolName))
                {
                    // Find the symbol in the tree.
                    Symbol symbol = FindSymbolInTree(symbolName, ApplicationController.SymbolEditorController.View.TreeView.Nodes);

                    if (symbol == null)
                    {
                        throw new Exception("The symbol " + symbolName + " should have been found in the tree.");
                    }

                    SemanticID topStructure = ApplicationController.Recurse(symbol, structureMap, symbolMap);
                    SemanticID symbolID     = ApplicationController.CeptrInterface.DeclareSymbol(ApplicationController.CeptrInterface.RootSymbolsNode, topStructure, symbolName);
                    symbolMap[symbolName] = symbolID;
                }
            }
        }
Esempio n. 3
0
        public void ShowSymbolDump(Symbol symbol)
        {
            View.Output.Text = String.Empty;

            try
            {
                ApplicationController.CeptrInterface.CreateStructureAndSymbolNodes();
                Dictionary <string, SemanticID> structureMap = new Dictionary <string, SemanticID>();
                Dictionary <string, SemanticID> symbolMap    = new Dictionary <string, SemanticID>();
                SemanticID topStructure = ApplicationController.Recurse(symbol, structureMap, symbolMap);
                ApplicationController.CeptrInterface.DeclareSymbol(ApplicationController.CeptrInterface.RootSymbolsNode, topStructure, symbol.Name);

                string ret = ApplicationController.CeptrInterface.DumpSymbols(ApplicationController.CeptrInterface.RootSymbolsNode, ApplicationController.CeptrInterface.RootStructuresNode);
                View.Output.Text = ApplicationController.FormatDump(ret);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }