2 // Copyright (C) 2016 Google, Inc.
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
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.
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.
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.
36 // Map from physical token form (e.g. '-') to logical operator
37 // form (e.g., binary subtract or unary negate).
39 #include "hlslOpMap.h"
43 // Map parsing tokens that could be assignments into assignment operators.
44 TOperator HlslOpMap::assignment(EHlslTokenClass op)
47 case EHTokAssign: return EOpAssign;
48 case EHTokMulAssign: return EOpMulAssign;
49 case EHTokDivAssign: return EOpDivAssign;
50 case EHTokAddAssign: return EOpAddAssign;
51 case EHTokModAssign: return EOpModAssign;
52 case EHTokLeftAssign: return EOpLeftShiftAssign;
53 case EHTokRightAssign: return EOpRightShiftAssign;
54 case EHTokAndAssign: return EOpAndAssign;
55 case EHTokXorAssign: return EOpExclusiveOrAssign;
56 case EHTokOrAssign: return EOpInclusiveOrAssign;
57 case EHTokSubAssign: return EOpSubAssign;
64 // Map parsing tokens that could be binary operations into binary operators.
65 TOperator HlslOpMap::binary(EHlslTokenClass op)
68 case EHTokPlus: return EOpAdd;
69 case EHTokDash: return EOpSub;
70 case EHTokStar: return EOpMul;
71 case EHTokSlash: return EOpDiv;
72 case EHTokPercent: return EOpMod;
73 case EHTokRightOp: return EOpRightShift;
74 case EHTokLeftOp: return EOpLeftShift;
75 case EHTokAmpersand: return EOpAnd;
76 case EHTokVerticalBar: return EOpInclusiveOr;
77 case EHTokCaret: return EOpExclusiveOr;
78 case EHTokEqOp: return EOpEqual;
79 case EHTokNeOp: return EOpNotEqual;
80 case EHTokLeftAngle: return EOpLessThan;
81 case EHTokRightAngle: return EOpGreaterThan;
82 case EHTokLeOp: return EOpLessThanEqual;
83 case EHTokGeOp: return EOpGreaterThanEqual;
84 case EHTokOrOp: return EOpLogicalOr;
85 case EHTokXorOp: return EOpLogicalXor;
86 case EHTokAndOp: return EOpLogicalAnd;
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)
98 case EHTokPlus: return EOpAdd; // means no-op, but still a unary op was present
99 case EHTokDash: return EOpNegative;
100 case EHTokBang: return EOpLogicalNot;
101 case EHTokTilde: return EOpBitwiseNot;
103 case EHTokIncOp: return EOpPreIncrement;
104 case EHTokDecOp: return EOpPreDecrement;
106 default: return EOpNull; // means not a pre-unary op
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)
115 case EHTokDot: return EOpIndexDirectStruct;
116 case EHTokLeftBracket: return EOpIndexIndirect;
118 case EHTokIncOp: return EOpPostIncrement;
119 case EHTokDecOp: return EOpPostDecrement;
121 case EHTokColonColon: return EOpScoping;
123 default: return EOpNull; // means not a post-unary op
127 // Map operators into their level of precedence.
128 PrecedenceLevel HlslOpMap::precedenceLevel(TOperator op)
151 case EOpLessThanEqual:
152 case EOpGreaterThanEqual:
173 } // end namespace glslang