1import sys 2from genutil import * 3 4# Templates 5 6reservedOperatorCaseTemplate = """ 7case operator_${{NAME}} 8 expect compile_fail 9 values {} 10 11 both "" 12 precision mediump float; 13 precision mediump int; 14 15 ${DECLARATIONS} 16 17 void main() 18 { 19 ${SETUP} 20 int value = 100; 21 ${{OP}} 22 ${OUTPUT} 23 } 24 "" 25end 26"""[1:-1] 27 28# Classes 29 30class ReservedOperatorCase(ShaderCase): 31 def __init__(self, op): 32 self.name = op.name 33 if op.operator == "~": 34 self.operation = 'value = ~value;' 35 else: 36 self.operation = 'value ' + op.operator + ' 1;' 37 38 def __str__(self): 39 params = { 40 "NAME": self.name, 41 "OP" : self.operation 42 } 43 return fillTemplate(reservedOperatorCaseTemplate, params) 44 45 46class Operator(): 47 def __init__(self, operator, name): 48 self.operator = operator 49 self.name = name 50 51# Declarations 52 53RESERVED_OPERATORS = [ 54 Operator("%", "modulo"), 55 Operator("~", "bitwise_not"), 56 Operator("<<", "bitwise_shift_left"), 57 Operator(">>", "bitwise_shift_right"), 58 Operator("&", "bitwise_and"), 59 Operator("^", "bitwise_xor"), 60 Operator("|", "bitwise_or"), 61 Operator("%=", "assign_modulo"), 62 Operator("<<=", "assign_shift_left"), 63 Operator(">>=", "assign_shift_right"), 64 Operator("&=", "assign_and"), 65 Operator("^=", "assign_xor"), 66 Operator("|=", "assign_or") 67] 68 69# Reserved operator usage cases 70 71reservedOperatorCases = [] 72 73for operator in RESERVED_OPERATORS: 74 reservedOperatorCases.append(ReservedOperatorCase(operator)) # Reserved operators 75 76# Main program 77 78if __name__ == "__main__": 79 print "Generating shader case files." 80 writeAllCases("reserved_operators.test", reservedOperatorCases)