diff options
author | Johan Berntsson | 2008-07-04 08:59:41 +0000 |
---|---|---|
committer | Johan Berntsson | 2008-07-04 08:59:41 +0000 |
commit | 382fb8cea6c7a71ecbdab2a4ef8526bf3045fb2e (patch) | |
tree | d6c441851a7471aa897bef8c8fe462e3beb03576 /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs | |
parent | Mantis#1647. Thank you very much, Sempuki for a patch that: (diff) | |
download | opensim-SC_OLD-382fb8cea6c7a71ecbdab2a4ef8526bf3045fb2e.zip opensim-SC_OLD-382fb8cea6c7a71ecbdab2a4ef8526bf3045fb2e.tar.gz opensim-SC_OLD-382fb8cea6c7a71ecbdab2a4ef8526bf3045fb2e.tar.bz2 opensim-SC_OLD-382fb8cea6c7a71ecbdab2a4ef8526bf3045fb2e.tar.xz |
The new llScript-cs parser. Thanks Mike
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs new file mode 100644 index 0000000..db40ace --- /dev/null +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSCodeTransformer.cs | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Tools; | ||
31 | |||
32 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | ||
33 | { | ||
34 | public class LSL2CSCodeTransformer | ||
35 | { | ||
36 | private SYMBOL m_astRoot = null; | ||
37 | private static Dictionary<string, string> m_datatypeLSL2OpenSim = new Dictionary<string, string>(); | ||
38 | |||
39 | /// <summary> | ||
40 | /// Pass the new CodeTranformer an abstract syntax tree. | ||
41 | /// </summary> | ||
42 | /// <param name="astRoot">The root node of the AST.</param> | ||
43 | public LSL2CSCodeTransformer(SYMBOL astRoot) | ||
44 | { | ||
45 | m_astRoot = astRoot; | ||
46 | |||
47 | // let's populate the dictionary | ||
48 | try | ||
49 | { | ||
50 | m_datatypeLSL2OpenSim.Add("integer", "LSL_Types.LSLInteger"); | ||
51 | m_datatypeLSL2OpenSim.Add("float", "LSL_Types.LSLFloat"); | ||
52 | //m_datatypeLSL2OpenSim.Add("key", "LSL_Types.key"); // key doesn't seem to be used | ||
53 | m_datatypeLSL2OpenSim.Add("key", "LSL_Types.LSLString"); | ||
54 | m_datatypeLSL2OpenSim.Add("string", "LSL_Types.LSLString"); | ||
55 | m_datatypeLSL2OpenSim.Add("vector", "LSL_Types.Vector3"); | ||
56 | m_datatypeLSL2OpenSim.Add("rotation", "LSL_Types.Quaternion"); | ||
57 | m_datatypeLSL2OpenSim.Add("list", "LSL_Types.list"); | ||
58 | } | ||
59 | catch | ||
60 | { | ||
61 | // temporary workaround since we are adding to a static datatype | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Transform the code in the AST we have. | ||
67 | /// </summary> | ||
68 | /// <returns>The root node of the transformed AST</returns> | ||
69 | public SYMBOL Transform() | ||
70 | { | ||
71 | foreach (SYMBOL s in m_astRoot.kids) | ||
72 | TransformNode(s); | ||
73 | |||
74 | return m_astRoot; | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// Recursively called to transform each type of node. Will transform this | ||
79 | /// node, then all it's children. | ||
80 | /// </summary> | ||
81 | /// <param name="s">The current node to transform.</param> | ||
82 | private void TransformNode(SYMBOL s) | ||
83 | { | ||
84 | // make sure to put type lower in the inheritance hierarchy first | ||
85 | // ie: since IdentConstant and StringConstant inherit from Constant, | ||
86 | // put IdentConstant and StringConstant before Constant | ||
87 | if (s is Declaration) | ||
88 | ((Declaration) s).Datatype = m_datatypeLSL2OpenSim[((Declaration) s).Datatype]; | ||
89 | else if (s is Constant) | ||
90 | ((Constant) s).Type = m_datatypeLSL2OpenSim[((Constant) s).Type]; | ||
91 | else if (s is TypecastExpression) | ||
92 | ((TypecastExpression) s).TypecastType = m_datatypeLSL2OpenSim[((TypecastExpression) s).TypecastType]; | ||
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]; | ||
95 | |||
96 | foreach (SYMBOL kid in s.kids) | ||
97 | TransformNode(kid); | ||
98 | } | ||
99 | } | ||
100 | } | ||