private BooleanIsNullExpression GetIsNotNull() { var isNull = new BooleanIsNullExpression(); isNull.IsNot = true; var query = (isNull.Expression = new ScalarSubquery()) as ScalarSubquery; var spec = (query.QueryExpression = new QuerySpecification()) as QuerySpecification; spec.SelectElements.Add(new SelectStarExpression()); var fromTable = new QueryDerivedTable(); spec.FromClause = new FromClause(); spec.FromClause.TableReferences.Add(fromTable); var subQuerySpec = new QuerySpecification(); var version = new GlobalVariableExpression(); version.Name = "@@version"; var columnName = new IdentifierOrValueExpression(); //var v = (columnName.ValueExpression = new StringLiteral()) as StringLiteral; //v.Value = "v"; columnName.Identifier = new Identifier(); columnName.Identifier.Value = "v"; subQuerySpec.SelectElements.Add(new SelectScalarExpression {Expression = version, ColumnName = columnName}); fromTable.QueryExpression = subQuerySpec; fromTable.Alias = new Identifier {Value = "edition"}; spec.WhereClause = new WhereClause(); var likePredicate = (spec.WhereClause.SearchCondition = new LikePredicate()) as LikePredicate; var col = (likePredicate.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression; col.ColumnType = ColumnType.Regular; col.MultiPartIdentifier = new MultiPartIdentifier(); col.MultiPartIdentifier.Identifiers.Add(new Identifier {Value = "v"}); var ver = (likePredicate.SecondExpression = new StringLiteral()) as StringLiteral; ver.Value = "%Enterprise%"; return isNull; }
public override void ExplicitVisit(GlobalVariableExpression node) { if (node.Name.ToLower().Contains("identity")) { this.InvalidVariables.Add(node); } }
protected override Expression MakeWrapper(GlobalVariableExpression variable) { Debug.Assert(!_names.IsReadOnly); int index = _names.Count; _names.Add(variable.Name); return(Expression.ArrayAccess(_array, Expression.Constant(index))); }
protected override Expression RewriteSet(AssignmentExtensionExpression node) { GlobalVariableExpression lvalue = (GlobalVariableExpression)node.Expression; return(AstUtils.Convert( Expression.Assign( MapToExpression(lvalue), AstUtils.Convert(Visit(node.Value), typeof(object)) ), node.Type )); }
private Expression Rewrite(AssignmentExtensionExpression node) { Expression lvalue = node.Expression; GlobalVariableExpression global = lvalue as GlobalVariableExpression; if (global != null) { return(RewriteSet(node)); } return(node); }
protected override Expression MakeWrapper(GlobalVariableExpression variable) { Debug.Assert(!_fields.ContainsKey(variable)); FieldBuilder field = TypeGen.TypeBuilder.DefineField( variable.Name, typeof(ModuleGlobalWrapper), FieldAttributes.Assembly | FieldAttributes.Static ); _fields.Add(variable, field); return(Expression.Field(null, field)); }
private BooleanIsNullExpression GetIsNotNull() { var isNull = new BooleanIsNullExpression(); isNull.IsNot = true; var query = (isNull.Expression = new ScalarSubquery()) as ScalarSubquery; var spec = (query.QueryExpression = new QuerySpecification()) as QuerySpecification; spec.SelectElements.Add(new SelectStarExpression()); var fromTable = new QueryDerivedTable(); spec.FromClause = new FromClause(); spec.FromClause.TableReferences.Add(fromTable); var subQuerySpec = new QuerySpecification(); var version = new GlobalVariableExpression(); version.Name = "@@version"; var columnName = new IdentifierOrValueExpression(); //var v = (columnName.ValueExpression = new StringLiteral()) as StringLiteral; //v.Value = "v"; columnName.Identifier = new Identifier(); columnName.Identifier.Value = "v"; subQuerySpec.SelectElements.Add(new SelectScalarExpression { Expression = version, ColumnName = columnName }); fromTable.QueryExpression = subQuerySpec; fromTable.Alias = new Identifier { Value = "edition" }; spec.WhereClause = new WhereClause(); var likePredicate = (spec.WhereClause.SearchCondition = new LikePredicate()) as LikePredicate; var col = (likePredicate.FirstExpression = new ColumnReferenceExpression()) as ColumnReferenceExpression; col.ColumnType = ColumnType.Regular; col.MultiPartIdentifier = new MultiPartIdentifier(); col.MultiPartIdentifier.Identifiers.Add(new Identifier { Value = "v" }); var ver = (likePredicate.SecondExpression = new StringLiteral()) as StringLiteral; ver.Value = "%Enterprise%"; return(isNull); }
protected override Expression RewriteGet(GlobalVariableExpression node) { EnsureUniqueName(node); return(AstUtils.Convert( Expression.Call( typeof(ScriptingRuntimeHelpers).GetMethod(node.IsLocal ? "LookupName" : "LookupGlobalName"), new Expression[] { Context, AstUtils.Constant(SymbolTable.StringToId(node.Name)) } ), node.Type )); }
protected Expression MapToExpression(GlobalVariableExpression variable) { Expression result; if (_mapToExpression.TryGetValue(variable, out result)) { return(result); } EnsureUniqueName(_globalNames, variable); result = Expression.Property( MakeWrapper(variable), typeof(ModuleGlobalWrapper).GetProperty("CurrentValue") ); return(_mapToExpression[variable] = result); }
protected override Expression RewriteSet(AssignmentExtensionExpression node) { GlobalVariableExpression lvalue = (GlobalVariableExpression)node.Expression; EnsureUniqueName(lvalue); return(AstUtils.Convert( Expression.Call( typeof(ScriptingRuntimeHelpers).GetMethod(lvalue.IsLocal ? "SetName" : "SetGlobalName"), new Expression[] { Context, AstUtils.Constant(SymbolTable.StringToId(lvalue.Name)), Visit(node.Value) } ), node.Type )); }
protected override Expression VisitExtension(Expression node) { if (node is YieldExpression || node is GeneratorExpression || node is FinallyFlowControlExpression) { // These should be rewritten last, when doing finaly compilation // for now, just walk them so we can find other nodes return(base.VisitExtension(node)); } GlobalVariableExpression global = node as GlobalVariableExpression; if (global != null) { return(RewriteGet(global)); } CodeContextExpression cc = node as CodeContextExpression; if (cc != null) { return(_context); } CodeContextScopeExpression ccs = node as CodeContextScopeExpression; if (ccs != null) { return(Rewrite(ccs)); } AssignmentExtensionExpression aee = node as AssignmentExtensionExpression; if (aee != null) { return(Rewrite(aee)); } // Must remove extension nodes because they could contain // one of the above node types. See, e.g. DeleteUnboundExpression return(Visit(node.ReduceExtensions())); }
public override Expression Variable(string name, SourceInfo sourceInfo) { Expression result; if (!_variableCache.TryGetValue(name, out result)) { object global = null; if (_globals?.TryGetValue(name, out global) ?? false) { result = new GlobalVariableExpression(name, global); _variableCache[name] = result; } else { result = base.Variable(name, sourceInfo); } _variableCache[name] = result; } return(result); }
protected abstract Expression RewriteGet(GlobalVariableExpression node);
protected override Expression RewriteGet(GlobalVariableExpression node) { return(AstUtils.Convert(MapToExpression(node), node.Type)); }
public override void Visit(GlobalVariableExpression node) { this.action(node); }
public override void ExplicitVisit(GlobalVariableExpression fragment) { _fragments.Add(fragment); }
private void EnsureUniqueName(GlobalVariableExpression node) { EnsureUniqueName(node.IsLocal ? _localNames : _globalNames, node); }
protected abstract Expression MakeWrapper(GlobalVariableExpression variable);
protected static void EnsureUniqueName(IDictionary <string, GlobalVariableExpression> varsByName, GlobalVariableExpression node) { GlobalVariableExpression n2; if (varsByName.TryGetValue(node.Name, out n2)) { if (node == n2) { return; } throw Error.GlobalsMustBeUnique(); } varsByName.Add(node.Name, node); }
protected virtual Expression VisitGlobalVariable(GlobalVariableExpression node) => base.VisitExtension(node);