29 using System.Collections.Generic;
30 using System.Reflection;
34 namespace OpenSim.
Region.ScriptEngine.Shared.CodeTools
40 private SYMBOL m_astRoot = null;
41 private static Dictionary<string, string> m_datatypeLSL2OpenSim = null;
52 if (null == m_datatypeLSL2OpenSim)
54 m_datatypeLSL2OpenSim =
new Dictionary<string, string>();
55 m_datatypeLSL2OpenSim.Add(
"integer",
"LSL_Types.LSLInteger");
56 m_datatypeLSL2OpenSim.Add(
"float",
"LSL_Types.LSLFloat");
58 m_datatypeLSL2OpenSim.Add(
"key",
"LSL_Types.LSLString");
59 m_datatypeLSL2OpenSim.Add(
"string",
"LSL_Types.LSLString");
60 m_datatypeLSL2OpenSim.Add(
"vector",
"LSL_Types.Vector3");
61 m_datatypeLSL2OpenSim.Add(
"rotation",
"LSL_Types.Quaternion");
62 m_datatypeLSL2OpenSim.Add(
"list",
"LSL_Types.list");
72 foreach (SYMBOL s
in m_astRoot.kids)
83 private void TransformNode(SYMBOL s)
91 ((Declaration) s).Datatype = m_datatypeLSL2OpenSim[((Declaration) s).Datatype];
93 ((Constant) s).Type = m_datatypeLSL2OpenSim[((Constant) s).Type];
95 ((TypecastExpression) s).TypecastType = m_datatypeLSL2OpenSim[((TypecastExpression) s).TypecastType];
99 for (
int i = 0; i < s.kids.Count; i++)
110 if (null != s.kids[i])
115 AddImplicitInitialization(s, i);
117 TransformNode((SYMBOL) s.kids[i]);
133 private void AddImplicitInitialization(SYMBOL s,
int didx)
136 int sKidSize = s.kids.Count;
137 object [] sKids =
new object[sKidSize];
138 for (
int i = 0; i < sKidSize; i++)
139 sKids[i] = s.kids.Pop();
142 Declaration currentDeclaration = (Declaration) sKids[didx];
145 Assignment newAssignment =
new Assignment(currentDeclaration.yyps,
147 GetZeroConstant(currentDeclaration.yyps, currentDeclaration.Datatype),
149 sKids[didx] = newAssignment;
152 for (
int i = 0; i < sKidSize; i++)
153 s.kids.Add(sKids[i]);
168 private SYMBOL GetZeroConstant(Parser p,
string constantType)
170 switch (constantType)
173 return new Constant(p, constantType,
"0");
175 return new Constant(p, constantType,
"0.0");
178 return new Constant(p, constantType,
"");
180 ArgumentList al =
new ArgumentList(p);
181 return new ListConstant(p, al);
183 Constant vca =
new Constant(p,
"float",
"0.0");
184 Constant vcb =
new Constant(p,
"float",
"0.0");
185 Constant vcc =
new Constant(p,
"float",
"0.0");
186 ConstantExpression vcea =
new ConstantExpression(p, vca);
187 ConstantExpression vceb =
new ConstantExpression(p, vcb);
188 ConstantExpression vcec =
new ConstantExpression(p, vcc);
189 return new VectorConstant(p, vcea, vceb, vcec);
191 Constant rca =
new Constant(p,
"float",
"0.0");
192 Constant rcb =
new Constant(p,
"float",
"0.0");
193 Constant rcc =
new Constant(p,
"float",
"0.0");
194 Constant rcd =
new Constant(p,
"float",
"0.0");
195 ConstantExpression rcea =
new ConstantExpression(p, rca);
196 ConstantExpression rceb =
new ConstantExpression(p, rcb);
197 ConstantExpression rcec =
new ConstantExpression(p, rcc);
198 ConstantExpression rced =
new ConstantExpression(p, rcd);
199 return new RotationConstant(p, rcea, rceb, rcec, rced);