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

BUILD: Fix most of the compilation and linkage errors

parent 3225845f
Branches
Étiquettes
1 requête de fusion!25Draft: New Vivy module spec
Pipeline #2876 en échec
...@@ -13,6 +13,12 @@ IrElement::IrElement(IrElement *p) noexcept ...@@ -13,6 +13,12 @@ IrElement::IrElement(IrElement *p) noexcept
parentRoot = dynamic_cast<IrRoot *>(this); parentRoot = dynamic_cast<IrRoot *>(this);
} }
IrRoot *
IrElement::irRoot() const noexcept
{
return parentRoot;
}
void void
IrElement::throwUnexpectedToken(const Token &tok) const IrElement::throwUnexpectedToken(const Token &tok) const
{ {
......
...@@ -30,6 +30,12 @@ IrExpression::setInnerType(IrType *type) ...@@ -30,6 +30,12 @@ IrExpression::setInnerType(IrType *type)
selfInnerType->setParent(this); selfInnerType->setParent(this);
} }
IrScope *
IrExpression::parentScope() const noexcept
{
return selfParentScope;
}
std::string std::string
IrExpression::toString() const noexcept IrExpression::toString() const noexcept
{ {
...@@ -101,6 +107,19 @@ IrEVariableRef::toString() const noexcept ...@@ -101,6 +107,19 @@ IrEVariableRef::toString() const noexcept
} }
return ret; return ret;
} }
IrEVariableRef::IrEVariableRef(IrVariable *var) noexcept
: IrExpression(nullptr, Type::VariableRef)
, referencedVariable(var)
{
}
IrEVariableRef::IrEVariableRef(IrVariable *var, std::vector<IrExpression *> &&argIndicies)
: IrExpression(nullptr, Type::VariableRef)
, referencedVariable(var)
, indicies(argIndicies)
{
}
} }
/* /*
...@@ -230,6 +249,13 @@ IrECall::toString() const noexcept ...@@ -230,6 +249,13 @@ IrECall::toString() const noexcept
return ret; return ret;
} }
IrECall::IrECall(IrFunction *func, std::vector<IrExpression *> &&args) noexcept
: IrExpression(nullptr, Type::Call)
, callPtr(func)
, inArgs(args)
{
}
const IrFunction * const IrFunction *
IrECall::call() const noexcept IrECall::call() const noexcept
{ {
......
...@@ -97,6 +97,8 @@ class IrECall : public IrExpression { ...@@ -97,6 +97,8 @@ class IrECall : public IrExpression {
IrFunction *callPtr = nullptr; IrFunction *callPtr = nullptr;
std::vector<IrExpression *> inArgs; std::vector<IrExpression *> inArgs;
IrECall(IrFunction *, std::vector<IrExpression *> &&) noexcept;
public: public:
std::string toString() const noexcept override; std::string toString() const noexcept override;
......
...@@ -5,22 +5,6 @@ ...@@ -5,22 +5,6 @@
#include "IrJob.hh" #include "IrJob.hh"
#include "Lib/Script/FrontEnd/Lexer.hh" #include "Lib/Script/FrontEnd/Lexer.hh"
/*
** Protected way of getting a thing from a vector if the inner elements
** have a `name()` mehod that returns a StrV
*/
template <typename T> static T *
findInVector(const std::vector<T *> &vector, ::Vivy::Script::StrV itemName) noexcept
{
for (T *item : vector) {
if (::Vivy::Script::StrV::equal(item->name(), itemName))
return item;
}
return nullptr;
}
namespace Vivy::Script namespace Vivy::Script
{ {
const IrRoot * const IrRoot *
...@@ -69,37 +53,37 @@ IrModule::job(const std::string &name) noexcept ...@@ -69,37 +53,37 @@ IrModule::job(const std::string &name) noexcept
const IrOption * const IrOption *
IrModule::option(StrV name) const noexcept IrModule::option(StrV name) const noexcept
{ {
return findInVector(localOptions, name); return Utils::findInVector(localOptions, name);
} }
const IrFunction * const IrFunction *
IrModule::function(StrV name) const noexcept IrModule::function(StrV name) const noexcept
{ {
return findInVector(localFunctions, name); return Utils::findInVector(localFunctions, name);
} }
const IrJob * const IrJob *
IrModule::job(StrV name) const noexcept IrModule::job(StrV name) const noexcept
{ {
return findInVector(localJobs, name); return Utils::findInVector(localJobs, name);
} }
IrOption * IrOption *
IrModule::option(StrV name) noexcept IrModule::option(StrV name) noexcept
{ {
return findInVector(localOptions, name); return Utils::findInVector(localOptions, name);
} }
IrFunction * IrFunction *
IrModule::function(StrV name) noexcept IrModule::function(StrV name) noexcept
{ {
return findInVector(localFunctions, name); return Utils::findInVector(localFunctions, name);
} }
IrJob * IrJob *
IrModule::job(StrV name) noexcept IrModule::job(StrV name) noexcept
{ {
return findInVector(localJobs, name); return Utils::findInVector(localJobs, name);
} }
std::string std::string
......
...@@ -35,6 +35,12 @@ IrRoot::IrRoot() noexcept ...@@ -35,6 +35,12 @@ IrRoot::IrRoot() noexcept
{ {
} }
IrScope *
IrRoot::scope() noexcept
{
return globalScope;
}
const IrRoot * const IrRoot *
IrRoot::parent() const noexcept IrRoot::parent() const noexcept
{ {
......
#include "IrScope.hh" #include "IrScope.hh"
#include "IrVariable.hh"
#include "IrFunction.hh"
#include "IrRoot.hh" #include "IrRoot.hh"
namespace Vivy::Script namespace Vivy::Script
...@@ -14,4 +16,40 @@ IrScope::isLocal() const noexcept ...@@ -14,4 +16,40 @@ IrScope::isLocal() const noexcept
{ {
return !isGlobal(); return !isGlobal();
} }
IrFunction *
IrScope::getFunctionByName(const char *name) const noexcept
{
return getFunctionByName(StrV::fromStr(name));
}
IrFunction *
IrScope::getFunctionByName(const std::string &name) const noexcept
{
return getFunctionByName(name.c_str());
}
IrVariable *
IrScope::getVariableByName(const char *name) const noexcept
{
return getVariableByName(StrV::fromStr(name));
}
IrVariable *
IrScope::getVariableByName(const std::string &name) const noexcept
{
return getVariableByName(name.c_str());
}
IrFunction *
IrScope::getFunctionByName(StrV name) const noexcept
{
return Utils::findInVector(inScopeFunctions, name);
}
IrVariable *
IrScope::getVariableByName(StrV name) const noexcept
{
return Utils::findInVector(inScopeVariables, name);
}
} }
...@@ -75,5 +75,28 @@ struct StrV final { ...@@ -75,5 +75,28 @@ struct StrV final {
#define STRV_FMT "%.*s" /* Format string for a string view */ #define STRV_FMT "%.*s" /* Format string for a string view */
#define STRV_ARG(sv) ((sv).count), ((sv).data) /* Unpack the string view */ #define STRV_ARG(sv) ((sv).count), ((sv).data) /* Unpack the string view */
}
namespace Vivy::Script::Utils
{
/*
** Protected way of getting a thing from a vector if the inner elements
** have a `name()` mehod that returns a StrV.
** TODO: Enforce the `name()` thing with a concept
*/
template <typename T>
// clang-format off
requires requires(T *item) { { item->name() } -> std::same_as<::Vivy::Script::StrV>; }
// clang-format on
static inline T *
findInVector(const std::vector<T *> &vector, ::Vivy::Script::StrV itemName) noexcept
{
for (T *item : vector) {
if (::Vivy::Script::StrV::equal(item->name(), itemName))
return item;
}
return nullptr;
}
} }
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