void CanFindThing(string code, Func <ClassDeclaration, bool> classFinder,
                          Func <FunctionDeclaration, bool> funcFinder,
                          Func <TLFunction, bool> tlVerifier)
        {
            CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind");

            var               errors = new ErrorHandling();
            ModuleInventory   mi     = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors);
            ModuleDeclaration mod    = compiler.ReflectToModules(new string [] { compiler.DirectoryPath },
                                                                 new string [] { compiler.DirectoryPath }, null, "CanFind") [0];

            ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(classFinder);

            Assert.IsNotNull(classDecl, "nominal type not found");

            FunctionDeclaration funcDecl = classDecl.AllMethodsNoCDTor().FirstOrDefault(funcFinder);

            Assert.IsNotNull(funcDecl, "func decl not found");

            // see the note in the implementation of CanFindThing above
            TLFunction func = XmlToTLFunctionMapper.ToTLFunction(funcDecl, mi, null);

            Assert.IsNotNull(func, "TLFunction not found");
            Assert.IsTrue(tlVerifier(func), "verifier failed");
        }
 public TypeSpecificationFolderTreeNode( ModuleDeclaration module )
     : base( TreeViewImage.Folder, null )
 {
     this.module = module;
     this.Text = "Type Constructions";
     this.EnableLatePopulate();
 }
Exemplo n.º 3
0
 public ExternalFoldersTreeNode(ModuleDeclaration module)
     : base(TreeViewImage.Folder, null)
 {
     this.module = module;
     this.Text   = "References";
     this.EnableLatePopulate();
 }
        public PropertyNotificationAssets(ModuleDeclaration module)
        {
            if (module == null) throw new ArgumentNullException("module");
            Contract.EndContractBlock();
            //INotifyPropertyChanged Related
            INotifyPropertyChangedTypeSignature = module.FindType(typeof(INotifyPropertyChanged));
            PropertyChangedEventHandlerTypeSignature =
                module.FindType(typeof(INotifyPropertyChanged).GetEvent("PropertyChanged").EventHandlerType);

            PropertyChangedEventHandlerInvokeMethod =
                module.FindMethod(PropertyChangedEventHandlerTypeSignature, "Invoke");

            PropertyChangedEventArgsTypeSignature =
                module.FindType(typeof(PropertyChangedEventArgs));

            PropertyChangedEventArgsConstructor =
                module.FindMethod(PropertyChangedEventArgsTypeSignature, ".ctor");

            //INotifyPropertyChanging Realted
            INotifyPropertyChangingTypeSignature =
                module.FindType(typeof(INotifyPropertyChanging));
            PropertyChangingEventHandlerTypeSignature =
                module.FindType(typeof(INotifyPropertyChanging).GetEvent("PropertyChanging").EventHandlerType);

            PropertyChangingEventHandlerInvokeMethod =
                module.FindMethod(PropertyChangingEventHandlerTypeSignature, "Invoke");

            PropertyChangingEventArgsTypeSignature =
                module.FindType(typeof(PropertyChangingEventArgs));

            PropertyChangingEventArgsConstructor =
                module.FindMethod(PropertyChangingEventArgsTypeSignature, ".ctor");
        }
 public ExternalFoldersTreeNode( ModuleDeclaration module )
     : base( TreeViewImage.Folder, null )
 {
     this.module = module;
     this.Text = "References";
     this.EnableLatePopulate();
 }
Exemplo n.º 6
0
 public void Visit(ModuleDeclaration node)
 {
     if (node != null && node.Binding != null)
     {
         m_bindings.Add(node.Binding);
     }
 }
Exemplo n.º 7
0
 public TypeSpecificationFolderTreeNode(ModuleDeclaration module)
     : base(TreeViewImage.Folder, null)
 {
     this.module = module;
     this.Text   = "Type Constructions";
     this.EnableLatePopulate();
 }
Exemplo n.º 8
0
        public static AssemblyLoaderInfo LoadAssemblyLoader(bool createTemporaryAssemblies,
                                                            bool hasUnmanaged,
                                                            ModuleDeclaration module)
        {
            AssemblyLoaderInfo info = new AssemblyLoaderInfo();
            TypeDefDeclaration sourceType;

            if (createTemporaryAssemblies)
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplateWithTempAssembly")
                             .GetTypeDefinition();
            }
            else if (hasUnmanaged)
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplateWithUnmanagedHandler")
                             .GetTypeDefinition();
            }
            else
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplate")
                             .GetTypeDefinition();
            }

            info.AttachMethod            = module.FindMethod(sourceType, "Attach").GetMethodDefinition();
            info.StaticConstructorMethod = module.FindMethod(sourceType, ".cctor").GetMethodDefinition();

            info.AssemblyNamesField = sourceType.FindField("assemblyNames")?.Field;
            info.SymbolNamesField   = sourceType.FindField("symbolNames")?.Field;
            info.PreloadListField   = sourceType.FindField("preloadList")?.Field;
            info.Preload32ListField = sourceType.FindField("preload32List")?.Field;
            info.Preload64ListField = sourceType.FindField("preload64List")?.Field;
            info.Md5HashField       = sourceType.FindField("md5Hash")?.Field;
            info.ChecksumsField     = sourceType.FindField("checksums")?.Field;
            return(info);
        }
Exemplo n.º 9
0
        public void OptionalSmokeTest1()
        {
            string            code   = "public func optInt(x:Int) -> Int? { if (x >= 0) { return x; }\nreturn nil; }\n";
            ModuleDeclaration module = ReflectToModules(code, "SomeModule").Find(m => m.Name == "SomeModule");

            Assert.IsNotNull(module);
        }
Exemplo n.º 10
0
        public void FindsPropertyGetterAndSetterFuncs()
        {
            string code = "public class Bar { public var x:Int = 0; }";

            CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind");

            ModuleDeclaration mod = compiler.ReflectToModules(new string [] { compiler.DirectoryPath },
                                                              new string [] { compiler.DirectoryPath }, null, "CanFind") [0];

            ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(cl => cl.Name == "Bar");

            Assert.IsNotNull(classDecl);

            PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(p => p.Name == "x");

            Assert.IsNotNull(propDecl);

            FunctionDeclaration getter = propDecl.GetGetter();

            Assert.IsNotNull(getter);

            FunctionDeclaration setter = propDecl.GetSetter();

            Assert.IsNotNull(setter);
        }
Exemplo n.º 11
0
        public PostEdgeWeaverAssets(ModuleDeclaration module)
        {
            if (module == null) throw new ArgumentNullException("module");
            _module = module;
            _delegateCombineMethod =
                new Lazy<IMethod>(() => {
                    var method = _module.FindMethod("System.Delegate, mscorlib", "Combine", "System.Delegate, mscorlib","System.Delegate, mscorlib");
                    Debug.Assert(method != null, "Could not find Delegate.Combine used by PostEdgeWeaverAssets.");
                    return method;
                });

            _delegateRemoveMethod =
                new Lazy<IMethod>(() => {
                    var method = _module.FindMethod("System.Delegate, mscorlib", "Remove", "System.Delegate, mscorlib", "System.Delegate, mscorlib");
                    Debug.Assert(method != null, "Could not find Delegate.Remove used by PostEdgeWeaverAssets.");
                    return method;
                });

            _compareExchangeMethod =
                new Lazy<IMethod>(() => {
                    var method = _module.FindMethod("System.Threading.Interlocked, mscorlib", "CompareExchange",
                        methodDef => methodDef.IsGenericDefinition);
                    Debug.Assert(method != null, "System.Threading.Interlocked.CompareExchange used by PostEdgeWeaverAssets.");
                    return method;
                });
        }
Exemplo n.º 12
0
 private void convertComputationUnit(CompilationUnitSyntax compilationUnit, ModuleDeclaration module)
 {
     foreach (var memberDeclarationSyntax in compilationUnit.Members)
     {
         converMemberDeclaration(memberDeclarationSyntax, module);
     }
 }
Exemplo n.º 13
0
        public StringFormatWriter(ModuleDeclaration module)
        {
            this.module = module;
            ITypeSignature stringType = module.Cache.GetType(typeof(string));

            this.format1Method = module.FindMethod(stringType, "Format",
                method => method.Parameters.Count == 2 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object));

            this.format2Method = module.FindMethod(stringType, "Format",
                method => method.Parameters.Count == 3 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                          IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object));

            this.format3Method = module.FindMethod(stringType, "Format",
                method => method.Parameters.Count == 4 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                          IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object) &&
                          IntrinsicTypeSignature.Is(method.Parameters[3].ParameterType, IntrinsicType.Object));

            this.formatArrayMethod = module.FindMethod(stringType, "Format",
                method => method.Parameters.Count == 2 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));
        }
Exemplo n.º 14
0
        private void ProcessModuleProperty(TypeScriptContext tsc, ModuleDeclaration md, HtmlNode h, string sn)
        {
            var div = h.ParentNode;

            var typeText = div.SelectSingleNode("*[@class='type-signature']")?.InnerText.Trim();

            var vd = new VariableDeclaration()
            {
                IsConstant   = div.SelectSingleNode("div/span[@class='label label-constant']") != null,
                Name         = sn,
                VariableType = string.IsNullOrEmpty(typeText) ? BuiltinType.Any : ResolveType(tsc, typeText).Type
            };
            var dsc = div.SelectNodes("p[not(@class)]").SanitizeDocumentation();

            if (dsc != null)
            {
                vd.Documentation = new Documentation()
                {
                    Summary = dsc
                };
            }
            md.Statements.Add(vd);

            StatementParsed?.Invoke(this, new StatementEventArgs(vd));
        }
        public StringFormatWriter(ModuleDeclaration module)
        {
            this.module = module;
            ITypeSignature stringType = module.Cache.GetType(typeof(string));

            this.format1Method = module.FindMethod(stringType, "Format",
                                                   method => method.Parameters.Count == 2 &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object));

            this.format2Method = module.FindMethod(stringType, "Format",
                                                   method => method.Parameters.Count == 3 &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object));

            this.format3Method = module.FindMethod(stringType, "Format",
                                                   method => method.Parameters.Count == 4 &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object) &&
                                                   IntrinsicTypeSignature.Is(method.Parameters[3].ParameterType, IntrinsicType.Object));

            this.formatArrayMethod = module.FindMethod(stringType, "Format",
                                                       method => method.Parameters.Count == 2 &&
                                                       IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                                       method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));
        }
Exemplo n.º 16
0
        void FindsProperty(string code, Func <ClassDeclaration, bool> classFinder,
                           Func <PropertyDeclaration, bool> propFinder)
        {
            CustomSwiftCompiler compiler = Utils.CompileSwift(code, moduleName: "CanFind");

            var               errors = new ErrorHandling();
            ModuleInventory   mi     = ModuleInventory.FromFile(Path.Combine(compiler.DirectoryPath, "libCanFind.dylib"), errors);
            ModuleDeclaration mod    = compiler.ReflectToModules(new string [] { compiler.DirectoryPath },
                                                                 new string [] { compiler.DirectoryPath }, null, "CanFind") [0];

            ClassDeclaration classDecl = mod.AllClasses.FirstOrDefault(classFinder);

            Assert.IsNotNull(classDecl, "null class");

            PropertyDeclaration propDecl = classDecl.Members.OfType <PropertyDeclaration> ().FirstOrDefault(propFinder);

            Assert.IsNotNull(propDecl, "null property");

            FunctionDeclaration getter = propDecl.GetGetter();

            Assert.IsNotNull(getter, "null getter");

            FunctionDeclaration setter = propDecl.GetSetter();

            Assert.IsNotNull(setter, "null setter");

            TLFunction tlgetter = XmlToTLFunctionMapper.ToTLFunction(getter, mi);

            Assert.IsNotNull(tlgetter, "null tlgetter");

            TLFunction tlsetter = XmlToTLFunctionMapper.ToTLFunction(setter, mi);

            Assert.IsNotNull(tlsetter, "null tlsetter");
        }
        public void RoundTripStruct()
        {
            ModuleDeclaration module   = ReflectToModules("public struct Foo {\npublic var x:Int\n } ", "SomeModule").Find(m => m.Name == "SomeModule");
            StructDeclaration fooClass = module.AllStructs.Where(cl => cl.Name == "Foo").FirstOrDefault();

            Assert.IsNotNull(fooClass);
            StructDeclaration unrootedFoo = fooClass.MakeUnrooted() as StructDeclaration;

            Entity entity = new Entity {
                SharpNamespace = "SomeModule",
                SharpTypeName  = "Foo",
                Type           = unrootedFoo
            };

            TypeDatabase db = new TypeDatabase();

            db.Add(entity);

            MemoryStream ostm = new MemoryStream();

            db.Write(ostm, "SomeModule");
            ostm.Seek(0, SeekOrigin.Begin);

            TypeDatabase dbread = new TypeDatabase();
            var          errors = dbread.Read(ostm);

            Utils.CheckErrors(errors);
            Entity entityRead = dbread.EntityForSwiftName("SomeModule.Foo");

            Assert.IsNotNull(entityRead);
            Assert.AreEqual(entity.SharpNamespace, entityRead.SharpNamespace);
            Assert.AreEqual(entity.SharpTypeName, entityRead.SharpTypeName);
            Assert.IsTrue(entity.Type is StructDeclaration);
        }
Exemplo n.º 18
0
        public void Initialize(ModuleDeclaration module)
        {
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.formatWriter          = new StringFormatWriter(module);

            this.loggerType = module.FindType(typeof(Logger));

            Predicate <MethodDefDeclaration> singleMessagePredicate =
                method => method.Parameters.Count == 1 &&
                IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger", singleMessagePredicate);

            this.writeDebugMethod = module.FindMethod(this.loggerType, "Trace", singleMessagePredicate);
            this.writeInfoMethod  = module.FindMethod(this.loggerType, "Info", singleMessagePredicate);
            this.writeWarnMethod  = module.FindMethod(this.loggerType, "Warn", singleMessagePredicate);
            this.writeErrorMethod = module.FindMethod(this.loggerType, "Error", singleMessagePredicate);
            this.writeFatalMethod = module.FindMethod(this.loggerType, "Fatal", singleMessagePredicate);

            this.getIsTraceEnabledMethod = module.FindMethod(this.loggerType, "get_IsTraceEnabled");
            this.getIsInfoEnabledMethod  = module.FindMethod(this.loggerType, "get_IsInfoEnabled");
            this.getIsWarnEnabledMethod  = module.FindMethod(this.loggerType, "get_IsWarnEnabled");
            this.getIsErrorEnabledMethod = module.FindMethod(this.loggerType, "get_IsErrorEnabled");
            this.getIsFatalEnabledMethod = module.FindMethod(this.loggerType, "get_IsFatalEnabled");
        }
Exemplo n.º 19
0
        public void Initialize(ModuleDeclaration module)
        {
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.formatWriter = new StringFormatWriter(module);

            this.loggerType = module.FindType(typeof(Logger));

            Predicate<MethodDefDeclaration> singleMessagePredicate =
                method => method.Parameters.Count == 1 &&
                    IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger", singleMessagePredicate);

            this.writeDebugMethod = module.FindMethod(this.loggerType, "Trace", singleMessagePredicate);
            this.writeInfoMethod = module.FindMethod(this.loggerType, "Info", singleMessagePredicate);
            this.writeWarnMethod = module.FindMethod(this.loggerType, "Warn", singleMessagePredicate);
            this.writeErrorMethod = module.FindMethod(this.loggerType, "Error", singleMessagePredicate);
            this.writeFatalMethod = module.FindMethod(this.loggerType, "Fatal", singleMessagePredicate);

            this.getIsTraceEnabledMethod = module.FindMethod(this.loggerType, "get_IsTraceEnabled");
            this.getIsInfoEnabledMethod = module.FindMethod(this.loggerType, "get_IsInfoEnabled");
            this.getIsWarnEnabledMethod = module.FindMethod(this.loggerType, "get_IsWarnEnabled");
            this.getIsErrorEnabledMethod = module.FindMethod(this.loggerType, "get_IsErrorEnabled");
            this.getIsFatalEnabledMethod = module.FindMethod(this.loggerType, "get_IsFatalEnabled");
        }
Exemplo n.º 20
0
        public ModuleTreeNode( ModuleDeclaration module, string path ) : base( module, TreeViewImage.Module )
        {
            this.Text = module.Name;
            this.module = module;
            this.path = path;

            this.EnableLatePopulate();
        }
Exemplo n.º 21
0
 public TransformationAssets(ModuleDeclaration module)
 {
     ObjectTypeSignature = module.FindType(typeof(object));
     ObjectEqualsMethod = module.FindMethod(typeof(object).GetMethod("Equals", new[] { typeof(object), typeof(object) }), BindingOptions.Default);
     LocationBindingTypeSignature = module.FindType(typeof(LocationBinding<>));
     SetValueMethod = module.FindMethod(LocationBindingTypeSignature, "SetValue", x => x.DeclaringType.IsGenericDefinition);
     GetValueMethod = module.FindMethod(LocationBindingTypeSignature, "GetValue", x => x.DeclaringType.IsGenericDefinition);
 }
Exemplo n.º 22
0
 private void converMemberDeclaration(MemberDeclarationSyntax memberDeclarationSyntax,
                                      ModuleDeclaration module)
 {
     if (memberDeclarationSyntax is ClassDeclarationSyntax classDeclarationSyntax)
     {
         convertClassDeclaration(classDeclarationSyntax, module);
     }
 }
Exemplo n.º 23
0
        public ModuleDeclaration Import(Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax compilationUnit)
        {
            var module = new ModuleDeclaration();

            convertComputationUnit(compilationUnit, module);

            return(module);
        }
        public void TestModuleDeclaration()
        {
            ModuleDeclaration node = new ModuleDeclaration(GetSymbolAtom(), new List <Declaration> {
                GetVarDeclaration()
            }, Declaration.DeclarationFlags.Export, DefaultLineInfo);

            CheckSerializationRoundTrip(node);
        }
        public ModuleTypesFolderTreeNode(ModuleDeclaration module)
            : base(module, TreeViewImage.Folder)
        {
            this.Text   = "Types";
            this.module = module;

            this.EnableLatePopulate();
        }
Exemplo n.º 26
0
        public ModuleTreeNode(ModuleDeclaration module, string path) : base(module, TreeViewImage.Module)
        {
            this.Text   = module.Name;
            this.module = module;
            this.path   = path;

            this.EnableLatePopulate();
        }
Exemplo n.º 27
0
        public static IExpression Parse(IEnumerator <TokenData> tokens, IContext parentContext, ref bool done)
        {
            if (!tokens.MoveNext())
            {
                done = true;
            }
            if (done)
            {
                return(null);
            }
            var moduleDecl = new ModuleDeclaration();
            var token      = tokens.Current;

            #region Identifier

            var identifiers = (ILocalIdentifierScope) new LocalIdentifierScope();
            if (token.Type == Token.IdentifierLiteral)
            {
                moduleDecl.Name = ((IIdentifierLiteral)token.Data).Content;
                identifiers     = parentContext.AddModule(moduleDecl);
                if (!tokens.MoveNext())
                {
                    done = true;
                }
                if (done)
                {
                    return(moduleDecl);      // fully forward declared
                }
                token = tokens.Current;
            }

            #endregion

            #region Body

            if (token.Type == Token.BlockStartIndentation)
            {
                var context = new Context(identifiers, new LocalValueScope())
                {
                    Parent = parentContext
                };
                var contentBlock = (BlockLiteral)token.Data;
                moduleDecl.Block = Parser.ParseBlockWithContext(contentBlock, context);
                if (!tokens.MoveNext())
                {
                    done = true;
                }
                if (done)
                {
                    return(moduleDecl);
                }
            }

            #endregion

            return(moduleDecl);
        }
Exemplo n.º 28
0
 public override void ExitModuleDeclaration(ModuleDeclaration moduleDeclaration)
 {
     if (moduleDeclaration.Name == "Native")
     {
         var root = moduleDeclaration.NearestAncestorOfType <Root>();
         moduleDeclaration.Remove();
         root.NativeModule = moduleDeclaration;
     }
 }
Exemplo n.º 29
0
        public void TestEmptyStruct()
        {
            ModuleDeclaration module = ReflectToModules("public struct Foo { } ", "SomeModule").Find(m => m.Name == "SomeModule");

            Assert.AreEqual(0, module.Classes.Count());
            Assert.AreEqual(0, module.Functions.Count());
            Assert.AreEqual(1, module.Structs.Count());
            Assert.AreEqual("Foo", module.Structs.First().Name);
        }
Exemplo n.º 30
0
        public void FuncReturningIntOption()
        {
            ModuleDeclaration module = ReflectToModules("public func returnIntOpt()->Int? { return 3; }", "SomeModule")
                                       .Find(m => m.Name == "SomeModule");

            Assert.NotNull(module);
            FunctionDeclaration func = module.Functions.FirstOrDefault(f => f.Name == "returnIntOpt");

            Assert.AreEqual("Swift.Optional<Swift.Int>", func.ReturnTypeName);
        }
Exemplo n.º 31
0
        public void FuncReturningDictionary()
        {
            ModuleDeclaration module = ReflectToModules("public func returnDict()->[Int:Float] { return [Int:Float](); }", "SomeModule")
                                       .Find(m => m.Name == "SomeModule");

            Assert.NotNull(module);
            FunctionDeclaration func = module.Functions.FirstOrDefault(f => f.Name == "returnDict");

            Assert.AreEqual("Swift.Dictionary<Swift.Int, Swift.Float>", func.ReturnTypeName);
        }
Exemplo n.º 32
0
        public void FuncReturningTuple()
        {
            ModuleDeclaration module = ReflectToModules("public func returnTuple()->(Int,Float) { return (0, 3.0); }", "SomeModule")
                                       .Find(m => m.Name == "SomeModule");

            Assert.NotNull(module);
            FunctionDeclaration func = module.Functions.FirstOrDefault(f => f.Name == "returnTuple");

            Assert.AreEqual("(Swift.Int, Swift.Float)", func.ReturnTypeName);
        }
Exemplo n.º 33
0
        private void ProcessModuleMethod(TypeScriptContext tsc, ModuleDeclaration md, HtmlNode h, string sn)
        {
            var div = h.ParentNode;
            var fd  = new FunctionDeclaration();

            ProcessFunctionCore(tsc, sn, div, fd);
            md.Statements.Add(fd);

            StatementParsed?.Invoke(this, new StatementEventArgs(fd));
        }
        public static TLFunction ToProtocolFactory(string swiftProxyFactoryName, ModuleDeclaration modDecl, ModuleContents contents, TypeMapper typeMap)
        {
            var swiftProxyFunctionDecl = modDecl.TopLevelFunctions.Where(fn => fn.Name == swiftProxyFactoryName).FirstOrDefault();

            if (swiftProxyFunctionDecl == null)
            {
                return(null);
            }
            return(ToTLFunction(swiftProxyFunctionDecl, contents, typeMap));
        }
Exemplo n.º 35
0
        public override IEnumerable <INode> VisitModuleDeclaration(TypescriptParser.ModuleDeclarationContext context)
        {
            var moduleDeclaration = new ModuleDeclaration(context, context.identifier().GetText(), base.VisitModuleDeclaration(context));

            if (context.EXPORT() != null)
            {
                moduleDeclaration.Modifiers.Add(MemberModifier.Export);
            }
            yield return(moduleDeclaration);
        }
Exemplo n.º 36
0
        public void GlobalBool()
        {
            ModuleDeclaration module = ReflectToModules("public var aGlobal:Bool = true", "SomeModule")
                                       .Find(m => m.Name == "SomeModule");

            Assert.NotNull(module);
            PropertyDeclaration decl = module.TopLevelProperties.FirstOrDefault(f => f.Name == "aGlobal");

            Assert.IsNotNull(decl);
        }
Exemplo n.º 37
0
 public void Visit(ModuleDeclaration node)
 {
     if (node != null)
     {
         // if there is a binding, then we shouldn't have a body so we will
         // need a terminator. If the binding is null, we will have a body,
         // but it might be null indicating an empty body; but we'll still output
         // the {} so we won't need a terminator.
         DoesRequire = node.Binding != null;
     }
 }
Exemplo n.º 38
0
            public Log4NetCategoryBuilder(Log4NetBackend parent, ModuleDeclaration module, string categoryName)
            {
                this.parent = parent;
                this.module = module;

                this.loggerField = this.parent.loggingImplementation.GetCategoryField(categoryName, this.parent.loggerType, writer =>
                {
                    writer.EmitInstructionString(OpCodeNumber.Ldstr, categoryName);
                    writer.EmitInstructionMethod(OpCodeNumber.Call, this.parent.categoryInitializerMethod);
                });
            }
Exemplo n.º 39
0
            public ConsoleCategoryBuilder(ConsoleBackend parent, ModuleDeclaration module)
            {
                this.parent = parent;
                this.module = module;

                this.writeLineMessage = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 1 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

                this.writeLineFormat1 = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 2 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object));

                this.writeLineFormat2 = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 3 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object));

                this.writeLineFormat3 = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 4 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[3].ParameterType, IntrinsicType.Object));

                this.writeLineFormat4 = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 5 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[3].ParameterType, IntrinsicType.Object) &&
                              IntrinsicTypeSignature.Is(method.Parameters[4].ParameterType, IntrinsicType.Object));

                this.writeLineFormatArray = module.FindMethod(
                    module.Cache.GetType(typeof(System.Console)), "WriteLine",
                    method => method.Parameters.Count == 2 &&
                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                              method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));
            }
Exemplo n.º 40
0
        public void Initialize(ModuleDeclaration module)
        {
            this.module = module;
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.loggerType = module.FindType(typeof(Logger));

            LoggerMethodsBuilder builder = new LoggerMethodsBuilder(module, this.loggerType);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger",
                method => method.Parameters.Count == 1 && IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) );

            this.loggerMethods[LogLevel.Debug] = builder.CreateLoggerMethods("Trace");
            this.loggerMethods[LogLevel.Info] = builder.CreateLoggerMethods("Info");
            this.loggerMethods[LogLevel.Warning] = builder.CreateLoggerMethods("Warn");
            this.loggerMethods[LogLevel.Error] = builder.CreateLoggerMethods("Error");
            this.loggerMethods[LogLevel.Fatal] = builder.CreateLoggerMethods("Fatal");
        }
        public LoggingImplementationTypeBuilder( ModuleDeclaration module )
        {
            this.module = module;
            this.categoryFields = new Dictionary<string, FieldDefDeclaration>();
            this.wrapperMethods = new Dictionary<IMethod, MethodDefDeclaration>();

            this.stringFormatArrayMethod = module.FindMethod( module.Cache.GetIntrinsic( IntrinsicType.String ), "Format",
                                                              method => method.Parameters.Count == 2 &&
                                                                        IntrinsicTypeSignature.Is( method.Parameters[0].ParameterType, IntrinsicType.String ) &&
                                                                        method.Parameters[1].ParameterType.BelongsToClassification( TypeClassifications.Array ) );

            this.traceWriteLineMethod = module.FindMethod( module.Cache.GetType( typeof(System.Diagnostics.Trace) ), "WriteLine",
                                                           method => method.Parameters.Count == 1 &&
                                                                     IntrinsicTypeSignature.Is( method.Parameters[0].ParameterType, IntrinsicType.String ) );

            this.weavingHelper = new WeavingHelper( module );
            this.implementationType = this.CreateContainingType();
            this.isLoggingField = this.CreateIsLoggingField();
        }
        private IMethod GetLoggerMethod(ModuleDeclaration module)
        {
            var systemMethod = interceptedMethod.GetSystemMethod(null, null, BindingOptions.Default);
            var systemParameters = systemMethod.GetParameters();

            var parameterTypes = new Type[systemParameters.Length + 1];
            for(int i = 0; i < systemParameters.Length; ++i)
            {
                parameterTypes[i] = systemParameters[i].ParameterType;
            }
            parameterTypes[systemParameters.Length] = typeof(ILog);

            var loggerMethod = Log.LoggerType.GetMethod(systemMethod.Name, BindingFlags.Public | BindingFlags.Static, null, parameterTypes, null);
            if (loggerMethod == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "There is a bug in CodeOMatic.Validation. The method '{0}' does not exist in the Logger class", interceptedMethod));
            }

            return module.FindMethod(loggerMethod, BindingOptions.Default);
        }
Exemplo n.º 43
0
        public void Initialize(ModuleDeclaration module)
        {
            this.module = module;
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);

            ITypeSignature traceTypeSignature = module.Cache.GetType(typeof(System.Diagnostics.Trace));

            this.writeLineString = module.FindMethod(traceTypeSignature, "WriteLine",
                method => method.Parameters.Count == 1 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

            this.traceInfoString = module.FindMethod(traceTypeSignature, "TraceInformation",
                method => method.Parameters.Count == 1 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

            this.traceInfoFormat = module.FindMethod(traceTypeSignature, "TraceInformation",
                method => method.Parameters.Count == 2 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));

            this.traceWarningString = module.FindMethod(traceTypeSignature, "TraceWarning",
                method => method.Parameters.Count == 1 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

            this.traceWarningFormat = module.FindMethod(traceTypeSignature, "TraceWarning",
                method => method.Parameters.Count == 2 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));

            this.traceErrorString = module.FindMethod(traceTypeSignature, "TraceError",
                method => method.Parameters.Count == 1 &&
                IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

            this.traceErrorFormat = module.FindMethod(traceTypeSignature, "TraceError",
                method => method.Parameters.Count == 2 &&
                          IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                          method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array));
        }
        public LoggerMethodsBuilder(ModuleDeclaration module, ITypeSignature loggerType)
        {
            this.module = module;
            this.loggerType = loggerType;

            // matches XXX(string)
            this.objectPredicate = method => method.Parameters.Count == 1 &&
                                             IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.Object);

            // matches XXX(string format, object arg)
            this.format1Predicate = method => method.Parameters.Count == 2 &&
                                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object);

            // matches XXX(string format, object arg0, object arg1)
            this.format2Predicate = method => method.Parameters.Count == 3 &&
                                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object);

            // matches XXX(string format, object arg0, object arg1, object arg2)
            this.format3Predicate = method => method.Parameters.Count == 4 &&
                                              IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[1].ParameterType, IntrinsicType.Object) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[2].ParameterType, IntrinsicType.Object) &&
                                              IntrinsicTypeSignature.Is(method.Parameters[3].ParameterType, IntrinsicType.Object);

            // matches XXX(string format, params object[] args)
            this.formatArrayPredicate = method => method.Parameters.Count == 2 &&
                                                  IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) &&
                                                  method.Parameters[1].ParameterType.BelongsToClassification(TypeClassifications.Array);

            this.objectExceptionPredicate = method => method.Parameters.Count == 2 &&
                                                      IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.Object) &&
                                                      method.Parameters[1].ParameterType.MatchesReference(module.Cache.GetType(typeof(Exception)));
        }
Exemplo n.º 45
0
 public void Initialize(ModuleDeclaration module)
 {
 }
 private static TransformationAssets GetTransformationAssets(ModuleDeclaration module)
 {
     return module.Cache.GetItem(() => new TransformationAssets(module));
 }
Exemplo n.º 47
0
 public void Initialize(ModuleDeclaration module)
 {
     this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
 }
 public Assets(ModuleDeclaration module)
 {
     this.ToStringMethodSignature = module.FindMethod(module.Cache.GetType(typeof(object)), "ToString");
 }
 public ExternalAssemblyFolderTreeNode( ModuleDeclaration module ) : base( TreeViewImage.Folder, null )
 {
     this.module = module;
     this.Text = "External Assemblies";
     this.EnableLatePopulate();
 }
Exemplo n.º 50
0
 public ConsoleBackendInstance(ConsoleBackend parent, ModuleDeclaration module)
 {
     this.parent = parent;
     this.module = module;
 }
Exemplo n.º 51
0
 public ConsoleBackendInstance(ModuleDeclaration module)
 {
     this.module = module;
 }
Exemplo n.º 52
0
 public Assets(ModuleDeclaration module)
 {
     OnThrow = module.FindMethod(typeof(OnThrowAspectAttribute).GetMethod("OnThrow", new[] { typeof(Exception) }), BindingOptions.Default);
     Exception = module.FindType(typeof(Exception));
 }
 public LoggingImplementationTypeBuilder(ModuleDeclaration module)
 {
     this.module = module;
     this.weavingHelper = new WeavingHelper(module);
     this.containingType = this.CreateContainingType();
 }