forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptCompilers.cs
More file actions
71 lines (71 loc) · 2.3 KB
/
Copy pathScriptCompilers.cs
File metadata and controls
71 lines (71 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor.Scripting.Compilers;
namespace UnityEditor.Scripting
{
internal static class ScriptCompilers
{
private static List<SupportedLanguage> _supportedLanguages;
static ScriptCompilers()
{
ScriptCompilers._supportedLanguages = new List<SupportedLanguage>();
foreach (Type current in new List<Type>
{
typeof(CSharpLanguage),
typeof(BooLanguage),
typeof(UnityScriptLanguage)
})
{
ScriptCompilers._supportedLanguages.Add((SupportedLanguage)Activator.CreateInstance(current));
}
}
internal static SupportedLanguageStruct[] GetSupportedLanguageStructs()
{
return (
from lang in ScriptCompilers._supportedLanguages
select new SupportedLanguageStruct
{
extension = lang.GetExtensionICanCompile(),
languageName = lang.GetLanguageName()
}).ToArray<SupportedLanguageStruct>();
}
internal static string GetNamespace(string file)
{
if (string.IsNullOrEmpty(file))
{
throw new ArgumentException("Invalid file");
}
string extensionOfSourceFile = ScriptCompilers.GetExtensionOfSourceFile(file);
foreach (SupportedLanguage current in ScriptCompilers._supportedLanguages)
{
if (current.GetExtensionICanCompile() == extensionOfSourceFile)
{
return current.GetNamespace(file);
}
}
throw new ApplicationException("Unable to find a suitable compiler");
}
internal static ScriptCompilerBase CreateCompilerInstance(MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater)
{
if (island._files.Length == 0)
{
throw new ArgumentException("Cannot compile MonoIsland with no files");
}
foreach (SupportedLanguage current in ScriptCompilers._supportedLanguages)
{
if (current.GetExtensionICanCompile() == island.GetExtensionOfSourceFiles())
{
return current.CreateCompiler(island, buildingForEditor, targetPlatform, runUpdater);
}
}
throw new ApplicationException(string.Format("Unable to find a suitable compiler for sources with extension '{0}' (Output assembly: {1})", island.GetExtensionOfSourceFiles(), island._output));
}
public static string GetExtensionOfSourceFile(string file)
{
string text = Path.GetExtension(file).ToLower();
return text.Substring(1);
}
}
}