Commit 864c3bfc authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Added the suffix AST to the ast nodes and some initial work on the GLSL type system.

parent 6c74dbba
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/glslsemantic.h $$PWD/glsltypes.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/glslsemantic.cpp $$PWD/glsltypes.cpp
OTHER_FILES = $$PWD/glsl.g
This diff is collapsed.
......@@ -47,6 +47,20 @@ class Engine;
class Lexer;
class Parser;
class MemoryPool;
// types
class Type;
class UndefinedType;
class VoidType;
class BoolType;
class IntType;
class UIntType;
class FloatType;
class DoubleType;
class OpaqueType;
class VectorType;
class MatrixType;
class AST;
template <typename T> class List;
}
......
......@@ -45,7 +45,7 @@ void AST::accept(AST *ast, Visitor *visitor)
ast->accept(visitor);
}
void TranslationUnit::accept0(Visitor *visitor)
void TranslationUnitAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(declarations, visitor);
......@@ -53,19 +53,19 @@ void TranslationUnit::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void IdentifierExpression::accept0(Visitor *visitor)
void IdentifierExpressionAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void LiteralExpression::accept0(Visitor *visitor)
void LiteralExpressionAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void BinaryExpression::accept0(Visitor *visitor)
void BinaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(left, visitor);
......@@ -74,14 +74,14 @@ void BinaryExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void UnaryExpression::accept0(Visitor *visitor)
void UnaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void TernaryExpression::accept0(Visitor *visitor)
void TernaryExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(first, visitor);
......@@ -91,7 +91,7 @@ void TernaryExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void AssignmentExpression::accept0(Visitor *visitor)
void AssignmentExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(variable, visitor);
......@@ -100,14 +100,14 @@ void AssignmentExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void MemberAccessExpression::accept0(Visitor *visitor)
void MemberAccessExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void FunctionCallExpression::accept0(Visitor *visitor)
void FunctionCallExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expr, visitor);
......@@ -117,14 +117,14 @@ void FunctionCallExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void FunctionIdentifier::accept0(Visitor *visitor)
void FunctionIdentifierAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void DeclarationExpression::accept0(Visitor *visitor)
void DeclarationExpressionAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(type, visitor);
......@@ -133,21 +133,21 @@ void DeclarationExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ExpressionStatement::accept0(Visitor *visitor)
void ExpressionStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void CompoundStatement::accept0(Visitor *visitor)
void CompoundStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(statements, visitor);
visitor->endVisit(this);
}
void IfStatement::accept0(Visitor *visitor)
void IfStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(condition, visitor);
......@@ -157,7 +157,7 @@ void IfStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void WhileStatement::accept0(Visitor *visitor)
void WhileStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(condition, visitor);
......@@ -166,7 +166,7 @@ void WhileStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void DoStatement::accept0(Visitor *visitor)
void DoStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(body, visitor);
......@@ -175,7 +175,7 @@ void DoStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void ForStatement::accept0(Visitor *visitor)
void ForStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(init, visitor);
......@@ -186,20 +186,20 @@ void ForStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void JumpStatement::accept0(Visitor *visitor)
void JumpStatementAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void ReturnStatement::accept0(Visitor *visitor)
void ReturnStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void SwitchStatement::accept0(Visitor *visitor)
void SwitchStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(expr, visitor);
......@@ -208,22 +208,22 @@ void SwitchStatement::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void CaseLabelStatement::accept0(Visitor *visitor)
void CaseLabelStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(expr, visitor);
visitor->endVisit(this);
}
void DeclarationStatement::accept0(Visitor *visitor)
void DeclarationStatementAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(decls, visitor);
visitor->endVisit(this);
}
BasicType::BasicType(int _token, const char *_name, Category _category)
: Type(Kind_BasicType), token(_token), name(_name), categ(_category)
BasicTypeAST::BasicTypeAST(int _token, const char *_name, Category _category)
: TypeAST(Kind_BasicType), token(_token), name(_name), categ(_category)
{
switch (token) {
case GLSLParserTable::T_VOID:
......@@ -239,18 +239,18 @@ BasicType::BasicType(int _token, const char *_name, Category _category)
}
}
void BasicType::accept0(Visitor *visitor)
void BasicTypeAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
Type::Precision BasicType::precision() const
TypeAST::Precision BasicTypeAST::precision() const
{
return prec;
}
bool BasicType::setPrecision(Precision precision)
bool BasicTypeAST::setPrecision(Precision precision)
{
if (prec == PrecNotValid)
return false;
......@@ -258,24 +258,24 @@ bool BasicType::setPrecision(Precision precision)
return true;
}
void NamedType::accept0(Visitor *visitor)
void NamedTypeAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
Type::Precision NamedType::precision() const
TypeAST::Precision NamedTypeAST::precision() const
{
// Named types are typically structs, which cannot have their precision set.
return PrecNotValid;
}
bool NamedType::setPrecision(Precision)
bool NamedTypeAST::setPrecision(Precision)
{
return false;
}
void ArrayType::accept0(Visitor *visitor)
void ArrayTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(elementType, visitor);
......@@ -284,12 +284,12 @@ void ArrayType::accept0(Visitor *visitor)
visitor->endVisit(this);
}
Type::Precision ArrayType::precision() const
TypeAST::Precision ArrayTypeAST::precision() const
{
return elementType ? elementType->precision() : PrecNotValid;
}
bool ArrayType::setPrecision(Precision precision)
bool ArrayTypeAST::setPrecision(Precision precision)
{
if (elementType)
return elementType->setPrecision(precision);
......@@ -297,39 +297,39 @@ bool ArrayType::setPrecision(Precision precision)
return false;
}
void StructType::accept0(Visitor *visitor)
void StructTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(fields, visitor);
visitor->endVisit(this);
}
Type::Precision StructType::precision() const
TypeAST::Precision StructTypeAST::precision() const
{
return PrecNotValid;
}
bool StructType::setPrecision(Precision)
bool StructTypeAST::setPrecision(Precision)
{
// Structs cannot have a precision set.
return false;
}
void StructType::Field::accept0(Visitor *visitor)
void StructTypeAST::Field::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void StructType::Field::setInnerType(Type *innerType)
void StructTypeAST::Field::setInnerType(TypeAST *innerType)
{
if (!innerType)
return;
Type **parent = &type;
Type *inner = type;
TypeAST **parent = &type;
TypeAST *inner = type;
while (inner != 0) {
ArrayType *array = inner->asArrayType();
ArrayTypeAST *array = inner->asArrayType();
if (!array)
break;
parent = &(array->elementType);
......@@ -338,7 +338,7 @@ void StructType::Field::setInnerType(Type *innerType)
*parent = innerType;
}
List<StructType::Field *> *StructType::fixInnerTypes(Type *innerType, List<Field *> *fields)
List<StructTypeAST::Field *> *StructTypeAST::fixInnerTypes(TypeAST *innerType, List<Field *> *fields)
{
if (!fields)
return fields;
......@@ -351,28 +351,28 @@ List<StructType::Field *> *StructType::fixInnerTypes(Type *innerType, List<Field
return fields;
}
void QualifiedType::accept0(Visitor *visitor)
void QualifiedTypeAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void PrecisionDeclaration::accept0(Visitor *visitor)
void PrecisionDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void ParameterDeclaration::accept0(Visitor *visitor)
void ParameterDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void VariableDeclaration::accept0(Visitor *visitor)
void VariableDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(type, visitor);
......@@ -381,20 +381,20 @@ void VariableDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
Type *VariableDeclaration::declarationType(List<Declaration *> *decls)
TypeAST *VariableDeclarationAST::declarationType(List<DeclarationAST *> *decls)
{
VariableDeclaration *var = decls->value->asVariableDeclaration();
VariableDeclarationAST *var = decls->value->asVariableDeclaration();
return var ? var->type : 0;
}
void TypeDeclaration::accept0(Visitor *visitor)
void TypeDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(type, visitor);
visitor->endVisit(this);
}
void TypeAndVariableDeclaration::accept0(Visitor *visitor)
void TypeAndVariableDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(typeDecl, visitor);
......@@ -403,20 +403,20 @@ void TypeAndVariableDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
void InvariantDeclaration::accept0(Visitor *visitor)
void InvariantDeclarationAST::accept0(Visitor *visitor)
{
visitor->visit(this);
visitor->endVisit(this);
}
void InitDeclaration::accept0(Visitor *visitor)
void InitDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this))
accept(decls, visitor);
visitor->endVisit(this);
}
void FunctionDeclaration::accept0(Visitor *visitor)
void FunctionDeclarationAST::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(returnType, visitor);
......
This diff is collapsed.
......@@ -44,113 +44,113 @@ public:
virtual bool preVisit(AST *) { return true; }
virtual void postVisit(AST *) {}
virtual bool visit(TranslationUnit *) { return true; }
virtual void endVisit(TranslationUnit *) {}
virtual bool visit(TranslationUnitAST *) { return true; }
virtual void endVisit(TranslationUnitAST *) {}
virtual bool visit(IdentifierExpression *) { return true; }
virtual void endVisit(IdentifierExpression *) {}
virtual bool visit(IdentifierExpressionAST *) { return true; }
virtual void endVisit(IdentifierExpressionAST *) {}
virtual bool visit(LiteralExpression *) { return true; }
virtual void endVisit(LiteralExpression *) {}
virtual bool visit(LiteralExpressionAST *) { return true; }
virtual void endVisit(LiteralExpressionAST *) {}
virtual bool visit(BinaryExpression *) { return true; }
virtual void endVisit(BinaryExpression *) {}
virtual bool visit(BinaryExpressionAST *) { return true; }
virtual void endVisit(BinaryExpressionAST *) {}
virtual bool visit(UnaryExpression *) { return true; }
virtual void endVisit(UnaryExpression *) {}
virtual bool visit(UnaryExpressionAST *) { return true; }
virtual void endVisit(UnaryExpressionAST *) {}
virtual bool visit(TernaryExpression *) { return true; }
virtual void endVisit(TernaryExpression *) {}
virtual bool visit(TernaryExpressionAST *) { return true; }
virtual void endVisit(TernaryExpressionAST *) {}
virtual bool visit(AssignmentExpression *) { return true; }
virtual void endVisit(AssignmentExpression *) {}
virtual bool visit(AssignmentExpressionAST *) { return true; }
virtual void endVisit(AssignmentExpressionAST *) {}
virtual bool visit(MemberAccessExpression *) { return true; }
virtual void endVisit(MemberAccessExpression *) {}
virtual bool visit(MemberAccessExpressionAST *) { return true; }
virtual void endVisit(MemberAccessExpressionAST *) {}
virtual bool visit(FunctionCallExpression *) { return true; }
virtual void endVisit(FunctionCallExpression *) {}
virtual bool visit(FunctionCallExpressionAST *) { return true; }
virtual void endVisit(FunctionCallExpressionAST *) {}
virtual bool visit(FunctionIdentifier *) { return true; }
virtual void endVisit(FunctionIdentifier *) {}
virtual bool visit(FunctionIdentifierAST *) { return true; }
virtual void endVisit(FunctionIdentifierAST *) {}
virtual bool visit(DeclarationExpression *) { return true; }
virtual void endVisit(DeclarationExpression *) {}
virtual bool visit(DeclarationExpressionAST *) { return true; }
virtual void endVisit(DeclarationExpressionAST *) {}
virtual bool visit(ExpressionStatement *) { return true; }
virtual void endVisit(ExpressionStatement *) {}
virtual bool visit(ExpressionStatementAST *) { return true; }
virtual void endVisit(ExpressionStatementAST *) {}
virtual bool visit(CompoundStatement *) { return true; }
virtual void endVisit(CompoundStatement *) {}
virtual bool visit(CompoundStatementAST *) { return true; }
virtual void endVisit(CompoundStatementAST *) {}
virtual bool visit(IfStatement *) { return true; }
virtual void endVisit(IfStatement *) {}
virtual bool visit(IfStatementAST *) { return true; }
virtual void endVisit(IfStatementAST *) {}
virtual bool visit(WhileStatement *) { return true; }
virtual void endVisit(WhileStatement *) {}
virtual bool visit(WhileStatementAST *) { return true; }
virtual void endVisit(WhileStatementAST *) {}
virtual bool visit(DoStatement *) { return true; }
virtual void endVisit(DoStatement *) {}
virtual bool visit(DoStatementAST *) { return true; }
virtual void endVisit(DoStatementAST *) {}
virtual bool visit(ForStatement *) { return true; }
virtual void endVisit(ForStatement *) {}
virtual bool visit(ForStatementAST *) { return true; }
virtual void endVisit(ForStatementAST *) {}
virtual bool visit(JumpStatement *) { return true; }
virtual void endVisit(JumpStatement *) {}
virtual bool visit(JumpStatementAST *) { return true; }
virtual void endVisit(JumpStatementAST *) {}
virtual bool visit(ReturnStatement *) { return true; }
virtual void endVisit(ReturnStatement *) {}
virtual bool visit(ReturnStatementAST *) { return true; }
virtual void endVisit(ReturnStatementAST *) {}
virtual bool visit(SwitchStatement *) { return true; }
virtual void endVisit(SwitchStatement *) {}
virtual bool visit(SwitchStatementAST *) { return true; }
virtual void endVisit(SwitchStatementAST *) {}
virtual bool visit(CaseLabelStatement *) { return true; }
virtual void endVisit(CaseLabelStatement *) {}
virtual bool visit(CaseLabelStatementAST *) { return true; }
virtual void endVisit(CaseLabelStatementAST *) {}
virtual bool visit(DeclarationStatement *) { return true; }
virtual void endVisit(DeclarationStatement *) {}
virtual bool visit(DeclarationStatementAST *) { return true; }
virtual void endVisit(DeclarationStatementAST *) {}
virtual bool visit(BasicType *) { return true; }
virtual void endVisit(BasicType *) {}
virtual bool visit(BasicTypeAST *) { return true; }
virtual void endVisit(BasicTypeAST *) {}
virtual bool visit(NamedType *) { return true; }
virtual void endVisit(NamedType *) {}
virtual bool visit(NamedTypeAST *) { return true; }
virtual void endVisit(NamedTypeAST *) {}
virtual bool visit(ArrayType *) { return true; }
virtual void endVisit(ArrayType *) {}
virtual bool visit(ArrayTypeAST *) { return true; }
virtual void endVisit(ArrayTypeAST *) {}
virtual bool visit(StructType *) { return true; }
virtual void endVisit(StructType *) {}
virtual bool visit(StructTypeAST *) { return true; }
virtual void endVisit(StructTypeAST *) {}
virtual bool visit(StructType::Field *) { return true; }
virtual void endVisit(StructType::Field *) {}
virtual bool visit(StructTypeAST::Field *) { return true; }
virtual void endVisit(StructTypeAST::Field *) {}
virtual bool visit(QualifiedType *) { return true; }
virtual void endVisit(QualifiedType *) {}
virtual bool visit(QualifiedTypeAST *) { return true; }
virtual void endVisit(QualifiedTypeAST *) {}
virtual bool visit(PrecisionDeclaration *) { return true; }
virtual void endVisit(PrecisionDeclaration *) {}
virtual bool visit(PrecisionDeclarationAST *) { return true; }
virtual void endVisit(PrecisionDeclarationAST *) {}
virtual bool visit(ParameterDeclaration *) { return true; }
virtual void endVisit(ParameterDeclaration *) {}
virtual bool visit(ParameterDeclarationAST *) { return true; }
virtual void endVisit(ParameterDeclarationAST *) {}
virtual bool visit(VariableDeclaration *) { return true; }
virtual void endVisit(VariableDeclaration *) {}
virtual bool visit(VariableDeclarationAST *) { return true; }
virtual void endVisit(VariableDeclarationAST *) {}
virtual bool visit(TypeDeclaration *) { return true; }
virtual void endVisit(TypeDeclaration *) {}
virtual bool visit(TypeDeclarationAST *) { return true; }
virtual void endVisit(TypeDeclarationAST *) {}
virtual bool visit(TypeAndVariableDeclaration *) { return true; }
virtual void endVisit(TypeAndVariableDeclaration *) {}
virtual bool visit(TypeAndVariableDeclarationAST *) { return true; }
virtual void endVisit(TypeAndVariableDeclarationAST *) {}
virtual bool visit(InvariantDeclaration *) { return true; }
virtual void endVisit(InvariantDeclaration *) {}
virtual bool visit(InvariantDeclarationAST *) { return true; }
virtual void endVisit(InvariantDeclarationAST *) {}
virtual bool visit(InitDeclaration *) { return true; }
virtual void endVisit(InitDeclaration *) {}