Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused type conversion methods #545

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<h3 align="center">Spice Programming Language</h3>
<p align="center">Compiler and standard library for the Spice programming language.</p>
<p align="center">
<a target="_blank" href="https://github.com/spicelang/spice/releases/latest"><img src="https://img.shields.io/github/v/release/spicelang/spice?include_prereleases"></a>
<a target="_blank" href="https://hub.docker.com/r/chillibits/spice"><img src="https://img.shields.io/docker/pulls/chillibits/spice"></a>
<a target="_blank" href="https://github.com/spicelang/spice/actions/workflows/ci-cpp.yml"><img src="https://github.com/spicelang/spice/actions/workflows/ci-cpp.yml/badge.svg"></a>
<a target="_blank" href="https://github.com/spicelang/spice/actions/workflows/codeql-analysis.yml"><img src="https://github.com/spicelang/spice/actions/workflows/codeql-analysis.yml/badge.svg"></a>
<a target="_blank" href="https://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>
<a target="_blank" href="./LICENSE.md"><img src="https://img.shields.io/github/license/spicelang/spice"></a>
<a target="_blank" href="https://discord.gg/D6sCsJyWPg"><img src="https://dcbadge.vercel.app/api/server/D6sCsJyWPg?style=flat"></a>
<a target="_blank" href="https://github.com/spicelang/spice/releases/latest"><img alt="Latest release" src="https://img.shields.io/github/v/release/spicelang/spice?include_prereleases"></a>
<a target="_blank" href="https://hub.docker.com/r/chillibits/spice"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/chillibits/spice"></a>
<a target="_blank" href="https://github.com/spicelang/spice/actions/workflows/ci-cpp.yml"><img alt="CI status" src="https://github.com/spicelang/spice/actions/workflows/ci-cpp.yml/badge.svg"></a>
<a target="_blank" href="https://github.com/spicelang/spice/actions/workflows/codeql-analysis.yml"><img alt="CodeQL status" src="https://github.com/spicelang/spice/actions/workflows/codeql-analysis.yml/badge.svg"></a>
<a target="_blank" href="https://makeapullrequest.com"><img alt="PRs welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>
<a target="_blank" href="./LICENSE"><img alt="License" src="https://img.shields.io/github/license/spicelang/spice"></a>
<a target="_blank" href="https://discord.gg/D6sCsJyWPg"><img alt="Discord server" src="https://dcbadge.vercel.app/api/server/D6sCsJyWPg?style=flat"></a>
</p>
</p>

Expand Down
4 changes: 2 additions & 2 deletions src/CompilerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CompilerPass::CompilerPass(GlobalResourceManager &resourceManager, SourceFile *s
* @param scope Scope to change to
* @param scopeType Expected type of the given scope
*/
void CompilerPass::changeToScope(Scope *scope, ScopeType scopeType) {
void CompilerPass::changeToScope(Scope *scope, [[maybe_unused]] ScopeType scopeType) {
assert(scope != nullptr);
assert(scope->type == scopeType);
assert(!scope->isGenericScope);
Expand All @@ -47,7 +47,7 @@ void CompilerPass::changeToScope(const std::string &scopeName, ScopeType scopeTy
*
* @param oldScopeType Expected type of the scope to leave
*/
void CompilerPass::changeToParentScope(ScopeType oldScopeType) {
void CompilerPass::changeToParentScope([[maybe_unused]] ScopeType oldScopeType) {
assert(currentScope->type == oldScopeType);
assert(currentScope->parent != nullptr);
currentScope = currentScope->parent;
Expand Down
4 changes: 2 additions & 2 deletions src/irgenerator/GenValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ std::any IRGenerator::visitDataType(const DataTypeNode *node) {

llvm::Value *IRGenerator::buildFatFctPtr(Scope *bodyScope, llvm::Type *capturesStructType, llvm::Value *lambda) {
// Create capture struct if required
llvm::Value *capturesPtr;
llvm::Value *capturesPtr = nullptr;
if (capturesStructType != nullptr) {
assert(bodyScope != nullptr);
// If we have a single capture of ptr type, we can directly store it into the fat ptr. Otherwise, we need a stack allocated
Expand Down Expand Up @@ -908,7 +908,7 @@ llvm::Value *IRGenerator::buildFatFctPtr(Scope *bodyScope, llvm::Type *capturesS
llvm::Value *fctPtr = insertStructGEP(llvmTypes.fatPtrType, fatFctPtr, 0);
insertStore(lambda, fctPtr);
llvm::Value *capturePtr = insertStructGEP(llvmTypes.fatPtrType, fatFctPtr, 1);
insertStore(capturesStructType != nullptr ? capturesPtr : llvm::PoisonValue::get(builder.getPtrTy()), capturePtr);
insertStore(capturesPtr != nullptr ? capturesPtr : llvm::PoisonValue::get(builder.getPtrTy()), capturePtr);

return fatFctPtr;
}
Expand Down
1 change: 0 additions & 1 deletion src/symboltablebuilder/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class Scope {
[[nodiscard]] bool isInAsyncScope() const;
[[nodiscard]] bool doesAllowUnsafeOperations() const;
[[nodiscard]] bool isImportedBy(const Scope *askingScope) const;
const StructRegistry &getStructs() const { return structs; }
[[nodiscard]] nlohmann::json getSymbolTableJSON() const;

// Wrapper methods for symbol table
Expand Down
87 changes: 0 additions & 87 deletions src/symboltablebuilder/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ Scope *Type::getBodyScope() const {
return typeChain.back().data.bodyScope;
}

/**
* Get the pointer type of the current type as a new type
*
* @param node AST node for error messages
* @return Pointer type of the current type
*/
Type Type::toPointer(const ASTNode *node) const {
// Do not allow pointers of dyn
if (is(TY_DYN))
throw SemanticError(node, DYN_POINTERS_NOT_ALLOWED, "Just use the dyn type without '*' instead");
if (isRef())
throw SemanticError(node, REF_POINTERS_ARE_NOT_ALLOWED, "Pointers to references are not allowed. Use pointer instead");

TypeChain newTypeChain = typeChain;
newTypeChain.emplace_back(TY_PTR);
return Type(newTypeChain);
}

/**
* Get the pointer type of the current type as a new type
*
Expand All @@ -107,25 +89,6 @@ const Type *Type::toPtr(const ASTNode *node) const {
return TypeRegistry::getOrInsert(newTypeChain);
}

/**
* Get the reference type of the current type as a new type
*
* @param node AST node for error messages
* @return Reference type of the current type
*/
Type Type::toReference(const ASTNode *node) const {
// Do not allow references of dyn
if (is(TY_DYN))
throw SemanticError(node, DYN_REFERENCES_NOT_ALLOWED, "Just use the dyn type without '&' instead");
// Do not allow references of references
if (isRef())
throw SemanticError(node, MULTI_REF_NOT_ALLOWED, "References to references are not allowed");

TypeChain newTypeChain = typeChain;
newTypeChain.emplace_back(TY_REF);
return Type(newTypeChain);
}

/**
* Get the reference type of the current type as a new type
*
Expand All @@ -148,22 +111,6 @@ const Type *Type::toRef(const ASTNode *node) const {
return TypeRegistry::getOrInsert(newTypeChain);
}

/**
* Get the array type of the current type as a new type
*
* @param node AST node for error messages
* @param size Size of the array
* @return Array type of the current type
*/
Type Type::toArray(const ASTNode *node, unsigned int size, bool skipDynCheck /*=false*/) const {
// Do not allow arrays of dyn
if (!skipDynCheck && typeChain.back().superType == TY_DYN)
throw SemanticError(node, DYN_ARRAYS_NOT_ALLOWED, "Just use the dyn type without '[]' instead");

TypeChain newTypeChain = typeChain;
newTypeChain.emplace_back(TY_ARRAY, TypeChainElementData{.arraySize = size});
return Type(newTypeChain);
}
/**
* Get the array type of the current type as a new type
*
Expand All @@ -184,20 +131,6 @@ const Type *Type::toArr(const ASTNode *node, unsigned int size, bool skipDynChec
return TypeRegistry::getOrInsert(newTypeChain);
}

/**
* Retrieve the base type of an array or a pointer
*
* @return Base type
*/
Type Type::getContainedTy() const {
if (is(TY_STRING))
return Type(TY_CHAR);
assert(typeChain.size() > 1);
TypeChain newTypeChain = typeChain;
newTypeChain.pop_back();
return Type(newTypeChain);
}

/**
* Retrieve the base type of an array or a pointer
*
Expand All @@ -216,26 +149,6 @@ const Type *Type::getContained() const {
return TypeRegistry::getOrInsert(newTypeChain);
}

/**
* Replace the base type with another one
*
* @param newBaseType New base type
* @return The new type
*/
Type Type::replaceBaseType(const Type &newBaseType) const {
assert(!typeChain.empty());

// Create new type chain
TypeChain newTypeChain = newBaseType.typeChain;
const bool doubleRef = newTypeChain.back().superType == TY_REF && typeChain.back().superType == TY_REF;
for (size_t i = 1; i < typeChain.size(); i++)
if (!doubleRef || i > 1)
newTypeChain.push_back(typeChain.at(i));

// Return the new chain as a symbol type
return Type(newTypeChain);
}

/**
* Replace the base type with another one
*
Expand Down
5 changes: 0 additions & 5 deletions src/symboltablebuilder/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ class Type {
[[nodiscard]] llvm::Type *toLLVMType(llvm::LLVMContext &context, Scope *accessScope) const;

// Get new type, based on this one
[[nodiscard]] [[deprecated]] Type toPointer(const ASTNode *node) const;
[[nodiscard]] const Type *toPtr(const ASTNode *node) const;
[[nodiscard]] [[deprecated]] Type toReference(const ASTNode *node) const;
[[nodiscard]] const Type *toRef(const ASTNode *node) const;
[[nodiscard]] [[deprecated]] Type toArray(const ASTNode *node, unsigned int size = 0, bool skipDynCheck = false) const;
[[nodiscard]] const Type *toArr(const ASTNode *node, unsigned int size = 0, bool skipDynCheck = false) const;
[[nodiscard]] [[deprecated]] Type getContainedTy() const;
[[nodiscard]] const Type *getContained() const;
[[nodiscard]] [[deprecated]] Type replaceBaseType(const Type &newBaseType) const;
[[nodiscard]] const Type *replaceBase(const Type *newBaseType) const;
[[nodiscard]] const Type *removeReferenceWrapper() const;
[[nodiscard]] const Type *getBase() const;
Expand Down
2 changes: 1 addition & 1 deletion src/util/GlobalDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ template <typename T> ALWAYS_INLINE static T spice_pointer_cast(auto source) {
}

// Fail with an assertion error message
#define assert_fail(msg) assert(false && msg)
#define assert_fail(msg) assert(false && (msg))

#ifdef __GNUC__
#pragma GCC diagnostic pop
Expand Down
1 change: 0 additions & 1 deletion src/visualizer/ASTVisualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class ASTVisualizer : private CompilerPass, public AbstractASTVisitor {
private:
// Members
const std::vector<std::string> nodeNames;
int currentTabs = 1;
std::stack<std::string> parentNodeIds;

// Private methods
Expand Down