public void Visit(ProcedureDefinition statement)
        {
            var argList = new List<CodeParameterDeclarationExpression>();
            foreach (var arg in statement.Args)
            {
                var variableType = TablePrimitive.FromString(arg.Type).Type;
                var codeParam = new CodeParameterDeclarationExpression(variableType, arg.Variable);
                Scope.Current.RegisterPrimitive(codeParam.Name, variableType, codeParam.Type);
                Scope.Current.Type.Type.Members.Add(new CodeMemberField() { Name = codeParam.Name, Type = codeParam.Type, Attributes = MemberAttributes.Public | MemberAttributes.Final });

                var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + codeParam.Name), new CodeVariableReferenceExpression(codeParam.Name));
                _mainType.Constructor.Statements.Add(assignment);

                argList.Add(codeParam);
            }

            _mainType.Type.Name = statement.Name;
            _mainType.Constructor.Parameters.Clear();
            _mainType.Constructor.BaseConstructorArgs.Clear();
            _mainType.Constructor.Parameters.AddRange(argList.ToArray());
            _mainType.Constructor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(new CodeTypeReference(typeof(string[])), 0));

            //visit block
            var blockArgs = VisitChild(statement.Block);
            _codeStack.Peek().ParentStatements.AddRange(blockArgs.ParentStatements);
        }
Пример #2
0
        public void Visit(ProcedureDefinition definition, CommonTree tree)
        {
            Parent(tree).Children.Add(definition);
            SetLine(definition, tree);

            definition.Name = tree.Children[0].Text;
            Visit(tree.Children[1]);

            if (tree.Children.Count > 2)
            {
                var args = tree.Children[2] as CommonTree;
                foreach (var arg in args.Children)
                    definition.Children.Add(new TableColumnArg() { Variable = arg.GetChild(0).Text, Type = arg.GetChild(1).Text });
            }
        }