diff options
author | Marc Laukien <marc@zeroc.com> | 2002-03-14 20:14:23 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-03-14 20:14:23 +0000 |
commit | 6381bda7e291f33ae52d71420de6b1758f3c283f (patch) | |
tree | 0b64c9c1e80e30d9847488f7474af0754a71421f /cpp/src/Slice/Parser.cpp | |
parent | Style snafu. (diff) | |
download | ice-6381bda7e291f33ae52d71420de6b1758f3c283f.tar.bz2 ice-6381bda7e291f33ae52d71420de6b1758f3c283f.tar.xz ice-6381bda7e291f33ae52d71420de6b1758f3c283f.zip |
proxy lookup fix
Diffstat (limited to 'cpp/src/Slice/Parser.cpp')
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 147 |
1 files changed, 113 insertions, 34 deletions
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index 3108638b59b..156a44a2c94 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -552,6 +552,19 @@ Slice::Container::createEnumerator(const string& name) TypeList Slice::Container::lookupType(const string& scoped, bool printError) { + // + // Remove whitespace. + // + string sc = scoped; + string::size_type pos; + while((pos = sc.find_first_of(" \t\r\n")) != string::npos) + { + sc.erase(pos, 1); + } + + // + // Check for builtin type. + // static const char* builtinTable[] = { "byte", @@ -569,7 +582,7 @@ Slice::Container::lookupType(const string& scoped, bool printError) for (unsigned int i = 0; i < sizeof(builtinTable) / sizeof(const char*); ++i) { - if (scoped == builtinTable[i]) + if (sc == builtinTable[i]) { TypeList result; result.push_back(_unit->builtin(static_cast<Builtin::Kind>(i))); @@ -577,37 +590,69 @@ Slice::Container::lookupType(const string& scoped, bool printError) } } + // + // Not a builtin type, try to look up a constructed type. + // return lookupTypeNoBuiltin(scoped, printError); } TypeList Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) { - if (scoped.size() >= 2 && scoped[0] == ':') + // + // Remove whitespace. + // + string sc = scoped; + string::size_type pos; + while((pos = sc.find_first_of(" \t\r\n")) != string::npos) { - return _unit->lookupTypeNoBuiltin(scoped.substr(2), printError); + sc.erase(pos, 1); } - - ContainedList matches = _unit->findContents(thisScope() + scoped); - if (matches.empty()) + + // + // Absolute scoped name? + // + if (sc.size() >= 2 && sc[0] == ':') { - ContainedPtr contained = ContainedPtr::dynamicCast(this); - if (!contained) + return _unit->lookupTypeNoBuiltin(sc.substr(2), printError); + } + + TypeList results; + if (sc.rfind('*') == sc.length() - 1) + { + // + // Proxies. + // + ContainedList matches = _unit->findContents(thisScope() + sc.substr(0, sc.length() - 1)); + for (ContainedList::const_iterator p = matches.begin(); p != matches.end(); ++p) { - if (printError) + ClassDefPtr def = ClassDefPtr::dynamicCast(*p); + if (def) { - string msg = "`"; - msg += scoped; - msg += "' is not defined"; - _unit->error(msg); + continue; // Ignore class definitions } - return TypeList(); + + ClassDeclPtr cl = ClassDeclPtr::dynamicCast(*p); + if (!cl) + { + if (printError) + { + string msg = "`"; + msg += sc; + msg += "' must be class or interface"; + _unit->error(msg); + } + return TypeList(); + } + results.push_back(new Proxy(cl)); } - return contained->container()->lookupTypeNoBuiltin(scoped, printError); } else { - TypeList results; + // + // Non-Proxies. + // + ContainedList matches = _unit->findContents(thisScope() + sc); for (ContainedList::const_iterator p = matches.begin(); p != matches.end(); ++p) { ClassDefPtr def = ClassDefPtr::dynamicCast(*p); @@ -615,27 +660,27 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) { continue; // Ignore class definitions } - + ExceptionPtr ex = ExceptionPtr::dynamicCast(*p); if (ex) { if (printError) { string msg = "`"; - msg += scoped; + msg += sc; msg += "' is an exception, which cannot be used as a type"; _unit->error(msg); } return TypeList(); } - + TypePtr type = TypePtr::dynamicCast(*p); if (!type) { if (printError) { string msg = "`"; - msg += scoped; + msg += sc; msg += "' is not a type"; _unit->error(msg); } @@ -643,6 +688,26 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) } results.push_back(type); } + } + + if (results.empty()) + { + ContainedPtr contained = ContainedPtr::dynamicCast(this); + if (!contained) + { + if (printError) + { + string msg = "`"; + msg += sc; + msg += "' is not defined"; + _unit->error(msg); + } + return TypeList(); + } + return contained->container()->lookupTypeNoBuiltin(sc, printError); + } + else + { return results; } } @@ -650,13 +715,35 @@ Slice::Container::lookupTypeNoBuiltin(const string& scoped, bool printError) ContainedList Slice::Container::lookupContained(const string& scoped, bool printError) { - if (scoped.size() >= 2 && scoped[0] == ':') + // + // Remove whitespace. + // + string sc = scoped; + string::size_type pos; + while((pos = sc.find_first_of(" \t\r\n")) != string::npos) + { + sc.erase(pos, 1); + } + + // + // Absolute scoped name? + // + if (sc.size() >= 2 && sc[0] == ':') { - return _unit->lookupContained(scoped.substr(2), printError); + return _unit->lookupContained(sc.substr(2), printError); } - ContainedList matches = _unit->findContents(thisScope() + scoped); - if (matches.empty()) + ContainedList matches = _unit->findContents(thisScope() + sc); + ContainedList results; + for (ContainedList::const_iterator p = matches.begin(); p != matches.end(); ++p) + { + if (!ClassDefPtr::dynamicCast(*p)) // Ignore class definitions + { + results.push_back(*p); + } + } + + if (results.empty()) { ContainedPtr contained = ContainedPtr::dynamicCast(this); if (!contained) @@ -664,24 +751,16 @@ Slice::Container::lookupContained(const string& scoped, bool printError) if (printError) { string msg = "`"; - msg += scoped; + msg += sc; msg += "' is not defined"; _unit->error(msg); } return ContainedList(); } - return contained->container()->lookupContained(scoped, printError); + return contained->container()->lookupContained(sc, printError); } else { - ContainedList results; - for (ContainedList::const_iterator p = matches.begin(); p != matches.end(); ++p) - { - if (!ClassDefPtr::dynamicCast(*p)) // Ignore class definitions - { - results.push_back(*p); - } - } return results; } } |