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

Side by Side Diff: bin/main.cc

Issue 10548017: Fix for issue-2837 (allow --print-flags without a script name). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_debugger_api.h" 10 #include "include/dart_debugger_api.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 184
185 185
186 // Parse out the command line arguments. Returns -1 if the arguments 186 // Parse out the command line arguments. Returns -1 if the arguments
187 // are incorrect, 0 otherwise. 187 // are incorrect, 0 otherwise.
188 static int ParseArguments(int argc, 188 static int ParseArguments(int argc,
189 char** argv, 189 char** argv,
190 CommandLineOptions* vm_options, 190 CommandLineOptions* vm_options,
191 char** executable_name, 191 char** executable_name,
192 char** script_name, 192 char** script_name,
193 CommandLineOptions* dart_options) { 193 CommandLineOptions* dart_options,
194 bool* print_flags_seen) {
194 const char* kPrefix = "--"; 195 const char* kPrefix = "--";
195 const intptr_t kPrefixLen = strlen(kPrefix); 196 const intptr_t kPrefixLen = strlen(kPrefix);
196 197
197 // Get the executable name. 198 // Get the executable name.
198 *executable_name = argv[0]; 199 *executable_name = argv[0];
199 200
200 // Start the rest after the executable name. 201 // Start the rest after the executable name.
201 int i = 1; 202 int i = 1;
202 203
203 // Parse out the vm options. 204 // Parse out the vm options.
204 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { 205 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
205 if (ProcessMainOptions(argv[i])) { 206 if (ProcessMainOptions(argv[i])) {
206 i++; 207 i++;
207 } else { 208 } else {
209 const char* kPrintFlags1 = "--print-flags";
210 const char* kPrintFlags2 = "--print_flags";
211 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) ||
212 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) {
213 *print_flags_seen = true;
214 }
208 vm_options->AddArgument(argv[i]); 215 vm_options->AddArgument(argv[i]);
209 i++; 216 i++;
210 } 217 }
211 } 218 }
212 if (generate_pprof_symbols_filename != NULL) { 219 if (generate_pprof_symbols_filename != NULL) {
213 Dart_InitPprofSupport(); 220 Dart_InitPprofSupport();
214 } 221 }
215 222
216 if (flow_graph_file != NULL) { 223 if (flow_graph_file != NULL) {
217 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile); 224 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile);
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 684 }
678 685
679 686
680 int main(int argc, char** argv) { 687 int main(int argc, char** argv) {
681 char* executable_name; 688 char* executable_name;
682 char* script_name; 689 char* script_name;
683 CommandLineOptions vm_options(argc); 690 CommandLineOptions vm_options(argc);
684 CommandLineOptions dart_options(argc); 691 CommandLineOptions dart_options(argc);
685 CommandLineOptions import_map(argc); 692 CommandLineOptions import_map(argc);
686 import_map_options = &import_map; 693 import_map_options = &import_map;
694 bool print_flags_seen = false;
687 695
688 // Perform platform specific initialization. 696 // Perform platform specific initialization.
689 if (!Platform::Initialize()) { 697 if (!Platform::Initialize()) {
690 fprintf(stderr, "Initialization failed\n"); 698 fprintf(stderr, "Initialization failed\n");
691 } 699 }
692 700
693 // Parse command line arguments. 701 // Parse command line arguments.
694 if (ParseArguments(argc, 702 if (ParseArguments(argc,
695 argv, 703 argv,
696 &vm_options, 704 &vm_options,
697 &executable_name, 705 &executable_name,
698 &script_name, 706 &script_name,
699 &dart_options) < 0) { 707 &dart_options,
700 PrintUsage(); 708 &print_flags_seen) < 0) {
701 return kErrorExitCode; 709 if (print_flags_seen) {
710 // Will set the VM flags, print them out and then we exit as no
711 // script was specified on the command line.
712 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
713 return 0;
714 } else {
715 PrintUsage();
716 return kErrorExitCode;
717 }
702 } 718 }
703 719
704 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 720 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
705 721
706 // Initialize the Dart VM. 722 // Initialize the Dart VM.
707 Dart_Initialize(CreateIsolateAndSetup, NULL); 723 Dart_Initialize(CreateIsolateAndSetup, NULL);
708 724
709 original_working_directory = Directory::Current(); 725 original_working_directory = Directory::Current();
710 726
711 // Call CreateIsolateAndSetup which creates an isolate and loads up 727 // Call CreateIsolateAndSetup which creates an isolate and loads up
712 // the specified application script. 728 // the specified application script.
713 char* error = NULL; 729 char* error = NULL;
714 char* isolate_name = BuildIsolateName(script_name, "main"); 730 char* isolate_name = BuildIsolateName(script_name, "main");
715 if (!CreateIsolateAndSetupHelper(script_name, 731 if (!CreateIsolateAndSetupHelper(script_name,
716 "main", 732 "main",
717 true, // Canonicalize the script name. 733 true, // Canonicalize the script name.
718 NULL, 734 NULL,
719 &error)) { 735 &error)) {
720 fprintf(stderr, "%s\n", error); 736 fprintf(stderr, "%s\n", error);
721 free(const_cast<char*>(original_working_directory)); 737 free(const_cast<char*>(original_working_directory));
722 free(error); 738 free(error);
723 delete [] isolate_name; 739 delete [] isolate_name;
724 return 255; // Indicates we encountered an error. 740 return kErrorExitCode; // Indicates we encountered an error.
725 } 741 }
726 delete [] isolate_name; 742 delete [] isolate_name;
727 743
728 Dart_Isolate isolate = Dart_CurrentIsolate(); 744 Dart_Isolate isolate = Dart_CurrentIsolate();
729 ASSERT(isolate != NULL); 745 ASSERT(isolate != NULL);
730 Dart_Handle result; 746 Dart_Handle result;
731 747
732 Dart_EnterScope(); 748 Dart_EnterScope();
733 749
734 if (has_compile_all) { 750 if (has_compile_all) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 DumpPprofSymbolInfo(); 798 DumpPprofSymbolInfo();
783 // Shutdown the isolate. 799 // Shutdown the isolate.
784 Dart_ShutdownIsolate(); 800 Dart_ShutdownIsolate();
785 // Terminate process exit-code handler. 801 // Terminate process exit-code handler.
786 Process::TerminateExitCodeHandler(); 802 Process::TerminateExitCodeHandler();
787 803
788 free(const_cast<char*>(original_working_directory)); 804 free(const_cast<char*>(original_working_directory));
789 805
790 return 0; 806 return 0;
791 } 807 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698