public void SetUp() { snippetGenerator = new SnippetGenerator(true); var loader = new CecilLoader(); loader.IncludeInternalMembers = true; myLib = loader.LoadAssemblyFile(typeof(SnippetGenerationTests).Assembly.Location); mscorlib = loader.LoadAssemblyFile(typeof(object).Assembly.Location); compilation = new SimpleCompilation(myLib, mscorlib); }
private static IEnumerable <IUnresolvedAssembly> GetProjectReferences(List <string> explicitReferences) { var loader = new CecilLoader(); yield return(loader.LoadAssemblyFile(typeof(object).Assembly.Location)); foreach (var reference in explicitReferences) { yield return(loader.LoadAssemblyFile(reference)); } }
public void SetUp() { var cecilLoader = new CecilLoader() { IncludeInternalMembers = true }; var mscorlib = cecilLoader.LoadAssemblyFile(typeof(object).Assembly.Location); var systemCore = cecilLoader.LoadAssemblyFile(typeof(System.Linq.Enumerable).Assembly.Location); compilation = new SimpleCompilation(cecilLoader.LoadAssemblyFile(typeof(OverloadResolutionTests).Assembly.Location), mscorlib, systemCore); }
public CSharpCompletion() { projectContent = new CSharpProjectContent(); var assemblies = new List <Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll // typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll // typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll // typeof(Form).Assembly, // System.Windows.Forms.dll // typeof(ICSharpCode.NRefactory.TypeSystem.IProjectContent).Assembly, }; var unresolvedAssemblies = new IUnresolvedAssembly[assemblies.Count]; Stopwatch total = Stopwatch.StartNew(); Parallel.For( 0, assemblies.Count, delegate(int i) { var loader = new CecilLoader(); var path = assemblies[i].Location; loader.DocumentationProvider = GetXmlDocumentation(assemblies[i].Location); unresolvedAssemblies[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); Debug.WriteLine("Init project content, loading base assemblies: " + total.Elapsed); projectContent = projectContent.AddAssemblyReferences((IEnumerable <IUnresolvedAssembly>)unresolvedAssemblies); }
static IEnumerable <ITypeDefinition> LoadTypes() { var tt = typeof(File).Assembly.Location; Reflector.OutputDir = Environment.CurrentDirectory; var asmFile = Assembly.GetExecutingAssembly().Location; //asmFile = "".GetType().Assembly.Location; string xmlFile = Path.GetFullPath(Path.GetFileNameWithoutExtension(asmFile) + ".xml"); XmlDocumentationProvider doc = MonoCompletionEngine.GetXmlDocumentation(asmFile); if (doc == null && File.Exists(xmlFile)) { doc = new XmlDocumentationProvider(xmlFile); } var loader = new CecilLoader { DocumentationProvider = doc }; var unresolvedAsm = loader.LoadAssemblyFile(asmFile); var compilation = new SimpleCompilation(unresolvedAsm); var context = new SimpleTypeResolveContext(compilation); var asm = unresolvedAsm.Resolve(context); return(asm.GetAllTypeDefinitions().ToArray()); }
public CSharpCompletion() { projectContent = new CSharpProjectContent(); var assemblies = new List <Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll typeof(Sandbox.Common.ObjectBuilders.MyObjectBuilder_AdvancedDoor).Assembly, // SpaceEngineers.ObjectBuilders.dll typeof(SpaceEngineers.Game.ModAPI.IMyButtonPanel).Assembly, // SpaceEngineers.Game.dll typeof(Sandbox.MySandboxGame).Assembly, // Sandbox.Game.dll typeof(Sandbox.ModAPI.MyAPIGateway).Assembly, // Sandbox.Common.dll typeof(Sandbox.Graphics.GUI.MyGuiSandbox).Assembly, // Sandbox.Graphics.dll typeof(VRage.MyModelData).Assembly, // VRage.dll typeof(VRage.Exceptions).Assembly, // VRage.Library.dll typeof(VRageMath.MathHelper).Assembly, // VRage.Math typeof(VRage.Game.ObjectBuilders.MyObjectBuilder_EntityStat).Assembly, //VRage.Game }; var unresolvedAssemblies = new IUnresolvedAssembly[assemblies.Count]; Stopwatch total = Stopwatch.StartNew(); Parallel.For( 0, assemblies.Count, delegate(int i) { var loader = new CecilLoader(); var path = assemblies[i].Location; loader.DocumentationProvider = GetXmlDocumentation(assemblies[i].Location); unresolvedAssemblies[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); Debug.WriteLine("Init project content, loading base assemblies: " + total.Elapsed); projectContent = projectContent.AddAssemblyReferences((IEnumerable <IUnresolvedAssembly>)unresolvedAssemblies); }
/// <summary> /// Loads the assemblies needed to generate completion options. /// </summary> /// <param name="assemblies">List of assemblies. If nothing is passed in, a default list will be used.</param> /// <returns>List of assemblies.</returns> /// <remarks>This is an expensive operation.</remarks> private static IUnresolvedAssembly[] GetAssemblies(List <Assembly> assemblies = null) { // List of assemblies frequently used in manager scripts. // These assemblies get used by the CSharpCompletion object to look for intellisense options. // Would be better to dynamically generate this list based on the user's script. The disadvantage of doing it that way // is that loading these assemblies into the CSharpCompletion object is quite slow. if (assemblies == null) { assemblies = new List <Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(System.Linq.Enumerable).Assembly, // System.Core.dll typeof(System.Xml.XmlDocument).Assembly, // System.Xml.dll typeof(System.Drawing.Bitmap).Assembly, // System.Drawing.dll typeof(IProjectContent).Assembly, typeof(Models.Core.IModel).Assembly, // Models.exe typeof(APSIM.Shared.Utilities.StringUtilities).Assembly, // APSIM.Shared.dll } } ; assemblies = assemblies.Where(v => !v.IsDynamic).ToList(); IUnresolvedAssembly[] assemblyList = new IUnresolvedAssembly[assemblies.Count]; for (int i = 0; i < assemblies.Count; i++) { var loader = new CecilLoader(); loader.DocumentationProvider = GetXmlDocumentation(assemblies[i].Location); assemblyList[i] = loader.LoadAssemblyFile(assemblies[i].Location); } return(assemblyList); } }
private IUnresolvedAssembly Load(Assembly assembly) { var loader = new CecilLoader { DocumentationProvider = GetXmlDocumentation(assembly.Location) }; return(loader.LoadAssemblyFile(assembly.Location)); }
public CSharpAmbienceTests() { ambience = new CSharpAmbience(); mscorlib = CecilLoaderTests.Mscorlib; var loader = new CecilLoader(); loader.IncludeInternalMembers = true; myLib = loader.LoadAssemblyFile(typeof(CSharpAmbienceTests).Assembly.Location); compilation = new SimpleCompilation(myLib, mscorlib); }
public void FixtureSetUp() { // use "IncludeInternalMembers" so that Cecil results match C# parser results CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true }; testCasePC = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); }
public void FixtureSetUp() { CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true, LazyLoad = true }; IUnresolvedAssembly pc = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); base.compilation = new SimpleCompilation(pc, CecilLoaderTests.Mscorlib); }
public void FixtureSetUp() { // use "IncludeInternalMembers" so that Cecil results match C# parser results CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true }; IUnresolvedAssembly asm = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); compilation = new SimpleCompilation(asm, CecilLoaderTests.Mscorlib); }
public MetricsReader(string fileName) { loader = new CecilLoader(true) { IncludeInternalMembers = true }; namespaceMappings = new Dictionary <string, NamespaceNode>(); typeMappings = new Dictionary <ITypeDefinition, TypeNode>(); methodMappings = new Dictionary <IMethod, MethodNode>(); fieldMappings = new Dictionary <IField, FieldNode>(); cecilMappings = new Dictionary <MemberReference, IEntity>(); compilation = new SimpleCompilation(loader.LoadAssemblyFile(fileName)); // TODO load referenced assemblies into compilation. Assembly = new AssemblyNode(compilation.MainAssembly.AssemblyName); assemblyDefinition = loader.GetCecilObject(compilation.MainAssembly.UnresolvedAssembly); foreach (var type in compilation.MainAssembly.GetAllTypeDefinitions()) { ReadType(type); foreach (IMethod method in type.Methods) { ReadMethod(method); } foreach (IProperty property in type.Properties) { if (property.CanGet) { ReadMethod(property.Getter); } if (property.CanSet) { ReadMethod(property.Setter); } } foreach (IField field in type.Fields) { ReadField(field); } } foreach (var method in methodMappings.Values) { ReadInstructions(method, method.Method, loader.GetCecilObject((IUnresolvedMethod)method.Method.UnresolvedMember)); } Assembly.namespaces = namespaceMappings.Values; }
public static void AddAssembly(string file) { if (String.IsNullOrEmpty(file)) { return; } var loader = new CecilLoader(); var unresolvedAssembly = loader.LoadAssemblyFile(file); projectContent = projectContent.AddAssemblyReferences(unresolvedAssembly); }
// Token: 0x06000025 RID: 37 RVA: 0x00002B34 File Offset: 0x00000D34 private IUnresolvedAssembly LoadAssembly(string path) { if (this.assemblies.ContainsKey(path)) { return(this.assemblies[path]); } CecilLoader cecilLoader = new CecilLoader(); IUnresolvedAssembly unresolvedAssembly = cecilLoader.LoadAssemblyFile(path); this.assemblies.Add(path, unresolvedAssembly); return(unresolvedAssembly); }
public void FixtureSetUp() { CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true }; IProjectContent pc = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); FastSerializer serializer = new FastSerializer(); using (MemoryStream ms = new MemoryStream()) { serializer.Serialize(ms, pc); ms.Position = 0; testCasePC = (IProjectContent)serializer.Deserialize(ms); } }
public void FixtureSetUp() { CecilLoader loader = new CecilLoader() { IncludeInternalMembers = true }; IUnresolvedAssembly pc = loader.LoadAssemblyFile(typeof(TestCase.SimplePublicClass).Assembly.Location); FastSerializer serializer = new FastSerializer(); using (MemoryStream ms = new MemoryStream()) { serializer.Serialize(ms, pc); ms.Position = 0; var asm = (IUnresolvedAssembly)serializer.Deserialize(ms); base.compilation = new SimpleCompilation(asm, CecilLoaderTests.Mscorlib); } }
public Minifier(MinifierOptions options = null, string[] ignoredIdentifiers = null, string[] ignoredComments = null) { Options = options ?? new MinifierOptions(); _projectContent = new CSharpProjectContent(); var assemblies = new List <Assembly> { typeof(object).Assembly, // mscorlib typeof(Uri).Assembly, // System.dll typeof(Enumerable).Assembly, // System.Core.dll }; var unresolvedAssemblies = new IUnresolvedAssembly[assemblies.Count]; Parallel.For( 0, assemblies.Count, delegate(int i) { var loader = new CecilLoader(); var path = assemblies[i].Location; unresolvedAssemblies[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); _projectContent = _projectContent.AddAssemblyReferences((IEnumerable <IUnresolvedAssembly>)unresolvedAssemblies); IgnoredIdentifiers = ignoredIdentifiers == null ? new List <string>() : ignoredIdentifiers.ToList(); IgnoredComments = new List <string>(); if (ignoredComments != null) { foreach (string comment in ignoredComments) { var str = comment; if (str.StartsWith("//")) { str = str.Substring("//".Length); } else if (str.StartsWith("/*") && str.EndsWith("*/")) { str = str.Substring("/*".Length, str.Length - "/*".Length - "*/".Length); } if (!IgnoredComments.Contains(str)) { IgnoredComments.Add(str); } } } }
private IUnresolvedAssembly LoadAssembly(string filename) { if (filename.Contains("System.EnterpriseServices.dll")) { return(null);//HACK: exception is thrown by cecil in this assembly } var loader = new CecilLoader(); try { var x = loader.LoadAssemblyFile(filename); return(x); } catch (Exception e) { Console.WriteLine("Error loading assembly: " + filename + ", " + e.Message); return(null); } }
private void UpdateScriptCode() { string scriptStart, scriptEnd; string[] loadedReferences = InteractiveExecution.GetScriptHelperCode(out scriptStart, out scriptEnd).ToArray(); if (loadedReferences.Length != loadedAssemblies.Count) { var newAssemblies = new Dictionary <string, IUnresolvedAssembly>(); foreach (var assemblyPath in loadedReferences) { if (!loadedAssemblies.ContainsKey(assemblyPath)) { try { var loader = new CecilLoader(); loader.DocumentationProvider = GetXmlDocumentation(assemblyPath); newAssemblies.Add(assemblyPath, loader.LoadAssemblyFile(assemblyPath)); } catch (Exception) { newAssemblies.Add(assemblyPath, null); } } } if (newAssemblies.Count > 0) { projectContent = projectContent.AddAssemblyReferences(newAssemblies.Values.Where(a => a != null)); foreach (var kvp in newAssemblies) { loadedAssemblies.Add(kvp.Key, kvp.Value); } } } Regex lineRegex = new Regex("#line[^\n]*", RegexOptions.Compiled); ScriptStart = lineRegex.Replace(scriptStart, ""); ScriptEnd = lineRegex.Replace(scriptEnd, ""); }
IProjectContent[] LoadProjects(CecilLoader loader) { const string dir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\"; return(new IProjectContent[] { loader.LoadAssemblyFile(dir + "mscorlib.dll"), loader.LoadAssemblyFile(dir + "System.dll"), loader.LoadAssemblyFile(dir + "System.Core.dll"), loader.LoadAssemblyFile(dir + "System.Xml.dll"), loader.LoadAssemblyFile(dir + "System.Xml.Linq.dll"), loader.LoadAssemblyFile(dir + "System.Data.dll"), loader.LoadAssemblyFile(dir + "System.Drawing.dll"), loader.LoadAssemblyFile(dir + "System.Windows.Forms.dll"), loader.LoadAssemblyFile(dir + "WindowsBase.dll"), loader.LoadAssemblyFile(dir + "PresentationCore.dll"), loader.LoadAssemblyFile(dir + "PresentationFramework.dll") }); }
/// <summary> /// Public translation interface. /// Translates the given method to HLSL /// </summary> /// <param name="s">Shader type definition.</param> /// <param name="m">A method representing a shader to translate.</param> /// <param name="attr">The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute</param> /// <param name="type">The shader type as ShaderType</param> /// <returns>The translated GLSL shader source</returns> public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr, ShaderType type) { if (s == null) { throw new ArgumentNullException("s"); } if (m == null) { throw new ArgumentNullException("m"); } if (attr == null) { throw new ArgumentNullException("attr"); } var sbase = s.BaseType.Resolve(); while (sbase.MetadataToken.ToInt32() != typeof(Shader).MetadataToken) { sbase = sbase.BaseType.Resolve(); } var dctx = new DecompilerContext(s.Module) { CurrentType = s, CurrentMethod = m, CancellationToken = CancellationToken.None }; var d = AstMethodBodyBuilder.CreateMethodBody(m, dctx); //var ctx = new CecilTypeResolveContext(sbase.Module); var loader = new CecilLoader(); var mscorlib = loader.LoadAssemblyFile(typeof(object).Assembly.Location); var slsharp = loader.LoadAssembly(sbase.Module.Assembly); var project = loader.LoadAssembly(s.Module.Assembly); var ctx = new CompositeTypeResolveContext(new[] { project, slsharp, mscorlib }); var resolver = new CSharpResolver(ctx, CancellationToken.None) { UsingScope = new UsingScope(project) }; /* * foreach (var v in m.Body.Variables) * { * resolver.AddVariable(v.VariableType, null, v.Name) * }*/ //resolver.AddVariable() //resolver.LocalVariables = m.Body.Variables; // TODO: need a more sane way to get the correct class + member var ss = ctx.GetAllTypes().First(c => c.FullName == s.FullName); resolver.CurrentTypeDefinition = ss; resolver.CurrentMember = ss.Methods.First(n => SameMethod(m, n, ctx)); var rv = new ResolveVisitor(resolver, new ParsedFile("memory", resolver.UsingScope), null); var glsl = new HlslVisitor(d, attr, rv, dctx); _functions.UnionWith(glsl.Functions); var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value; var sig = HlslVisitor.GetSignature(m); var code = glsl.Result; var desc = new FunctionDescription(Shader.GetMethodName(m), sig + code, entry, type); _dependencies.UnionWith(glsl.Dependencies); return(desc); }