2020-07-25 15:49:19 +01:00
|
|
|
/**
|
|
|
|
* Serene programming language.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-03-28 10:53:32 +01:00
|
|
|
#include "serene/namespace.hpp"
|
2020-07-25 15:49:19 +01:00
|
|
|
#include "serene/expr.hpp"
|
|
|
|
#include "serene/llvm/IR/Value.h"
|
2021-04-04 23:08:57 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-07-25 15:49:19 +01:00
|
|
|
#include <fmt/core.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace serene {
|
|
|
|
|
2021-04-04 23:08:57 +01:00
|
|
|
Namespace::Namespace(llvm::StringRef ns_name,
|
|
|
|
llvm::Optional<llvm::StringRef> filename) {
|
|
|
|
|
|
|
|
this->filename = filename;
|
|
|
|
this->name = ns_name;
|
|
|
|
};
|
|
|
|
|
2021-03-28 10:53:32 +01:00
|
|
|
ast_tree &Namespace::Tree() { return this->tree; }
|
2020-08-03 12:39:20 +01:00
|
|
|
|
2021-04-04 23:08:57 +01:00
|
|
|
llvm::Optional<mlir::Value> Namespace::lookup(llvm::StringRef name) {
|
|
|
|
if (auto value = rootScope.lookup(name)) {
|
2021-03-28 10:53:32 +01:00
|
|
|
return value;
|
|
|
|
}
|
2020-08-03 12:39:20 +01:00
|
|
|
|
2021-04-04 23:08:57 +01:00
|
|
|
return llvm::None;
|
2021-03-28 10:53:32 +01:00
|
|
|
};
|
2020-08-01 21:32:21 +01:00
|
|
|
|
2021-03-28 10:53:32 +01:00
|
|
|
mlir::LogicalResult Namespace::setTree(ast_tree t) {
|
|
|
|
if (initialized) {
|
|
|
|
return mlir::failure();
|
2020-08-01 21:32:21 +01:00
|
|
|
}
|
2021-03-28 10:53:32 +01:00
|
|
|
this->tree = t;
|
|
|
|
this->initialized = true;
|
|
|
|
return mlir::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
mlir::LogicalResult Namespace::insert_symbol(mlir::StringRef name,
|
|
|
|
mlir::Value v) {
|
|
|
|
|
2021-04-04 23:08:57 +01:00
|
|
|
rootScope.insert(PairT(name, v));
|
2021-03-28 10:53:32 +01:00
|
|
|
return mlir::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Namespace::print_scope(){};
|
2020-08-01 21:32:21 +01:00
|
|
|
|
2020-07-25 15:49:19 +01:00
|
|
|
Namespace::~Namespace() {}
|
|
|
|
|
|
|
|
} // namespace serene
|