From 0b9ba091db187adfa65a7f2249407db413927449 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sun, 18 Dec 2011 21:33:57 +0000 Subject: [PATCH] ICU-8972 move genpname/genpname.cpp to genprops/pnameswriter.cpp; use on-the-fly property names data for ppucd parsing: avoids having to rebuild ICU & tools before generating properties data X-SVN-Rev: 31153 --- tools/unicode/c/CMakeLists.txt | 3 +- tools/unicode/c/genprops/CMakeLists.txt | 2 +- tools/unicode/c/genprops/corepropswriter.cpp | 1 + tools/unicode/c/genprops/genprops.cpp | 14 ++ tools/unicode/c/genprops/genprops.h | 7 + .../data.h => genprops/pnames_data.h} | 0 .../pnameswriter.cpp} | 228 +++++++++++------- 7 files changed, 171 insertions(+), 84 deletions(-) rename tools/unicode/c/{genpname/data.h => genprops/pnames_data.h} (100%) rename tools/unicode/c/{genpname/genpname.cpp => genprops/pnameswriter.cpp} (73%) diff --git a/tools/unicode/c/CMakeLists.txt b/tools/unicode/c/CMakeLists.txt index 5fb9353a48d..ab726672a7a 100644 --- a/tools/unicode/c/CMakeLists.txt +++ b/tools/unicode/c/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2010, International Business Machines +# Copyright (C) 2010-2011, International Business Machines # Corporation and others. All Rights Reserved. # # created on: 2010jun03 @@ -21,7 +21,6 @@ add_subdirectory(genbidi) add_subdirectory(gencase) add_subdirectory(gennames) add_subdirectory(gennorm) -add_subdirectory(genpname) add_subdirectory(genprops) add_subdirectory(genuca) add_subdirectory(genuts46) diff --git a/tools/unicode/c/genprops/CMakeLists.txt b/tools/unicode/c/genprops/CMakeLists.txt index 3310e797214..b959e9472d9 100644 --- a/tools/unicode/c/genprops/CMakeLists.txt +++ b/tools/unicode/c/genprops/CMakeLists.txt @@ -5,5 +5,5 @@ # created by: Markus W. Scherer # edited on: 2010jul20 # edited by: Stuart G. Gill -add_executable(genprops genprops.cpp corepropswriter.cpp) +add_executable(genprops genprops.cpp corepropswriter.cpp pnameswriter.cpp) target_link_libraries(genprops icuuc icutu) diff --git a/tools/unicode/c/genprops/corepropswriter.cpp b/tools/unicode/c/genprops/corepropswriter.cpp index 9b7734c3840..7c0dbce3d7a 100644 --- a/tools/unicode/c/genprops/corepropswriter.cpp +++ b/tools/unicode/c/genprops/corepropswriter.cpp @@ -707,6 +707,7 @@ CorePropsWriter::finalizeData(UErrorCode &errorCode) { ((int32_t)U_DT_COUNT-1); if(beVerbose) { + puts("* uprops.icu stats *"); printf("trie size in bytes: %5u\n", (int)trieSize); printf("size in bytes of additional props trie:%5u\n", (int)props2TrieSize); printf("number of additional props vectors: %5u\n", (int)pvRows); diff --git a/tools/unicode/c/genprops/genprops.cpp b/tools/unicode/c/genprops/genprops.cpp index f90492a1e51..92be699b6f1 100644 --- a/tools/unicode/c/genprops/genprops.cpp +++ b/tools/unicode/c/genprops/genprops.cpp @@ -35,6 +35,7 @@ U_NAMESPACE_USE UBool beVerbose=FALSE; +PropsWriter::PropsWriter() {} PropsWriter::~PropsWriter() {} void PropsWriter::setUnicodeVersion(const UVersionInfo) {} void PropsWriter::setProps(const UniProps &, const UnicodeSet &, UErrorCode &) {} @@ -94,6 +95,7 @@ main(int argc, char* argv[]) { /* initialize */ IcuToolErrorCode errorCode("genprops"); + LocalPointer pnamesWriter(createPNamesWriter(errorCode)); LocalPointer corePropsWriter(createCorePropsWriter(errorCode)); if(errorCode.isFailure()) { fprintf(stderr, "genprops: unable to create PropsWriters - %s\n", errorCode.errorName()); @@ -118,6 +120,16 @@ main(int argc, char* argv[]) { ppucdPath.data(), errorCode.errorName()); return errorCode.reset(); } + + // The PNamesWriter uses preparsed pnames_data.h. + pnamesWriter->finalizeData(errorCode); + if(U_FAILURE(errorCode)) { + fprintf(stderr, "genprops: PNamesWriter::finalizeData() failed - %s\n", + errorCode.errorName()); + return errorCode.reset(); + } + ppucd.setPropertyNames(pnamesWriter->getPropertyNames()); + PreparsedUCD::LineType lineType; UnicodeSet newValues; while((lineType=ppucd.readLine(errorCode))!=PreparsedUCD::NO_LINE) { @@ -152,6 +164,8 @@ main(int argc, char* argv[]) { UBool withCopyright=options[COPYRIGHT].doesOccur; + pnamesWriter->writeCSourceFile(sourceCommon.data(), errorCode); + pnamesWriter->writeBinaryData(sourceDataIn.data(), withCopyright, errorCode); corePropsWriter->writeCSourceFile(sourceCommon.data(), errorCode); corePropsWriter->writeBinaryData(sourceDataIn.data(), withCopyright, errorCode); diff --git a/tools/unicode/c/genprops/genprops.h b/tools/unicode/c/genprops/genprops.h index 002f2ef1afc..e598ed72785 100644 --- a/tools/unicode/c/genprops/genprops.h +++ b/tools/unicode/c/genprops/genprops.h @@ -25,6 +25,7 @@ class PropsWriter { public: + PropsWriter(); virtual ~PropsWriter(); virtual void setUnicodeVersion(const UVersionInfo version); virtual void setProps(const icu::UniProps &props, const icu::UnicodeSet &newValues, UErrorCode &errorCode); @@ -33,7 +34,13 @@ public: virtual void writeBinaryData(const char *path, UBool withCopyright, UErrorCode &errorCode); }; +class PNamesWriter : public PropsWriter { +public: + virtual const PropertyNames *getPropertyNames() = 0; +}; + PropsWriter *createCorePropsWriter(UErrorCode &errorCode); +PNamesWriter *createPNamesWriter(UErrorCode &errorCode); /* global flags */ U_CFUNC UBool beVerbose; diff --git a/tools/unicode/c/genpname/data.h b/tools/unicode/c/genprops/pnames_data.h similarity index 100% rename from tools/unicode/c/genpname/data.h rename to tools/unicode/c/genprops/pnames_data.h diff --git a/tools/unicode/c/genpname/genpname.cpp b/tools/unicode/c/genprops/pnameswriter.cpp similarity index 73% rename from tools/unicode/c/genpname/genpname.cpp rename to tools/unicode/c/genprops/pnameswriter.cpp index 541d6deb7ae..6b0e5d42606 100644 --- a/tools/unicode/c/genpname/genpname.cpp +++ b/tools/unicode/c/genprops/pnameswriter.cpp @@ -6,21 +6,23 @@ * Date Name Description * 10/11/02 aliu Creation. * 2010nov19 Markus Scherer Rewrite for formatVersion 2. +* 2011dec18 Markus Scherer Moved genpname/genpname.cpp to genprops/pnameswriter.cpp. ********************************************************************** */ #include "unicode/utypes.h" +#include "unicode/bytestrie.h" #include "unicode/bytestriebuilder.h" #include "unicode/putil.h" #include "unicode/uclean.h" -#include "cmemory.h" #include "charstr.h" #include "cstring.h" #include "denseranges.h" -#include "unewdata.h" -#include "uoptions.h" +#include "genprops.h" #include "propname.h" #include "toolutil.h" +#include "uinvchar.h" +#include "unewdata.h" #include "uvectr32.h" #include "writesrc.h" @@ -132,7 +134,7 @@ Property::Property(int32_t _enumValue, } // *** Include the data header *** -#include "data.h" +#include "pnames_data.h" /* return a list of unique names, not including "", for this property * @param stringIndices array of at least MAX_NAMES_PER_GROUP @@ -174,13 +176,32 @@ int32_t Alias::getUniqueNames(int32_t* stringIndices) const { // END DATA //---------------------------------------------------------------------- -class Builder { +class PNamesWriterImpl; + +class PNamesPropertyNames : public PropertyNames { public: - Builder(UErrorCode &errorCode) : valueMaps(errorCode), btb(errorCode), maxNameLength(0) {} + PNamesPropertyNames(const PNamesWriterImpl &pnwi) + : impl(pnwi), valueMaps(NULL), bytesTries(NULL) {} + void init(); + virtual int32_t getPropertyEnum(const char *name) const; + virtual int32_t getPropertyValueEnum(int32_t property, const char *name) const; +private: + int32_t findProperty(int32_t property) const; + UBool containsName(BytesTrie &trie, const char *name) const; + int32_t getPropertyOrValueEnum(int32_t bytesTrieOffset, const char *alias) const; + + const PNamesWriterImpl &impl; + const int32_t *valueMaps; + const uint8_t *bytesTries; +}; - void build() { - IcuToolErrorCode errorCode("genpname Builder::build()"); +class PNamesWriterImpl : public PNamesWriter { +public: + PNamesWriterImpl(UErrorCode &errorCode) + : valueMaps(errorCode), btb(errorCode), maxNameLength(0), + pnames(*this) {} + virtual void finalizeData(UErrorCode &errorCode) { // Build main property aliases value map at value map offset 0, // so that we need not store another offset for it. UVector32 propEnums(errorCode); @@ -265,8 +286,19 @@ public: for(i=PropNameData::IX_RESERVED7; i(impl.bytesTries.data()); +} - /* error handling, printing usage message */ - if(argc<0) { - fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]); - } - if(argc!=1 || options[HELP_H].doesOccur || options[HELP_QUESTION_MARK].doesOccur) { - fprintf(stderr, - "Usage: %s [-options]\n" - "\tCreates " PNAME_DATA_NAME "." PNAME_DATA_TYPE "\n" - "\n", - argv[0]); - fprintf(stderr, - "Options:\n" - "\t-h or -? or --help this usage text\n" - "\t-v or --verbose turn on verbose output\n" - "\t-c or --copyright include a copyright notice\n" - "\t-d or --destdir destination directory, followed by the path\n" - "\t-C or --csource generate a .h source file rather than the .icu binary\n"); - return argc!=1 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; +int32_t PNamesPropertyNames::findProperty(int32_t property) const { + int32_t i=1; // valueMaps index, initially after numRanges + for(int32_t numRanges=valueMaps[0]; numRanges>0; --numRanges) { + // Read and skip the start and limit of this range. + int32_t start=valueMaps[i]; + int32_t limit=valueMaps[i+1]; + i+=2; + if(property