public void Visit(VariableReferance variable, CommonTree tree) { Parent(tree).Children.Add(variable); SetLine(variable, tree); variable.Id = tree.Text; }
public void Visit(SelectId id) { var selectInfo = new SelectArgsInfo(); _codeStack.Peek().Scope = new ScopeData <Type> { Type = typeof(int?), CodeDomReference = new CodeTypeReference(typeof(int?)) }; _codeStack.Peek().CodeExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("row"), id.Id); selectInfo.ColumnName = id.Id; _codeStack.Peek().Tag = selectInfo; //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); var dynamicAlias = Scope.Current.AliasType <DynamicObject>(); 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 if (dynamicAlias.Length == 1) //if there is an dynamic alias in the select scope we try to get the variable from it even if it might be in the global scope { _codeStack.Peek().CodeExpression = new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("row"), dynamicAlias[0]), new CodePrimitiveExpression(id.Id)); _codeStack.Peek().Scope = new ScopeData <Type> { Type = typeof(string), CodeDomReference = new CodeTypeReference(typeof(string)) }; } else //not found in the table variable so look up scope. if dynamic table we need to generate { //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)); } } }
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)); } } }
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); }