forked from qt-creator/qt-creator
Initial work on the GLSL symbols.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h $$PWD/glslparsertable_p.h $$PWD/glslast.h \
|
||||
$$PWD/glslastvisitor.h $$PWD/glslengine.h $$PWD/glslmemorypool.h $$PWD/glslastdump.h \
|
||||
$$PWD/glslsemantic.h $$PWD/glsltype.h $$PWD/glsltypes.h $$PWD/glslsymbol.h
|
||||
$$PWD/glslsemantic.h $$PWD/glsltype.h $$PWD/glsltypes.h $$PWD/glslsymbol.h $$PWD/glslsymbols.h
|
||||
SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \
|
||||
$$PWD/glsllexer.cpp $$PWD/glslast.cpp \
|
||||
$$PWD/glslastvisitor.cpp $$PWD/glslengine.cpp $$PWD/glslmemorypool.cpp $$PWD/glslastdump.cpp \
|
||||
$$PWD/glslsemantic.cpp $$PWD/glsltype.cpp $$PWD/glsltypes.cpp $$PWD/glslsymbol.cpp
|
||||
$$PWD/glslsemantic.cpp $$PWD/glsltype.cpp $$PWD/glsltypes.cpp $$PWD/glslsymbol.cpp $$PWD/glslsymbols.cpp
|
||||
|
||||
OTHER_FILES = $$PWD/glsl.g
|
||||
|
||||
@@ -61,6 +61,13 @@ class OpaqueType;
|
||||
class VectorType;
|
||||
class MatrixType;
|
||||
|
||||
// symbols
|
||||
class Struct;
|
||||
class Function;
|
||||
class Argument;
|
||||
class Block;
|
||||
class Variable;
|
||||
|
||||
class AST;
|
||||
template <typename T> class List;
|
||||
}
|
||||
|
||||
@@ -31,31 +31,36 @@
|
||||
|
||||
using namespace GLSL;
|
||||
|
||||
Symbol::Symbol(Scope *scope)
|
||||
: _scope(scope)
|
||||
{
|
||||
}
|
||||
|
||||
Symbol::~Symbol()
|
||||
{
|
||||
}
|
||||
|
||||
Scope *Symbol::scope() const
|
||||
{
|
||||
return _scope;
|
||||
}
|
||||
|
||||
void Symbol::setScope(Scope *scope)
|
||||
{
|
||||
_scope = scope;
|
||||
}
|
||||
|
||||
Scope::Scope(Scope *enclosingScope)
|
||||
: _enclosingScope(enclosingScope)
|
||||
: Symbol(enclosingScope)
|
||||
{
|
||||
}
|
||||
|
||||
Scope *Scope::enclosingScope() const
|
||||
{
|
||||
return _enclosingScope;
|
||||
}
|
||||
|
||||
void Scope::setEnclosingScope(Scope *enclosingScope)
|
||||
{
|
||||
_enclosingScope = enclosingScope;
|
||||
}
|
||||
|
||||
Symbol *Scope::lookup(const QString &name) const
|
||||
{
|
||||
if (Symbol *s = find(name))
|
||||
return s;
|
||||
else if (Scope *e = enclosingScope())
|
||||
return e->lookup(name);
|
||||
else if (Scope *s = scope())
|
||||
return s->lookup(name);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,31 +37,37 @@ namespace GLSL {
|
||||
class Symbol;
|
||||
class Scope;
|
||||
|
||||
class Symbol
|
||||
class GLSL_EXPORT Symbol
|
||||
{
|
||||
public:
|
||||
Symbol(Scope *scope = 0);
|
||||
virtual ~Symbol();
|
||||
|
||||
virtual Scope *asScope() { return 0; }
|
||||
Scope *scope() const;
|
||||
void setScope(Scope *scope);
|
||||
|
||||
virtual Type *type() const = 0;
|
||||
virtual Scope *asScope() { return 0; }
|
||||
virtual Struct *asStruct() { return 0; }
|
||||
virtual Function *asFunction() { return 0; }
|
||||
virtual Argument *asArgument() { return 0; }
|
||||
virtual Block *asBlock() { return 0; }
|
||||
virtual Variable *asVariable() { return 0; }
|
||||
|
||||
virtual const Type *type() const = 0;
|
||||
|
||||
private:
|
||||
Scope *_scope;
|
||||
};
|
||||
|
||||
class Scope: public Symbol
|
||||
class GLSL_EXPORT Scope: public Symbol
|
||||
{
|
||||
public:
|
||||
Scope(Scope *enclosingScope = 0);
|
||||
|
||||
Scope *enclosingScope() const;
|
||||
void setEnclosingScope(Scope *enclosingScope);
|
||||
Scope(Scope *sscope = 0);
|
||||
|
||||
Symbol *lookup(const QString &name) const;
|
||||
virtual Symbol *find(const QString &name) const = 0;
|
||||
|
||||
virtual Scope *asScope() { return this; }
|
||||
|
||||
private:
|
||||
Scope *_enclosingScope;
|
||||
};
|
||||
|
||||
} // end of namespace GLSL
|
||||
|
||||
107
src/libs/glsl/glslsymbols.cpp
Normal file
107
src/libs/glsl/glslsymbols.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "glsltypes.h"
|
||||
#include "glslsymbols.h"
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
using namespace GLSL;
|
||||
|
||||
Argument::Argument(Function *scope)
|
||||
: Symbol(scope)
|
||||
, _type(0)
|
||||
{
|
||||
}
|
||||
|
||||
QString Argument::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
void Argument::setName(const QString &name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
const Type *Argument::type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
void Argument::setType(const Type *type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
|
||||
Block::Block(Scope *enclosingScope)
|
||||
: Scope(enclosingScope)
|
||||
{
|
||||
}
|
||||
|
||||
void Block::addMember(const QString &name, Symbol *symbol)
|
||||
{
|
||||
_members.insert(name, symbol);
|
||||
}
|
||||
|
||||
const Type *Block::type() const
|
||||
{
|
||||
// ### assert?
|
||||
return 0;
|
||||
}
|
||||
|
||||
Symbol *Block::find(const QString &name) const
|
||||
{
|
||||
return _members.value(name);
|
||||
}
|
||||
|
||||
Variable::Variable(Scope *scope)
|
||||
: Symbol(scope)
|
||||
, _type(0)
|
||||
{
|
||||
}
|
||||
|
||||
QString Variable::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
void Variable::setName(const QString &name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
const Type *Variable::type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
void Variable::setType(const Type *type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
94
src/libs/glsl/glslsymbols.h
Normal file
94
src/libs/glsl/glslsymbols.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://qt.nokia.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
#ifndef GLSLSYMBOLS_H
|
||||
#define GLSLSYMBOLS_H
|
||||
|
||||
#include "glsltype.h"
|
||||
#include "glslsymbol.h"
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
namespace GLSL {
|
||||
|
||||
class GLSL_EXPORT Argument: public Symbol
|
||||
{
|
||||
public:
|
||||
Argument(Function *scope);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
virtual const Type *type() const;
|
||||
void setType(const Type *type);
|
||||
|
||||
virtual Argument *asArgument() { return this; }
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
const Type *_type;
|
||||
};
|
||||
|
||||
class GLSL_EXPORT Variable: public Symbol
|
||||
{
|
||||
public:
|
||||
Variable(Scope *scope);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
virtual const Type *type() const;
|
||||
void setType(const Type *type);
|
||||
|
||||
virtual Variable *asVariable() { return this; }
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
const Type *_type;
|
||||
};
|
||||
|
||||
class GLSL_EXPORT Block: public Scope
|
||||
{
|
||||
public:
|
||||
Block(Scope *enclosingScope = 0);
|
||||
|
||||
void addMember(const QString &name, Symbol *symbol);
|
||||
|
||||
virtual Block *asBlock() { return this; }
|
||||
|
||||
virtual const Type *type() const;
|
||||
virtual Symbol *find(const QString &name) const;
|
||||
|
||||
private:
|
||||
QHash<QString, Symbol *> _members;
|
||||
};
|
||||
|
||||
} // end of namespace GLSL
|
||||
|
||||
#endif // GLSLSYMBOLS_H
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
virtual const VectorType *asVectorType() const { return 0; }
|
||||
virtual const MatrixType *asMatrixType() const { return 0; }
|
||||
|
||||
virtual const Struct *asStructType() const { return 0; }
|
||||
virtual const Function *asFunctionType() const { return 0; }
|
||||
|
||||
virtual bool isEqualTo(const Type *other) const = 0;
|
||||
virtual bool isLessThan(const Type *other) const = 0;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "glsltypes.h"
|
||||
#include <QtCore/qglobal.h>
|
||||
#include "glslsymbols.h"
|
||||
|
||||
using namespace GLSL;
|
||||
|
||||
@@ -195,3 +195,76 @@ bool MatrixType::isLessThan(const Type *other) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Struct::isEqualTo(const Type *other) const
|
||||
{
|
||||
Q_UNUSED(other);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Struct::isLessThan(const Type *other) const
|
||||
{
|
||||
Q_UNUSED(other);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString Function::name() const
|
||||
{
|
||||
return _name;
|
||||
|
||||
}
|
||||
|
||||
void Function::setName(const QString &name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
const Type *Function::returnType() const
|
||||
{
|
||||
return _returnType;
|
||||
}
|
||||
|
||||
void Function::setReturnType(const Type *returnType)
|
||||
{
|
||||
_returnType = returnType;
|
||||
}
|
||||
|
||||
QVector<Argument *> Function::arguments() const
|
||||
{
|
||||
return _arguments;
|
||||
}
|
||||
|
||||
void Function::addArgument(Argument *arg)
|
||||
{
|
||||
_arguments.append(arg);
|
||||
}
|
||||
|
||||
int Function::argumentCount() const
|
||||
{
|
||||
return _arguments.size();
|
||||
}
|
||||
|
||||
Argument *Function::argumentAt(int index) const
|
||||
{
|
||||
return _arguments.at(index);
|
||||
}
|
||||
|
||||
bool Function::isEqualTo(const Type *other) const
|
||||
{
|
||||
Q_UNUSED(other);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Function::isLessThan(const Type *other) const
|
||||
{
|
||||
Q_UNUSED(other);
|
||||
return false;
|
||||
}
|
||||
|
||||
Symbol *Function::find(const QString &name) const
|
||||
{
|
||||
foreach (Argument *arg, _arguments) {
|
||||
if (arg->name() == name)
|
||||
return arg;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
#define GLSLTYPES_H
|
||||
|
||||
#include "glsltype.h"
|
||||
#include "glslsymbol.h"
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace GLSL {
|
||||
|
||||
@@ -133,6 +136,53 @@ private:
|
||||
int _rows;
|
||||
};
|
||||
|
||||
class GLSL_EXPORT Struct: public Type, public Symbol
|
||||
{
|
||||
public:
|
||||
Struct(Scope *scope = 0);
|
||||
|
||||
// as Type
|
||||
virtual const Struct *asStructType() const { return this; }
|
||||
virtual bool isEqualTo(const Type *other) const;
|
||||
virtual bool isLessThan(const Type *other) const;
|
||||
|
||||
// as Symbol
|
||||
virtual Struct *asStruct() { return this; } // as Symbol
|
||||
};
|
||||
|
||||
class GLSL_EXPORT Function: public Type, public Scope
|
||||
{
|
||||
public:
|
||||
Function(Scope *scope = 0);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
const Type *returnType() const;
|
||||
void setReturnType(const Type *returnType);
|
||||
|
||||
QVector<Argument *> arguments() const;
|
||||
void addArgument(Argument *arg);
|
||||
int argumentCount() const;
|
||||
Argument *argumentAt(int index) const;
|
||||
|
||||
// as Type
|
||||
virtual const Function *asFunctionType() const { return this; }
|
||||
virtual bool isEqualTo(const Type *other) const;
|
||||
virtual bool isLessThan(const Type *other) const;
|
||||
|
||||
// as Symbol
|
||||
virtual Function *asFunction() { return this; }
|
||||
virtual const Type *type() const { return this; }
|
||||
|
||||
virtual Symbol *find(const QString &name) const;
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
const Type *_returnType;
|
||||
QVector<Argument *> _arguments;
|
||||
};
|
||||
|
||||
} // end of namespace GLSL
|
||||
|
||||
#endif // GLSLTYPES_H
|
||||
|
||||
Reference in New Issue
Block a user