Commit 130f8e74 authored by Rhys Weatherley's avatar Rhys Weatherley
Browse files

Populate keyword list from GLSL language variant

parent 22db6cd7
......@@ -1664,3 +1664,210 @@ int Lexer::classify(const char *s, int n) {
} // switch
}
QStringList Lexer::keywords(int variant) {
QStringList list;
list += QLatin1String("do");
list += QLatin1String("if");
list += QLatin1String("in");
list += QLatin1String("for");
list += QLatin1String("int");
list += QLatin1String("out");
list += QLatin1String("bool");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("case");
list += QLatin1String("else");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("flat");
if (variant & (Lexer::Variant_GLSL_ES_100 | Lexer::Variant_GLSL_400))
list += QLatin1String("lowp");
list += QLatin1String("mat2");
list += QLatin1String("mat3");
list += QLatin1String("mat4");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("uint");
list += QLatin1String("vec2");
list += QLatin1String("vec3");
list += QLatin1String("vec4");
list += QLatin1String("void");
list += QLatin1String("true");
list += QLatin1String("break");
list += QLatin1String("bvec2");
list += QLatin1String("bvec3");
list += QLatin1String("bvec4");
list += QLatin1String("const");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat2");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat3");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat4");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dvec2");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dvec3");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dvec4");
list += QLatin1String("float");
if (variant & (Lexer::Variant_GLSL_ES_100 | Lexer::Variant_GLSL_400))
list += QLatin1String("highp");
list += QLatin1String("inout");
list += QLatin1String("ivec2");
list += QLatin1String("ivec3");
list += QLatin1String("ivec4");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("patch");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("uvec2");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("uvec3");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("uvec4");
list += QLatin1String("while");
list += QLatin1String("false");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("double");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("layout");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat2x2");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat2x3");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat2x4");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat3x2");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat3x3");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat3x4");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat4x2");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat4x3");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("mat4x4");
list += QLatin1String("return");
if (variant & (Lexer::Variant_Reserved))
list += QLatin1String("sample");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("smooth");
list += QLatin1String("struct");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("switch");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("default");
if (variant & (Lexer::Variant_FragmentShader))
list += QLatin1String("discard");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat2x2");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat2x3");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat2x4");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat3x2");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat3x3");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat3x4");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat4x2");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat4x3");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("dmat4x4");
if (variant & (Lexer::Variant_GLSL_ES_100 | Lexer::Variant_GLSL_400))
list += QLatin1String("mediump");
list += QLatin1String("uniform");
list += QLatin1String("varying");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("centroid");
list += QLatin1String("continue");
if (variant & (Lexer::Variant_VertexShader))
list += QLatin1String("attribute");
list += QLatin1String("invariant");
if (variant & (Lexer::Variant_GLSL_ES_100))
list += QLatin1String("precision");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("sampler1D");
list += QLatin1String("sampler2D");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("sampler3D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler1D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler2D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler3D");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("subroutine");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler1D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler2D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler3D");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler2DMS");
list += QLatin1String("samplerCube");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler2DMS");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isamplerCube");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler2DMS");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usamplerCube");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("noperspective");
list += QLatin1String("sampler2DRect");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("samplerBuffer");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler2DRect");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isamplerBuffer");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler1DArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler2DArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler2DRect");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usamplerBuffer");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler1DArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler2DArray");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("sampler1DShadow");
if (variant & (Lexer::Variant_GLSL_120))
list += QLatin1String("sampler2DShadow");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler1DArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler2DArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler2DMSArray");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("samplerCubeArray");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("isampler2DMSArray");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("isamplerCubeArray");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("samplerCubeShadow");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("usampler2DMSarray");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("usamplerCubeArray");
list += QLatin1String("sampler2DRectShadow");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler1DArrayShadow");
if (variant & (Lexer::Variant_GLSL_150))
list += QLatin1String("sampler2DArrayShadow");
if (variant & (Lexer::Variant_GLSL_400))
list += QLatin1String("samplerCubeArrayShadow");
return list;
}
......@@ -32,6 +32,7 @@
#include "glsl.h"
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
namespace GLSL {
......@@ -106,6 +107,8 @@ public:
void *yyval() const { return _yyval.ptr; }
static QStringList keywords(int variant);
private:
static int classify(const char *s, int len);
......
......@@ -249,6 +249,25 @@ void gen_classify(const std::multimap<size_t, std::string> &keywords)
<< "}" << std::endl << std::endl;
}
void gen_keyword_list(const std::multimap<size_t, std::string> &keywords)
{
std::cout << "QStringList " << option_class_name << "keywords(int variant) {" << std::endl
<< " QStringList list;" << std::endl;
std::multimap<size_t, std::string>::const_iterator it = keywords.begin();
for (; it != keywords.end(); ++it) {
std::string varid = variant_id(it->second);
if (varid.empty()) {
std::cout << " list += QLatin1String(\"" << it->second << "\");" << std::endl;
} else {
varid = varid.substr(3);
std::cout << " if (variant & (" << varid << "))" << std::endl;
std::cout << " list += QLatin1String(\"" << it->second << "\");" << std::endl;
}
}
std::cout << " return list;" << std::endl
<< "}" << std::endl << std::endl;
}
void gen_enums(const std::multimap<size_t, std::string> &keywords)
{
std::cout << "enum {" << std::endl;
......@@ -382,4 +401,6 @@ int main(int argc, char *argv[]) {
}
gen_classify(keywords);
gen_keyword_list(keywords);
}
......@@ -95,131 +95,6 @@ static bool checkStartOfIdentifier(const QString &word)
return false;
}
static const char *glsl_keywords[] =
{ // ### TODO: get the keywords from the lexer
"attribute",
"bool",
"break",
"bvec2",
"bvec3",
"bvec4",
"case",
"centroid",
"const",
"continue",
"default",
"discard",
"dmat2",
"dmat2x2",
"dmat2x3",
"dmat2x4",
"dmat3",
"dmat3x2",
"dmat3x3",
"dmat3x4",
"dmat4",
"dmat4x2",
"dmat4x3",
"dmat4x4",
"do",
"double",
"dvec2",
"dvec3",
"dvec4",
"else",
"false",
"flat",
"float",
"for",
"highp",
"if",
"in",
"inout",
"int",
"invariant",
"isampler1D",
"isampler1DArray",
"isampler2D",
"isampler2DArray",
"isampler2DMS",
"isampler2DMSArray",
"isampler2DRect",
"isampler3D",
"isamplerBuffer",
"isamplerCube",
"isamplerCubeArray",
"ivec2",
"ivec3",
"ivec4",
"layout",
"lowp",
"mat2",
"mat2x2",
"mat2x3",
"mat2x4",
"mat3",
"mat3x2",
"mat3x3",
"mat3x4",
"mat4",
"mat4x2",
"mat4x3",
"mat4x4",
"mediump",
"noperspective",
"out",
"patch",
"precision",
"return",
"sample",
"sampler1D",
"sampler1DArray",
"sampler1DArrayShadow",
"sampler1DShadow",
"sampler2D",
"sampler2DArray",
"sampler2DArrayShadow",
"sampler2DMS",
"sampler2DMSArray",
"sampler2DRect",
"sampler2DRectShadow",
"sampler2DShadow",
"sampler3D",
"samplerBuffer",
"samplerCube",
"samplerCubeArray",
"samplerCubeArrayShadow",
"samplerCubeShadow",
"smooth",
"struct",
"subroutine",
"switch",
"true",
"uint",
"uniform",
"usampler1D",
"usampler1DArray",
"usampler2D",
"usampler2DArray",
"usampler2DMS",
"usampler2DMSarray",
"usampler2DRect",
"usampler3D",
"usamplerBuffer",
"usamplerCube",
"usamplerCubeArray",
"uvec2",
"uvec3",
"uvec4",
"varying",
"vec2",
"vec3",
"vec4",
"void",
"while",
0
};
namespace GLSLEditor {
namespace Internal {
class FunctionArgumentWidget : public QLabel
......@@ -489,6 +364,8 @@ CodeCompletion::CodeCompletion(QObject *parent)
m_editor(0),
m_startPosition(-1),
m_restartCompletion(false),
m_keywordVariant(-1),
m_keywordIcon(":/glsleditor/images/keyword.png"),
m_varIcon(":/glsleditor/images/var.png"),
m_functionIcon(":/glsleditor/images/func.png"),
m_typeIcon(":/glsleditor/images/type.png"),
......@@ -498,13 +375,6 @@ CodeCompletion::CodeCompletion(QObject *parent)
m_varyingIcon(":/glsleditor/images/varying.png"),
m_otherIcon(":/glsleditor/images/other.png")
{
const QIcon keywordIcon(QLatin1String(":/glsleditor/images/keyword.png"));
for (const char **it = glsl_keywords; *it; ++it) {
TextEditor::CompletionItem item(this);
item.text = QString::fromLatin1(*it);
item.icon = keywordIcon;
m_keywordCompletions.append(item);
}
}
CodeCompletion::~CodeCompletion()
......@@ -677,6 +547,18 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
members += currentScope->members();
}
if (m_keywordVariant != edit->languageVariant()) {
QStringList keywords = GLSL::Lexer::keywords(edit->languageVariant());
m_keywordCompletions.clear();
for (int index = 0; index < keywords.size(); ++index) {
TextEditor::CompletionItem item(this);
item.text = keywords.at(index);
item.icon = m_keywordIcon;
m_keywordCompletions.append(item);
}
m_keywordVariant = edit->languageVariant();
}
m_completions += m_keywordCompletions;
}
......
......@@ -107,6 +107,9 @@ private:
static bool glslCompletionItemLessThan(const TextEditor::CompletionItem &l, const TextEditor::CompletionItem &r);
int m_keywordVariant;
QIcon m_keywordIcon;
QIcon m_varIcon;
QIcon m_functionIcon;
QIcon m_typeIcon;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment