diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/GrammarUtil.h | 49 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 40 | ||||
-rw-r--r-- | cpp/src/Slice/Scanner.l | 117 |
3 files changed, 118 insertions, 88 deletions
diff --git a/cpp/src/Slice/GrammarUtil.h b/cpp/src/Slice/GrammarUtil.h index 889ad02d797..591fa976eed 100644 --- a/cpp/src/Slice/GrammarUtil.h +++ b/cpp/src/Slice/GrammarUtil.h @@ -17,55 +17,6 @@ namespace Slice { -// TODO: ML: Consider moving to Scanner.l, as it is only used there. -// -// Function object to do case-insensitive string comparison. -// -struct CICompare : public std::binary_function<std::string, std::string, bool> -{ - // TODO: ML: Make non-inline. (Not necessary if moved to Scanner.l) - bool operator()(const std::string& s1, const std::string& s2) const - { - std::string::const_iterator p1 = s1.begin(); - std::string::const_iterator p2 = s2.begin(); - while(p1 != s1.end() && p2 != s2.end() && tolower(*p1) == tolower(*p2)) - { - ++p1; - ++p2; - } - if(p1 == s1.end() && p2 == s2.end()) - { - return false; - } - else if(p1 == s1.end()) - { - return true; - } - else if(p2 == s2.end()) - { - return false; - } - else - { - return tolower(*p1) < tolower(*p2); - } - } -}; - -// -// Definitions for the case-insensitive keyword-token map. -// -// TODO: ML: Naming conventions for types. (Should be StringTokenMap.) -// TODO: ML: Consider moving to Scanner.l, as it is only used there. Then keywordMap can also be static. -typedef std::map<std::string, int, CICompare> stringTokenMap; -extern stringTokenMap keywordMap; - -// -// initialize() fills the keyword map with all keyword-token pairs. -// -// TODO: ML: Perhaps initializeKeywordMap() would be a better name? -void initialize(); - class StringTok; class StringListTok; class TypeStringTok; diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index d42a0b000b2..838a56c338e 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -731,6 +731,15 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) continue; // Ignore class definitions } + if(printError && matches.front()->name() != sc) + { + string msg; + msg = "type name `" + sc; + msg += "' is capitalized inconsistently with its previous name: `"; + msg += matches.front()->scoped() + "'"; + _unit->warning(msg); // TODO: change to error in stable_39 + } + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); if(!cl) { @@ -760,6 +769,15 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) continue; // Ignore class definitions } + if(printError && matches.front()->name() != sc) + { + string msg; + msg = "type name `" + sc + "' is capitalized inconsistently with its previous name: `"; + msg += matches.front()->scoped() + "'"; + _unit->warning(msg); // TODO: change to error in stable_39 + } + + ExceptionPtr ex = ExceptionPtr::dynamicCast(*p); if(ex) { @@ -839,7 +857,16 @@ Slice::Container::lookupContained(const string& scoped, bool printError) if(!ClassDefPtr::dynamicCast(*p)) // Ignore class definitions { results.push_back(*p); + + if(printError && (*p)->name() != sc) + { + string msg; + msg = "`" + sc + "' is capitalized inconsistently with its previous name: `"; + msg += (*p)->scoped() + "'"; + _unit->warning(msg); // TODO: change to error in stable_39 + } } + } if(results.empty()) @@ -867,7 +894,7 @@ Slice::Container::lookupContained(const string& scoped, bool printError) ExceptionPtr Slice::Container::lookupException(const string& scoped, bool printError) { - ContainedList contained = lookupContained(scoped, printError); + ContainedList contained = lookupContained(scoped, false); if(contained.empty()) { return 0; @@ -888,6 +915,13 @@ Slice::Container::lookupException(const string& scoped, bool printError) } return 0; } + if(printError && (*p)->name() != scoped) + { + string msg; + msg = "exception name `" + scoped + "' is capitalized inconsistently with its previous name: `"; + msg += (*p)->scoped() + "'"; + _unit->warning(msg); // TODO: change to error in stable_39 + } exceptions.push_back(ex); } assert(exceptions.size() == 1); @@ -2819,7 +2853,7 @@ Slice::Unit::currentIncludeLevel() const void Slice::Unit::error(const char* s) { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; + cout << _currentFile << ':' << _currentLine << ": " << s << endl; _errors++; } @@ -2832,7 +2866,7 @@ Slice::Unit::error(const string& s) void Slice::Unit::warning(const char* s) const { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; + cout << _currentFile << ':' << _currentLine << ": warning: " << s << endl; } void diff --git a/cpp/src/Slice/Scanner.l b/cpp/src/Slice/Scanner.l index 41ef43b0f6f..f37fbc5a00b 100644 --- a/cpp/src/Slice/Scanner.l +++ b/cpp/src/Slice/Scanner.l @@ -16,7 +16,53 @@ using namespace std; using namespace Slice; -#define YY_USER_INIT initialize(); +namespace Slice +{ + +// +// Function object to do case-insensitive string comparison. +// +struct CICompare : public std::binary_function<std::string, std::string, bool> +{ + bool operator()(const std::string& s1, const std::string& s2) const + { + std::string::const_iterator p1 = s1.begin(); + std::string::const_iterator p2 = s2.begin(); + while(p1 != s1.end() && p2 != s2.end() && tolower(*p1) == tolower(*p2)) + { + ++p1; + ++p2; + } + if(p1 == s1.end() && p2 == s2.end()) + { + return false; + } + else if(p1 == s1.end()) + { + return true; + } + else if(p2 == s2.end()) + { + return false; + } + else + { + return tolower(*p1) < tolower(*p2); + } + } +}; + +// +// Definitions for the case-insensitive keyword-token map. +// +typedef std::map<std::string, int, CICompare> StringTokenMap; +static StringTokenMap keywordMap; + +void Slice::initScanner(); + +} + +#define YY_USER_INIT initScanner(); %} @@ -111,17 +157,16 @@ using namespace Slice; } *yylvalp = ident; - stringTokenMap::const_iterator pos = keywordMap.find(ident->v); + StringTokenMap::const_iterator pos = keywordMap.find(ident->v); if(pos != keywordMap.end()) { if(pos->first != ident->v) { -// TODO: ML: Indentation. - string msg; - msg = "illegal identifier: `" + ident->v + "' differs from keyword `"; - msg += pos->first + "' only in capitalization"; - unit->error(msg); - ident->v = pos->first; + string msg; + msg = "illegal identifier: `" + ident->v + "' differs from keyword `"; + msg += pos->first + "' only in capitalization"; + unit->error(msg); + ident->v = pos->first; } return pos->second; } @@ -250,39 +295,39 @@ using namespace Slice; %% -// TODO: ML: Coding conventions. namespace Slice { -stringTokenMap keywordMap; +// +// initScanner() fills the keyword map with all keyword-token pairs. +// void -initialize() +initScanner() { -// TODO: ML: Indentation is 4 char positions, not 8. - keywordMap["module"] = ICE_MODULE; - keywordMap["class"] = ICE_CLASS; - keywordMap["interface"] = ICE_INTERFACE; - keywordMap["exception"] = ICE_EXCEPTION; - keywordMap["struct"] = ICE_STRUCT; - keywordMap["sequence"] = ICE_SEQUENCE; - keywordMap["dictionary"] = ICE_DICTIONARY; - keywordMap["enum"] = ICE_ENUM; - keywordMap["out"] = ICE_OUT; - keywordMap["extends"] = ICE_EXTENDS; - keywordMap["implements"] = ICE_IMPLEMENTS; - keywordMap["throws"] = ICE_THROWS; - keywordMap["void"] = ICE_VOID; - keywordMap["byte"] = ICE_BYTE; - keywordMap["bool"] = ICE_BOOL; - keywordMap["short"] = ICE_SHORT; - keywordMap["int"] = ICE_INT; - keywordMap["long"] = ICE_LONG; - keywordMap["float"] = ICE_FLOAT; - keywordMap["double"] = ICE_DOUBLE; - keywordMap["string"] = ICE_STRING; - keywordMap["Object"] = ICE_OBJECT; - keywordMap["LocalObject"] = ICE_LOCAL_OBJECT; - keywordMap["local"] = ICE_LOCAL; + keywordMap["module"] = ICE_MODULE; + keywordMap["class"] = ICE_CLASS; + keywordMap["interface"] = ICE_INTERFACE; + keywordMap["exception"] = ICE_EXCEPTION; + keywordMap["struct"] = ICE_STRUCT; + keywordMap["sequence"] = ICE_SEQUENCE; + keywordMap["dictionary"] = ICE_DICTIONARY; + keywordMap["enum"] = ICE_ENUM; + keywordMap["out"] = ICE_OUT; + keywordMap["extends"] = ICE_EXTENDS; + keywordMap["implements"] = ICE_IMPLEMENTS; + keywordMap["throws"] = ICE_THROWS; + keywordMap["void"] = ICE_VOID; + keywordMap["byte"] = ICE_BYTE; + keywordMap["bool"] = ICE_BOOL; + keywordMap["short"] = ICE_SHORT; + keywordMap["int"] = ICE_INT; + keywordMap["long"] = ICE_LONG; + keywordMap["float"] = ICE_FLOAT; + keywordMap["double"] = ICE_DOUBLE; + keywordMap["string"] = ICE_STRING; + keywordMap["Object"] = ICE_OBJECT; + keywordMap["LocalObject"] = ICE_LOCAL_OBJECT; + keywordMap["local"] = ICE_LOCAL; } } |