diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs index db40ace..16b12c3 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs | |||
@@ -93,8 +93,94 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
93 | else if (s is GlobalFunctionDefinition && "void" != ((GlobalFunctionDefinition) s).ReturnType) // we don't need to translate "void" | 93 | else if (s is GlobalFunctionDefinition && "void" != ((GlobalFunctionDefinition) s).ReturnType) // we don't need to translate "void" |
94 | ((GlobalFunctionDefinition) s).ReturnType = m_datatypeLSL2OpenSim[((GlobalFunctionDefinition) s).ReturnType]; | 94 | ((GlobalFunctionDefinition) s).ReturnType = m_datatypeLSL2OpenSim[((GlobalFunctionDefinition) s).ReturnType]; |
95 | 95 | ||
96 | foreach (SYMBOL kid in s.kids) | 96 | for (int i = 0; i < s.kids.Count; i++) |
97 | TransformNode(kid); | 97 | { |
98 | if (!(s is Assignment || s is ArgumentDeclarationList) && s.kids[i] is Declaration) | ||
99 | AddImplicitInitialization(s, i); | ||
100 | |||
101 | TransformNode((SYMBOL) s.kids[i]); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// Replaces an instance of the node at s.kids[didx] with an assignment | ||
107 | /// node. The assignment node has the Declaration node on the left hand | ||
108 | /// side and a default initializer on the right hand side. | ||
109 | /// </summary> | ||
110 | /// <param name="s"> | ||
111 | /// The node containing the Declaration node that needs replacing. | ||
112 | /// </param> | ||
113 | /// <param name="didx">Index of the Declaration node to replace.</param> | ||
114 | private void AddImplicitInitialization(SYMBOL s, int didx) | ||
115 | { | ||
116 | // We take the kids for a while to play with them. | ||
117 | int sKidSize = s.kids.Count; | ||
118 | object [] sKids = new object[sKidSize]; | ||
119 | for (int i = 0; i < sKidSize; i++) | ||
120 | sKids[i] = s.kids.Pop(); | ||
121 | |||
122 | // The child to be changed. | ||
123 | Declaration currentDeclaration = (Declaration) sKids[didx]; | ||
124 | |||
125 | // We need an assignment node. | ||
126 | Assignment newAssignment = new Assignment(currentDeclaration.yyps, | ||
127 | currentDeclaration, | ||
128 | GetZeroConstant(currentDeclaration.yyps, currentDeclaration.Datatype), | ||
129 | "="); | ||
130 | sKids[didx] = newAssignment; | ||
131 | |||
132 | // Put the kids back where they belong. | ||
133 | for (int i = 0; i < sKidSize; i++) | ||
134 | s.kids.Add(sKids[i]); | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Generates the node structure required to generate a default | ||
139 | /// initialization. | ||
140 | /// </summary> | ||
141 | /// <param name="p"> | ||
142 | /// Tools.Parser instance to use when instantiating nodes. | ||
143 | /// </param> | ||
144 | /// <param name="constantType">String describing the datatype.</param> | ||
145 | /// <returns> | ||
146 | /// A SYMBOL node conaining the appropriate structure for intializing a | ||
147 | /// constantType. | ||
148 | /// </returns> | ||
149 | private SYMBOL GetZeroConstant(Parser p, string constantType) | ||
150 | { | ||
151 | switch (constantType) | ||
152 | { | ||
153 | case "integer": | ||
154 | return new Constant(p, constantType, "0"); | ||
155 | case "float": | ||
156 | return new Constant(p, constantType, "0.0"); | ||
157 | case "string": | ||
158 | case "key": | ||
159 | return new Constant(p, constantType, ""); | ||
160 | case "list": | ||
161 | ArgumentList al = new ArgumentList(p); | ||
162 | return new ListConstant(p, al); | ||
163 | case "vector": | ||
164 | Constant vca = new Constant(p, "float", "0.0"); | ||
165 | Constant vcb = new Constant(p, "float", "0.0"); | ||
166 | Constant vcc = new Constant(p, "float", "0.0"); | ||
167 | ConstantExpression vcea = new ConstantExpression(p, vca); | ||
168 | ConstantExpression vceb = new ConstantExpression(p, vcb); | ||
169 | ConstantExpression vcec = new ConstantExpression(p, vcc); | ||
170 | return new VectorConstant(p, vcea, vceb, vcec); | ||
171 | case "rotation": | ||
172 | Constant rca = new Constant(p, "float", "0.0"); | ||
173 | Constant rcb = new Constant(p, "float", "0.0"); | ||
174 | Constant rcc = new Constant(p, "float", "0.0"); | ||
175 | Constant rcd = new Constant(p, "float", "0.0"); | ||
176 | ConstantExpression rcea = new ConstantExpression(p, rca); | ||
177 | ConstantExpression rceb = new ConstantExpression(p, rcb); | ||
178 | ConstantExpression rcec = new ConstantExpression(p, rcc); | ||
179 | ConstantExpression rced = new ConstantExpression(p, rcd); | ||
180 | return new RotationConstant(p, rcea, rceb, rcec, rced); | ||
181 | default: | ||
182 | return null; // this will probably break stuff | ||
183 | } | ||
98 | } | 184 | } |
99 | } | 185 | } |
100 | } | 186 | } |