diff options
Diffstat (limited to 'cpp')
26 files changed, 416 insertions, 156 deletions
diff --git a/cpp/include/Slice/Parser.h b/cpp/include/Slice/Parser.h index e961ea35223..c0d6a2c7300 100644 --- a/cpp/include/Slice/Parser.h +++ b/cpp/include/Slice/Parser.h @@ -456,7 +456,7 @@ protected: Container(const UnitPtr&); - void checkPrefix(const std::string&) const; + void checkIdentifier(const std::string&) const; bool checkInterfaceAndLocal(const std::string&, bool, bool, bool, bool, bool); bool checkGlobalMetaData(const StringList&, const StringList&); bool validateConstant(const std::string&, const TypePtr&, const SyntaxTreeBasePtr&, const std::string&, bool); @@ -937,11 +937,11 @@ class SLICE_API Unit : virtual public Container { public: - static UnitPtr createUnit(bool, bool, bool, const StringList& = StringList()); + static UnitPtr createUnit(bool, bool, bool, bool, const StringList& = StringList()); bool ignRedefs() const; - bool allowIcePrefix() const; + bool allowUnderscore() const; void setComment(const std::string&); std::string currentComment(); // Not const, as this function removes the current comment. @@ -1004,12 +1004,13 @@ public: private: - Unit(bool, bool, bool, const StringList&); + Unit(bool, bool, bool, bool, const StringList&); static void eraseWhiteSpace(::std::string&); bool _ignRedefs; bool _all; bool _allowIcePrefix; + bool _allowUnderscore; StringList _defaultGlobalMetaData; int _errors; std::string _currentComment; 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<string> cppArgs; bool debug; bool ice = true; // Needs to be true in order to create default definitions. + bool underscore; string outputFile; string inputFile; vector<string> 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<Slice::UnitPtr> 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<string> 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<Slice::UnitPtr> 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<Slice::UnitPtr> 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<unsigned char>(name[0])); - prefix3 += ::tolower(static_cast<unsigned char>(name[1])); - prefix3 += ::tolower(static_cast<unsigned char>(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<unsigned char>(name[0])); + prefix3 += ::tolower(static_cast<unsigned char>(name[1])); + prefix3 += ::tolower(static_cast<unsigned char>(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<std::string, int, Slice::CICompare> 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 { @@ -2129,31 +2135,6 @@ initScanner() } // -// 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 // corresponding keyword token; otherwise, return 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<std::string, int, Slice::CICompare> 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); } @@ -483,31 +480,6 @@ initScanner() } // -// 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 // corresponding keyword token; otherwise, return 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<secondary key type>.\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<string> 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<string> args; @@ -1737,6 +1739,8 @@ compile(int argc, char* argv[]) bool ice = opts.isSet("ice"); + bool underscore = opts.isSet("underscore"); + StringList globalMetadata; vector<string> 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<string> 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()) diff --git a/cpp/test/Slice/errorDetection/IdentAsKeyword.err b/cpp/test/Slice/errorDetection/IdentAsKeyword.err index 7fd2910e0bd..344750d35b5 100644 --- a/cpp/test/Slice/errorDetection/IdentAsKeyword.err +++ b/cpp/test/Slice/errorDetection/IdentAsKeyword.err @@ -82,9 +82,17 @@ IdentAsKeyword.ice:81: keyword `byte' cannot be used as parameter name IdentAsKeyword.ice:83: keyword `byte' cannot be used as parameter name IdentAsKeyword.ice:84: illegal identifier: `BYTE' differs from keyword `byte' only in capitalization IdentAsKeyword.ice:84: keyword `byte' cannot be used as parameter name +IdentAsKeyword.ice:88: illegal leading underscore in identifier `_a' IdentAsKeyword.ice:88: illegal underscore in identifier `_a' +IdentAsKeyword.ice:89: illegal leading underscore in identifier `_true' IdentAsKeyword.ice:89: illegal underscore in identifier `_true' +IdentAsKeyword.ice:90: illegal leading underscore in identifier `_true' IdentAsKeyword.ice:90: illegal underscore in identifier `_true' +IdentAsKeyword.ice:92: illegal trailing underscore in identifier `b_' IdentAsKeyword.ice:92: illegal underscore in identifier `b_' -IdentAsKeyword.ice:93: illegal underscore in identifier `tr_ue' -IdentAsKeyword.ice:94: illegal underscore in identifier `tr_ue' +IdentAsKeyword.ice:94: illegal double underscore in identifier `b__c' +IdentAsKeyword.ice:94: illegal underscore in identifier `b__c' +IdentAsKeyword.ice:95: illegal double underscore in identifier `b___c' +IdentAsKeyword.ice:95: illegal underscore in identifier `b___c' +IdentAsKeyword.ice:97: illegal underscore in identifier `a_b' +IdentAsKeyword.ice:98: illegal underscore in identifier `a_b_c' diff --git a/cpp/test/Slice/errorDetection/IdentAsKeyword.ice b/cpp/test/Slice/errorDetection/IdentAsKeyword.ice index 96ddca99d11..30a5adbc1a7 100644 --- a/cpp/test/Slice/errorDetection/IdentAsKeyword.ice +++ b/cpp/test/Slice/errorDetection/IdentAsKeyword.ice @@ -89,8 +89,12 @@ interface _a; // Illegal leading underscore interface _true; // Illegal leading underscore interface \_true; // Illegal leading underscore -interface b_; // Illegal underscore -interface tr_ue; // Illegal underscore -interface \tr_ue; // Illegal underscore +interface b_; // Illegal trailing underscore + +interface b__c; // Illegal underscores +interface b___c; // Illegal underscores + +interface a_b; // Illegal underscore +interface a_b_c; // Illegal underscores }; diff --git a/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.err b/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.err new file mode 100644 index 00000000000..fde90f00e3e --- /dev/null +++ b/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.err @@ -0,0 +1,90 @@ +IdentAsKeywordUnderscore.ice:15: illegal identifier: `INTERFACE' differs from keyword `interface' only in capitalization +IdentAsKeywordUnderscore.ice:17: illegal identifier: `Void' differs from keyword `void' only in capitalization +IdentAsKeywordUnderscore.ice:17: keyword `void' cannot be used as exception name +IdentAsKeywordUnderscore.ice:18: keyword `int' cannot be used as exception name +IdentAsKeywordUnderscore.ice:20: illegal identifier: `OUT' differs from keyword `out' only in capitalization +IdentAsKeywordUnderscore.ice:20: keyword `out' cannot be used as struct name +IdentAsKeywordUnderscore.ice:21: keyword `double' cannot be used as struct name +IdentAsKeywordUnderscore.ice:23: illegal identifier: `Int' differs from keyword `int' only in capitalization +IdentAsKeywordUnderscore.ice:23: keyword `int' cannot be used as data member name +IdentAsKeywordUnderscore.ice:24: keyword `byte' cannot be used as data member name +IdentAsKeywordUnderscore.ice:25: illegal identifier: `Int' differs from keyword `int' only in capitalization +IdentAsKeywordUnderscore.ice:25: keyword `int' cannot be used as data member name +IdentAsKeywordUnderscore.ice:26: keyword `byte' cannot be used as data member name +IdentAsKeywordUnderscore.ice:28: illegal identifier: `inTERface' differs from keyword `interface' only in capitalization +IdentAsKeywordUnderscore.ice:28: keyword `interface' cannot be used as class name +IdentAsKeywordUnderscore.ice:29: keyword `interface' cannot be used as class name +IdentAsKeywordUnderscore.ice:31: illegal identifier: `MOdule' differs from keyword `module' only in capitalization +IdentAsKeywordUnderscore.ice:31: keyword `module' cannot be used as class name +IdentAsKeywordUnderscore.ice:32: keyword `module' cannot be used as class name +IdentAsKeywordUnderscore.ice:32: redefinition of class `module' +IdentAsKeywordUnderscore.ice:34: illegal identifier: `extendS' differs from keyword `extends' only in capitalization +IdentAsKeywordUnderscore.ice:34: keyword `extends' cannot be used as data member name +IdentAsKeywordUnderscore.ice:35: redefinition of class `C' +IdentAsKeywordUnderscore.ice:35: keyword `extends' cannot be used as data member name +IdentAsKeywordUnderscore.ice:36: keyword `extends' cannot be used as data member name +IdentAsKeywordUnderscore.ice:38: keyword `local' cannot be used as interface name +IdentAsKeywordUnderscore.ice:39: illegal identifier: `Local' differs from keyword `local' only in capitalization +IdentAsKeywordUnderscore.ice:39: keyword `local' cannot be used as interface name +IdentAsKeywordUnderscore.ice:41: keyword `Object' cannot be used as interface name +IdentAsKeywordUnderscore.ice:42: illegal identifier: `object' differs from keyword `Object' only in capitalization +IdentAsKeywordUnderscore.ice:42: keyword `Object' cannot be used as interface name +IdentAsKeywordUnderscore.ice:42: redefinition of interface `Object' +IdentAsKeywordUnderscore.ice:43: keyword `long' cannot be used as interface name +IdentAsKeywordUnderscore.ice:45: illegal identifier: `impLEments' differs from keyword `implements' only in capitalization +IdentAsKeywordUnderscore.ice:45: keyword `implements' cannot be used as sequence name +IdentAsKeywordUnderscore.ice:46: redefinition of sequence `implements' as sequence +IdentAsKeywordUnderscore.ice:46: keyword `implements' cannot be used as sequence name +IdentAsKeywordUnderscore.ice:47: keyword `short' cannot be used as sequence name +IdentAsKeywordUnderscore.ice:49: syntax error +IdentAsKeywordUnderscore.ice:50: illegal identifier: `moDule' differs from keyword `module' only in capitalization +IdentAsKeywordUnderscore.ice:50: syntax error +IdentAsKeywordUnderscore.ice:52: keyword `throws' cannot be used as dictionary name +IdentAsKeywordUnderscore.ice:53: illegal identifier: `thRows' differs from keyword `throws' only in capitalization +IdentAsKeywordUnderscore.ice:53: redefinition of dictionary `throws' as dictionary +IdentAsKeywordUnderscore.ice:53: keyword `throws' cannot be used as dictionary name +IdentAsKeywordUnderscore.ice:54: illegal identifier: `LOCALobject' differs from keyword `LocalObject' only in capitalization +IdentAsKeywordUnderscore.ice:54: keyword `LocalObject' cannot be used as dictionary name +IdentAsKeywordUnderscore.ice:56: syntax error +IdentAsKeywordUnderscore.ice:57: illegal identifier: `MODULE' differs from keyword `module' only in capitalization +IdentAsKeywordUnderscore.ice:57: syntax error +IdentAsKeywordUnderscore.ice:59: syntax error +IdentAsKeywordUnderscore.ice:60: illegal identifier: `OUT' differs from keyword `out' only in capitalization +IdentAsKeywordUnderscore.ice:60: syntax error +IdentAsKeywordUnderscore.ice:62: syntax error +IdentAsKeywordUnderscore.ice:63: illegal identifier: `VOID' differs from keyword `void' only in capitalization +IdentAsKeywordUnderscore.ice:63: syntax error +IdentAsKeywordUnderscore.ice:63: illegal identifier: `VOID' differs from keyword `void' only in capitalization +IdentAsKeywordUnderscore.ice:65: keyword `local' cannot be used as enumeration name +IdentAsKeywordUnderscore.ice:65: redefinition of interface `local' as enumeration +IdentAsKeywordUnderscore.ice:66: illegal identifier: `LOCAL' differs from keyword `local' only in capitalization +IdentAsKeywordUnderscore.ice:66: keyword `local' cannot be used as enumeration name +IdentAsKeywordUnderscore.ice:66: redefinition of interface `local' as enumeration +IdentAsKeywordUnderscore.ice:66: enumerator `c' differs only in capitalization from class `C' +IdentAsKeywordUnderscore.ice:68: keyword `long' cannot be used as enumerator +IdentAsKeywordUnderscore.ice:68: keyword `byte' cannot be used as enumerator +IdentAsKeywordUnderscore.ice:69: illegal identifier: `LONG' differs from keyword `long' only in capitalization +IdentAsKeywordUnderscore.ice:69: keyword `long' cannot be used as enumerator +IdentAsKeywordUnderscore.ice:69: illegal identifier: `BYTE' differs from keyword `byte' only in capitalization +IdentAsKeywordUnderscore.ice:69: keyword `byte' cannot be used as enumerator +IdentAsKeywordUnderscore.ice:71: keyword `module' cannot be used as operation name +IdentAsKeywordUnderscore.ice:72: illegal identifier: `mODule' differs from keyword `module' only in capitalization +IdentAsKeywordUnderscore.ice:72: keyword `module' cannot be used as operation name +IdentAsKeywordUnderscore.ice:74: keyword `exception' cannot be used as operation name +IdentAsKeywordUnderscore.ice:75: illegal identifier: `EXception' differs from keyword `exception' only in capitalization +IdentAsKeywordUnderscore.ice:75: keyword `exception' cannot be used as operation name +IdentAsKeywordUnderscore.ice:77: syntax error +IdentAsKeywordUnderscore.ice:78: illegal identifier: `OUT' differs from keyword `out' only in capitalization +IdentAsKeywordUnderscore.ice:78: syntax error +IdentAsKeywordUnderscore.ice:80: keyword `byte' cannot be used as parameter name +IdentAsKeywordUnderscore.ice:81: illegal identifier: `BYTE' differs from keyword `byte' only in capitalization +IdentAsKeywordUnderscore.ice:81: keyword `byte' cannot be used as parameter name +IdentAsKeywordUnderscore.ice:83: keyword `byte' cannot be used as parameter name +IdentAsKeywordUnderscore.ice:84: illegal identifier: `BYTE' differs from keyword `byte' only in capitalization +IdentAsKeywordUnderscore.ice:84: keyword `byte' cannot be used as parameter name +IdentAsKeywordUnderscore.ice:88: illegal leading underscore in identifier `_a' +IdentAsKeywordUnderscore.ice:89: illegal leading underscore in identifier `_true' +IdentAsKeywordUnderscore.ice:90: illegal leading underscore in identifier `_true' +IdentAsKeywordUnderscore.ice:92: illegal trailing underscore in identifier `b_' +IdentAsKeywordUnderscore.ice:94: illegal double underscore in identifier `b__c' +IdentAsKeywordUnderscore.ice:95: illegal double underscore in identifier `b___c' diff --git a/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.ice b/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.ice new file mode 100644 index 00000000000..e2fae525d29 --- /dev/null +++ b/cpp/test/Slice/errorDetection/IdentAsKeywordUnderscore.ice @@ -0,0 +1,100 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + + + +module Test +{ + +INTERFACE i { void op(); }; + +exception Void {}; +exception int {}; + +struct OUT { long l; }; +struct double { long l; }; + +struct s1 { long Int; }; +struct s2 { long byte; }; +struct s3 { short Int; byte b; }; +struct s4 { float byte; byte b; }; + +class inTERface; +class interface; + +class MOdule { long l; }; +class module { long l; }; + +class C { long extendS; }; +class C { long extends; }; +class D { long extends; }; + +interface local; +interface Local; + +interface Object { void op(); }; +interface object { void op(); }; +interface long { void op(); }; + +sequence<long> impLEments; +sequence<long> implements; +sequence<long> short; + +sequence<module> seq1; +sequence<moDule> seq2; + +dictionary<long, long> throws; +dictionary<long, long> thRows; +dictionary<long, long> LOCALobject; + +dictionary<module, long> d1; +dictionary<MODULE, long> d2; + +dictionary<long, out> d3; +dictionary<long, OUT> d4; + +dictionary<void, void> d5; +dictionary<VOID, VOID> d6; + +enum local { a, b }; +enum LOCAL { c, e }; + +enum e1 { long, byte, foo }; +enum e2 { LONG, BYTE, bar }; + +interface i1 { long module(); }; +interface i2 { long mODule(); }; + +interface i3 { void exception(); }; +interface i4 { void EXception(); }; + +interface i5 { out op(); }; +interface i6 { OUT op(); }; + +interface i7 { void op(double byte); }; +interface i8 { void op(double BYTE); }; + +interface i9 { void op(out double byte); }; +interface i10 { void op(out double BYTE); }; + +interface \true {}; // OK, escaped keyword + +interface _a; // Illegal leading underscore +interface _true; // Illegal leading underscore +interface \_true; // Illegal leading underscore + +interface b_; // Illegal trailing underscore + +interface b__c; // Illegal underscores +interface b___c; // Illegal underscores + +interface a_b; // OK +interface a_b_c; // OK + +}; diff --git a/cpp/test/Slice/errorDetection/run.py b/cpp/test/Slice/errorDetection/run.py index 1db53e1ff4a..02768f08a44 100755 --- a/cpp/test/Slice/errorDetection/run.py +++ b/cpp/test/Slice/errorDetection/run.py @@ -33,7 +33,11 @@ files.sort() for file in files: print file + "...", - command = slice2cpp + ' -I. "%s"' % os.path.join(os.getcwd(), file) + + if file.find("Underscore") != -1: + command = slice2cpp + ' --underscore -I. "%s"' % os.path.join(os.getcwd(), file) + else: + command = slice2cpp + ' -I. "%s"' % os.path.join(os.getcwd(), file) p = TestUtil.runCommand(command) (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr) diff --git a/cpp/test/Slice/keyword/Client.cpp b/cpp/test/Slice/keyword/Client.cpp index 40cbeef1125..40e30d4c3ca 100644 --- a/cpp/test/Slice/keyword/Client.cpp +++ b/cpp/test/Slice/keyword/Client.cpp @@ -121,6 +121,8 @@ testtypes() const int m = _cpp_and::_cpp_template; test(m == _cpp_and::_cpp_template); + + test(_cpp_and::_cpp_xor_eq == 0); } int diff --git a/cpp/test/Slice/keyword/Key.ice b/cpp/test/Slice/keyword/Key.ice index 5a532ad297b..28c1ea2f3b1 100644 --- a/cpp/test/Slice/keyword/Key.ice +++ b/cpp/test/Slice/keyword/Key.ice @@ -78,5 +78,6 @@ const int using = 0; const int virtual = 0; const int while = 0; const int xor = 0; +const int xor_eq = 0; }; diff --git a/cpp/test/Slice/keyword/Makefile b/cpp/test/Slice/keyword/Makefile index c1a43b8c423..a160b7620eb 100644 --- a/cpp/test/Slice/keyword/Makefile +++ b/cpp/test/Slice/keyword/Makefile @@ -23,7 +23,7 @@ SLICE_SRCS = Key.ice include $(top_srcdir)/config/Make.rules CPPFLAGS := -I. -I../../include $(CPPFLAGS) -SLICE2CPPFLAGS := --stream $(SLICE2CPPFLAGS) +SLICE2CPPFLAGS := --underscore --stream $(SLICE2CPPFLAGS) $(CLIENT): $(COBJS) rm -f $@ diff --git a/cpp/test/Slice/keyword/Makefile.mak b/cpp/test/Slice/keyword/Makefile.mak index 3c0c5a1f477..a3a66bcd9ef 100644 --- a/cpp/test/Slice/keyword/Makefile.mak +++ b/cpp/test/Slice/keyword/Makefile.mak @@ -21,7 +21,7 @@ SRCS = $(COBJS:.obj=.cpp) !include $(top_srcdir)/config/Make.rules.mak
CPPFLAGS = -I. -I../../include $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN
-SLICE2CPPFLAGS = --stream $(SLICE2CPPFLAGS)
+SLICE2CPPFLAGS = --underscore --stream $(SLICE2CPPFLAGS)
!if "$(GENERATE_PDB)" == "yes"
CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb)
|