2using System.Collections.Generic;
25 #region Private Variables
28 private object m_objectValue;
29 private object m_objectIndex;
33 #region Private Methods
35 private Operand(
OperandType operandType,
object objectValue,
object objectIndex)
37 m_operandType = operandType;
38 m_objectValue = objectValue;
39 m_objectIndex = objectIndex;
42 private string ToString(
object objectValue)
44 if (objectValue.GetType() == typeof(
string))
45 return "\"" + objectValue +
"\"";
47 return objectValue.ToString();
52 #region Public Static Methods
59 public static Operand
Variable(
string identifier)
61 return new Operand(
OperandType.Variable, identifier,
null);
66 return new Operand(
OperandType.Member, identifier, val);
71 return new Operand(
OperandType.Pointer, identifier, pointer);
76 return new Operand(
OperandType.InstructionPointer, instruction,
null);
81 return new Operand(
OperandType.FunctionPointer,
function,
null);
86 return new Operand(
OperandType.RoutinePointer, routine,
null);
91 #region Public Methods
93 private string ToLiteral(
string input)
96 var literal =
new StringBuilder(input.Length + 2);
98 foreach (var c
in input)
105 literal.Append(
"\\\"");
109 literal.Append(
"\\a");
113 literal.Append(
"\\b");
117 literal.Append(
"\\n");
121 literal.Append(
"\\r");
125 literal.Append(
"\\t");
129 if (
char.GetUnicodeCategory(c) != System.Globalization.UnicodeCategory.Control)
133 literal.Append(
@"\u");
134 literal.Append(((ushort)c).
ToString(
"x4"));
142 return literal.ToString();
149 switch (m_operandType)
156 if (m_objectValue.GetType().ToString() ==
"System.String")
157 return ToLiteral((
string)m_objectValue);
159 else if (m_objectValue.GetType().ToString() ==
"System.Char")
160 return ToLiteral(
"" + (
char)m_objectValue);
168 return m_objectValue.ToString();
171 return m_objectValue +
"[" +
ToString(m_objectIndex) +
"]";
174 return m_objectValue +
"[" + m_objectIndex +
"]";
177 return "[" + ((
Instruction) m_objectValue).Address.ToString(
"X8") +
"]";
182 return "<" + scriptFunction.Name +
"@" + scriptFunction.
EntryPoint.
Address.ToString(
"X8") +
">";
186 return m_objectValue.ToString();
189 return ToLiteral(m_operandType.ToString());
196 #region Public Properties
200 get {
return m_operandType; }
201 set { m_operandType = value; }
206 get {
return m_objectValue; }
215 return m_objectIndex;
221 m_objectIndex = value;
231 return (
string) m_objectIndex;
237 m_objectIndex = value;
245 if (m_operandType !=
OperandType.InstructionPointer)
252 if (m_operandType !=
OperandType.InstructionPointer)
255 m_objectValue = value;
273 m_objectValue = value;
292 m_objectValue = value;
A function, forward declared in a script.
An instruction in a virtual intermediate language.
Instruction InstructionPointer
static Operand MemberVariable(string identifier, object val)
static Operand Literal(object val)
override string ToString()
static Operand AllocateInstructionPointer(Instruction instruction)
static Operand CreatePointer(string identifier, string pointer)
static Operand AllocateFunctionPointer(Function function)
static Operand AllocateRoutinePointer(Routine routine)
static Operand Variable(string identifier)
A Routine is an abstract representation of a method.