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 
     35 	both ""
     36 		precision mediump float;
     37 
     38 		${DECLARATIONS}
     39 
     40 		void main()
     41 		{
     42 			${SETUP}
     43 			float ${{IDENTIFIER}} = 1.0;
     44 			${OUTPUT}
     45 		}
     46 	""
     47 end
     48 """[1:-1]
     49 
     50 # Classes
     51 
     52 class IdentifierCase(ShaderCase):
     53 	def __init__(self, name, identifier):
     54 		self.name		= name
     55 		self.identifier = identifier
     56 
     57 	def __str__(self):
     58 		params = {	"NAME"			: self.name,
     59 					"IDENTIFIER"	: self.identifier }
     60 		return fillTemplate(identifierCaseTemplate, params)
     61 
     62 
     63 # Declarations
     64 
     65 KEYWORDS = [
     66 	"attribute", "const", "uniform", "varying",	"break", "continue", "do", "for", "while",
     67 	"if", "else", "in", "out", "inout", "float", "int", "void", "bool", "true", "false",
     68 	"lowp", "mediump", "highp", "precision", "invariant", "discard", "return", "mat2", "mat3",
     69 	"mat4",	"vec2", "vec3", "vec4", "ivec2", "ivec3", "ivec4", "bvec2", "bvec3", "bvec4",
     70 	"sampler2D", "samplerCube",	"struct"
     71 ]
     72 
     73 RESERVED_KEYWORDS = [
     74 	"asm", "class", "union", "enum", "typedef", "template", "this", "packed", "goto", "switch",
     75 	"default", "inline", "noinline", "volatile", "public", "static", "extern", "external",
     76 	"interface", "flat", "long", "short", "double", "half", "fixed", "unsigned", "superp",
     77 	"input", "output", "hvec2", "hvec3", "hvec4", "dvec2", "dvec3", "dvec4", "fvec2", "fvec3",
     78 	"fvec4", "sampler1D", "sampler3D", "sampler1DShadow", "sampler2DShadow", "sampler2DRect",
     79 	"sampler3DRect", "sampler2DRectShadow", "sizeof", "cast", "namespace", "using"
     80 ]
     81 
     82 INVALID_IDENTIFIERS = [
     83 	("two_underscores_begin",	"__invalid"),
     84 	("two_underscores_middle",	"in__valid"),
     85 	("two_underscores_end",		"invalid__"),
     86 	("gl_begin",				"gl_Invalid"),
     87 	("digit",					"0123"),
     88 	("digit_begin",				"0invalid")
     89 ]
     90 
     91 # Keyword usage
     92 
     93 keywords			= []
     94 reservedKeywords	= []
     95 invalidIdentifiers	= []
     96 
     97 for keyword in KEYWORDS:
     98 	keywords.append(IdentifierCase(keyword, keyword))			# Keywords
     99 
    100 for keyword in RESERVED_KEYWORDS:
    101 	reservedKeywords.append(IdentifierCase(keyword, keyword))	# Reserved keywords
    102 
    103 for (name, identifier) in INVALID_IDENTIFIERS:
    104 	invalidIdentifiers.append(IdentifierCase(name, identifier)) # Invalid identifiers
    105 
    106 keywordCases = [
    107 	CaseGroup("keywords",				"Usage of keywords as identifiers.",			keywords),
    108 	CaseGroup("reserved_keywords",		"Usage of reserved keywords as identifiers.",	reservedKeywords),
    109 	CaseGroup("invalid_identifiers",	"Usage of invalid identifiers.",				invalidIdentifiers)
    110 ]
    111 
    112 # Main program
    113 
    114 if __name__ == "__main__":
    115 	print "Generating shader case files."
    116 	writeAllCases("keywords.test", keywordCases)
    117