ISemantic E(AssignExpression x, ISemantic lValue=null) { if (!eval) return E(x.LeftOperand); var l = TryGetValue(lValue ?? E(x.LeftOperand)); //TODO return null; }
public IExpression ParseExpression() { IExpression expr = this.ParseNoAssignExpression(); if (expr == null) { return(null); } if (!(expr is NameExpression) && !(expr is ClassVarExpression) && !(expr is InstanceVarExpression) && !(expr is DotExpression) && !(expr is IndexedExpression)) { return(expr); } var token = this.lexer.NextToken(); if (token == null) { return(expr); } if (token.Type != TokenType.Operator || token.Value != "=") { this.lexer.PushToken(token); return(expr); } IExpression assignexpr = null; if (expr is NameExpression) { assignexpr = new AssignExpression(((NameExpression)expr).Name, this.ParseExpression()); } else if (expr is DotExpression) { assignexpr = new AssignDotExpressions((DotExpression)expr, this.ParseExpression()); } else if (expr is InstanceVarExpression) { assignexpr = new AssignInstanceVarExpression(((InstanceVarExpression)expr).Name, this.ParseExpression()); } else if (expr is ClassVarExpression) { assignexpr = new AssignClassVarExpression(((ClassVarExpression)expr).Name, this.ParseExpression()); } else if (expr is IndexedExpression) { assignexpr = new AssignIndexedExpression(((IndexedExpression)expr).Expression, ((IndexedExpression)expr).IndexExpression, this.ParseExpression()); } return(assignexpr); }
ISemantic E(AssignExpression x, ISemantic lValue = null) { if (!eval) { return(E(x.LeftOperand)); } var l = TryGetValue(lValue ?? E(x.LeftOperand)); //TODO return(null); }
public void ExecuteTwoAssignCommands() { Context context = new Context(); AssignExpression expr1 = new AssignExpression("one", new ConstantExpression(1)); AssignExpression expr2 = new AssignExpression("two", new ConstantExpression(2)); CompositeExpression expr = new CompositeExpression(new IExpression[] { expr1, expr2 }); var result = expr.Evaluate(context); Assert.AreEqual(2, result); Assert.AreEqual(1, context.GetValue("one")); Assert.AreEqual(2, context.GetValue("two")); }
public void GetLocalVariables() { Context context = new Context(); AssignExpression expr1 = new AssignExpression("one", new ConstantExpression(1)); AssignExpression expr2 = new AssignExpression("two", new ConstantExpression(2)); CompositeExpression expr = new CompositeExpression(new IExpression[] { expr1, expr2 }); var result = expr.GetLocalVariables(); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains("one")); Assert.IsTrue(result.Contains("two")); }
public ISymbolValue Visit(AssignExpression x) { var lValue = this.lValue ?? (x.LeftOperand != null ? x.LeftOperand.Accept(this) : null); this.lValue = null; this.rValue = null; var l = TryGetValue(lValue); //TODO this.rValue = null; return null; }
/// <summary> /// Ако срещнем присвояване стойност на променлива, която няма записан стек в таблицата /// означава, че нейната декларация е заедно с присвояването. /// <example> /// Например: /// <code>int a = 5</code> /// </example> /// В такъв случай записваме променливата в таблицата за променливи декларация-на-първо-присвояване. /// </summary> /// <param name="node">Текущ връх</param> /// <returns>Обработен връх</returns> public override ICodeNode VisitAssignExpression(AssignExpression node) { VariableReferenceExpression varRefExp = node.Target as VariableReferenceExpression; if (varRefExp != null) { VariableDefinition varDef = varRefExp.Variable.Resolve(); if (firstAssignment[varDef].assignExpression == null) { firstAssignment[varDef] = new FirstAssignmentInfo(node, blockStack.Peek()); } } return(base.VisitAssignExpression(node)); }
public void AssignInteger() { Context context = new Context(); IExpression expr = new ConstantExpression(42); AssignExpression aexpr = new AssignExpression("a", expr); Assert.AreEqual("a", aexpr.Name); Assert.AreSame(expr, aexpr.Expression); var result = aexpr.Evaluate(context); Assert.IsNotNull(result); Assert.AreEqual(42, result); Assert.AreEqual(42, context.GetValue("a")); }
public void EvaluateAssignExpression() { Context context = new Context(); AssignExpression expr = new AssignExpression("one", new ConstantExpression(1)); Assert.AreEqual("one", expr.Name); Assert.IsNotNull(expr.Expression); var result = expr.Evaluate(context); Assert.IsNotNull(result); Assert.AreEqual(1, result); Assert.AreEqual(1, context.GetValue("one")); }
public ISymbolValue Visit(AssignExpression x) { var lValue = this.lValue ?? (x.LeftOperand != null ? x.LeftOperand.Accept(this) : null); this.lValue = null; this.rValue = null; var l = TryGetValue(lValue); //TODO this.rValue = null; return(null); }
public void Equals() { AssignExpression expr1 = new AssignExpression("a", new ConstantExpression(1)); AssignExpression expr2 = new AssignExpression("a", new ConstantExpression(2)); AssignExpression expr3 = new AssignExpression("b", new ConstantExpression(1)); AssignExpression expr4 = new AssignExpression("a", new ConstantExpression(1)); Assert.IsTrue(expr1.Equals(expr4)); Assert.IsTrue(expr4.Equals(expr1)); Assert.AreEqual(expr1.GetHashCode(), expr4.GetHashCode()); Assert.IsFalse(expr1.Equals(null)); Assert.IsFalse(expr1.Equals(expr2)); Assert.IsFalse(expr1.Equals(expr3)); Assert.IsFalse(expr1.Equals(123)); }
public override ICodeNode VisitAssignExpression(AssignExpression node) { ICodeNode result = base.VisitAssignExpression(node); int value; if (expressionNumbers.TryGetValue(node, out value)) { // } else { expressionNumbers.Add(node, expressionCnt++); } return(result); }
public void ExecuteCompositeCommand() { IExpression expr1 = new AssignExpression("a", new ConstantExpression(1)); ExpressionCommand cmd1 = new ExpressionCommand(expr1); IExpression expr2 = new AssignExpression("b", new ConstantExpression(2)); ExpressionCommand cmd2 = new ExpressionCommand(expr2); IList <ICommand> cmds = new ICommand[] { cmd1, cmd2 }; CompositeCommand cmd = new CompositeCommand(cmds); Context context = new Context(); cmd.Execute(context); Assert.AreEqual(1, context.GetValue("a")); Assert.AreEqual(2, context.GetValue("b")); }
public void ExecuteCompositeCommandWithReturn() { IExpression expr1 = new AssignExpression("a", new ConstantExpression(1)); ExpressionCommand cmd1 = new ExpressionCommand(expr1); ICommand cmd2 = new ReturnCommand(new ConstantExpression(3)); IExpression expr3 = new AssignExpression("b", new ConstantExpression(2)); ExpressionCommand cmd3 = new ExpressionCommand(expr3); IList <ICommand> cmds = new ICommand[] { cmd1, cmd2, cmd3 }; CompositeCommand cmd = new CompositeCommand(cmds); Context context = new Context(); cmd.Execute(context); Assert.AreEqual(1, context.GetValue("a")); Assert.IsTrue(context.HasReturn); Assert.AreEqual(3, context.ReturnValue); Assert.IsNull(context.GetValue("b")); }
public void Equals() { AssignExpression aexpr1 = new AssignExpression("one", new ConstantExpression(1)); AssignExpression aexpr2 = new AssignExpression("two", new ConstantExpression(2)); CompositeExpression expr1 = new CompositeExpression(new IExpression[] { aexpr1, aexpr2 }); CompositeExpression expr2 = new CompositeExpression(new IExpression[] { aexpr2, aexpr1 }); CompositeExpression expr3 = new CompositeExpression(new IExpression[] { aexpr1 }); CompositeExpression expr4 = new CompositeExpression(new IExpression[] { aexpr1, aexpr2 }); Assert.IsTrue(expr1.Equals(expr4)); Assert.IsTrue(expr4.Equals(expr1)); Assert.AreEqual(expr1.GetHashCode(), expr4.GetHashCode()); Assert.IsFalse(expr1.Equals(null)); Assert.IsFalse(expr1.Equals(123)); Assert.IsFalse(expr1.Equals(expr2)); Assert.IsFalse(expr2.Equals(expr1)); Assert.IsFalse(expr1.Equals(expr3)); Assert.IsFalse(expr3.Equals(expr1)); }
ExpressionType TranslateExpression(AssignExpression e) { ExpressionType lvalue = TranslateVariable(e.Var); ExpressionType exp = TranslateExpression(e.Exp); if (e.Var is SimpleVariable && Env.ValueEnvironment[(e.Var as SimpleVariable).Name] is LoopVariableEntry) { Error.Report(e.Var.Pos, "Loop variable cannot be assigned"); return(new ExpressionType(null, Types.Type._void)); } if (exp.Type.CoerceTo(Types.Type._void)) { Error.Report(e.Exp.Pos, "Cannot assign a 'void'"); return(new ExpressionType(null, Types.Type._void)); } if (!exp.Type.CoerceTo(lvalue.Type)) { Error.Report(e.Pos, "Cannot assign a '" + exp.Type.ToString() + "' to '" + lvalue.Type.ToString() + "'"); return(new ExpressionType(null, Types.Type._void)); } return(new ExpressionType(Translate.TranslateAssignExp(lvalue.Exp, exp.Exp), Types.Type._void)); }
public override void VisitAssignExpression(AssignExpression node) { //Visit (node.Target); switch (node.Target.CodeNodeType) { case CodeNodeType.VariableReferenceExpression: Visit(node.Expression); cil.EmitInstruction(OpCodes.Stloc, ((VariableReferenceExpression)node.Target).Variable.Index); break; case CodeNodeType.ArgumentReferenceExpression: Visit(node.Expression); cil.EmitInstruction(OpCodes.Starg, ((ArgumentReferenceExpression)node.Target).Parameter.Index + 1); break; case CodeNodeType.FieldReferenceExpression: Visit(node.Expression); FieldReferenceExpression fldRefExp = (FieldReferenceExpression)node.Target; //TODO: fldRefExp.Target! FieldDefinition fld = fldRefExp.Field.Resolve(); if ((fld.Attributes & FieldAttributes.Static) != 0) { cil.EmitInstruction(OpCodes.Stsfld, fld); } else { cil.EmitInstruction(OpCodes.Stfld, fld); } break; } }
public void Execute(Context context) { object from = this.fromexpr.Evaluate(context); object to = this.toexpr.Evaluate(context); context.SetValue(this.name, from); AssignExpression increxpr; if (this.stepexpr == null) { increxpr = new AssignExpression(this.name, new BinaryOperatorExpression(BinaryOperator.Add, new NameExpression(this.name), new ConstantExpression(1))); } else { increxpr = new AssignExpression(this.name, new BinaryOperatorExpression(BinaryOperator.Add, new NameExpression(this.name), this.stepexpr)); } while (((IComparable)context.GetValue(this.name)).CompareTo(to) != 1) { this.body.Execute(context); increxpr.Evaluate(context); } }
public override ICodeNode VisitAssignExpression(AssignExpression node) { var result = Pattern.CodePattern.Match(SelfAssignmentPattern, node); if (!result.Success) { return(base.VisitAssignExpression(node)); } var target = (Expression)result [TargetKey]; var @operator = (BinaryOperator)result [OperatorKey]; switch (@operator) { case BinaryOperator.Add: case BinaryOperator.Subtract: return(new UnaryExpression( GetCorrespondingOperator(@operator), target)); default: return(base.VisitAssignExpression(node)); } }
public static Result Run(AssignExpression assign, Scope scope) { Result right_result = Interpreters.Execute(assign.Right, scope); if (right_result.FastReturn) { return(right_result); } switch (assign.Left) { case ArrayAccessExpression array_access_expression: ArrayInterpreter.Resolve(array_access_expression, scope, (arr, key) => { arr.Set(new ArrayItem(key, right_result.ResultValue)); }); break; case VariableExpression variable_expression: IVariable variable = scope.Variables.EnsureExists(variable_expression.Name); variable.Value = right_result.ResultValue; break; case StaticFieldAccessExpression static_field_access_expression: ClassInterpreter.Resolve(static_field_access_expression, scope, (var) => { var.Value = right_result.ResultValue; }); break; default: Log.Error($"Cannot execute assign expression: Left Value is of unknown type {assign.Left}"); break; } return(right_result); }
public AbstractType Visit(AssignExpression x) { return(OpExpressionType(x)); }
public AssignActionBlock (Instruction sourceInstruction, AssignExpression assign) : base (sourceInstruction) { _assignExpression = assign; }
/// <summary> /// Creates a new instance of the <typeparamref name="TModel"/> into the database /// </summary> /// <param name="entity">The data to be created</param> /// <param name="dbConnection">Reference to an existing database connection</param> /// <param name="dbTransaction">Reference to an existing database transaction</param> /// <returns>An instance of the recently created object</returns> /// <exception cref="PrimaryKeyViolationException">Thrown if the record already exists</exception> public virtual TModel Create(TCreateDTO entity, IDbConnection dbConnection, IDbTransaction dbTransaction) { // Ensure Model is Valid if (!IsModelValid) { throw new Exception("Model is invalid"); } // Initializes a transaction, if applicable IDbConnection connection = dbConnection; IDbTransaction transaction = dbTransaction; try { // Creates a connection if no connection has been passed if (connection == null) { connection = DbContext.GetConnection(); } // Initializes a transaction if no transaction has been passed if (transaction == null) { transaction = connection.BeginTransaction(); } // Map Dto to Model var model = entity.MapToModel(); // Calls the "OnBeforeCreate" method if (!OnBeforeCreate(model, entity, connection, transaction)) { throw new Exception("Create operation cancelled"); } // Verify Primary Key Violation var models = Get(GetPrimaryKeyFilters(model), connection, transaction); if (models.Count > 0) { throw new PrimaryKeyViolationException($"Duplicated Key for '{typeof(TModel).Name}'"); } // Calls Model Format function FormatModel(model); // Define AssignExpressions var assignExpressions = new List <AssignExpression>(); foreach (var fieldInfo in Fields) { // Define the Assign Expression Object AssignExpression assignExpression; // For String type, shrink character count (when size is specified) if ((fieldInfo.Attribute.Type == typeof(string)) && (fieldInfo.Attribute.Size > 0)) { // Shrink Field Contents, if applicable var fieldContents = fieldInfo.Property.GetValue(model)?.ToString().PadRight(fieldInfo.Attribute.Size, ' ').Substring(0, fieldInfo.Attribute.Size).Trim(); // Apply New Contents to the Model //if (fieldContents == null) fieldContents = ""; fieldInfo.Property.SetValue(model, fieldContents); // Apply to the AssignExpression assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), fieldContents); } else { // Check for Enum types if (fieldInfo.Property.PropertyType.IsEnum) { // Enumerations have a special treatment as its value need to be parsed from the string that represents it var enumValue = fieldInfo.Property.GetValue(model); object finalValue = null; // If value is null, force it to zero if (enumValue == null) { finalValue = 0; } else { finalValue = Convert.ChangeType(enumValue, fieldInfo.Property.PropertyType.GetEnumUnderlyingType()); } assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), finalValue); } else { assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), fieldInfo.Property.GetValue(model)); } } assignExpressions.Add(assignExpression); } // Create the Insert Operation with the previously setup Assign Expressions var insert = new InsertDbOperation(DatabaseTableAttribute.Name) { Assignments = assignExpressions.ToArray() }; // Runs the Insert Statement DbContext.ExecuteNonQuery(insert, connection, transaction); // Calls the "OnAfterCreate" method OnAfterCreate(model, entity, connection, transaction); if (dbTransaction == null) { transaction.Commit(); } // Returns the Entity Created return(model); } catch { // Check if this action is joining a transaction if (dbTransaction == null) { transaction.Rollback(); } throw; } finally { // Closes the connection created on this method if (dbConnection == null) { if (connection?.State == ConnectionState.Open) { connection.Close(); } } } }
public virtual void PostWalk(AssignExpression node) { }
public override void PostWalk(AssignExpression node) { }
public AssignActionBlock(Instruction sourceInstruction, AssignExpression assign) : base(sourceInstruction) { _assignExpression = assign; }
public override void Visit(AssignExpression node) { CannotOptimize(node); }
public override ICodeNode VisitAssignExpression(AssignExpression node) { return(base.VisitAssignExpression(node)); // if (node.Target is VariableReferenceExpression ||) }
public IExpression AssignExpression(IBlockNode Scope = null) { var left = ConditionalExpression(Scope); if (Lexer.IsEOF) { if (!TrackerVariables.IsParsingAssignExpression) { LastParsedObject = left; TrackerVariables.IsParsingAssignExpression = true; } return left; } if (!AssignOps[laKind]) return left; Step(); var ate = new AssignExpression(t.Kind); LastParsedObject = ate; ate.LeftOperand = left; ate.RightOperand = AssignExpression(Scope); return ate; }
public FirstAssignmentInfo(AssignExpression assignExpression, BlockStatement inBlock) { this.assignExpression = assignExpression; this.inBlock = inBlock; }
void PrintExpression(AssignExpression e, int d) { SayLn("AssignExpression("); PrintVariable(e.Var, d + 1); SayLn(","); PrintExpression(e.Exp, d + 1); Say(")"); }
public IExpression AssignExpression(IBlockNode Scope = null) { var left = ConditionalExpression(Scope); if (!AssignOps[laKind]) return left; Step(); var ate = new AssignExpression(t.Kind); LastParsedObject = ate; ate.LeftOperand = left; ate.RightOperand = AssignExpression(Scope); return ate; }
public string VisitAssignExpression(AssignExpression assignExpression) => $"{assignExpression.Left.AcceptVisitor(this)} " + $"{assignExpression.PreAssignOperator?.ToSymbol() ?? ""}= " + $"{assignExpression.Right.AcceptVisitor(this)}";
public IExpression AssignExpression(IBlockNode Scope = null) { var left = ConditionalExpression(Scope); if (!IsAssignOperator(laKind)) return left; Step(); var ate = new AssignExpression(t.Kind); ate.LeftOperand = left; ate.RightOperand = AssignExpression(Scope); return ate; }
// AssignStmt public override bool Walk(AssignExpression node) { node.Right.Walk(this); node.Left.Walk(_fdef); return false; }
public override void Visit (AssignExpression node) { Visit (node.Target); Write (" = "); Visit (node.Expression); }
public void Visit(AssignExpression x) { }
public virtual void Visit (AssignExpression node) { Visit (node.Target); Visit (node.Expression); }
// AssignExpression public virtual bool Walk(AssignExpression node) { return true; }
public void Visit(AssignExpression x) { }
// AssignExpression public override bool Walk(AssignExpression node) { return false; }
private static Expression GetQueryExpression(ActionFlowGraph afg) { IDictionary <int, Expression> variables = new Dictionary <int, Expression>(); ActionBlock block = afg.Blocks[0]; while (block != null) { switch (block.ActionType) { case ActionType.Invoke: InvokeActionBlock invokeBlock = (InvokeActionBlock)block; MethodInvocationExpression invocation = invokeBlock.Expression; if (IsActivateInvocation(invocation) || IsNoSideEffectIndirectActivationInvocation(invocation)) { block = invokeBlock.Next; break; } UnsupportedExpression(invocation); break; case ActionType.ConditionalBranch: UnsupportedPredicate("Conditional blocks are not supported."); break; case ActionType.Branch: block = ((BranchActionBlock)block).Target; break; case ActionType.Assign: { AssignActionBlock assignBlock = (AssignActionBlock)block; AssignExpression assign = assignBlock.AssignExpression; VariableReferenceExpression variable = assign.Target as VariableReferenceExpression; if (null == variable) { UnsupportedExpression(assign); } else { if (variables.ContainsKey(variable.Variable.Index)) { UnsupportedExpression(assign.Expression); } variables.Add(variable.Variable.Index, assign.Expression); block = assignBlock.Next; } break; } case ActionType.Return: { Expression expression = ((ReturnActionBlock)block).Expression; VariableReferenceExpression variable = expression as VariableReferenceExpression; return(null == variable ? expression : variables[variable.Variable.Index]); } } } return(null); }
void PrintExpression(AssignExpression e, int d) { SayLn("AssignExpression("); PrintVariable(e.Var, d + 1); SayLn(","); PrintExpression(e.Exp, d + 1); Say(")"); }
public override void Visit(AssignExpression node) { UnsupportedExpression(node); }
/// <summary> /// Updates the Record to the Database /// </summary> /// <remarks>This action updates the entire records and all fields on it, not partial updates</remarks> /// <param name="entity">The entity to be updated</param> /// <param name="dbConnection">Reference to an existing database connection</param> /// <param name="dbTransaction">Reference to an existing database transaction</param> public virtual void Update(TUpdateDTO entity, IDbConnection dbConnection, IDbTransaction dbTransaction) { // Ensure Model is Valid if (!IsModelValid) { throw new Exception("Model is invalid"); } // Map Dto to Model var model = entity.MapToModel(); // Initializes a transaction, if applicable IDbConnection connection = dbConnection; IDbTransaction transaction = dbTransaction; try { // Creates a connection if no connection has been passed if (connection == null) { connection = DbContext.GetConnection(); } // Initializes a transaction if no transaction has been passed if (transaction == null) { transaction = connection.BeginTransaction(); } // Verify if the record exists var primarykeys = GetPrimaryKeyFilters(model); var models = Get(primarykeys, connection, transaction); if (models.Count == 0) { throw new RecordNotFoundException($"Unable to find '{model.GetType().Name}' to update based on the given primary keys", primarykeys); } // Calls Model Format function FormatModel(model); // Calls the "OnBeforeUpdate" method if (!OnBeforeUpdate(models[0], model, entity, connection, transaction)) { throw new Exception("Update operation cancelled"); } // Define AssignExpressions var assignExpressions = new List <AssignExpression>(); foreach (var fieldInfo in Fields) { // Define the Assign Expression Object AssignExpression assignExpression; // For String type, shrink character count (when size is specified) if ((fieldInfo.Attribute.Type == typeof(string)) && (fieldInfo.Attribute.Size > 0)) { if (fieldInfo.Property.GetValue(model) != null) { // Shrink Field Contents, if applicable var fieldContents = fieldInfo.Property.GetValue(model)?.ToString().PadRight(fieldInfo.Attribute.Size, ' ').Substring(0, fieldInfo.Attribute.Size).Trim(); // Apply New Contents to the Model //if (fieldContents == null) fieldContents = ""; //TODO: fix it on the framework fieldInfo.Property.SetValue(model, fieldContents); // Apply to the AssignExpression assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), fieldContents); } else { // Apply New Contents to the Model fieldInfo.Property.SetValue(model, null); // Apply to the AssignExpression assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), ""); } } else { // Check for Enum types if (fieldInfo.Property.PropertyType.IsEnum) { // Enumerations have a special treatment as its value need to be parsed from the string that represents it var enumValue = fieldInfo.Property.GetValue(model); object finalValue = null; // If value is null, force it to zero if (enumValue == null) { finalValue = 0; } else { finalValue = Convert.ChangeType(enumValue, fieldInfo.Property.PropertyType.GetEnumUnderlyingType()); } assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), finalValue); } else { assignExpression = new AssignExpression(new Field(fieldInfo.Attribute.Name), fieldInfo.Property.GetValue(model)); } } assignExpressions.Add(assignExpression); } var update = new UpdateDbOperation(DatabaseTableAttribute.Name) { Assignments = assignExpressions.ToArray() }; update.Where.AppendQueryFilters(GetPrimaryKeyFilters(model), false); DbContext.ExecuteNonQuery(update, connection, transaction); // Calls the OnAfterUpdate method OnAfterUpdate(model, entity, connection, transaction); // Commits the transaction if (dbTransaction == null) { transaction.Commit(); } } catch { // Check if this action is joining a transaction if (dbTransaction == null) { transaction.Rollback(); } throw; } finally { // Closes the connection created on this method if (dbConnection == null) { if (connection?.State == ConnectionState.Open) { connection.Close(); } } } }
public override void Visit(AssignExpression node) { CannotOptimize(node); }