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

Unified Diff: runtime/bin/main.cc

Issue 12517005: Add a command line option to generate source code for a script (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/include/dart_debugger_api.h » ('j') | runtime/include/dart_debugger_api.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/main.cc
===================================================================
--- runtime/bin/main.cc (revision 19934)
+++ runtime/bin/main.cc (working copy)
@@ -63,6 +63,11 @@
static bool has_compile_all = false;
+// Global flag that is used to indicate that we want to print the source code
+// for script that is being run.
+static bool has_print_script = false;
+
+
static bool IsValidFlag(const char* name,
const char* prefix,
intptr_t prefix_length) {
@@ -186,6 +191,16 @@
}
+static bool ProcessPrintScriptOption(const char* arg) {
+ ASSERT(arg != NULL);
+ if (*arg != '\0') {
+ return false;
+ }
+ has_print_script = true;
+ return true;
+}
+
+
static bool ProcessVmStatsRootOption(const char* arg) {
ASSERT(arg != NULL);
vmstats_root = arg;
@@ -238,6 +253,7 @@
{ "--generate-script-snapshot=", ProcessGenScriptSnapshotOption },
{ "--stats-root=", ProcessVmStatsRootOption },
{ "--stats", ProcessVmStatsOption },
+ { "--print-script", ProcessPrintScriptOption },
bakster 2013/03/14 08:42:16 Why are some flags using - and others using _? How
siva 2013/03/14 09:38:46 We are moving to a "-" pattern. Will change the ot
{ NULL, NULL }
};
@@ -583,6 +599,9 @@
"--generate-script-snapshot=<file_name>\n"
" loads Dart script and generates a snapshot in the specified file\n"
"\n"
+"--print-source\n"
+" Generates Dart source code back and prints it after parsing a Dart script\n"
bakster 2013/03/14 08:42:16 Consistency: use lowercase "generates"?
siva 2013/03/14 09:38:46 Done.
+"\n"
"--stats[:<port number>]\n"
" enables VM stats service and listens on specified port for HTTP requests\n"
" (default port number is dynamically assigned)\n"
@@ -805,6 +824,37 @@
Dart_GetError(result));
}
}
+ if (has_print_script) {
bakster 2013/03/14 08:42:16 I would move this chunk of code out in a function.
siva 2013/03/14 09:38:46 Done.
+ Dart_Handle library_url = Dart_LibraryUrl(Dart_RootLibrary());
+ if (Dart_IsError(library_url)) {
+ return ErrorExit("%s\n", Dart_GetError(library_url));
+ }
+ Dart_Handle script_urls = Dart_GetScriptURLs(library_url);
+ if (Dart_IsError(script_urls)) {
+ return ErrorExit("%s\n", Dart_GetError(script_urls));
+ }
+ intptr_t length;
+ result = Dart_ListLength(script_urls, &length);
+ if (Dart_IsError(result)) {
+ return ErrorExit("%s\n", Dart_GetError(result));
+ }
+ for (intptr_t i = 0; i < length; i++) {
+ Dart_Handle script_url = Dart_ListGetAt(script_urls, i);
+ if (Dart_IsError(script_url)) {
+ return ErrorExit("%s\n", Dart_GetError(script_url));
+ }
+ result = Dart_GenerateScriptSource(library_url, script_url);
+ if (Dart_IsError(result)) {
+ return ErrorExit("%s\n", Dart_GetError(result));
+ }
+ const char* script_source = NULL;
+ result = Dart_StringToCString(result, &script_source);
+ if (Dart_IsError(result)) {
+ return ErrorExit("%s\n", Dart_GetError(result));
+ }
+ Log::Print("%s\n", script_source);
+ }
+ }
// Lookup and invoke the top level main function.
result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
« no previous file with comments | « no previous file | runtime/include/dart_debugger_api.h » ('j') | runtime/include/dart_debugger_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698