From ab9f9550cf28060b7e78472b20911c0c867327fd Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 21 Feb 2013 16:18:20 -0700 Subject: [PATCH] move tokenizer.h to include/avian/util/string.h, merge in the String declaration from object-writer/tools.h --- include/avian/tools/object-writer/tools.h | 21 +++------ .../avian/util/string.h | 43 ++++++++++++------- makefile | 6 ++- src/classpath-common.h | 9 ++-- src/finder.cpp | 18 ++++---- src/tools/object-writer/elf.cpp | 1 + src/tools/object-writer/mach-o.cpp | 1 + src/tools/object-writer/pe.cpp | 1 + src/tools/object-writer/tools.cpp | 6 +-- 9 files changed, 58 insertions(+), 48 deletions(-) rename src/tokenizer.h => include/avian/util/string.h (56%) diff --git a/include/avian/tools/object-writer/tools.h b/include/avian/tools/object-writer/tools.h index 46bcd691e8..411dfaec9e 100644 --- a/include/avian/tools/object-writer/tools.h +++ b/include/avian/tools/object-writer/tools.h @@ -12,6 +12,9 @@ #define AVIAN_TOOLS_H_ #include + +#include + #include "environment.h" namespace avian { @@ -38,24 +41,12 @@ public: virtual void write(uint8_t byte); }; -class String { -public: - const char* text; - size_t length; - - String(const char* text); - - inline String(const char* text, size_t length): - text(text), - length(length) {} -}; - class SymbolInfo { public: unsigned addr; - String name; + util::String name; - inline SymbolInfo(uint64_t addr, const String& name): + inline SymbolInfo(uint64_t addr, const util::String& name): addr(addr), name(name) {} @@ -78,7 +69,7 @@ public: class StringTable : public Buffer { public: - unsigned add(String str); + unsigned add(util::String str); }; template diff --git a/src/tokenizer.h b/include/avian/util/string.h similarity index 56% rename from src/tokenizer.h rename to include/avian/util/string.h index 5699227c74..b0b338abfa 100644 --- a/src/tokenizer.h +++ b/include/avian/util/string.h @@ -8,27 +8,37 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#ifndef TOKENIZER_H -#define TOKENIZER_H +#ifndef AVIAN_UTIL_STRING_H +#define AVIAN_UTIL_STRING_H -namespace vm { +#include + +namespace avian { +namespace util { + +class String { +public: + const char* text; + size_t length; + + String(const char* text): + text(text), + length(strlen(text)) {} + + inline String(const char* text, size_t length): + text(text), + length(length) {} +}; class Tokenizer { public: - class Token { - public: - Token(const char* s, unsigned length): s(s), length(length) { } - - const char* s; - unsigned length; - }; Tokenizer(const char* s, char delimiter): s(s), limit(0), delimiter(delimiter) { } - Tokenizer(const char* s, unsigned length, char delimiter): - s(s), limit(s + length), delimiter(delimiter) + Tokenizer(String str, char delimiter): + s(str.text), limit(str.text + str.length), delimiter(delimiter) { } bool hasMore() { @@ -36,10 +46,10 @@ class Tokenizer { return s != limit and *s != 0; } - Token next() { + String next() { const char* p = s; while (s != limit and *s and *s != delimiter) ++s; - return Token(p, s - p); + return String(p, s - p); } const char* s; @@ -47,6 +57,7 @@ class Tokenizer { char delimiter; }; -} // namespace +} // namespace util +} // namespace avain -#endif//TOKENIZER_H +#endif//AVIAN_UTIL_STRING_H diff --git a/makefile b/makefile index 7524a163c1..1251933442 100755 --- a/makefile +++ b/makefile @@ -939,7 +939,11 @@ generated-code = \ $(build)/type-name-initializations.cpp \ $(build)/type-maps.cpp -vm-depends := $(generated-code) $(wildcard $(src)/*.h) $(wildcard $(src)/codegen/*.h) $(wildcard $(src)/codegen/compiler/*.h) +vm-depends := $(generated-code) \ + $(wildcard $(src)/*.h) \ + $(wildcard $(src)/codegen/*.h) \ + $(wildcard $(src)/codegen/compiler/*.h) \ + $(shell find include -name '*.h') vm-sources = \ $(src)/vm/system/$(system).cpp \ diff --git a/src/classpath-common.h b/src/classpath-common.h index 6298d47695..92ae23c165 100644 --- a/src/classpath-common.h +++ b/src/classpath-common.h @@ -11,10 +11,11 @@ #ifndef CLASSPATH_COMMON_H #define CLASSPATH_COMMON_H -#include "tokenizer.h" - +#include #include +using namespace avian::util; + namespace vm { object @@ -217,13 +218,13 @@ loadLibrary(Thread* t, const char* path, const char* name, bool mapName, for (Tokenizer tokenizer(path, t->m->system->pathSeparator()); tokenizer.hasMore();) { - Tokenizer::Token token(tokenizer.next()); + String token(tokenizer.next()); unsigned fullNameLength = token.length + 1 + nameLength; THREAD_RUNTIME_ARRAY(t, char, fullName, fullNameLength + 1); snprintf(RUNTIME_ARRAY_BODY(fullName), fullNameLength + 1, - "%.*s/%s", token.length, token.s, name); + "%.*s/%s", token.length, token.text, name); lib = loadLibrary(t, RUNTIME_ARRAY_BODY(fullName)); if (lib) break; diff --git a/src/finder.cpp b/src/finder.cpp index 879796075b..a3fa539910 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -8,15 +8,17 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "zlib-custom.h" #include -#include "tokenizer.h" +#include +#include + +#include "zlib-custom.h" #include "finder.h" #include "lzma.h" -#include using namespace vm; +using namespace avian::util; namespace { @@ -658,12 +660,12 @@ addTokens(System* s, Element** first, Element** last, Allocator* allocator, const char* jarName, unsigned jarNameBase, const char* tokens, unsigned tokensLength, const char* bootLibrary) { - for (Tokenizer t(tokens, tokensLength, ' '); t.hasMore();) { - Tokenizer::Token token(t.next()); + for (Tokenizer t(String(tokens, tokensLength), ' '); t.hasMore();) { + String token(t.next()); RUNTIME_ARRAY(char, n, jarNameBase + token.length + 1); memcpy(RUNTIME_ARRAY_BODY(n), jarName, jarNameBase); - memcpy(RUNTIME_ARRAY_BODY(n) + jarNameBase, token.s, token.length); + memcpy(RUNTIME_ARRAY_BODY(n) + jarNameBase, token.text, token.length); RUNTIME_ARRAY_BODY(n)[jarNameBase + token.length] = 0; add(s, first, last, allocator, RUNTIME_ARRAY_BODY(n), @@ -813,9 +815,9 @@ parsePath(System* s, Allocator* allocator, const char* path, Element* first = 0; Element* last = 0; for (Tokenizer t(path, s->pathSeparator()); t.hasMore();) { - Tokenizer::Token token(t.next()); + String token(t.next()); - add(s, &first, &last, allocator, token.s, token.length, bootLibrary); + add(s, &first, &last, allocator, token.text, token.length, bootLibrary); } return first; diff --git a/src/tools/object-writer/elf.cpp b/src/tools/object-writer/elf.cpp index bf220e1e04..555d6fd9ca 100644 --- a/src/tools/object-writer/elf.cpp +++ b/src/tools/object-writer/elf.cpp @@ -72,6 +72,7 @@ namespace { using namespace avian::tools; +using namespace avian::util; template struct ElfTypes { diff --git a/src/tools/object-writer/mach-o.cpp b/src/tools/object-writer/mach-o.cpp index fac134f272..03066fc247 100644 --- a/src/tools/object-writer/mach-o.cpp +++ b/src/tools/object-writer/mach-o.cpp @@ -43,6 +43,7 @@ namespace { using namespace avian::tools; +using namespace avian::util; typedef int cpu_type_t; typedef int cpu_subtype_t; diff --git a/src/tools/object-writer/pe.cpp b/src/tools/object-writer/pe.cpp index 0fdc4a16e0..b96124582b 100644 --- a/src/tools/object-writer/pe.cpp +++ b/src/tools/object-writer/pe.cpp @@ -86,6 +86,7 @@ pad(unsigned n) } using namespace avian::tools; +using namespace avian::util; template class WindowsPlatform : public Platform { diff --git a/src/tools/object-writer/tools.cpp b/src/tools/object-writer/tools.cpp index 49726245c7..4284778550 100644 --- a/src/tools/object-writer/tools.cpp +++ b/src/tools/object-writer/tools.cpp @@ -15,14 +15,12 @@ #include +using namespace avian::util; + namespace avian { namespace tools { -String::String(const char* text): - text(text), - length(strlen(text)) {} - Buffer::Buffer(): capacity(100), length(0),