示例#1
0
        /// <summary>
        /// 函数参数定义
        /// </summary>
        /// <param name="node"></param>
        public void Visit(ParameterDeclarationNode node)
        {
            var builder = new StringBuilder();

            builder.Append("函数参数:");
            builder.AppendFormat("{0} {1}", node.Type, node.Name);
            Console.Write(builder.ToString());
        }
 protected override List <AssemblyElement> VisitParameterDeclaration(ParameterDeclarationNode node)
 {
     return(new List <AssemblyElement>
     {
         GetParameterPush(node.Symbol),
         GetAssignInstruction(node.Symbol),
     });
 }
        protected override List <AssemblyElement> VisitFunctionDefinition(FunctionDefinitionNode node)
        {
            List <AssemblyElement> instructions = ((BlockSymbol)node.Symbol).Instructions;

            if (node.IsExternal)
            {
                return(instructions);
            }

            for (int i = node.ParameterNodes.Count - 1; i >= 0; i--)
            {
                ParameterDeclarationNode parameterNode = node.ParameterNodes[i];
                instructions.AddRange(Visit(parameterNode));
            }
            foreach (StatementNode bodyNode in node.BodyNodes)
            {
                instructions.AddRange(Visit(bodyNode));
            }
            instructions.Add(new Ret());
            return(instructions);
        }
示例#4
0
 public Type Visit(ParameterDeclarationNode node)
 {
     foreach (var typeNode in node)
     {
         Type type = Visit((dynamic)typeNode);
         int  pos  = 0;
         foreach (var idNode in typeNode)
         {
             var varName = idNode.AnchorToken.Lexeme;
             if (CurrentScopeHasSymbol(varName))
             {
                 throw new SemanticError($"Duplicated parameter: {varName}",
                                         idNode.AnchorToken);
             }
             else
             {
                 AddSymbolToScope(varName, type, Kind.PARAM, pos: pos++, value: type.DefaultValue());
             }
         }
     }
     return(Type.VOID);
 }
示例#5
0
 public void Visit(ParameterDeclarationNode node)
 {
     // do nothing
 }
示例#6
0
 internal override void Visit(ParameterDeclarationNode node)
 {
 }