Home | History | Annotate | Download | only in scripts
      1 # -*- coding: utf-8 -*-
      2 
      3 #-------------------------------------------------------------------------
      4 # drawElements Quality Program utilities
      5 # --------------------------------------
      6 #
      7 # Copyright 2015 The Android Open Source Project
      8 #
      9 # Licensed under the Apache License, Version 2.0 (the "License");
     10 # you may not use this file except in compliance with the License.
     11 # You may obtain a copy of the License at
     12 #
     13 #      http://www.apache.org/licenses/LICENSE-2.0
     14 #
     15 # Unless required by applicable law or agreed to in writing, software
     16 # distributed under the License is distributed on an "AS IS" BASIS,
     17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18 # See the License for the specific language governing permissions and
     19 # limitations under the License.
     20 #
     21 #-------------------------------------------------------------------------
     22 
     23 import sys
     24 from genutil import *
     25 
     26 # \todo [arttu 2012-12-20] Current set tests variable names only, add function names, structure names, and field selectors.
     27 
     28 # Templates
     29 
     30 identifierCaseTemplate = """
     31 case ${{NAME}}
     32 	expect compile_fail
     33 	values {}
     34 	version 300 es
     35 
     36 	both ""
     37 		#version 300 es
     38 		precision mediump float;
     39 		${DECLARATIONS}
     40 
     41 		void main()
     42 		{
     43 			${SETUP}
     44 			float ${{IDENTIFIER}} = 1.0;
     45 			${OUTPUT}
     46 		}
     47 	""
     48 end
     49 """[1:-1]
     50 
     51 # Classes
     52 
     53 class IdentifierCase(ShaderCase):
     54 	def __init__(self, name, identifier):
     55 		self.name		= name
     56 		self.identifier = identifier
     57 
     58 	def __str__(self):
     59 		params = {	"NAME"			: self.name,
     60 					"IDENTIFIER"	: self.identifier }
     61 		return fillTemplate(identifierCaseTemplate, params)
     62 
     63 # Declarations
     64 
     65 KEYWORDS = [
     66 	"const", "uniform",	"layout", "centroid", "flat", "smooth",	"break", "continue", "do",
     67 	"for", "while", "switch", "case", "default","if", "else", "in", "out", "inout",	"float",
     68 	"int", "void", "bool", "true", "false", "invariant", "discard", "return", "mat2", "mat3",
     69 	"mat4",	"mat2x2", "mat2x3", "mat2x4", "mat3x2", "mat3x3", "mat3x4", "mat4x2", "mat4x3", "mat4x4",
     70 	"vec2", "vec3", "vec4", "ivec2", "ivec3", "ivec4", "bvec2", "bvec3", "bvec4", "uint", "uvec2",
     71 	"uvec3", "uvec4", "lowp", "mediump", "highp", "precision", "sampler2D", "sampler3D", "samplerCube",
     72 	"sampler2DShadow", "samplerCubeShadow", "sampler2DArray", "sampler2DArrayShadow", "isampler2D",
     73 	"isampler3D", "isamplerCube", "isampler2DArray", "usampler2D", "usampler3D", "usamplerCube",
     74 	"usampler2DArray", "struct"
     75 ]
     76 
     77 RESERVED_KEYWORDS = [
     78 	"attribute", "varying", "coherent", "restrict", "readonly", "writeonly",
     79 	"resource", "atomic_uint", "noperspective",	"patch", "sample", "subroutine", "common",
     80 	"partition", "active", "asm", "class", "union", "enum", "typedef", "template", "this",
     81 	"goto", "inline", "noinline", "volatile", "public", "static", "extern", "external", "interface",
     82 	"long", "short", "double", "half", "fixed", "unsigned", "superp", "input", "output",
     83 	"hvec2", "hvec3", "hvec4", "dvec2", "dvec3", "dvec4", "fvec2", "fvec3", "fvec4", "sampler3DRect",
     84 	"filter", "image1D", "image2D", "image3D", "imageCube", "iimage1D", "iimage2D", "iimage3D",
     85 	"iimageCube", "uimage1D", "uimage2D", "uimage3D", "uimageCube", "image1DArray", "image2DArray",
     86 	"iimage1DArray", "iimage2DArray", "uimage1DArray", "uimage2DArray", "image1DShadow", "image2DShadow",
     87 	"image1DArrayShadow", "image2DArrayShadow", "imageBuffer", "iimageBuffer", "uimageBuffer",
     88 	"sampler1D", "sampler1DShadow", "sampler1DArray", "sampler1DArrayShadow", "isampler1D",
     89 	"isampler1DArray", "usampler1D", "usampler1DArray", "sampler2DRect", "sampler2DRectShadow",
     90 	"isampler2DRect", "usampler2DRect", "samplerBuffer", "isamplerBuffer", "usamplerBuffer",
     91 	"sampler2DMS", "isampler2DMS", "usampler2DMS", "sampler2DMSArray", "isampler2DMSArray",
     92 	"usampler2DMSArray", "sizeof", "cast", "namespace", "using"
     93 ]
     94 
     95 INVALID_IDENTIFIERS = [
     96 	("two_underscores_begin",	"__invalid"),
     97 	("two_underscores_middle",	"in__valid"),
     98 	("two_underscores_end",		"invalid__"),
     99 	("gl_begin",				"gl_Invalid"),
    100 	("digit",					"0123"),
    101 	("digit_begin",				"0invalid"),
    102 	("max_length",				"abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdX"),
    103 ]
    104 
    105 # Keyword usage
    106 
    107 keywords			= []
    108 reservedKeywords	= []
    109 invalidIdentifiers	= []
    110 
    111 for keyword in KEYWORDS:
    112 	keywords.append(IdentifierCase(keyword, keyword))			# Keywords
    113 
    114 for keyword in RESERVED_KEYWORDS:
    115 	reservedKeywords.append(IdentifierCase(keyword, keyword))	# Reserved keywords
    116 
    117 for (name, identifier) in INVALID_IDENTIFIERS:
    118 	invalidIdentifiers.append(IdentifierCase(name, identifier)) # Invalid identifiers
    119 
    120 keywordCases = [
    121 	CaseGroup("keywords",				"Usage of keywords as identifiers.",			keywords),
    122 	CaseGroup("reserved_keywords",		"Usage of reserved keywords as identifiers.",	reservedKeywords),
    123 	CaseGroup("invalid_identifiers",	"Usage of invalid identifiers.",				invalidIdentifiers)
    124 ]
    125 
    126 # Main program
    127 
    128 if __name__ == "__main__":
    129 	print "Generating shader case files."
    130 	writeAllCases("keywords.test", keywordCases)
    131