2 // Copyright (C) 2016 LunarG, 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 #include "hlslAttributes.h"
41 // Map the given string to an attribute enum from TAttributeType,
42 // or EatNone if invalid.
43 TAttributeType TAttributeMap::attributeFromName(const TString& name)
45 // These are case insensitive.
46 TString lowername(name);
47 std::transform(lowername.begin(), lowername.end(), lowername.begin(), ::tolower);
49 if (lowername == "allow_uav_condition")
50 return EatAllow_uav_condition;
51 else if (lowername == "branch")
53 else if (lowername == "call")
55 else if (lowername == "domain")
57 else if (lowername == "earlydepthstencil")
58 return EatEarlyDepthStencil;
59 else if (lowername == "fastopt")
61 else if (lowername == "flatten")
63 else if (lowername == "forcecase")
65 else if (lowername == "instance")
67 else if (lowername == "maxtessfactor")
68 return EatMaxTessFactor;
69 else if (lowername == "maxvertexcount")
70 return EatMaxVertexCount;
71 else if (lowername == "numthreads")
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")
83 else if (lowername == "loop")
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)
96 const TAttributeType attr = attributeFromName(*name);
99 attributes[attr] = value;
104 // Look up entry (const version), and return aggregate node. This cannot change the map.
105 const TIntermAggregate* TAttributeMap::operator[](TAttributeType attr) const
107 const auto entry = attributes.find(attr);
109 return (entry == attributes.end()) ? nullptr : entry->second;
112 // True if entry exists in map (even if value is nullptr)
113 bool TAttributeMap::contains(TAttributeType attr) const
115 return attributes.find(attr) != attributes.end();
118 } // end namespace glslang