-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCompilerToolCommon.cs
More file actions
100 lines (95 loc) · 2.58 KB
/
CompilerToolCommon.cs
File metadata and controls
100 lines (95 loc) · 2.58 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSharp.Java.Ast;
using System.IO;
namespace JSharp.Compiler
{
static class ListExtensions
{
public static void RemoveDoubles<T>(this List<T> list, T item) where T : class
{
var i = 0;
var count = 0;
while (i < list.Count)
{
var item2 = list[i];
if (item2 == item)
{
count++;
if (count > 1)
{
list.RemoveAt(i);
continue;
}
}
i++;
}
}
public static void RemoveDoublesByKey<K, T>(this IList<T> list, Func<T, K> keySelector)
where T : class
where K : class
{
var set = new HashSet<K>();
var i = 0;
while (i < list.Count)
{
var item = list[i];
var key = keySelector(item);
if (key != null)
{
if (set.Contains(key))
{
list.RemoveAt(i);
continue;
}
else
{
set.Add(key);
}
}
i++;
}
}
}
class CodeInjection
{
public CodeInjection()
{
Dependencies = new List<CodeInjection>();
}
public List<CodeInjection> SelfAndDependencies()
{
var list = new List<CodeInjection> { this };
if (Dependencies.IsNotNullOrEmpty())
{
foreach (var dep in Dependencies)
{
list.AddRange(dep.SelfAndDependencies());
}
}
return list;
}
public string JsCode { get; set; }
public string FunctionName { get; set; }
public JStatement JsStatement { get; set; }
public List<CodeInjection> Dependencies { get; set; }
}
class CompilerEvent
{
public CompilerEvent(Action before, Action action, Action after)
{
Before = before;
Action = action;
After = after;
}
public CompilerEvent(Action action)
{
Action = action;
}
public Action Before { get; set; }
public Action Action { get; set; }
public Action After { get; set; }
}
}