本文整理汇总了C#中Boo.Lang.Compiler.Ast.Field类的典型用法代码示例。如果您正苦于以下问题:C# Field类的具体用法?C# Field怎么用?C# Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Field类属于Boo.Lang.Compiler.Ast命名空间,在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateViewStateSlice
Expression CreateViewStateSlice(Field f)
{
// ViewState["<f.Name>"]
return new SlicingExpression(
new ReferenceExpression("ViewState"),
new StringLiteralExpression(f.Name));
}
示例2: LeaveField
public override void LeaveField(Field node)
{
if (!node.IsVisibilitySet)
{
node.Modifiers |= TypeMemberModifiers.Protected;
}
}
示例3: CreateGetter
Method CreateGetter(Field f)
{
Method m = new Method();
m.Name = "get";
// value = ViewState["<f.Name>"]
m.Body.Statements.Add(
new ExpressionStatement(
new BinaryExpression(
BinaryOperatorType.Assign,
new ReferenceExpression("value"),
CreateViewStateSlice(f)
)
)
);
if (null != _default)
{
// return <_default> unless value
ReturnStatement rs = new ReturnStatement(_default);
rs.Modifier = new StatementModifier(StatementModifierType.Unless, new ReferenceExpression("value"));
m.Body.Statements.Add(rs);
}
// return value
m.Body.Statements.Add(
new ReturnStatement(
new ReferenceExpression("value")
)
);
return m;
}
示例4: OnField
public override void OnField(Field node)
{
if (this.LookingFor(node))
{
this.Found(node.Type);
}
}
示例5: OnField
public override void OnField(Field node)
{
if (node.Type != null) {
TypeReference initializerType = GetInferredType(node.Initializer);
if (node.Type.Matches(initializerType)) {
node.Type = null;
}
}
base.OnField(node);
}
示例6: OnField
override public void OnField(Field node)
{
if (null == node.Entity)
{
node.Entity = new InternalField(node);
if (!node.IsVisible && !node.IsSynthetic)
{
node.Annotate(PrivateMemberNeverUsed, null);
}
}
}
示例7: CreateSetter
Method CreateSetter(Field f)
{
Method m = new Method();
m.Name = "set";
m.Body.Statements.Add(
new ExpressionStatement(
new BinaryExpression(
BinaryOperatorType.Assign,
CreateViewStateSlice(f),
new ReferenceExpression("value")
)
)
);
return m;
}
示例8: LeaveField
public override void LeaveField(Field node)
{
if (!node.IsVisibilitySet)
{
node.Visibility = Context.Parameters.DefaultFieldVisibility;
//protected field in a sealed type == private,
//so let the compiler mark them private automatically in order to get
//unused members warnings for free (and to make IL analysis tools happy as a bonus)
if (node.IsProtected && node.DeclaringType.IsFinal)
node.Visibility = TypeMemberModifiers.Private;
}
LeaveMember(node);
}
示例9: ExtendBaseClass
/// <summary>
/// Extends the base class by placing the blocks of macros into methods on the base class
/// of the same name.
/// </summary>
/// <example>
/// MyMethod:
/// PerformActions
///
/// If an overridable method called MyMethod exists on <see cref="BaseClassCompilerStep.BaseClass"/>, then
/// it is overridden as follows:
/// <code>
/// public override void MyMethod() { PerformActions(); }
/// </code>
/// </example>
protected override void ExtendBaseClass(Module module, ClassDefinition definition)
{
List<MethodInfo> methodsThatAreOverridable = new List<MethodInfo>();
MethodInfo[] baseClassMethods =
BaseClass.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.InvokeMethod);
foreach (MethodInfo method in baseClassMethods)
{
if(method.DeclaringType==typeof(object))
continue;
if (method.IsVirtual || method.IsAbstract)
methodsThatAreOverridable.Add(method);
}
MethodSubstitutionTransformer mst = new MethodSubstitutionTransformer(methodsThatAreOverridable.ToArray(), definition);
mst.Visit(module);
foreach (Statement statement in module.Globals.Statements)
{
ExpressionStatement es = statement as ExpressionStatement;
if (es != null)
{
BinaryExpression be = es.Expression as BinaryExpression;
if (be != null)
{
if (be.Left.NodeType == NodeType.ReferenceExpression && be.Operator == BinaryOperatorType.Assign)
{
ReferenceExpression refExp = be.Left as ReferenceExpression;
Field field = new Field(refExp.LexicalInfo);
field.Name = refExp.Name;
field.Initializer = be.Right;
definition.Members.Add(field);
}
}
}
}
if (transformers != null)
{
foreach (DepthFirstTransformer transformer in transformers)
transformer.Visit(module);
}
}
示例10: ConvertField
void ConvertField(TypeReference typeRef, VariableDeclaration variable, FieldDeclaration fieldDeclaration)
{
B.TypeMember m;
if (currentType is B.EnumDefinition) {
if (variable.Initializer.IsNull) {
m = new B.EnumMember(GetLexicalInfo(fieldDeclaration));
} else {
PrimitiveExpression p = variable.Initializer as PrimitiveExpression;
if (p == null || !(p.Value is int)) {
AddError(fieldDeclaration, "enum member initializer must be integer value");
return;
}
m = new B.EnumMember(GetLexicalInfo(fieldDeclaration), new B.IntegerLiteralExpression((int)p.Value));
}
} else {
m = new B.Field(GetLexicalInfo(fieldDeclaration), ConvertTypeReference(typeRef), ConvertExpression(variable.Initializer));
m.Modifiers = ConvertModifier(fieldDeclaration, B.TypeMemberModifiers.Private);
}
m.Name = variable.Name;
ConvertAttributes(fieldDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
}
示例11: ProcessLiteralField
void ProcessLiteralField(Field node)
{
Visit(node.Initializer);
ProcessFieldInitializerType(node, node.Initializer.ExpressionType);
((InternalField)node.Entity).StaticValue = node.Initializer;
node.Initializer = null;
}
示例12: ProcessFieldInitializerType
void ProcessFieldInitializerType(Field node, IType initializerType)
{
if (null == node.Type)
node.Type = CreateTypeReference(node.LexicalInfo, MapNullToObject(initializerType));
else
AssertTypeCompatibility(node.Initializer, GetType(node.Type), initializerType);
}
示例13: ProcessFieldInitializer
void ProcessFieldInitializer(Field node)
{
Expression initializer = node.Initializer;
if (null == initializer) return;
//do not unnecessarily assign fields to default values
switch (initializer.NodeType)
{
case NodeType.NullLiteralExpression:
node.Initializer = null;
return;
case NodeType.IntegerLiteralExpression:
if (0 == ((IntegerLiteralExpression) initializer).Value) {
node.Initializer = null;
return;
}
break;
case NodeType.BoolLiteralExpression:
if (false == ((BoolLiteralExpression) initializer).Value) {
node.Initializer = null;
return;
}
break;
case NodeType.DoubleLiteralExpression:
if (0.0f == ((DoubleLiteralExpression) initializer).Value) {
node.Initializer = null;
return;
}
break;
}
Method method = GetInitializerMethod(node);
method.Body.Add(
CodeBuilder.CreateAssignment(
initializer.LexicalInfo,
CodeBuilder.CreateReference(node),
initializer));
node.Initializer = null;
}
示例14: PreProcessFieldInitializer
private void PreProcessFieldInitializer(Field node)
{
Expression initializer = node.Initializer;
if (node.IsFinal && node.IsStatic)
{
if (IsValidLiteralInitializer(initializer))
{
ProcessLiteralField(node);
return;
}
}
BlockExpression closure = node.Initializer as BlockExpression;
if (closure != null)
{
InferClosureSignature(closure);
}
Method method = GetInitializerMethod(node);
InternalMethod entity = (InternalMethod)method.Entity;
ReferenceExpression temp = new ReferenceExpression(TempInitializerName);
BinaryExpression assignment = new BinaryExpression(
node.LexicalInfo,
BinaryOperatorType.Assign,
temp,
initializer);
ProcessNodeInMethodContext(entity, entity, assignment);
method.Locals.RemoveByEntity(temp.Entity);
IType initializerType = GetExpressionType(assignment.Right);
ProcessFieldInitializerType(node, initializerType);
node.Initializer = assignment.Right;
}
示例15: GetInitializerMethod
Method GetInitializerMethod(Field node)
{
return GetInitializerFor(node.DeclaringType, node.IsStatic);
}