示例#1
0
        public static AbstractType Demangle(string mangledString, ResolutionContext ctxt, out ITypeDeclaration qualifier, out bool isCFunction)
        {
            if(string.IsNullOrEmpty(mangledString))
                throw new ArgumentException("input string must not be null or empty!");

            if (!mangledString.StartsWith("_D"))
            {
                isCFunction = true;

                if (mangledString.StartsWith ("__D"))
                    mangledString = mangledString.Substring (1);
                // C Functions
                else if (mangledString.StartsWith ("_")) {
                    qualifier = new IdentifierDeclaration (mangledString.Substring (1));
                    return null;
                }
            }

            //TODO: What about C functions that start with 'D'?
            isCFunction = false;

            var dmng = new Demangler(mangledString) { ctxt = ctxt };

            return dmng.MangledName(out qualifier);
        }
示例#2
0
        private IModule GetModule(ITypeReference typeReference)
        {
            if (typeReference != null)
            {
                if (typeReference.GenericType != null)
                {
                    typeReference = typeReference.GenericType;
                }

                ITypeDeclaration typeDeclaration = typeReference.Resolve();
                if (typeDeclaration != null)
                {
                    do
                    {
                        IModule module = typeDeclaration.Owner as IModule;
                        if (module != null)
                        {
                            return(module);
                        }

                        typeDeclaration = typeDeclaration.Owner as ITypeDeclaration;
                    }while (typeDeclaration != null);
                }
            }
            return(null);
        }
示例#3
0
 protected internal EqualFormulaRef(IFormulaRef left, IFormulaRef right, ITypeDeclaration type, IMethodDeclaration method, IFormulaRef parent)
     : base(left, right, type, method, parent)
 {
     this.parent = parent;
     this.left = left;
     this.right = right;
 }
示例#4
0
        public override ITypeDeclaration Transform(ITypeDeclaration itd)
        {
            analysis = new MethodAnalysisTransform();
            Stopwatch watch = null;

            if (compiler.ShowProgress)
            {
                Console.Write($"({analysis.Name} ");
                watch = Stopwatch.StartNew();
            }
            analysis.Context.InputAttributes = context.InputAttributes;
            analysis.Transform(itd);
            if (compiler.ShowProgress)
            {
                watch.Stop();
                Console.Write("{0}ms) ", watch.ElapsedMilliseconds);
            }
            context.Results = analysis.Context.Results;
            if (!context.Results.IsSuccess)
            {
                Error("analysis failed");
                return(itd);
            }
            if (debug)
            {
                Trace.WriteLine("method graph:");
                Trace.WriteLine(analysis.MethodGraph);
            }
            Initialise();
            CheckAcyclic(analysis.MethodGraph);
            // collect the set of public methods
            foreach (var methodIndex in analysis.MethodGraph.Nodes)
            {
                if (analysis.methods[methodIndex].Declaration.Visibility.HasFlag(MethodVisibility.Public))
                {
                    publicMethods.Add(methodIndex);
                }
            }
            detailsOfMethod = Util.ArrayInit(analysis.MethodGraph.Nodes.Count, methodIndex => new MethodDetails());
            // runs faster with CallersBeforeCallees
            var methodOrder = GetCallersBeforeCallees(analysis.MethodGraph);

            methodsToAnalyze.AddRange(methodOrder);
            while (methodsToAnalyze.Count > 0)
            {
                foreach (int methodIndex in methodOrder)
                {
                    if (methodsToAnalyze.Contains(methodIndex))
                    {
                        // AnalyzeMethod may add new methods to methodsToAnalyze.
                        AnalyzeMethod(methodIndex);
                    }
                }
            }
            if (debug)
            {
                Trace.WriteLine($"{this.Name}: {analysis.MethodGraph.Nodes.Count} methods, {methodsAnalyzedCount} methods analyzed");
            }
            return(itd);
        }
        public static IExpression TryConvertTypeDeclaration(ITypeDeclaration td, bool ignoreInnerDeclaration = false)
        {
            if (td.InnerDeclaration == null || ignoreInnerDeclaration)
            {
                if (td is IdentifierDeclaration)
                {
                    var id = td as IdentifierDeclaration;
                    if (id.Id == null)
                        return null;
                    return new IdentifierExpression(id.Id) { Location = id.Location, EndLocation = id.EndLocation };
                }
                if (td is TemplateInstanceExpression)
                    return td as IExpression;

                return null;
            }

            var pfa = new PostfixExpression_Access{
                PostfixForeExpression = TryConvertTypeDeclaration(td.InnerDeclaration),
                AccessExpression  = TryConvertTypeDeclaration(td, true)
            };
            if (pfa.PostfixForeExpression == null)
                return null;
            return pfa;
        }
示例#6
0
        public override ITypeDeclaration Transform(ITypeDeclaration itd)
        {
            analysis = new LivenessAnalysisTransform(compiler);
            Stopwatch watch = null;

            if (compiler.ShowProgress)
            {
                Console.Write($"({analysis.Name} ");
                watch = Stopwatch.StartNew();
            }
            analysis.Context.InputAttributes = context.InputAttributes;
            analysis.Transform(itd);
            if (compiler.ShowProgress)
            {
                watch.Stop();
                Console.Write("{0}ms) ", watch.ElapsedMilliseconds);
            }
            context.Results = analysis.Context.Results;
            if (!context.Results.IsSuccess)
            {
                Error("analysis failed");
                return(itd);
            }
            var itdOut = base.Transform(itd);

            return(itdOut);
        }
示例#7
0
文件: Mangler.cs 项目: Orvid/D_Parser
        public static string Mangle(ITypeDeclaration td)
        {
            var sb = new StringBuilder();

            Mangle(td, sb);
            return(sb.ToString());
        }
示例#8
0
 internal TaskGraphView(ITypeDeclaration itd, BasicTransformContext context)
 {
     pretasks  = Builder.StmtCollection();
     looptasks = Builder.StmtCollection();
     foreach (IMethodDeclaration imd in itd.Methods)
     {
         if (!context.InputAttributes.Has <OperatorMethod>(imd))
         {
             continue;
         }
         foreach (IStatement ist in imd.Body.Statements)
         {
             if (ist is IWhileStatement)
             {
                 looptasks.AddRange(((IWhileStatement)ist).Body.Statements);
                 continue;
             }
             if (context.InputAttributes.Has <OperatorStatement>(ist))
             {
                 pretasks.Add(ist);
             }
         }
         //                if (imd.Name == "Initialise") pretasks.AddRange(((IBlockStatement)imd.Body).Statements);
         //if (imd.Name == "Update") looptasks.AddRange(((IBlockStatement)imd.Body).Statements);
     }
     this.context = context;
     OnTasksChanged();
 }
        private static ICollection GetInterfaces(ITypeDeclaration value)
        {
            ArrayList list = new ArrayList(value.Interfaces);

            if (value.BaseType != null)
            {
                ITypeDeclaration baseType = value.BaseType.Resolve();
                foreach (ITypeReference interfaceReference in baseType.Interfaces)
                {
                    if (list.Contains(interfaceReference))
                    {
                        list.Remove(interfaceReference);
                    }
                }
            }

            foreach (ITypeReference interfaceReference in value.Interfaces)
            {
                ITypeDeclaration interfaceDeclaration = interfaceReference.Resolve();
                foreach (ITypeReference interfaceBaseReference in interfaceDeclaration.Interfaces)
                {
                    if (list.Contains(interfaceBaseReference))
                    {
                        list.Remove(interfaceBaseReference);
                    }
                }
            }

            ITypeReference[] array = new ITypeReference[list.Count];
            list.CopyTo(array, 0);
            return(array);
        }
示例#10
0
        public override ITypeDeclaration Transform(ITypeDeclaration itd)
        {
            analysis = new ChannelAnalysisTransform();
            analysis.Context.InputAttributes = context.InputAttributes;
            analysis.Transform(itd);
            context.Results = analysis.Context.Results;
            var itdOut = base.Transform(itd);

            if (context.trackTransform && debug)
            {
                IBlockStatement block = Builder.BlockStmt();
                foreach (var entry in analysis.usageInfo)
                {
                    IVariableDeclaration ivd = entry.Key;
                    var info = entry.Value;
                    block.Statements.Add(Builder.CommentStmt(info.ToString()));
                }
                context.OutputAttributes.Add(itdOut, new DebugInfo()
                {
                    Transform = this,
                    Name      = "analysis",
                    Value     = block
                });
            }
            return(itdOut);
        }
示例#11
0
        public List <ITypeDeclaration> TransformToDeclaration(ITypeDeclaration typeDecl)
        {
            Stack <ITypeDeclaration> typesToTransform = new Stack <ITypeDeclaration>();

            typesToTransform.Push(typeDecl);

            HashSet <ITypeDeclaration> typesTransformed = new HashSet <ITypeDeclaration>();
            List <ITypeDeclaration>    typeDeclarations = new List <ITypeDeclaration>();

            while (typesToTransform.Count > 0)
            {
                ITypeDeclaration itd = typesToTransform.Pop();
                ITypeDeclaration td  = Transform.Transform(itd);
                transformMap[itd] = td;
                typeDeclarations.Add(td);
                typesTransformed.Add(itd);
                foreach (ITypeDeclaration t2 in Transform.Context.TypesToTransform)
                {
                    if (!typesTransformed.Contains(t2))
                    {
                        typesToTransform.Push(t2);
                    }
                }
            }
            return(typeDeclarations);
        }
        public bool HandleDecl(TemplateTypeParameter p ,ITypeDeclaration td, ISemantic rr)
        {
            if (td is IdentifierDeclaration)
                return HandleDecl(p,(IdentifierDeclaration)td, rr);

            //HACK Ensure that no information gets lost by using this function
            // -- getting a value but requiring an abstract type and just extract it from the value - is this correct behaviour?
            var at = AbstractType.Get(rr);

            if (td is ArrayDecl)
                return HandleDecl(p,(ArrayDecl)td, DResolver.StripMemberSymbols(at) as AssocArrayType);
            else if (td is DTokenDeclaration)
                return HandleDecl((DTokenDeclaration)td, at);
            else if (td is DelegateDeclaration)
                return HandleDecl(p, (DelegateDeclaration)td, DResolver.StripMemberSymbols(at) as DelegateType);
            else if (td is PointerDecl)
                return HandleDecl(p, (PointerDecl)td, DResolver.StripMemberSymbols(at) as PointerType);
            else if (td is MemberFunctionAttributeDecl)
                return HandleDecl(p,(MemberFunctionAttributeDecl)td, at);
            else if (td is TypeOfDeclaration)
                return HandleDecl((TypeOfDeclaration)td, at);
            else if (td is VectorDeclaration)
                return HandleDecl((VectorDeclaration)td, at);
            else if (td is TemplateInstanceExpression)
                return HandleDecl(p,(TemplateInstanceExpression)td, at);

            return false;
        }
示例#13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="typeDeclaration">TypeDeclaration to decompile into a BizTalk artifact.</param>
        public DecompiledArtifact(ITypeDeclaration typeDeclaration)
        {
            Namespace = typeDeclaration.Namespace;
            Name      = typeDeclaration.Name;

            ArtifactValue = ExtractArtifact(typeDeclaration);
        }
示例#14
0
        /// <summary>
        /// Extract the initializer for the given TypeDeclaration.
        /// </summary>
        /// <param name="typeDeclaration">TypeDeclaration to extarct the initializer from.</param>
        /// <returns>Value of the initializer as a string.</returns>
        protected virtual string ExtractArtifact(ITypeDeclaration typeDeclaration)
        {
            string value = null;

            // Locate the field for this artifact and extract its initializer
            string expectedFieldName = FieldName;

            foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
            {
                // BizTalk 2006 compiles textual representations as private const string fields
                if (fieldDeclaration.Visibility == FieldVisibility.Private)
                {
                    // Loacte the field holding the textual representation of the artifact
                    if (String.CompareOrdinal(expectedFieldName, fieldDeclaration.Name) == 0)
                    {
                        ILiteralExpression litteralExpression = fieldDeclaration.Initializer as ILiteralExpression;
                        if (litteralExpression != null)
                        {
                            value = litteralExpression.Value as string;
                            break;
                        }
                    }
                }
            }

            return(value);
        }
示例#15
0
        /// <summary>
        /// Fetches every Type Declaration in the assembly
        /// </summary>
        public static void FetchTypes()
        {         // Search the current and (if the NodeEditor is packed into a .dll) the calling one
            types = new Dictionary <string, TypeData> ();

            List <Assembly> scriptAssemblies = AppDomain.CurrentDomain.GetAssemblies()
                                               .Where((Assembly a) => a.FullName.StartsWith("Assembly-"))
                                               .ToList(); // This filters out all script assemblies

            if (!scriptAssemblies.Contains(Assembly.GetExecutingAssembly()))
            {
                scriptAssemblies.Add(Assembly.GetExecutingAssembly());
            }
            foreach (Assembly assembly in scriptAssemblies)
            {
                foreach (Type type in assembly.GetTypes().Where(T => T.IsClass && !T.IsAbstract && T.GetInterfaces().Contains(typeof(ITypeDeclaration))))
                {
                    ITypeDeclaration typeDecl = assembly.CreateInstance(type.FullName) as ITypeDeclaration;
                    if (typeDecl == null)
                    {
                        UnityEngine.Debug.LogError("Error with Type Declaration " + type.FullName);
                        return;
                    }
                    Texture2D InputKnob  = NodeEditor.LoadTexture(typeDecl.InputKnob_TexPath);
                    Texture2D OutputKnob = NodeEditor.LoadTexture(typeDecl.OutputKnob_TexPath);
                    types.Add(typeDecl.name, new TypeData(typeDecl.col, InputKnob, OutputKnob, typeDecl.Type));
                }
            }
        }
示例#16
0
 protected internal ConditionalFormula(IFormula test, IFormula ifTrue, IFormula ifFalse, ITypeDeclaration type, IFormula parent)
     : base(NodeType.Conditional, type, parent)
 {
     Test = test;
     IfTrue = ifTrue;
     IfFalse = ifFalse;
 }
示例#17
0
            public string BuildArrayContentString(ulong Offset, ITypeDeclaration type)
            {
                bool IsString;

                object[] marr = ExtractArray(Offset, type, out IsString);
                return(BuildArrayContentString(marr, IsString));
            }
示例#18
0
        /// <summary>
        /// Fetches every Type Declaration in the assembly
        /// </summary>
        public static void FetchTypes()
        {         // Search the current and (if the NodeEditor is packed into a .dll) the calling one
            types = new Dictionary <string, TypeData> ();

            List <Assembly> scriptAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();

            if (!scriptAssemblies.Contains(Assembly.GetExecutingAssembly()))
            {
                scriptAssemblies.Add(Assembly.GetExecutingAssembly());
            }
            foreach (Assembly assembly in scriptAssemblies)
            {
                if (!assembly.FullName.Contains("Assembly"))
                {
                    continue;
                }
                foreach (Type type in assembly.GetTypes().Where(T => T.IsClass && !T.IsAbstract && T.GetInterfaces().Contains(typeof(ITypeDeclaration))))
                {
                    ITypeDeclaration typeDecl = assembly.CreateInstance(type.FullName) as ITypeDeclaration;
                    if (typeDecl == null)
                    {
                        Debug.LogError("Error with Type Declaration " + type.FullName);
                        return;
                    }
                    types.Add(typeDecl.name, new TypeData(typeDecl));
                }
            }
        }
示例#19
0
        bool IsMoreSpecialized(ITypeDeclaration Spec, TemplateParameter t2, Dictionary <TemplateParameter, ISemantic> t1_DummyParamList)
        {
            AbstractType t1_TypeResults;

            // Make a type out of t1's specialization
            using (ctxt.Push(ctxt.ScopedBlock != null ? ctxt.ScopedBlock.Parent : null))
            {
                var dict = ctxt.CurrentContext.DeducedTemplateParameters;
                // Make the T in e.g. T[] a virtual type so T will be replaced by it
                // T** will be X** then - so a theoretically valid type instead of a template param
                var dummyType = new ClassType(new DClassLike {
                    Name = "X"
                }, null, null);
                foreach (var kv in t1_DummyParamList)
                {
                    dict[kv.Key] = new TemplateParameterSymbol(t2, dummyType);
                }

                t1_TypeResults = Resolver.TypeResolution.TypeDeclarationResolver.ResolveSingle(Spec, ctxt);
            }

            if (t1_TypeResults == null)
            {
                return(true);
            }

            // Now try to fit the virtual Type t2 into t1 - and return true if it's possible
            return(new TemplateParameterDeduction(new DeducedTypeDictionary(), ctxt).Handle(t2, t1_TypeResults));
        }
示例#20
0
        public static DMethod ParseMethodDeclarationHeader(string headerCode, out ITypeDeclaration identifierChain)
        {
            using (var sr = new StringReader(headerCode))
            {
                var p = Create(sr);
                p.Step();

                var n = new DMethod();
                p.CheckForStorageClasses(p.doc);
                p.ApplyAttributes(n);
                p.FunctionAttributes(n);

                n.Type = p.Type(null);

                identifierChain = p.IdentifierList();
                if (identifierChain is IdentifierDeclaration)
                {
                    n.NameHash = (identifierChain as IdentifierDeclaration).IdHash;
                }

                n.Parameters = p.Parameters(n);

                return(n);
            }
        }
        public ParameterDeclaration AddParam(ITypeDeclaration type, string name, bool nonNull)
        {
            ParameterDeclaration p = new ParameterDeclaration(type, name, nonNull);

            this.Parameters.Add(p);
            return(p);
        }
示例#22
0
 public virtual void VisitInner(ITypeDeclaration td)
 {
     if (td.InnerDeclaration != null)
     {
         td.InnerDeclaration.Accept(this);
     }
 }
示例#23
0
        public void MarkTypeAsUsed(ITypeDeclaration declaration)
        {
            SetConstructorsState(declaration.DeclaredElement, UsageState.USED_MASK | UsageState.CANNOT_BE_PRIVATE |
                                 UsageState.CANNOT_BE_INTERNAL | UsageState.CANNOT_BE_PROTECTED);

            collectUsagesStageProcess.SetElementState(declaration.DeclaredElement, UsageState.ACCESSED);
        }
示例#24
0
		public static AbstractType DemangleAndResolve(string mangledString, ResolutionContext ctxt, out ITypeDeclaration qualifier)
		{
			bool isCFunction;
			Demangler.Demangle(mangledString, ctxt, out qualifier, out isCFunction);
			
			// Seek for C functions | Functions that have no direct module association (e.g. _Dmain)
			if(qualifier is IdentifierDeclaration && qualifier.InnerDeclaration == null)
			{
				var id = (qualifier as IdentifierDeclaration).Id;
				return Resolver.ASTScanner.NameScan.ScanForCFunction(ctxt, id, isCFunction);
			}
			
			bool seekCtor = false;
			if(qualifier is IdentifierDeclaration)
			{
				var id = (qualifier as IdentifierDeclaration).Id;
				if((seekCtor = (id == DMethod.ConstructorIdentifier)) || id == "__Class" || id =="__ModuleInfo")
					qualifier = qualifier.InnerDeclaration;
			}

			var resSym = TypeDeclarationResolver.ResolveSingle(qualifier,ctxt);
			
			if(seekCtor && resSym is UserDefinedType)
			{
				var ctor = (resSym as TemplateIntermediateType).Definition[DMethod.ConstructorIdentifier].FirstOrDefault();
				if(ctor!= null)
					resSym = new MemberSymbol(ctor as DNode, null, null);
			}
			return resSym;
		}
示例#25
0
        private void AddCollectionMethods(ClassDeclaration col, ITypeDeclaration mappedType, string name, string pname)
        {
            // add method
            MethodDeclaration    add  = col.AddMethod("Add" + name);
            ParameterDeclaration para = add.Signature.Parameters.Add(mappedType, pname, true);

            add.Body.Add(
                Expr.This.Prop("List").Method("Add").Invoke(para)
                );

            // add method
            MethodDeclaration contains = col.AddMethod("Contains" + name);

            contains.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool));
            para = contains.Signature.Parameters.Add(mappedType, pname, true);
            contains.Body.Return(
                Expr.This.Prop("List").Method("Contains").Invoke(para)
                );

            // add method
            MethodDeclaration remove = col.AddMethod("Remove" + name);

            para = remove.Signature.Parameters.Add(mappedType, pname, true);
            remove.Body.Add(
                Expr.This.Prop("List").Method("Remove").Invoke(para)
                );
        }
        public override void Execute(SolutionModel solutionModel, SelectionContext context)
        {
            FileModel fileModel;
            CodeSpan  selection;

            if (!solutionModel.IsEditorSelection(context, out fileModel, out selection))
            {
                return;
            }

            IMemberDeclaration memberDeclaration = fileModel.InnerMost <IMemberDeclaration>(selection);

            if (memberDeclaration.ExistsTextuallyInFile && !memberDeclaration.Identifier.CodeSpan.Intersects(selection))
            {
                memberDeclaration.Identifier.Select();
            }
            else
            {
                ITypeDeclaration typeDeclaration = fileModel.InnerMost <ITypeDeclaration>(selection);

                if (typeDeclaration.ExistsTextuallyInFile)
                {
                    NavigateToTypeDeclaration(typeDeclaration, selection);
                }
            }
        }
        private void FindMethods(ITypeDeclaration typeDeclaration, string[] searchFors, List <MethodDeclarationInfo> list)
        {
            foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
            {
                try
                {
                    string methodText = this.Decompile(methodDeclaration);
                    bool   found      = false;
                    foreach (string s in searchFors)
                    {
                        if (methodText.Contains(s))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        list.Add(new MethodDeclarationInfo(methodDeclaration, methodText));
                    }
                }
                catch (Exception ex)
                {
                    list.Add(new MethodDeclarationInfo(methodDeclaration, ex.Message));
                }
            }

            foreach (ITypeDeclaration nestedType in typeDeclaration.NestedTypes)
            {
                FindMethods(nestedType, searchFors, list);
            }
        }
示例#28
0
        public override ITypeDeclaration Transform(ITypeDeclaration itd)
        {
            bool useJaggedSubarrayWithMarginal = (this.algorithmDefault is ExpectationPropagation);

            analysis = new VariableAnalysisTransform(useJaggedSubarrayWithMarginal);
            analysis.Context.InputAttributes = context.InputAttributes;
            analysis.Transform(itd);
            context.Results = analysis.Context.Results;
            var itdOut = base.Transform(itd);

            if (context.trackTransform)
            {
                IBlockStatement block = Builder.BlockStmt();
                block.Statements.Add(Builder.CommentStmt("variablesOmittingVariableFactor:"));
                foreach (var ivd in analysis.variablesExcludingVariableFactor)
                {
                    block.Statements.Add(Builder.CommentStmt(ivd.ToString()));
                }
                context.OutputAttributes.Add(itdOut, new DebugInfo()
                {
                    Transform = this,
                    Name      = "analysis",
                    Value     = block
                });
            }
            return(itdOut);
        }
示例#29
0
			public StaticPropertyInfo(string name, string desc, byte primitiveType)
			{ 
				Name = name;
				Description = desc; 
				OverrideType = new DTokenDeclaration(primitiveType); 
				ResolvedBaseTypeGetter = (t,ctxt) => new PrimitiveType(primitiveType) { NonStaticAccess = RequireThis }; 
			}
 private void ConvertNamespaceDeclaration(ITypeDeclaration declaringType, NamespaceDeclarationSyntax namespaceDeclaration)
 {
     foreach (var member in namespaceDeclaration.Members)
     {
         ConvertMember(declaringType, member);
     }
 }
示例#31
0
 protected internal BinaryFormula(NodeType nodeType, IFormula left, IFormula right, ITypeDeclaration type, IMethodDeclaration method, IFormula parent)
     : base(nodeType, type, parent)
 {
     Left = left;
     Method = method;
     Right = right;
 }
示例#32
0
        internal IGeneratedAlgorithm CompileWithoutParams(ITypeDeclaration itd, MethodBase method, AttributeRegistry <object, ICompilerAttribute> inputAttributes)
        {
            AttributeRegistry <object, ICompilerAttribute> outputAttributes = (AttributeRegistry <object, ICompilerAttribute>)inputAttributes.Clone();
            List <ITypeDeclaration> output = GetTransformedDeclaration(itd, method, outputAttributes);

            return(CompileWithoutParams <IGeneratedAlgorithm>(output));
        }
        private IMethodDeclaration ConvertMethodDecl(ITypeDeclaration typeDeclaration, MethodDeclarationSyntax methodDeclarationSyntax)
        {
            var methodSymbol = model.GetDeclaredSymbol(methodDeclarationSyntax);

            var methodDecl = Builder.MethodDecl();

            methodDecl.Name          = methodSymbol.Name;
            methodDecl.DeclaringType = typeDeclaration;
            methodDecl.Static        = methodSymbol.IsStatic;
            methodDecl.Visibility    = ConvertVisibility(methodSymbol.DeclaredAccessibility);
            methodDecl.Virtual       = methodSymbol.IsVirtual;
            methodDecl.Abstract      = methodSymbol.IsAbstract;
            methodDecl.Final         = methodSymbol.IsSealed;

            var methodReturnType = ConvertTypeReference(methodSymbol.ReturnType);

            methodDecl.ReturnType = Builder.MethodReturnType(methodReturnType);

            ConvertAttributes(methodDeclarationSyntax.AttributeLists, methodDecl.Attributes);

            foreach (var paramSym in methodSymbol.Parameters)
            {
                var paramDecl = Builder.Param(paramSym.Name, ConvertTypeReference(paramSym.Type));
                methodDecl.Parameters.Add(paramDecl);
            }

            methodDecl.MethodInfo = Builder.ToMethodThrows(methodDecl);

            return(methodDecl);
        }
示例#34
0
 public override void VisitInner(ITypeDeclaration td)
 {
     if (PushSelectionRange(td))
     {
         base.VisitInner(td);
     }
 }
示例#35
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            ITypeDeclaration typeDeclaration = GetTargetTypeDeclaration(_highlighting.BaseClass);

            if (typeDeclaration == null)
            {
                return(null);
            }

            MemberSignature signature = CreateTransformTextSignature(typeDeclaration);
            TypeTarget      target    = CreateTarget(typeDeclaration);

            var context = new CreateMethodDeclarationContext {
                AccessRights = AccessRights.PUBLIC,
                ExecuteTemplateOverMemberBody = false,
                ExecuteTemplateOverName       = false,
                ExecuteTemplateOverParameters = false,
                ExecuteTemplateOverReturnType = false,
                IsAbstract       = true,
                IsStatic         = false,
                MethodSignatures = new[] { signature },
                MethodName       = T4CSharpIntermediateConverterBase.TransformTextMethodName,
                SourceReferenceExpressionReference = null,
                Target = target,
            };

            IntentionResult intentionResult = MethodDeclarationBuilder.Create(context);

            intentionResult.ExecuteTemplate();
            return(null);
        }
示例#36
0
        public MethodSignature(IMethodDeclaration methDecl)
        {
            this.meth_decl = methDecl;
            this.name      = meth_decl.Name;

            if (meth_decl.SpecialName)
            {
                this.m_type = MethodType.SpecialName;
                switch (this.name)
                {
                case "op_Implicit": this.m_type = MethodType.ImplicitCast; break;

                case "op_Explicit":     this.m_type = MethodType.ExplicitCast; break;

                case ".cctor":          this.m_type = MethodType.Constructor; break;

                case ".ctor":           this.m_type = MethodType.StaticConstructor; break;

                default:
                    string op;
                    if (operators.TryGetValue(name, out op))
                    {
                        this.name   = op;
                        this.m_type = MethodType.Operator;
                    }
                    break;
                }
            }
            else
            {
                this.m_type = MethodType.Ordinary;
            }

            type_decl = ((ITypeReference)methDecl.DeclaringType).Resolve();
        }
示例#37
0
        public void MarkTypeAsUsed(ITypeDeclaration declaration)
        {
            SetConstructorsState(declaration.DeclaredElement, UsageState.USED_MASK | UsageState.CANNOT_BE_PRIVATE |
                                                         UsageState.CANNOT_BE_INTERNAL | UsageState.CANNOT_BE_PROTECTED);

            collectUsagesStageProcess.SetElementState(declaration.DeclaredElement, UsageState.ACCESSED);
        }
示例#38
0
		public static AbstractType Demangle(string mangledString, out ITypeDeclaration qualifier, out bool isCFunction)
		{
			if(string.IsNullOrEmpty(mangledString))
				throw new ArgumentException("строка ввода должна не быть пустой или null!");
			
			if (!mangledString.StartsWith("_D"))
			{
				isCFunction = true;

				if (mangledString.StartsWith ("__D"))
					mangledString = mangledString.Substring (1);
				// C Functions
				else if (mangledString.StartsWith ("_")) {
					qualifier = new IdentifierDeclaration (mangledString.Substring (1));
					return null;
				}
			}

			//TODO: What about C functions that start with 'D'?
			isCFunction = false;
			
			var dmng = new Demangler(mangledString);
			
			return dmng.MangledName(out qualifier);
		}
示例#39
0
        private static ICollection GetInterfaces(ITypeDeclaration value)
        {
            ArrayList list = new ArrayList(0);

            list.AddRange(value.Interfaces);
            if (value.BaseType != null)
            {
                ITypeDeclaration declaration2 = value.BaseType.Resolve();
                foreach (ITypeReference reference in declaration2.Interfaces)
                {
                    if (list.Contains(reference))
                    {
                        list.Remove(reference);
                    }
                }
            }
            foreach (ITypeReference reference in value.Interfaces)
            {
                ITypeDeclaration declaration = reference.Resolve();
                foreach (ITypeReference reference2 in declaration.Interfaces)
                {
                    if (list.Contains(reference2))
                    {
                        list.Remove(reference2);
                    }
                }
            }
            ITypeReference[] array = new ITypeReference[list.Count];
            list.CopyTo(array, 0);
            return(array);
        }
 internal FieldDeclaration(string name, Declaration declaringType, ITypeDeclaration type)
     : base(name,declaringType)
 {
     if (type==null)
         throw new ArgumentNullException("type");
     this.type = type;
 }
示例#41
0
        public static AbstractType Demangle(string mangledString, out ITypeDeclaration qualifier, out bool isCFunction)
        {
            if (string.IsNullOrEmpty(mangledString))
            {
                throw new ArgumentException("input string must not be null or empty!");
            }

            if (!mangledString.StartsWith("_D"))
            {
                isCFunction = true;

                if (mangledString.StartsWith("__D"))
                {
                    mangledString = mangledString.Substring(1);
                }
                // C Functions
                else if (mangledString.StartsWith("_"))
                {
                    qualifier = new IdentifierDeclaration(mangledString.Substring(1));
                    return(null);
                }
            }

            //TODO: What about C functions that start with 'D'?
            isCFunction = false;

            var dmng = new Demangler(mangledString);

            return(dmng.MangledName(out qualifier));
        }
示例#42
0
        public ObjectCreationExpression(ITypeDeclaration type, params Expression[] args)
        {
            if (type==null)
                throw new ArgumentNullException("type");

            this.type = type;
            this.args.AddRange(args);
        }
 internal IndexerDeclaration(
     Declaration declaringType,
     ITypeDeclaration returnType)
     : base("Item",declaringType)
 {
     this.signature.ReturnType = returnType;
     this.Attributes = MemberAttributes.Public;
 }
 internal EventDeclaration(string name, Declaration declaringType, ITypeDeclaration type)
     : base(name,declaringType)
 {
     if (type==null)
         throw new ArgumentNullException("type");
     this.type = type;
     this.Attributes = MemberAttributes.Public;
 }
示例#45
0
		public TypeData (ITypeDeclaration typeDecl) 
		{
			Declaration = typeDecl;
			Type = Declaration.Type;
			Col = Declaration.Col;

			InputKnob = ResourceManager.GetTintedTexture (Declaration.InputKnobTexPath, Col);
			OutputKnob = ResourceManager.GetTintedTexture (Declaration.OutputKnobTexPath, Col);
		}
示例#46
0
		public TypeData (ITypeDeclaration typeDecl) 
		{
			declaration = typeDecl;
			Type = declaration.Type;
			col = declaration.col;

			InputKnob = ResourceManager.GetTintedTexture (declaration.InputKnob_TexPath, col);
			OutputKnob = ResourceManager.GetTintedTexture (declaration.OutputKnob_TexPath, col);
		}
示例#47
0
 internal ParameterDeclaration(ITypeDeclaration type, string name, bool nonNull)
 {
     if (type==null)
         throw new ArgumentNullException("type");
     if (name==null)
         throw new ArgumentNullException("name");
     this.type = type;
     this.name=name;
     this.nonNull = nonNull;
 }
        public CastExpression(ITypeDeclaration targetType, Expression expression)
        {
            if (targetType==null)
                throw new ArgumentNullException("targetType");
            if (expression == null)
                throw new ArgumentNullException("expression");

            this.targetType = targetType;
            this.expression = expression;
        }
        public ArrayCreationWithInitializersExpression(
            ITypeDeclaration type,
            params Expression[] initializers)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            this.type = type;
            this.initializers.AddRange(initializers);
        }
示例#50
0
 /// <summary>
 /// Detects the nested types.
 /// </summary>
 /// <param name="typeDeclaration">The type declaration.</param>
 /// <returns>An IEnumerable of ITypeDeclaration with the nested types.</returns>
 private static IEnumerable<ITypeDeclaration> NestedTypes(ITypeDeclaration typeDeclaration)
 {
   foreach (ITypeDeclaration nestedType in typeDeclaration.NestedTypes)
   {
     yield return nestedType;
     foreach (ITypeDeclaration nestedNestedType in NestedTypes(nestedType))
     {
       yield return nestedNestedType;
     }
   }
 }
示例#51
0
 public static IBlockFormula Block(
     IBlockFormula parentBlock,
     ReadOnlyCollection<IBlockFormula> childBlocks,
     ReadOnlyCollection<IFormula> variables,
     ReadOnlyCollection<IFormula> formulas,
     IFormula result,
     ITypeDeclaration type,
     IFormula parent)
 {
     return new BlockFormula(parentBlock, childBlocks, variables, formulas, result, type, parent);
 }
示例#52
0
        public DelegateCreateExpression(ITypeDeclaration delegateType, 
			MethodReferenceExpression targetMethod)
        {
            if (delegateType==null)
                throw new ArgumentNullException("delegateType");
            if (targetMethod==null)
                throw new ArgumentNullException("targetMethod");

            this.delegateType = delegateType;
            this.targetMethod = targetMethod;
        }
示例#53
0
 protected internal MethodCallFormula(
     IFormula instance,
     IMethodDeclaration method,
     ReadOnlyCollection<IFormula> arguments,
     ITypeDeclaration type,
     IFormula parent)
     : base(NodeType.Call, type, parent)
 {
     Instance = instance;
     Method = method;
     Arguments = arguments;
 }
        public ArrayCreationWithSizeExpression(
            ITypeDeclaration type,
            Expression sizeExpression)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (sizeExpression == null)
                throw new ArgumentNullException("sizeExpression");

            this.type = type;
            this.sizeExpression = sizeExpression;
        }
示例#55
0
        public PredicateGrouping(ITypeDeclaration declaration, string regionType, Predicate<ITypeMemberDeclaration> predicate)
            : base(declaration)
        {
            if (regionType == null)
                throw new ArgumentNullException("regionType");

            if(predicate == null)
                throw new ArgumentNullException("predicate");

            this.regionType = regionType;
            this.predicate = predicate;
        }
示例#56
0
    /// <summary>
    /// Finds the derived types.
    /// </summary>
    /// <param name="typeDeclaration">The type declaration.</param>
    /// <returns>An IEnumerable'1 of ITypeDeclaration instances that are derived from the given type declaration.</returns>
    public IEnumerable<ITypeDeclaration> FindDerivedTypes(ITypeDeclaration typeDeclaration)
    {
      if (!this.table.ContainsKey(typeDeclaration))
      {
        LiveSequence.Common.Logger.Current.Debug("no derived types in current table");
        return new List<ITypeDeclaration>();
      }

      List<ITypeDeclaration> list = this.table[typeDeclaration];
      list.Sort();
      return list;
    }
        public VariableDeclarationStatement(
			ITypeDeclaration type,
			string name
			)
        {
            if (type==null)
                throw new ArgumentNullException("type");
            if (name==null)
                throw new ArgumentNullException("name");
            this.type = type;
            this.name = name;
        }
示例#58
0
        public void MarkTypeAsUsed(ITypeDeclaration declaration)
        {
            //ITypeElement element = declaration.DeclaredElement;

            //UsageState mask = UsageState.USED_MASK |
            //                  UsageState.CANNOT_BE_PRIVATE |
            //                  UsageState.CANNOT_BE_INTERNAL |
            //                  UsageState.CANNOT_BE_PROTECTED;

            //SetConstructorsState(element, mask);

            //collectUsagesStageProcess.SetElementState(element, UsageState.ACCESSED);
        }
示例#59
0
 protected internal ConditionalFormulaRef(
     IFormulaRef test,
     IFormulaRef ifTrue,
     IFormulaRef ifFalse,
     ITypeDeclaration type,
     IFormulaRef parent)
     : base(test, ifTrue, ifFalse, type, parent)
 {
     this.parent = parent;
     this.test = test;
     this.ifTrue = ifTrue;
     this.ifFalse = ifFalse;
 }
示例#60
0
    /// <summary>
    /// Adds to table.
    /// </summary>
    /// <param name="keyTypeReference">The key type reference.</param>
    /// <param name="typeDeclaration">The type declaration.</param>
    private void AddToTable(ITypeReference keyTypeReference, ITypeDeclaration typeDeclaration)
    {
      if (!this.table.ContainsKey(keyTypeReference))
      {
        this.table.Add(keyTypeReference, new List<ITypeDeclaration>());
      }

      // Get the list that belongs to the given key
      List<ITypeDeclaration> list = this.table[keyTypeReference];

      // Check if list already contains typeDeclaration; otherwise add it.
      if (list.Find(lookupDeclaration => lookupDeclaration == typeDeclaration) == null)
      {
        list.Add(typeDeclaration);
      }
    }