-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #51 `new` is used to create a pointer to a scalar value
- Loading branch information
Showing
20 changed files
with
333 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ class Identifier; | |
class BinaryCalcul; | ||
|
||
class Assignation; | ||
|
||
class Pointer; | ||
} | ||
|
||
#endif // FILC_AST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2024-Present Kevin Traini | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
#ifndef FILC_POINTER_H | ||
#define FILC_POINTER_H | ||
|
||
#include "filc/grammar/expression/Expression.h" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace filc { | ||
class Pointer final : public Expression { | ||
public: | ||
Pointer(std::string type_name, const std::shared_ptr<Expression> &value); | ||
|
||
[[nodiscard]] auto getTypeName() const -> std::string; | ||
|
||
[[nodiscard]] auto getValue() const -> std::shared_ptr<Expression>; | ||
|
||
[[nodiscard]] auto getPointedType() const -> std::shared_ptr<AbstractType>; | ||
|
||
auto acceptVoidVisitor(Visitor<void> *visitor) -> void override; | ||
|
||
auto acceptIRVisitor(Visitor<llvm::Value *> *visitor) -> llvm::Value * override; | ||
|
||
private: | ||
std::string _type_name; | ||
std::shared_ptr<Expression> _value; | ||
}; | ||
} // namespace filc | ||
|
||
#endif // FILC_POINTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ VAR: 'var'; | |
VAL: 'val'; | ||
TRUE: 'true'; | ||
FALSE: 'false'; | ||
NEW: 'new'; | ||
|
||
// Operators | ||
EQ: '='; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2024-Present Kevin Traini | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
#include "filc/grammar/pointer/Pointer.h" | ||
|
||
using namespace filc; | ||
|
||
Pointer::Pointer(std::string type_name, const std::shared_ptr<Expression> &value) | ||
: _type_name(std::move(type_name)), _value(value) {} | ||
|
||
auto Pointer::getTypeName() const -> std::string { | ||
return _type_name; | ||
} | ||
|
||
auto Pointer::getValue() const -> std::shared_ptr<Expression> { | ||
return _value; | ||
} | ||
|
||
auto Pointer::getPointedType() const -> std::shared_ptr<AbstractType> { | ||
const auto type = std::dynamic_pointer_cast<PointerType>(getType()); | ||
if (type == nullptr) { | ||
return nullptr; | ||
} | ||
|
||
return type->getPointedType(); | ||
} | ||
|
||
auto Pointer::acceptVoidVisitor(Visitor<void> *visitor) -> void { | ||
visitor->visitPointer(this); | ||
} | ||
|
||
auto Pointer::acceptIRVisitor(Visitor<llvm::Value *> *visitor) -> llvm::Value * { | ||
return visitor->visitPointer(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.