1 | /* |
---|---|
2 | * Copyright 2016 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #include "src/sksl/SkSLUtil.h" |
9 | |
10 | #include "src/sksl/SkSLStringStream.h" |
11 | |
12 | #ifndef __STDC_FORMAT_MACROS |
13 | #define __STDC_FORMAT_MACROS |
14 | #endif |
15 | |
16 | namespace SkSL { |
17 | |
18 | #if defined(SKSL_STANDALONE) || !SK_SUPPORT_GPU |
19 | StandaloneShaderCaps standaloneCaps; |
20 | #endif |
21 | |
22 | void sksl_abort() { |
23 | #ifdef SKSL_STANDALONE |
24 | abort(); |
25 | #else |
26 | sk_abort_no_print(); |
27 | exit(1); |
28 | #endif |
29 | } |
30 | |
31 | void write_stringstream(const StringStream& s, OutputStream& out) { |
32 | out.write(s.str().c_str(), s.str().size()); |
33 | } |
34 | |
35 | bool is_assignment(Token::Kind op) { |
36 | switch (op) { |
37 | case Token::EQ: // fall through |
38 | case Token::PLUSEQ: // fall through |
39 | case Token::MINUSEQ: // fall through |
40 | case Token::STAREQ: // fall through |
41 | case Token::SLASHEQ: // fall through |
42 | case Token::PERCENTEQ: // fall through |
43 | case Token::SHLEQ: // fall through |
44 | case Token::SHREQ: // fall through |
45 | case Token::BITWISEOREQ: // fall through |
46 | case Token::BITWISEXOREQ: // fall through |
47 | case Token::BITWISEANDEQ: // fall through |
48 | case Token::LOGICALOREQ: // fall through |
49 | case Token::LOGICALXOREQ: // fall through |
50 | case Token::LOGICALANDEQ: |
51 | return true; |
52 | default: |
53 | return false; |
54 | } |
55 | } |
56 | |
57 | Token::Kind remove_assignment(Token::Kind op) { |
58 | switch (op) { |
59 | case Token::PLUSEQ: return Token::PLUS; |
60 | case Token::MINUSEQ: return Token::MINUS; |
61 | case Token::STAREQ: return Token::STAR; |
62 | case Token::SLASHEQ: return Token::SLASH; |
63 | case Token::PERCENTEQ: return Token::PERCENT; |
64 | case Token::SHLEQ: return Token::SHL; |
65 | case Token::SHREQ: return Token::SHR; |
66 | case Token::BITWISEOREQ: return Token::BITWISEOR; |
67 | case Token::BITWISEXOREQ: return Token::BITWISEXOR; |
68 | case Token::BITWISEANDEQ: return Token::BITWISEAND; |
69 | case Token::LOGICALOREQ: return Token::LOGICALOR; |
70 | case Token::LOGICALXOREQ: return Token::LOGICALXOR; |
71 | case Token::LOGICALANDEQ: return Token::LOGICALAND; |
72 | default: return op; |
73 | } |
74 | } |
75 | |
76 | } // namespace |
77 |