summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-11-26 11:33:49 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2010-11-26 12:00:53 +0100
commit57e881600177a9c23f9c47ec1de3649050ed8315 (patch)
tree10246f6d7431aeb3c55cc1a15fc24ed1c145519c
parentf891916afb772bae53de1b3393f8868a3c310d9a (diff)
downloadqt-creator-57e881600177a9c23f9c47ec1de3649050ed8315.tar.gz
Added GLSL::OverloadSet.
-rw-r--r--src/libs/glsl/glsl.h2
-rw-r--r--src/libs/glsl/glslengine.cpp26
-rw-r--r--src/libs/glsl/glslengine.h3
-rw-r--r--src/libs/glsl/glslsemantic.cpp4
-rw-r--r--src/libs/glsl/glslsymbol.h2
-rw-r--r--src/libs/glsl/glslsymbols.cpp44
-rw-r--r--src/libs/glsl/glslsymbols.h18
-rw-r--r--src/libs/glsl/glsltype.h1
-rw-r--r--src/libs/glsl/glsltypes.cpp45
-rw-r--r--src/libs/glsl/glsltypes.h23
10 files changed, 166 insertions, 2 deletions
diff --git a/src/libs/glsl/glsl.h b/src/libs/glsl/glsl.h
index bb43c1d009..cdfbcdc3c5 100644
--- a/src/libs/glsl/glsl.h
+++ b/src/libs/glsl/glsl.h
@@ -72,6 +72,8 @@ class Function;
class Argument;
class Block;
class Variable;
+class OverloadSet;
+class Namespace;
class AST;
template <typename T> class List;
diff --git a/src/libs/glsl/glslengine.cpp b/src/libs/glsl/glslengine.cpp
index 87c59e2f59..31078dda86 100644
--- a/src/libs/glsl/glslengine.cpp
+++ b/src/libs/glsl/glslengine.cpp
@@ -179,6 +179,24 @@ void Engine::addDiagnosticMessage(const DiagnosticMessage &m)
_diagnosticMessages.append(m);
}
+void Engine::warning(int line, const QString &message)
+{
+ DiagnosticMessage m;
+ m.setKind(DiagnosticMessage::Warning);
+ m.setLine(line);
+ m.setMessage(message);
+ addDiagnosticMessage(m);
+}
+
+void Engine::error(int line, const QString &message)
+{
+ DiagnosticMessage m;
+ m.setKind(DiagnosticMessage::Error);
+ m.setLine(line);
+ m.setMessage(message);
+ addDiagnosticMessage(m);
+}
+
QSet<QString> Engine::identifiers() const
{
return _identifiers;
@@ -194,6 +212,13 @@ bool GLSL::DiagnosticMessage::isWarning() const
return _kind == Warning;
}
+Namespace *Engine::newNamespace()
+{
+ Namespace *s = new Namespace();
+ _symbols.append(s);
+ return s;
+}
+
Struct *Engine::newStruct(Scope *scope)
{
Struct *s = new Struct(scope);
@@ -232,3 +257,4 @@ Variable *Engine::newVariable(Scope *scope, const QString &name, const Type *typ
_symbols.append(var);
return var;
}
+
diff --git a/src/libs/glsl/glslengine.h b/src/libs/glsl/glslengine.h
index 417f72e942..ffeb3d9ed0 100644
--- a/src/libs/glsl/glslengine.h
+++ b/src/libs/glsl/glslengine.h
@@ -111,6 +111,7 @@ public:
const MatrixType *matrixType(const Type *elementType, int columns, int rows);
// symbols
+ Namespace *newNamespace();
Struct *newStruct(Scope *scope = 0);
Block *newBlock(Scope *scope = 0);
Function *newFunction(Scope *scope = 0);
@@ -122,6 +123,8 @@ public:
QList<DiagnosticMessage> diagnosticMessages() const;
void clearDiagnosticMessages();
void addDiagnosticMessage(const DiagnosticMessage &m);
+ void warning(int line, const QString &message);
+ void error(int line, const QString &message);
private:
QSet<QString> _identifiers;
diff --git a/src/libs/glsl/glslsemantic.cpp b/src/libs/glsl/glslsemantic.cpp
index fc5829c207..2bcaa80d9c 100644
--- a/src/libs/glsl/glslsemantic.cpp
+++ b/src/libs/glsl/glslsemantic.cpp
@@ -80,7 +80,7 @@ void Semantic::declaration(DeclarationAST *ast)
Scope *Semantic::translationUnit(TranslationUnitAST *ast)
{
- Block *globalScope = _engine->newBlock();
+ Namespace *globalScope = _engine->newNamespace();
Scope *previousScope = switchScope(globalScope);
for (List<DeclarationAST *> *it = ast->declarations; it; it = it->next) {
DeclarationAST *decl = it->value;
@@ -216,10 +216,12 @@ bool Semantic::visit(ExpressionStatementAST *ast)
bool Semantic::visit(CompoundStatementAST *ast)
{
+ Scope *previousScope = switchScope(_engine->newBlock(_scope));
for (List<StatementAST *> *it = ast->statements; it; it = it->next) {
StatementAST *stmt = it->value;
statement(stmt);
}
+ (void) switchScope(previousScope);
return false;
}
diff --git a/src/libs/glsl/glslsymbol.h b/src/libs/glsl/glslsymbol.h
index d4eee75e6f..99e2e8d9da 100644
--- a/src/libs/glsl/glslsymbol.h
+++ b/src/libs/glsl/glslsymbol.h
@@ -56,6 +56,8 @@ public:
virtual Argument *asArgument() { return 0; }
virtual Block *asBlock() { return 0; }
virtual Variable *asVariable() { return 0; }
+ virtual OverloadSet *asOverloadSet() { return 0; }
+ virtual Namespace *asNamespace() { return 0; }
virtual const Type *type() const = 0;
diff --git a/src/libs/glsl/glslsymbols.cpp b/src/libs/glsl/glslsymbols.cpp
index 4562ba1256..ee0628eb39 100644
--- a/src/libs/glsl/glslsymbols.cpp
+++ b/src/libs/glsl/glslsymbols.cpp
@@ -29,7 +29,7 @@
#include "glsltypes.h"
#include "glslsymbols.h"
-#include <QtCore/qglobal.h>
+#include <QtCore/QDebug>
using namespace GLSL;
@@ -85,3 +85,45 @@ void Variable::setType(const Type *type)
{
_type = type;
}
+
+Namespace::Namespace()
+{
+}
+
+Namespace::~Namespace()
+{
+ qDeleteAll(_overloadSets);
+}
+
+void Namespace::add(Symbol *symbol)
+{
+ Symbol *&sym = _members[symbol->name()];
+ if (! sym)
+ sym = symbol;
+ else if (Function *fun = symbol->asFunction()) {
+ if (OverloadSet *o = sym->asOverloadSet()) {
+ o->addFunction(fun);
+ } else if (Function *firstFunction = sym->asFunction()) {
+ OverloadSet *o = new OverloadSet(this);
+ _overloadSets.append(o);
+ o->addFunction(firstFunction);
+ o->addFunction(fun);
+ sym = o;
+ }
+ else {
+ // ### warning? return false?
+ }
+ } else {
+ // ### warning? return false?
+ }
+}
+
+const Type *Namespace::type() const
+{
+ return 0;
+}
+
+Symbol *Namespace::find(const QString &name) const
+{
+ return _members.value(name);
+}
diff --git a/src/libs/glsl/glslsymbols.h b/src/libs/glsl/glslsymbols.h
index 21f0a4c686..9e870c13ca 100644
--- a/src/libs/glsl/glslsymbols.h
+++ b/src/libs/glsl/glslsymbols.h
@@ -81,6 +81,24 @@ private:
QHash<QString, Symbol *> _members;
};
+class GLSL_EXPORT Namespace: public Scope
+{
+public:
+ Namespace();
+ virtual ~Namespace();
+
+ void add(Symbol *symbol);
+
+ virtual Namespace *asNamespace() { return this; }
+
+ virtual const Type *type() const;
+ virtual Symbol *find(const QString &name) const;
+
+private:
+ QHash<QString, Symbol *> _members;
+ QVector<OverloadSet *> _overloadSets;
+};
+
} // end of namespace GLSL
#endif // GLSLSYMBOLS_H
diff --git a/src/libs/glsl/glsltype.h b/src/libs/glsl/glsltype.h
index 1159856b89..0d3f3c39e9 100644
--- a/src/libs/glsl/glsltype.h
+++ b/src/libs/glsl/glsltype.h
@@ -51,6 +51,7 @@ public:
virtual const MatrixType *asMatrixType() const { return 0; }
virtual const ArrayType *asArrayType() const { return 0; }
virtual const SamplerType *asSamplerType() const { return 0; }
+ virtual const OverloadSet *asOverloadSetType() const { return 0; }
virtual const Struct *asStructType() const { return 0; }
virtual const Function *asFunctionType() const { return 0; }
diff --git a/src/libs/glsl/glsltypes.cpp b/src/libs/glsl/glsltypes.cpp
index 41c3b14149..f894b90cec 100644
--- a/src/libs/glsl/glsltypes.cpp
+++ b/src/libs/glsl/glsltypes.cpp
@@ -390,3 +390,48 @@ bool SamplerType::isLessThan(const Type *other) const
Q_ASSERT(samp != 0);
return _kind < samp->kind();
}
+
+OverloadSet::OverloadSet(Scope *enclosingScope)
+ : Scope(enclosingScope)
+{
+}
+
+QVector<Function *> OverloadSet::functions() const
+{
+ return _functions;
+}
+
+void OverloadSet::addFunction(Function *function)
+{
+ _functions.append(function);
+}
+
+const Type *OverloadSet::type() const
+{
+ return this;
+}
+
+Symbol *OverloadSet::find(const QString &) const
+{
+ return 0;
+}
+
+void OverloadSet::add(Symbol *symbol)
+{
+ if (symbol) {
+ if (Function *fun = symbol->asFunction())
+ addFunction(fun);
+ }
+}
+
+bool OverloadSet::isEqualTo(const Type *other) const
+{
+ Q_UNUSED(other);
+ return false;
+}
+
+bool OverloadSet::isLessThan(const Type *other) const
+{
+ Q_UNUSED(other);
+ return false;
+}
diff --git a/src/libs/glsl/glsltypes.h b/src/libs/glsl/glsltypes.h
index cabb60b47b..02be903b8b 100644
--- a/src/libs/glsl/glsltypes.h
+++ b/src/libs/glsl/glsltypes.h
@@ -249,6 +249,29 @@ private:
int _kind;
};
+class GLSL_EXPORT OverloadSet: public Type, public Scope
+{
+public:
+ OverloadSet(Scope *enclosingScope = 0);
+
+ QVector<Function *> functions() const;
+ void addFunction(Function *function);
+
+ // as symbol
+ virtual OverloadSet *asOverloadSet() { return this; }
+ virtual const Type *type() const;
+ virtual Symbol *find(const QString &name) const;
+ virtual void add(Symbol *symbol);
+
+ // as type
+ virtual const OverloadSet *asOverloadSetType() const { return this; }
+ virtual bool isEqualTo(const Type *other) const;
+ virtual bool isLessThan(const Type *other) const;
+
+private:
+ QVector<Function *> _functions;
+};
+
} // end of namespace GLSL
#endif // GLSLTYPES_H