public SwitchCase(TypeContainer elemType, string elemName, object[] discriminatorValues, 
                   FieldBuilder elemField) {
     m_elemType = elemType;
     m_elemName = elemName;
     m_elemField = elemField;
     m_discriminatorValues = discriminatorValues;
 }
Example #2
0
        /// <summary>
        /// reefines a prameter; not possible for return parameter, ...? TODO: refact ...
        /// </summary>
        /// <param name="methodBuild"></param>
        /// <param name="spec"></param>
        /// <param name="paramNr"></param>
        private void DefineParameter(MethodBuilder methodBuild, ParameterSpec spec, int paramNr)
        {
            ParameterAttributes paramAttr = ParameterAttributes.None;

            if (spec.IsOut())
            {
                paramAttr = paramAttr | ParameterAttributes.Out;
            }
            ParameterBuilder paramBuild = methodBuild.DefineParameter(paramNr, paramAttr, spec.GetPramName());
            // custom attribute spec
            TypeContainer specType = spec.GetParamType();

            for (int i = 0; i < specType.GetSeparatedAttrs().Length; i++)
            {
                paramBuild.SetCustomAttribute(specType.GetSeparatedAttrs()[i]);
            }
        }
Example #3
0
        private MethodBuilder AddPropertyGetterInternal(TypeBuilder builder, string propertyName,
                                                        string forIdlGetterName,
                                                        TypeContainer propertyType, MethodAttributes attrs)
        {
            Type          propTypeCls = propertyType.GetSeparatedClsType();
            MethodBuilder getAccessor = builder.DefineMethod("get_" + propertyName,
                                                             attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                                                             propTypeCls, System.Type.EmptyTypes);

            ParameterBuilder retParamGet = CreateParamBuilderForRetParam(getAccessor);

            // add custom attributes
            for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++)
            {
                retParamGet.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
            }
            if (forIdlGetterName != null)
            {
                AddFromIdlNameAttribute(getAccessor, forIdlGetterName);
            }
            return(getAccessor);
        }
Example #4
0
        /// <summary>creates a ParameterSpec for a ParameterInfo</summary>
        public ParameterSpec(ParameterInfo forParamInfo)
        {
            if (forParamInfo.IsOut)
            {
                m_direction = ParameterDirection.s_out;
            }
            else if (forParamInfo.ParameterType.IsByRef)
            {
                m_direction = ParameterDirection.s_inout;
            }
            else
            {
                m_direction = ParameterDirection.s_in;
            }
            m_paramName = forParamInfo.Name;

            // custom attributes
            System.Object[] attrs = forParamInfo.GetCustomAttributes(false);
            m_paramType = new TypeContainer(forParamInfo.ParameterType,
                                            AttributeExtCollection.
                                            ConvertToAttributeCollection(attrs),
                                            true);
        }
Example #5
0
        /// <summary>
        /// adds a property to a type, including the custom attributes needed.
        /// </summary>
        public PropertyBuilder AddProperty(TypeBuilder builder, string propertyName,
                                           TypeContainer propertyType,
                                           MethodBuilder getAccessor, MethodBuilder setAccessor)
        {
            Type            propTypeCls = propertyType.GetSeparatedClsType();
            PropertyBuilder propBuild   = builder.DefineProperty(propertyName, PropertyAttributes.None,
                                                                 propTypeCls, System.Type.EmptyTypes);

            // add accessor methods
            if (getAccessor != null)
            {
                propBuild.SetGetMethod(getAccessor);
            }
            if (setAccessor != null)
            {
                propBuild.SetSetMethod(setAccessor);
            }
            // define custom attributes
            for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++)
            {
                propBuild.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
            }
            return(propBuild);
        }
 /// <summary>
 /// Like <see cref="Ch.Elca.Iiop.Idl.IlEmitHelper.AddProperty(TypeBuilder, string, TypeContainer, MethodBuilder, MethodBuilder)"/>,
 /// but adds additionally a FromIdlName attribute to the property
 /// </summary>
 public PropertyBuilder AddProperty(TypeBuilder builder, string clsPropertyName,
                                    string forIdlAttributeName,                                       
                                    TypeContainer propertyType, 
                                    MethodBuilder getAccessor, MethodBuilder setAccessor) {
     PropertyBuilder propBuild = AddProperty(builder, clsPropertyName,
                                             propertyType, 
                                             getAccessor, setAccessor);
     AddFromIdlNameAttribute(propBuild, forIdlAttributeName);
     return propBuild;
 }
 /**
  * @see parser.IDLParserVisitor#visit(ASTwide_string_type, Object)
  * @param data unsed
  * @return a TypeContainer for the wideString-Type
  */
 public Object visit(ASTwide_string_type node, Object data) {
     AttributeExtCollection attrs = new AttributeExtCollection(
         new Attribute[] { new StringValueAttribute(), new WideCharAttribute(true) });
     TypeContainer containter = new TypeContainer(typeof(System.String), attrs);
     return containter;
 }
Example #8
0
 public ElementCase(string elemName, TypeContainer elemType)
 {
     ElemName = elemName;
     ElemType = elemType;
     discriminatorValues = new ArrayList();
 }
 public void GenerateSwitchCase(TypeContainer elemType, string elemDeclIdent, object[] discriminatorValues) {
     
     // generate val-field for this switch-case
     FieldBuilder elemField = m_ilEmitHelper.AddFieldWithCustomAttrs(m_builder, "m_" + elemDeclIdent,
                                                                     elemType, FieldAttributes.Private);
     SwitchCase switchCase = new SwitchCase(elemType, elemDeclIdent, discriminatorValues,
                                            elemField);            
     // AMELIORATION possiblity: check range conflict with existing cases, before adding case
     m_switchCases.Add(switchCase);
     // generate accessor and modifier methods
     GenerateAccessorMethod(switchCase);
     GenerateModifierMethod(switchCase);
 }
Example #10
0
 private void InitalizePredefinedSymbolMappings(SymbolTable symTable) {
     Symbol abstrBase = symTable.ResolveScopedNameToSymbol(symTable.getTopScope(),
                                                           new ArrayList(new string[] { "omg.org", "CORBA", "AbstractBase" }));
     m_completeTypeTable[abstrBase] = 
         new TypeContainer(ReflectionHelper.ObjectType,
                           new AttributeExtCollection(new Attribute[] { new ObjectIdlTypeAttribute(IdlTypeObject.AbstractBase) }));
 }
 /**
  * @see parser.IDLParserVisitor#visit(ASTop_type_spec, Object)
  * @param data the active buildinfo for the current scope
  * @return the TypeContainer for this op_type_spec
  */
 public Object visit(ASTop_type_spec node, Object data) {
     TypeContainer returnType;
     if (node.jjtGetNumChildren() == 0) {
         // void
         returnType = new TypeContainer(typeof(void));
     } else {
         // <parameter type spec>
         returnType = (TypeContainer) node.jjtGetChild(0).jjtAccept(this, data);
         if (returnType == null) {
             throw new InvalidIdlException(
                 String.Format("type {0} not (yet) defined for {1}",
                               ((SimpleNode)node.jjtGetChild(0)).GetIdentification(),
                               node.GetIdentification()));
         }
         returnType = ReplaceByCustomMappedIfNeeded(returnType);
     }
     return returnType;
 }
    ///<summary>add abstract methods for all implemented interfaces to the abstract class,
    ///add properties for all implemented interfaces to the abstrct class</summary>
    private void AddInheritedMembersAbstractDeclToClassForIf(TypeBuilder classBuilder, 
                                                             System.Type[] interfaces) {
        if (!(classBuilder.IsClass)) { 
            return; 
        } // only needed for classes
        
        // make sure to include interfaces inherited by the direct implemented interfaces are also considered here
        interfaces = FlattenInterfaceHierarchy(interfaces);
        for (int i = 0; i < interfaces.Length; i++) {
            Type ifType = interfaces[i];    
            // methods
            MethodInfo[] methods = ifType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            for (int j = 0; j < methods.Length; j++) {
                if (methods[j].IsSpecialName) {
                    continue; // do not add methods with special name, e.g. property accessor methods
                }
                if (ReflectionHelper.IsMethodDefinedOnType(methods[j], classBuilder.BaseType,
                                                           BindingFlags.Instance | BindingFlags.Public)) {
                    continue; // method is already defined on a baseclass -> do not re-add
                }
                // normal parameters
                ParameterInfo[] parameters = methods[j].GetParameters();
                ParameterSpec[] paramSpecs = new ParameterSpec[parameters.Length];
                for (int k = 0; k < parameters.Length; k++) {
                    paramSpecs[k] = new ParameterSpec(parameters[k]);
                }
                m_ilEmitHelper.AddMethod(classBuilder, methods[j].Name, paramSpecs,
                                         new TypeContainer(methods[j].ReturnType, 
                                                           AttributeExtCollection.ConvertToAttributeCollection(
                                                               methods[j].ReturnTypeCustomAttributes.GetCustomAttributes(false)),
                                                           true),
                                         MethodAttributes.Abstract | MethodAttributes.Public |
                                         MethodAttributes.Virtual | MethodAttributes.NewSlot |
                                         MethodAttributes.HideBySig);
                
            }
            // properties
            PropertyInfo[] properties = ifType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            for (int j = 0; j < properties.Length; j++) {
                
                if (ReflectionHelper.IsPropertyDefinedOnType(properties[j], classBuilder.BaseType,
                                                             BindingFlags.Instance | BindingFlags.Public)) {
                    continue; // property is already defined on a baseclass -> do not re-add
                }
                
                TypeContainer propType = new TypeContainer(properties[j].PropertyType,
                                                           AttributeExtCollection.ConvertToAttributeCollection(
                                                           properties[j].GetCustomAttributes(true)), true);
                MethodBuilder getAccessor = 
                    m_ilEmitHelper.AddPropertyGetter(classBuilder, properties[j].Name,
                                                     propType, MethodAttributes.Virtual | MethodAttributes.Abstract |
                                                               MethodAttributes.Public | MethodAttributes.HideBySig | 
                                                               MethodAttributes.SpecialName | MethodAttributes.NewSlot);
                MethodBuilder setAccessor = null;
                if (properties[j].CanWrite) {
                    setAccessor = 
                        m_ilEmitHelper.AddPropertySetter(classBuilder, properties[j].Name,
                                                         propType, MethodAttributes.Virtual | MethodAttributes.Abstract |
                                                                   MethodAttributes.Public | MethodAttributes.HideBySig |
                                                                   MethodAttributes.SpecialName | MethodAttributes.NewSlot);
                }
                
                m_ilEmitHelper.AddProperty(classBuilder, properties[j].Name,
                                           propType,
                                           getAccessor, setAccessor);                                                                                           
            }

        }
    }
Example #13
0
 /// <summary>
 /// adds a property getter method.
 /// </summary>
 /// <param name="attrs">MethodAttributes, automatically adds HideBySig and SpecialName</param>
 public MethodBuilder AddPropertyGetter(TypeBuilder builder, string propertyName,
                                        TypeContainer propertyType, MethodAttributes attrs)
 {
     return(AddPropertyGetterInternal(builder, propertyName, null, propertyType, attrs));
 }
Example #14
0
 /// <summary>creates a ParameterSpec for a ParameterInfo</summary>
 public ParameterSpec(ParameterInfo forParamInfo) {
     if (forParamInfo.IsOut) {
         m_direction = ParameterDirection.s_out;
     } else if (forParamInfo.ParameterType.IsByRef) {
         m_direction = ParameterDirection.s_inout;
     } else {
         m_direction = ParameterDirection.s_in;
     }            
     m_paramName = forParamInfo.Name;
     
     // custom attributes
     System.Object[] attrs = forParamInfo.GetCustomAttributes(false);
     m_paramType = new TypeContainer(forParamInfo.ParameterType,
                                     AttributeExtCollection.
                                         ConvertToAttributeCollection(attrs), 
                                     true);
 }
Example #15
0
 /// <summary>creates an in parameterspec</summary>
 public ParameterSpec(String paramName, Type clsType) {
     m_paramName = paramName;
     m_paramType = new TypeContainer(clsType);
     m_direction = ParameterDirection.s_in;
 }
Example #16
0
 public ParameterSpec(String paramName, TypeContainer paramType, 
     ParameterDirection direction) {
     m_paramName = paramName;
     m_paramType = paramType;
     m_direction = direction;
 }
Example #17
0
 public bool IsAssignableTo(TypeContainer type) {
     return type.GetCompactClsType().IsEnum;
 }                        
Example #18
0
 public bool IsAssignableTo(TypeContainer type) {
     return type.GetCompactClsType().Equals(ReflectionHelper.BooleanType);                   
 }                        
Example #19
0
 public bool IsAssignableTo(TypeContainer type) {
     if (type.GetCompactClsType().Equals(ReflectionHelper.ByteType)) {
         return m_value >= SByte.MinValue && m_value <= Byte.MaxValue;    
     } else if (type.GetCompactClsType().Equals(ReflectionHelper.Int16Type)) {
         if (type.GetAssignableFromType().Equals(typeof(UInt16))) {
             return m_value >= UInt16.MinValue && m_value <= UInt16.MaxValue;
         } else {
             return m_value >= Int16.MinValue && m_value <= Int16.MaxValue;
         }
     } else if (type.GetCompactClsType().Equals(ReflectionHelper.Int32Type)) {
         if (type.GetAssignableFromType().Equals(typeof(UInt32))) {
             return m_value >= UInt32.MinValue && m_value <= UInt32.MaxValue;
         } else {
             return m_value >= Int32.MinValue && m_value <= Int32.MaxValue;
         }                
     } else if (type.GetCompactClsType().Equals(ReflectionHelper.Int64Type)) {
         if (type.GetAssignableFromType().Equals(typeof(UInt64))) {
             return m_value >= UInt64.MinValue && m_value <= UInt64.MaxValue;
         } else {
             return m_value >= Int64.MinValue && m_value <= Int64.MaxValue;
         }                
     } else {
         return false;
     }
 }        
Example #20
0
 /// <summary>creates an in parameterspec</summary>
 public ParameterSpec(String paramName, Type clsType)
 {
     m_paramName = paramName;
     m_paramType = new TypeContainer(clsType);
     m_direction = ParameterDirection.s_in;
 }
Example #21
0
 /// <summary>adds a method to a type, setting the attributes on the parameters</summary>
 /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
 /// <returns>the MethodBuilder for the method created</returns>
 public MethodBuilder AddMethod(TypeBuilder builder, string methodName, ParameterSpec[] parameters, 
                                TypeContainer returnType, MethodAttributes attrs) {
 
     Type[] paramTypes = new Type[parameters.Length];
     for (int i = 0; i < parameters.Length; i++) { 
         paramTypes[i] = parameters[i].GetParamTypeMergedDirection();
     }
 
     MethodBuilder methodBuild = builder.DefineMethod(methodName, attrs, 
                                                      returnType.GetSeparatedClsType(),
                                                      paramTypes);
     // define the paramter-names / attributes
     for (int i = 0; i < parameters.Length; i++) {
         DefineParameter(methodBuild, parameters[i], i+1);
     }
     // add custom attributes for the return type
     ParameterBuilder paramBuild = CreateParamBuilderForRetParam(methodBuild);
     for (int i = 0; i < returnType.GetSeparatedAttrs().Length; i++) {
         paramBuild.SetCustomAttribute(returnType.GetSeparatedAttrs()[i]);
     }
     return methodBuild;
 }
 /**
  * @see parser.IDLParserVisitor#visit(ASTvalue_base_type, Object)
  * @return a Type Container for the Corba type ValueBase
  */
 public Object visit(ASTvalue_base_type node, Object data) {
     AttributeExtCollection attrs = new AttributeExtCollection(
         new Attribute[] { new ObjectIdlTypeAttribute(IdlTypeObject.ValueBase) });
     TypeContainer container = new TypeContainer(typeof(System.Object), attrs);
     return container;
 }
Example #23
0
 /// <summary>add a fully defined type to the known types</summary>
 private void AddCompleteTypeDefinition(Symbol typeSymbol, TypeContainer fullDecl) {
     if (m_typesInCreation.ContainsKey(typeSymbol)) { 
         throw new InternalCompilerException("type can't be registered, an incomplete declaration exists; symbol: " + typeSymbol);  // should not occur, check by sym table
     }
     if (m_completeTypeTable.ContainsKey(typeSymbol)) { 
         throw new InternalCompilerException("type already defined; symbol: " + typeSymbol); // should not occur, checked by sym table
     }
     
     m_completeTypeTable[typeSymbol] = fullDecl;
 }
Example #24
0
 /// <summary>
 /// register a resolved typedef
 /// </summary>
 public void RegisterTypeDef(TypeContainer fullDecl, Symbol forSymbol) {
     AddCompleteTypeDefinition(forSymbol, fullDecl);
 }
Example #25
0
 /// <summary>
 /// Like <see cref="Ch.Elca.Iiop.Idl.IlEmitHelper.AddMethod(TypeBuilder, string, ParameterSpec[], TypeContainer, MethodAttributes)"/>,
 /// but adds additionally a FromIdlName attribute to the method
 /// </summary>
 public MethodBuilder AddMethod(TypeBuilder builder, string clsMethodName,
                                string forIdlMethodName,
                                ParameterSpec[] parameters,
                                TypeContainer returnType, MethodAttributes attrs) {
     MethodBuilder methodBuild = AddMethod(builder, clsMethodName, parameters,
                                           returnType, attrs);
     AddFromIdlNameAttribute(methodBuild, forIdlMethodName);
     return methodBuild;
 }
 /** 
  * replaces a TypeContainer with the one for the custom mapped type, if a custom mapped type is
  * present. Else Returns the unmodified one.
  **/
 internal static TypeContainer ReplaceByCustomMappedIfNeeded(TypeContainer specType) {
     Type clsType = specType.GetCompactClsType(); // do the mapping on the fusioned type!
     // check for custom Mapping here:
     CompilerMappingPlugin plugin = CompilerMappingPlugin.GetSingleton();
     if (plugin.IsCustomMappingPresentForIdl(clsType.FullName)) {
         Type mappedType = plugin.GetMappingForIdl(clsType.FullName);
         return new TypeContainer(mappedType);
     } else {
         return specType;
     }       
 }
Example #27
0
        /// <summary> 
        /// get the full defined Type or the fwd decl
        /// </summary>
        public TypeContainer GetKnownType(Symbol forSymbol) {
            // search in all complete types from this run, also typesdefs, ...
            TypeContainer result = (TypeContainer)m_completeTypeTable[forSymbol];
            if (result == null) {
                result = (TypeContainer)m_typesInCreation[forSymbol];
            }
            if (result == null) {
                // search in build-module to get also types from a run over a previous root idl-file (one specified on the command line)
                Type fromBuildMod = GetTypeFromBuildModule(forSymbol);
                if (fromBuildMod != null) {
                    result = new CompileTimeTypeContainer(this, fromBuildMod);
                }        
            }
            if (result == null) { 
                // check in types, which are defined in referenced assemblies

                Type fromAsm = GetTypeFromRefAssemblies(forSymbol);
                if (fromAsm != null) {
                    // remark: all types in ref assemblies are fully completed -> no need for compileTimeTypeContainer
                    result = new TypeContainer(fromAsm);
                }
            }
            if ((result == null) && (m_sequenceRecursionAllowedType != null) &&
                m_sequenceRecursionAllowedType.SymbolPart.Equals(forSymbol)) {
                result = m_sequenceRecursionAllowedType.TypePart;
            }
            return result;
        }
Example #28
0
 /// <summary>adds a field to a type, including the custom attributes needed</summary>
 /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
 /// <returns>the FieldBuilder for the field created</returns>
 public FieldBuilder AddFieldWithCustomAttrs(TypeBuilder builder, string fieldName, 
                                             TypeContainer fieldType, FieldAttributes attrs) {
     // consider custom mappings
     Type clsType = fieldType.GetSeparatedClsType();
     FieldBuilder fieldBuild = builder.DefineField(fieldName, clsType, attrs);
     // add custom attributes
     for (int j = 0; j < fieldType.GetSeparatedAttrs().Length; j++) {
         fieldBuild.SetCustomAttribute(fieldType.GetSeparatedAttrs()[j]);
     }
     return fieldBuild;
 }
Example #29
0
 public TypeSymbolPair(Symbol symbolPart, TypeContainer typePart) {
     SymbolPart = symbolPart;
     TypePart = typePart;
 }
Example #30
0
 /// <summary>
 /// adds a property setter method; optinally adds a FromIdlNameAttribute,
 /// if forIdlAttributeName is != null.
 /// </summary>
 private MethodBuilder AddPropertySetterInternal(TypeBuilder builder,
                                                 string propertyName,
                                                 string forIdlSetterName, 
                                                 TypeContainer propertyType, 
                                                 MethodAttributes attrs) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     MethodBuilder setAccessor = builder.DefineMethod("set_" + propertyName, 
                                                      attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName, 
                                                      null, new System.Type[] { propTypeCls });
     
     ParameterBuilder valParam = setAccessor.DefineParameter(1, ParameterAttributes.None, "value"); 
     // add custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {
         valParam.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
     }
     
     if (forIdlSetterName != null) {
         AddFromIdlNameAttribute(setAccessor, forIdlSetterName);    
     }            
     return setAccessor;                                                                                                                                    
 }
 public void AddDiscriminatorFieldAndProperty(TypeContainer discrType, ArrayList coveredDiscrRange) {
     if ((m_discrType != null) || (m_coveredDiscrs == null)) {
         throw new INTERNAL(899, CompletionStatus.Completed_MayBe);
     }
     m_discrType = discrType;
     m_coveredDiscrs = coveredDiscrRange;
     m_discrField = m_ilEmitHelper.AddFieldWithCustomAttrs(m_builder, DISCR_FIELD_NAME, m_discrType, 
                                                           FieldAttributes.Private);
     // Property for discriminiator
     String propName = DISCR_PROPERTY_NAME;
     // set the methods for the property
     MethodBuilder getAccessor = m_ilEmitHelper.AddPropertyGetter(m_builder, propName, m_discrType,
                                                                  MethodAttributes.Public);
     ILGenerator gen = getAccessor.GetILGenerator();
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Ldfld, m_discrField);
     gen.Emit(OpCodes.Ret);
     MethodBuilder setAccessor = null;
     m_ilEmitHelper.AddProperty(m_builder, propName, m_discrType, getAccessor, setAccessor);
     // add a method, which returns an array of covered discriminators
     AddCoveredDiscrsGetter();
 }
Example #32
0
 /// <summary>
 /// adds a property getter method with a FromIdlName attribute 
 /// (based on the name of the property, this setter is defined for)
 /// </summary>
 /// <param name="attrs">MethodAttributes, automatically adds HideBySig and SpecialName</param>
 public MethodBuilder AddPropertyGetter(TypeBuilder builder, string propertyName,
                                        string forIdlGetterName,
                                        TypeContainer propertyType, MethodAttributes attrs) {
     return AddPropertyGetterInternal(builder, propertyName, forIdlGetterName, 
                                      propertyType, attrs);
 }
Example #33
0
 private MethodBuilder AddPropertyGetterInternal(TypeBuilder builder, string propertyName,
                                                string forIdlGetterName, 
                                                TypeContainer propertyType, MethodAttributes attrs) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     MethodBuilder getAccessor = builder.DefineMethod("get_" + propertyName, 
                                                      attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName, 
                                                      propTypeCls, System.Type.EmptyTypes);
     
     ParameterBuilder retParamGet = CreateParamBuilderForRetParam(getAccessor);
     // add custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {                
         retParamGet.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
     }
     if (forIdlGetterName != null) {
         AddFromIdlNameAttribute(getAccessor, forIdlGetterName);    
     }
     return getAccessor;                                                           
 }
Example #34
0
 /// <summary>
 /// adds a property to a type, including the custom attributes needed.
 /// </summary>
 public PropertyBuilder AddProperty(TypeBuilder builder, string propertyName, 
                                    TypeContainer propertyType, 
                                    MethodBuilder getAccessor, MethodBuilder setAccessor) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     PropertyBuilder propBuild = builder.DefineProperty(propertyName, PropertyAttributes.None, 
                                                        propTypeCls, System.Type.EmptyTypes);
     // add accessor methods
     if (getAccessor != null) {
         propBuild.SetGetMethod(getAccessor);
     }            
     if (setAccessor != null) {
         propBuild.SetSetMethod(setAccessor);
     }
     // define custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {
         propBuild.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);                
     }
     return propBuild;
 }
Example #35
0
        internal override Type CreateType(ModuleBuilder modBuilder, string fullTypeName)
        {
            UnionGenerationHelper genHelper = new UnionGenerationHelper(modBuilder, fullTypeName,
                                                                        TypeAttributes.Public);

            TypeContainer discrType = new TypeContainer(((TypeCodeImpl)m_discriminatorType).GetClsForTypeCode(),
                                                        ((TypeCodeImpl)m_discriminatorType).GetClsAttributesForTypeCode());
            // extract covered discr range from m_members
            ArrayList coveredDiscriminatorRange = CoveredDiscriminatorRange();
            genHelper.AddDiscriminatorFieldAndProperty(discrType, coveredDiscriminatorRange);

            Hashtable cases = CollectCases();
            foreach (ElementCase elemCase in cases.Values)
            {
                genHelper.GenerateSwitchCase(elemCase.ElemType, elemCase.ElemName,
                                             elemCase.GetDiscriminatorValues());
            }

            // add rep-id Attr
            IlEmitHelper.GetSingleton().AddRepositoryIDAttribute(genHelper.Builder, m_id);

            // create the resulting type
            return genHelper.FinalizeType();
        }
    /**
     * @see parser.IDLParserVisitor#visit(ASTsequence_type, Object)
     * @param data the buildinfo in use for the current scope
     * @return the type container for the IDLSequence type
     */
    public Object visit(ASTsequence_type node, Object data) {
        CheckParameterForBuildInfo(data, node);        
        BuildInfo containerInfo = (BuildInfo) data;
        SimpleNode elemTypeNode = (SimpleNode)node.jjtGetChild(0);
        if (containerInfo.GetContainterType() != null) {
            // inform the type-manager of structs/unions in creation, because
            // recursion using seuqneces is the only allowed recursion for structs/unions
            m_typeManager.PublishTypeForSequenceRecursion(containerInfo.GetContainerSymbol(),
                                                          containerInfo.GetContainterType());
        }
        Debug.WriteLine("determine element type of IDLSequence");
        TypeContainer elemType = (TypeContainer)elemTypeNode.jjtAccept(this, data);
        // disallow further recursive use of union/struct (before next seq recursion)
        m_typeManager.UnpublishTypeForSequenceRecursion();
        if (elemType == null) {
            throw new InvalidIdlException(
                String.Format("sequence element type not defined for {0}",
                              node.GetIdentification()));
        }
        elemType = ReplaceByCustomMappedIfNeeded(elemType);
        // use here the fusioned type as element type; potential unboxing of element type 
        // should be done by users of TypeContainer (if needed)!
        Debug.WriteLine("seq type determined: " + elemType.GetCompactClsType());
        // create CLS array type with the help of GetType(), otherwise not possible
        Type arrayType;
        // because not fully defined types are possible, use module and not assembly to get type from
        Module declModule = elemType.GetCompactClsType().Module;
        arrayType = declModule.GetType(elemType.GetCompactClsType().FullName + "[]"); // not nice, better solution ?        
        Debug.WriteLine("created array type: " + arrayType);
        
        // determin if sequence is bounded or unbounded
        long bound = 0;
        if (node.jjtGetNumChildren() > 1) { 
            // bounded sequnece
            bound = (long) node.jjtGetChild(1).jjtAccept(this, data);
        }

        // determine the needed attributes: IdlSequence is required by the sequence itself; 
        // combine with the attribute from the element type
        // possible are: IdlSequence (for sequence of sequence), ObjectIdlType,
        // WideChar, StringValue
        // invariant: boxed value attribute is not among them, because elem type 
        // is in the compact form        
        AttributeExtCollection elemAttributes = elemType.GetCompactTypeAttrInstances();
        long seqAttrOrderNr = IdlSequenceAttribute.DetermineSequenceAttributeOrderNr(elemAttributes);
        IdlSequenceAttribute seqAttr = new IdlSequenceAttribute(seqAttrOrderNr, bound);
        AttributeExtCollection sequenceAttributes = 
            new AttributeExtCollection(elemAttributes);
        sequenceAttributes = sequenceAttributes.MergeAttribute(seqAttr);
        TypeContainer result = new TypeContainer(arrayType,
                                                 sequenceAttributes );
        return result;
    }