diff --git a/src/Lib/Script/Ast/IrExpression.cc b/src/Lib/Script/Ast/IrExpression.cc index b3086532464ab9585f535c62e164405bfa9fc9f2..10cf3fe11e0ba5b400949e907d92ea2752a0c58a 100644 --- a/src/Lib/Script/Ast/IrExpression.cc +++ b/src/Lib/Script/Ast/IrExpression.cc @@ -94,11 +94,28 @@ IrEConstExpr::IrEConstExpr(const Token &singleElement) : IrExpression(nullptr, Type::ConstExpr) { switch (singleElement.valueType()) { - case Token::Type::INTEGER: - case Token::Type::FLOATING: - case Token::Type::COLORLIT: + case Token::Type::INTEGER: { + setInnerType(IrElement::create<IrTPrimitive>(this, IrType::PrimitiveType::Int)); + inner.integer = singleElement.asInteger(); + return; + } + + case Token::Type::FLOATING: { + setInnerType(IrElement::create<IrTPrimitive>(this, IrType::PrimitiveType::Float)); + inner.floating = singleElement.asFloating(); + return; + } + + case Token::Type::COLORLIT: { + setInnerType(IrElement::create<IrTPrimitive>(this, IrType::PrimitiveType::Color)); + inner.string = singleElement.asColorLit(); + return; + } + case Token::Type::STRINGLIT: { - throw std::logic_error("IrEConstExpr: not implemented " + singleElement.toString()); + setInnerType(IrElement::create<IrTPrimitive>(this, IrType::PrimitiveType::String)); + inner.string = singleElement.asStringLit(); + return; } /* Only handle true or false */ @@ -115,9 +132,7 @@ IrEConstExpr::IrEConstExpr(const Token &singleElement) } case Token::Type::QNAME: - default: { - throw std::logic_error("IrEConstExpr unexpected token: " + singleElement.toString()); - } + default: throw std::logic_error("IrEConstExpr unexpected token: " + singleElement.toString()); } } @@ -141,7 +156,7 @@ IrEConstExpr::getInnerInteger() const return inner.integer; } -float +double IrEConstExpr::getInnerFloating() const { innerType()->assertInnerType(IrType::PrimitiveType::Float); diff --git a/src/Lib/Script/Ast/IrExpression.hh b/src/Lib/Script/Ast/IrExpression.hh index 5df659d59769865bbeb1b9bbb9c0d2e41d0d11da..93ea0f69d200b9e1eadae501cc2f1476f533e65e 100644 --- a/src/Lib/Script/Ast/IrExpression.hh +++ b/src/Lib/Script/Ast/IrExpression.hh @@ -38,7 +38,7 @@ class IrEConstExpr : public IrExpression { union { bool boolean; int integer; - float floating; + double floating; /* StringLit + ColorLit */ StrV string = STRV_NULL; @@ -50,7 +50,7 @@ public: bool getInnerBoolean() const; int getInnerInteger() const; - float getInnerFloating() const; + double getInnerFloating() const; StrV getInnerStringLit() const; StrV getInnerColorLit() const; }; diff --git a/src/Lib/Script/Ast/Parser/IrExpression.hh b/src/Lib/Script/Ast/Parser/IrExpression.hh index 7abd049517523366d1ae87639efb4bc20a3467ea..57bcbd04f159a56da4ed0783af1c007e30ad011a 100644 --- a/src/Lib/Script/Ast/Parser/IrExpression.hh +++ b/src/Lib/Script/Ast/Parser/IrExpression.hh @@ -1,3 +1,3 @@ /* In: std::vector<Token>* tokens */ -throw std::logic_error("Parser/IrExpression: Not implemented"); \ No newline at end of file +throw std::logic_error("Parser/IrExpression: Not implemented");