[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Sat Sep 3 09:59:14 UTC 2005
SVN commit 456812 by okellogg:
NativeImportBase::preprocess(): Handle C style multi-line comments.
Languages that don't want it can just reimplement the method.
M +4 -0 adaimport.cpp
M +6 -0 adaimport.h
M +1 -52 idlimport.cpp
M +1 -2 idlimport.h
M +53 -3 nativeimportbase.cpp
M +7 -1 nativeimportbase.h
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/adaimport.cpp #456811:456812
@@ -35,6 +35,10 @@
AdaImport::~AdaImport() {
}
+bool AdaImport::preprocess(QString&) {
+ return false;
+}
+
void AdaImport::fillSource(QString word) {
QString lexeme;
const uint len = word.length();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/adaimport.h #456811:456812
@@ -34,6 +34,12 @@
*/
void fillSource(QString word);
+ /**
+ * Reimplement operation from NativeImportBase to be a no-op.
+ * Ada does not require preprocessing.
+ */
+ bool preprocess(QString& line);
+
};
#endif
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/idlimport.cpp #456811:456812
@@ -31,7 +31,6 @@
IDLImport::IDLImport() : NativeImportBase("//") {
m_isOneway = m_isReadonly = m_isAttribute = false;
- m_inComment = false;
}
IDLImport::~IDLImport() {
@@ -52,57 +51,7 @@
// Ignore C preprocessor generated lines.
if (line.startsWith("#"))
return true; // done
- // Check for end of multi line comment.
- if (m_inComment) {
- int pos = line.find("*/");
- if (pos == -1) {
- m_comment += line + "\n";
- return true; // done
- }
- if (pos > 0) {
- QString text = line.mid(0, pos - 1);
- m_comment += text.stripWhiteSpace();
- }
- m_source.append(m_singleLineCommentIntro + m_comment); // denotes comments in `m_source'
- m_comment = "";
- m_inComment = false;
- pos++; // pos now points at the slash in the "*/"
- if (pos == (int)line.length() - 1)
- return true; // done
- line = line.mid(pos + 1);
- }
- // If we get here then m_inComment is false.
- // Check for start of multi line comment.
- int pos = line.find("/*");
- if (pos != -1) {
- int endpos = line.find("*/");
- if (endpos == -1) {
- m_inComment = true;
- if (pos + 1 < (int)line.length() - 1) {
- QString cmnt = line.mid(pos + 2);
- m_comment += cmnt.stripWhiteSpace() + "\n";
- }
- if (pos == 0)
- return true; // done
- line = line.left(pos);
- } else { // It's a multiline comment on a single line.
- if (endpos > pos + 2) {
- QString cmnt = line.mid(pos + 2, endpos - pos - 2);
- cmnt = cmnt.stripWhiteSpace();
- if (!cmnt.isEmpty())
- m_source.append(m_singleLineCommentIntro + cmnt);
- }
- endpos++; // endpos now points at the slash of "*/"
- QString pre;
- if (pos > 0)
- pre = line.left(pos);
- QString post;
- if (endpos < (int)line.length() - 1)
- post = line.mid(endpos + 1);
- line = pre + post;
- }
- }
- return false; // The input was not completely consumed by preprocessing.
+ return NativeImportBase::preprocess(line);
}
void IDLImport::fillSource(QString word) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/idlimport.h #456811:456812
@@ -30,7 +30,7 @@
void parseFile(QString file);
/**
- * Implement abstract operation from NativeImportBase.
+ * Override operation from NativeImportBase.
*/
bool preprocess(QString& line);
@@ -42,7 +42,6 @@
protected:
QString joinTypename();
bool m_isOneway, m_isReadonly, m_isAttribute;
- bool m_inComment;
};
#endif
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/nativeimportbase.cpp #456811:456812
@@ -28,6 +28,7 @@
m_klass = NULL;
m_currentAccess = Uml::Public;
m_isAbstract = false;
+ m_inComment = false;
}
NativeImportBase::~NativeImportBase() {
@@ -54,9 +55,58 @@
return m_source[m_srcIndex];
}
-bool NativeImportBase::preprocess(QString&) {
- // The default is that no preprocessing is needed.
- return false; // The return value indicates that we are not done yet.
+bool NativeImportBase::preprocess(QString& line) {
+ // Check for end of multi line comment.
+ if (m_inComment) {
+ int pos = line.find("*/");
+ if (pos == -1) {
+ m_comment += line + "\n";
+ return true; // done
+ }
+ if (pos > 0) {
+ QString text = line.mid(0, pos - 1);
+ m_comment += text.stripWhiteSpace();
+ }
+ m_source.append(m_singleLineCommentIntro + m_comment); // denotes comments in `m_source'
+ m_comment = "";
+ m_inComment = false;
+ pos++; // pos now points at the slash in the "*/"
+ if (pos == (int)line.length() - 1)
+ return true; // done
+ line = line.mid(pos + 1);
+ }
+ // If we get here then m_inComment is false.
+ // Check for start of multi line comment.
+ int pos = line.find("/*");
+ if (pos != -1) {
+ int endpos = line.find("*/");
+ if (endpos == -1) {
+ m_inComment = true;
+ if (pos + 1 < (int)line.length() - 1) {
+ QString cmnt = line.mid(pos + 2);
+ m_comment += cmnt.stripWhiteSpace() + "\n";
+ }
+ if (pos == 0)
+ return true; // done
+ line = line.left(pos);
+ } else { // It's a multiline comment on a single line.
+ if (endpos > pos + 2) {
+ QString cmnt = line.mid(pos + 2, endpos - pos - 2);
+ cmnt = cmnt.stripWhiteSpace();
+ if (!cmnt.isEmpty())
+ m_source.append(m_singleLineCommentIntro + cmnt);
+ }
+ endpos++; // endpos now points at the slash of "*/"
+ QString pre;
+ if (pos > 0)
+ pre = line.left(pos);
+ QString post;
+ if (endpos < (int)line.length() - 1)
+ post = line.mid(endpos + 1);
+ line = pre + post;
+ }
+ }
+ return false; // The input was not completely consumed by preprocessing.
}
/// The lexer. Tokenizes the given string and fills `m_source'.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/nativeimportbase.h #456811:456812
@@ -64,7 +64,8 @@
* Preprocess a line.
* May modify the given line to remove items consumed by the
* preprocessing such as comments or preprocessor directives.
- * The default implementation is a no-op.
+ * The default implementation handles C style multi-line comments
+ * (slash-star, star-slash.)
*
* @param line The line to preprocess.
* @return True if the line was completely consumed,
@@ -129,6 +130,11 @@
*/
QString m_comment;
/**
+ * True if we are currently in a multi-line comment.
+ * Only applies to languages with multi-line comments.
+ */
+ bool m_inComment;
+ /**
* Accumulator for abstractness
*/
bool m_isAbstract;
More information about the umbrello-devel
mailing list