예제 #1
0
        public void Visit(BufferTable table)
        {
            var descriptor = new TableDescriptor(typeof(BufferTable<>));
            var bufferTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
            bufferTable.BaseTypes.Add(new CodeTypeReference("IRow"));

            var bufferCodeDomType = new CodeTypeReference("CodeTable", new CodeTypeReference(table.Variable));
            Scope.Current.Type.Type.Members.Add(
                new CodeMemberField(bufferCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });

            Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
                new CodeSnippetExpression(table.Variable),
                new CodeObjectCreateExpression(
                    new CodeTypeReference("BufferTable", new CodeTypeReference(table.Variable)))));

            foreach (var arg in table.Args)
            {
                var domArg = VisitChild(arg);
                bufferTable.Members.AddRange(domArg.ParentMemberDefinitions);
                descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive = TablePrimitive.FromString(arg.Type) });
            }

            _mainType.Type.Members.Add(bufferTable);

            if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));

            Scope.Current.RegisterTable(table.Variable, descriptor, bufferCodeDomType);
        }
예제 #2
0
        public void Visit(FileTable table)
        {
            var descriptor = new TableDescriptor(typeof(FileTable<>));
            var fileTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
            fileTable.BaseTypes.Add(new CodeTypeReference("IRowWriter"));
            fileTable.BaseTypes.Add(new CodeTypeReference("IRowReader"));

            //field
            var fileTableCodeDomType = new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable));
            Scope.Current.Type.Type.Members.Add(
                new CodeMemberField(fileTableCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });

            var locationArg = VisitChild(table.Location);

            //constructor
            Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
                new CodeSnippetExpression(table.Variable),
                new CodeObjectCreateExpression(
                    new CodeTypeReference("FileTable", new CodeTypeReference(table.Variable)))));

            BuildIRowWriterImplementation(fileTable, table.Args);
            BuildIRowReaderImplementation(fileTable, table.Args);

            foreach (var arg in table.Args)
            {
                var domArg = VisitChild(arg);
                fileTable.Members.AddRange(domArg.ParentMemberDefinitions);
                descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive= TablePrimitive.FromString(arg.Type)});
            }

            _mainType.Type.Members.Add(fileTable);

            if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));

            Scope.Current.RegisterTable(table.Variable, descriptor, fileTableCodeDomType);

            //Init Code
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Init_" + fileTable.Name;
            method.Attributes = MemberAttributes.Private;

            _mainType.Type.Members.Add(method);
            var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".Location"), locationArg.CodeExpression);
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".FieldTerminator"), new CodePrimitiveExpression(table.FieldTerminator));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".RowTerminator"), new CodePrimitiveExpression(table.RowTerminator));
            method.Statements.Add(assignment);

            method.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable), "Load"));

            var methodcall = new CodeMethodInvokeExpression(
               new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }
예제 #3
0
        public void Visit(MsSqlTable table)
        {
            var descriptor = new TableDescriptor(typeof(MsSqlTable<>));
            var sqlTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
            sqlTable.BaseTypes.Add(new CodeTypeReference("IRow"));

            var sqlTableCodeDomType = new CodeTypeReference("MsSqlTable", new CodeTypeReference(table.Variable));
            Scope.Current.Type.Type.Members.Add(
                new CodeMemberField(sqlTableCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });

            Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
               new CodeSnippetExpression(table.Variable),
               new CodeObjectCreateExpression(
                   new CodeTypeReference("MsSqlTable", new CodeTypeReference(table.Variable)))));

            var codeExpressions = new List<CodeExpression>();
            foreach (var arg in table.Args)
            {
                var domArg = VisitChild(arg);
                sqlTable.Members.AddRange(domArg.ParentMemberDefinitions);
                codeExpressions.Add(new CodePrimitiveExpression(arg.Variable));
                descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive = TablePrimitive.FromString(arg.Type) });
            }

            _mainType.Type.Members.Add(sqlTable);

            if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
                Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));

            Scope.Current.RegisterTable(table.Variable, descriptor, sqlTableCodeDomType);

            //Init Code
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Init_" + sqlTable.Name;
            method.Attributes = MemberAttributes.Private;

            _mainType.Type.Members.Add(method);

            var assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".ConnectionString"), new CodePrimitiveExpression(table.ConnectionString));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".Table"), new CodePrimitiveExpression(table.Table));
            method.Statements.Add(assignment);

            assignment = new CodeAssignStatement(new CodeVariableReferenceExpression("_" + Scope.Current.ScopeIdentifier + "." + table.Variable + ".FieldNames"),
                new CodeArrayCreateExpression(new CodeTypeReference(typeof(string)), codeExpressions.ToArray()));
            method.Statements.Add(assignment);

            var methodcall = new CodeMethodInvokeExpression(
               new CodeMethodReferenceExpression(null, method.Name));

            _codeStack.Peek().ParentStatements.Add(methodcall);
            _codeStack.Peek().CodeExpression = methodcall;
        }