// =============================================================================
//
// This file is part of the qlow compiler.
//
// Copyright (C) 2014-2015 Nicolas Winkler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// =============================================================================
#ifndef QLOW_AST_H
#define QLOW_AST_H
#include
#include
#include
#include
#include "Visitor.h"
namespace qlow
{
class AstVisitor;
namespace ast
{
template
using List = std::vector>;
// base class
struct AstObject;
struct Class;
struct FeatureDeclaration;
struct FieldDeclaration;
struct MethodDefinition;
struct VariableDeclaration;
struct ArgumentDeclaration;
struct DoEndBlock;
struct Statement;
struct Expression;
struct FeatureCall;
struct AssignmentStatement;
struct NewVariableStatement;
struct Operation;
struct UnaryOperation;
struct BinaryOperation;
}
namespace sem
{
struct SemanticObject;
}
}
struct qlow::ast::AstObject :
public Visitable, AstVisitor>
{
virtual ~AstObject(void);
};
struct qlow::ast::Class : public AstObject
{
std::string name;
List features;
inline Class(const std::string& name, List& features) :
name(name), features(std::move(features))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::FeatureDeclaration : public AstObject
{
std::string name;
std::string type;
inline FeatureDeclaration(const std::string& type, const std::string& name) :
name(name), type(type)
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::FieldDeclaration : public FeatureDeclaration
{
inline FieldDeclaration(const std::string& type, const std::string& name) :
FeatureDeclaration(type, name)
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::MethodDefinition : public FeatureDeclaration
{
List arguments;
std::unique_ptr body;
inline MethodDefinition(const std::string& type, const std::string& name,
std::unique_ptr body) :
FeatureDeclaration(type, name),
body(std::move(body))
{
}
inline MethodDefinition(const std::string& type, const std::string& name,
List&& arguments, std::unique_ptr body) :
FeatureDeclaration(type, name),
arguments(std::move(arguments)),
body(std::move(body))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::VariableDeclaration : public AstObject
{
std::string type;
std::string name;
inline VariableDeclaration(const std::string& type, const std::string& name) :
type(type), name(name)
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::ArgumentDeclaration :
public VariableDeclaration
{
inline ArgumentDeclaration(const std::string& type, const std::string& name) :
VariableDeclaration(type, name)
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::DoEndBlock : public AstObject
{
List statements;
inline DoEndBlock(List&& statements) :
statements(std::move(statements))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::Statement : public virtual AstObject
{
virtual ~Statement(void);
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::Expression : public virtual AstObject
{
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::FeatureCall : public Expression, public Statement
{
std::unique_ptr target;
std::string name;
List arguments;
inline FeatureCall(std::unique_ptr target, const std::string& name) :
target(std::move(target)), name(name)
{
}
inline FeatureCall(std::unique_ptr target, const std::string& name,
List&& arguments) :
target(std::move(target)), name(name), arguments(std::move(arguments))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::AssignmentStatement : public Statement
{
std::string target;
std::unique_ptr expr;
inline AssignmentStatement(const std::string& target, std::unique_ptr expr) :
target(target), expr(std::move(expr))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::NewVariableStatement : public Statement
{
std::string name;
std::string type;
inline NewVariableStatement(const std::string& name, const std::string& type) :
name(name), type(type)
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::Operation : public Expression
{
enum Operator {
PLUS, MINUS, ASTERISK, SLASH
};
Operator op;
inline Operation(Operator op) :
op(op)
{
}
};
struct qlow::ast::UnaryOperation : public Operation
{
enum Side
{
PREFIX,
SUFFIX,
};
Side side;
std::unique_ptr expr;
inline UnaryOperation(std::unique_ptr expr, Side side, Operator op) :
Operation(op),
side(side),
expr(std::move(expr))
{
}
std::unique_ptr accept(AstVisitor& v);
};
struct qlow::ast::BinaryOperation : public Operation
{
std::unique_ptr left;
std::unique_ptr right;
inline BinaryOperation(std::unique_ptr left, std::unique_ptr right, Operator op) :
Operation(op),
left(std::move(left)), right(std::move(right))
{
}
std::unique_ptr accept(AstVisitor& v);
};
#endif // QLOW_AST_H