Ejemplo n.º 1
0
        public override IRppNode Analyze(SymbolTable scope, Diagnostic diagnostic)
        {
            if (TargetType == null)
            {
                throw new Exception("TargetType should be specified before anaylyze is called");
            }

            RType classType = TargetType;
            // TODO It's kinda weird to have resolution here and not in the scope, because similar
            // lookup is done for methods
            while (classType != null && Field == null)
            {
                Field = classType.Fields.FirstOrDefault(f => f.Name == Name);
                if (Field != null)
                {
                    break;
                }

                classType = classType.BaseType;
            }

            if (Field == null)
            {
                var functions = scope.LookupFunction(Name);
                if (functions.Any(f => f.Parameters.IsEmpty()))
                {
                    RppFuncCall funcCall = new RppFuncCall(Name, Collections.NoExprs);
                    return funcCall.Analyze(scope, diagnostic);
                }

                throw SemanticExceptionFactory.ValueIsNotMember(Token, TargetType.ToString());
            }

            Debug.Assert(classType != null, "obj != null");

            Type = new ResolvableType(Field.Type);

            return this;
        }
Ejemplo n.º 2
0
 private RppFieldInfo InflateField(RppFieldInfo field)
 {
     return new RppInflatedField(field, _genericArguments, this);
 }
Ejemplo n.º 3
0
 public RppInflatedField(RppFieldInfo genericFieldDefinition, RType[] genericArguments, RType declaringType)
     : base(genericFieldDefinition.Name, genericFieldDefinition.Type, genericFieldDefinition.Attributes, declaringType)
 {
     GenericFieldDefinition = genericFieldDefinition;
     _genericArguments = genericArguments;
 }
Ejemplo n.º 4
0
        private void LoadField(RppFieldInfo field)
        {
            if (!_inSelector)
            {
                _body.Emit(OpCodes.Ldarg_0);
                if (ClosureContext?.CapturedThis != null)
                {
                    _body.Emit(OpCodes.Ldfld, ClosureContext.CapturedThis);
                }
            }

            if (IsInsideGetterOrSetter(field.Name))
            {
                _body.Emit(OpCodes.Ldfld, field.Native);
            }
            else
            {
                _body.Emit(OpCodes.Callvirt, field.NativeGetter);
            }
        }
Ejemplo n.º 5
0
 private static RppSelector CallSetter(IRppExpr target, RppFieldInfo field, IRppExpr value)
 {
     return new RppSelector(target, new RppFuncCall(field.SetterName, List(value)));
 }
Ejemplo n.º 6
0
 private bool Equals(RppFieldInfo other)
 {
     return String.Equals(Name, other.Name) && Attributes == other.Attributes && Type.Equals(other.Type)
            && DeclaringType.Equals(other.DeclaringType);
 }
Ejemplo n.º 7
0
        private void CreateProperty(RppFieldInfo field, IEnumerable<RppMethodInfo> methods)
        {
            Debug.Assert(_typeBuilder != null, "_typeBuilder != null");

            PropertyBuilder propertyBuilder = _typeBuilder.DefineProperty(field.Name, PropertyAttributes.None, field.Type.NativeType, null);
            propertyBuilder.SetCustomAttribute(RTypeUtils.CreateCompilerGeneratedAttribute());

            // TODO we need to update visibility somehow
            FieldBuilder fieldBuilder = _typeBuilder.DefineField(field.MangledName, field.Type.NativeType, FieldAttributes.Public);
            fieldBuilder.SetCustomAttribute(RTypeUtils.CreateCompilerGeneratedAttribute());

            SetAccessors(propertyBuilder, methods);

            field.Native = fieldBuilder;
            field.NativeProperty = propertyBuilder;
        }
Ejemplo n.º 8
0
 public RppFieldInfo DefineField([NotNull] string name, [NotNull] RType type, RFieldAttributes attributes)
 {
     RppFieldInfo field = new RppFieldInfo(name, type, attributes, this);
     _fields.Add(field);
     return field;
 }
Ejemplo n.º 9
0
        private static RppFieldInfo Convert(FieldInfo field, RType declaringType)
        {
            RType fieldType = GetOrCreateType(field.FieldType.Name, field.FieldType);
            bool priv = (field.Attributes & FieldAttributes.Private) != 0;
            RFieldAttributes attr = priv ? RFieldAttributes.Private : RFieldAttributes.Public;
            RppFieldInfo rppField = new RppFieldInfo(field.Name, fieldType, attr, declaringType)
            {
                Native = field
            };

            return rppField;
        }
Ejemplo n.º 10
0
        private static RppFieldInfo Convert(PropertyInfo property, RType declaringType)
        {
            RType fieldType = GetOrCreateType(property.PropertyType.Name, property.PropertyType);
            const RFieldAttributes attr = RFieldAttributes.Public;
            RppFieldInfo rppField = new RppFieldInfo(property.Name, fieldType, attr, declaringType)
            {
                NativeProperty = property
            };

            return rppField;
        }
Ejemplo n.º 11
0
 private EmptyTypeDefinition()
 {
     TypeParameters = new RppTypeParameterInfo[0];
     Constructors = new RppMethodInfo[0];
     Fields = new RppFieldInfo[0];
     Methods = new RppMethodInfo[0];
 }