本文整理汇总了C#中MemberBinding类的典型用法代码示例。如果您正苦于以下问题:C# MemberBinding类的具体用法?C# MemberBinding怎么用?C# MemberBinding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberBinding类属于命名空间,在下文中一共展示了MemberBinding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding){
if (memberBinding == null) return null;
if (memberBinding.BoundMember != null){
if (!memberBinding.BoundMember.IsStatic){
//add precondition that target object is not null
}
}
return base.VisitMemberBinding(memberBinding);
}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:9,代码来源:Verifier.cs
示例2: VisitRefTypeExpression
public override Expression VisitRefTypeExpression(RefTypeExpression reftypexp) {
if (reftypexp == null) return null;
Expression result = base.VisitRefTypeExpression (reftypexp);
if (result != reftypexp) return result;
UnaryExpression refanytype = new UnaryExpression(reftypexp.Operand, NodeType.Refanytype, SystemTypes.RuntimeTypeHandle, reftypexp.SourceContext);
ExpressionList arguments = new ExpressionList(1);
arguments.Add(refanytype);
MemberBinding mb = new MemberBinding(null, Runtime.GetTypeFromHandle);
return new MethodCall(mb, arguments, NodeType.Call, SystemTypes.Type);
}
开发者ID:dbremner,项目名称:specsharp,代码行数:10,代码来源:Normalizer.cs
示例3: AsBinding
internal override MemberBinding AsBinding() {
switch (_action) {
case RewriteAction.None:
return _binding;
case RewriteAction.Copy:
MemberBinding[] newBindings = new MemberBinding[_bindings.Count];
for (int i = 0; i < _bindings.Count; i++) {
newBindings[i] = _bindingRewriters[i].AsBinding();
}
return Expression.MemberBind(_binding.Member, new TrueReadOnlyCollection<MemberBinding>(newBindings));
}
throw ContractUtils.Unreachable;
}
开发者ID:aceptra,项目名称:ironruby,代码行数:13,代码来源:StackSpiller.Bindings.cs
示例4: Create
internal static BindingRewriter Create(MemberBinding binding, StackSpiller spiller, Stack stack) {
switch (binding.BindingType) {
case MemberBindingType.Assignment:
MemberAssignment assign = (MemberAssignment)binding;
return new MemberAssignmentRewriter(assign, spiller, stack);
case MemberBindingType.ListBinding:
MemberListBinding list = (MemberListBinding)binding;
return new ListBindingRewriter(list, spiller, stack);
case MemberBindingType.MemberBinding:
MemberMemberBinding member = (MemberMemberBinding)binding;
return new MemberMemberBindingRewriter(member, spiller, stack);
}
throw Error.UnhandledBinding();
}
开发者ID:aceptra,项目名称:ironruby,代码行数:14,代码来源:StackSpiller.Bindings.cs
示例5: VisitMemberBinding
public override void VisitMemberBinding(MemberBinding memberBinding)
{
var method = memberBinding.BoundMember as Method;
if (method != null)
{
string message;
if (_problematicTypes.TryGetValue(method.DeclaringType.FullName, out message))
{
Problems.Add(new Problem(GetResolution(method.DeclaringType.FullName, message), memberBinding.UniqueKey.ToString()));
}
}
base.VisitMemberBinding(memberBinding);
}
开发者ID:haxard,项目名称:lab,代码行数:14,代码来源:DoNotUseProblematicTaskTypesRule.cs
示例6: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding binding)
{
Member boundMember = binding.BoundMember;
if (boundMember is Field && !boundMember.IsStatic && boundMember.DeclaringType != null && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField)
{
Expression target = VisitExpression(binding.TargetObject);
// Since we do not visit member bindings of assignment statements, we know/guess that this is a ldfld.
Local targetLocal = new Local(boundMember.DeclaringType);
Statement evaluateTarget = new AssignmentStatement(targetLocal, target, binding.SourceContext);
Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsReading"))), null, NodeType.Call, SystemTypes.Void));
Statement ldfld = new ExpressionStatement(new MemberBinding(targetLocal, boundMember, binding.SourceContext));
return new BlockExpression(new Block(new StatementList(new Statement[] {evaluateTarget, check, ldfld})), binding.Type);
}
else
{
return base.VisitMemberBinding(binding);
}
}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:19,代码来源:GuardedFieldAccessInstrumenter.cs
示例7: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding){
if (memberBinding == null) return null;
Field f = memberBinding.BoundMember as Field;
if (f != null){
if (f.IsLiteral){
if (f.DefaultValue != null) return f.DefaultValue;
Expression e = f.Initializer;
if (e == Evaluator.BeingEvaluated) throw new CircularConstantException();
f.Initializer = Evaluator.BeingEvaluated;
Literal lit = null;
try{
lit = this.VisitExpression(e) as Literal;
}catch(CircularConstantException){
f.Initializer = null;
throw;
}
if (lit != null){
if (f.DeclaringType is EnumNode && f.Type == f.DeclaringType) lit.Type = f.DeclaringType;
f.DefaultValue = lit;
f.Initializer = null;
return lit;
}
}else{
//Should never get here from the compiler itself, but only from runtime code paths.
if (f.IsStatic) return f.GetValue(null);
Expression targetLiteral = this.VisitExpression(memberBinding.TargetObject) as Expression;
if (targetLiteral != null){
// HACK: Unary Expressions with NodeType "AddressOf" not getting converted to Literal.
UnaryExpression uexpr = targetLiteral as UnaryExpression;
if (uexpr != null)
targetLiteral = this.VisitExpression(uexpr.Operand);
if (targetLiteral is Literal)
return f.GetValue(targetLiteral as Literal);
}
}
}
return null;
}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:38,代码来源:Evaluator.cs
示例8: VisitMemberBinding
public virtual void VisitMemberBinding (MemberBinding node)
{
if (node == null)
return;
VisitExpression (node.TargetObject);
}
开发者ID:carrie901,项目名称:mono,代码行数:7,代码来源:NodeInspector.cs
示例9: VisitApplyToAll
public override Expression VisitApplyToAll(ApplyToAll applyToAll) {
if (applyToAll == null) return null;
Expression collection = applyToAll.Operand1;
if (collection == null) { Debug.Assert(false); return null; }
TypeNode elemType = this.typeSystem.GetStreamElementType(collection.Type, this.TypeViewer);
bool singleTon = elemType == collection.Type;
Local loc = applyToAll.ElementLocal;
if (loc == null) loc = new Local(elemType);
if (singleTon)
applyToAll.Operand1 = this.VisitExpression(collection);
else
applyToAll.Operand1 = this.VisitEnumerableCollection(collection, loc.Type);
if (applyToAll.Operand1 == null) return null;
AnonymousNestedFunction func = applyToAll.Operand2 as AnonymousNestedFunction;
Expression expr = applyToAll.Operand2 as BlockExpression;
if (func != null || expr != null) {
this.VisitAnonymousNestedFunction(func);
if (singleTon || applyToAll.Type == SystemTypes.Void) return applyToAll;
//Create an iterator to compute stream that results from ApplyToAll
Class closureClass = this.currentMethod.Scope.ClosureClass;
Method method = new Method();
method.Name = Identifier.For("Function:"+method.UniqueKey);
method.SourceContext = collection.SourceContext;
method.Flags = MethodFlags.CompilerControlled;
method.CallingConvention = CallingConventionFlags.HasThis;
method.InitLocals = true;
method.DeclaringType = closureClass;
closureClass.Members.Add(method);
method.Scope = new MethodScope(new TypeScope(null, closureClass), null);
Parameter coll = new Parameter(StandardIds.Collection, collection.Type);
ParameterField fcoll = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Collection, collection.Type, null);
fcoll.Parameter = coll;
method.Scope.Members.Add(fcoll);
Parameter closure = new Parameter(StandardIds.Closure, closureClass);
ParameterField fclosure = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Closure, closureClass, null);
fclosure.Parameter = closure;
if (func != null) {
method.Scope.Members.Add(fclosure);
method.Parameters = new ParameterList(coll, closure);
} else
method.Parameters = new ParameterList(coll);
method.ReturnType = applyToAll.Type;
ForEach forEach = new ForEach();
forEach.TargetVariable = loc;
forEach.TargetVariableType = loc.Type;
forEach.SourceEnumerable = new MemberBinding(new ImplicitThis(), fcoll);
if (func != null) {
MemberBinding mb = new MemberBinding(new MemberBinding(new ImplicitThis(), fclosure), func.Method);
expr = new MethodCall(mb, new ExpressionList(loc), NodeType.Call, func.Method.ReturnType, func.SourceContext);
} else
expr = this.VisitExpression(expr);
expr = this.typeSystem.ImplicitCoercion(expr, this.typeSystem.GetStreamElementType(applyToAll.Type, this.TypeViewer), this.TypeViewer);
if (expr == null) return null;
BlockExpression bExpr = expr as BlockExpression;
if (bExpr != null && bExpr.Type == SystemTypes.Void)
forEach.Body = bExpr.Block;
else
forEach.Body = new Block(new StatementList(new Yield(expr)));
forEach.ScopeForTemporaryVariables = new BlockScope(method.Scope, forEach.Body);
method.Body = new Block(new StatementList(forEach));
applyToAll.ResultIterator = this.VisitMethod(method);
return applyToAll;
}
Debug.Assert(false);
return null;
}
开发者ID:hesam,项目名称:SketchSharp,代码行数:66,代码来源:Checker.cs
示例10: GetProjectionList
public virtual void GetProjectionList(Accessor accessor, Expression source, ExpressionList list){
if (accessor == null) return;
MemberAccessor ma = accessor as MemberAccessor;
if (ma != null){
MemberBinding mb = new MemberBinding(source, ma.Member);
mb.SourceContext = source.SourceContext;
if (ma.Yield){
list.Add(mb);
}
if (ma.Next != null){
this.GetProjectionList(ma.Next, mb, list);
}
return;
}
SequenceAccessor sa = accessor as SequenceAccessor;
if (sa != null){
foreach( Accessor acc in sa.Accessors ){
this.GetProjectionList(acc, source, list);
}
return;
}
this.HandleError(source, Error.QueryProjectThroughTypeUnion);
}
开发者ID:dbremner,项目名称:specsharp,代码行数:23,代码来源:Resolver.cs
示例11: EmitBinding
private void EmitBinding(MemberBinding binding, Type objectType)
{
switch (binding.BindingType)
{
case MemberBindingType.Assignment:
EmitMemberAssignment((MemberAssignment)binding, objectType);
break;
case MemberBindingType.ListBinding:
EmitMemberListBinding((MemberListBinding)binding);
break;
case MemberBindingType.MemberBinding:
EmitMemberMemberBinding((MemberMemberBinding)binding);
break;
default:
throw Error.UnknownBindingType();
}
}
开发者ID:SGuyGe,项目名称:corefx,代码行数:17,代码来源:LambdaCompiler.Expressions.cs
示例12: VisitMemberBinding
public virtual Differences VisitMemberBinding(MemberBinding memberBinding1, MemberBinding memberBinding2){
Differences differences = new Differences(memberBinding1, memberBinding2);
if (memberBinding1 == null || memberBinding2 == null){
if (memberBinding1 != memberBinding2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
return differences;
}
MemberBinding changes = (MemberBinding)memberBinding2.Clone();
MemberBinding deletions = (MemberBinding)memberBinding2.Clone();
MemberBinding insertions = (MemberBinding)memberBinding2.Clone();
if (memberBinding1.Alignment == memberBinding2.Alignment) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
Differences diff = this.VisitMember(memberBinding1.BoundMember, memberBinding2.BoundMember);
if (diff == null){Debug.Assert(false); return differences;}
changes.BoundMember = diff.Changes as Member;
deletions.BoundMember = diff.Deletions as Member;
insertions.BoundMember = diff.Insertions as Member;
Debug.Assert(diff.Changes == changes.BoundMember && diff.Deletions == deletions.BoundMember && diff.Insertions == insertions.BoundMember);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
diff = this.VisitExpression(memberBinding1.TargetObject, memberBinding2.TargetObject);
if (diff == null){Debug.Assert(false); return differences;}
changes.TargetObject = diff.Changes as Expression;
deletions.TargetObject = diff.Deletions as Expression;
insertions.TargetObject = diff.Insertions as Expression;
Debug.Assert(diff.Changes == changes.TargetObject && diff.Deletions == deletions.TargetObject && diff.Insertions == insertions.TargetObject);
differences.NumberOfDifferences += diff.NumberOfDifferences;
differences.NumberOfSimilarities += diff.NumberOfSimilarities;
if (memberBinding1.Volatile == memberBinding2.Volatile) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;
if (differences.NumberOfDifferences == 0){
differences.Changes = null;
differences.Deletions = null;
differences.Insertions = null;
}else{
differences.Changes = changes;
differences.Deletions = deletions;
differences.Insertions = insertions;
}
return differences;
}
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:43,代码来源:Comparer.cs
示例13: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding)
{
var result = base.VisitMemberBinding(memberBinding);
var mb = result as MemberBinding;
if (mb != null)
{
mb.BoundMember = this.VisitMemberReference(mb.BoundMember);
}
return result;
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:10,代码来源:Specializer.cs
示例14: VisitMemberBinding
public virtual Expression VisitMemberBinding(MemberBinding memberBinding, bool isTargetOfAssignment) {
if (memberBinding == null) return null;
Member mem = memberBinding.BoundMember;
if (mem == null) return null;
TypeNode memType = mem.DeclaringType;
Expression originalTarget = memberBinding.TargetObject;
Expression target = originalTarget;
if (mem.IsStatic) {
this.VisitTypeReference(mem.DeclaringType);
}
if (target != null) {
QueryContext qc = target as QueryContext;
if (qc != null && qc.Type == null) {
this.HandleError(memberBinding, Error.IdentifierNotFound, mem.Name.ToString());
return null;
}
target = memberBinding.TargetObject = this.VisitExpression(target);
if (target == null) return null;
}
Property prop = mem as Property;
if (prop != null) {
Error e = Error.None;
if (isTargetOfAssignment && !(prop.Type is Reference)) {
Method setter = prop.Setter;
if (setter == null) setter = prop.GetBaseSetter();
if (setter == null) {
e = Error.NoSetter;
}
else if (setter.IsAbstract && memberBinding.TargetObject is Base)
e = Error.AbstractBaseCall;
} else {
if (prop.Getter == null) e = Error.NoGetter;
}
if (e != Error.None) {
string typeName = this.GetTypeName(mem.DeclaringType);
this.HandleError(memberBinding, e, typeName+"."+mem.Name);
return null;
}
}
TypeNode targetType = target == null ? null : TypeNode.StripModifiers(target.Type);
bool errorIfCurrentMethodIsStatic = false;
if (target is ImplicitThis) {
errorIfCurrentMethodIsStatic = !(memType is BlockScope || memType is MethodScope); //locals and parameters are excempt
if (errorIfCurrentMethodIsStatic && !this.NotAccessible(mem)) {
if (this.MayNotReferenceThisFromFieldInitializer && this.currentMethod == null && this.currentField != null && !this.currentField.IsStatic) {
this.HandleError(memberBinding, Error.ThisReferenceFromFieldInitializer, this.GetMemberSignature(mem));
return null;
}
if (!this.GetTypeView(this.currentType).IsAssignableTo(memType)) {
this.HandleError(memberBinding, Error.AccessToNonStaticOuterMember, this.GetTypeName(mem.DeclaringType), this.GetTypeName(this.currentType));
return null;
}
}
if (!this.MayReferenceThisAndBase && !(memType is Scope) && !this.insideInvariant) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
}
targetType = null;
} else if (target is Base || target is This) {
if (!this.MayReferenceThisAndBase && !(this.insideInvariant && target is This)) {
if (target is Base)
this.HandleError(memberBinding, Error.BaseInBadContext, this.GetMemberSignature(mem));
else
this.HandleError(memberBinding, Error.ThisInBadContext, this.GetMemberSignature(mem));
return null;
}
targetType = null;
errorIfCurrentMethodIsStatic = true;
} else if (!mem.IsStatic && target is Literal) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
} else if (target != null) {
target = memberBinding.TargetObject = this.typeSystem.ExplicitCoercion(target, memType, this.TypeViewer);
if (target == null) return null;
if (prop != null && memType != null && memType.IsValueType)
target = memberBinding.TargetObject = new UnaryExpression(target, NodeType.AddressOf, memType.GetReferenceType());
}
if (errorIfCurrentMethodIsStatic &&
((this.currentMethod != null && this.currentMethod.IsStatic) || (this.currentField != null && this.currentField.IsStatic))) {
this.HandleError(memberBinding, Error.ObjectRequired, this.GetMemberSignature(mem));
return null;
}
if (this.NotAccessible(mem, ref targetType)) {
string mname = mem.Name.ToString();
if (targetType == null && target != null && target.Type != null && !(target is ImplicitThis || target is This || target is Base))
this.HandleError(memberBinding, Error.NotVisibleViaBaseType, this.GetTypeName(mem.DeclaringType)+"."+mname,
this.GetTypeName(target.Type), this.GetTypeName(this.currentType));
else if (mem.IsSpecialName && mem is Field && ((Field)mem).Type is DelegateNode)
this.HandleError(memberBinding, Error.InaccessibleEventBackingField, this.GetTypeName(mem.DeclaringType) + "." + mname, this.GetTypeName(mem.DeclaringType));
else {
Node offendingNode = memberBinding;
QualifiedIdentifier qi = memberBinding.BoundMemberExpression as QualifiedIdentifier;
if (qi != null) offendingNode = qi.Identifier;
this.HandleError(offendingNode, Error.MemberNotVisible, this.GetTypeName(mem.DeclaringType) + "." + mname);
this.HandleRelatedError(mem);
}
return null;
} else {
string mname = mem.Name.ToString();
if (!mem.IsCompilerControlled && (this.insideMethodContract || this.insideInvariant)) {
//.........这里部分代码省略.........
开发者ID:hesam,项目名称:SketchSharp,代码行数:101,代码来源:Checker.cs
示例15: VisitConstruct
public override Expression VisitConstruct(Construct cons){
if (cons == null) return cons;
cons.Owner = this.VisitExpression(cons.Owner);
cons.Constructor = this.VisitExpression(cons.Constructor);
MemberBinding mb = cons.Constructor as MemberBinding;
if (mb == null){
Literal literal = cons.Constructor as Literal;
if (literal == null) return cons;
TypeNode t = literal.Value as TypeNode;
if (t == null) return cons;
cons.Type = t;
cons.Constructor = mb = new MemberBinding(null, t);
mb.SourceContext = literal.SourceContext;
}else{
TypeNode t = mb.BoundMember as TypeNode;
if (t == null) return cons; //TODO: if the bound member is an instance initializer, use it.
cons.Type = t;
}
AnonymousNestedFunction func = null;
DelegateNode delType = cons.Type as DelegateNode;
if (delType != null && cons.Operands != null && cons.Operands.Count == 1){
Method meth = null;
Expression ob = Literal.Null;
Expression e = cons.Operands[0];
MemberBinding emb = e as MemberBinding;
if (emb != null) e = emb.BoundMemberExpression;
TemplateInstance instance = e as TemplateInstance;
TypeNodeList typeArguments = instance == null ? null : instance.TypeArguments;
if (instance != null) e = instance.Expression;
NameBinding nb = e as NameBinding;
if (nb != null){
meth = this.ChooseMethodMatchingDelegate(nb.BoundMembers, delType, typeArguments);
if (meth != null && !meth.IsStatic)
ob = new ImplicitThis();
else if (meth == null){
e = this.VisitExpression(e);
if (e.Type is DelegateNode){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
if (meth != null)
ob = e;
}
}
}else{
QualifiedIdentifier qualId = e as QualifiedIdentifier;
if (qualId != null){
ob = qualId.Qualifier = this.VisitExpression(qualId.Qualifier);
if (ob is Literal && ob.Type == SystemTypes.Type)
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView((ob as Literal).Value as TypeNode).GetMembersNamed(qualId.Identifier), delType, typeArguments);
else if (ob == null)
return null;
else if (ob != null && ob.Type != null){
TypeNode oT = TypeNode.StripModifiers(ob.Type);
Reference rT = oT as Reference;
if (rT != null) oT = rT.ElementType;
while (oT != null){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(oT).GetMembersNamed(qualId.Identifier), delType, typeArguments);
if (meth != null) break;
oT = oT.BaseType;
}
}
if (meth == null){
e = this.VisitExpression(e);
if (e.Type is DelegateNode){
meth = this.ChooseMethodMatchingDelegate(this.GetTypeView(e.Type).GetMembersNamed(StandardIds.Invoke), delType, typeArguments);
if (meth != null){
qualId.BoundMember = new MemberBinding(e, meth, qualId.Identifier);
ob = e;
}
}
}else
qualId.BoundMember = new MemberBinding(ob, meth, qualId.Identifier);
}else{
func = e as AnonymousNestedFunction;
if (func != null){
meth = func.Method;
if (meth != null){
meth.ReturnType = delType.ReturnType;
ParameterList mParams = meth.Parameters;
ParameterList dParams = delType.Parameters;
int n = mParams == null ? 0 : mParams.Count;
int m = dParams == null ? 0 : dParams.Count;
for (int i = 0; i < n; i++){
Parameter mPar = mParams[i];
if (mPar == null) return null;
if (i >= m){
if (mPar.Type == null) mPar.Type = SystemTypes.Object;
continue;
}
Parameter dPar = dParams[i];
if (mPar.Type == null){
if (dPar != null)
mPar.Type = dPar.Type;
if (mPar.Type == null)
mPar.Type = SystemTypes.Object;
}
}
if (n != m){
Node nde = new Expression(NodeType.Nop);
if (n == 0)
nde.SourceContext = cons.Constructor.SourceContext;
//.........这里部分代码省略.........
开发者ID:dbremner,项目名称:specsharp,代码行数:101,代码来源:Resolver.cs
示例16: VisitBinaryExpression
public virtual Expression VisitBinaryExpression(BinaryExpression binaryExpression, Expression opnd1, Expression opnd2, TypeNode t1, TypeNode t2){
if (binaryExpression == null){Debug.Assert(false); return null;}
if (t1 == SystemTypes.String || t2 == SystemTypes.String) {
switch (binaryExpression.NodeType) {
case NodeType.Add:
if (opnd1 is Literal && opnd2 is Literal && t1 == SystemTypes.String && t2 == SystemTypes.String) {
string s1 = ((Literal)opnd1).Value as string;
string s2 = ((Literal)opnd2).Value as string;
return new Literal(s1 + s2, SystemTypes.String, binaryExpression.SourceContext);
}
Method operatorMethod = this.GetBinaryOperatorOverload(binaryExpression);
if (operatorMethod != null) break;
if (this.typeSystem.ImplicitCoercionFromTo(t1, SystemTypes.String, this.TypeViewer) && this.typeSystem.ImplicitCoercionFromTo(t2, SystemTypes.String, this.TypeViewer))
return new MethodCall(new MemberBinding(null, Runtime.StringConcatStrings), new ExpressionList(opnd1, opnd2),
NodeType.Call, SystemTypes.String, binaryExpression.SourceContext);
else
return new MethodCall(new MemberBinding(null, Runtime.StringConcatObjects), new ExpressionList(opnd1, opnd2),
NodeType.Call, SystemTypes.String, binaryExpression.SourceContext);
case NodeType.Eq:
case NodeType.Ne:
binaryExpression.Type = SystemTypes.Boolean;
if (t1 == SystemTypes.String && t2 == SystemTypes.String)
return this.StringValueComparison(binaryExpression);
else if (t1 == SystemTypes.Object || t2 == SystemTypes.Object)
return binaryExpression;
else
break;
}
}
if ((t1 is DelegateNode) && (t2 is DelegateNode) && t1 != t2 && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
this.HandleError(binaryExpression, Error.BadBinaryOps,
binaryExpression.NodeType == NodeType.Eq ? "==" : "!=", this.GetTypeName(t1), this.GetTypeName(t2));
return null;
}
if ((t1 != SystemTypes.Object && t2 != SystemTypes.Object) ||
!(binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne) ||
(t1.Template == SystemTypes.GenericBoxed || t2.Template == SystemTypes.GenericBoxed)){
Method operatorMethod = this.GetBinaryOperatorOverload(binaryExpression);
if (operatorMethod != null) {
MemberBinding callee = new MemberBinding(null, operatorMethod);
ExpressionList arguments = new ExpressionList(2);
if (t1 == SystemTypes.Delegate && t2 is DelegateNode && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
if (opnd1 is MemberBinding && ((MemberBinding)opnd1).BoundMember is Method)
opnd1 = this.VisitExpression(new Construct(new MemberBinding(null, t2), new ExpressionList(opnd1)));
}
arguments.Add(opnd1);
if (t1 is DelegateNode && t2 == SystemTypes.Delegate && (binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne)) {
if (opnd2 is MemberBinding && ((MemberBinding)opnd2).BoundMember is Method)
opnd2 = this.VisitExpression(new Construct(new MemberBinding(null, t1), new ExpressionList(opnd2)));
}
arguments.Add(opnd2);
MethodCall call = new MethodCall(callee, arguments);
call.SourceContext = binaryExpression.SourceContext;
call.Type = operatorMethod.ReturnType;
switch (binaryExpression.NodeType) {
case NodeType.LogicalAnd:
case NodeType.LogicalOr:
binaryExpression.Operand1 = new Local(call.Type);
binaryExpression.Operand2 = call;
binaryExpression.Type = call.Type;
return binaryExpression;
}
return call;
}else if ((t1 == SystemTypes.String || t2 == SystemTypes.String) &&
(binaryExpression.NodeType == NodeType.Eq || binaryExpression.NodeType == NodeType.Ne) &&
this.typeSystem.ImplicitCoercionFromTo(t1, SystemTypes.String, this.TypeViewer) &&
this.typeSystem.ImplicitCoercionFromTo(t2, SystemTypes.String, this.TypeViewer)){
return this.StringValueComparison(binaryExpression);
}
}
if (t1 is DelegateNode || t2 is DelegateNode){
if (binaryExpression.NodeType == NodeType.Add || binaryExpression.NodeType == NodeType.Sub) {
binaryExpression.Type = this.typeSystem.ImplicitCoercionFromTo(opnd1, t1, t2, this.TypeViewer) ? t2 : t1;
return binaryExpression;
}
}
if ((t1 is Pointer || t2 is Pointer) && (binaryExpression.NodeType == NodeType.Add || binaryExpression.NodeType == NodeType.Sub)){
TypeNode elementType = t1 is Pointer ? ((Pointer)t1).ElementType : ((Pointer)t2).ElementType;
Expression sizeOf = this.VisitUnaryExpression(new UnaryExpression(new Literal(elementType, SystemTypes.Type), NodeType.Sizeof, SystemTypes.UInt32));
if (binaryExpression.NodeType == NodeType.Sub) {
if (elementType == SystemTypes.Void) {
this.HandleError(binaryExpression, Error.VoidError);
return null;
}
if (t1 is Pointer && t2 is Pointer && ((Pointer)t1).ElementType == ((Pointer)t2).ElementType) {
binaryExpression.Operand1 = new BinaryExpression(opnd1, new Literal(SystemTypes.Int64, SystemTypes.Type), NodeType.ExplicitCoercion, SystemTypes.Int64, opnd1.SourceContext);
binaryExpression.Operand2 = new BinaryExpression(opnd2, new Literal(SystemTypes.Int64, SystemTypes.Type), NodeType.ExplicitCoercion, SystemTypes.Int64, opnd2.SourceContext);
binaryExpression.Type = SystemTypes.Int64;
return new BinaryExpression(binaryExpression, sizeOf, NodeType.Div, SystemTypes.Int64, binaryExpression.SourceContext);
}
}
if (!(t1 is Pointer && t2 is Pointer)) {
binaryExpression.Type = t1 is Pointer ? t1 : t2;
if (elementType == SystemTypes.Void) {
this.HandleError(binaryExpression, Error.VoidError);
return null;
}
sizeOf.Type = SystemTypes.IntPtr;
if (t1 is Pointer) {
Literal lit = binaryExpression.Operand2 as Literal;
//.........这里部分代码省略.........
开发者ID:dbremner,项目名称:specsharp,代码行数:101,代码来源:Resolver.cs
示例17: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding memberBinding){
if (memberBinding == null) return null;
Member member = memberBinding.BoundMember;
if (member == null) return memberBinding;
Method method = member as Method;
if (method != null && method.Template != null && memberBinding.BoundMemberExpression is TemplateInstance){
this.VisitResolvedReference(method, ((TemplateInstance)memberBinding.BoundMemberExpression).Expression);
TypeNodeList templateArguments = ((TemplateInstance)memberBinding.BoundMemberExpression).TypeArgumentExpressions;
this.VisitResolvedTypeReferenceList(method.TemplateArguments, templateArguments);
}else
this.VisitResolvedReference(memberBinding.BoundMember, memberBinding.BoundMemberExpression);
return base.VisitMemberBinding(memberBinding);
}
开发者ID:dbremner,项目名称:specsharp,代码行数:13,代码来源:Resolver.cs
示例18: OnInvalidMemberBinding
public virtual Expression OnInvalidMemberBinding(MemberBinding mb, QualifiedIdentifier qualId){
return mb;
}
开发者ID:dbremner,项目名称:specsharp,代码行数:3,代码来源:Resolver.cs
示例19: VisitMemberBinding
public virtual Expression VisitMemberBinding (MemberBinding node)
{
if (node == null)
return null;
node.TargetObject = VisitExpression (node.TargetObject);
return node;
}
开发者ID:carrie901,项目名称:mono,代码行数:9,代码来源:DefaultNodeVisitor.cs
示例20: VisitTypeNode
//.........这里部分代码省略.........
{
//typeNode defines a modelfield (i.e., implementingMember) that can implement mfCToImplement
Debug.Assert(typeNode.Contract != null); //a class that defines a modelfield must have a modelfieldcontract that applies to it.
foreach (ModelfieldContract mfC in typeNode.Contract.ModelfieldContracts)
if (mfC.Modelfield == implementingMember)
{
mfCThatImplements = mfC;
break;
}
Debug.Assert(mfCThatImplements != null);
}
#endregion
#region if there is no implementingMember: add a new modelfield + contract to typeNode and store contract in mfCThatImplements
//TODO: Unfortunately, qualified identifiers have already been resolved: currently references to the modelfield will produce an error.
if (implementingMember == null)
{
Identifier mfIdent = new Identifier(mfCToImplement.Modelfield.Name.Name);
mfCThatImplements = new ModelfieldContract(typeNode, new AttributeList(), mfCToImplement.ModelfieldType, mfIdent, typeNode.SourceContext);
Field mf = (mfCThatImplements.Modelfield as Field);
mf.SourceContext = mfCToImplement.SourceContext; //the modelfield does not appear in the code but implements mfCToImplement.
typeNode.Members.Add(mf);
if (typeNode.Contract == null)
typeNode.Contract = new TypeContract(typeNode);
typeNode.Contract.ModelfieldContracts.Add(mfCThatImplements);
}
#endregion
#region Implement the property and property getter that represent mfCToImplement, let getter return mfCThatImplements.Modelfield
//assert typeNode.Contract.ModelfieldContracts.Contains(mfCThatImplements);
//create Property:
// public <mfCThatImplements.ModelfieldType> <mfCThatImplements.Modelfield.Name>
// ensures result == <mfCThatImplements.Modelfield>;
// { [Confined] get { return <mfCThatImplements.Modelfield>; } }
// Note that getter needs to be confined because it inherits NoDefaultContract
MemberBinding thisMf = new MemberBinding(new This(typeNode), mfCThatImplements.Modelfield);
Statement ret = new Return(thisMf);
Method getter = new Method(typeNode, new AttributeList(), (mfCToImplement.Modelfield as Property).Getter.Name, new ParameterList(), mfCThatImplements.ModelfieldType, new Block(new StatementList(ret)));
getter.Flags = MethodFlags.Public;
getter.CallingConvention = CallingConventionFlags.HasThis;
if (getter.Contract == null)
{
getter.Contract = new MethodContract(getter);
}
Expression resultOfGet = new ReturnValue(getter.ReturnType, mfCToImplement.SourceContext);
BinaryExpression b = new BinaryExpression(resultOfGet, thisMf, NodeType.Eq, mfCToImplement.SourceContext);
b.Type = SystemTypes.Boolean;
//Give getter Confined (as it has NoDefaultContract)
// That means make it [Pure][Reads(Reads.Owned)]
InstanceInitializer pCtor = SystemTypes.PureAttribute.GetConstructor();
if (pCtor != null)
getter.Attributes.Add(new AttributeNode(new MemberBinding(null, pCtor), null, AttributeTargets.Method));
InstanceInitializer rCtor = SystemTypes.ReadsAttribute.GetConstructor(); // can use nullary ctor since default is confined
if (rCtor != null)
getter.Attributes.Add(new AttributeNode(new MemberBinding(null, rCtor), null, AttributeTargets.Method));
getter.Contract.Ensures.Add(new EnsuresNormal(b));
Identifier implPropName = new Identifier(mfCToImplement.Modelfield.FullName, mfCToImplement.SourceContext); //use full name as typeNode might define modelfield with this name itself.
Property implementingProperty = new Property(typeNode, new AttributeList(), PropertyFlags.None, implPropName, getter, null);
typeNode.Members.Add(implementingProperty);
typeNode.Members.Add(getter);
#endregion
#region Copy the info from mfCToImplement to typeNode's mfCThatImplements
foreach (Expression satClause in mfCToImplement.SatisfiesList)
mfCThatImplements.SatisfiesList.Add(satClause);
//Don't copy the explicit witness from the implemented contract: can likely infer a better one.
#endregion
}
开发者ID:hesam,项目名称:SketchSharp,代码行数:67,代码来源:Checker.cs
注:本文中的MemberBinding类示例整理自Gith |
请发表评论