2021-04-12 23:18:32 +01:00
|
|
|
/* -*- C++ -*-
|
2021-10-12 20:51:03 +01:00
|
|
|
* Serene Programming Language
|
2021-04-12 23:18:32 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* Copyright (c) 2019-2021 Sameer Rahmani <lxsameer@gnu.org>
|
2021-04-12 23:18:32 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2.
|
2021-04-12 23:18:32 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2021-04-12 23:18:32 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-04-12 23:18:32 +01:00
|
|
|
*/
|
|
|
|
|
2021-10-17 20:12:17 +01:00
|
|
|
#ifndef SERENE_READER_SEMANTICS_H
|
|
|
|
#define SERENE_READER_SEMANTICS_H
|
2021-04-12 23:18:32 +01:00
|
|
|
|
2021-04-25 09:56:28 +01:00
|
|
|
#include "serene/context.h"
|
2021-05-06 19:17:57 +01:00
|
|
|
#include "serene/errors/error.h"
|
2021-04-12 23:18:32 +01:00
|
|
|
#include "serene/exprs/expression.h"
|
|
|
|
|
|
|
|
namespace serene::reader {
|
2021-05-06 19:17:57 +01:00
|
|
|
using AnalyzeResult = Result<exprs::Ast, std::vector<exprs::ErrorPtr>>;
|
2021-08-07 17:41:19 +01:00
|
|
|
/// The entry point to the Semantic analysis phase. It calls the `analyze`
|
|
|
|
/// method of each node in the given AST and creates a new AST that contains a
|
|
|
|
/// more comprehensive set of nodes in a semantically correct AST. If the
|
|
|
|
/// `analyze` method of a node return a `nullptr` value as the `success` result
|
|
|
|
/// (Checkout the `Result` type in `utils.h`) then the original node will be
|
|
|
|
/// used instead. Also please note that in **Serene** Semantic errors
|
|
|
|
/// represented as AST nodes as well. So you should expect an `analyze` method
|
|
|
|
/// of a node to return a `Result<node>::Success(Error...)` in case of a
|
|
|
|
/// semantic error.
|
2021-04-24 20:18:33 +01:00
|
|
|
///
|
2021-08-07 17:41:19 +01:00
|
|
|
/// \param ctx The semantic analysis context
|
|
|
|
/// \param inputAst The raw AST to analyze and possibly rewrite.
|
2021-10-17 14:57:17 +01:00
|
|
|
AnalyzeResult analyze(serene::SereneContext &ctx, exprs::Ast &inputAst);
|
2021-04-12 23:18:32 +01:00
|
|
|
}; // namespace serene::reader
|
|
|
|
|
|
|
|
#endif
|