/src/glslang/glslang/HLSL/hlslOpMap.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Copyright (C) 2016 Google, Inc. |
3 | | // |
4 | | // All rights reserved. |
5 | | // |
6 | | // Redistribution and use in source and binary forms, with or without |
7 | | // modification, are permitted provided that the following conditions |
8 | | // are met: |
9 | | // |
10 | | // Redistributions of source code must retain the above copyright |
11 | | // notice, this list of conditions and the following disclaimer. |
12 | | // |
13 | | // Redistributions in binary form must reproduce the above |
14 | | // copyright notice, this list of conditions and the following |
15 | | // disclaimer in the documentation and/or other materials provided |
16 | | // with the distribution. |
17 | | // |
18 | | // Neither the name of Google, Inc., nor the names of its |
19 | | // contributors may be used to endorse or promote products derived |
20 | | // from this software without specific prior written permission. |
21 | | // |
22 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
23 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
24 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
25 | | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
26 | | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
27 | | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
28 | | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
29 | | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
30 | | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31 | | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32 | | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33 | | // POSSIBILITY OF SUCH DAMAGE. |
34 | | // |
35 | | |
36 | | // Map from physical token form (e.g. '-') to logical operator |
37 | | // form (e.g., binary subtract or unary negate). |
38 | | |
39 | | #include "hlslOpMap.h" |
40 | | |
41 | | namespace glslang { |
42 | | |
43 | | // Map parsing tokens that could be assignments into assignment operators. |
44 | | TOperator HlslOpMap::assignment(EHlslTokenClass op) |
45 | 189 | { |
46 | 189 | switch (op) { |
47 | 0 | case EHTokAssign: return EOpAssign; |
48 | 0 | case EHTokMulAssign: return EOpMulAssign; |
49 | 0 | case EHTokDivAssign: return EOpDivAssign; |
50 | 0 | case EHTokAddAssign: return EOpAddAssign; |
51 | 0 | case EHTokModAssign: return EOpModAssign; |
52 | 0 | case EHTokLeftAssign: return EOpLeftShiftAssign; |
53 | 0 | case EHTokRightAssign: return EOpRightShiftAssign; |
54 | 0 | case EHTokAndAssign: return EOpAndAssign; |
55 | 0 | case EHTokXorAssign: return EOpExclusiveOrAssign; |
56 | 0 | case EHTokOrAssign: return EOpInclusiveOrAssign; |
57 | 0 | case EHTokSubAssign: return EOpSubAssign; |
58 | | |
59 | 189 | default: |
60 | 189 | return EOpNull; |
61 | 189 | } |
62 | 189 | } |
63 | | |
64 | | // Map parsing tokens that could be binary operations into binary operators. |
65 | | TOperator HlslOpMap::binary(EHlslTokenClass op) |
66 | 2.18k | { |
67 | 2.18k | switch (op) { |
68 | 8 | case EHTokPlus: return EOpAdd; |
69 | 6 | case EHTokDash: return EOpSub; |
70 | 1 | case EHTokStar: return EOpMul; |
71 | 21 | case EHTokSlash: return EOpDiv; |
72 | 0 | case EHTokPercent: return EOpMod; |
73 | 0 | case EHTokRightOp: return EOpRightShift; |
74 | 0 | case EHTokLeftOp: return EOpLeftShift; |
75 | 0 | case EHTokAmpersand: return EOpAnd; |
76 | 0 | case EHTokVerticalBar: return EOpInclusiveOr; |
77 | 0 | case EHTokCaret: return EOpExclusiveOr; |
78 | 0 | case EHTokEqOp: return EOpEqual; |
79 | 0 | case EHTokNeOp: return EOpNotEqual; |
80 | 64 | case EHTokLeftAngle: return EOpLessThan; |
81 | 0 | case EHTokRightAngle: return EOpGreaterThan; |
82 | 0 | case EHTokLeOp: return EOpLessThanEqual; |
83 | 0 | case EHTokGeOp: return EOpGreaterThanEqual; |
84 | 0 | case EHTokOrOp: return EOpLogicalOr; |
85 | 0 | case EHTokXorOp: return EOpLogicalXor; |
86 | 0 | case EHTokAndOp: return EOpLogicalAnd; |
87 | | |
88 | 2.08k | default: |
89 | 2.08k | return EOpNull; |
90 | 2.18k | } |
91 | 2.18k | } |
92 | | |
93 | | // Map parsing tokens that could be unary operations into unary operators. |
94 | | // These are just the ones that can appear in front of its operand. |
95 | | TOperator HlslOpMap::preUnary(EHlslTokenClass op) |
96 | 1.00k | { |
97 | 1.00k | switch (op) { |
98 | 6 | case EHTokPlus: return EOpAdd; // means no-op, but still a unary op was present |
99 | 0 | case EHTokDash: return EOpNegative; |
100 | 15 | case EHTokBang: return EOpLogicalNot; |
101 | 1 | case EHTokTilde: return EOpBitwiseNot; |
102 | | |
103 | 15 | case EHTokIncOp: return EOpPreIncrement; |
104 | 0 | case EHTokDecOp: return EOpPreDecrement; |
105 | | |
106 | 963 | default: return EOpNull; // means not a pre-unary op |
107 | 1.00k | } |
108 | 1.00k | } |
109 | | |
110 | | // Map parsing tokens that could be unary operations into unary operators. |
111 | | // These are just the ones that can appear behind its operand. |
112 | | TOperator HlslOpMap::postUnary(EHlslTokenClass op) |
113 | 352 | { |
114 | 352 | switch (op) { |
115 | 13 | case EHTokDot: return EOpIndexDirectStruct; |
116 | 104 | case EHTokLeftBracket: return EOpIndexIndirect; |
117 | | |
118 | 0 | case EHTokIncOp: return EOpPostIncrement; |
119 | 0 | case EHTokDecOp: return EOpPostDecrement; |
120 | | |
121 | 0 | case EHTokColonColon: return EOpScoping; |
122 | | |
123 | 235 | default: return EOpNull; // means not a post-unary op |
124 | 352 | } |
125 | 352 | } |
126 | | |
127 | | // Map operators into their level of precedence. |
128 | | PrecedenceLevel HlslOpMap::precedenceLevel(TOperator op) |
129 | 2.18k | { |
130 | 2.18k | switch (op) { |
131 | 0 | case EOpLogicalOr: |
132 | 0 | return PlLogicalOr; |
133 | 0 | case EOpLogicalXor: |
134 | 0 | return PlLogicalXor; |
135 | 0 | case EOpLogicalAnd: |
136 | 0 | return PlLogicalAnd; |
137 | | |
138 | 0 | case EOpInclusiveOr: |
139 | 0 | return PlBitwiseOr; |
140 | 0 | case EOpExclusiveOr: |
141 | 0 | return PlBitwiseXor; |
142 | 0 | case EOpAnd: |
143 | 0 | return PlBitwiseAnd; |
144 | | |
145 | 0 | case EOpEqual: |
146 | 0 | case EOpNotEqual: |
147 | 0 | return PlEquality; |
148 | | |
149 | 64 | case EOpLessThan: |
150 | 64 | case EOpGreaterThan: |
151 | 64 | case EOpLessThanEqual: |
152 | 64 | case EOpGreaterThanEqual: |
153 | 64 | return PlRelational; |
154 | | |
155 | 0 | case EOpRightShift: |
156 | 0 | case EOpLeftShift: |
157 | 0 | return PlShift; |
158 | | |
159 | 8 | case EOpAdd: |
160 | 14 | case EOpSub: |
161 | 14 | return PlAdd; |
162 | | |
163 | 1 | case EOpMul: |
164 | 22 | case EOpDiv: |
165 | 22 | case EOpMod: |
166 | 22 | return PlMul; |
167 | | |
168 | 2.08k | default: |
169 | 2.08k | return PlBad; |
170 | 2.18k | } |
171 | 2.18k | } |
172 | | |
173 | | } // end namespace glslang |