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