private HLLocation ProcessBoundExpression(IBoundExpression pExpression) { if (pExpression.Definition is ILocalDefinition) { ILocalDefinition definition = pExpression.Definition as ILocalDefinition; HLLocation location = HLLocalLocation.Create(HLDomain.GetLocal(definition)); if (pExpression.Type.ResolvedType.TypeCode == PrimitiveTypeCode.Reference) { location = location.AddressOf(); } return(location); } else if (pExpression.Definition is IParameterDefinition) { return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition))); } else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference) { IFieldDefinition definition = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField; HLType typeFieldContainer = HLDomain.GetOrCreateType(definition.Container); HLField field = HLDomain.GetField(definition); if (field.IsStatic) { return(HLStaticFieldLocation.Create(field)); } HLLocation instance = ProcessExpression(pExpression.Instance); return(HLFieldLocation.Create(instance, field)); } throw new NotSupportedException(); }
private IBoundExpression ResolveLExpressionIsProceduralModule() { /* * <l-expression> is classified as a procedural module, this procedural module has an accessible * member named <unrestricted-name>, <unrestricted-name> either does not specify a type * character or specifies a type character whose associated type matches the declared type of the * member, and one of the following is true: * - The member is a variable, property or function. In this case, the member access expression is * classified as a variable, property or function, respectively, and has the same declared type as * the member. * - The member is a subroutine. In this case, the member access expression is classified as a * subroutine. * - The member is a value. In this case, the member access expression is classified as a value with * the same declared type as the member. */ bool isDefaultInstanceVariableClass = _lExpression.Classification == ExpressionClassification.Type && _lExpression.ReferencedDeclaration.DeclarationType == DeclarationType.ClassModule && ((ClassModuleDeclaration)_lExpression.ReferencedDeclaration).HasDefaultInstanceVariable; if (_lExpression.Classification != ExpressionClassification.ProceduralModule && !isDefaultInstanceVariableClass) { return(null); } IBoundExpression boundExpression = null; boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.Variable, ExpressionClassification.Variable); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, _propertySearchType, ExpressionClassification.Property); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.Function, ExpressionClassification.Function); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.Procedure, ExpressionClassification.Subroutine); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.Constant, ExpressionClassification.Value); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.Enumeration, ExpressionClassification.Value); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(_lExpression.ReferencedDeclaration, DeclarationType.EnumerationMember, ExpressionClassification.Value); if (boundExpression != null) { return(boundExpression); } return(boundExpression); }
private IBoundExpression ResolvePreferUdt(string name) { IBoundExpression boundExpression = null; boundExpression = ResolveEnclosingModule(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveOtherModuleInEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveReferencedProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveModuleInReferencedProject(name); if (boundExpression != null) { return(boundExpression); } return(new ResolutionFailedExpression(_expression)); }
private IBoundExpression ResolveLExpressionIsIndexExpression(IBoundExpression lExpression) { /* * <l-expression> is classified as an index expression and the argument list is not empty. * Thus, me must be dealing with a default member access or an array access. */ if (lExpression is IndexExpression && _argumentList.HasArguments && lExpression.ReferencedDeclaration != null) { IBoundExpression boundExpression = null; var asTypeName = lExpression.ReferencedDeclaration.AsTypeName; var asTypeDeclaration = lExpression.ReferencedDeclaration.AsTypeDeclaration; boundExpression = ResolveDefaultMember(lExpression, asTypeName, asTypeDeclaration); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveLExpressionDeclaredTypeIsArray(lExpression, asTypeDeclaration); if (boundExpression != null) { return(boundExpression); } return(boundExpression); } return(null); }
private IBoundExpression ResolvePreferProject(string name) { IBoundExpression boundExpression = null; // EnclosingProject and EnclosingModule have been switched. boundExpression = ResolveEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveEnclosingModule(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveOtherModuleInEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveReferencedProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveModuleInReferencedProject(name); return(boundExpression); }
public IBoundExpression Resolve() { IBoundExpression boundExpression = null; string name = ExpressionName.GetName(_expression.name()); boundExpression = ResolveEnclosingModule(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveOtherModuleInEnclosingProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveReferencedProject(name); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveModuleInReferencedProject(name); return(boundExpression); }
private IBoundExpression CreateFailedExpression(IBoundExpression expression, ParserRuleContext context) { var failedExpr = new ResolutionFailedExpression(context); failedExpr.AddSuccessfullyResolvedExpression(expression); return(failedExpr); }
private IBoundExpression ResolveLExpressionDeclaredTypeIsArray(IBoundExpression lExpression, Declaration asTypeDeclaration) { /* * The declared type of <l-expression> is an array type, an empty argument list has not already * been specified for it, and one of the following is true: */ if (lExpression.ReferencedDeclaration.IsArray) { /* * <argument-list> represents an empty argument list. In this case, the index expression * takes on the classification and declared type of <l-expression> and references the same * array. */ if (!_argumentList.HasArguments) { return(new IndexExpression(asTypeDeclaration, lExpression.Classification, _expression, lExpression, _argumentList)); } else { /* * <argument-list> represents an argument list with a number of positional arguments equal * to the rank of the array, and with no named arguments. In this case, the index expression * references an individual element of the array, is classified as a variable and has the * declared type of the array’s element type. * * TODO: Implement compatibility checking / amend the grammar */ if (!_argumentList.HasNamedArguments) { return(new IndexExpression(asTypeDeclaration, ExpressionClassification.Variable, _expression, lExpression, _argumentList)); } } } return(null); }
private IBoundExpression Resolve(IBoundExpression lExpression) { IBoundExpression boundExpression = null; if (lExpression.Classification == ExpressionClassification.ResolutionFailed) { return(CreateFailedExpression(lExpression)); } boundExpression = ResolveLExpressionIsVariablePropertyFunctionNoParameters(lExpression); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveLExpressionIsPropertyFunctionSubroutine(lExpression); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveLExpressionIsUnbound(lExpression); if (boundExpression != null) { return(boundExpression); } return(CreateFailedExpression(lExpression)); }
public IBoundExpression Resolve() { IBoundExpression boundExpression = null; var lExpression = _lExpressionBinding.Resolve(); if (lExpression.Classification == ExpressionClassification.ResolutionFailed) { return(lExpression); } string unrestrictedName = Identifier.GetName(_expression.unrestrictedIdentifier()); boundExpression = ResolveLExpressionIsProject(lExpression, unrestrictedName); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveLExpressionIsModule(lExpression, unrestrictedName); if (boundExpression != null) { return(boundExpression); } var failedExpr = new ResolutionFailedExpression(); failedExpr.AddSuccessfullyResolvedExpression(lExpression); return(failedExpr); }
private IBoundExpression ResolveLExpressionIsVariablePropertyFunctionNoParameters(IBoundExpression lExpression) { /* * <l-expression> is classified as a variable, or <l-expression> is classified as a property or function * with a parameter list that cannot accept any parameters and an <argument-list> that is not * empty, and one of the following is true (see below): */ bool isVariable = lExpression.Classification == ExpressionClassification.Variable; bool propertyWithParameters = lExpression.Classification == ExpressionClassification.Property && !((IDeclarationWithParameter)lExpression.ReferencedDeclaration).Parameters.Any(); bool functionWithParameters = lExpression.Classification == ExpressionClassification.Function && !((IDeclarationWithParameter)lExpression.ReferencedDeclaration).Parameters.Any(); if (isVariable || ((propertyWithParameters || functionWithParameters) && _argumentList.HasArguments)) { IBoundExpression boundExpression = null; var asTypeName = lExpression.ReferencedDeclaration.AsTypeName; var asTypeDeclaration = lExpression.ReferencedDeclaration.AsTypeDeclaration; boundExpression = ResolveDefaultMember(lExpression, asTypeName, asTypeDeclaration); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveLExpressionDeclaredTypeIsArray(lExpression, asTypeDeclaration); if (boundExpression != null) { return(boundExpression); } return(boundExpression); } return(null); }
public IBoundExpression Resolve() { IBoundExpression boundExpression = null; var lExpression = _lExpressionBinding.Resolve(); if (lExpression == null) { return(null); } string name = GetUnrestrictedName(); if (lExpression.Classification != ExpressionClassification.ProceduralModule) { return(null); } boundExpression = ResolveMemberInModule(lExpression, name, lExpression.ReferencedDeclaration, DeclarationType.Function, ExpressionClassification.Function); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(lExpression, name, lExpression.ReferencedDeclaration, DeclarationType.Procedure, ExpressionClassification.Subroutine); if (boundExpression != null) { return(boundExpression); } return(boundExpression); }
private IBoundExpression ResolveMemberInModule(IBoundExpression lExpression, string name, Declaration module, DeclarationType memberType) { /* * <l-expression> is classified as a procedural module or a type referencing a class defined in a * class module, and one of the following is true: * * This module has an accessible UDT or Enum definition named <unrestricted-name>. In this * case, the member access expression is classified as a type and refers to the specified UDT or * Enum type. */ var enclosingProjectType = _declarationFinder.FindMemberEnclosedProjectInModule(_project, _module, _parent, module, name, memberType); if (enclosingProjectType != null) { return(new MemberAccessExpression(enclosingProjectType, ExpressionClassification.Type, _expression, _unrestrictedNameContext, lExpression)); } var referencedProjectType = _declarationFinder.FindMemberReferencedProjectInModule(_project, _module, _parent, module, name, memberType); if (referencedProjectType != null) { return(new MemberAccessExpression(referencedProjectType, ExpressionClassification.Type, _expression, _unrestrictedNameContext, lExpression)); } return(null); }
private IBoundExpression CreateFailedExpression(IBoundExpression expression) { var failedExpr = new ResolutionFailedExpression(); failedExpr.AddSuccessfullyResolvedExpression(expression); return(failedExpr); }
public IBoundExpression Resolve() { IBoundExpression boundExpression = null; var lExpression = _lExpressionBinding.Resolve(); if (lExpression.Classification == ExpressionClassification.ResolutionFailed) { return(lExpression); } string name = Identifier.GetName(_expression.unrestrictedIdentifier()); if (lExpression.Classification != ExpressionClassification.ProceduralModule) { return(null); } boundExpression = ResolveMemberInModule(lExpression, name, lExpression.ReferencedDeclaration, DeclarationType.Function, ExpressionClassification.Function); if (boundExpression != null) { return(boundExpression); } boundExpression = ResolveMemberInModule(lExpression, name, lExpression.ReferencedDeclaration, DeclarationType.Procedure, ExpressionClassification.Subroutine); if (boundExpression != null) { return(boundExpression); } var failedExpr = new ResolutionFailedExpression(_expression); failedExpr.AddSuccessfullyResolvedExpression(lExpression); return(failedExpr); }
public override IExpression Rewrite(IBoundExpression boundExpression) { var result = base.Rewrite(boundExpression); var field = boundExpression.Definition as IFieldReference; if (field == null) { var capturedLocal = boundExpression.Definition as CapturedLocalDefinition; if (capturedLocal != null) { field = capturedLocal.capturingField; } } if (field != null) { var locOrPar = this.closureFieldToLocalOrParameterMap.Find(field.InternedKey); if (locOrPar != null) { var be = locOrPar as BoundExpression; if (be != null && be.Definition is LocalDefinition) { this.numberOfReferencesToLocal[be.Definition]++; } return(locOrPar); } } return(result); }
private void Visit(OutputListExpression expression, Declaration parent, IBoundExpression withExpression) { foreach (var itemExpression in expression.ItemExpressions) { Visit(itemExpression, parent, withExpression); } }
private static IBoundExpression ResolveViaDefaultMember(IBoundExpression wrappedExpression, string asTypeName, Declaration asTypeDeclaration, ParserRuleContext expression) { if (Tokens.Variant.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase) || Tokens.Object.Equals(asTypeName, StringComparison.InvariantCultureIgnoreCase)) { // We cannot know the the default member in this case, so return an unbound member call. return(new ProcedureCoercionExpression(wrappedExpression.ReferencedDeclaration, ExpressionClassification.Unbound, expression, wrappedExpression)); } var defaultMember = (asTypeDeclaration as ClassModuleDeclaration)?.DefaultMember; if (defaultMember == null || !IsPropertyGetLetFunctionProcedure(defaultMember) || !IsPublic(defaultMember)) { return(CreateFailedExpression(wrappedExpression, expression)); } var defaultMemberClassification = DefaultMemberClassification(defaultMember); var parameters = ((IParameterizedDeclaration)defaultMember).Parameters.ToList(); if (parameters.All(parameter => parameter.IsOptional || parameter.IsParamArray)) { //We found some default member accepting the empty argument list. So, we are done. return(new ProcedureCoercionExpression(defaultMember, defaultMemberClassification, expression, wrappedExpression)); } return(CreateFailedExpression(wrappedExpression, expression)); }
public ParenthesizedExpression( Declaration referencedDeclaration, ParserRuleContext context, IBoundExpression expression) : base(referencedDeclaration, ExpressionClassification.Value, context) { _expression = expression; }
private static IBoundExpression CreateFailedDefaultMemberAccessExpression(IBoundExpression lExpression, ArgumentList argumentList, ParserRuleContext context) { var failedExpr = new DictionaryAccessExpression(lExpression.ReferencedDeclaration, ExpressionClassification.ResolutionFailed, context, lExpression, argumentList, context); var argumentExpressions = argumentList.Arguments.Select(arg => arg.Expression); return(failedExpr.JoinAsFailedResolution(context, argumentExpressions.Concat(new [] { lExpression }))); }
public UnaryOpExpression( Declaration referencedDeclaration, ParserRuleContext context, IBoundExpression expr) : base(referencedDeclaration, ExpressionClassification.Value, context) { _expr = expr; }
public override void Visit(IBoundExpression boundExpression) { if (Process(boundExpression)) { visitor.Visit(boundExpression); } base.Visit(boundExpression); }
public NewExpression( Declaration referencedDeclaration, ParserRuleContext context, IBoundExpression typeExpression) : base(referencedDeclaration, ExpressionClassification.Value, context) { _typeExpression = typeExpression; }
public void Resolve(Declaration calledProcedure) { _expression = _binding.Resolve(); if (calledProcedure != null) { _namedArgumentExpression = _namedArgumentExpressionCreator(calledProcedure); } }
public DictionaryAccessDefaultBinding( ParserRuleContext expression, IBoundExpression lExpression, ArgumentList argumentList) { _expression = expression; _lExpression = lExpression; _argumentList = argumentList; }
public NewExpression( Declaration referencedDeclaration, ParserRuleContext context, IBoundExpression typeExpression) // Marked as Variable instead of Value to integrate into rest of binding process. : base(referencedDeclaration, ExpressionClassification.Variable, context) { TypeExpression = typeExpression; }
public LetCoercionDefaultBinding( ParserRuleContext expression, IBoundExpression wrappedExpression, bool isAssignment = false) { _expression = expression; _wrappedExpression = wrappedExpression; _isAssignment = isAssignment; }
public IBoundExpression Resolve() { if (_lExpressionBinding != null) { _lExpression = _lExpressionBinding.Resolve(); } return(Resolve(_lExpression, _argumentList, _expression)); }
public IBoundExpression Resolve() { if (_wrappedExpressionBinding != null) { _wrappedExpression = _wrappedExpressionBinding.Resolve(); } return(Resolve(_wrappedExpression, _expression, _isAssignment)); }
public ObjectPrintExpression( ParserRuleContext context, IBoundExpression printMethodExpression, IBoundExpression outputListBoundExpression) : base(null, ExpressionClassification.Subroutine, context) { PrintMethodExpressions = printMethodExpression; OutputListExpression = outputListBoundExpression; }
public override void TraverseChildren(IBoundExpression boundExpression) { var tm = boundExpression.Definition as ITypeMemberReference; if (tm != null) { var resolvedMember = tm.ResolvedTypeDefinitionMember; string propertyName = ContractHelper.GetStringArgumentFromAttribute(resolvedMember.Attributes, "System.Diagnostics.Contracts.ContractPublicPropertyNameAttribute"); // we don't care what it is, it just means it has a public property that represents it // so if it is null, then it is *not* a field that has a [ContractPublicPropertyName] marking // and so its visibility counts. If it *is* such a field, then it is considered to be public. // (TODO: checker should make sure that the property it names is public.) if (propertyName == null) { this.currentVisibility = TypeHelper.VisibilityIntersection(this.currentVisibility, resolvedMember.Visibility); } } base.TraverseChildren(boundExpression); }
public override IExpression Rewrite(IBoundExpression boundExpression) { var fieldReference = boundExpression.Definition as IFieldReference; if (fieldReference != null) { if (this.delegatesCachedInFields != null) { var cachedDelegate = this.delegatesCachedInFields.Find(fieldReference.InternedKey); if (cachedDelegate != null) return cachedDelegate; } } else if (this.delegatesCachedInLocals != null) { var local = boundExpression.Definition as LocalDefinition; if (local != null) { AnonymousDelegate cachedDelegate; if (this.delegatesCachedInLocals.TryGetValue(local, out cachedDelegate)) { Contract.Assume(cachedDelegate != null); return cachedDelegate; } } } return base.Rewrite(boundExpression); }
/// <summary> /// Traverses the bound expression. /// </summary> public void Traverse(IBoundExpression boundExpression) { Contract.Requires(boundExpression != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(boundExpression); if (this.StopTraversal) return; this.TraverseChildren(boundExpression); if (this.StopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(boundExpression); }
/// <summary> /// Performs some computation with the given bound expression. /// </summary> /// <param name="boundExpression"></param> public virtual void Visit(IBoundExpression boundExpression) { }
/// <summary> /// Rewrites the given bound expression. /// </summary> /// <param name="boundExpression"></param> public virtual IExpression Rewrite(IBoundExpression boundExpression) { return boundExpression; }
public override IExpression Rewrite(IBoundExpression boundExpression) { if (boundExpression.Definition == this.local) { this.replacementHappened = true; this.replacedLastUseOfLocalVersion = this.bindingsThatMakeALastUseOfALocalVersion.Contains(boundExpression); return this.expressionToSubstituteForLocal; } return base.Rewrite(boundExpression); }
public void Visit(IBoundExpression boundExpression) { throw new NotImplementedException(); }
public override IExpression Rewrite(IBoundExpression boundExpression) { if (boundExpression.Instance == null || ExpressionTraverser.IsAtomicInstance(boundExpression.Instance)) return boundExpression; // boundExpression == BE(inst, def), i.e., inst.def // return { loc := e; [assert loc != null;] | BE(BE(null,loc), def) }, i.e., "loc := e; loc.def" // where e is the rewritten inst var e = base.Rewrite(boundExpression.Instance); var loc = new LocalDefinition() { Name = this.host.NameTable.GetNameFor("_loc" + this.sink.LocalCounter.ToString()), Type = e.Type, }; var locDecl = new LocalDeclarationStatement() { InitialValue = e, LocalVariable = loc, }; return new BlockExpression() { BlockStatement = new BlockStatement() { Statements = new List<IStatement> { locDecl }, }, Expression = new BoundExpression() { Definition = boundExpression.Definition, Instance = new BoundExpression() { Definition = loc, Instance = null, Type = loc.Type, }, Type = boundExpression.Type, }, }; }
/// <summary> /// Performs some computation with the given bound expression. /// </summary> /// <param name="boundExpression"></param> public virtual void Visit(IBoundExpression boundExpression) { this.Visit((IExpression)boundExpression); }
public void Visit(IBoundExpression boundExpression) { this.result = this.copier.Copy(boundExpression); }
public override void TraverseChildren(IBoundExpression boundExpression) { //if (boundExpression.Instance != null && !IsAtomicInstance(boundExpression.Instance)) { // // Simplify the BE so that all nested dereferences and method calls are broken up into separate assignments to locals. // var se = ExpressionSimplifier.Simplify(this.sink, boundExpression); // this.Traverse(se); // return; //} if (boundExpression.Instance != null) { this.Traverse(boundExpression.Instance); var nestedBE = boundExpression.Instance as IBoundExpression; if (nestedBE != null) { var l = this.sink.CreateFreshLocal(nestedBE.Type); var e = this.TranslatedExpressions.Pop(); var lhs = Bpl.Expr.Ident(l); var cmd = Bpl.Cmd.SimpleAssign(boundExpression.Token(), lhs, e); this.StmtTraverser.StmtBuilder.Add(cmd); this.TranslatedExpressions.Push(lhs); } } #region Local ILocalDefinition local = boundExpression.Definition as ILocalDefinition; if (local != null) { TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.FindOrCreateLocalVariable(local))); return; } #endregion #region Parameter IParameterDefinition param = boundExpression.Definition as IParameterDefinition; if (param != null) { this.LoadParameter(param); return; } #endregion #region Field IFieldReference field = boundExpression.Definition as IFieldReference; if (field != null) { var f = Bpl.Expr.Ident(this.sink.FindOrCreateFieldVariable(field.ResolvedField)); var instance = boundExpression.Instance; if (instance == null) { TranslatedExpressions.Push(f); } else { // this.Traverse(instance); Bpl.Expr instanceExpr = TranslatedExpressions.Pop(); var bplType = this.sink.CciTypeToBoogie(field.Type); var e = this.sink.Heap.ReadHeap(instanceExpr, f, field.ContainingType.ResolvedType.IsStruct ? AccessType.Struct : AccessType.Heap, bplType); AssertOrAssumeNonNull(boundExpression.Token(), instanceExpr); this.TranslatedExpressions.Push(e); } return; } #endregion #region ArrayIndexer IArrayIndexer/*?*/ indexer = boundExpression.Definition as IArrayIndexer; if (indexer != null) { this.Traverse(indexer); return; } #endregion #region AddressDereference IAddressDereference/*?*/ deref = boundExpression.Definition as IAddressDereference; if (deref != null) { IAddressOf/*?*/ addressOf = deref.Address as IAddressOf; if (addressOf != null) { this.Traverse(addressOf.Expression); return; } if (boundExpression.Instance != null) { // TODO this.Traverse(boundExpression.Instance); Console.Write("->"); } else if (deref.Address.Type is IPointerTypeReference) Console.Write("*"); this.Traverse(deref.Address); return; } else { if (boundExpression.Instance != null) { throw new NotImplementedException("Addr DeRef without instance."); } } #endregion }
/// <summary> /// Returns a shallow copy of the given bound expression. /// </summary> /// <param name="boundExpression"></param> public BoundExpression Copy(IBoundExpression boundExpression) { return new BoundExpression(boundExpression); }
/// <summary> /// Returns a deep copy of the given bound expression. /// </summary> /// <param name="boundExpression"></param> public BoundExpression Copy(IBoundExpression boundExpression) { var mutableCopy = this.shallowCopier.Copy(boundExpression); this.CopyChildren((Expression)mutableCopy); if (mutableCopy.Instance != null) mutableCopy.Instance = this.Copy(mutableCopy.Instance); var local = mutableCopy.Definition as ILocalDefinition; if (local != null) mutableCopy.Definition = this.GetExistingCopyIfInsideCone(local); else { var parameter = mutableCopy.Definition as IParameterDefinition; if (parameter != null) mutableCopy.Definition = this.GetExistingCopyIfInsideCone(parameter); else { var fieldReference = (IFieldReference)mutableCopy.Definition; mutableCopy.Definition = this.Copy(fieldReference); } } return mutableCopy; }
/// <summary> /// Visits the specified bound expression. /// </summary> /// <param name="boundExpression">The bound expression.</param> public override void Visit(IBoundExpression boundExpression) { BoundExpression mutableBoundExpression = new BoundExpression(boundExpression); this.resultExpression = this.myCodeCopier.DeepCopy(mutableBoundExpression); }
/// <summary> /// Traverses the children of the bound expression. /// </summary> public virtual void TraverseChildren(IBoundExpression boundExpression) { Contract.Requires(boundExpression != null); this.TraverseChildren((IExpression)boundExpression); if (this.StopTraversal) return; if (boundExpression.Instance != null) { this.Traverse(boundExpression.Instance); if (this.StopTraversal) return; } var local = boundExpression.Definition as ILocalDefinition; if (local != null) this.Traverse(local); else { var parameter = boundExpression.Definition as IParameterDefinition; if (parameter != null) this.Traverse(parameter); else { var fieldReference = (IFieldReference)boundExpression.Definition; this.Traverse(fieldReference); } } }
public override void Visit(IBoundExpression boundExpression) { //if (boundExpression.Instance != null) //{ // this.Visit(boundExpression.Instance); // // TODO: (mschaef) look where it's bound and do something //} #region LocalDefinition ILocalDefinition local = boundExpression.Definition as ILocalDefinition; if (local != null) { TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.FindOrCreateLocalVariable(local))); return; } #endregion #region ParameterDefiniton IParameterDefinition param = boundExpression.Definition as IParameterDefinition; if (param != null) { TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.FindParameterVariable(param))); return; } #endregion #region FieldDefinition IFieldReference field = boundExpression.Definition as IFieldReference; if (field != null) { if (boundExpression.Instance != null) { ProcessFieldVariable(field, boundExpression.Instance,true); return; } else { throw new NotImplementedException(String.Format("Field {0} with Instance NULL.", boundExpression.ToString())); } } #endregion #region PropertyDefinition IPropertyDefinition prop = boundExpression.Definition as IPropertyDefinition; if (prop != null) { throw new NotImplementedException("Properties are not implemented"); } #endregion #region ArrayIndexer IArrayIndexer/*?*/ indexer = boundExpression.Definition as IArrayIndexer; if (indexer != null) { this.Visit(indexer); return; } #endregion #region AddressDereference IAddressDereference/*?*/ deref = boundExpression.Definition as IAddressDereference; if (deref != null) { IAddressOf/*?*/ addressOf = deref.Address as IAddressOf; if (addressOf != null) { this.Visit(addressOf.Expression); return; } if (boundExpression.Instance != null) { // TODO this.Visit(boundExpression.Instance); Console.Write("->"); } else if (deref.Address.Type is IPointerTypeReference) Console.Write("*"); this.Visit(deref.Address); return; } else { if (boundExpression.Instance != null) { throw new NotImplementedException("Addr DeRef without instance."); } } #endregion }
public void Visit(IBoundExpression boundExpression) { this.traverser.Traverse(boundExpression); }
/// <summary> /// /// </summary> /// <param name="boundExpression"></param> public BoundExpression(IBoundExpression boundExpression) : base(boundExpression) { if (boundExpression.IsUnaligned) this.alignment = boundExpression.Alignment; else this.alignment = 0; this.definition = boundExpression.Definition; this.instance = boundExpression.Instance; this.isVolatile = boundExpression.IsVolatile; }
public void Visit(IBoundExpression boundExpression) { Contract.Requires(boundExpression != null); throw new NotImplementedException(); }
/// <summary> /// Returns a shallow copy of the given bound expression. /// </summary> /// <param name="boundExpression"></param> public BoundExpression Copy(IBoundExpression boundExpression) { Contract.Requires(boundExpression != null); Contract.Ensures(Contract.Result<BoundExpression>() != null); return new BoundExpression(boundExpression); }
/// <summary> /// Traverses the given bound expression. /// </summary> /// <param name="boundExpression"></param> public virtual void Visit(IBoundExpression boundExpression) { if (this.stopTraversal) return; this.path.Push(boundExpression); var definition = boundExpression.Definition; var local = definition as ILocalDefinition; if (local != null) this.VisitReference(local); else { var parameter = definition as IParameterDefinition; if (parameter != null) this.VisitReference(parameter); else { var field = (IFieldReference)definition; this.Visit(field); } } if (boundExpression.Instance != null) this.Visit(boundExpression.Instance); this.path.Pop(); }
public override void Visit(IBoundExpression boundExpression) { NewLineAddIndent(); AppendElementType(boundExpression); //if (boundExpression.Definition != null && boundExpression.Definition is ILocalDefinition) //{ // Visit(boundExpression.Definition as ILocalDefinition); //} base.Visit(boundExpression); }
public override void Visit(IBoundExpression boundExpression) { IParameterDefinition par = boundExpression.Definition as IParameterDefinition; if (par != null && par.IsOut) { ISourceItem sourceItem = boundExpression as ISourceItem; if (sourceItem == null) sourceItem = this.defaultSourceItemForErrorReporting; this.helper.ReportError(new AstErrorMessage(sourceItem, Error.OutParameterReferenceNotAllowedHere, par.Name.Value)); OutParameterFound = true; } base.Visit(boundExpression); }
public override IExpression Rewrite(IBoundExpression boundExpression) { if (this.expressionToSubstituteForSingleUseSingleReferenceLocal != null && boundExpression.Definition == this.currentSingleUseSingleReferenceLocal) { if (this.localsToEliminate == null) this.localsToEliminate = new SetOfObjects(); this.localsToEliminate.Add(this.currentSingleUseSingleReferenceLocal); return this.expressionToSubstituteForSingleUseSingleReferenceLocal; } return base.Rewrite(boundExpression); }
public override void TraverseChildren(IBoundExpression boundExpression) { if (boundExpression.Instance != null) { IAddressOf/*?*/ addressOf = boundExpression.Instance as IAddressOf; if (addressOf != null && addressOf.Expression.Type.IsValueType) { this.Traverse(addressOf.Expression); } else { this.Traverse(boundExpression.Instance); } this.PrintToken(CSharpToken.Dot); } PrintBoundExpressionDefinition(boundExpression.Instance, boundExpression.Definition); }
public override void TraverseChildren(IBoundExpression boundExpression) { base.TraverseChildren(boundExpression); ITypeReference type = Dummy.TypeReference; ILocalDefinition/*?*/ local = boundExpression.Definition as ILocalDefinition; if (local != null) { type = local.Type; if (local.IsReference) { if (local.IsPinned) { type = Immutable.PointerType.GetPointerType(type, this.host.InternFactory); } else { type = Immutable.ManagedPointerType.GetManagedPointerType(type, this.host.InternFactory); } } } else { IParameterDefinition/*?*/ parameter = boundExpression.Definition as IParameterDefinition; if (parameter != null) { type = parameter.Type; if (parameter.IsByReference) type = Immutable.ManagedPointerType.GetManagedPointerType(type, this.host.InternFactory); } else { IFieldReference/*?*/ field = boundExpression.Definition as IFieldReference; if (field != null) type = field.Type; } } ((BoundExpression)boundExpression).Type = type; }
public override void TraverseChildren(IBoundExpression boundExpression) { this.LookForCapturedDefinition(boundExpression.Definition); base.TraverseChildren(boundExpression); }
public override void TraverseChildren(IBoundExpression boundExpression) { MethodEnter(boundExpression); base.TraverseChildren(boundExpression); MethodExit(); }
public virtual void onASTElement(IBoundExpression boundExpression) { }
public override void TraverseChildren(IBoundExpression boundExpression) { if (boundExpression.Definition == this.local) { if (this.numberOfReferencesToLocal[local] == 1) this.localCanBeReplaced = true; else this.localCanBeReplaced = this.bindingsThatMakeALastUseOfALocalVersion.Contains(boundExpression); this.StopTraversal = true; return; } base.TraverseChildren(boundExpression); }