dlang-sqlite inital

This commit is contained in:
Damian committed 2026-10-12 23:24:32 +02:00
commit ce0a6c08e4
160 files changed
+362540

No files matched your search

+172
View File
@@ -0,0 +1,172 @@
#ifndef DLANG_EXPRESSIONS_HPP
#define DLANG_EXPRESSIONS_HPP
#include <string>
#include <iostream>
#include "../types/include.hpp"
struct Expression {
virtual ~Expression() = default;
virtual void Print(int indent = 0) const = 0;
};
struct NumberExpression : Expression {
double value;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "Number: " << value << '\n';
}
};
struct BooleanExpression : Expression {
bool value;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "Boolean: " << (value ? "true" : "false") << '\n';
}
};
struct StringExpression : Expression {
std::string value;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "string: " << value << '\n';
}
};
struct IdentifierExpression : Expression {
std::string name;
std::string keyName;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "Identifier: " << name << '\n';
}
};
struct BinaryExpression : Expression {
std::unique_ptr<Expression> left;
std::string op;
std::unique_ptr<Expression> right;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "Binary: " << op << '\n';
left->Print(indent + 2);
right->Print(indent + 2);
}
};
struct CallExpression : Expression
{
std::unique_ptr<Expression> callee;
std::vector< std::unique_ptr<Expression>> expressions;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ') << " Call" << "\n";
callee->Print(indent + 2);
for (const auto& expr : expressions)
expr->Print(indent + 2);
}
};
struct TableLiteralExpression : Expression
{
std::vector<std::pair<std::string, std::unique_ptr<Expression>>> fields;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "TableLiteral {\n";
for (const auto& [key, expr] : fields)
{
std::cout << std::string(indent + 2, ' ')
<< key << ":\n";
if (expr)
{
expr->Print(indent + 4);
}
}
std::cout << std::string(indent, ' ')
<< "}\n";
}
};
struct ListLiteralExpression : Expression
{
std::vector<std::unique_ptr<Expression>> fields;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "TableLiteral {\n";
for (const auto& val : fields)
val->Print(indent + 2);
std::cout << std::string(indent, ' ')
<< "}\n";
}
};
struct MemberAccessExpression : Expression
{
std::unique_ptr<Expression> object;
std::string memberName;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "MemberAccess: ." << memberName << '\n';
if (object)
{
object->Print(indent + 2);
}
}
};
struct IndexAccessExpression : Expression
{
std::unique_ptr<Expression> object;
std::unique_ptr<Expression> memberIndex;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "IndexAccess: ." << '\n';
memberIndex->Print(indent);
if (object)
{
object->Print(indent + 2);
}
}
};
struct SizeExpression : Expression
{
std::string identifier;
void Print(int indent = 0) const override
{
std::cout << std::string(indent, ' ')
<< "Identifier: " << identifier << '\n';
}
};
#endif