Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: tools/testing/frogpad/frogpad.dart

Issue 10387232: Remove string concatenation with + from all Dart files in tools directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /** 6 /**
7 * This is the entrypoint for a version of the frog compiler that 7 * This is the entrypoint for a version of the frog compiler that
8 * can run in the browser. 8 * can run in the browser.
9 * Because this is running in the browser, frog cannot access 9 * Because this is running in the browser, frog cannot access
10 * the file system. Instead, we assume the all necessary files 10 * the file system. Instead, we assume the all necessary files
11 * have been placed in inert <script> elements somewhere on the page. 11 * have been placed in inert <script> elements somewhere on the page.
12 * (See frogpad.py for more details on how the html page is constructed.) 12 * (See frogpad.py for more details on how the html page is constructed.)
13 */ 13 */
14 14
15 #import("dart:html", prefix:"html"); 15 #import("dart:html", prefix:"html");
16 #import("../../../frog/lang.dart"); 16 #import("../../../frog/lang.dart");
17 #import("../../../frog/file_system.dart"); 17 #import("../../../frog/file_system.dart");
18 18
19 // id of script element containing name of the main dart file 19 // id of script element containing name of the main dart file
20 // to compile. 20 // to compile.
21 final String MAIN_ID = "main_id"; 21 final String MAIN_ID = "main_id";
22 22
23 // id of script element containing name of the frog directory 23 // id of script element containing name of the frog directory
24 final String FROGDIR_ID = "frogdir_id"; 24 final String FROGDIR_ID = "frogdir_id";
25 25
26 void main() { 26 void main() {
27 String warnings = ""; 27 StringBuffer warnings = new StringBuffer();
28 HtmlFileSystem fs = new HtmlFileSystem(); 28 HtmlFileSystem fs = new HtmlFileSystem();
29 String frogDir = getText(FROGDIR_ID); 29 String frogDir = getText(FROGDIR_ID);
30 String mainFile = getText(MAIN_ID); 30 String mainFile = getText(MAIN_ID);
31 setText("input", fs.readAll(mainFile)); 31 setText("input", fs.readAll(mainFile));
32 32
33 int time1 = new Date.now().value; 33 int time1 = new Date.now().value;
34 List<String> args = [ 34 List<String> args = [
35 "dummy_arg1", 35 "dummy_arg1",
36 "dummy_arg2", 36 "dummy_arg2",
37 "--enable_type_checks", 37 "--enable_type_checks",
38 "--enable_asserts", 38 "--enable_asserts",
39 mainFile]; 39 mainFile];
40 parseOptions(frogDir, args, fs); 40 parseOptions(frogDir, args, fs);
41 41
42 options.useColors = false; 42 options.useColors = false;
43 43
44 initializeWorld(fs); 44 initializeWorld(fs);
45 world.messageHandler = void _( 45 world.messageHandler = void _(
46 String prefix, String message, SourceSpan span) { 46 String prefix, String message, SourceSpan span) {
47 String location = ""; 47 String location = "";
48 if (span !== null) { 48 if (span !== null) {
49 location = span.locationText; 49 location = span.locationText;
50 } 50 }
51 warnings += prefix + message + location + "\n"; 51 warnings.add('$prefix$message$location\n');
52 }; 52 };
53 bool success = world.compile(); 53 bool success = world.compile();
54 int time2 = new Date.now().value; 54 int time2 = new Date.now().value;
55 String output = "throw 'frogpad compilation error';\n"; 55 String output = "throw 'frogpad compilation error';\n";
56 if (success) { 56 if (success) {
57 output = world.getGeneratedCode(); 57 output = world.getGeneratedCode();
58 } 58 }
59 setText("output", output); 59 setText("output", output);
60 setText("warnings", warnings); 60 setText("warnings", warnings.toString());
61 61
62 String timing = "generated ${output.length} characters in " + 62 String timing = "generated ${output.length} characters in "
63 "${((time2 - time1) / 1000).toStringAsPrecision(3)} seconds"; 63 "${((time2 - time1) / 1000).toStringAsPrecision(3)} seconds";
64 setText("timing", timing); 64 setText("timing", timing);
65 } 65 }
66 66
67 void setText(String id, String text) { 67 void setText(String id, String text) {
68 html.Element element = html.document.query("#$id"); 68 html.Element element = html.document.query("#$id");
69 if (element === null) { 69 if (element === null) {
70 throw new Exception("Can't find element $id"); 70 throw new Exception("Can't find element $id");
71 } 71 }
72 element.innerHTML = htmlEscape(text); 72 element.innerHTML = htmlEscape(text);
(...skipping 21 matching lines...) Expand all
94 String text = getText(idOfFilename(filename)); 94 String text = getText(idOfFilename(filename));
95 print("read $filename (${text.length} bytes)"); 95 print("read $filename (${text.length} bytes)");
96 return text; 96 return text;
97 } 97 }
98 98
99 /** 99 /**
100 * Returns the id of the <script> element that contains 100 * Returns the id of the <script> element that contains
101 * the contents of this file. 101 * the contents of this file.
102 * The id is constructed by taking the filename and replacing 102 * The id is constructed by taking the filename and replacing
103 * all slashes and dots with underscores. For example, the file name: 103 * all slashes and dots with underscores. For example, the file name:
104 * 104 *
105 * "/usr/local/src/dart/frog/lang.dart" 105 * "/usr/local/src/dart/frog/lang.dart"
106 * 106 *
107 * becomes: 107 * becomes:
108 * 108 *
109 * "_usr_local_src_dart_frog_lang_dart" 109 * "_usr_local_src_dart_frog_lang_dart"
110 * 110 *
111 * And, so this file's contents will be found in a <script> 111 * And, so this file's contents will be found in a <script>
112 * element that looks like this: 112 * element that looks like this:
113 * 113 *
114 * <script type=application/inert id="_usr_local_src_dart_frog_lang_dart"> 114 * <script type=application/inert id="_usr_local_src_dart_frog_lang_dart">
115 * ... contents of file lang.dart placed here ... 115 * ... contents of file lang.dart placed here ...
116 * etc. 116 * etc.
117 */ 117 */
118 String idOfFilename(String filename) { 118 String idOfFilename(String filename) {
119 return filename.replaceAll("/", "_").replaceAll(".", "_"); 119 return filename.replaceAll("/", "_").replaceAll(".", "_");
120 } 120 }
121 121
122 void writeString(String outfile, String text) { 122 void writeString(String outfile, String text) {
123 throw new UnsupportedOperationException(""); 123 throw new UnsupportedOperationException("");
124 } 124 }
125 125
126 bool fileExists(String filename) { 126 bool fileExists(String filename) {
127 // frog calls this to check if files exist before reading them. We return 127 // frog calls this to check if files exist before reading them. We return
128 // true here for all files, and let it fail later if frog attempts to read 128 // true here for all files, and let it fail later if frog attempts to read
129 // the contents of a non-existent file. 129 // the contents of a non-existent file.
130 return true; 130 return true;
131 } 131 }
132 132
133 void createDirectory(String path, [bool recursive]) { 133 void createDirectory(String path, [bool recursive]) {
134 throw new UnsupportedOperationException(""); 134 throw new UnsupportedOperationException("");
135 } 135 }
136 136
137 void removeDirectory(String path, [bool recursive]) { 137 void removeDirectory(String path, [bool recursive]) {
138 throw new UnsupportedOperationException(""); 138 throw new UnsupportedOperationException("");
139 } 139 }
140 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698