本文整理汇总了C#中Mono.CSharp.ToplevelBlock.GetParameterReference方法的典型用法代码示例。如果您正苦于以下问题:C# ToplevelBlock.GetParameterReference方法的具体用法?C# ToplevelBlock.GetParameterReference怎么用?C# ToplevelBlock.GetParameterReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.ToplevelBlock
的用法示例。
在下文中一共展示了ToplevelBlock.GetParameterReference方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoDefineMembers
//.........这里部分代码省略.........
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc),
field_to_string));
continue;
}
//
// Implementation of ToString () body using string concatenation
//
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)),
field_to_string);
rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
}
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (Compiler.BuiltinTypes, " }", loc));
//
// Equals (object obj) override
//
var other_variable_assign = new TemporaryVariableReference (li_other, loc);
equals_block.AddStatement (new StatementExpression (
new SimpleAssign (other_variable_assign,
new As (equals_block.GetParameterReference (0, loc),
current_type, loc), loc)));
Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc));
if (rs_equals != null)
equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals);
equals_block.AddStatement (new Return (equals_test, loc));
equals.Block = equals_block;
equals.Define ();
Members.Add (equals);
//
// GetHashCode () override
//
Method hashcode = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Int, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("GetHashCode", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
//
// Modified FNV with good avalanche behavior and uniform
// distribution with larger hash sizes.
//
// const int FNV_prime = 16777619;
// int hash = (int) 2166136261;
// foreach (int d in data)
// hash = (hash ^ d) * FNV_prime;
// hash += hash << 13;
// hash ^= hash >> 7;
// hash += hash << 3;
// hash ^= hash >> 17;
// hash += hash << 5;
示例2: Emit
public override void Emit (DeclSpace parent)
{
if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0) {
if (parent is Class) {
MethodBuilder mb = method_data.MethodBuilder;
mb.SetImplementationFlags (mb.GetMethodImplementationFlags () | MethodImplAttributes.Synchronized);
}
var field_info = ((EventField) method).backing_field;
FieldExpr f_expr = new FieldExpr (field_info, Location);
if ((method.ModFlags & Modifiers.STATIC) == 0)
f_expr.InstanceExpression = new CompilerGeneratedThis (field_info.Spec.MemberType, Location);
block = new ToplevelBlock (Compiler, ParameterInfo, Location);
block.AddStatement (new StatementExpression (
new CompoundAssign (Operation,
f_expr,
block.GetParameterReference (ParameterInfo[0].Name, Location),
Location)));
}
base.Emit (parent);
}
示例3: DefineOverrides
void DefineOverrides ()
{
Location loc = Location;
Method equals = new Method (this, null, TypeManager.system_boolean_expr,
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
Mono.CSharp.ParametersCompiled.CreateFullyResolved (new Parameter (null, "obj", 0, null, loc), TypeManager.object_type), null);
Method tostring = new Method (this, null, TypeManager.system_string_expr,
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.Parameters, loc);
TypeExpr current_type;
if (IsGeneric)
current_type = new GenericTypeExpr (this, loc);
else
current_type = new TypeExpression (TypeBuilder, loc);
equals_block.AddVariable (current_type, "other", loc);
LocalVariableReference other_variable = new LocalVariableReference (equals_block, "other", loc);
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);
Expression rs_equals = null;
Expression string_concat = new StringConstant ("{", loc);
Expression rs_hashcode = new IntConstant (-2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
Field f = (Field) Fields [i];
MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
system_collections_generic, "EqualityComparer",
new TypeArguments (new SimpleName (TypeParameters [i].Name, loc)), loc),
"Default", loc);
Arguments arguments_equal = new Arguments (2);
arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name)));
Expression field_equal = new Invocation (new MemberAccess (equality_comparer,
"Equals", loc), arguments_equal);
Arguments arguments_hashcode = new Arguments (1);
arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name)));
Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
"GetHashCode", loc), arguments_hashcode);
IntConstant FNV_prime = new IntConstant (16777619, loc);
rs_hashcode = new Binary (Binary.Operator.Multiply,
new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode),
FNV_prime);
Expression field_to_string = new Conditional (new Binary (Binary.Operator.Inequality,
new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc)),
new Invocation (new MemberAccess (
new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
new StringConstant (string.Empty, loc));
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
new StringConstant (" " + p.Name + " = ", loc),
field_to_string));
continue;
}
//
// Implementation of ToString () body using string concatenation
//
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (", " + p.Name + " = ", loc)),
field_to_string);
rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal);
}
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new StringConstant (" }", loc));
//
// Equals (object obj) override
//
LocalVariableReference other_variable_assign = new LocalVariableReference (equals_block, "other", loc);
equals_block.AddStatement (new StatementExpression (
new SimpleAssign (other_variable_assign,
new As (equals_block.GetParameterReference ("obj", loc),
current_type, loc), loc)));
Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc));
if (rs_equals != null)
equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals);
equals_block.AddStatement (new Return (equals_test, loc));
//.........这里部分代码省略.........
示例4: GenerateNumberMatcher
Method GenerateNumberMatcher ()
{
var loc = Location;
var parameters = ParametersCompiled.CreateFullyResolved (
new [] {
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc),
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "value", 0, null, loc),
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Bool, loc), "enumType", 0, null, loc),
},
new [] {
Compiler.BuiltinTypes.Object,
Compiler.BuiltinTypes.Object,
Compiler.BuiltinTypes.Bool
});
var m = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
Modifiers.PUBLIC | Modifiers.STATIC | Modifiers.DEBUGGER_HIDDEN, new MemberName ("NumberMatcher", loc),
parameters, null);
parameters [0].Resolve (m, 0);
parameters [1].Resolve (m, 1);
parameters [2].Resolve (m, 2);
ToplevelBlock top_block = new ToplevelBlock (Compiler, parameters, loc);
m.Block = top_block;
//
// if (enumType)
// return Equals (obj, value);
//
var equals_args = new Arguments (2);
equals_args.Add (new Argument (top_block.GetParameterReference (0, loc)));
equals_args.Add (new Argument (top_block.GetParameterReference (1, loc)));
var if_type = new If (
top_block.GetParameterReference (2, loc),
new Return (new Invocation (new SimpleName ("Equals", loc), equals_args), loc),
loc);
top_block.AddStatement (if_type);
//
// if (obj is Enum || obj == null)
// return false;
//
var if_enum = new If (
new Binary (Binary.Operator.LogicalOr,
new Is (top_block.GetParameterReference (0, loc), new TypeExpression (Compiler.BuiltinTypes.Enum, loc), loc),
new Binary (Binary.Operator.Equality, top_block.GetParameterReference (0, loc), new NullLiteral (loc))),
new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc),
loc);
top_block.AddStatement (if_enum);
var system_convert = new MemberAccess (new QualifiedAliasMember ("global", "System", loc), "Convert", loc);
var expl_block = new ExplicitBlock (top_block, loc, loc);
//
// var converted = System.Convert.ChangeType (obj, System.Convert.GetTypeCode (value));
//
var lv_converted = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Object, top_block, loc);
var arguments_gettypecode = new Arguments (1);
arguments_gettypecode.Add (new Argument (top_block.GetParameterReference (1, loc)));
var gettypecode = new Invocation (new MemberAccess (system_convert, "GetTypeCode", loc), arguments_gettypecode);
var arguments_changetype = new Arguments (1);
arguments_changetype.Add (new Argument (top_block.GetParameterReference (0, loc)));
arguments_changetype.Add (new Argument (gettypecode));
var changetype = new Invocation (new MemberAccess (system_convert, "ChangeType", loc), arguments_changetype);
expl_block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (lv_converted, loc), changetype, loc)));
//
// return converted.Equals (value)
//
var equals_arguments = new Arguments (1);
equals_arguments.Add (new Argument (top_block.GetParameterReference (1, loc)));
var equals_invocation = new Invocation (new MemberAccess (new LocalVariableReference (lv_converted, loc), "Equals"), equals_arguments);
expl_block.AddStatement (new Return (equals_invocation, loc));
var catch_block = new ExplicitBlock (top_block, loc, loc);
catch_block.AddStatement (new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc));
top_block.AddStatement (new TryCatch (expl_block, new List<Catch> () {
new Catch (catch_block, loc)
}, loc, false));
m.Define ();
m.PrepareEmit ();
AddMember (m);
return m;
}
示例5: CheckParentConflictName
protected virtual bool CheckParentConflictName (ToplevelBlock block, string name, Location l)
{
LocalInfo vi = GetLocalInfo (name);
if (vi != null) {
Report.SymbolRelatedToPreviousError (vi.Location, name);
if (Explicit == vi.Block.Explicit) {
Error_AlreadyDeclared (l, name, null);
} else {
Error_AlreadyDeclared (l, name, this is ToplevelBlock ?
"parent or current" : "parent");
}
return false;
}
if (block != null) {
Expression e = block.GetParameterReference (name, Location.Null);
if (e != null) {
ParameterReference pr = e as ParameterReference;
if (this is Linq.QueryBlock && (pr != null && pr.Parameter is Linq.QueryBlock.ImplicitQueryParameter || e is MemberAccess))
Error_AlreadyDeclared (loc, name);
else
Error_AlreadyDeclared (loc, name, "parent or current");
return false;
}
}
return true;
}