Example #1
0
        public IDictionary <string, ITypeReference> GetTypeReferenceListing()
        {
            Dictionary <string, ITypeReference> result = new Dictionary <string, ITypeReference>();
            ITypeParameterMembers tParams = this;
            IDeclarationTarget    target  = this.TargetDeclaration;

            while (target != null)
            {
                foreach (ITypeParameterMember arg in tParams.Values)
                {
                    result.Add(arg.Name, arg.GetTypeReference());
                }
                if (target.ParentTarget != null)
                {
                    target = target.ParentTarget;
                }
                if (target is IParameteredDeclaredType)
                {
                    tParams = ((IParameteredDeclaredType)target).TypeParameters;
                }
                else
                {
                    target = null;
                }
            }
            return(result);
        }
Example #2
0
        public BreakStatement(IStatementBlock sourceBlock)
            : base(sourceBlock)
        {
            IStatementBlockLocalMember local     = null;
            IBreakTargetExitPoint      exitPoint = null;
            IDeclarationTarget         parent    = sourceBlock;

            //Search up for the block that needs the break.
            while (parent != null && local == null)
            {
                if (parent is IBreakTargetStatement)
                {
                    local     = ((IBreakTargetStatement)parent).BreakLocal;
                    exitPoint = ((IBreakTargetStatement)parent).ExitLabel;
                    ((IBreakTargetStatement)parent).UtilizeBreakMeasures = true;
                    break;
                }
                parent = parent.ParentTarget;
            }
            if (local == null && !(sourceBlock.Parent is ISwitchStatementCase))
            {
                throw new InvalidOperationException("Cannot insert a break into a non-terminable block.");
            }
            this.terminalVariable = local;
            this.exitSymbol       = exitPoint;
        }
Example #3
0
        public IIntermediateProject AddNew(IDeclarationTarget parentTarget)
        {
            IIntermediateProject iip = new IntermediateProject(this.RootDeclaration);

            iip.ParentTarget = parentTarget;
            lock (this.baseList)
                this.baseList.Add(iip);
            return(iip);
        }
Example #4
0
        private string Obfuscate(string p, IDeclarationTarget target)
        {
            string result;
            string oP = p;

            p += target.ToString();
            if (!obfuscations.TryGetValue(p, out result))
            {
                int           l  = (int)r.Next(1, oP.Length);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < l; i++)
                {
                    char current = p[r.Next(0, p.Length)];
                    switch (current)
                    {
                    case '[':
                    case ']':
                        current = 'Ø';
                        break;

                    case ':':
                    case '.':
                    case ',':
                    case ' ':
                    case '+':
                        current = '_';
                        break;

                    case '(':
                    case ')':
                        current = 'µ';
                        break;

                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        if (i == 0)
                        {
                            current = (char)('ⅰ' + (current - '0'));
                        }
                        break;
                    }
                    sb.Append(current);
                }
                result = sb.ToString();
                obfuscations.Add(p, result);
            }
            return(result);
        }
Example #5
0
            internal static bool ImplementsNameCollideCheck(IDeclarationTarget source, string interfaceName, ICodeTranslationOptions options)
            {
                IDeclarationTarget idt = source;
                string             shortInterfaceName = interfaceName;

                if (shortInterfaceName.Contains("."))
                {
                    shortInterfaceName = shortInterfaceName.Substring(shortInterfaceName.LastIndexOf('.') + 1);
                }
                int  hitCount    = 0;
                bool autoResolve = options.AutoResolveReferences;

                if (autoResolve)
                {
                    options.AutoResolveReferences = false;
                }
                List <string> names = new List <string>();

                while (idt != null)
                {
                    if (idt is IInterfaceImplementableType)
                    {
                        IInterfaceImplementableType parent = (IInterfaceImplementableType)idt;
                        foreach (ITypeReference itr in parent.ImplementsList)
                        {
                            string shortCurrentName;
                            string currentName = itr.TypeInstance.GetTypeName(options);
                            if (currentName.Contains("."))
                            {
                                shortCurrentName = currentName.Substring(currentName.LastIndexOf('.') + 1);
                            }
                            else
                            {
                                shortCurrentName = currentName;
                            }
                            //Increment the hit count if the short name of the current
                            //interface equals that of the one requested.  And if the exact
                            //name hasn't been encountered yet.  If it hasn't then it's a valid match
                            //otherwise it's just the same exact one.
                            if (shortCurrentName == shortInterfaceName && !names.Contains(currentName))
                            {
                                hitCount++;
                            }
                            names.Add(currentName);
                        }
                    }
                    idt = idt.ParentTarget;
                }
                if (autoResolve)
                {
                    options.AutoResolveReferences = autoResolve;
                }
                return(hitCount > 1);
            }
Example #6
0
        /// <summary>
        /// Returns the number of members in the declarations that target what's provided.
        /// </summary>
        /// <param name="target">The member to check which target.</param>
        /// <returns>An integer containing the number of members that are children of the <paramref name="target"/>.</returns>
        public int GetCountForTarget(IDeclarationTarget target)
        {
            int count = 0;

            foreach (TItem member in this.Values)
            {
                if (member.ParentTarget.Equals(target))
                {
                    count++;
                }
            }
            return(count);
        }
Example #7
0
            /// <summary>
            /// Determines whether the <paramref name="declaration"/> is a candidate for a module in
            /// the Visual Basic.NET language.
            /// </summary>
            /// <param name="declaration">The <see cref="IDeclarationTarget"/> to check to see if it
            /// is a vb module candidate.</param>
            /// <returns>true if the <paramref name="declaration"/> is a valid candidate.</returns>
            /// <remarks>If the <paramref name="declaration"/> is a valid candidate, the translator
            /// will flatten the partial hierarchy using the options' <see cref="ICodeTranslationOptions.AllowPartials"/> property.</remarks>
            internal static bool DeclarationIsVBModuleCandidate(IDeclarationTarget declaration)
            {
                if (!(declaration is IClassType))
                {
                    return(false);
                }
                IClassType @class = (IClassType)declaration;

                if ((@class.TypeParameters == null || @class.TypeParameters.Count == 0) && @class.IsStatic)
                {
                    return(@class.ParentTarget is INameSpaceDeclaration && @class.Partials.Count == 0);
                }
                return(false);
            }
Example #8
0
        private void InitializeNameSpaceDependencies()
        {
            if (!this.initialized)
            {
                Begin();
            }
            List <string> result = new List <string>();

            foreach (ITypeReference itr in this.sourceData)
            {
                IType it = itr.TypeInstance;
                if (it is IDeclaredType)
                {
                    IDeclarationTarget idt = (IDeclarationTarget)it;
                    while (idt != null && (!(idt is INameSpaceDeclaration)))
                    {
                        idt = idt.ParentTarget;
                    }
                    if (idt is INameSpaceDeclaration)
                    {
                        if (!result.Contains(((INameSpaceDeclaration)(idt)).FullName))
                        {
                            result.Add(((INameSpaceDeclaration)(idt)).FullName);
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (it is IExternType)
                {
                    if (((IExternType)(it)).Type.IsGenericParameter)
                    {
                        continue;
                    }
                    if ((!(result.Contains(((IExternType)(it)).Type.Namespace))))
                    {
                        result.Add(((IExternType)(it)).Type.Namespace);
                    }
                }
                else
                {
                    continue;
                }
            }
            result.Sort(nsSorter);
            this.nameSpaceDependencies = result;
        }
Example #9
0
        public INameSpaceDeclaration GetNamespace()
        {
            IDeclarationTarget current = this;

            while (!((current is INameSpaceDeclaration) || (current == null)))
            {
                current = current.ParentTarget;
            }

            /* *
             * The condition of the iteration determines whether this is null.
             * If the parent item is null, or a namespace, it should be valued
             * accordingly.
             * */
            return((INameSpaceDeclaration)current);
        }
Example #10
0
            internal static void GetDeclaredHierarchy(IDeclaredTypeReference typeReference, ITypeReferenceCollection typeParameters, out List <IDeclaredType> hierarchy, out Stack <ITypeReference> typeParamsStack)
            {
                IDeclaredType type = typeReference.TypeInstance;

                hierarchy = new List <IDeclaredType>();
                List <ITypeReference> typeParams = new List <ITypeReference>(typeParameters);

                typeParams.Reverse();
                typeParamsStack = new Stack <ITypeReference>(typeParams);

                for (IDeclarationTarget iDecTar = type; iDecTar != null && iDecTar is IDeclaredType; iDecTar = iDecTar.ParentTarget)
                {
                    hierarchy.Add((IDeclaredType)iDecTar);
                }
                hierarchy.Reverse();
            }
Example #11
0
        private static IList <IDeclarationTarget> GetDeclarationHierarchy(IDeclarationTarget source)
        {
            Stack <IDeclarationTarget> stack   = new Stack <IDeclarationTarget>();
            List <IDeclarationTarget>  result  = new List <IDeclarationTarget>();
            IDeclarationTarget         current = source;

            while (!((current is INameSpaceDeclaration) || (current == null)))
            {
                stack.Push(current);
                current = current.ParentTarget;
            }
            while (stack.Count > 0)
            {
                result.Add(stack.Pop());
            }
            return(result);
        }
Example #12
0
        protected virtual ITypeReferenceCollection FillInTypeParameters(ITypeReferenceCollection originalSet)
        {
            List <IDeclarationTarget> parents = new List <IDeclarationTarget>();
            ITypeReferenceCollection  resultSet;

            if (originalSet == null)
            {
                resultSet = new TypeReferenceCollection();
            }
            else
            {
                resultSet = new TypeReferenceCollection(originalSet.ToArray());
            }
            for (IDeclarationTarget parent = this; ((parent != null) && (!(parent is INameSpaceDeclaration))); parent = parent.ParentTarget)
            {
                parents.Add(parent);
            }
            parents.Reverse();
            int skip = 0;

            for (IDeclarationTarget parent = parents[0]; parents.Count > 0; parents.RemoveAt(0), parent = parents.Count > 0 ? parents[0] : null)
            {
                if (parent is IParameteredDeclaredType)
                {
                    if (((IParameteredDeclaredType)parent).TypeParameters == null)
                    {
                        continue;
                    }
                    foreach (ITypeParameterMember itpm in ((IParameteredDeclaredType)parent).TypeParameters.Values)
                    {
                        if (skip++ >= resultSet.Count)
                        {
                            resultSet.Add(itpm);
                        }
                    }
                }
            }
            return(resultSet);
        }
Example #13
0
        public string WriteResources()
        {
            IDeclarationTarget idt = null;

            if (this.IsPartial)
            {
                return(null);
            }
            for (idt = this; idt != null && (!(idt is INameSpaceDeclaration)); idt = idt.ParentTarget)
            {
                ;
            }
            if ((idt == null) || (!(idt is INameSpaceDeclaration)))
            {
                throw new InvalidOperationException("Object in an invalid state.");
            }
            INameSpaceDeclaration insd = (INameSpaceDeclaration)idt;
            TemporaryFile         tf;

            if (this == this.Project.Resources)
            {
                tf = TemporaryFileHelper.GetTemporaryDirectory("", true).Files.GetTemporaryFile(string.Format("Resources.resources", insd.FullName, this.Name));
            }
            else
            {
                tf = TemporaryFileHelper.GetTemporaryDirectory("", true).Files.GetTemporaryFile(string.Format("{0}.{1}.resources", insd.FullName, this.Name));
            }

            tf.OpenStream(FileMode.Create);
            ResourceWriter rw = new ResourceWriter(tf.FileStream);

            foreach (IDeclarationResourcesStringTableEntry idrste in this.StringTable.Values)
            {
                rw.AddResource(idrste.Name, idrste.Value);
            }
            rw.Close();
            tf.CloseStream();
            return(tf.FileName);
        }
Example #14
0
            internal static bool DeclarationIsVBModule(IDeclarationTarget declaration, IIntermediateCodeTranslatorOptions options)
            {
                if (!(declaration is IClassType))
                {
                    return(false);
                }
                IClassType @class = (IClassType)declaration;

                if (@class.TypeParameters == null || @class.TypeParameters.Count == 0)
                {
                    if (@class.ParentTarget is INameSpaceDeclaration && @class.IsStatic)
                    {
                        if (options.AllowPartials)
                        {
                            //Basically if all other partials have no members,
                            //Then it means that it is still a module.
                            foreach (IClassType ict in @class.GetRootDeclaration().Partials)
                            {
                                if (ict == @class)
                                {
                                    continue;
                                }
                                else if (ict.GetMemberCount(false) > 0 || ict.GetTypeCount(false) > 0)
                                {
                                    return(false);
                                }
                            }
                            if (@class != @class.GetRootDeclaration() && @class.GetRootDeclaration().GetMemberCount(false) > 0)
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
Example #15
0
 TItem ISegmentableDeclarationTargetPartials <TItem> .AddNew(IDeclarationTarget parentTarget)
 {
     return(this.AddNew((ITypeParent)parentTarget));
 }
Example #16
0
            public static string BuildMemberReferenceComment(ICodeTranslationOptions options, IMember member)
            {
                if (options == null)
                {
                    throw new ArgumentNullException("options");
                }
                string parentCref = ((IType)member.ParentTarget).GetTypeName(options, true);

                //If there is a build trail to go by, check to see what kind of scope
                //is available.  If the parent of the field is available, then referencing
                //field should be easier.
                if (options.BuildTrail != null)
                {
                    IDeclarationTarget idt = member.ParentTarget;
                    while (idt != null && !(idt is INameSpaceDeclaration))
                    {
                        idt = idt.ParentTarget;
                    }
                    INameSpaceDeclaration currentNameSpace = null;
                    bool importsContainsNameSpace          = false;
                    if (idt != null && options.ImportList != null)
                    {
                        importsContainsNameSpace = options.ImportList.Contains(((INameSpaceDeclaration)(idt)).FullName);
                    }
                    if (!importsContainsNameSpace)
                    {
                        for (int i = 0; i < options.BuildTrail.Count; i++)
                        {
                            if (Special.GetThisAt(options.BuildTrail, i) is INameSpaceDeclaration)
                            {
                                currentNameSpace = (INameSpaceDeclaration)Special.GetThisAt(options.BuildTrail, i);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (currentNameSpace != null && idt != null && (currentNameSpace.FullName == ((INameSpaceDeclaration)idt).FullName || currentNameSpace.FullName.Contains(((INameSpaceDeclaration)idt).FullName + ".")))
                    {
                        /* *
                         * The build trail's current namespace contains the full name of the
                         * parent namespace.
                         * */
                        parentCref = parentCref.Substring(currentNameSpace.FullName.Length + 1);
                    }
                    else if (importsContainsNameSpace)
                    {
                        /* *
                         * The import list contains the namespace
                         * */
                        parentCref = parentCref.Substring(((INameSpaceDeclaration)idt).FullName.Length + 1);
                    }
                    else
                    {
                        goto _verbose;
                    }
                }
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));

_verbose:
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));
            }
Example #17
0
 ISegmentableDeclarationTarget ISegmentableDeclarationTargetPartials.AddNew(IDeclarationTarget parentTarget)
 {
     return(this.AddNew((INameSpaceParent)parentTarget));
 }
Example #18
0
 /// <summary>
 /// Creates a new <see cref="BlockedStatement{TDom}"/> with the <paramref name="sourceBlock"/>
 /// provided.
 /// </summary>
 /// <param name="sourceBlock">The target point which the <see cref="BlockedStatement{TDom}"/> is
 /// created in.</param>
 protected BlockedStatement(IStatementBlock sourceBlock)
     : base(sourceBlock)
 {
     this.parentTarget = sourceBlock;
 }