/// <summary>
 /// COPY a ctx (I'm deliberately not using copy constructor) to avoid
 /// confusion with creating node with parent.
 /// </summary>
 /// <remarks>
 /// COPY a ctx (I'm deliberately not using copy constructor) to avoid
 /// confusion with creating node with parent. Does not copy children.
 /// </remarks>
 public virtual void CopyFrom(Antlr4.Runtime.ParserRuleContext ctx)
 {
     this.parent        = ctx.parent;
     this.invokingState = ctx.invokingState;
     this.start         = ctx.start;
     this.stop          = ctx.stop;
 }
Exemple #2
0
 public override void CopyFrom(Antlr4.Runtime.ParserRuleContext ctx)
 {
     base.CopyFrom(ctx);
     if (ctx is ParserRuleContextWithDiagnostics)
     {
         this._diagnostics = ((ParserRuleContextWithDiagnostics)ctx)._diagnostics;
     }
 }
 public void ExitEveryRule(Antlr4.Runtime.ParserRuleContext ctx)
 {
     Console.WriteLine("Exiting rule {0}", ctx);
     if (Definitions.ContainsKey(ctx))
     {
         var definition = Definitions[ctx];
         definition.Exit();
     }
 }
        public override void CopyFrom(Antlr4.Runtime.ParserRuleContext ctx)
        {
            base.CopyFrom(ctx);
            var diagnostics = ctx as ParserRuleContextWithDiagnostics;

            if (diagnostics != null)
            {
                this._diagnostics = diagnostics._diagnostics;
            }
        }
Exemple #5
0
        private LLVMRegister VisitFunctionDeclarationBody
        (
            Antlr4.Runtime.ParserRuleContext context,
            ClepsType clepsReturnType,
            ClepsParser.FunctionParametersListContext parametersContext,
            string functionName,
            bool isStatic
        )
        {
            string className = String.Join(".", CurrentNamespaceAndClass);

            if (!ClassManager.DoesClassContainMember(className, functionName, isStatic))
            {
                //if the member was not found in the loaded member stage, then this is probably due to an earlier parsing error, just stop processing this member
                return(null);
            }

            FunctionHierarchy.Add(functionName);
            string fullyQualifiedName = String.Join(".", CurrentNamespaceAndClass.Union(FunctionHierarchy).ToList());

            LLVMValueRef      currFunc   = LLVM.GetNamedFunction(Module, fullyQualifiedName);
            LLVMBasicBlockRef basicBlock = LLVM.GetFirstBasicBlock(currFunc);

            LLVM.PositionBuilderAtEnd(Builder, basicBlock);

            VariableManager.AddBlock();

            List <string>    paramNames          = parametersContext._FunctionParameterNames.Select(p => p.VariableName.Text).ToList();
            List <ClepsType> clepsParameterTypes = parametersContext._FunctionParameterTypes.Select(t => ClepsType.GetBasicType(t)).ToList();

            if (!isStatic)
            {
                ClepsType thisClassType = ClepsType.GetBasicType(className, 1);
                paramNames.Insert(0, "this");
                clepsParameterTypes.Insert(0, thisClassType);
            }

            List <LLVMValueRef> paramValueRegisters = currFunc.GetParams().ToList();

            paramNames.Zip(clepsParameterTypes, (ParamName, ParamType) => new { ParamName, ParamType })
            .Zip(paramValueRegisters, (ParamNameAndType, ParamRegister) => new { ParamNameAndType.ParamName, ParamNameAndType.ParamType, ParamRegister })
            .ToList()
            .ForEach(p => {
                LLVMValueRef functionParamPtr = LLVM.BuildAlloca(Builder, LLVM.TypeOf(p.ParamRegister), p.ParamName);
                LLVM.BuildStore(Builder, p.ParamRegister, functionParamPtr);
                VariableManager.AddLocalVariable(p.ParamName, p.ParamType, functionParamPtr);
            });

            var ret = VisitChildren(context);

            VariableManager.RemoveBlock();
            FunctionHierarchy.RemoveAt(FunctionHierarchy.Count - 1);
            return(ret);
        }
Exemple #6
0
        private void AddGlobalsInlineDef(Antlr4.Runtime.ParserRuleContext ruleContext)
        {
            // CONSTANTS

            var allConsts = ruleContext.GetRuleContexts <DaedalusParser.ConstDefContext>();

            foreach (var c in allConsts)
            {
                foreach (var cv in c.constValueDef())
                {
                    GlobalConsts.Add(new Constant
                    {
                        Column = cv.Start.Column,
                        Line   = cv.Start.Line,
                        Name   = cv.nameNode().GetText(),
                        Type   = c.typeReference().GetText(),
                        Value  = cv.constValueAssignment().expressionBlock().GetText(),
                    });
                }
            }

            // VARIABLES

            var allVarDecls = ruleContext.GetRuleContexts <DaedalusParser.VarDeclContext>();

            foreach (var v in allVarDecls)
            {
                foreach (var vals in v.varValueDecl())
                {
                    GlobalVars.Add(new Variable
                    {
                        Name   = vals.nameNode().GetText(),
                        Type   = v.typeReference().GetText(),
                        Line   = vals.nameNode().Start.Line,
                        Column = vals.nameNode().Start.Column
                    });
                }
                foreach (var innerVarDecl in v.varDecl())
                {
                    foreach (var vals in v.varValueDecl())
                    {
                        GlobalVars.Add(new Variable
                        {
                            Name   = vals.nameNode().GetText(),
                            Type   = v.typeReference().GetText(),
                            Line   = vals.nameNode().Start.Line,
                            Column = vals.nameNode().Start.Column
                        });
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// COPY a ctx (I'm deliberately not using copy constructor) to avoid
        /// confusion with creating node with parent. Does not copy children.
        ///
        /// This is used in the generated parser code to flip a generic XContext
        /// node for rule X to a YContext for alt label Y. In that sense, it is
        /// not really a generic copy function.
        ///
        /// If we do an error sync() at start of a rule, we might add error nodes
        /// to the generic XContext so this function must copy those nodes to
        /// the YContext as well else they are lost!
        /// </summary>
        public virtual void CopyFrom(Antlr4.Runtime.ParserRuleContext ctx)
        {
            // from RuleContext
            this.Parent        = ctx.Parent;
            this.invokingState = ctx.invokingState;
            this._start        = ctx._start;
            this._stop         = ctx._stop;

            // copy any error nodes to alt label node
            if (ctx.children != null)
            {
                children = new List <IParseTree>();
                // reset parent pointer for any error nodes
                foreach (var child in ctx.children)
                {
                    var errorChildNode = child as ErrorNodeImpl;
                    if (errorChildNode != null)
                    {
                        children.Add(errorChildNode);
                        errorChildNode.Parent = this;
                    }
                }
            }
        }
Exemple #8
0
 public virtual void ExitEveryRule(ParserRuleContext ctx)
 {
     _output.WriteLine("exit    " + this._enclosing.RuleNames[ctx.RuleIndex] + ", LT(1)=" + this._enclosing._input.LT(1).Text);
 }
 public ParserRuleContext(Antlr4.Runtime.ParserRuleContext parent, int invokingStateNumber)
     : base(parent, invokingStateNumber)
 {
 }
 /// <inheritdoc/>
 /// <remarks>The default implementation does nothing.</remarks>
 public virtual void ExitEveryRule([NotNull] ParserRuleContext context)
 {
 }
 public XSharpParserRuleContext(Antlr4.Runtime.ParserRuleContext parent, int state) : base(parent, state)
 {
 }
 /// <summary>
 /// Method that encapsulates how to get the coordenate of the node in the AST
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private Coord GetCoord(Antlr4.Runtime.ParserRuleContext context)
 {
     return(new Coord(context.Start.Line, context.Start.Column));
     //return new Coord(((dynamic)context).Depth(), ((dynamic)context).getAltNumber());
 }
Exemple #13
0
 public SemanticException(Antlr4.Runtime.ParserRuleContext context, string message) : base(message)
 {
     Context = context;
 }
 public override void ExitEveryRule(ParserRuleContext context)
 {
     Logger.writeLog("{end rule: " + this.parser.RuleNames[context.RuleIndex] + " : " + context.Start.Text + "}\n");
 }
Exemple #15
0
 public virtual void EnterRecursionRule(ParserRuleContext localctx, int ruleIndex)
 {
     EnterRecursionRule(localctx, Atn.ruleToStartState[ruleIndex].stateNumber, ruleIndex, 0);
 }
Exemple #16
0
        private void AddGlobalsBlockDef(Antlr4.Runtime.ParserRuleContext ruleContext)
        {
            // Classes

            var allClassDefs = ruleContext.GetRuleContexts <DaedalusParser.ClassDefContext>();

            foreach (var cd in allClassDefs)
            {
                var classVars   = new List <Variable>();
                var allVarDecls = cd.varDecl();
                if (allVarDecls != null)
                {
                    foreach (var v in allVarDecls)
                    {
                        foreach (var vals in v.varValueDecl())
                        {
                            classVars.Add(new Variable
                            {
                                Name   = vals.nameNode().GetText(),
                                Type   = v.typeReference().GetText(),
                                Line   = vals.nameNode().Start.Line,
                                Column = vals.nameNode().Start.Column
                            });
                        }
                    }
                }
                GlobalClasses.Add(new Class
                {
                    Fields = classVars,
                    Name   = cd.nameNode().GetText(),
                    Line   = cd.nameNode().Start.Line,
                    Column = cd.nameNode().Start.Column,
                });
            }

            // Prototypes

            var allPrototypeDefs = ruleContext.GetRuleContexts <DaedalusParser.PrototypeDefContext>();

            foreach (var pd in allPrototypeDefs)
            {
                GlobalPrototypes.Add(new Prototype
                {
                    Name   = pd.nameNode().GetText(),
                    Column = pd.nameNode().Start.Column,
                    Line   = pd.nameNode().Start.Line,
                    Parent = pd.parentReference().Identifier().GetText(),
                });
            }

            // INSTANCES

            var allInsts = ruleContext.GetRuleContexts <DaedalusParser.InstanceDefContext>();

            foreach (var inst in allInsts)
            {
                GlobalInstances.Add(new Instance
                {
                    Column = inst.nameNode().Start.Column,
                    Line   = inst.nameNode().Start.Line,
                    Name   = inst.nameNode().GetText(),
                    Parent = inst.parentReference().GetText(),
                });
            }
        }
Exemple #17
0
 public virtual void ExitEveryRule(ParserRuleContext ctx)
 {
     System.Console.Out.WriteLine("exit    " + this._enclosing.RuleNames[ctx.GetRuleIndex
                                                                             ()] + ", LT(1)=" + this._enclosing._input.Lt(1).Text);
 }
Exemple #18
0
 public RecognitionException(string message, IRecognizer recognizer, IIntStream input, ParserRuleContext ctx)
     : base(message)
 {
     this.recognizer = recognizer;
     this.input      = input;
     this.ctx        = ctx;
     if (recognizer != null)
     {
         this.offendingState = recognizer.State;
     }
 }
Exemple #19
0
 public virtual void EnterEveryRule(ParserRuleContext ctx)
 {
 }