private void Implement_Template(GMacMacroTemplate macroTemplate, GMacFrame frame)
        {
            try
            {
                Context.MarkCheckPointState();

                Context.PushState(frame.ChildSymbolScope);

                var macro = GMacMacroGenerator.Translate(Context, macroTemplate.TemplateParseNode);
                _generatedMacros.Add(macro);

                Context.PopState();

                Context.UnmarkCheckPointState();
            }
            catch (CompilerException)
            {
                Context.RestoreToCheckPointState();
            }
            catch (Exception e)
            {
                Context.RestoreToCheckPointState();
                throw (new Exception("Unhandled Exception", e));
            }
        }
Exemple #2
0
        public static GMacMacro Translate(GMacSymbolTranslatorContext context, ParseTreeNode node)
        {
            //var eventId = context.CompilationLog.TimeCounter.StartEvent("macro gen");

            context.PushState(RoleNames.Macro, node);

            var translator = new GMacMacroGenerator();//new GMacMacroGenerator(context);

            translator.SetContext(context);
            translator.Translate();

            context.PopState();

            var result = translator._generatedMacro;

            //MasterPool.Release(translator);

            //context.CompilationLog.TimeCounter.EndEvent(eventId);

            return(result);
        }
Exemple #3
0
        private void translate_GMacDSL_Items_List(ParseTreeNode node)
        {
            if (CompilationLog.HasErrors && CompilationLog.StopOnFirstError)
            {
                return;
            }

            var subnode = node.ChildNodes[0];

            if (_translateNamespaceFirst && subnode.Term.ToString() != GMacParseNodeNames.Namespace)
            {
                CompilationLog.RaiseGeneratorError <int>("DSL definitions must start with a namespace", subnode);
            }

            _translateNamespaceFirst = false;

            switch (subnode.Term.ToString())
            {
            case GMacParseNodeNames.Breakpoint:
                GMacRootAst.EnableBreakpoints = true;
                break;

            case GMacParseNodeNames.Namespace:
                GMacNamespaceGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.OpenNamespace:
                //Only namespaces and frames can be used in the 'open' statement
                Context.OpenScope(
                    (SymbolWithScope)GMacValueAccessGenerator.Translate_Direct(
                        Context,
                        subnode.ChildNodes[0],
                        new[] { RoleNames.Namespace, RoleNames.Frame }
                        )
                    );

                break;

            case GMacParseNodeNames.Frame:
                GMacFrameGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Constant:
                GMacConstantGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Structure:
                GMacStructureGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Transform:
                GMacTransformGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.Macro:
                GMacMacroGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.MacroTemplate:
                GMacMacroTemplateGenerator.Translate(Context, subnode);
                break;

            case GMacParseNodeNames.TemplatesImplementation:
                GMacTemplatesImplementationGenerator.Translate(Context, subnode);
                break;

            default:
                CompilationLog.RaiseGeneratorError <int>("DSL definitions item not recognized", subnode);
                break;
            }
        }