Exemple #1
0
 private JST.Expression ReflectionNamespaceExpression(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv)
 {
     var nm = innerTypeCompEnv.Type.EffectiveName(Env.Global);
     var lit = nm.Namespace.Length == 0
                   ? (JST.Expression)new JST.NullExpression()
                   : (JST.Expression)new JST.StringLiteral(nm.Namespace);
     if (innerTypeCompEnv.Type.Arity == 0)
         return lit;
     else
     {
         return JST.Expression.DotCall
             (RootId.ToE(),
              Constants.RootReflectionNamespace,
              lit,
              new JST.ArrayLiteral
                  (innerTypeCompEnv.TypeBoundArguments.Select(t => innerTypeCompEnv.ResolveType(t, TypePhase.Id)).ToSeq()));
     }
 }
Exemple #2
0
 private JST.Expression ReflectionNameExpression(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, bool isFullName)
 {
     var nm = CST.CSTWriter.WithAppend
         (Env.Global,
          isFullName ? CST.WriterStyle.ReflectionFullName : CST.WriterStyle.ReflectionName,
          innerTypeCompEnv.Type.EffectiveName(Env.Global).Append);
     var lit = new JST.StringLiteral(nm);
     if (innerTypeCompEnv.Type.Arity == 0)
         return lit;
     else
     {
         return JST.Expression.DotCall
             (RootId.ToE(),
              Constants.RootReflectionName,
              lit,
              new JST.ArrayLiteral
                  (innerTypeCompEnv.TypeBoundArguments.Select(t => innerTypeCompEnv.ResolveType(t, TypePhase.Id)).ToSeq()),
              new JST.BooleanLiteral(isFullName));
     }
 }
Exemple #3
0
 private JST.Expression EventInfoFromEvent(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, Map<CST.MethodSignature, JST.Identifier> sharedMethodInfos, CST.EventDef eventDef)
 {
     var slot = Env.GlobalMapping.ResolveEventDefToSlot(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, eventDef);
     var slotExp = new JST.StringLiteral(Constants.ObjectEventSlot(slot));
     return JST.Expression.DotCall
         (RootId.ToE(),
          Constants.RootReflectionEventInfo,
          slotExp,
          TypeId.ToE(),
          new JST.BooleanLiteral(eventDef.IsStatic),
          new JST.BooleanLiteral(!eventDef.IsStatic),
          new JST.StringLiteral(eventDef.Name),
          CustomAttributesExpression
              (body, innerTypeCompEnv,
               CST.MessageContextBuilders.Member(Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, eventDef),
               eventDef.CustomAttributes),
          innerTypeCompEnv.ResolveType(eventDef.HandlerType, TypePhase.Constructed),
          eventDef.Add == null || !sharedMethodInfos.ContainsKey(eventDef.Add)
              ? (JST.Expression)new JST.NullExpression()
              : sharedMethodInfos[eventDef.Add].ToE(),
          eventDef.Remove == null || !sharedMethodInfos.ContainsKey(eventDef.Remove)
              ? (JST.Expression)new JST.NullExpression()
              : sharedMethodInfos[eventDef.Remove].ToE());
 }
Exemple #4
0
 private JST.Expression PropertyInfoFromProperty(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, Map<CST.MethodSignature, JST.Identifier> sharedMethodInfos, CST.PropertyDef propDef)
 {
     var slot = Env.GlobalMapping.ResolvePropertyDefToSlot(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, propDef);
     var slotExp = new JST.StringLiteral(Constants.ObjectPropertySlot(slot));
     return JST.Expression.DotCall
         (RootId.ToE(),
          Constants.RootReflectionPropertyInfo,
          slotExp,
          TypeId.ToE(),
          new JST.BooleanLiteral(propDef.IsStatic),
          new JST.BooleanLiteral(!propDef.IsStatic),
          new JST.StringLiteral(propDef.Name),
          CustomAttributesExpression
              (body, innerTypeCompEnv,
               CST.MessageContextBuilders.Member(Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, propDef),
               propDef.CustomAttributes),
          innerTypeCompEnv.ResolveType(propDef.FieldType, TypePhase.Constructed),
          propDef.Get == null || !sharedMethodInfos.ContainsKey(propDef.Get) ? (JST.Expression)new JST.NullExpression() : sharedMethodInfos[propDef.Get].ToE(),
          propDef.Set == null || !sharedMethodInfos.ContainsKey(propDef.Set) ? (JST.Expression)new JST.NullExpression() : sharedMethodInfos[propDef.Set].ToE());
 }
Exemple #5
0
        private JST.Expression FieldInfoFromField(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, CST.FieldDef fieldDef)
        {
            if (Env.AttributeHelper.FieldHasAttribute
                (innerTypeCompEnv.Assembly,
                 innerTypeCompEnv.Type,
                 fieldDef,
                 Env.Global.CompilerGeneratedAttributeRef,
                 false,
                 false))
                // Ignore compiler-generate fields
                return null;

            var slot = Env.GlobalMapping.ResolveFieldDefToSlot
                (innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, fieldDef);
            return JST.Expression.DotCall
                (RootId.ToE(),
                 Constants.RootReflectionFieldInfo,
                 new JST.StringLiteral(slot),
                 TypeId.ToE(),
                 new JST.BooleanLiteral(fieldDef.IsStatic),
                 new JST.BooleanLiteral(!fieldDef.IsStatic),
                 new JST.StringLiteral(fieldDef.Name),
                 CustomAttributesExpression
                     (body,
                      innerTypeCompEnv,
                      CST.MessageContextBuilders.Member
                          (Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, fieldDef),
                      fieldDef.CustomAttributes),
                 innerTypeCompEnv.ResolveType(fieldDef.FieldType, TypePhase.Constructed),
                 new JST.NullExpression());
        }
Exemple #6
0
        private JST.Expression MethodInfoFromMethod(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, CST.MethodDef methodDef)
        {
            if (methodDef.TypeArity > 0)
                // TODO: polymorphic methods
                return null;

            if (methodDef.Invalid != null || !methodDef.IsUsed ||
                Env.InlinedMethods.IsInlinable(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, methodDef))
                // This is possible if method is a getter/setter/adder/removed for a used property
                // or event but the method itself is unused or inlined.
                return null;

            if (methodDef.IsOverriding)
                // MethodInfo will have been supplied by supertype
                return null;

            var slot = Env.GlobalMapping.ResolveMethodDefToSlot(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, methodDef);
            var attrs = CustomAttributesExpression
                (body,
                 innerTypeCompEnv,
                 CST.MessageContextBuilders.Member
                     (Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, methodDef),
                 methodDef.CustomAttributes);
            var paramTypes = new JST.ArrayLiteral
                (methodDef.ValueParameters.Skip(methodDef.IsStatic ? 0 : 1).Select
                     (p => innerTypeCompEnv.ResolveType(p.Type, TypePhase.Constructed)).ToSeq());
            if (methodDef.IsConstructor)
                return JST.Expression.DotCall
                    (RootId.ToE(),
                     Constants.RootReflectionConstructorInfo,
                     new JST.StringLiteral(slot),
                     TypeId.ToE(),
                     new JST.BooleanLiteral(!methodDef.IsStatic),
                     attrs,
                     paramTypes);
            else
                return JST.Expression.DotCall
                    (RootId.ToE(),
                     Constants.RootReflectionMethodInfo,
                     new JST.StringLiteral(slot),
                     TypeId.ToE(),
                     new JST.BooleanLiteral(methodDef.IsStatic),
                     new JST.BooleanLiteral(!methodDef.IsStatic),
                     new JST.StringLiteral(methodDef.Name),
                     attrs,
                     new JST.BooleanLiteral(methodDef.IsVirtualOrAbstract),
                     paramTypes,
                     new JST.BooleanLiteral(true),
                     methodDef.Result == null
                         ? (JST.Expression)new JST.NullExpression()
                         : innerTypeCompEnv.ResolveType(methodDef.Result.Type, TypePhase.Constructed));
        }