示例#1
0
        public override void EnterParameterDecl(DaedalusParser.ParameterDeclContext context)
        {
            BaseExecBlockContext baseExecBlock = _assemblyBuilder.ExecBlocks.Last();
            string execBlockName      = baseExecBlock.GetSymbol().Name;
            string parameterLocalName = context.nameNode().GetText();
            string parameterName      = $"{execBlockName}.{parameterLocalName}";

            int parentIndex = DatSymbol.NULL_INDEX;

            string        parameterTypeName = context.typeReference().GetText();
            DatSymbolType?parameterType     = DatSymbolTypeFromString(parameterTypeName);

            if (parameterType is DatSymbolType.Class)
            {
                parameterType = DatSymbolType.Instance;
                var parentSymbol = _assemblyBuilder.ResolveSymbol(parameterTypeName);
                parentIndex = parentSymbol.Index;
            }

            DatSymbol symbol;
            var       location = GetLocation(context);

            var arraySizeContext = context.arraySize();

            if (arraySizeContext != null)
            {
                if (!uint.TryParse(arraySizeContext.GetText(), out var arrIndex))
                {
                    var constSymbol = _assemblyBuilder.ResolveSymbol(arraySizeContext.GetText());
                    if (constSymbol.Flags != DatSymbolFlag.Const || constSymbol.Type != DatSymbolType.Int)
                    {
                        throw new Exception($"Expected integer constant: {arraySizeContext.GetText()}");
                    }

                    arrIndex = (uint)(int)constSymbol.Content[0];
                }

                symbol = SymbolBuilder.BuildArrOfVariables(parameterName, parameterType.Value, arrIndex, location);
            }
            else
            {
                if (_assemblyBuilder.IsCurrentlyParsingExternals)
                {
                    symbol = SymbolBuilder.BuildExternalParameter(parameterName, parameterType.Value, location, parentIndex);
                }
                else
                {
                    symbol = SymbolBuilder.BuildParameter(parameterName, parameterType.Value, location, parentIndex);
                }
            }

            _assemblyBuilder.AddSymbol(symbol);
        }
示例#2
0
        public override ASTNode VisitParameterDecl([NotNull] DaedalusParser.ParameterDeclContext context)
        {
            NodeLocation location     = GetLocation(context);
            NameNode     typeNameNode = new NameNode(GetLocation(context.dataType()), context.dataType().GetText());
            NameNode     nameNode     = new NameNode(GetLocation(context.nameNode()), context.nameNode().GetText());

            if (context.arraySize() != null)
            {
                var arraySize = (ExpressionNode)VisitArraySize(context.arraySize());
                ParameterArrayDeclarationNode parameterArrayDeclarationNode = new ParameterArrayDeclarationNode(location, typeNameNode, nameNode, arraySize);
                _arrayDeclarationNodes.Add(parameterArrayDeclarationNode);
                return(parameterArrayDeclarationNode);
            }
            return(new ParameterDeclarationNode(location, typeNameNode, nameNode));
        }
示例#3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DaedalusParser.parameterDecl"/>.
 /// <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 VisitParameterDecl([NotNull] DaedalusParser.ParameterDeclContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="DaedalusParser.parameterDecl"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitParameterDecl([NotNull] DaedalusParser.ParameterDeclContext context)
 {
 }