From 7177dce4e970c5f9e2c17aa61ba4ee42484481c3 Mon Sep 17 00:00:00 2001 From: "turnidge@google.com" Date: Wed, 15 Feb 2012 19:14:03 +0000 Subject: [PATCH] Make gen files more human-readable by using a string initializer instead of an integer array initializer. For example, the initializer in builtin_gen.cc now looks something like this: const char Builtin::builtin_source_[] = // ----- bin/builtin.dart ----- "// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file\n" "// for details. All rights reserved. Use of this source code is governed by a\n" "// BSD-style license that can be found in the LICENSE file.\n" "\n" "#library(\"builtin\");\n" "#import(\"dart:nativewrappers\");\n" "#import(\"dart:coreimpl\");\n" "\n" "void print(arg) {\n" " _Logger._printString(arg.toString());\n" /* L10 */ "}\n" "\n" "void exit(int status) {\n" " if (status is !int) {\n" " throw new IllegalArgumentException(\"int status expected\");\n" " }\n" " _exit(status);\n" "}\n" "\n" "_exit(int status) native \"Exit\";\n" /* L20 */ "\n" "class _Logger {\n" " static void _printString(String s) native \"Logger_PrintString\";\n" "}\n" ; Review URL: https://chromiumcodereview.appspot.com//9348112 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4280 260f80e4-7a28-3924-810f-c04153c831b5 --- runtime/bin/builtin_in.cc | 6 ++--- runtime/bin/io_in.cc | 6 ++--- runtime/tools/create_string_literal.py | 31 +++++++++++++++++--------- runtime/vm/corelib_impl_in.cc | 6 ++--- runtime/vm/corelib_in.cc | 6 ++--- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/runtime/bin/builtin_in.cc b/runtime/bin/builtin_in.cc index b3a87fd4841..91bfcda14ad 100644 --- a/runtime/bin/builtin_in.cc +++ b/runtime/bin/builtin_in.cc @@ -11,6 +11,6 @@ // builtin.dart file. // This string forms the content of builtin functionality which is injected // into standalone dart to provide some test/debug functionality. -const char Builtin::builtin_source_[] = { - {{DART_SOURCE}} -}; +const char Builtin::builtin_source_[] = +{{DART_SOURCE}} + ; /* NOLINT */ diff --git a/runtime/bin/io_in.cc b/runtime/bin/io_in.cc index 52fabda3a0a..6cf58ad837d 100644 --- a/runtime/bin/io_in.cc +++ b/runtime/bin/io_in.cc @@ -9,6 +9,6 @@ // The string on the next line will be filled in with the contents of // the dart files of the dart:io library. -const char Builtin::io_source_[] = { - {{DART_SOURCE}} -}; +const char Builtin::io_source_[] = +{{DART_SOURCE}} + ; /* NOLINT */ diff --git a/runtime/tools/create_string_literal.py b/runtime/tools/create_string_literal.py index d016301e02f..4cf601f6759 100644 --- a/runtime/tools/create_string_literal.py +++ b/runtime/tools/create_string_literal.py @@ -13,21 +13,32 @@ from optparse import OptionParser def makeString(input_files): + printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\ +!#$%&'()*+,-./:;<=>?@[]^_`{|}~ " result = ' ' + lineNumber = 1 for string_file in input_files: if string_file.endswith('dart'): fileHandle = open(string_file, 'rb') - lineCounter = 0 - result += ' // ' + string_file + '\n ' + quoted = False + result += '\n // ----- ' + string_file + ' -----\n\n' for byte in fileHandle.read(): - result += ' %d,' % ord(byte) - lineCounter += 1 - if lineCounter == 10: - result += '\n ' - lineCounter = 0 - if lineCounter != 0: - result += '\n ' - result += ' // Terminating null character.\n 0' + if not quoted: + result += ' "' + quoted = True + if byte in printable: + result += byte + elif byte == '\n': + if lineNumber % 10 == 0: + result += '\\n" /* L%d */\n' % lineNumber + else: + result += '\\n"\n' + lineNumber += 1 + quoted = False + elif byte == '\"': + result += '\\"' + else: + result += '\\x%02x' % ord(byte) return result diff --git a/runtime/vm/corelib_impl_in.cc b/runtime/vm/corelib_impl_in.cc index 4141a13390a..ce0b93ef4ca 100644 --- a/runtime/vm/corelib_impl_in.cc +++ b/runtime/vm/corelib_impl_in.cc @@ -9,8 +9,8 @@ namespace dart { // The string on the next line will be filled in with the contents of the // bootstrap dart files. -const char Bootstrap::corelib_impl_source_[] = { - {{DART_SOURCE}} -}; +const char Bootstrap::corelib_impl_source_[] = +{{DART_SOURCE}} + ; /* NOLINT */ } // namespace dart diff --git a/runtime/vm/corelib_in.cc b/runtime/vm/corelib_in.cc index 4216309a803..4560c9eb5ca 100644 --- a/runtime/vm/corelib_in.cc +++ b/runtime/vm/corelib_in.cc @@ -8,8 +8,8 @@ namespace dart { // The string on the next line will be filled in with the contents of the // bootstrap dart files. -const char Bootstrap::corelib_source_[] = { - {{DART_SOURCE}} -}; +const char Bootstrap::corelib_source_[] = +{{DART_SOURCE}} + ; /* NOLINT */ } // namespace dart