/** handles the declaration for the interface definition / fwd declaration
  * @return the TypeBuilder for this interface
  */
 private TypeBuilder CreateOrGetInterfaceDcl(Symbol forSymbol, System.Type[] interfaces, 
                                             bool isAbstract, bool isLocal, bool isForward) {
     TypeBuilder interfaceToBuild = null;
     if (!m_typeManager.IsFwdDeclared(forSymbol)) {
         Trace.WriteLine("generating code for interface: " + forSymbol.getSymbolName());
         interfaceToBuild = m_typeManager.StartTypeDefinition(forSymbol, 
                                                              TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract,
                                                              null, interfaces, isForward);
         // add InterfaceTypeAttribute
         IdlTypeInterface ifType = IdlTypeInterface.ConcreteInterface;
         if (isAbstract) { 
             ifType = IdlTypeInterface.AbstractInterface; 
         }
         if (isLocal) {
             ifType = IdlTypeInterface.LocalInterface;
         }
         if ((isLocal) && (isAbstract)) {
             throw new InternalCompilerException("internal error: iftype precondition");
         }
         // add interface type
         CustomAttributeBuilder interfaceTypeAttrBuilder = new InterfaceTypeAttribute(ifType).CreateAttributeBuilder();
         interfaceToBuild.SetCustomAttribute(interfaceTypeAttrBuilder);
         interfaceToBuild.AddInterfaceImplementation(typeof(IIdlEntity));
     } else {
         // get incomplete type
         Trace.WriteLine("complete interface: " + forSymbol.getSymbolName());
         interfaceToBuild = m_typeManager.GetIncompleteForwardDeclaration(forSymbol);
         // add inheritance relationship:
         for (int i = 0; i < interfaces.Length; i++) {
             interfaceToBuild.AddInterfaceImplementation(interfaces[i]);
         }
     }
     return interfaceToBuild;
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 /// <summary>
 /// allows sequence recursion for unions/struct. Don't forget to call
 /// UnpublishTypeForSequenceRecursion after sequence elem type is identified
 /// </summary>
 public void PublishTypeForSequenceRecursion(Symbol typeSym, TypeBuilder type) {
     if (!IsTypeDeclarded(typeSym)) {
         TypeContainer container =
             new CompileTimeTypeContainer(this, type);
         m_sequenceRecursionAllowedType = new TypeSymbolPair(typeSym, container);
     }            
 }
Exemplo n.º 4
0
 /// <summary>
 /// checks, if a type is already declared in a referenced assembly
 /// </summary>
 public bool IsTypeDeclaredInRefAssemblies(Symbol forSymbol) {
    return GetTypeFromRefAssemblies(forSymbol) != null;
 }
Exemplo n.º 5
0
 /// <summary>checks if a type generation can be skipped, 
 /// because type is already defined in a previous run over a parse tree 
 /// or in a reference assembly
 /// </summary>
 /// <remarks>this method is used to support runs over more than one parse tree
 /// </remarks>
 public bool CheckSkip(Symbol forSymbol) {
 
     if (IsTypeDeclaredInRefAssemblies(forSymbol)) {
         // skip, because already defined in a referenced assembly 
         // -> this overrides the def from idl
         return true;
     }
 
     // check here directly on module, to find out about runs of the compiler for
     // previous files (for every run over a new file on the IDL To CLS argument line, 
     // a new TypeManager is used)
     Type inBuildModule = GetTypeFromBuildModule(forSymbol);
     if (inBuildModule != null && !IsIncompleteDeclarationPresent(forSymbol)) { 
         // safe to skip, because type is already fully declared in this run
         return true;
     }
         
     // do not skip
     return false;
 }
Exemplo n.º 6
0
 public bool IsFwdDeclared(Symbol forSymbol) {
     return GetIncompleteForwardDeclartionUnchecked(forSymbol) != null;
 }
Exemplo n.º 7
0
 private void AddRepositoryIdAttribute(TypeBuilder typeBuild, Symbol typeSymbol) {
     string repositoryId = FindRepositoryId(typeSymbol);
     if (repositoryId == null) {
         // no repository id specified, create one from the idl, because of special name mappings
         // creating a rep-id in Channel code can lead to the wrong one ...                
         repositoryId = typeSymbol.ConstructRepositoryId();
     }
     AddRepositoryIdAttribute(typeBuild, repositoryId);
 }
Exemplo n.º 8
0
 /// <summary>
 /// start a type definition for a type with System.Object as parent
 /// </summary>        
 /// <param name="isForwardDeclaration">specifies, if this type is created from an idl forward declaration</param>
 public TypeBuilder StartTypeDefinition(Symbol typeSymbol,
                                        TypeAttributes typeAttributes, Type[] interfaces,
                                        bool isForwardDeclaration) {
     return StartTypeDefinition(typeSymbol, typeAttributes, typeof(System.Object), interfaces,
                                isForwardDeclaration);        
 }
Exemplo n.º 9
0
        /// <summary>
        /// Start a type definition for a boxed value type
        /// Adds also repository id and IIdlEntity inheritance.
        /// </summary>
        public TypeBuilder StartBoxedValueTypeDefinition(Symbol typeSymbol, Type boxedType, 
                                                         CustomAttributeBuilder[] boxedTypeAttributes) {            

            if (IsTypeDeclarded(typeSymbol)) {
                // was not skipped, tried to redeclare -> internal error
                throw new InternalCompilerException("A type with the name " + 
                                                    GetKnownType(typeSymbol).GetCompactClsType().FullName +
                                                    " is already declared for symbol: " + typeSymbol);
            }

            Scope enclosingScope = typeSymbol.getDeclaredIn();
            String fullyQualName = enclosingScope.GetFullyQualifiedNameForSymbol(typeSymbol.getSymbolName());
                                                    
            Trace.WriteLine("generating code for boxed value type: " + fullyQualName);
            
            TypeBuilder result =
                m_boxedValueTypeGenerator.CreateBoxedType(boxedType, m_modBuilder,
                                                          fullyQualName, boxedTypeAttributes);
                                                            
            // book-keeping
            TypeContainer container = new CompileTimeTypeContainer(this, result);
            m_typesInCreation[typeSymbol] = container;
            
            // repository and iidlentiry inheritance
            result.AddInterfaceImplementation(typeof(IIdlEntity));
            AddRepositoryIdAttribute(result, typeSymbol);            
            
            return result;            
        }    
Exemplo n.º 10
0
 /// <summary>
 /// start a type definition for a type
 /// </summary>        
 /// <param name="isForwardDeclaration">specifies, if this type is created from an idl forward declaration</param>
 private TypeBuilder StartTypeDefinition(Symbol typeSymbol, string fullyQualName,
                                        TypeAttributes typeAttributes, Type parent, Type[] interfaces,
                                        bool isForwardDeclaration) {                                   
                                       
      if (IsTypeDeclarded(typeSymbol)) {
          // was not skipped, tried to redeclare -> internal error
          throw new InternalCompilerException("A type with the name " + 
                                              GetKnownType(typeSymbol).GetCompactClsType().FullName +
                                              " is already declared for symbol: " + typeSymbol);
      }            
     
     TypeBuilder result = m_modBuilder.DefineType(fullyQualName, typeAttributes, parent, interfaces);
     AddRepositoryIdAttribute(result, typeSymbol); // every constructed type should have a rep-id.
     // book-keeping
     TypeContainer container = new CompileTimeTypeContainer(this, result);
     m_typesInCreation[typeSymbol] = container;
                                                                                  
     if (isForwardDeclaration) {
         // store type-fwd declaration in a special place, to allow searching only those when trying to complete a fwd declaration.
         m_fwdDeclaredTypes[typeSymbol] = container;
     }
                                            
     return result;
 }
Exemplo n.º 11
0
 /// <summary>
 /// start a type definition for a type
 /// </summary>        
 /// <param name="isForwardDeclaration">specifies, if this type is created from an idl forward declaration</param>
 public TypeBuilder StartTypeDefinition(Symbol typeSymbol,
                                        TypeAttributes typeAttributes, Type parent, Type[] interfaces,
                                        bool isForwardDeclaration) {
     Scope enclosingScope = typeSymbol.getDeclaredIn();
     String fullyQualName = enclosingScope.GetFullyQualifiedNameForSymbol(typeSymbol.getSymbolName());
     return StartTypeDefinition(typeSymbol, fullyQualName, 
                                typeAttributes, parent, interfaces, isForwardDeclaration);
 }
Exemplo n.º 12
0
 /// <summary>finds the repository id attribute for the symbol starting the search in startInScope</summary>
 private string FindRepositoryId(Symbol forSymbol) {
     Scope startInScope = forSymbol.getDeclaredIn();
     string forName = forSymbol.getSymbolName();
     string result = startInScope.getRepositoryIdFor(forName);
     if (result == null) {
         // try inside scope to find it
         Scope innerScope = startInScope.getChildScope(forName);
         if (innerScope != null) {
             result = innerScope.getRepositoryIdFor(forName);
         }
     }
     return result;
 }
Exemplo n.º 13
0
 public BuildInfo(Scope buildScope, TypeBuilder containerType, 
                  Symbol containerSymbol) {
     m_buildScope = buildScope;
     m_containerType = containerType;
     m_containerSymbol = containerSymbol;
 }
Exemplo n.º 14
0
 /** handles the declaration for the value definition / fwd declaration
  * @return the TypeBuilder for this interface
  */
 private TypeBuilder CreateOrGetValueDcl(Symbol forSymbol,
                                         System.Type parent, System.Type[] interfaces,
                                         bool isAbstract, bool isForwardDecl) {
     TypeBuilder valueToBuild;
     if (!m_typeManager.IsFwdDeclared(forSymbol)) {
         Trace.WriteLine("generating code for value type: " + forSymbol.getSymbolName());
         TypeAttributes attrs = TypeAttributes.Public | TypeAttributes.Abstract;
         if (isAbstract) {
             attrs |= TypeAttributes.Interface;
             if (parent != null) { 
                 // classes are considered as concrete value types
                 throw new InvalidIdlException("not possible for an abstract value type " +
                                               forSymbol.getDeclaredIn().GetFullyQualifiedNameForSymbol(forSymbol.getSymbolName()) + 
                                               " to inherit from a concrete one " +
                                               parent.FullName);
             }
         } else {
             attrs |= TypeAttributes.Class;
         }
         valueToBuild = m_typeManager.StartTypeDefinition(forSymbol, attrs, parent, interfaces, 
                                                          isForwardDecl);            
         if (isAbstract) {
             // add InterfaceTypeAttribute
             IdlTypeInterface ifType = IdlTypeInterface.AbstractValueType;
             CustomAttributeBuilder interfaceTypeAttrBuilder = new InterfaceTypeAttribute(ifType).CreateAttributeBuilder();
             valueToBuild.SetCustomAttribute(interfaceTypeAttrBuilder);
         }
         valueToBuild.AddInterfaceImplementation(typeof(IIdlEntity)); // implement IDLEntity
     } else {
         // get incomplete type
         Trace.WriteLine("complete valuetype: " + forSymbol.getSymbolName());
         valueToBuild = m_typeManager.GetIncompleteForwardDeclaration(forSymbol);
         // add inheritance relationship:
         for (int i = 0; i < interfaces.Length; i++) {
             valueToBuild.AddInterfaceImplementation(interfaces[i]);
         }
         if (parent != null) { 
             valueToBuild.SetParent(parent);
         }
     }
     // add abstract methods for all interface methods, a class inherit from (only if valueToBuild is a class an not an interface)
     // add property to abstract class for all properties defined in an interface (only if valueToBuild is a class an not an interface)
     AddInheritedMembersAbstractDeclToClassForIf(valueToBuild, interfaces);
     return valueToBuild;
 }
Exemplo n.º 15
0
 private bool IsIncompleteDeclarationPresent(Symbol typeSymbol) {
     return m_typesInCreation[typeSymbol] != null;
 }                        
Exemplo n.º 16
0
        public UnionGenerationHelper StartUnionTypeDefinition(Symbol typeSymbol, string fullyQualName) {            
            
            if (IsTypeDeclarded(typeSymbol)) {
                // was not skipped, tried to redeclare -> internal error
                throw new InternalCompilerException("A type with the name " + 
                                                    GetKnownType(typeSymbol).GetCompactClsType().FullName +
                                                    " is already declared for symbol: " + typeSymbol);
            }            
            
            UnionGenerationHelper genHelper = new UnionGenerationHelper(m_modBuilder, fullyQualName,
                                                                        TypeAttributes.Public);
            AddRepositoryIdAttribute(genHelper.Builder, typeSymbol);
            // book-keeping
            TypeContainer container = new CompileTimeTypeContainer(this, genHelper.Builder);
            m_typesInCreation[typeSymbol] = container;

            return genHelper;
        }
Exemplo n.º 17
0
 /// <summary>
 /// is at least a forward declaration for the type represented by the symbol present
 /// </summary>
 public bool IsTypeDeclarded(Symbol forSymbol) {
     TypeContainer type = GetKnownType(forSymbol);
     return (type != null);
 }
Exemplo n.º 18
0
 public Type EndUnionTypeDefinition(Symbol typeSymbol, UnionGenerationHelper helper) {
     Type resultType = helper.FinalizeType();
     
     // book-keeping
     m_typesInCreation.Remove(typeSymbol);
     AddCompleteTypeDefinition(typeSymbol, new CompileTimeTypeContainer(this, resultType));
     
     return resultType;            
 }
Exemplo n.º 19
0
 private void AddRepositoryIdAttribute(Symbol typeSymbol) {                        
     TypeBuilder inCreation = GetTypeFromTypesInCreation(typeSymbol);
     AddRepositoryIdAttribute(inCreation, typeSymbol);            
 }
Exemplo n.º 20
0
 /// <summary>
 /// completed the type definiton by creation toComplete.CreateType and
 /// updates internal state used to tell about status of types
 /// </summary>
 /// <param name="toComplete"></param>
 /// <returns></returns>
 public Type EndTypeDefinition(Symbol typeSymbol) {                                                
     TypeBuilder toComplete = GetTypeFromTypesInCreation(typeSymbol);                                                
     Type resultType = toComplete.CreateType();
     
     // update the book-keeping
     m_typesInCreation.Remove(typeSymbol);
     m_fwdDeclaredTypes.Remove(typeSymbol);
     AddCompleteTypeDefinition(typeSymbol,new CompileTimeTypeContainer(this, resultType));
     return resultType;                        
 }                
Exemplo n.º 21
0
 private string GetFullTypeNameForSymbol(Symbol forSymbol) {
     Scope declIn = forSymbol.getDeclaredIn();
     return declIn.GetFullyQualifiedNameForSymbol(forSymbol.getSymbolName());
 }
Exemplo n.º 22
0
 public TypeBuilder GetIncompleteForwardDeclaration(Symbol typeSymbol) {
     TypeBuilder result = GetIncompleteForwardDeclartionUnchecked(typeSymbol);
     if (result != null) {
         return result;
     } else {
         // must be found, otherwise an implementation error ...
         throw new InternalCompilerException("forward decl not retrieved again for " + typeSymbol);
     }
 }
Exemplo n.º 23
0
 private Type GetTypeFromRefAssemblies(Symbol forSymbol) {
     string fullName = GetFullTypeNameForSymbol(forSymbol);          
     String repId = 
         forSymbol.getDeclaredIn().getRepositoryIdFor(forSymbol.getSymbolName());
     return m_refAsmTypes.GetTypeFromRefAssemblies(fullName, repId);
 }
Exemplo n.º 24
0
 /// <summary>
 /// the same as GetIncompleteForwardDeclaration, but throws no exception if not found
 /// </summary>
 private TypeBuilder GetIncompleteForwardDeclartionUnchecked(Symbol typeSymbol) {
     TypeContainer container = (TypeContainer)m_fwdDeclaredTypes[typeSymbol];
     TypeBuilder result = (container != null ? container.GetCompactClsType() as TypeBuilder : null);
     return result;
 }
Exemplo n.º 25
0
 /// <summary>
 /// checks if a type is known by ModuleBuilder and if yes, returns it; otherwise; returns null        
 /// </summary>  
 private Type GetTypeFromBuildModule(Symbol forSymbol) {
     string fullName = GetFullTypeNameForSymbol(forSymbol);
     Type result = GetTypeFromBuildModule(fullName);
     return result;
 }
Exemplo n.º 26
0
 /// <summary>
 /// returns the typebuilder if found among types in creation, otherwise throws exception
 /// </summary>                
 private TypeBuilder GetTypeFromTypesInCreation(Symbol typeSymbol) {
     TypeContainer container = (TypeContainer)m_typesInCreation[typeSymbol];
     TypeBuilder toComplete = (container != null ? container.GetCompactClsType() as TypeBuilder : null);
     if (toComplete != null) {
         return toComplete;            
     } else {
         throw new InternalCompilerException("type in creation not found: " + typeSymbol);
     }
 }
Exemplo n.º 27
0
 /// <summary>
 /// register a resolved typedef
 /// </summary>
 public void RegisterTypeDef(TypeContainer fullDecl, Symbol forSymbol) {
     AddCompleteTypeDefinition(forSymbol, fullDecl);
 }
Exemplo n.º 28
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;
 }
Exemplo n.º 29
0
 public TypeSymbolPair(Symbol symbolPart, TypeContainer typePart) {
     SymbolPart = symbolPart;
     TypePart = typePart;
 }
Exemplo n.º 30
0
 public ConcreteValTypeBuildInfo(Scope buildScope,
                                 TypeBuilder containerType,
                                 Symbol containerSymbol,
                                 ConstructorBuilder defConstr) :
                                     base(buildScope, containerType,
                                          containerSymbol) {
     m_defaultConstr = defConstr;
 }