forked from pasztorpisti/vs-window-title-changer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompiledExpressionCache.cs
47 lines (42 loc) · 1.33 KB
/
CompiledExpressionCache.cs
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
using System;
using VSWindowTitleChanger.ExpressionEvaluator;
namespace VSWindowTitleChanger
{
struct CompiledExpression
{
public ExpressionEvaluator.Expression expression;
public Exception compile_error;
public bool contains_exec;
}
class CompiledExpressionCache
{
ExecFuncEvaluator m_ExecFuncEvaluator;
IVariableValueResolver m_CompileTimeConstants;
Cache<string, CompiledExpression> m_Cache;
public CompiledExpressionCache(ExecFuncEvaluator exec_func_evaluator, IVariableValueResolver compile_time_constants, int max_size)
{
m_Cache = new Cache<string, CompiledExpression>(CompileExpression, max_size);
m_ExecFuncEvaluator = exec_func_evaluator;
m_CompileTimeConstants = compile_time_constants;
}
public CompiledExpression GetEntry(string expression_str)
{
return m_Cache.GetEntry(expression_str);
}
CompiledExpression CompileExpression(string expression_string)
{
CompiledExpression compiled = new CompiledExpression();
try
{
Parser expression_parser = new Parser(expression_string, m_ExecFuncEvaluator, m_CompileTimeConstants);
compiled.expression = expression_parser.Parse();
compiled.contains_exec = expression_parser.ContainsExec;
}
catch (Exception ex)
{
compiled.compile_error = ex;
}
return compiled;
}
}
}