Setup dependent external sources
[platform/upstream/VK-GL-CTS.git] / external / glslang / src / hlsl / hlslAttributes.cpp
1 //
2 // Copyright (C) 2016 LunarG, 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 #include "hlslAttributes.h"
37 #include <cstdlib>
38 #include <cctype>
39
40 namespace glslang {
41     // Map the given string to an attribute enum from TAttributeType,
42     // or EatNone if invalid.
43     TAttributeType TAttributeMap::attributeFromName(const TString& name)
44     {
45         // These are case insensitive.
46         TString lowername(name);
47         std::transform(lowername.begin(), lowername.end(), lowername.begin(), ::tolower);
48
49         if (lowername == "allow_uav_condition")
50             return EatAllow_uav_condition;
51         else if (lowername == "branch")
52             return EatBranch;
53         else if (lowername == "call")
54             return EatCall;
55         else if (lowername == "domain")
56             return EatDomain;
57         else if (lowername == "earlydepthstencil")
58             return EatEarlyDepthStencil;
59         else if (lowername == "fastopt")
60             return EatFastOpt;
61         else if (lowername == "flatten")
62             return EatFlatten;
63         else if (lowername == "forcecase")
64             return EatForceCase;
65         else if (lowername == "instance")
66             return EatInstance;
67         else if (lowername == "maxtessfactor")
68             return EatMaxTessFactor;
69         else if (lowername == "maxvertexcount")
70             return EatMaxVertexCount;
71         else if (lowername == "numthreads")
72             return EatNumThreads;
73         else if (lowername == "outputcontrolpoints")
74             return EatOutputControlPoints;
75         else if (lowername == "outputtopology")
76             return EatOutputTopology;
77         else if (lowername == "partitioning")
78             return EatPartitioning;
79         else if (lowername == "patchconstantfunc")
80             return EatPatchConstantFunc;
81         else if (lowername == "unroll")
82             return EatUnroll;
83         else if (lowername == "loop")
84             return EatLoop;
85         else
86             return EatNone;
87     }
88
89     // Look up entry, inserting if it's not there, and if name is a valid attribute name
90     // as known by attributeFromName.
91     TAttributeType TAttributeMap::setAttribute(const TString* name, TIntermAggregate* value)
92     {
93         if (name == nullptr)
94             return EatNone;
95
96         const TAttributeType attr = attributeFromName(*name);
97
98         if (attr != EatNone)
99             attributes[attr] = value;
100
101         return attr;
102     }
103
104     // Look up entry (const version), and return aggregate node.  This cannot change the map.
105     const TIntermAggregate* TAttributeMap::operator[](TAttributeType attr) const
106     {
107         const auto entry = attributes.find(attr);
108
109         return (entry == attributes.end()) ? nullptr : entry->second;
110     }
111
112     // True if entry exists in map (even if value is nullptr)
113     bool TAttributeMap::contains(TAttributeType attr) const
114     {
115         return attributes.find(attr) != attributes.end();
116     }
117
118 } // end namespace glslang