aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/glsleditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2017-05-05 20:34:29 +0200
committerEike Ziller <eike.ziller@qt.io>2017-05-23 07:47:22 +0000
commitcf57965ebc8ec913a2b2fafe352ddae3f7706b98 (patch)
tree8e793cc8ed288fe1f3156a87613e18a7e6709bf3 /src/plugins/glsleditor
parent762f67f729ea01d21cb23646da69cbce89958789 (diff)
Simplify text format handling in syntax highlighters
Pass the mapping from custom enum to text style in form of a function, which then can use a switch which is checked by compilers, and avoids the need to lookup a different enum somewhere else to find out what the mapping actually is. That mapping is cached to keep performance as before. Also, most highlighters created an enum just for the purpose of mapping to text styles, basically creating duplicated subsets of text style like enums everywhere. Instead provide a default, identity mapping from text styles to text styles. Change-Id: I2ea1ca702b99e36b8742dfda510b1b2753f0a1c2 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/glsleditor')
-rw-r--r--src/plugins/glsleditor/glslhighlighter.cpp34
-rw-r--r--src/plugins/glsleditor/glslhighlighter.h16
2 files changed, 11 insertions, 39 deletions
diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp
index 23f9c9d550..1faf60d2c0 100644
--- a/src/plugins/glsleditor/glslhighlighter.cpp
+++ b/src/plugins/glsleditor/glslhighlighter.cpp
@@ -34,26 +34,14 @@
using namespace TextEditor;
+const TextStyle GLSLReservedKeyword = C_REMOVED_LINE;
+
namespace GlslEditor {
namespace Internal {
GlslHighlighter::GlslHighlighter()
{
- static const QVector<TextStyle> categories({
- C_NUMBER,
- C_STRING,
- C_TYPE,
- C_KEYWORD,
- C_OPERATOR,
- C_PREPROCESSOR,
- C_LABEL,
- C_COMMENT,
- C_DOXYGEN_COMMENT,
- C_DOXYGEN_TAG,
- C_VISUAL_WHITESPACE,
- C_REMOVED_LINE
- });
- setTextFormatCategories(categories);
+ setDefaultTextFormatCategories();
}
void GlslHighlighter::highlightBlock(const QString &text)
@@ -99,7 +87,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
setCurrentBlockState(previousState);
TextDocumentLayout::clearParentheses(currentBlock());
if (text.length()) // the empty line can still contain whitespace
- setFormat(0, text.length(), formatForCategory(GLSLVisualWhitespace));
+ setFormat(0, text.length(), formatForCategory(C_VISUAL_WHITESPACE));
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
return;
}
@@ -123,7 +111,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
if (previousTokenEnd != tk.begin()) {
setFormat(previousTokenEnd, tk.begin() - previousTokenEnd,
- formatForCategory(GLSLVisualWhitespace));
+ formatForCategory(C_VISUAL_WHITESPACE));
}
if (tk.is(GLSL::Parser::T_LEFT_PAREN) || tk.is(GLSL::Parser::T_LEFT_BRACE) || tk.is(GLSL::Parser::T_LEFT_BRACKET)) {
@@ -160,17 +148,17 @@ void GlslHighlighter::highlightBlock(const QString &text)
highlightAsPreprocessor = false;
if (false /* && i == 0 && tk.is(GLSL::Parser::T_POUND)*/) {
- highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
+ highlightLine(text, tk.begin(), tk.length, formatForCategory(C_PREPROCESSOR));
highlightAsPreprocessor = true;
} else if (highlightCurrentWordAsPreprocessor && isPPKeyword(text.midRef(tk.begin(), tk.length))) {
- setFormat(tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
+ setFormat(tk.begin(), tk.length, formatForCategory(C_PREPROCESSOR));
} else if (tk.is(GLSL::Parser::T_NUMBER)) {
- setFormat(tk.begin(), tk.length, formatForCategory(GLSLNumberFormat));
+ setFormat(tk.begin(), tk.length, formatForCategory(C_NUMBER));
} else if (tk.is(GLSL::Parser::T_COMMENT)) {
- highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLCommentFormat));
+ highlightLine(text, tk.begin(), tk.length, formatForCategory(C_COMMENT));
// we need to insert a close comment parenthesis, if
// - the line starts in a C Comment (initalState != 0)
@@ -195,7 +183,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
if (kind == GLSL::Parser::T_RESERVED)
setFormat(tk.position, tk.length, formatForCategory(GLSLReservedKeyword));
else if (kind != GLSL::Parser::T_IDENTIFIER)
- setFormat(tk.position, tk.length, formatForCategory(GLSLKeywordFormat));
+ setFormat(tk.position, tk.length, formatForCategory(C_KEYWORD));
}
}
@@ -248,7 +236,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
void GlslHighlighter::highlightLine(const QString &text, int position, int length,
const QTextCharFormat &format)
{
- const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace);
+ const QTextCharFormat visualSpaceFormat = formatForCategory(C_VISUAL_WHITESPACE);
const int end = position + length;
int index = position;
diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h
index afbe882a41..0a8215c0f5 100644
--- a/src/plugins/glsleditor/glslhighlighter.h
+++ b/src/plugins/glsleditor/glslhighlighter.h
@@ -35,22 +35,6 @@ class GlslHighlighter : public TextEditor::SyntaxHighlighter
Q_OBJECT
public:
- enum Formats {
- GLSLNumberFormat,
- GLSLStringFormat,
- GLSLTypeFormat,
- GLSLKeywordFormat,
- GLSLOperatorFormat,
- GLSLPreprocessorFormat,
- GLSLLabelFormat,
- GLSLCommentFormat,
- GLSLDoxygenCommentFormat,
- GLSLDoxygenTagFormat,
- GLSLVisualWhitespace,
- GLSLReservedKeyword,
- NumGLSLFormats
- };
-
GlslHighlighter();
protected: