gfx/angle/src/compiler/DirectiveHandler.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #include "compiler/DirectiveHandler.h"
michael@0 8
michael@0 9 #include <sstream>
michael@0 10
michael@0 11 #include "compiler/compiler_debug.h"
michael@0 12 #include "compiler/Diagnostics.h"
michael@0 13
michael@0 14 static TBehavior getBehavior(const std::string& str)
michael@0 15 {
michael@0 16 static const std::string kRequire("require");
michael@0 17 static const std::string kEnable("enable");
michael@0 18 static const std::string kDisable("disable");
michael@0 19 static const std::string kWarn("warn");
michael@0 20
michael@0 21 if (str == kRequire) return EBhRequire;
michael@0 22 else if (str == kEnable) return EBhEnable;
michael@0 23 else if (str == kDisable) return EBhDisable;
michael@0 24 else if (str == kWarn) return EBhWarn;
michael@0 25 return EBhUndefined;
michael@0 26 }
michael@0 27
michael@0 28 TDirectiveHandler::TDirectiveHandler(TExtensionBehavior& extBehavior,
michael@0 29 TDiagnostics& diagnostics)
michael@0 30 : mExtensionBehavior(extBehavior),
michael@0 31 mDiagnostics(diagnostics)
michael@0 32 {
michael@0 33 }
michael@0 34
michael@0 35 TDirectiveHandler::~TDirectiveHandler()
michael@0 36 {
michael@0 37 }
michael@0 38
michael@0 39 void TDirectiveHandler::handleError(const pp::SourceLocation& loc,
michael@0 40 const std::string& msg)
michael@0 41 {
michael@0 42 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc, msg, "", "");
michael@0 43 }
michael@0 44
michael@0 45 void TDirectiveHandler::handlePragma(const pp::SourceLocation& loc,
michael@0 46 const std::string& name,
michael@0 47 const std::string& value)
michael@0 48 {
michael@0 49 static const std::string kSTDGL("STDGL");
michael@0 50 static const std::string kOptimize("optimize");
michael@0 51 static const std::string kDebug("debug");
michael@0 52 static const std::string kOn("on");
michael@0 53 static const std::string kOff("off");
michael@0 54
michael@0 55 bool invalidValue = false;
michael@0 56 if (name == kSTDGL)
michael@0 57 {
michael@0 58 // The STDGL pragma is used to reserve pragmas for use by future
michael@0 59 // revisions of GLSL. Ignore it.
michael@0 60 return;
michael@0 61 }
michael@0 62 else if (name == kOptimize)
michael@0 63 {
michael@0 64 if (value == kOn) mPragma.optimize = true;
michael@0 65 else if (value == kOff) mPragma.optimize = false;
michael@0 66 else invalidValue = true;
michael@0 67 }
michael@0 68 else if (name == kDebug)
michael@0 69 {
michael@0 70 if (value == kOn) mPragma.debug = true;
michael@0 71 else if (value == kOff) mPragma.debug = false;
michael@0 72 else invalidValue = true;
michael@0 73 }
michael@0 74 else
michael@0 75 {
michael@0 76 mDiagnostics.report(pp::Diagnostics::UNRECOGNIZED_PRAGMA, loc, name);
michael@0 77 return;
michael@0 78 }
michael@0 79
michael@0 80 if (invalidValue)
michael@0 81 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc,
michael@0 82 "invalid pragma value", value,
michael@0 83 "'on' or 'off' expected");
michael@0 84 }
michael@0 85
michael@0 86 void TDirectiveHandler::handleExtension(const pp::SourceLocation& loc,
michael@0 87 const std::string& name,
michael@0 88 const std::string& behavior)
michael@0 89 {
michael@0 90 static const std::string kExtAll("all");
michael@0 91
michael@0 92 TBehavior behaviorVal = getBehavior(behavior);
michael@0 93 if (behaviorVal == EBhUndefined)
michael@0 94 {
michael@0 95 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc,
michael@0 96 "behavior", name, "invalid");
michael@0 97 return;
michael@0 98 }
michael@0 99
michael@0 100 if (name == kExtAll)
michael@0 101 {
michael@0 102 if (behaviorVal == EBhRequire)
michael@0 103 {
michael@0 104 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc,
michael@0 105 "extension", name,
michael@0 106 "cannot have 'require' behavior");
michael@0 107 }
michael@0 108 else if (behaviorVal == EBhEnable)
michael@0 109 {
michael@0 110 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc,
michael@0 111 "extension", name,
michael@0 112 "cannot have 'enable' behavior");
michael@0 113 }
michael@0 114 else
michael@0 115 {
michael@0 116 for (TExtensionBehavior::iterator iter = mExtensionBehavior.begin();
michael@0 117 iter != mExtensionBehavior.end(); ++iter)
michael@0 118 iter->second = behaviorVal;
michael@0 119 }
michael@0 120 return;
michael@0 121 }
michael@0 122
michael@0 123 TExtensionBehavior::iterator iter = mExtensionBehavior.find(name);
michael@0 124 if (iter != mExtensionBehavior.end())
michael@0 125 {
michael@0 126 iter->second = behaviorVal;
michael@0 127 return;
michael@0 128 }
michael@0 129
michael@0 130 pp::Diagnostics::Severity severity = pp::Diagnostics::ERROR;
michael@0 131 switch (behaviorVal) {
michael@0 132 case EBhRequire:
michael@0 133 severity = pp::Diagnostics::ERROR;
michael@0 134 break;
michael@0 135 case EBhEnable:
michael@0 136 case EBhWarn:
michael@0 137 case EBhDisable:
michael@0 138 severity = pp::Diagnostics::WARNING;
michael@0 139 break;
michael@0 140 default:
michael@0 141 UNREACHABLE();
michael@0 142 break;
michael@0 143 }
michael@0 144 mDiagnostics.writeInfo(severity, loc,
michael@0 145 "extension", name, "is not supported");
michael@0 146 }
michael@0 147
michael@0 148 void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc,
michael@0 149 int version)
michael@0 150 {
michael@0 151 static const int kVersion = 100;
michael@0 152
michael@0 153 if (version != kVersion)
michael@0 154 {
michael@0 155 std::stringstream stream;
michael@0 156 stream << version;
michael@0 157 std::string str = stream.str();
michael@0 158 mDiagnostics.writeInfo(pp::Diagnostics::ERROR, loc,
michael@0 159 "version number", str, "not supported");
michael@0 160 }
michael@0 161 }

mercurial