From 487dd39e3483217cccb80f46e7a65674c7f6c05a Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Mon, 24 May 2010 09:51:55 -0700 Subject: bug 4752 - allow underscores in Slice identifiers --- cpp/src/FreezeScript/DumpDB.cpp | 9 ++- cpp/src/FreezeScript/transformdb.cpp | 9 ++- cpp/src/Slice/CPlusPlusUtil.cpp | 7 +-- cpp/src/Slice/Parser.cpp | 103 ++++++++++++++++++++++++++--------- cpp/src/Slice/RubyUtil.cpp | 9 ++- cpp/src/Slice/Scanner.cpp | 91 ++++++++++++------------------- cpp/src/Slice/Scanner.l | 28 ---------- cpp/src/slice2cpp/Main.cpp | 10 +++- cpp/src/slice2cs/Main.cpp | 10 +++- cpp/src/slice2freeze/Main.cpp | 8 ++- cpp/src/slice2freezej/Main.cpp | 8 ++- cpp/src/slice2html/Main.cpp | 6 +- cpp/src/slice2java/Main.cpp | 10 +++- cpp/src/slice2php/Main.cpp | 10 +++- cpp/src/slice2py/Main.cpp | 10 +++- cpp/src/slice2rb/Main.cpp | 10 +++- 16 files changed, 194 insertions(+), 144 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp index f5ab1653de3..fca6163b4a3 100755 --- a/cpp/src/FreezeScript/DumpDB.cpp +++ b/cpp/src/FreezeScript/DumpDB.cpp @@ -93,7 +93,8 @@ usage(const string& n) "-UNAME Remove any definition for NAME.\n" "-IDIR Put DIR in the include file search path.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "-o FILE Output sample descriptors into the file FILE.\n" "-f FILE Execute the descriptors in the file FILE.\n" "--load SLICE Load Slice definitions from the file SLICE.\n" @@ -128,6 +129,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator vector cppArgs; bool debug; bool ice = true; // Needs to be true in order to create default definitions. + bool underscore; string outputFile; string inputFile; vector slice; @@ -145,6 +147,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("o", "", IceUtilInternal::Options::NeedArg); opts.addOpt("f", "", IceUtilInternal::Options::NeedArg); opts.addOpt("", "load", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); @@ -258,6 +261,8 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator // No need to set --ice option here -- it is always true. + underscore = opts.isSet("underscore"); + if(opts.isSet("o")) { outputFile = opts.optArg("o"); @@ -314,7 +319,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator return EXIT_FAILURE; } - Slice::UnitPtr unit = Slice::Unit::createUnit(true, true, ice); + Slice::UnitPtr unit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer unitD(unit); if(!FreezeScript::parseSlice(appName, unit, slice, cppArgs, debug)) { diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp index 9d5afb3f8b9..add21992e10 100755 --- a/cpp/src/FreezeScript/transformdb.cpp +++ b/cpp/src/FreezeScript/transformdb.cpp @@ -53,6 +53,7 @@ usage(const std::string& n) "-DNAME=DEF Define NAME as DEF.\n" "-UNAME Remove any definition for NAME.\n" "-d, --debug Print debug messages.\n" + "--underscore Permit underscores in Slice identifiers.\n" "--include-old DIR Put DIR in the include file search path for old Slice\n" " definitions.\n" "--include-new DIR Put DIR in the include file search path for new Slice\n" @@ -217,6 +218,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator vector newCppArgs; bool debug; bool ice = true; // Needs to be true in order to create default definitions. + bool underscore; string outputFile; bool ignoreTypeChanges; bool purgeObjects; @@ -237,6 +239,7 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator opts.addOpt("D", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("d", "debug"); + opts.addOpt("", "underscore"); opts.addOpt("o", "", IceUtilInternal::Options::NeedArg); opts.addOpt("i"); opts.addOpt("p"); @@ -295,6 +298,8 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator } debug = opts.isSet("debug"); + underscore = opts.isSet("underscore"); + if(opts.isSet("o")) { outputFile = opts.optArg("o"); @@ -412,14 +417,14 @@ run(const Ice::StringSeq& originalArgs, const Ice::CommunicatorPtr& communicator return EXIT_FAILURE; } - Slice::UnitPtr oldUnit = Slice::Unit::createUnit(true, true, ice); + Slice::UnitPtr oldUnit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer oldD(oldUnit); if(!FreezeScript::parseSlice(appName, oldUnit, oldSlice, oldCppArgs, debug)) { return EXIT_FAILURE; } - Slice::UnitPtr newUnit = Slice::Unit::createUnit(true, true, ice); + Slice::UnitPtr newUnit = Slice::Unit::createUnit(true, true, ice, underscore); FreezeScript::Destroyer newD(newUnit); if(!FreezeScript::parseSlice(appName, newUnit, newSlice, newCppArgs, debug)) { diff --git a/cpp/src/Slice/CPlusPlusUtil.cpp b/cpp/src/Slice/CPlusPlusUtil.cpp index 08ab56a67cf..6baf74213b9 100644 --- a/cpp/src/Slice/CPlusPlusUtil.cpp +++ b/cpp/src/Slice/CPlusPlusUtil.cpp @@ -493,10 +493,9 @@ lookupKwd(const string& name) // Keyword list. *Must* be kept in alphabetical order. // // Note that this keyword list unnecessarily contains C++ keywords - // that are illegal slice identifiers -- namely identifiers that - // contain underscores (and_eq, for example), and slice keywords - // (class, int, etc.). They have not been removed so that the - // keyword list is kept complete. + // that are illegal Slice identifiers -- namely identifiers that + // are Slice keywords (class, int, etc.). They have not been removed + // so that the keyword list is kept complete. // static const string keywordList[] = { diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 70bfd33d573..c1e27516176 100755 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -482,7 +482,7 @@ Slice::Container::destroy() ModulePtr Slice::Container::createModule(const string& name) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); matches.sort(); // Modules can occur many times... matches.unique(); // ... but we only want one instance of each. @@ -530,7 +530,7 @@ Slice::Container::createModule(const string& name) ClassDefPtr Slice::Container::createClassDef(const string& name, bool intf, const ClassList& bases, bool local) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); for(ContainedList::const_iterator p = matches.begin(); p != matches.end(); ++p) { @@ -620,7 +620,7 @@ Slice::Container::createClassDef(const string& name, bool intf, const ClassList& ClassDeclPtr Slice::Container::createClassDecl(const string& name, bool intf, bool local) { - checkPrefix(name); + checkIdentifier(name); ClassDefPtr def; @@ -711,7 +711,7 @@ Slice::Container::createClassDecl(const string& name, bool intf, bool local) ExceptionPtr Slice::Container::createException(const string& name, const ExceptionPtr& base, bool local, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -762,7 +762,7 @@ Slice::Container::createException(const string& name, const ExceptionPtr& base, StructPtr Slice::Container::createStruct(const string& name, bool local, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -806,7 +806,7 @@ SequencePtr Slice::Container::createSequence(const string& name, const TypePtr& type, const StringList& metaData, bool local, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE && !local) { @@ -871,7 +871,7 @@ Slice::Container::createDictionary(const string& name, const TypePtr& keyType, c const TypePtr& valueType, const StringList& valueMetaData, bool local, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE && !local) { @@ -953,7 +953,7 @@ Slice::Container::createDictionary(const string& name, const TypePtr& keyType, c EnumPtr Slice::Container::createEnum(const string& name, bool local, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -996,7 +996,7 @@ Slice::Container::createEnum(const string& name, bool local, NodeType nt) EnumeratorPtr Slice::Container::createEnumerator(const string& name) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -1036,7 +1036,7 @@ Slice::Container::createConst(const string name, const TypePtr& constType, const const SyntaxTreeBasePtr& literalType, const string& value, const string& literal, NodeType nt) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -2097,19 +2097,59 @@ Slice::Container::Container(const UnitPtr& unit) : } void -Slice::Container::checkPrefix(const string& name) const +Slice::Container::checkIdentifier(const string& name) const { - if(_unit->currentIncludeLevel() == 0 && !_unit->allowIcePrefix()) + // + // Weed out identifiers with reserved suffixes. + // + static const string suffixBlacklist[] = { "Helper", "Holder", "Prx", "Ptr" }; + for(size_t i = 0; i < sizeof(suffixBlacklist) / sizeof(*suffixBlacklist); ++i) + { + if(name.find(suffixBlacklist[i], name.size() - suffixBlacklist[i].size()) != string::npos) + { + _unit->error("illegal identifier `" + name + "': `" + suffixBlacklist[i] + "' suffix is reserved"); + } + } + + // + // Check for illegal underscores. + // + if(name.find('_') == 0) + { + _unit->error("illegal leading underscore in identifier `" + name + "'"); + } + else if(name.rfind('_') == name.size() - 1) + { + _unit->error("illegal trailing underscore in identifier `" + name + "'"); + } + else if(name.rfind("__") != string::npos) + { + _unit->error("illegal double underscore in identifier `" + name + "'"); + } + + if(_unit->currentIncludeLevel() == 0) { - if(name.size() >= 3) + // + // For rules controlled by a translator option, we don't complain about included files. + // + + if(!_unit->allowUnderscore() && name.find('_') != string::npos) + { + _unit->error("illegal underscore in identifier `" + name + "'"); + } + + if(!_unit->allowIcePrefix()) { - string prefix3; - prefix3 += ::tolower(static_cast(name[0])); - prefix3 += ::tolower(static_cast(name[1])); - prefix3 += ::tolower(static_cast(name[2])); - if(prefix3 == "ice") + if(name.size() >= 3) { - _unit->error("illegal identifier `" + name + "': `" + name.substr(0, 3) + "' prefix is reserved"); + string prefix3; + prefix3 += ::tolower(static_cast(name[0])); + prefix3 += ::tolower(static_cast(name[1])); + prefix3 += ::tolower(static_cast(name[2])); + if(prefix3 == "ice") + { + _unit->error("illegal identifier `" + name + "': `" + name.substr(0, 3) + "' prefix is reserved"); + } } } } @@ -2794,7 +2834,7 @@ Slice::ClassDef::createOperation(const string& name, const TypePtr& returnType, Operation::Mode mode) { - checkPrefix(name); + checkIdentifier(name); ContainedList matches = _unit->findContents(thisScope() + name); if(!matches.empty()) @@ -2899,7 +2939,7 @@ DataMemberPtr Slice::ClassDef::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, const string& defaultValue, const string& defaultLiteral) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE) { @@ -3407,7 +3447,7 @@ DataMemberPtr Slice::Exception::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, const string& defaultValue, const string& defaultLiteral) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE) { @@ -3748,7 +3788,7 @@ DataMemberPtr Slice::Struct::createDataMember(const string& name, const TypePtr& type, const SyntaxTreeBasePtr& defaultLiteralType, const string& defaultValue, const string& defaultLiteral) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE) { @@ -4504,7 +4544,7 @@ Slice::Operation::sendMode() const ParamDeclPtr Slice::Operation::createParamDecl(const string& name, const TypePtr& type, bool isOutParam) { - checkPrefix(name); + checkIdentifier(name); if(_unit->profile() == IceE) { @@ -5032,9 +5072,10 @@ Slice::DataMember::DataMember(const ContainerPtr& container, const string& name, // ---------------------------------------------------------------------- UnitPtr -Slice::Unit::createUnit(bool ignRedefs, bool all, bool allowIcePrefix, const StringList& defaultGlobalMetadata) +Slice::Unit::createUnit(bool ignRedefs, bool all, bool allowIcePrefix, bool allowUnderscore, + const StringList& defaultGlobalMetadata) { - return new Unit(ignRedefs, all, allowIcePrefix, defaultGlobalMetadata); + return new Unit(ignRedefs, all, allowIcePrefix, allowUnderscore, defaultGlobalMetadata); } bool @@ -5049,6 +5090,12 @@ Slice::Unit::allowIcePrefix() const return _allowIcePrefix; } +bool +Slice::Unit::allowUnderscore() const +{ + return _allowUnderscore; +} + void Slice::Unit::setComment(const string& comment) { @@ -5663,12 +5710,14 @@ Slice::Unit::builtin(Builtin::Kind kind) return builtin; } -Slice::Unit::Unit(bool ignRedefs, bool all, bool allowIcePrefix, const StringList& defaultGlobalMetadata) : +Slice::Unit::Unit(bool ignRedefs, bool all, bool allowIcePrefix, bool allowUnderscore, + const StringList& defaultGlobalMetadata) : SyntaxTreeBase(0), Container(0), _ignRedefs(ignRedefs), _all(all), _allowIcePrefix(allowIcePrefix), + _allowUnderscore(allowUnderscore), _defaultGlobalMetaData(defaultGlobalMetadata), _errors(0), _currentLine(0), diff --git a/cpp/src/Slice/RubyUtil.cpp b/cpp/src/Slice/RubyUtil.cpp index ada72fe1ce3..f62dbc124fe 100755 --- a/cpp/src/Slice/RubyUtil.cpp +++ b/cpp/src/Slice/RubyUtil.cpp @@ -116,9 +116,12 @@ lookupKwd(const string& name) static const string keywordList[] = { "BEGIN", "END", "alias", "and", "begin", "break", "case", "class", "clone", "def", "display", "do", "dup", - "else", "elsif", "end", "ensure", "extend", "false", "for", "freeze", "hash", "if", "in", "inspect", "method", - "methods", "module", "new", "next", "nil", "not", "or", "redo", "rescue", "retry", "return", "self", "send", - "super", "taint", "then", "true", "undef", "unless", "untaint", "until", "when", "while", "yield" + "else", "elsif", "end", "ensure", "extend", "false", "for", "freeze", "hash", "if", "in", "initialize_copy", + "inspect", "instance_eval", "instance_variable_get", "instance_variable_set", "instance_variables", "method", + "method_missing", "methods", "module", "new", "next", "nil", "not", "object_id", "or", "private_methods", + "protected_methods", "public_methods", "redo", "rescue", "retry", "return", "self", "send", + "singleton_methods", "super", "taint", "then", "to_a", "to_s", "true", "undef", "unless", "untaint", "until", + "when", "while", "yield" }; bool found = binary_search(&keywordList[0], &keywordList[sizeof(keywordList) / sizeof(*keywordList)], diff --git a/cpp/src/Slice/Scanner.cpp b/cpp/src/Slice/Scanner.cpp index 9b74ab2241e..3300be94dc6 100644 --- a/cpp/src/Slice/Scanner.cpp +++ b/cpp/src/Slice/Scanner.cpp @@ -17,7 +17,7 @@ #define yytext slice_text #line 19 "lex.yy.c" -/* A lexical scanner generated by flex */ +/* A lexical scanner generated by flex*/ /* Scanner skeleton version: * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ @@ -153,6 +153,15 @@ extern FILE *yyin, *yyout; #define unput(c) yyunput( c, yytext_ptr ) +/* Some routines like yy_flex_realloc() are emitted as static but are + not called by all lexers. This generates warnings in some compilers, + notably GCC. Arrange to suppress these. */ +#ifdef __GNUC__ +#define YY_MAY_BE_UNUSED __attribute__((unused)) +#else +#define YY_MAY_BE_UNUSED +#endif + /* The following is because we cannot portably get our hands on size_t * (without autoconf's help, which isn't available because we want * flex-generated scanners to compile on their own). @@ -259,7 +268,7 @@ YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )) YY_MAY_BE_UNUSED; static void yy_flex_free YY_PROTO(( void * )); #define yy_new_buffer yy_create_buffer @@ -499,7 +508,6 @@ typedef std::map StringTokenMap; static StringTokenMap keywordMap; void initScanner(); -void checkIdentifier(const string&); int checkKeyword(string&); } @@ -511,7 +519,7 @@ int checkKeyword(string&); #define MAINSCAN 2 -#line 514 "lex.yy.c" +#line 522 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -665,10 +673,10 @@ YY_DECL register char *yy_cp = NULL, *yy_bp = NULL; register int yy_act; -#line 68 "Scanner.l" +#line 67 "Scanner.l" -#line 671 "lex.yy.c" +#line 679 "lex.yy.c" if ( yy_init ) { @@ -757,7 +765,7 @@ case 1: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 70 "Scanner.l" +#line 69 "Scanner.l" { if(unit->scanPosition(yytext)) { @@ -770,7 +778,7 @@ case 2: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 77 "Scanner.l" +#line 76 "Scanner.l" { if(unit->scanPosition(yytext)) { @@ -783,7 +791,7 @@ case 3: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 84 "Scanner.l" +#line 83 "Scanner.l" { if(unit->scanPosition(yytext)) { @@ -796,7 +804,7 @@ case 4: yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 91 "Scanner.l" +#line 90 "Scanner.l" { if(unit->scanPosition(yytext)) { @@ -806,7 +814,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 98 "Scanner.l" +#line 97 "Scanner.l" { // C++-style comment BEGIN(MAINSCAN); @@ -824,7 +832,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 113 "Scanner.l" +#line 112 "Scanner.l" { // C-style comment BEGIN(MAINSCAN); @@ -868,7 +876,7 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 154 "Scanner.l" +#line 153 "Scanner.l" { BEGIN(MAINSCAN); return ICE_SCOPE_DELIMITER; @@ -876,7 +884,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 159 "Scanner.l" +#line 158 "Scanner.l" { BEGIN(MAINSCAN); return ICE_METADATA_OPEN; @@ -884,7 +892,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 164 "Scanner.l" +#line 163 "Scanner.l" { BEGIN(MAINSCAN); return ICE_METADATA_CLOSE; @@ -892,7 +900,7 @@ YY_RULE_SETUP YY_BREAK case 10: YY_RULE_SETUP -#line 169 "Scanner.l" +#line 168 "Scanner.l" { BEGIN(MAINSCAN); return ICE_GLOBAL_METADATA_OPEN; @@ -900,7 +908,7 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 174 "Scanner.l" +#line 173 "Scanner.l" { BEGIN(MAINSCAN); return ICE_GLOBAL_METADATA_CLOSE; @@ -908,14 +916,13 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 179 "Scanner.l" +#line 178 "Scanner.l" { BEGIN(MAINSCAN); StringTokPtr ident = new StringTok; ident->v = *yytext == '\\' ? yytext + 1 : yytext; ident->v.erase(ident->v.find_first_of(" \t\v\n\r\f(")); *yylvalp = ident; - checkIdentifier(ident->v); if(*yytext == '\\') { return ICE_IDENT_OP; @@ -925,19 +932,18 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 193 "Scanner.l" +#line 191 "Scanner.l" { BEGIN(MAINSCAN); StringTokPtr ident = new StringTok; ident->v = *yytext == '\\' ? yytext + 1 : yytext; *yylvalp = ident; - checkIdentifier(ident->v); return *yytext == '\\' ? ICE_IDENTIFIER : checkKeyword(ident->v); } YY_BREAK case 14: YY_RULE_SETUP -#line 202 "Scanner.l" +#line 199 "Scanner.l" { BEGIN(MAINSCAN); StringTokPtr str = new StringTok; @@ -1101,7 +1107,7 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 363 "Scanner.l" +#line 360 "Scanner.l" { BEGIN(MAINSCAN); IntegerTokPtr itp = new IntegerTok; @@ -1120,7 +1126,7 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 379 "Scanner.l" +#line 376 "Scanner.l" { BEGIN(MAINSCAN); errno = 0; @@ -1153,7 +1159,7 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -#line 409 "Scanner.l" +#line 406 "Scanner.l" { // Ignore white-space @@ -1169,7 +1175,7 @@ YY_RULE_SETUP YY_BREAK case 18: YY_RULE_SETUP -#line 422 "Scanner.l" +#line 419 "Scanner.l" { // Ignore UTF-8 BOM, rule only active when parsing start of file. @@ -1178,7 +1184,7 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 428 "Scanner.l" +#line 425 "Scanner.l" { BEGIN(MAINSCAN); if(yytext[0] < 32 || yytext[0] > 126) @@ -1197,10 +1203,10 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 444 "Scanner.l" +#line 441 "Scanner.l" ECHO; YY_BREAK -#line 1203 "lex.yy.c" +#line 1209 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(BOMSCAN): case YY_STATE_EOF(MAINSCAN): @@ -2086,7 +2092,7 @@ int main() return 0; } #endif -#line 444 "Scanner.l" +#line 441 "Scanner.l" namespace Slice { @@ -2128,31 +2134,6 @@ initScanner() keywordMap["idempotent"] = ICE_IDEMPOTENT; } -// -// Check if an identifier is well-formed. -// - -void -checkIdentifier(const string& id) -{ - if(id.find('_') != string::npos) - { - unit->error("illegal underscore in identifier `" + id + "'"); - } - - // - // Weed out identifiers with reserved suffixes. - // - static const string suffixBlacklist[] = { "Helper", "Holder", "Prx", "Ptr" }; - for(size_t i = 0; i < sizeof(suffixBlacklist) / sizeof(*suffixBlacklist); ++i) - { - if(id.find(suffixBlacklist[i], id.size() - suffixBlacklist[i].size()) != string::npos) - { - unit->error("illegal identifier `" + id + "': `" + suffixBlacklist[i] + "' suffix is reserved"); - } - } -} - // // Check if an identifier looks like a keyword. // If the identifier is a keyword, return the diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index a615b2fd149..268a9f32d9e 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -42,7 +42,6 @@ typedef std::map StringTokenMap; static StringTokenMap keywordMap; void initScanner(); -void checkIdentifier(const string&); int checkKeyword(string&); } @@ -182,7 +181,6 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e ident->v = *yytext == '\\' ? yytext + 1 : yytext; ident->v.erase(ident->v.find_first_of(" \t\v\n\r\f(")); *yylvalp = ident; - checkIdentifier(ident->v); if(*yytext == '\\') { return ICE_IDENT_OP; @@ -195,7 +193,6 @@ floating_literal (({fractional_constant}{exponent_part}?)|((\+|-)?[[:digit:]]+{e StringTokPtr ident = new StringTok; ident->v = *yytext == '\\' ? yytext + 1 : yytext; *yylvalp = ident; - checkIdentifier(ident->v); return *yytext == '\\' ? ICE_IDENTIFIER : checkKeyword(ident->v); } @@ -482,31 +479,6 @@ initScanner() keywordMap["idempotent"] = ICE_IDEMPOTENT; } -// -// Check if an identifier is well-formed. -// - -void -checkIdentifier(const string& id) -{ - if(id.find('_') != string::npos) - { - unit->error("illegal underscore in identifier `" + id + "'"); - } - - // - // Weed out identifiers with reserved suffixes. - // - static const string suffixBlacklist[] = { "Helper", "Holder", "Prx", "Ptr" }; - for(size_t i = 0; i < sizeof(suffixBlacklist) / sizeof(*suffixBlacklist); ++i) - { - if(id.find(suffixBlacklist[i], id.size() - suffixBlacklist[i].size()) != string::npos) - { - unit->error("illegal identifier `" + id + "': `" + suffixBlacklist[i] + "' suffix is reserved"); - } - } -} - // // Check if an identifier looks like a keyword. // If the identifier is a keyword, return the diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 5932f164075..0ca754b25e5 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -75,7 +75,8 @@ usage(const char* n) "--impl Generate sample implementations.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--checksum Generate checksums for Slice definitions.\n" "--stream Generate marshaling support for public stream API.\n" ; @@ -101,6 +102,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "checksum"); opts.addOpt("", "stream"); @@ -170,6 +172,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + bool checksum = opts.isSet("checksum"); bool stream = opts.isSet("stream"); @@ -207,7 +211,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -253,7 +257,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); if(!icecpp->close()) diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 0e132820bac..87ed3c684a4 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -72,7 +72,8 @@ usage(const char* n) "--impl-tie Generate sample TIE implementations.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--checksum Generate checksums for Slice definitions.\n" "--stream Generate marshaling support for public stream API.\n" ; @@ -95,6 +96,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "checksum"); opts.addOpt("", "stream"); @@ -158,6 +160,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + bool checksum = opts.isSet("checksum"); bool stream = opts.isSet("stream"); @@ -202,7 +206,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -247,7 +251,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr p = Unit::createUnit(false, false, ice); + UnitPtr p = Unit::createUnit(false, false, ice, underscore); int parseStatus = p->parse(*i, cppHandle, debug); if(!icecpp->close()) diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 97fe20f2e1b..764baa002a6 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -239,7 +239,8 @@ usage(const char* n) " value is std::less.\n" "--output-dir DIR Create files in the directory DIR.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" ; } @@ -1526,6 +1527,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); vector args; try @@ -1923,6 +1925,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + if(dicts.empty() && indices.empty()) { getErrorStream() << argv[0] << ": error: no Freeze types specified" << endl; @@ -1937,7 +1941,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(true, false, ice); + UnitPtr u = Unit::createUnit(true, false, ice, underscore); StringList includes; diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp index e6490332333..e5223c5366f 100755 --- a/cpp/src/slice2freezej/Main.cpp +++ b/cpp/src/slice2freezej/Main.cpp @@ -1457,7 +1457,8 @@ usage(const char* n) "--output-dir DIR Create files in the directory DIR.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--meta META Define global metadata directive META.\n" ; } @@ -1480,6 +1481,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); vector args; @@ -1737,6 +1739,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + StringList globalMetadata; vector v = opts.argVec("meta"); copy(v.begin(), v.end(), back_inserter(globalMetadata)); @@ -1748,7 +1752,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(true, false, ice, globalMetadata); + UnitPtr u = Unit::createUnit(true, false, ice, underscore, globalMetadata); int status = EXIT_SUCCESS; diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index f281be68a6c..4d5ee7993a8 100755 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -80,6 +80,7 @@ usage(const char* n) "--summary NUM Print a warning if a summary sentence exceeds NUM characters.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--ice Permit underscores in Slice identifiers.\n" ; } @@ -105,6 +106,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "summary", IceUtilInternal::Options::NeedArg, "0"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); vector args; try @@ -202,6 +204,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + if(args.empty()) { getErrorStream() << argv[0] << ": error: no input file" << endl; @@ -209,7 +213,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr p = Unit::createUnit(true, false, ice); + UnitPtr p = Unit::createUnit(true, false, ice, underscore); int status = EXIT_SUCCESS; diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index ffa4f6890dc..90978cf7cbe 100755 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -75,7 +75,8 @@ usage(const char* n) "--depend-xml Generate dependencies in XML format.\n" "--list-generated Emit list of generated files in XML format.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--checksum CLASS Generate checksums for Slice definitions into CLASS.\n" "--stream Generate marshaling support for public stream API.\n" "--meta META Define global metadata directive META.\n" @@ -101,6 +102,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "list-generated"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "checksum", IceUtilInternal::Options::NeedArg); opts.addOpt("", "stream"); opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); @@ -166,6 +168,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + string checksumClass = opts.optArg("checksum"); bool stream = opts.isSet("stream"); @@ -223,7 +227,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -282,7 +286,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr p = Unit::createUnit(false, false, ice, globalMetadata); + UnitPtr p = Unit::createUnit(false, false, ice, underscore, globalMetadata); int parseStatus = p->parse(*i, cppHandle, debug, Ice); if(!icecpp->close()) diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index d66a791af51..4e05affbaf7 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1526,7 +1526,8 @@ usage(const char* n) "--output-dir DIR Create files in the directory DIR.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" "-n, --namespace Use PHP namespaces (requires PHP 5.3.0 or later).\n" @@ -1547,6 +1548,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "all"); opts.addOpt("", "checksum"); opts.addOpt("n", "namespace"); @@ -1605,6 +1607,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + bool all = opts.isSet("all"); bool checksum = opts.isSet("checksum"); @@ -1644,7 +1648,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -1690,7 +1694,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); + UnitPtr u = Unit::createUnit(false, all, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); if(!icecpp->close()) diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 58fc3a9f47c..0eed26549c7 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -373,7 +373,8 @@ usage(const char* n) "--output-dir DIR Create files in the directory DIR.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" "--prefix PREFIX Prepend filenames of Python modules with PREFIX.\n" @@ -394,6 +395,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "all"); opts.addOpt("", "no-package"); opts.addOpt("", "checksum"); @@ -453,6 +455,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + bool all = opts.isSet("all"); bool noPackage = opts.isSet("no-package"); @@ -496,7 +500,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -542,7 +546,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); + UnitPtr u = Unit::createUnit(false, all, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); if(!icecpp->close()) diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index ae41372844b..e4b6cd04264 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -86,7 +86,8 @@ usage(const char* n) "--output-dir DIR Create files in the directory DIR.\n" "--depend Generate Makefile dependencies.\n" "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--ice Permit `Ice' prefix (for building Ice source code only).\n" + "--underscore Permit underscores in Slice identifiers.\n" "--all Generate code for Slice definitions in included files.\n" "--checksum Generate checksums for Slice definitions.\n" ; @@ -106,6 +107,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "depend"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); + opts.addOpt("", "underscore"); opts.addOpt("", "all"); opts.addOpt("", "checksum"); @@ -163,6 +165,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + bool all = opts.isSet("all"); bool checksum = opts.isSet("checksum"); @@ -200,7 +204,7 @@ compile(int argc, char* argv[]) return EXIT_FAILURE; } - UnitPtr u = Unit::createUnit(false, false, ice); + UnitPtr u = Unit::createUnit(false, false, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); u->destroy(); @@ -246,7 +250,7 @@ compile(int argc, char* argv[]) } else { - UnitPtr u = Unit::createUnit(false, all, ice); + UnitPtr u = Unit::createUnit(false, all, ice, underscore); int parseStatus = u->parse(*i, cppHandle, debug); if(!icecpp->close()) -- cgit v1.2.3