| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class ConstantEmitter implements ConstantVisitor { | 5 class ConstantEmitter implements ConstantVisitor { |
| 6 final Compiler compiler; | 6 final Compiler compiler; |
| 7 final Namer namer; | 7 final Namer namer; |
| 8 | 8 |
| 9 CodeBuffer buffer; | 9 CodeBuffer buffer; |
| 10 bool shouldEmitCanonicalVersion; | 10 bool shouldEmitCanonicalVersion; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 * a form that is valid as JavaScript string literal content. | 87 * a form that is valid as JavaScript string literal content. |
| 88 * The string is assumed quoted by single quote characters. | 88 * The string is assumed quoted by single quote characters. |
| 89 */ | 89 */ |
| 90 void writeEscapedString(DartString string, | 90 void writeEscapedString(DartString string, |
| 91 CodeBuffer buffer, | 91 CodeBuffer buffer, |
| 92 Node diagnosticNode) { | 92 Node diagnosticNode) { |
| 93 Iterator<int> iterator = string.iterator(); | 93 Iterator<int> iterator = string.iterator(); |
| 94 while (iterator.hasNext()) { | 94 while (iterator.hasNext()) { |
| 95 int code = iterator.next(); | 95 int code = iterator.next(); |
| 96 if (code === $SQ) { | 96 if (code === $SQ) { |
| 97 buffer.add(@"\'"); | 97 buffer.add(r"\'"); |
| 98 } else if (code === $LF) { | 98 } else if (code === $LF) { |
| 99 buffer.add(@'\n'); | 99 buffer.add(r'\n'); |
| 100 } else if (code === $CR) { | 100 } else if (code === $CR) { |
| 101 buffer.add(@'\r'); | 101 buffer.add(r'\r'); |
| 102 } else if (code === $LS) { | 102 } else if (code === $LS) { |
| 103 // This Unicode line terminator and $PS are invalid in JS string | 103 // This Unicode line terminator and $PS are invalid in JS string |
| 104 // literals. | 104 // literals. |
| 105 buffer.add(@'\u2028'); | 105 buffer.add(r'\u2028'); |
| 106 } else if (code === $PS) { | 106 } else if (code === $PS) { |
| 107 buffer.add(@'\u2029'); | 107 buffer.add(r'\u2029'); |
| 108 } else if (code === $BACKSLASH) { | 108 } else if (code === $BACKSLASH) { |
| 109 buffer.add(@'\\'); | 109 buffer.add(r'\\'); |
| 110 } else { | 110 } else { |
| 111 if (code > 0xffff) { | 111 if (code > 0xffff) { |
| 112 compiler.reportError( | 112 compiler.reportError( |
| 113 diagnosticNode, | 113 diagnosticNode, |
| 114 'Unhandled non-BMP character: U+${code.toRadixString(16)}'); | 114 'Unhandled non-BMP character: U+${code.toRadixString(16)}'); |
| 115 } | 115 } |
| 116 // TODO(lrn): Consider whether all codes above 0x7f really need to | 116 // TODO(lrn): Consider whether all codes above 0x7f really need to |
| 117 // be escaped. We build a Dart string here, so it should be a literal | 117 // be escaped. We build a Dart string here, so it should be a literal |
| 118 // stage that converts it to, e.g., UTF-8 for a JS interpreter. | 118 // stage that converts it to, e.g., UTF-8 for a JS interpreter. |
| 119 if (code < 0x20) { | 119 if (code < 0x20) { |
| 120 buffer.add(@'\x'); | 120 buffer.add(r'\x'); |
| 121 if (code < 0x10) buffer.add('0'); | 121 if (code < 0x10) buffer.add('0'); |
| 122 buffer.add(code.toRadixString(16)); | 122 buffer.add(code.toRadixString(16)); |
| 123 } else if (code >= 0x80) { | 123 } else if (code >= 0x80) { |
| 124 if (code < 0x100) { | 124 if (code < 0x100) { |
| 125 buffer.add(@'\x'); | 125 buffer.add(r'\x'); |
| 126 } else { | 126 } else { |
| 127 buffer.add(@'\u'); | 127 buffer.add(r'\u'); |
| 128 if (code < 0x1000) { | 128 if (code < 0x1000) { |
| 129 buffer.add('0'); | 129 buffer.add('0'); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 buffer.add(code.toRadixString(16)); | 132 buffer.add(code.toRadixString(16)); |
| 133 } else { | 133 } else { |
| 134 buffer.addCharCode(code); | 134 buffer.addCharCode(code); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 } | 137 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 buffer.add(getJsConstructor(constant.type.element)); | 243 buffer.add(getJsConstructor(constant.type.element)); |
| 244 buffer.add("("); | 244 buffer.add("("); |
| 245 for (int i = 0; i < constant.fields.length; i++) { | 245 for (int i = 0; i < constant.fields.length; i++) { |
| 246 if (i != 0) buffer.add(", "); | 246 if (i != 0) buffer.add(", "); |
| 247 _visit(constant.fields[i]); | 247 _visit(constant.fields[i]); |
| 248 } | 248 } |
| 249 buffer.add(")"); | 249 buffer.add(")"); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| OLD | NEW |