Ejemplo n.º 1
0
        /// <summary>
        /// Gets IP interfaces which are up
        /// </summary>
        private void GetInterfaces()
        {
            foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (networkInterface.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (UnicastIPAddressInformation ip in networkInterface.GetIPProperties().UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            InterfaceList.Add(new IPNetworkInterface
                            {
                                InterfaceAddress = ip.Address.ToString(),
                                InterfaceName    = networkInterface.Name
                            });
                        }
                    }
                }
            }

            if (InterfaceList.Count > 0)
            {
                SelectedInterface = InterfaceList[0];
            }
            else
            {
                selectedInterface = null;
            }

            RaisePropertyChanged("SelectedInterface");
        }
Ejemplo n.º 2
0
        private void RefreshInterfaceList()
        {
            // Retrieve the interfaces list
            IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            // Scan the list printing every entry
            for (int i = 0; i < allDevices.Count(); i++)
            {
                InterfaceList.Add(allDevices[i]);
            }
        }
        public void PopulateLists()
        {
            InterfaceList.Add(new DerivedIFaceA());
            InterfaceList.Add(new DerivedIFaceB());

            AbstractTypeList.Add(new DerivedAbstractA());
            AbstractTypeList.Add(new DerivedAbstractB());

            BaseTypeList.Add(new BaseType());
            BaseTypeList.Add(new DerivedBaseA());
            BaseTypeList.Add(new DerivedBaseB());
        }
Ejemplo n.º 4
0
        private ClassParameter ConvertToClassParameter(TypeNode typeParameter, InterfaceList interfaces, Class baseClass, ClassExpression cExpr)
        {
            ClassParameter cParam = typeParameter is MethodTypeParameter ? new MethodClassParameter() : new ClassParameter();

            this.typeParamToClassParamMap[typeParameter.UniqueKey] = cParam;
            cParam.SourceContext      = typeParameter.SourceContext;
            cParam.TypeParameterFlags = ((ITypeParameter)typeParameter).TypeParameterFlags;
            if (typeParameter.IsUnmanaged)
            {
                cParam.SetIsUnmanaged();
            }
            cParam.Name                = typeParameter.Name;
            cParam.Namespace           = StandardIds.ClassParameter;
            cParam.BaseClass           = baseClass == null ? SystemTypes.Object : baseClass;
            cParam.BaseClassExpression = cExpr;
            cParam.DeclaringMember     = ((ITypeParameter)typeParameter).DeclaringMember;
            cParam.DeclaringModule     = typeParameter.DeclaringModule;
            cParam.DeclaringType       = typeParameter is MethodTypeParameter ? null : typeParameter.DeclaringType;
            cParam.Flags               = typeParameter.Flags & ~TypeFlags.Interface;
            cParam.ParameterListIndex  = ((ITypeParameter)typeParameter).ParameterListIndex;
            MemberList mems = cParam.DeclaringType == null ? null : cParam.DeclaringType.Members;
            int        n    = mems == null ? 0 : mems.Count;

            for (int i = 0; i < n; i++)
            {
                if ((mems[i] as TypeNode) == typeParameter)
                {
                    mems[i] = cParam;
                    break;
                }
            }
            if (cExpr != null)
            {
                n = interfaces.Count - 1;
                InterfaceList actualInterfaces = new InterfaceList(n);
                for (int i = 0; i < n; i++)
                {
                    actualInterfaces.Add(interfaces[i + 1]);
                }
                cParam.Interfaces = actualInterfaces;
            }
            else
            {
                cParam.Interfaces = interfaces;
            }
            if (cExpr != null)
            {
                cParam.BaseClass = this.VisitClassExpression(cExpr);
            }
            return(cParam);
        }
Ejemplo n.º 5
0
        /// <exception cref="ArgumentException">
        /// The language of <paramref name="interfaceType"/> does not equal.-or-
        /// <paramref name="interfaceType"/> is earlier implemented interface.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="interfaceType"/> is null.
        /// </exception>
        internal virtual void AddInterface(InterfaceType interfaceType)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            for (int i = 0; i < InterfaceList.Count; i++)
            {
                if (InterfaceList[i] == interfaceType)
                {
                    throw new ArgumentException("error_cannot_add_same_interface");
                }
            }

            InterfaceList.Add(interfaceType);
        }
Ejemplo n.º 6
0
        /// <exception cref="RelationshipException">
        ///     The language of <paramref name="interfaceType" /> does not equal.-or-
        ///     <paramref name="interfaceType" /> is earlier implemented interface.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="interfaceType" /> is null.
        /// </exception>
        public virtual void AddInterface(InterfaceType interfaceType)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            foreach (var implementedInterface in InterfaceList)
            {
                if (interfaceType == implementedInterface)
                {
                    throw new RelationshipException(Strings.ErrorCannotAddSameInterface);
                }
            }

            InterfaceList.Add(interfaceType);
            Changed();
        }
Ejemplo n.º 7
0
        /// <exception cref="RelationException">
        /// The language of <paramref name="interfaceType"/> does not equal.-or-
        /// <paramref name="interfaceType"/> is earlier implemented interface.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="interfaceType"/> is null.
        /// </exception>
        public virtual void AddInterface(InterfaceType interfaceType)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            foreach (InterfaceType implementedInterface in InterfaceList)
            {
                if (interfaceType == implementedInterface)
                {
                    throw new RelationException(
                              Strings.GetString("error_cannot_add_same_interface"));
                }
            }

            InterfaceList.Add(interfaceType);
            Modified();
        }
Ejemplo n.º 8
0
 private ClassParameter ConvertToClassParameter(TypeNode typeParameter, InterfaceList interfaces, Class baseClass, ClassExpression cExpr){
   ClassParameter cParam = typeParameter is MethodTypeParameter ? new MethodClassParameter() : new ClassParameter();
   this.typeParamToClassParamMap[typeParameter.UniqueKey] = cParam;
   cParam.SourceContext = typeParameter.SourceContext;
   cParam.TypeParameterFlags = ((ITypeParameter)typeParameter).TypeParameterFlags;
   if (typeParameter.IsUnmanaged) { cParam.SetIsUnmanaged(); }
   cParam.Name = typeParameter.Name;
   cParam.Namespace = StandardIds.ClassParameter;
   cParam.BaseClass = baseClass == null ? SystemTypes.Object : baseClass;
   cParam.BaseClassExpression = cExpr;
   cParam.DeclaringMember = ((ITypeParameter)typeParameter).DeclaringMember;
   cParam.DeclaringModule = typeParameter.DeclaringModule;
   cParam.DeclaringType = typeParameter is MethodTypeParameter ? null : typeParameter.DeclaringType;
   cParam.Flags = typeParameter.Flags & ~TypeFlags.Interface;
   cParam.ParameterListIndex = ((ITypeParameter)typeParameter).ParameterListIndex;
   MemberList mems = cParam.DeclaringType == null ? null : cParam.DeclaringType.Members;
   int n = mems == null ? 0 : mems.Count;
   for (int i = 0; i < n; i++){
     if ((mems[i] as TypeNode) == typeParameter){
       mems[i] = cParam;
       break;
     }
   }
   if (cExpr != null){
     n = interfaces.Count - 1;
     InterfaceList actualInterfaces = new InterfaceList(n);
     for (int i = 0; i < n; i++)
       actualInterfaces.Add(interfaces[i + 1]);
     cParam.Interfaces = actualInterfaces;
   }else
     cParam.Interfaces = interfaces;
   if (cExpr != null) cParam.BaseClass = this.VisitClassExpression(cExpr);
   return cParam;
 }
Ejemplo n.º 9
0
 public virtual Differences VisitInterfaceReferenceList(InterfaceList list1, InterfaceList list2,
   out InterfaceList changes, out InterfaceList deletions, out InterfaceList insertions){
   changes = list1 == null ? null : list1.Clone();
   deletions = list1 == null ? null : list1.Clone();
   insertions = list1 == null ? new InterfaceList() : list1.Clone();
   //^ assert insertions != null;
   Differences differences = new Differences();
   //Compare definitions that have matching key attributes
   TrivialHashtable matchingPosFor = new TrivialHashtable();
   TrivialHashtable matchedNodes = new TrivialHashtable();
   for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){
     //^ assert list2 != null;
     Interface nd2 = list2[j];
     if (nd2 == null || nd2.Name == null) continue;
     matchingPosFor[nd2.Name.UniqueIdKey] = j;
     insertions.Add(null);
   }
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Interface nd1 = list1[i];
     if (nd1 == null || nd1.Name == null) continue;
     object pos = matchingPosFor[nd1.Name.UniqueIdKey];
     if (!(pos is int)) continue;
     //^ assert pos != null;
     //^ assume list2 != null; //since there was entry int matchingPosFor
     int j = (int)pos;
     Interface nd2 = list2[j];
     //nd1 and nd2 have the same key attributes and are therefore treated as the same entity
     matchedNodes[nd1.UniqueKey] = nd1;
     //^ assume nd2 != null;
     matchedNodes[nd2.UniqueKey] = nd2;
     //nd1 and nd2 may still be different, though, so find out how different
     Differences diff = this.VisitInterface(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.NumberOfDifferences != 0){
       changes[i] = diff.Changes as Interface;
       deletions[i] = diff.Deletions as Interface;
       insertions[i] = diff.Insertions as Interface;
       insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
       //Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]);
       differences.NumberOfDifferences += diff.NumberOfDifferences;
       differences.NumberOfSimilarities += diff.NumberOfSimilarities;
       continue;
     }
     changes[i] = null;
     deletions[i] = null;
     insertions[i] = null;
     insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation
   }
   //Find deletions
   for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){
     //^ assert list1 != null && changes != null && deletions != null;
     Interface nd1 = list1[i]; 
     if (nd1 == null) continue;
     if (matchedNodes[nd1.UniqueKey] != null) continue;
     changes[i] = null;
     deletions[i] = nd1;
     insertions[i] = null;
     differences.NumberOfDifferences += 1;
   }
   //Find insertions
   for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){
     //^ assert list2 != null;
     Interface nd2 = list2[j]; 
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     insertions[n+j] = nd2;  //Records nd2 as an insertion into list1, along with its position in list2
     differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here?
   }
   if (differences.NumberOfDifferences == 0){
     changes = null;
     deletions = null;
     insertions = null;
   }
   return differences;
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Computes an upper bound in the type hierarchy for the set of argument types.
    /// This upper bound is a type that all types in the list are assignable to.
    /// If the types are all classes, then *the* least-upper-bound in the class
    /// hierarchy is returned.
    /// If the types contain at least one interface, then *a* deepest upper-bound
    /// is found from the intersection of the upward closure of each type.
    /// Note that if one of the types is System.Object, then that is immediately
    /// returned as the unified type without further examination of the list.
    /// </summary>
    /// <param name="ts">A list containing the set of types from which to compute the unified type.</param>
    /// <returns>The type corresponding to the least-upper-bound.</returns>
    public virtual TypeNode UnifiedType(TypeNodeList ts, TypeViewer typeViewer){
      if (ts == null || ts.Count == 0) return null;
      TypeNode unifiedType = SystemTypes.Object; // default unified type
      bool atLeastOneInterface = false;
      #region If at least one of the types is System.Object, then that is the unified type
      for (int i = 0, n = ts.Count; i < n; i++){
        TypeNode t = this.Unwrap(ts[i]);
        if (t == SystemTypes.Object){
          return SystemTypes.Object;
        }
      }
      #endregion If at least one of the types is System.Object, then that is the unified type
      // assert forall{TypeNode t in ts; t != SystemTypes.Object};
      #region See if any of the types are interfaces
      for (int i = 0, n = ts.Count; i < n; i++){
        TypeNode t = this.Unwrap(ts[i]);
        if (t.NodeType == NodeType.Interface){
          atLeastOneInterface = true;
          break;
        }
      }
      #endregion See if any of the types are interfaces

      #region Find the LUB in the class hierarchy (if there are no interfaces)
      if (!atLeastOneInterface){
        TrivialHashtable h = new TrivialHashtable(ts.Count);
        // Create the list [s, .., t] for each element t of ts where for each item
        // in the list, t_i, t_i = t_{i+1}.BaseType. (s.BaseType == SystemTypes.Object)
        // Store the list in a hashtable keyed by t.
        // Do this only for classes. Handle interfaces in a different way because of
        // multiple inheritance.
        for (int i = 0, n = ts.Count; i < n; i++){
          TypeNodeList tl = new TypeNodeList();
          TypeNode t = this.Unwrap(ts[i]);
          tl.Add(t);
          TypeNode t2 = t.BaseType;
          while (t2 != null && t2 != SystemTypes.Object){ // avoid including System.Object in the list for classes
            tl.Insert(t2,0);
            t2 = this.Unwrap(t2.BaseType);
          }
          h[ts[i].UniqueKey] = tl;
        }
        bool stop = false;
        int depth = 0;
        while (!stop){
          TypeNode putativeUnifiedType = null;
          int i = 0;
          int n = ts.Count;
          putativeUnifiedType = ((TypeNodeList) h[ts[0].UniqueKey])[depth];
          while (i < n){
            TypeNode t = ts[i];
            TypeNodeList subTypes = (TypeNodeList) h[t.UniqueKey];
            if (subTypes.Count <= depth || subTypes[depth] != putativeUnifiedType){
              // either reached the top of the hierarchy for t_i or it is on a different branch
              // than the current one.
              stop = true;
              break;
            }
            i++;
          }
          if (i == n){ // made it all the way through: all types are subtypes of the current one
            unifiedType = putativeUnifiedType;
          }
          depth++;
        }
      }
      #endregion Find the LUB in the class hierarchy (if there are no interfaces)
      #region Find *a* LUB in the interface hierarchy (if there is at least one interface or current LUB is object)
      if (unifiedType == SystemTypes.Object || atLeastOneInterface){
        TrivialHashtable interfaces = new TrivialHashtable();
        for (int i = 0, n = ts.Count; i < n; i++){
          InterfaceList il = new InterfaceList();
          interfaces[ts[i].UniqueKey] = il;
          this.SupportedInterfaces(ts[i],il,typeViewer); // side-effect: il gets added to
        }
        // interfaces[ts[i]] is the upward closure of all of the interfaces supported by ts[i]
        // compute the intersection of all of the upward closures
        // might as well start with the first type in the list ts
        InterfaceList intersection = new InterfaceList();
        InterfaceList firstIfaceList = (InterfaceList)interfaces[ts[0].UniqueKey];
        for (int i = 0, n = firstIfaceList.Count; i < n; i++){
          Interface iface = firstIfaceList[i];
          bool found = false;
          int j = 1; // start at second type in the list ts
          while (j < ts.Count){
            InterfaceList cur = (InterfaceList)interfaces[ts[j].UniqueKey];
            found = false;
            for (int k = 0, p = cur.Count; k < p; k++){
              if (cur[k] == iface){
                found = true;
                break;
              }
            }
            if (!found){
              // then the j-th type doesn't support iface, don't bother looking in the rest
              break;
            }
            j++;
          }
          if (found){
            intersection.Add(iface);
          }
        }
        // TODO: take the "deepest" interface in the intersection.
        // "deepest" means that if any other type in the intersection is a subtype
        // of it, then *don't* consider it.
        if (intersection.Count > 0){
          InterfaceList finalIntersection = new InterfaceList(intersection.Count);
          Interface iface = intersection[0];
          for (int i = 0, n = intersection.Count; i < n; i++){
            Interface curFace = intersection [i];
            int j = 0;
            int m = intersection.Count;
            while (j < m){
              if (j != i){
                Interface jFace = intersection[j];
                if (TypeViewer.GetTypeView(typeViewer, jFace).IsAssignableTo(curFace))
                  break;
              }
              j++;
            }
            if (j == m){ // made it all the way through, no other iface is a subtype of curFace
              finalIntersection.Add(curFace);
            }
          }
          if (finalIntersection.Count > 0){
            unifiedType = finalIntersection[0]; // heuristic: just take the first one
          }
        }
      }
      #endregion Find *a* LUB in the interface hierarchy (if there is at least one interface or current LUB is object)
      return unifiedType;
    }
Ejemplo n.º 11
0
 public virtual void SupportedInterfaces(TypeNode t, InterfaceList ifaceList, TypeViewer typeViewer){
   if (ifaceList == null) return;
   TypeNode unwrappedT = this.Unwrap(t);
   Interface iface = unwrappedT as Interface;
   if (iface != null){
     // possibly not needed, but seems better to keep ifaceList as a set
     int i = 0;
     while (i < ifaceList.Count){
       if (ifaceList[i] == iface)
         break;
       i++;
     }
     if (i == ifaceList.Count) // not found
       ifaceList.Add(iface);
   }else{
     // nop
   }
   InterfaceList ifaces = TypeViewer.GetTypeView(typeViewer, unwrappedT).Interfaces;
   for (int i = 0, n = ifaces == null ? 0 : ifaces.Count; i < n; i++){
     this.SupportedInterfaces(ifaces[i],ifaceList,typeViewer);
   }
   return;
 }
Ejemplo n.º 12
0
 private InterfaceList ParseInterfaceList(TokenSet followers, bool expectLeftBrace){
   InterfaceList ilist = new InterfaceList();
   TokenSet followersOrComma = followers|Token.Comma;
   for(;;){
     Expression id = this.scanner.GetIdentifier();
     switch(this.currentToken){
       case Token.Bool:
       case Token.Decimal:
       case Token.Sbyte:
       case Token.Byte:
       case Token.Short:
       case Token.Ushort:
       case Token.Int:
       case Token.Uint:
       case Token.Long:
       case Token.Ulong:
       case Token.Char:
       case Token.Float:
       case Token.Double:
       case Token.Object:
       case Token.String:
       case Token.Void:
         TypeExpression texpr = this.TypeExpressionFor(this.currentToken);
         this.GetNextToken();
         ilist.Add(new InterfaceExpression(texpr.Expression, texpr.SourceContext));
         goto lookForComma;
       default:
         bool idOK = Parser.IdentifierOrNonReservedKeyword[this.currentToken];
         if (idOK){
           this.GetNextToken();
           if (this.currentToken == Token.DoubleColon){
             this.GetNextToken();
             Identifier id2 = this.scanner.GetIdentifier();
             id2.Prefix = (Identifier)id;
             id2.SourceContext.StartPos = id.SourceContext.StartPos;
             this.SkipIdentifierOrNonReservedKeyword();
             id = id2;
           }
           if (this.currentToken == Token.Dot)
             id = this.ParseQualifiedIdentifier(id, followersOrComma|Token.LessThan);
         }else{
           int col = this.scanner.endPos;
           this.SkipIdentifierOrNonReservedKeyword(Error.TypeExpected);
           if (col == this.scanner.endPos && this.currentToken != Token.EndOfFile){
             //Did not consume a token, but just gave an error
             if (!followersOrComma[this.currentToken]) this.GetNextToken();
             if (followers[this.currentToken]) return ilist;
             if (this.currentToken != Token.Comma){
               if (Parser.IdentifierOrNonReservedKeyword[this.currentToken]) continue;
               break;
             }
             this.GetNextToken();
             continue;
           }
           if (this.currentToken == Token.Dot)
             id = this.ParseQualifiedIdentifier(id, followersOrComma|Token.LessThan);
           if (!idOK) goto lookForComma;
         }
         break;
     }
     //I really want an Identifier here for StartName
     if (this.sink != null) {
       Identifier name = id as Identifier;
       if (id is QualifiedIdentifier) {
         name = ((QualifiedIdentifier)id).Identifier;
       }
       if (name != null) {
         this.sink.StartName(name);
       }
     }
     InterfaceExpression ifaceExpr = new InterfaceExpression(id, id.SourceContext);
     if (this.currentToken == Token.LessThan){
     yetAnotherTypeArgumentList:
       this.GetNextToken();
       TypeNodeList arguments = new TypeNodeList();
       for(;;){
         TypeNode t = this.ParseTypeExpression(null, followers|Token.Comma|Token.GreaterThan);
         arguments.Add(t);
         if (this.currentToken != Token.Comma) break;
         this.GetNextToken();
       }
       ifaceExpr.TemplateArguments = arguments;
       ifaceExpr.TemplateArgumentExpressions = arguments.Clone();
       ifaceExpr.SourceContext.EndPos = this.scanner.endPos;
       this.Skip(Token.GreaterThan);
       if (this.currentToken == Token.Dot) {
         TemplateInstance tempInst = new TemplateInstance(ifaceExpr.Expression, ifaceExpr.TemplateArguments);
         tempInst.TypeArgumentExpressions = ifaceExpr.TemplateArguments == null ? null : ifaceExpr.TemplateArguments.Clone();
         tempInst.SourceContext = ifaceExpr.SourceContext;
         ifaceExpr.Expression = this.ParseQualifiedIdentifier(tempInst, followersOrComma|Token.LessThan);
         ifaceExpr.TemplateArguments = null;
         ifaceExpr.TemplateArgumentExpressions = null;
         if (ifaceExpr.Expression != null) ifaceExpr.SourceContext = ifaceExpr.Expression.SourceContext;
         if (this.currentToken == Token.LessThan) goto yetAnotherTypeArgumentList;
       }
     }
     ilist.Add(ifaceExpr);
   lookForComma:
     if (Parser.TypeOperator[this.currentToken] && !(expectLeftBrace && this.currentToken == Token.LeftBrace)){
       this.HandleError(Error.BadBaseType);
       this.GetNextToken();
       if (this.currentToken == Token.RightBracket || this.currentToken == Token.RightBrace)
         this.GetNextToken();
       this.SkipTo(followersOrComma, Error.None);
     }else if (!followersOrComma[this.currentToken])
       this.SkipTo(followersOrComma, Error.TypeExpected);
     if (this.currentToken == Token.Comma){
       if (followers[Token.Comma] && followers[Token.GreaterThan])
         break; //Parsing the constraint of a type parameter
       this.GetNextToken();
       if (expectLeftBrace && (this.currentToken == Token.Class || this.currentToken == Token.Struct || this.currentToken == Token.New))
         break;
     }else if (!Parser.TypeStart[this.currentToken] || this.currentToken == Token.Where)
       break;
     else if (Parser.ContractStart[this.currentToken])
       break;
   }
   return ilist;
 }
Ejemplo n.º 13
0
 private InterfaceList TranslateToInterfaceList(CodeTypeReferenceCollection interfaces){
   int n = interfaces == null ? 0 : interfaces.Count;
   InterfaceList interfaceList = new InterfaceList(n);
   for (int i = 0; i < n; i++)
     interfaceList.Add(this.TranslateToInterface(interfaces[i]));
   return interfaceList;
 }
Ejemplo n.º 14
0
 private InterfaceList FindMatchingInterfaces(Class c, ZMethod zMethod)
 {
     InterfaceList matches = new InterfaceList(1);
     if (c.Interfaces != null && c.Interfaces.Count > 0)
     {
         for (int i = 0; i < c.Interfaces.Count; i++)
         {
             Interface x = c.Interfaces[i];
             if (x.GetMatchingMethod(zMethod) != null)
                 matches.Add(x);
         }
     }
     return matches;
 }
Ejemplo n.º 15
0
 private void GetInterfaces(int i, int firstInterfaceIndex, InterfaceList/*!*/ interfaces)
 {
     InterfaceImplRow[] intfaces = this.tables.InterfaceImplTable;
     for (int j = firstInterfaceIndex, n = intfaces.Length; j < n; j++)
     {
         if (intfaces[j].Class != i) continue; //TODO: break if sorted
         TypeNode ifaceT = this.DecodeAndGetTypeDefOrRefOrSpec(intfaces[j].Interface);
         Interface iface = ifaceT as Interface;
         if (iface == null)
         {
             iface = new Interface();
             if (ifaceT != null)
             {
                 iface.DeclaringModule = ifaceT.DeclaringModule;
                 iface.Namespace = ifaceT.Namespace;
                 iface.Name = ifaceT.Name;
             }
         }
         interfaces.Add(iface);
     }
 }
Ejemplo n.º 16
0
 private void GetGenericParameterConstraints(int index, ref TypeNode/*!*/ parameter)
 {
     Debug.Assert(parameter != null);
     index++;
     GenericParamConstraintRow[] genericParameterConstraints = this.tables.GenericParamConstraintTable;
     TypeNodeList constraints = new TypeNodeList();
     Class baseClass = null;
     InterfaceList interfaces = new InterfaceList();
     int i = 0, n = genericParameterConstraints.Length, j = n - 1;
     bool sorted = (this.sortedTablesMask >> (int)TableIndices.GenericParamConstraint) % 2 == 1;
     if (sorted)
     {
         while (i < j)
         {
             int k = (i + j) / 2;
             if (genericParameterConstraints[k].Param < index)
                 i = k + 1;
             else
                 j = k;
         }
         while (i > 0 && genericParameterConstraints[i - 1].Param == index) i--;
     }
     for (; i < n; i++)
     {
         if (genericParameterConstraints[i].Param == index)
         {
             TypeNode t = this.DecodeAndGetTypeDefOrRefOrSpec(genericParameterConstraints[i].Constraint);
             Class c = t as Class;
             if (c != null)
                 baseClass = c;
             else if (t is Interface)
                 interfaces.Add((Interface)t);
             constraints.Add(t);
         }
         else if (sorted)
             break;
     }
     ClassParameter cp = parameter as ClassParameter;
     if (cp == null && baseClass != null)
     {
         cp = ((ITypeParameter)parameter).DeclaringMember is Method ? new MethodClassParameter() : new ClassParameter();
         cp.Name = parameter.Name;
         cp.DeclaringMember = ((ITypeParameter)parameter).DeclaringMember;
         cp.ParameterListIndex = ((ITypeParameter)parameter).ParameterListIndex;
         cp.DeclaringModule = this.module;
         cp.TypeParameterFlags = ((ITypeParameter)parameter).TypeParameterFlags;
         parameter = cp;
     }
     if (cp != null)
         cp.structuralElementTypes = constraints;
     else
         ((TypeParameter)parameter).structuralElementTypes = constraints;
     if (baseClass != null && cp != null) cp.BaseClass = baseClass;
     parameter.Interfaces = interfaces;
 }
Ejemplo n.º 17
0
 public virtual void VisitBaseClassReference(Class Class){
   if (Class == null) return;
   if (Class.Name.UniqueIdKey == StandardIds.CapitalObject.UniqueIdKey && Class.Namespace.UniqueIdKey == StandardIds.System.UniqueIdKey) {
     Class.BaseClass = null; Class.BaseClassExpression = null;
     return;
   }
   if (Class.PartiallyDefines is Class && ((Class)Class.PartiallyDefines).BaseClass == null) 
     this.VisitBaseClassReference((Class)Class.PartiallyDefines);
   TypeNodeList partialTypes = Class.IsDefinedBy;
   if (partialTypes != null){
     for (int i = 0, n = partialTypes == null ? 0 : partialTypes.Count; i < n; i++){
       Class partialClass = partialTypes[i] as Class;
       if (partialClass == null || partialClass.BaseClass == SystemTypes.Object) continue;
       partialClass.PartiallyDefines = null; //Stop recursion
       this.VisitBaseClassReference(partialClass);
       partialClass.PartiallyDefines = Class;
       if (partialClass.BaseClass == SystemTypes.Object) continue;
       Class.BaseClass = partialClass.BaseClass;
       return;
     }
   }
   //Visit Class.BaseClass, but guard against doing it twice 
   //(this routine can get called when visiting a derived class that occurs lexically before Class)
   if (Class.BaseClassExpression == Class) return; //Still resolving the base class. This is a recursive call due to a recursive type argument.
   if (Class.BaseClass != null) {
     ClassExpression cExpr = Class.BaseClass as ClassExpression;
     if (cExpr == null) return; //Been here before and found a base class
     this.VisitBaseClassReference(Class, true);
     return;
   }
   //Leaving the BaseClass null is the convention for asking that the first expression in the interface list be treated as the base class, if possible.
   //If not possible, the convention is to set BaseClass equal to SystemTypes.Object.
   InterfaceList interfaces = Class.Interfaces;
   InterfaceList interfaceExpressions = Class.InterfaceExpressions;
   if (interfaces != null && interfaces.Count > 0){
     Interface iface = interfaces[0];
     InterfaceExpression ifExpr = iface as InterfaceExpression;
     if (ifExpr != null){
       ClassExpression cExpr = new ClassExpression(ifExpr.Expression, ifExpr.TemplateArguments, ifExpr.SourceContext);
       Class.BaseClass = Class.BaseClassExpression = cExpr;
       if (this.VisitBaseClassReference(Class, false)){
         //The first expression is not meant as an interface, remove it from the list
         int n = interfaces.Count-1;
         InterfaceList actualInterfaces = new InterfaceList(n);
         InterfaceList actualInterfaceExpressions = new InterfaceList(n);
         for (int i = 0; i < n; i++) {
           actualInterfaces.Add(interfaces[i+1]);
           if (interfaceExpressions != null)
             actualInterfaceExpressions.Add(interfaceExpressions[i+1]);
         }
         Class.Interfaces = actualInterfaces;
         if (interfaceExpressions != null)
           Class.InterfaceExpressions = actualInterfaceExpressions;
       }else{
         Class.BaseClass = SystemTypes.Object; Class.BaseClassExpression = null;
       }
     }else{
       Class.BaseClass = SystemTypes.Object; Class.BaseClassExpression = null;
     }
   }else{
     Class.BaseClass = SystemTypes.Object; Class.BaseClassExpression = null;
   }
   if (Class.BaseClass != null && Class.BaseClass != SystemTypes.Object) {
     this.VisitBaseClassReference(Class.BaseClass.Template as Class);
     this.VisitBaseClassReference(Class.BaseClass);
   }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// 注册需要的接口实现
 /// </summary>
 /// <typeparam name="T">接口</typeparam>
 /// <typeparam name="TK">实现类</typeparam>
 public void Register <T, TK>() where T : class where TK : T
 {
     ObjectContainer.Register(Castle.MicroKernel.Registration.
                              Component.For <T>().ImplementedBy <TK>());
     InterfaceList.Add(typeof(T));
 }