コード例 #1
0
        public override void EnterClassDef([NotNull] DaedalusParser.ClassDefContext context)
        {
            var className   = context.nameNode().GetText();
            var classSymbol = SymbolBuilder.BuildClass(className, 0, 0, GetLocation(context));

            _assemblyBuilder.AddSymbol(classSymbol);

            var  classId        = classSymbol.Index;
            int  classVarOffset = classSymbol.ClassOffset;
            uint classLength    = 0;

            // TODO: refactor later
            foreach (var varDeclContext in context.varDecl())
            {
                var typeName = varDeclContext.typeReference().GetText();
                var type     = DatSymbolTypeFromString(typeName);

                for (int i = 0; i < varDeclContext.ChildCount; i++)
                {
                    var varContext = varDeclContext.GetChild(i);

                    if (varContext is TerminalNodeImpl)
                    {
                        continue; // skips ','
                    }
                    if (varContext is DaedalusParser.VarValueDeclContext varValueContext)
                    {
                        var name     = varValueContext.nameNode().GetText();
                        var location = GetLocation(context);

                        var symbol = SymbolBuilder.BuildClassVar(name, type, 1, className, classId,
                                                                 classVarOffset, location); // TODO : Validate params
                        _assemblyBuilder.AddSymbol(symbol);

                        classVarOffset += (type == DatSymbolType.String ? 20 : 4);
                        classLength++;
                    }

                    if (varContext is DaedalusParser.VarArrayDeclContext varArrayContext)
                    {
                        var name     = varArrayContext.nameNode().GetText();
                        var location = GetLocation(context);
                        var size     = EvaluatorHelper.EvaluteArraySize(varArrayContext.arraySize(), _assemblyBuilder);

                        var symbol = SymbolBuilder.BuildClassVar(name, type, (uint)size, className, classId,
                                                                 classVarOffset, location); // TODO : Validate params
                        _assemblyBuilder.AddSymbol(symbol);

                        classVarOffset += (type == DatSymbolType.String ? 20 : 4) * size;
                        classLength++;
                    }
                }
            }

            classSymbol.ArrayLength = classLength;
            classSymbol.ClassSize   = classVarOffset - classSymbol.ClassOffset;
        }
コード例 #2
0
        public override ASTNode VisitClassDef([NotNull] DaedalusParser.ClassDefContext context)
        {
            NameNode nameNode = new NameNode(GetLocation(context.nameNode()), context.nameNode().GetText());
            List <DeclarationNode> varDeclarationNodes = new List <DeclarationNode>();

            foreach (DaedalusParser.VarDeclContext varDeclContext in context.varDecl())
            {
                ASTNode node = VisitVarDecl(varDeclContext);


                if (node is TemporaryNode temporaryNode)
                {
                    varDeclarationNodes.AddRange(temporaryNode.Nodes);
                }
                else
                {
                    varDeclarationNodes.Add((VarDeclarationNode)node);
                }
            }
            return(new ClassDefinitionNode(GetLocation(context), nameNode, varDeclarationNodes));
        }
コード例 #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DaedalusParser.classDef"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitClassDef([NotNull] DaedalusParser.ClassDefContext context)
 {
     return(VisitChildren(context));
 }
コード例 #4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="DaedalusParser.classDef"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitClassDef([NotNull] DaedalusParser.ClassDefContext context)
 {
 }