summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Parser.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2005-12-19 05:55:19 +0000
committerMichi Henning <michi@zeroc.com>2005-12-19 05:55:19 +0000
commit7b804228ffedba327b7c3c632d5973f9687e48e4 (patch)
treed0173e97caa65ec954dc85b8b5593a834d76a8de /cpp/src/Slice/Parser.cpp
parentBacked out previous check-in, which happened by mistake. (diff)
downloadice-7b804228ffedba327b7c3c632d5973f9687e48e4.tar.bz2
ice-7b804228ffedba327b7c3c632d5973f9687e48e4.tar.xz
ice-7b804228ffedba327b7c3c632d5973f9687e48e4.zip
Fixed bug 666.
Diffstat (limited to 'cpp/src/Slice/Parser.cpp')
-rw-r--r--cpp/src/Slice/Parser.cpp125
1 files changed, 83 insertions, 42 deletions
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index b9ac3797d14..ac1fc25948e 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -4736,78 +4736,104 @@ Slice::Unit::scanPosition(const char* s)
{
assert(*s == '#');
- const char* p = s + 1; // Skip leading #
- while(isspace(*p))
+ string line(s + 1); // Skip leading #
+ eraseWhiteSpace(line);
+ if(line.find("line", 0) == 0) // Erase optional "line"
{
- ++p;
- }
- if(strncmp(p, "line", 4) == 0)
- {
- p += 4;
+ line.erase(0, 4);
+ eraseWhiteSpace(line);
}
- string line(p);
string::size_type idx;
- idx = line.find_first_not_of(" \t\r#");
+ _currentLine = atoi(line.c_str()) - 1; // Read line number
+
+ idx = line.find_first_of(" \t\r"); // Erase line number
if(idx != string::npos)
{
line.erase(0, idx);
}
+ eraseWhiteSpace(line);
- _currentLine = atoi(line.c_str()) - 1;
+ //
+ // If the string ends in <whitespace>1 or <whitespace>2, it is a push or pop directive.
+ //
+ enum LineType { File, Push, Pop };
- idx = line.find_first_of(" \t\r");
- if(idx != string::npos)
- {
- line.erase(0, idx);
- }
+ LineType type;
- idx = line.find_first_not_of(" \t\r\"");
+ idx = line.find_last_of(" \t\r");
if(idx != string::npos)
{
- line.erase(0, idx);
+ ++idx;
+ if(line.substr(idx) == "1")
+ {
+ type = Push;
+ line.erase(idx);
+ eraseWhiteSpace(line);
- string currentFile;
+ }
+ else if(line.substr(idx) == "2")
+ {
+ type = Pop;
+ line.erase(idx);
+ eraseWhiteSpace(line);
+ }
+ }
+ else
+ {
+ type = File;
+ }
- idx = line.find_first_of(" \t\r\"");
- if(idx != string::npos)
+ string currentFile;
+ if(!line.empty())
+ {
+ if(line[0] == '"')
{
- currentFile = line.substr(0, idx);
- line.erase(0, idx + 1);
+ idx = line.rfind('"');
+ if(idx != string::npos)
+ {
+ currentFile = line.substr(1, idx - 1);
+ }
}
else
{
currentFile = line;
}
+ }
- idx = line.find_first_not_of(" \t\r");
- if(idx != string::npos)
+ switch(type)
+ {
+ case Push:
{
- line.erase(0, idx);
- int val = atoi(line.c_str());
- if(val == 1)
+ if(++_currentIncludeLevel == 1)
{
- if(++_currentIncludeLevel == 1)
+ if(find(_includeFiles.begin(), _includeFiles.end(), currentFile) == _includeFiles.end())
{
- if(find(_includeFiles.begin(), _includeFiles.end(), currentFile) == _includeFiles.end())
- {
- _includeFiles.push_back(currentFile);
- }
+ _includeFiles.push_back(currentFile);
}
- pushDefinitionContext();
- }
- else if(val == 2)
- {
- --_currentIncludeLevel;
- popDefinitionContext();
}
+ pushDefinitionContext();
_currentComment = "";
+ break;
+ }
+ case Pop:
+ {
+ --_currentIncludeLevel;
+ popDefinitionContext();
+ _currentComment = "";
+ break;
+ }
+ default:
+ {
+ break; // Do nothing
}
-
- DefinitionContextPtr dc = currentDefinitionContext();
- assert(dc);
- dc->setFilename(currentFile);
+ }
+ if(!currentFile.empty())
+ {
+ DefinitionContextPtr dc = currentDefinitionContext();
+ assert(dc);
+ dc->setFilename(currentFile);
}
}
@@ -5228,6 +5254,21 @@ Slice::Unit::Unit(bool ignRedefs, bool all, bool allowIcePrefix, bool caseSensit
_unit = this;
}
+void
+Slice::Unit::eraseWhiteSpace(string& s)
+{
+ string::size_type idx = s.find_first_not_of(" \t\r");
+ if(idx != string::npos)
+ {
+ s.erase(0, idx);
+ }
+ idx = s.find_last_not_of(" \t\r");
+ if(idx != string::npos)
+ {
+ s.erase(++idx);
+ }
+}
+
// ----------------------------------------------------------------------
// CICompare
// ----------------------------------------------------------------------