Skip to content
Extraits de code Groupes Projets
Vérifiée Valider ad6c4a80 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

PARSER: IrOption is Ok modulo type and expression parsing

parent 94731101
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!25Draft: New Vivy module spec
Pipeline #2797 réussi
......@@ -4,10 +4,7 @@
namespace Vivy::Script
{
IrElement::IrElement(IrElement *p) noexcept
: parentElement(p != nullptr ? p : this)
{
}
IrElement::IrElement(IrElement *p) noexcept { setParent(p); }
IrElement::~IrElement() noexcept
{
......
......@@ -7,6 +7,12 @@
namespace Vivy::Script
{
IrExpression::IrExpression(IrElement *p, Type type) noexcept
: IrElement(p)
, selfType(type)
{
}
std::string
IrExpression::toString() const noexcept
{
......@@ -58,6 +64,12 @@ IrEVariableRef::parse(std::vector<Token> *)
namespace Vivy::Script
{
IrEConstExpr::IrEConstExpr(const Token &singleElement)
: IrExpression(nullptr, Type::ConstExpr)
{
throw std::logic_error("IrEConstExpr " + singleElement.toString());
}
std::string
IrEConstExpr::toString() const noexcept
{
......
......@@ -14,6 +14,9 @@ private:
Type selfType;
IrType *selfInnerType = nullptr;
protected:
IrExpression(IrElement *p, Type) noexcept;
public:
std::string toString() const noexcept override;
void parse(std::vector<Token> *) override;
......@@ -25,6 +28,8 @@ public:
class IrEConstExpr : public IrExpression {
VIVY_IR_ELEMENT(IrEConstExpr)
IrEConstExpr(const Token &);
public:
std::string toString() const noexcept override;
void parse(std::vector<Token> *) override;
......
#include "IrOption.hh"
#include "IrExpression.hh"
#include "IrType.hh"
#include "Lib/Script/FrontEnd/Lexer.hh"
namespace Vivy::Script
......@@ -89,6 +91,8 @@ IrOption::match(const std::vector<IrOption *> &others) const noexcept
void
IrOption::parse(std::vector<Token> *tokens)
{
IrModule *sourceModule = parent();
const Token firstDeclToken = getInnerTokenOpt(tokenListPop(tokens));
firstDeclToken.assertTypeSimple(TOKEN_OPTION);
......@@ -112,13 +116,19 @@ IrOption::parse(std::vector<Token> *tokens)
getInnerTokenOpt(tokenListPop(tokens)).assertTypeSimple(TOKEN_ASSIGN);
const Token defaultValueToken = getInnerTokenOpt(tokenListPop(tokens));
std::cerr << "Found option: " << shapeName.toStdString() << "."
<< fieldNameToken.asQName().toStdString() << " : "
<< typeNameToken.asSimple().toStdString() << " = " << defaultValueToken.toString()
<< ";\n";
IrEConstExpr *defaultValue = IrElement::create<IrEConstExpr>(this, defaultValueToken);
IrType *optionType = IrElement::create<IrTPrimitive>(this, typeNameToken);
const ShapeElement::Content content = {
.fieldName = fieldNameToken.asQName(),
.type = optionType,
.defaultValue = defaultValue,
};
addShape(sourceModule, content);
const Token continuationToken = getInnerTokenOpt(tokenListPop(tokens));
if (continuationToken.isSimple(TOKEN_COMMA))
if (const Token continuationToken = getInnerTokenOpt(tokenListPop(tokens));
continuationToken.isSimple(TOKEN_COMMA))
continue;
else if (continuationToken.isSimple(TOKEN_CURLY_BRACKET_RIGHT))
break;
......
......@@ -78,6 +78,11 @@ IrTOption::parse(std::vector<Token> *)
namespace Vivy::Script
{
IrTPrimitive::IrTPrimitive(const Token &name)
{
throw std::logic_error("IrTPrimitive " + name.toString());
}
IrType::Type
IrTPrimitive::type() const noexcept
{
......
......@@ -53,6 +53,8 @@ class IrTPrimitive : public IrType {
PrimitiveType selfInnerType;
unsigned int selfArraySize;
IrTPrimitive(const Token &);
public:
Type type() const noexcept override;
PrimitiveType innerType() const noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter