public void Visit(VariableReferance variable)
        {
            IScopeData codeType;
            Scope scope = Scope.Current;

            if (!Scope.Current.IsRegistered(variable.Id)) //If variable doesn't exist we need to register Sematic error
            {
                Errors.Add(new UnknownVariableReferenceException(new Semantic.LineInfo(variable.Line.Line, variable.Line.CharacterPosition), variable.Id));
                codeType = new ScopeData<TableDescriptor> { Type = new TableDescriptor(null), CodeDomReference = new CodeTypeReference("Table", new CodeTypeReference("3ab508bc-31b8-486f-a10a-4f5714f80a3b")) };
            }
            else
            {
                scope = Scope.FindScope(variable.Id);
                codeType = scope.GetScope(variable.Id);
            }

            _codeStack.Peek().Scope = codeType;
            _codeStack.Peek().CodeExpression = scope.CreateExpression(variable.Id);
        }
Esempio n. 2
0
        public void Visit(SelectId id)
        {
            _codeStack.Peek().Scope = new ScopeData<Type> { Type = typeof(int), CodeDomReference = new CodeTypeReference(typeof(int)) };
            _codeStack.Peek().CodeExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("row"), id.Id);
             _codeStack.Peek()
                   .ParentStatements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("result"),
                       "AddColumn",
                       new CodePrimitiveExpression(id.Id)));

            //1. Here we need to look through the select scope to get the variable.
            //If there, put correct table prefix.
            //if more than one we need to throw error
            //if we can't find we need to dig up the scope

            var tableMatches = Scope.Current.FindTableVariable(id.Id);

            if(tableMatches.Length > 0)
            {
                if (tableMatches.Length == 1) //we only found one
                {
                    _codeStack.Peek().CodeExpression = new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression("row"), tableMatches[0].TableAlias), id.Id);
                    _codeStack.Peek().Scope = new ScopeData<Type> { Type = tableMatches[0].TableVariable.Primitive.Type, CodeDomReference = new CodeTypeReference(tableMatches[0].TableVariable.Primitive.Type) };
                }
                else //error we found more than 1
                    Errors.Add(new AmbiguousSelectVariable(tableMatches, new Semantic.LineInfo(id.Line.Line, id.Line.CharacterPosition)));
            }
            else //not found in the table variable so look up scope
            {
                //Need to check in the Scope to see if variable is defined there. If in select statmenet it is valid to put variables in it.
                if (Scope.Current.IsRegistered(id.Id))
                {
                    var variable = new VariableReferance() { Id = id.Id, Line = id.Line };
                    var variableArgs = VisitChild(variable);
                    _codeStack.Peek().CodeExpression = variableArgs.CodeExpression;
                    _codeStack.Peek().Scope = variableArgs.Scope;
                }
                else
                    Errors.Add(new UnknownSelectVariableException(new Semantic.LineInfo(id.Line.Line, id.Line.CharacterPosition), id.Id));
            }
        }
Esempio n. 3
0
        public void Visit(VariableReferance variable, CommonTree tree)
        {
            Parent(tree).Children.Add(variable);
            SetLine(variable, tree);

            variable.Id = tree.Text;
        }