public LibraryOrTypeNodeViewModel(TypeLibrary library)
        {
            TypeLibrary   = library;
            Name          = library.Name;
            IconUriSource = @"\Resources\library.png";
            if (library.Hidden)
            {
                AccessUriSource = @"\Resources\lock.png";
            }

            foreach (var t in library.UserDefinedTypes)
            {
                GetViewModelForVbaType(t);
            }
        }
        public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
        {
            var rdr          = new StreamReader(new MemoryStream(bytes));
            var lexer        = new PascalLexer(rdr);
            var parser       = new PascalParser(lexer);
            var symbolTable  = new SymbolTable(platform);
            var declarations = parser.Parse();
            var tldser       = new TypeLibraryDeserializer(platform, true, dstLib);
            var constants    = EvaluateConstants(declarations);
            var typeImporter = new TypeImporter(platform, tldser, constants, dstLib);

            typeImporter.LoadTypes(declarations);
            LoadServices(declarations, typeImporter, constants, platform, dstLib);
            return(dstLib);
        }
Exemple #3
0
        private void Expect_TypeLibraryLoaderService_LoadLibrary(string expected, IDictionary <string, DataType> types)
        {
            var tl = new TypeLibrary(
                false,
                types,
                new Dictionary <string, FunctionType>(),
                new Dictionary <string, DataType>());

            Expect_TypeLibraryLoaderService_LoadLibrary(
                new TypeLibraryDefinition
            {
                Name = expected,
            },
                tl);
        }
Exemple #4
0
        internal static void SelectTypeLib(TypeLibrary lib)
        {
            // Find and select the registered node
            BrowserTreeNode typeLibNode = FindTypeLib(lib.Key);

            if (typeLibNode != null)
            {
                typeLibNode.PointToNode();
            }
            else
            {
                throw new Exception("Bug, expected to be in type lib tree: "
                                    + lib);
            }
        }
        public void CanDeclareAndCompileTypeMembers()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            //-- act

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);

            backend.ExpectCompile(type1, type2);
            libraryUnderTest.CompileDeclaredTypeMembers();

            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompile(type3, type4);
            libraryUnderTest.CompileDeclaredTypeMembers();

            // this should do nothing
            libraryUnderTest.CompileDeclaredTypeMembers();

            var product1 = libraryUnderTest.GetProduct(ref key1);
            var product2 = libraryUnderTest.GetProduct(ref key2);
            var product3 = libraryUnderTest.GetProduct(ref key3);
            var product4 = libraryUnderTest.GetProduct(ref key4);

            //-- assert

            product1.Artifact.SourceType.Should().BeSameAs(type1);
            product2.Artifact.SourceType.Should().BeSameAs(type2);
            product3.Artifact.SourceType.Should().BeSameAs(type3);
            product4.Artifact.SourceType.Should().BeSameAs(type4);
        }
        internal ComStructInfo(TypeLibrary typeLib,
                               TYPEKIND typeKind,
                               int index) :
            base(typeLib, typeKind, index)
        {
            switch (typeKind)
            {
            case TYPEKIND.TKIND_ENUM:
                _infoType = "Enum";
                break;

            case TYPEKIND.TKIND_MODULE:
                _infoType = "Module";
                break;

            case TYPEKIND.TKIND_RECORD:
                _infoType = "Struct";
                break;

            case TYPEKIND.TKIND_UNION:
                _infoType = "Union";
                break;
            }

            TYPEATTR typeAttr;
            IntPtr   typeAttrPtr;

            _typeInfo.GetTypeAttr(out typeAttrPtr);
            typeAttr =
                (TYPEATTR)Marshal.PtrToStructure(typeAttrPtr,
                                                 typeof(TYPEATTR));

            for (int i = 0; i < typeAttr.cVars; i++)
            {
                ComVariableInfo mi = new ComVariableInfo(this,
                                                         _typeKind,
                                                         _typeInfo,
                                                         i);
                _members.Add(mi);
            }

            _typeInfo.ReleaseTypeAttr(typeAttrPtr);

            if (TraceUtil.If(this, TraceLevel.Verbose))
            {
                Trace.WriteLine("Struct: " + _name);
            }
        }
Exemple #7
0
        // Restore the typelibs/controls that were previously loaded
        public static void RestoreComEnvironment()
        {
            if (_typelibs.Count == 0)
            {
                return;
            }
            ProgressDialog progressDialog = new ProgressDialog();

            progressDialog.Setup("Loading Remembered ActiveX Files",
                                 "Please wait while I load the previously " +
                                 "opened ActiveX files.",
                                 _typelibs.Count,
                                 ProgressDialog.HAS_PROGRESS_TEXT,
                                 ProgressDialog.FINAL);
            progressDialog.ShowIfNotDone();
            TraceUtil.WriteLineInfo(null, DateTime.Now + " ActiveX Restore start ");
            try {
                for (int i = _typelibs.Count - 1; i >= 0; --i)
                {
                    PreviouslyOpenedTypeLibrary typeLib = _typelibs[i];
                    try {
                        TraceUtil.WriteLineInfo(null, DateTime.Now + " restore assy: " + typeLib.FileName);
                        progressDialog.UpdateProgressText(typeLib.FileName);
                        Guid guid = new Guid(typeLib.Guid);
                        TypeLibrary.RestoreTypeLib(typeLib.FileName, guid, typeLib.Version);
                        TraceUtil.WriteLineInfo(null, DateTime.Now + " loaded assy: " + typeLib.FileName);
                        progressDialog.UpdateProgress(1);
                    } catch (Exception ex) {
                        TraceUtil.WriteLineWarning(null,
                                                   "Assemblies - deleting bad assemblies entry: "
                                                   + typeLib.FileName + " " + ex);
                        _typelibs.Remove(typeLib);
                        progressDialog.UpdateProgress(1);
                    }
                }
                // This depends on having all of the assemblies restored
                TraceUtil.WriteLineInfo(null, DateTime.Now + " ActiveX Restore end ");
            } catch (Exception ex) {
                TraceUtil.WriteLineError(null, "Unexpected exception "
                                         + "restoring assemblies: " + ex);
            }
            progressDialog.Finished();
            if (ComponentInspectorProperties.AddRunningComObjects)
            {
                AddRunningObjs();
            }
            FavoriteTypeLibNode.Expand();
        }
            public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
            {
                SerializationUtils.Assert(reader.TokenType == JsonTokenType.StartObject);

                SerializationUtils.MustReadPropertyName(ref reader, "Type");
                SerializationUtils.MustReadTokenType(ref reader, JsonTokenType.String);

                T obj;

                try
                {
                    obj = TypeLibrary.CreateInstance <T>(reader.GetString());
                }
                catch (TypeLibrary.UnknownTypeException e)
                {
                    throw new SerializationUtils.UnknownTypeException(reader.GetString(), e);
                }

                SerializationUtils.MustReadPropertyName(ref reader, "ID");
                SerializationUtils.MustReadTokenType(ref reader, JsonTokenType.Number);
                var id = reader.GetInt64();

                var readJsonDelegates = GetReadJsonDelegates(obj);

                reader.Read();
                while (reader.TokenType != JsonTokenType.EndObject)
                {
                    SerializationUtils.Assert(reader.TokenType == JsonTokenType.PropertyName);
                    var typeName = reader.GetString();
                    SerializationUtils.MustReadTokenType(ref reader, JsonTokenType.StartObject);

                    if (readJsonDelegates.ContainsKey(typeName))
                    {
                        readJsonDelegates[typeName].Invoke(ref reader, options);
                    }
                    else
                    {
                        // Warn
                        SerializationUtils.FinishCurrentObject(ref reader);
                    }
                    SerializationUtils.Assert(reader.TokenType == JsonTokenType.EndObject);
                    reader.Read();
                }

                SerializationUtils.Assert(reader.TokenType == JsonTokenType.EndObject);
                m_createdObjects.Add(id, obj);
                return(obj);
            }
Exemple #9
0
        public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
        {
            var rdr          = new StreamReader(new MemoryStream(bytes));
            var lexer        = new CLexer(rdr);
            var state        = new ParserState();
            var parser       = new CParser(state, lexer);
            var symbolTable  = new SymbolTable(platform);
            var declarations = parser.Parse();
            var tldser       = new TypeLibraryDeserializer(platform, true, dstLib);

            foreach (var decl in declarations)
            {
                ProcessDeclaration(decl, platform, tldser, symbolTable);
            }
            return(dstLib);
        }
Exemple #10
0
        private void AddTypeLibraryViewModel(TypeLibrary library)
        {
            if (library.FilePath == null)
            {
                return;
            }
            var viewModel = (from vm in LoadedTypeLibraries
                             where vm.TypeLibrary.FilePath != null &&
                             vm.TypeLibrary.FilePath == library.FilePath
                             select vm).SingleOrDefault();

            if (viewModel == null)
            {
                viewModel = new LibraryOrTypeNodeViewModel(library);
                LoadedTypeLibraries.Add(viewModel);
            }
        }
        // This could either be a MemberInfo, Type or a TypeLibrary,
        // and we point
        // to the correct node
        public void ShowTarget(Object linkModifier)
        {
            BrowserTreeNode resultNode = null;

            // A type library
            if (linkModifier is TypeLibrary)
            {
                resultNode = ComSupport.FindTypeLib(((TypeLibrary)linkModifier).Key);
            }
            else
            {
                Type type;
                if (linkModifier is Type)
                {
                    type = (Type)linkModifier;
                }
                else
                {
                    type = ((MemberInfo)linkModifier).DeclaringType;
                }
                // Get the typelib node
                TypeLibrary typeLib = TypeLibrary.GetTypeLib(type);
                if (typeLib == null)
                {
                    return;
                }
                // Find the type, this could be a class or an interface
                ComTypeLibTreeNode typeLibNode = (ComTypeLibTreeNode)ComSupport.FindTypeLib(typeLib.Key);
                String             typeName    = typeLib.GetMemberName(type);
                typeLibNode.ExpandNode();
                resultNode = SearchNode(typeLibNode, typeName);
                // Find the member (Type is also a MemberInfo)
                if (!(linkModifier is Type))
                {
                    MemberInfo      mi           = (MemberInfo)linkModifier;
                    ComTypeTreeNode typeTreeNode = (ComTypeTreeNode)resultNode;
                    resultNode = FindMember(typeLibNode, typeTreeNode, mi);
                }
            }
            // Point to the result
            if (resultNode != null)
            {
                ObjectBrowser.TabControl.SelectedTab = ComSupport.ComTabPage;
                resultNode.PointToNode();
            }
        }
Exemple #12
0
        public SystemService Build(IPlatform platform, TypeLibrary library)
        {
            SystemService svc = new SystemService();

            svc.Name               = Name;
            svc.SyscallInfo        = new SyscallInfo();
            svc.SyscallInfo.Vector = SyscallInfo != null
                ? Convert.ToInt32(SyscallInfo.Vector, 16)
                : this.Ordinal;

            if (SyscallInfo != null)
            {
                if (SyscallInfo.RegisterValues != null)
                {
                    svc.SyscallInfo.RegisterValues = new RegValue[SyscallInfo.RegisterValues.Length];
                    for (int i = 0; i < SyscallInfo.RegisterValues.Length; ++i)
                    {
                        svc.SyscallInfo.RegisterValues[i] = new RegValue
                        {
                            Register = platform.Architecture.GetRegister(SyscallInfo.RegisterValues[i].Register),
                            Value    = Convert.ToInt32(SyscallInfo.RegisterValues[i].Value, 16),
                        };
                    }
                }
                if (SyscallInfo.StackValues != null)
                {
                    svc.SyscallInfo.StackValues = SyscallInfo.StackValues.Select(sv =>
                                                                                 new StackValue
                    {
                        Offset = Convert.ToInt32(sv.Offset, 16),
                        Value  = Convert.ToInt32(sv.Value, 16)
                    }).ToArray();
                }
            }
            if (svc.SyscallInfo.RegisterValues == null)
            {
                svc.SyscallInfo.RegisterValues = new RegValue[0];
            }
            var loader = new TypeLibraryDeserializer(platform, true, library);
            var sser   = new ProcedureSerializer(platform, loader, "stdapi");

            svc.Signature       = sser.Deserialize(Signature, platform.Architecture.CreateFrame());
            svc.Characteristics = Characteristics != null ? Characteristics : DefaultProcedureCharacteristics.Instance;
            return(svc);
        }
Exemple #13
0
        protected Type GetTypeFromTypeLib(TypeLibrary typeLib)
        {
            if (typeLib == null)
            {
                _typeFailedException =
                    new Exception("Unable to determine TypeLib "
                                  + "from CLSID: " + _guidStr);
                throw _typeFailedException;
            }

            // Set this information because we might have read the
            // class from a source other than the type library
            _container = typeLib;
            _typeLib   = typeLib;

            // Get the type associated with the CLSId from the typelib
            if (Name == null)
            {
                ComClassInfo clsInfo = typeLib.GetClassInfoFromCLSID(_guid);
                Name = clsInfo.Name;
            }

            Type type = typeLib.FindTypeByName(Name,
                                               TypeLibrary.FIND_CLASS);

            if (type == null)
            {
                _typeFailedException =
                    new Exception("CLR type not found in "
                                  + _container
                                  + " for ActiveX type "
                                  + this
                                  + ".\n\nThis is likely caused by "
                                  + "the assembly corresponding to "
                                  + "this type library not being "
                                  + "available.");
                throw _typeFailedException;
            }

            if (TraceUtil.If(this, TraceLevel.Info))
            {
                Trace.WriteLine("ComClassInfo - type: " + type);
            }
            return(type);
        }
Exemple #14
0
        public void SlLookupType()
        {
            var slib = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef {
                        Name     = "int",
                        DataType = new PrimitiveType_v1 {
                            Domain = Reko.Core.Types.Domain.SignedInt, ByteSize = 4
                        }
                    }
                }
            };
            var lib = TypeLibrary.Load(new IntelArchitecture(ProcessorMode.Protected32), slib);

            Assert.AreEqual(PrimitiveType.Int32, lib.LookupType("int"));
        }
        public void Tlldr_signature()
        {
            Given_ArchitectureStub();
            arch.Stub(a => a.GetRegister("r3")).Return(new RegisterStorage("r3", 3, 0, PrimitiveType.Word32));
            var r3 = new RegisterStorage("r3", 3, 0, PrimitiveType.Word32);

            Given_ProcedureSignature(new FunctionType(
                                         new Identifier("", PrimitiveType.Int32, r3),
                                         new[] {
                new Identifier("", PrimitiveType.Real32, r3)
            }
                                         ));
            mr.ReplayAll();

            var typelib = new TypeLibrary();
            var tlldr   = new TypeLibraryDeserializer(platform, true, typelib);
            var fn      = tlldr.VisitSignature(new SerializedSignature
            {
                Arguments = new[]
                {
                    new Argument_v1 {
                        Name = "reg1",
                        Type = new PrimitiveType_v1 {
                            Domain = Domain.Real, ByteSize = 4
                        },
                        Kind = new Register_v1 {
                            Name = "r3"
                        }
                    }
                },
                ReturnValue = new Argument_v1
                {
                    Type = new PrimitiveType_v1 {
                        Domain = Domain.SignedInt, ByteSize = 4
                    },
                    Kind = new Register_v1 {
                        Name = "r3"
                    }
                }
            });

            Assert.AreEqual("(fn int32 (real32))", fn.ToString());
            mr.VerifyAll();
        }
Exemple #16
0
        public void TypesFailedToCompileDoNotExistAsProducts()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            //-- Assert

            Assert.Throws <KeyNotFoundException>(() => {
                libraryUnderTest.GetProduct(ref key2);
            });

            Assert.Throws <KeyNotFoundException>(() => {
                libraryUnderTest.GetProduct(ref key4);
            });
        }
Exemple #17
0
        public TypeLibrary LoadLibrary(IProcessorArchitecture arch, string name)
        {
            try
            {
                string libFileName = ImportFileLocation(name);
                if (!File.Exists(libFileName))
                {
                    return(null);
                }

                var lib = TypeLibrary.Load(arch, libFileName);
                lib.Filename = libFileName;
                return(lib);
            }
            catch
            {
                return(null);
            }
        }
        public TypeLibrary LoadLibrary(Platform platform, string name)
        {
            try
            {
                string libFileName = ImportFileLocation(name);
                if (!File.Exists(libFileName))
                {
                    return(null);
                }

                var lib = TypeLibrary.Load(platform, libFileName);
                lib.Filename = libFileName;
                return(lib);
            }
            catch
            {
                return(null);
            }
        }
Exemple #19
0
        public void SucceededProductsExistAfterFailedCompilation()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            var product1 = libraryUnderTest.GetProduct(ref key1);
            var product3 = libraryUnderTest.GetProduct(ref key3);

            //-- Assert

            product1.Artifact.SourceType.Should().BeSameAs(type1);
            product3.Artifact.SourceType.Should().BeSameAs(type3);
        }
Exemple #20
0
        // Adds the remembered type lib to the favorites part
        // of the type library tree
        internal static BrowserTreeNode AddTypeLib(TypeLibrary lib)
        {
            BrowserTreeNode findRoot;

            findRoot = _favTypeLibNode;
            if (findRoot == null)
            {
                return(null);
            }
            BrowserTreeNode typeLibNode = FindTypeLib(lib.Key, findRoot);

            if (typeLibNode == null)
            {
                typeLibNode = new ComTypeLibTreeNode(lib);
                // This might be called on the thread to restore open typelibs
                _comTree.Invoke(new BrowserTreeNode.AddLogicalInvoker(findRoot.AddLogicalNode),
                                new Object[] { typeLibNode });
            }
            return(typeLibNode);
        }
Exemple #21
0
        public void CompilationErrorsExceptionThrownWhenSomeTypesFailToCompile()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(ITestContractA));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            var key2  = new TypeKey(this.GetType(), typeof(ITestContractB));
            var type2 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key2));

            var key3  = new TypeKey(this.GetType(), typeof(ITestContractC));
            var type3 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key3));

            var key4  = new TypeKey(this.GetType(), typeof(ITestContractD));
            var type4 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key4));

            libraryUnderTest.DeclareTypeMember(key1, type1);
            libraryUnderTest.DeclareTypeMember(key2, type2);
            libraryUnderTest.DeclareTypeMember(key3, type3);
            libraryUnderTest.DeclareTypeMember(key4, type4);

            backend.ExpectCompileWithErrors(
                new[] { type1, type2, type3, type4 },
                success: new[] { true, false, true, false });

            //-- act

            var exception = Assert.Throws <CompilationErrorsException>(() => {
                libraryUnderTest.CompileDeclaredTypeMembers();
            });

            //-- Assert

            exception.TypesFailedToCompile.Should().NotBeNull();
            exception.TypesFailedToCompile.Count.Should().Be(2);
            exception.TypesFailedToCompile[0].Type.Should().BeSameAs(type2);
            exception.TypesFailedToCompile[1].Type.Should().BeSameAs(type4);
        }
Exemple #22
0
 public TypeLibrary Load(IPlatform platform, string module, TypeLibrary dstLib)
 {
     this.platform   = platform;
     this.tlLoader   = new TypeLibraryDeserializer(platform, true, dstLib);
     this.moduleName = module;
     tlLoader.SetModuleName(module);
     for (;;)
     {
         var tok = Peek();
         if (tok.Type == TokenType.EOF)
         {
             break;
         }
         if (PeekAndDiscard(TokenType.NL))
         {
             continue;
         }
         ParseLine();
     }
     return(dstLib);
 }
Exemple #23
0
        internal static AssemblyTreeNode AddAssy(Assembly assy, TypeLibrary typeLib)
        {
            // The assembly might have already been added (this can
            // happen when a previously converted [from com] assembly
            // is opened), if so,
            // find it and make sure the typeLib information is provided
            AssemblyTreeNode atNode = FindAssemblyNode(assy);

            if (atNode != null)
            {
                if (typeLib != null)
                {
                    atNode.TypeLib = typeLib;
                }
                return(atNode);
            }
            ICollection types = null;

            // Only get the types if the control tree is showing because
            // it can take a long time
            if (ComponentInspectorProperties.ShowControlPanel)
            {
                types = GetAssyTypes(assy);
            }
            AssemblyTreeNode node = new AssemblyTreeNode(assy, typeLib);

            if (_assyTree.InvokeRequired)
            {
                _assyTree.Invoke(new BrowserTreeNode.AddLogicalInvoker(_assyRootNode.AddLogicalNode),
                                 new Object[] { node });
                _controlTree.Invoke(new ControlTree.AddAssyInvoker(ControlTree.AddAssy),
                                    new Object[] { assy, types });
            }
            else
            {
                _assyRootNode.AddLogicalNode(node);
                ControlTree.AddAssy(assy, types);
            }
            return(node);
        }
        public void Tlldr_typedef_forwarded_union()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var typelib = new TypeLibrary();
            var tlldr   = new TypeLibraryDeserializer(platform, true, typelib);

            new SerializedTypedef
            {
                Name     = "variant_t",
                DataType = new UnionType_v1
                {
                    Name = "variant_union",
                }
            }.Accept(tlldr);
            new UnionType_v1
            {
                Name         = "variant_union",
                Alternatives = new[]
                {
                    new SerializedUnionAlternative {
                        Name = "foo",
                        Type = new PrimitiveType_v1 {
                            Domain = Domain.Integer, ByteSize = 4
                        },
                    },
                    new SerializedUnionAlternative {
                        Name = "bar",
                        Type = new PrimitiveType_v1 {
                            Domain = Domain.Real, ByteSize = 4
                        }
                    }
                }
            }.Accept(tlldr);

            var str = (UnionType)typelib.Types["variant_t"];

            Assert.AreEqual("(union \"variant_union\" (ui32 foo) (real32 bar))", str.ToString());
        }
Exemple #25
0
        public Assembly ResolveRef(object typeLib)
        {
            ITypeLib tLib = typeLib as ITypeLib;
            string   tLibname;
            string   outputFolder = "";
            string   interopFileName;
            string   asmPath;

            try
            {
                tLibname = Marshal.GetTypeLibName(tLib);
                IntPtr ppTlibAttri = IntPtr.Zero;
                tLib.GetLibAttr(out ppTlibAttri);
                System.Runtime.InteropServices.ComTypes.TYPELIBATTR tLibAttri = (System.Runtime.InteropServices.ComTypes.TYPELIBATTR)Marshal.PtrToStructure(ppTlibAttri, typeof(System.Runtime.InteropServices.ComTypes.TYPELIBATTR));
                string           guid        = tLibAttri.guid.ToString();
                RegistryKey      typeLibsKey = Registry.ClassesRoot.OpenSubKey("TypeLib\\{" + guid + "}");
                TypeLibrary      typeLibrary = TypeLibrary.Create(typeLibsKey);
                Converter.TlbImp importer    = new Converter.TlbImp(Parent.References);
                outputFolder    = Path.GetDirectoryName(this.Parent.AsmPath);
                interopFileName = Path.Combine(outputFolder, String.Concat("Interop.", typeLibrary.Name, ".dll"));

                asmPath = interopFileName;
                //asm.Save(Path.GetFileName(asmPath));
                //Call ResolveRefEventArgs to notify extra assembly imported as depenedencies
                ResolveRefEventArgs t = new ResolveRefEventArgs("Reference Interop '" + Path.GetFileName(asmPath) + "' created succesfully.");
                Parent.InvokeResolveRef(t);
                Parent.References.Add(new ComReferenceProjectItem(ScriptControl.GetProject(), typeLibrary));
                return(importer.Import(interopFileName, typeLibrary.Path, typeLibrary.Name, this.Parent));
            }
            catch (Exception Ex)
            {
                ResolveRefEventArgs t = new ResolveRefEventArgs(Ex.Message);
                Parent.InvokeResolveRef(t);
                return(null);
            }
            finally
            {
                Marshal.ReleaseComObject(tLib);
            }
        }
Exemple #26
0
        public void CanGetTypeMemberForExistingProduct()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(string));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            backend.RaiseProductsLoaded(new TypeFactoryProduct <TestArtifact>(key1, new TestArtifact(type1)));

            //-- act

            var actualResult = libraryUnderTest.GetOrBuildTypeMember(key1, actualKey => {
                throw new Exception("Callback should not be invoked");
            });

            //-- Assert

            actualResult.Should().BeSameAs(type1);
        }
Exemple #27
0
        public void CanGetDeclaredTypeMember()
        {
            //-- arrange

            var backend          = new TestBackend();
            var libraryUnderTest = new TypeLibrary <TestArtifact>(backend);

            var key1  = new TypeKey(this.GetType(), typeof(string));
            var type1 = new TypeMember(new TypeGeneratorInfo(this.GetType(), key1));

            libraryUnderTest.DeclareTypeMember(key1, type1);

            //-- act

            var actualResult = libraryUnderTest.GetOrBuildTypeMember(key1, actualKey => {
                throw new Exception("Callback should not be invoked");
            });

            //-- Assert

            actualResult.Should().BeSameAs(type1);
        }
Exemple #28
0
        // Returns a ComClassInfo for the requested class
        // Used for creating from within a typelib
        internal static ComClassInfo GetClassInfo(TypeLibrary typeLib,
                                                  TYPEKIND typeKind,
                                                  int index)
        {
            UCOMITypeInfo typeInfo;

            typeLib.ITypeLib.GetTypeInfo(index, out typeInfo);
            Guid guid = GuidFromTypeInfo(typeInfo);

            ComClassInfo clsInfo = (ComClassInfo)_classesByCLSID[guid];

            if (clsInfo != null)
            {
                // Add the type lib information if we have seen this
                // class before
                clsInfo.SetupTypeLibInfo(typeLib, typeKind, index,
                                         null, Guid.Empty);
                return(clsInfo);
            }

            return(new ComClassInfo(typeLib, typeKind, index,
                                    typeInfo, guid));
        }
        internal AssemblyTreeNode(Assembly assembly,
                                  TypeLibrary typeLib) : base()
        {
            _assembly = assembly;
            _typeLib  = typeLib;

            MethodInfo entryPoint = null;

            try
            {
                entryPoint = _assembly.EntryPoint;
            }
            catch
            {
                // Sadly, this can throw for some reason
            }

            if (entryPoint != null)
            {
                _isDragSource = true;
            }
            PostConstructor();
        }
Exemple #30
0
        public void SudLoadMetadata()
        {
            var sProject = new Project_v2 {
                Inputs =
                {
                    new MetadataFile_v2
                    {
                        Filename = "c:\\tmp\\foo.def"
                    }
                }
            };
            var loader  = mr.Stub <ILoader>();
            var typelib = new TypeLibrary();

            loader.Stub(l => l.LoadMetadata("")).IgnoreArguments().Return(typelib);
            mr.ReplayAll();

            var ploader = new ProjectLoader(loader);
            var project = ploader.LoadProject(sProject);

            Assert.AreEqual(1, project.MetadataFiles.Count);
            Assert.AreEqual("c:\\tmp\\foo.def", project.MetadataFiles[0].Filename);
        }
        //$REFACTOR: needs a better name.
        public TypeLibrary LoadLibrary(IPlatform platform, string name, TypeLibrary dstLib)
        {
            try
            {
                string libFileName = ImportFileLocation(name);
                if (!File.Exists(libFileName))
                    return dstLib;

                byte[] bytes;
                var fsSvc = services.RequireService<IFileSystemService>();
                using (var stm = fsSvc.CreateFileStream(libFileName, FileMode.Open, FileAccess.Read))
                {
                    bytes = new Byte[stm.Length];
                    stm.Read(bytes, 0, (int)stm.Length);
                }
                var tlldr = new TypeLibraryLoader(services, libFileName, bytes);
                var lib = tlldr.Load(platform, dstLib);
                return lib;
            }
            catch
            {
                return dstLib;
            }
        }
        public TypeLibrary LoadMetadataIntoLibrary(IPlatform platform, ITypeLibraryElement tlElement, TypeLibrary libDst)
        {
            var cfgSvc = services.RequireService<IConfigurationService>();
            var fsSvc = services.RequireService<IFileSystemService>();
            var diagSvc = services.RequireService<IDiagnosticsService>();
            try
            {
                string libFileName = cfgSvc.GetInstallationRelativePath(tlElement.Name);
                if (!fsSvc.FileExists(libFileName)) 
                    return libDst;

                byte[] bytes = fsSvc.ReadAllBytes(libFileName);
                MetadataLoader loader = CreateLoader(tlElement, libFileName, bytes);
                if (loader == null)
                    return libDst;
                var lib = loader.Load(platform, libDst);
                return lib;
            }
            catch (Exception ex)
            {
                diagSvc.Error(ex, string.Format("Unable to load metadata file {0}.", tlElement.Name));
                return libDst;
            }
        }
Exemple #33
0
 void Awake()
 {
     if (_instance == null)
     {
         //If I am the first instance, make me the Singleton
         _instance = this;
         DontDestroyOnLoad(this);
     }
     else
     {
         //If a Singleton already exists and you find
         //another reference in scene, destroy it!
         if (this != _instance)
             Destroy(this.gameObject);
     }
 }
Exemple #34
0
 public Library(TypeLibrary typeLibrary)
 {
     TypeLibrary = typeLibrary;
 }
Exemple #35
0
 public TypeObject SetLibrary(TypeLibrary library)
 {
     Library = library;
     throw new NotImplementedException();
 }