public void processAssignment(IAssignment assignment, out bool cGenerated, out string str) { string varName = assignment.getVarName(); if (!types.ContainsKey(varName)) { throw new VariableDoesNotExistException(varName); } COOPType coopType = assignment.getCOOPObject().actualType, varType = types[varName]; cGenerated = false; str = ""; if (coopType.Equals(varType)) { cGenerated = true; str = $"{varName} = {assignment.getCOOPObjectString()}"; } else if (varType.isParent(coopType) && !varType.isStrictlyClass() && coopType.isStrictlyClass()) { types[varName] = coopType; cGenerated = true; str = $"{(coopType as COOPClass).toUsableToC()} {varName} = {assignment.getCOOPObjectString()}"; } }
public override void Visit(IAssignment assignment) { if (!CheckForExistingNull(assignment.Source)) { MarkMutationTarget(assignment); } }
private IExpression ReplaceOperation(IAssignment operation) { IExpression result = operation.Source; return(result); }
void SetCurrentAssignment(IAssignment assignment, ActionPriority priority) { if (m_currentAssignment == assignment && m_currentPriority == priority) { return; } if (m_currentAssignment != null) { m_currentAssignment.StatusChanged -= OnJobStatusChanged; } m_currentAssignment = assignment; m_currentPriority = priority; if (m_currentAssignment != null) { m_currentAssignment.StatusChanged += OnJobStatusChanged; } if (AssignmentChanged != null) { AssignmentChanged(assignment); } }
/// <summary> /// Resolves changes in assignment methods. /// </summary> /// <param name="old">The current assignment method.</param> /// <param name="newA">The assignment method that may be used in the future.</param> protected void HandleAssignmentChange(IAssignment old, IAssignment newA) { // Don't do anything when the assignments are equal. var areEqual = old.GetType().Equals(newA.GetType()); if (areEqual) { return; } // Assign the new assignment method. Assignment = newA; // If the new assignment is a name assignment, a new name object should be assigned. if (newA is NameAssignment) { Object = new NameObject(); return; } // If the assignment method switches from the name object, there should be a new object to write to. if (old is NameAssignment && !(newA is NameAssignment)) { var nameObject = Object as NameObject; var name = nameObject?.Name?.Trim() ?? ""; if (name.Length > 0) { CreateObject(name); } } }
private (IType left, IType right) BindAssignment(IAssignment syntax) { return(syntax switch { AssignmentStatementSyntax assignmentSyntax => (BindExpression(assignmentSyntax.Left), BindExpression(assignmentSyntax.Right)), InitializedVariableDeclarationSyntax variable => (BindType(variable.Type !), BindExpression(variable.Initializer)), _ => throw new Exception("unknown type of assignment") });
private IExpression ReplaceOperation(IAssignment operation) { IExpression result = operation.Source; return result; }
public virtual async Task <ManagerResult> AssignTaskAsync(TTeamTask teamTask, int assignorId, int?assigneeId, string description, IUserProvider userProvider) { if (!userProvider.UserExists(assignorId)) { return(new ManagerResult(TeamTasksMessages.AssignorNotFound)); } if (assigneeId.HasValue && !userProvider.UserExists(assigneeId.Value)) { return(new ManagerResult(TeamTasksMessages.AssigneeNotFound)); } if (assigneeId.HasValue) { IAssignment assignment = await GetTeamTaskStore().FindAssignmentAsync(teamTask.Id, assigneeId.Value); if (assignment != null) { return(new ManagerResult(TeamTasksMessages.TaskAlreadyAssignedToAssignee)); } } try { await GetTeamTaskStore().CreateAssignmentAsync(teamTask.Id, assignorId, assigneeId, description); } catch (Exception e) { return(e.CreateManagerResult()); } return(new ManagerResult()); }
public void Visit(IAssignment stmt, SSTPrintingContext c) { c.Indentation(); stmt.Reference.Accept(this, c); c.Text(" = "); stmt.Expression.Accept(this, c); c.Text(";"); }
public void Setup() { IExpression expression = CreationUtilities.CreateExpression(); variable1 = GlobalContext.Instance.AddVariable("MyVariable", KnownTypes.Int); assignment = expression.SetAsAssignment(variable1); variable2 = GlobalContext.Instance.AddVariable("MyVariable2", KnownTypes.Int); }
private HLLocation ProcessAssignmentExpression(IAssignment pExpression) { HLLocation locationSource = ProcessExpression(pExpression.Source); HLLocation locationTarget = ProcessTargetExpression(pExpression.Target); mCurrentBlock.EmitAssignment(locationTarget, locationSource); return(locationTarget); }
/// <summary> /// Checks the equality with other assigned value. /// </summary> /// <param name="other">Other assigned value.</param> /// <returns>True if the objects are equal, false otherwise.</returns> public bool Equals(IAssignment other) { if (other == this) { return(true); } return(Variable == other.GetVariable() && Value == other.GetValue()); }
public void processAssignment(IAssignment assignment) { processAssignment(assignment, out bool generated, out string str); if (generated) { createdCStatements.Enqueue(str); } }
public override IStatement Visit(IAssignment stmt, int context) { return(new Assignment { Reference = _ref.Anonymize(stmt.Reference), Expression = Anonymize(stmt.Expression) }); }
public override void Visit(IAssignment assignment) { if (Process(assignment)) { visitor.Visit(assignment); } base.Visit(assignment); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IAssignment assignmentsCasted = item.As <IAssignment>(); if ((assignmentsCasted != null)) { this._parent.Assignments.Add(assignmentsCasted); } }
public virtual void ArrangeSubEvent(IAssignment newTerm, SubEventInsertRule rule, int randomOffset) { var startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue + (randomOffset * rule.OccurScale)); var newSubEvent = Term.New(startTime, rule.SubEvent, rule.SubEventLength); if (newSubEvent.IsInTheRange(newTerm.Start, newTerm.End)) Create(newSubEvent, (t,success)=> { }, false); }
/// <summary> /// Выдать права на задание. /// </summary> /// <param name="task">Задача.</param> /// <param name="assignment">Задание.</param> public static void GrantRightToAssignment(ITask task, IAssignment assignment) { // Выдать права на задание контролеру, инициатору и группе регистрации инициатора ведущей задачи (включая ведущие ведущего). var leadPerformers = Functions.ActionItemExecutionTask.GetLeadActionItemExecutionPerformers(ActionItemExecutionTasks.As(task)); foreach (var performer in leadPerformers) { assignment.AccessRights.Grant(performer, DefaultAccessRightsTypes.Change); } }
public void Put(IAssignment ele) { for (var i = 0; i < ass.Count; i++) { if (ass[i].uniqueId == ele.uniqueId) { ass[i] = ele; } } }
private void changeAssignment(bool useAsValue, double value, IAssignment assignment) { if (assignment == null) { return; } assignment.ObjectPath.Replace(GallbladderEmptyingRate, GallbladderEmptyingActive); assignment.UseAsValue = useAsValue; assignment.Formula = _context.Create <ConstantFormula>().WithValue(value); }
/// <summary> /// Проверить возможность отправки задания подписания на доработку. /// </summary> /// <param name="assignment">Задание.</param> /// <param name="errorMessage">Сообщение об ошибке.</param> /// <param name="eventArgs">Аргумент обработчика вызова.</param> /// <returns>True - разрешить отправку, иначе false.</returns> public static bool ValidateBeforeRework(IAssignment assignment, string errorMessage, Sungero.Domain.Client.ExecuteActionArgs eventArgs) { if (string.IsNullOrEmpty(assignment.ActiveText)) { eventArgs.AddError(errorMessage); return(false); } return(true); }
public void SetAssignment(IAssignment assignment) { for (var i = 0; i < Connections.Count; i++) { if (Connections[i].GetConnector().Id != assignment.GetConnector().Id) { continue; } Connections[i] = assignment; } }
/// <summary> /// Создать поручение. /// </summary> /// <param name="parentAssignment">Задание, от которого создается поручение.</param> /// <param name="mainTask">Задача "Рассмотрение входящего", из которой создается поручение.</param> /// <param name="resolutionText">Текст резолюции.</param> /// <returns>Поручение.</returns> public static IActionItemExecutionTask CreateActionItemExecution(IAssignment parentAssignment, IDocumentReviewTask mainTask, string resolutionText) { var document = mainTask.DocumentForReviewGroup.OfficialDocuments.First(); // TODO вернуть вызов с использованием задания, когда починят 24898. // var task = Functions.Module.Remote.CreateActionItemExecution(document, parentAssignment); var task = Functions.Module.Remote.CreateActionItemExecution(document, (int)parentAssignment.Id); task.ActionItem = resolutionText; task.Assignee = document.Assignee; return(task); }
public bool SameAs(IAssignment assignment) { if (assignment is RumbleAssignment) { return(Callback == (assignment as RumbleAssignment).Callback); } else { return(false); } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IAssignment assignmentItem = item.As <IAssignment>(); if (((assignmentItem != null) && this._parent.Assignments.Remove(assignmentItem))) { return(true); } return(false); }
/// <summary> /// Checks whether the specified assignment is actually constrained by the conditions. /// </summary> /// <param name="assignment">Assignment.</param> /// <returns>True if the given assignment is constrained by the conditions, false otherwise.</returns> public bool IsConstrained(IAssignment assignment) { foreach (var conditions in this) { if (conditions.IsConstrained(assignment)) { return(true); } } return(false); }
public ManageAccountController(IStudent students, IMessage messages, ISchoolClass schoolClass, IMark marks, IAssignment assignments, IParentAccount parentAccounts, ITeacherAccount teacherAccounts, UserManager <UserAccount> userManager) { _schoolClasses = schoolClass; _messages = messages; _students = students; _userManager = userManager; _parentAccounts = parentAccounts; _teacherAccounts = teacherAccounts; _assignments = assignments; _marks = marks; }
public override IAssignment DeleteAssignment(IAssignment assignment) { using (var db = new GanttResourcesEntities()) { int id = int.Parse(assignment.ID.ToString()); db.GanttResourceAssignments.Remove(db.GanttResourceAssignments.First(r => r.ID == id)); db.SaveChanges(); } return(assignment); }
public virtual void ArrangeSubEvent(IAssignment newTerm, SubEventInsertRule rule, int randomOffset) { var startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue + (randomOffset * rule.OccurScale)); var newSubEvent = Term.New(startTime, rule.SubEvent, rule.SubEventLength); if (newSubEvent.IsInTheRange(newTerm.Start, newTerm.End)) { Create(newSubEvent, (t, success) => { }, false); } }
/// <summary> /// Добавить блок с заданием. /// </summary> /// <param name="parentBlock">Основной блок.</param> /// <param name="assignment">Задание.</param> /// <param name="header">Заголовок блока.</param> /// <param name="result">Результат выполнения задания.</param> private void AddAssignmentBlock(StateBlock parentBlock, IAssignment assignment, string header, string result) { if (assignment != null && (assignment.Status != Workflow.AssignmentBase.Status.Completed || !string.IsNullOrEmpty(result))) { var isDraft = _obj.Status == Workflow.Task.Status.Draft; var labelStyle = Docflow.PublicFunctions.Module.CreateStyle(false, isDraft, false); parentBlock.IsExpanded = true; var block = parentBlock.AddChildBlock(); block.Entity = assignment; block.AssignIcon(StateBlockIconType.OfEntity, StateBlockIconSize.Large); if (assignment.Status == Workflow.AssignmentBase.Status.InProcess && assignment.IsRead == false) { Docflow.PublicFunctions.Module.AddInfoToRightContent(block, Docflow.ApprovalTasks.Resources.StateViewUnRead); } else { this.AddAssignmentStatusInfoToRight(block, labelStyle, assignment); } var headerStyle = Docflow.PublicFunctions.Module.CreateHeaderStyle(isDraft); var performerStyle = Docflow.PublicFunctions.Module.CreatePerformerDeadlineStyle(isDraft); block.AddLabel(header, headerStyle); block.AddLineBreak(); var resolutionPerformerName = Employees.Is(assignment.Performer) ? Company.PublicFunctions.Employee.GetShortName(Employees.As(assignment.Performer), false) : assignment.Performer.Name; block.AddLabel(string.Format("{0}: {1} {2}: {3}", Docflow.OfficialDocuments.Resources.StateViewTo, resolutionPerformerName, Docflow.OfficialDocuments.Resources.StateViewDeadline, Docflow.PublicFunctions.Module.ToShortDateShortTime(assignment.Deadline.Value.ToUserTime())), performerStyle); if (!string.IsNullOrEmpty(result)) { var separatorStyle = Docflow.PublicFunctions.Module.CreateSeparatorStyle(); block.AddLineBreak(); block.AddLabel(Docflow.Constants.Module.SeparatorText, separatorStyle); block.AddLineBreak(); block.AddEmptyLine(Docflow.Constants.Module.EmptyLineMargin); block.AddLabel(result); } else { Docflow.PublicFunctions.OfficialDocument.AddDeadlineHeaderToRight(block, assignment.Deadline.Value, assignment.Performer); } } }
public void StoreNewAssignment(Assign assign) { try { IAssignment asgn = (IAssignment)GetService(typeof(IAssignment).Name); asgn.StoreAssignment(assign); } catch (InterfaceNotFoundException) { throw new Exception("Submission failed. Try again."); } }
/// <summary> /// Checks whether the conditions are in conflict with the specified assignment (i.e. different constraints on the same variable). /// </summary> /// <param name="assignment">Assignment.</param> /// <returns>True if the conditions are conflicted with the given assignment, false otherwise.</returns> public bool IsConflictedWith(IAssignment assignment) { // in the context of clause condition, at least one of the disjuncts needs to be non-conflicting foreach (var conditions in this) { if (!conditions.IsConflictedWith(assignment)) { return(false); } } return(true); }
public IAssignment this[int i] { get { IAssignment a = null; map.TryGetValue(i, out a); return(a); } set { map[i] = value; } }
public override void Visit(IAssignment assignment) { // _log.Info("Visiting IAssignment: " + assignment); // var defaultEqualsDefinition = TypeHelper.GetMethod(Host.PlatformType.SystemObject.ResolvedType.Members, // Host.NameTable.GetNameFor("Equals"), // Host.PlatformType.SystemObject); var targetType = assignment.Target.Type; IMethodDefinition currentMethod = this.Parent.CurrentMethod; var field = currentMethod.ContainingTypeDefinition.Fields .Where(f => f.IsStatic == currentMethod.IsStatic) .FirstOrDefault(f => isCompatibile(targetType, f.Type.ResolvedType) && FieldIsNotSource(f, assignment.Source)); if (field != null) { MarkMutationTarget(assignment); } //.. assignment.Source = new BoundExpression(); /* var methodDefinition = methodCall.MethodToCall.ResolvedMethod; var containingType = methodCall.ThisArgument.Type.ResolvedType; _log.Info("IMethodCall is of " + methodDefinition); //Check if the type overrides the Equals method if (methodDefinition.Equals(defaultEqualsDefinition) && containingType.IsClass && containingType.BaseClasses.Any()) { var overridingMethod = TypeHelper.GetMethod(containingType.Members, Host.NameTable.GetNameFor("Equals"), Host.PlatformType.SystemObject); if (overridingMethod.IsVirtual) { MarkMutationTarget(methodCall); } } */ }
public override IExpression Rewrite(IAssignment assignment) { return new Assignment(assignment) { Source = new Conversion() { Type = assignment.Source.Type, TypeAfterConversion = assignment.Source.Type, ValueToConvert = new CompileTimeConstant() { Type = Host.PlatformType.SystemObject, Value = null, } } }; }
public virtual void ArrangeSubEvent(IAssignment newTerm, IEnumerable<SubEventInsertRule> rules, Action<ITerm, bool> callback) { var anyError = false; foreach (var rule in rules) { DateTime startTime; // Whole SubEvent should be inside the range of StartValue~EndValue var amountOfAvailableOccurPoints = rule.GetAmountOfAvailableOccurPoints(); if (amountOfAvailableOccurPoints == 1) { // SubEvent can only occur at the begin of range startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue); } else { var randomOffset = TermExt.ArrangeSubEventRandom.Next(0, amountOfAvailableOccurPoints); startTime = newTerm.Start.AddMinutes(rule.TimeRange.StartValue + (randomOffset * rule.OccurScale)); } var newSubEvent = Term.New(startTime, rule.SubEvent, rule.SubEventLength); if (newSubEvent.IsInTheRange(newTerm.Start, newTerm.End)) { Create(newSubEvent, (t, success) => { if (!success) anyError = true; }, false); } else anyError = true; if (anyError) break; } if (callback != null) callback(newTerm, !anyError); }
public void Visit(IAssignment assignment) { Contract.Requires(assignment != null); throw new NotImplementedException(); }
public void Visit(IAssignment assignment) { throw new NotImplementedException(); }
public override void TraverseChildren(IAssignment assignment) { var needsParen = LowerPrecedenceThanParentExpression(assignment); var savedCurrentPrecedence = this.currentPrecedence; this.currentPrecedence = this.Precedence(assignment); if (needsParen) this.sourceEmitterOutput.Write("("); var binOp = assignment.Source as IBinaryOperation; if (binOp != null && assignment.Target.Instance == null) { var leftBinding = binOp.LeftOperand as IBoundExpression; if (leftBinding != null && leftBinding.Instance == null && leftBinding.Definition == assignment.Target.Definition) { if (binOp is IAddition) { if (ExpressionHelper.IsIntegralOne(binOp.RightOperand)) { //TODO: pointer incr can have size == target type size. if (binOp.ResultIsUnmodifiedLeftOperand) { this.Traverse(assignment.Target); this.sourceEmitterOutput.Write("++"); } else { this.sourceEmitterOutput.Write("++"); this.Traverse(assignment.Target); } } else { this.Traverse(assignment.Target); this.sourceEmitterOutput.Write(" += "); this.Traverse(binOp.RightOperand); } goto Ret; } if (binOp is ISubtraction) { if (ExpressionHelper.IsIntegralOne(binOp.RightOperand)) { //TODO: pointer incr can have size == target type size. if (binOp.ResultIsUnmodifiedLeftOperand) { this.Traverse(assignment.Target); this.sourceEmitterOutput.Write("--"); } else { this.sourceEmitterOutput.Write("--"); this.Traverse(assignment.Target); } } else { this.Traverse(assignment.Target); this.sourceEmitterOutput.Write(" -= "); this.Traverse(binOp.RightOperand); } goto Ret; } this.Traverse(assignment.Target); if (binOp is IBitwiseAnd) { this.sourceEmitterOutput.Write(" &= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IBitwiseOr) { this.sourceEmitterOutput.Write(" |= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IDivision) { this.sourceEmitterOutput.Write(" /= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IExclusiveOr) { this.sourceEmitterOutput.Write(" ^= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is ILeftShift) { this.sourceEmitterOutput.Write(" <<= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IModulus) { this.sourceEmitterOutput.Write(" %= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IMultiplication) { this.sourceEmitterOutput.Write(" *= "); this.Traverse(binOp.RightOperand); goto Ret; } if (binOp is IRightShift) { this.sourceEmitterOutput.Write(" >>= "); this.Traverse(binOp.RightOperand); goto Ret; } } } this.Traverse(assignment.Target); this.PrintToken(CSharpToken.Space); this.PrintToken(CSharpToken.Assign); this.PrintToken(CSharpToken.Space); this.Traverse(assignment.Source); Ret: if (needsParen) this.sourceEmitterOutput.Write(")"); this.currentPrecedence = savedCurrentPrecedence; }
/// <summary> /// Returns a deep copy of the given assignment expression. /// </summary> /// <param name="assignment"></param> public Assignment Copy(IAssignment assignment) { var mutableCopy = this.shallowCopier.Copy(assignment); this.CopyChildren((Expression)mutableCopy); mutableCopy.Target = this.Copy(mutableCopy.Target); mutableCopy.Source = this.Copy(mutableCopy.Source); return mutableCopy; }
public void Visit(IAssignment assignment) { this.result = this.copier.Copy(assignment); }
/// <summary> /// Returns a shallow copy of the given assignment expression. /// </summary> /// <param name="assignment"></param> public Assignment Copy(IAssignment assignment) { return new Assignment(assignment); }
/// <summary> /// /// </summary> /// <remarks>(mschaef) Works, but still a stub </remarks> /// <param name="assignment"></param> public override void TraverseChildren(IAssignment assignment) { Contract.Assert(TranslatedExpressions.Count == 0); var tok = assignment.Token(); bool translationIntercepted= false; ICompileTimeConstant constant= assignment.Source as ICompileTimeConstant; // TODO move away phone related code from the translation, it would be better to have 2 or more translation phases // NAVIGATION TODO maybe this will go away if I can handle it with stubs if (PhoneCodeHelper.instance().PhonePlugin != null && PhoneCodeHelper.instance().PhoneNavigationToggled) { IFieldReference target = assignment.Target.Definition as IFieldReference; if (target != null && target.Name.Value == PhoneCodeHelper.IL_CURRENT_NAVIGATION_URI_VARIABLE) { if (constant != null && constant.Type == sink.host.PlatformType.SystemString && constant.Value != null && constant.Value.Equals(PhoneCodeHelper.BOOGIE_DO_HAVOC_CURRENTURI)) { TranslateHavocCurrentURI(); translationIntercepted = true; } StmtTraverser.StmtBuilder.Add(PhoneCodeHelper.instance().getAddNavigationCheck(sink)); } } if (!translationIntercepted) TranslateAssignment(tok, assignment.Target.Definition, assignment.Target.Instance, assignment.Source); }
/// <summary> /// Returns a shallow copy of the given assignment expression. /// </summary> /// <param name="assignment"></param> public Assignment Copy(IAssignment assignment) { Contract.Requires(assignment != null); Contract.Ensures(Contract.Result<Assignment>() != null); return new Assignment(assignment); }
/// <summary> /// /// </summary> /// <remarks>(mschaef) Works, but still a stub </remarks> /// <param name="assignment"></param> public override void Visit(IAssignment assignment) { #region Transform Right Hand Side ... this.Visit(assignment.Source); Bpl.Expr sourceexp = this.TranslatedExpressions.Pop(); #endregion this.Visit(assignment.Target); Bpl.Expr targetexp = this.TranslatedExpressions.Pop(); Bpl.IdentifierExpr idexp = targetexp as Bpl.IdentifierExpr; if (idexp != null) { StmtTraverser.StmtBuilder.Add(Bpl.Cmd.SimpleAssign(assignment.Token(), idexp, sourceexp)); return; } else { throw new TranslationException("Trying to create a SimpleAssign with complex/illegal lefthand side"); } }
public override void TraverseChildren(IAssignment assignment) { MethodEnter(assignment); base.TraverseChildren(assignment); MethodExit(); }
/// <summary> /// Returns a deep copy of the given assignment expression. /// </summary> /// <param name="assignment"></param> public Assignment Copy(IAssignment assignment) { Contract.Requires(assignment != null); Contract.Ensures(Contract.Result<Assignment>() != null); var mutableCopy = this.shallowCopier.Copy(assignment); this.CopyChildren((Expression)mutableCopy); mutableCopy.Target = this.Copy(mutableCopy.Target); mutableCopy.Source = this.Copy(mutableCopy.Source); return mutableCopy; }
/// <summary> /// Performs some computation with the given assignment expression. /// </summary> /// <param name="assignment"></param> public virtual void Visit(IAssignment assignment) { }
/// <summary> /// Traverses the assignment expression. /// </summary> public void Traverse(IAssignment assignment) { Contract.Requires(assignment != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(assignment); if (this.StopTraversal) return; this.TraverseChildren(assignment); if (this.StopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(assignment); }
/// <summary> /// /// </summary> /// <param name="assignment"></param> public Assignment(IAssignment assignment) : base(assignment) { this.source = assignment.Source; this.target = assignment.Target; }
/// <summary> /// Traverses the children of the assignment expression. /// </summary> public virtual void TraverseChildren(IAssignment assignment) { Contract.Requires(assignment != null); this.TraverseChildren((IExpression)assignment); if (this.StopTraversal) return; this.Traverse(assignment.Target); if (this.StopTraversal) return; this.Traverse(assignment.Source); }
public override IExpression Rewrite(IAssignment assignment) { var binOp = assignment.Source as BinaryOperation; if (binOp != null) { var addressDeref = binOp.LeftOperand as IAddressDereference; if (addressDeref != null) { var dupValue = addressDeref.Address as IDupValue; if (dupValue != null && assignment.Target.Definition is IAddressDereference) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; return binOp; } } } else { var boundExpr = binOp.LeftOperand as IBoundExpression; if (boundExpr != null && boundExpr.Definition == assignment.Target.Definition && boundExpr.Instance is IDupValue) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; return binOp; } } } } else { var assign2 = assignment.Source as Assignment; if (assign2 != null) { var targetLocal = assign2.Target.Definition as ILocalDefinition; if (targetLocal != null) { binOp = assign2.Source as BinaryOperation; if (binOp != null) { var addressDeref = binOp.LeftOperand as IAddressDereference; if (addressDeref != null) { var dupValue = addressDeref.Address as IDupValue; if (dupValue != null && assignment.Target.Definition is IAddressDereference) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; if (this.numberOfReferencesToLocal[targetLocal] == 1 && this.numberOfAssignmentsToLocal[targetLocal] == 1) this.currentSingleUseSingleReferenceLocal = targetLocal; return assign2; } } } } } } else { var conversion = assignment.Source as IConversion; if (conversion != null) { binOp = conversion.ValueToConvert as BinaryOperation; if (binOp != null) { var addressDeref = binOp.LeftOperand as IAddressDereference; if (addressDeref != null) { var dupValue = addressDeref.Address as IDupValue; if (dupValue != null && assignment.Target.Definition is IAddressDereference) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; return binOp; } } } else { var boundExpr = binOp.LeftOperand as IBoundExpression; if (boundExpr != null && boundExpr.Definition == assignment.Target.Definition && boundExpr.Instance is IDupValue) { if (binOp is IAddition || binOp is IBitwiseAnd || binOp is IBitwiseOr || binOp is IDivision || binOp is IExclusiveOr || binOp is ILeftShift || binOp is IModulus || binOp is IMultiplication || binOp is IRightShift || binOp is ISubtraction) { binOp.LeftOperand = assignment.Target; binOp.RightOperand = TypeInferencer.Convert(binOp.RightOperand, assignment.Target.Type); return binOp; } } } } else { // For a character-typed field, c, the C# source expressions: // o.c += (char)0, o.c -= (char)0, and o.c *= (char)1 // produce the IL: "load o; dup; ldfld c; stfld c;". // (For some reason, the C# compiler does not do the same thing for "o.c /= (char)1".) // Such IL shows up here as "o.c = convert(ushort, dup.c)". // Arbitrarily turn it back into "o.c += (char)0". if (IsBoundExpressionWithDupInstance(conversion.ValueToConvert)) { var t = conversion.ValueToConvert.Type; if (t.TypeCode == PrimitiveTypeCode.Char) { return new Addition() { LeftOperand = assignment.Target, RightOperand = new Conversion() { TypeAfterConversion = t, ValueToConvert = new CompileTimeConstant() { Value = 0, Type = assignment.Type, }, }, ResultIsUnmodifiedLeftOperand = false, Type = assignment.Type, }; } } } } else { // There are several C# source expressions that produce the IL: "load o; dup; ldfld f; stfld f;". // Examples are: o.f += 0, o.f -= 0, o.f *= 1, o.f &= true, o.f |= false. // (For some reason, the C# compiler does not do the same thing for "o.f /= 1".) // Such IL shows up here as "o.f = dup.f". // Arbitrarily turn it back into "o.f += 0" for arithmetic types and "o.f |= false" for boolean. if (IsBoundExpressionWithDupInstance(assignment.Source)) { if (TypeHelper.IsPrimitiveInteger(assignment.Type) && assignment.Type.TypeCode != PrimitiveTypeCode.Char) { return new Addition() { LeftOperand = assignment.Target, RightOperand = new CompileTimeConstant() { Value = 0, Type = assignment.Type, }, ResultIsUnmodifiedLeftOperand = false, Type = assignment.Type, }; } else if (assignment.Type.TypeCode == PrimitiveTypeCode.Boolean) { return new BitwiseOr() { LeftOperand = assignment.Target, RightOperand = new CompileTimeConstant() { Value = false, Type = assignment.Type, }, ResultIsUnmodifiedLeftOperand = false, Type = assignment.Type, }; } } } } } return base.Rewrite(assignment); }
public void Visit(IAssignment assignment) { this.traverser.Traverse(assignment); }
public override IExpression Rewrite(IAssignment assignment) { // _log.Info("Rewriting IAssignment: " + assignment + " Pass: " + MutationTarget.PassInfo); var targetType = assignment.Target.Type; IMethodDefinition currentMethod = CurrentMethod; var field = currentMethod.ContainingTypeDefinition.Fields .Where(f => f.IsStatic == currentMethod.IsStatic) .First(f => isCompatibile(targetType, f.Type.ResolvedType)); var assignmentNew = new Assignment(assignment); assignmentNew.Source = new BoundExpression { Instance = new ThisReference(){Type = CurrentMethod.ContainingTypeDefinition}, Definition = field, Type = field.Type, }; return assignmentNew; }
/// <summary> /// Performs some computation with the given assignment expression. /// </summary> /// <param name="assignment"></param> public virtual void Visit(IAssignment assignment) { this.Visit((IExpression)assignment); }
/// <summary> /// Rewrites the given assignment expression. /// </summary> public override IExpression Rewrite(IAssignment assignment) { var targetInstance = assignment.Target.Instance; var result = base.Rewrite(assignment); if (targetInstance == null && assignment.Target.Instance != null) { //The target now pushes something onto the stack that was not there before the rewrite. //It the right hand side uses the stack, then it will not see the stack it expected. //If so, we need to evaluate the right handside and squirrel it away in a temp before executing //the actual assignment. var popFinder = new PopFinder(); popFinder.Traverse(assignment.Source); if (popFinder.foundAPop) { var temp = new LocalDefinition() { Name = this.host.NameTable.GetNameFor("PopTemp"+this.popTempCounter++), Type = assignment.Source.Type }; var localDeclarationStatement = new LocalDeclarationStatement() { LocalVariable = temp, InitialValue = assignment.Source }; var blockStatement = new BlockStatement(); blockStatement.Statements.Add(localDeclarationStatement); Contract.Assume(assignment is Assignment); ((Assignment)assignment).Source = new BoundExpression() { Definition = temp, Type = temp.Type }; return new BlockExpression() { BlockStatement = blockStatement, Expression = assignment, Type = assignment.Type }; } } return result; }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Traverses the given assignment expression. /// </summary> /// <param name="assignment"></param> public virtual void Visit(IAssignment assignment) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(assignment); this.Visit(assignment.Target); this.Visit(assignment.Source); //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count. this.path.Pop(); }
public virtual void onASTElement(IAssignment assignment) { }
/// <summary> /// Visits the specified assignment. /// </summary> /// <param name="assignment">The assignment.</param> public override void Visit(IAssignment assignment) { Assignment mutableAssignment = new Assignment(assignment); this.resultExpression = this.myCodeCopier.DeepCopy(mutableAssignment); }