diff --git a/artifacts/compile_commands.json.tmpl b/artifacts/compile_commands.json.tmpl index 7e178c0..925b65c 100644 --- a/artifacts/compile_commands.json.tmpl +++ b/artifacts/compile_commands.json.tmpl @@ -29,6 +29,11 @@ "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o CMakeFiles/arx.dir/src/codegen/ast-to-object.cpp.o -c {{PROJECT_PATH}}/src/codegen/ast-to-object.cpp", "file": "{{PROJECT_PATH}}/src/codegen/ast-to-object.cpp" }, +{ + "directory": "{{PROJECT_PATH}}/build", + "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o CMakeFiles/arx.dir/src/codegen/ast-to-stdout.cpp.o -c {{PROJECT_PATH}}/src/codegen/ast-to-stdout.cpp", + "file": "{{PROJECT_PATH}}/src/codegen/ast-to-stdout.cpp" +}, { "directory": "{{PROJECT_PATH}}/build", "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o CMakeFiles/arx.dir/src/utils.cpp.o -c {{PROJECT_PATH}}/src/utils.cpp", @@ -94,6 +99,11 @@ "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -I{{PROJECT_PATH}}/build/tests -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -fsanitize=address -O1 -fno-omit-frame-pointer -fprofile-instr-generate -fcoverage-mapping -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o tests/CMakeFiles/ArxTests.dir/__/src/codegen/ast-to-object.cpp.o -c {{PROJECT_PATH}}/src/codegen/ast-to-object.cpp", "file": "{{PROJECT_PATH}}/src/codegen/ast-to-object.cpp" }, +{ + "directory": "{{PROJECT_PATH}}/build", + "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -I{{PROJECT_PATH}}/build/tests -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -fsanitize=address -O1 -fno-omit-frame-pointer -fprofile-instr-generate -fcoverage-mapping -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o tests/CMakeFiles/ArxTests.dir/__/src/codegen/ast-to-stdout.cpp.o -c {{PROJECT_PATH}}/src/codegen/ast-to-stdout.cpp", + "file": "{{PROJECT_PATH}}/src/codegen/ast-to-stdout.cpp" +}, { "directory": "{{PROJECT_PATH}}/build", "command": "{{CONDA_PREFIX}}/bin/clang++ -DGFLAGS_IS_A_DLL=0 -DGLOG_CUSTOM_PREFIX_SUPPORT -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I{{PROJECT_PATH}}/src -I{{PROJECT_PATH}}/build/tests -fvisibility-inlines-hidden -std=c++20 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem {{CONDA_PREFIX}}/include -fsanitize=address -O1 -fno-omit-frame-pointer -fprofile-instr-generate -fcoverage-mapping -O3 -DNDEBUG -fprofile-instr-generate -fcoverage-mapping -std=c++20 -o tests/CMakeFiles/ArxTests.dir/__/src/utils.cpp.o -c {{PROJECT_PATH}}/src/utils.cpp", diff --git a/meson.build b/meson.build index f24fb40..62554f6 100644 --- a/meson.build +++ b/meson.build @@ -2,11 +2,33 @@ project('arx', 'cpp', 'c', license : 'Apache-2.0', version : '1.5.0', # semantic-release default_options : [ - 'warning_level=3', + 'warning_level=everything', 'cpp_std=c++20', ] ) +add_global_arguments( + '-Wpedantic', + '-Wno-c++98-compat-pedantic', + '-Wno-padded', + '-Wno-missing-prototypes', + '-Wshadow', + '-Wnon-virtual-dtor', + '-Wcast-align', + '-Wunused', + '-Woverloaded-virtual', + '-Wconversion', + '-Wsign-conversion', + '-Wdouble-promotion', + '-Wformat=2', + '-Wimplicit-fallthrough', + '-Wsuggest-override', + '-Wnull-dereference', + '-Wold-style-cast', + language : 'cpp' +) + + PROJECT_PATH = meson.source_root() cxx = meson.get_compiler('cpp') @@ -25,7 +47,7 @@ project_src_files = files( # note: note working yet # PROJECT_PATH + '/src/codegen/ast-to-llvm.cpp', PROJECT_PATH + '/src/codegen/ast-to-object.cpp', - PROJECT_PATH + '/src/codegen/ast-to-output.cpp', + PROJECT_PATH + '/src/codegen/ast-to-stdout.cpp', PROJECT_PATH + '/src/error.cpp', PROJECT_PATH + '/src/io.cpp', PROJECT_PATH + '/src/lexer.cpp', diff --git a/src/codegen/ast-to-object.cpp b/src/codegen/ast-to-object.cpp index ff3b6dd..e13a303 100644 --- a/src/codegen/ast-to-object.cpp +++ b/src/codegen/ast-to-object.cpp @@ -106,9 +106,8 @@ class ASTToObjectVisitor : public Visitor { }; /** - * @brief - * @param Name - * @return + * @brief Put the function defined by the given name to result_func. + * @param Name Function name * * First, see if the function has already been added to the current * module. If not, check whether we can codegen the declaration from some @@ -127,10 +126,10 @@ auto ASTToObjectVisitor::getFunction(std::string Name) -> void { } /** - * @brief - * @param TheFunction - * @param VarName - * @return + * @brief Create the Entry Block Allocation. + * @param TheFunction The llvm function + * @param VarName The variable name + * @return An llvm allocation instance. * * CreateEntryBlockAlloca - Create an alloca instruction in the entry * block of the function. This is used for mutable variables etc. @@ -143,14 +142,17 @@ auto ASTToObjectVisitor::CreateEntryBlockAlloca( llvm::Type::getDoubleTy(*this->TheContext), nullptr, VarName); } +/** + * @brief Set to nullptr result_val and result_func in order to avoid trash. + * + */ auto ASTToObjectVisitor::clean() -> void { this->result_val = nullptr; this->result_func = nullptr; } /** - * @brief - * @return + * @brief Code generation for NumberExprAST. * */ auto ASTToObjectVisitor::visit(NumberExprAST* expr) -> void { @@ -159,8 +161,7 @@ auto ASTToObjectVisitor::visit(NumberExprAST* expr) -> void { } /** - * @brief Stat a variable in the function. - * @return The variable loaded into the llvm. + * @brief Code generation for VariableExprAST. * */ auto ASTToObjectVisitor::visit(VariableExprAST* expr) -> void { @@ -177,8 +178,7 @@ auto ASTToObjectVisitor::visit(VariableExprAST* expr) -> void { } /** - * @brief - * @return + * @brief Code generation for UnaryExprAST. * */ auto ASTToObjectVisitor::visit(UnaryExprAST* expr) -> void { @@ -201,8 +201,7 @@ auto ASTToObjectVisitor::visit(UnaryExprAST* expr) -> void { } /** - * @brief - * @return + * @brief Code generation for BinaryExprAST. * */ auto ASTToObjectVisitor::visit(BinaryExprAST* expr) -> void { @@ -278,8 +277,7 @@ auto ASTToObjectVisitor::visit(BinaryExprAST* expr) -> void { } /** - * @brief Look up the name in the global module table. - * @return + * @brief Code generation for CallExprAST. * */ auto ASTToObjectVisitor::visit(CallExprAST* expr) -> void { @@ -310,7 +308,7 @@ auto ASTToObjectVisitor::visit(CallExprAST* expr) -> void { } /** - * @brief + * @brief Code generation for IfExprAST. */ auto ASTToObjectVisitor::visit(IfExprAST* expr) -> void { expr->Cond.get()->accept(this); @@ -384,6 +382,11 @@ auto ASTToObjectVisitor::visit(IfExprAST* expr) -> void { return; } +/** + * @brief Code generation for ForExprAST. + * + * @param expr A `for` expression. + */ auto ASTToObjectVisitor::visit(ForExprAST* expr) -> void { llvm::Function* TheFunction = this->Builder->GetInsertBlock()->getParent(); @@ -489,8 +492,7 @@ auto ASTToObjectVisitor::visit(ForExprAST* expr) -> void { } /** - * @brief - * @return Return the body computation. + * @brief Code generation for VarExprAST. * */ auto ASTToObjectVisitor::visit(VarExprAST* expr) -> void { @@ -550,8 +552,7 @@ auto ASTToObjectVisitor::visit(VarExprAST* expr) -> void { } /** - * @brief - * @return + * @brief Code generation for PrototypeExprAST. * */ auto ASTToObjectVisitor::visit(PrototypeAST* expr) -> void { @@ -574,8 +575,7 @@ auto ASTToObjectVisitor::visit(PrototypeAST* expr) -> void { } /** - * @brief - * @return + * @brief Code generation for FunctionExprAST. * * Transfer ownership of the prototype to the FunctionProtos map, but * keep a reference to it for use below. @@ -634,7 +634,7 @@ auto ASTToObjectVisitor::visit(FunctionAST* expr) -> void { } /** - * @brief Open a new module. + * @brief Initialize LLVM Module And PassManager. * */ auto ASTToObjectVisitor::InitializeModuleAndPassManager() -> void { @@ -647,7 +647,7 @@ auto ASTToObjectVisitor::InitializeModuleAndPassManager() -> void { } /** - * @brief + * @brief The main loop that walks the AST. * top ::= definition | external | expression | ';' */ auto ASTToObjectVisitor::MainLoop(TreeAST* ast) -> void { @@ -671,7 +671,7 @@ auto ASTToObjectVisitor::MainLoop(TreeAST* ast) -> void { * */ extern "C" DLLEXPORT auto putchard(double X) -> double { - fputc((char) X, stderr); + fputc(static_cast(X), stderr); return 0; } @@ -685,8 +685,9 @@ extern "C" DLLEXPORT auto printd(double X) -> double { } /** - * @brief + * @brief Compile an AST to object file. * + * @param tree_ast The AST tree object. */ auto compile(TreeAST* tree_ast) -> void { auto codegen = new ASTToObjectVisitor(); @@ -768,7 +769,7 @@ auto compile(TreeAST* tree_ast) -> void { } /** - * @brief + * @brief Open the Arx shell. * */ auto open_shell() -> void { diff --git a/src/codegen/ast-to-output.cpp b/src/codegen/ast-to-stdout.cpp similarity index 93% rename from src/codegen/ast-to-output.cpp rename to src/codegen/ast-to-stdout.cpp index f5ee87d..cbcd499 100644 --- a/src/codegen/ast-to-output.cpp +++ b/src/codegen/ast-to-stdout.cpp @@ -1,4 +1,4 @@ -#include "ast-to-output.h" +#include "ast-to-stdout.h" #include #include "parser.h" @@ -21,7 +21,8 @@ class ASTToOutputVisitor : public Visitor { virtual void visit(VarExprAST*) override; virtual void visit(PrototypeAST*) override; virtual void visit(FunctionAST*) override; - virtual void clean() override{}; + + virtual void clean() override {} auto indentation() -> std::string { std::string _indent(this->indent, ' '); @@ -30,13 +31,13 @@ class ASTToOutputVisitor : public Visitor { auto set_annotation(std::string annotation) -> void { this->annotation = annotation; - }; + } auto get_annotation() -> std::string { std::string _anno = this->annotation; this->annotation = ""; return _anno; - }; + } }; void ASTToOutputVisitor::visit(NumberExprAST* expr) { @@ -173,14 +174,24 @@ void ASTToOutputVisitor::visit(ForExprAST* expr) { void ASTToOutputVisitor::visit(VarExprAST* expr) { // TODO: implement it - std::cout << "(VarExprAST" - << ")" << std::endl; + std::cout << "(VarExprAST " << std::endl; + this->indent += INDENT_SIZE; + + for (auto var_expr = expr->VarNames.begin(); + var_expr != expr->VarNames.end(); + ++var_expr) { + var_expr->second->accept(this); + std::cout << "," << std::endl; + } + + this->indent -= INDENT_SIZE; + + std::cout << ")" << std::endl; } void ASTToOutputVisitor::visit(PrototypeAST* expr) { // TODO: implement it - std::cout << "(PrototypeAST" - << ")" << std::endl; + std::cout << "(PrototypeAST " << expr->Name << ")" << std::endl; } void ASTToOutputVisitor::visit(FunctionAST* expr) { diff --git a/src/codegen/ast-to-output.h b/src/codegen/ast-to-stdout.h similarity index 100% rename from src/codegen/ast-to-output.h rename to src/codegen/ast-to-stdout.h diff --git a/src/error.h b/src/error.h index 203cfd4..1a03fa3 100644 --- a/src/error.h +++ b/src/error.h @@ -5,8 +5,7 @@ namespace llvm { /** - * @brief - * "llvm/IR/Value.h" + * @brief "llvm/IR/Value.h" * */ class Value; diff --git a/src/io.cpp b/src/io.cpp index 63212f8..50e12ae 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -12,8 +12,8 @@ std::string OUTPUT_FILE{""}; bool INPUT_FROM_STDIN = false; /** - * @brief - * @return + * @brief Get a char from the buffer of from the default input. + * @return An integer represenation of a char from the buffer. * */ auto get_char() -> int { @@ -24,7 +24,7 @@ auto get_char() -> int { } /** - * @brief + * @brief Copy the file content to the buffer. * */ auto file_to_buffer(std::string filename) -> void { @@ -41,7 +41,7 @@ auto file_to_buffer(std::string filename) -> void { } /** - * @brief + * @brief Copy the given string to the buffer. * */ auto string_to_buffer(std::string value) -> void { @@ -51,7 +51,7 @@ auto string_to_buffer(std::string value) -> void { } /** - * @brief + * @brief Load the content file or the standard input to the buffer. * */ auto load_input_to_buffer() -> void { diff --git a/src/jit.h b/src/jit.h index 1fcdada..7496b5a 100644 --- a/src/jit.h +++ b/src/jit.h @@ -58,9 +58,9 @@ namespace llvm { public: /** - * @param ES - * @param JTMB - * @param DL + * @param ES ExecutionSession + * @param JTMB JITTargetMachineBuilder + * @param DL DataLayout */ ArxJIT( std::unique_ptr ES, diff --git a/src/lexer.cpp b/src/lexer.cpp index 883aafb..a545b3b 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -7,8 +7,6 @@ #include "io.h" #include "lexer.h" -std::stringstream buffer; - SourceLocation Lexer::CurLoc; std::string Lexer::IdentifierStr = ""; // Filled in if tok_identifier @@ -17,9 +15,9 @@ SourceLocation Lexer::LexLoc; int Lexer::CurTok = tok_not_initialized; /** - * @brief - * @param Tok - * @return + * @brief Get the Token name. + * @param Tok The token + * @return Token name * */ auto Lexer::getTokName(int Tok) -> std::string { @@ -55,13 +53,13 @@ auto Lexer::getTokName(int Tok) -> std::string { case tok_const: return "const"; } - return std::string(1, (char) Tok); + return std::string(1, static_cast(Tok)); } /** - * @brief - * @param c - * @return + * @brief Check if given character is a valid first identifier character. + * @param c A single character for checking the token + * @return true if the token is valid, otherwise, false. * */ static auto is_identifier_first_char(char c) -> bool { @@ -69,9 +67,9 @@ static auto is_identifier_first_char(char c) -> bool { } /** - * @brief - * @param c - * @return + * @brief Check if the given character is a valid identifier char. + * @param c Given character from a token. + * @return true if the is a valid character, otherwise, false. * */ static auto is_identifier_char(char c) -> bool { @@ -79,8 +77,8 @@ static auto is_identifier_char(char c) -> bool { } /** - * @brief - * @return + * @brief advance the token from the buffer. + * @return Token in integer form. * */ auto Lexer::advance() -> int { @@ -96,7 +94,7 @@ auto Lexer::advance() -> int { } /** - * @brief + * @brief Get the next token. * @return Return the next token from standard input. * */ @@ -105,14 +103,15 @@ auto Lexer::gettok() -> int { // Skip any whitespace. while (isspace(LastChar)) { - LastChar = (char) Lexer::advance(); + LastChar = static_cast(Lexer::advance()); } Lexer::CurLoc = Lexer::LexLoc; if (is_identifier_first_char(LastChar)) { - Lexer::IdentifierStr = (char) LastChar; - while (is_identifier_char((LastChar = (char) Lexer::advance()))) { + Lexer::IdentifierStr = static_cast(LastChar); + while ( + is_identifier_char((LastChar = static_cast(Lexer::advance())))) { Lexer::IdentifierStr += LastChar; } @@ -153,8 +152,8 @@ auto Lexer::gettok() -> int { if (isdigit(LastChar) || LastChar == '.') { std::string NumStr; do { - NumStr += (char) LastChar; - LastChar = (char) Lexer::advance(); + NumStr += static_cast(LastChar); + LastChar = static_cast(Lexer::advance()); } while (isdigit(LastChar) || LastChar == '.'); Lexer::NumVal = strtod(NumStr.c_str(), nullptr); @@ -164,7 +163,7 @@ auto Lexer::gettok() -> int { // Comment until end of line. if (LastChar == '#') { do { - LastChar = advance(); + LastChar = static_cast(Lexer::advance()); } while (LastChar != EOF && LastChar != '\n' && LastChar != '\r'); if (LastChar != EOF) { @@ -179,14 +178,13 @@ auto Lexer::gettok() -> int { // Otherwise, just return the character as its ascii value. int ThisChar = LastChar; - LastChar = Lexer::advance(); + LastChar = static_cast(Lexer::advance()); return ThisChar; } /** * @brief Provide a simple token buffer. * @return - * CurTok is the current token the parser is looking at. * getNextToken reads another token from the lexer and updates * CurTok with its results. diff --git a/src/main.cpp b/src/main.cpp index 7c9c755..43fbbf7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ // #include "codegen/ast-to-llvm.h" #include "codegen/ast-to-object.h" -#include "codegen/ast-to-output.h" +#include "codegen/ast-to-stdout.h" #include "io.h" #include "parser.h" @@ -34,32 +34,32 @@ extern std::string OUTPUT_FILE; extern bool INPUT_FROM_STDIN; /** - * @brief - * @param count + * @brief Open the Arx shell. + * @param count An internal value from CLI11. * */ -auto main_open_shell(int count) -> void { +auto main_open_shell(__attribute__((unused)) int count) -> void { INPUT_FROM_STDIN = true; open_shell(); exit(0); } /** - * @brief - * @param count + * @brief Show the Arx version number. + * @param count An internal value from CLI11. * */ -auto main_show_version(int count) { +auto main_show_version(__attribute__((unused)) int count) -> void { load_input_to_buffer(); show_version(); exit(0); } /** - * @brief - * + * @brief Show the AST for the given source. + * @param count An internal value from CLI11. */ -auto main_show_ast(int count) -> void { +auto main_show_ast(__attribute__((unused)) int count) -> void { load_input_to_buffer(); TreeAST* ast = Parser::parse(); print_ast(ast); @@ -67,7 +67,7 @@ auto main_show_ast(int count) -> void { } /** - * @brief + * @brief Compile the given source code. * */ auto main_compile() -> void { @@ -78,10 +78,10 @@ auto main_compile() -> void { } /** - * @brief - * @param argc - * @param argv - * @return + * @brief The main function. + * @param argc used by CLI11. + * @param argv used by CLI11. + * @return exit code. * */ auto main(int argc, const char* argv[]) -> int { diff --git a/src/parser.cpp b/src/parser.cpp index 71ebae7..8100aa4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -76,7 +76,7 @@ void ExprAST::accept(Visitor* visitor) { /** * @brief Get the precedence of the pending binary operator token. - * @return + * @return The token precedence. * */ auto Parser::GetTokPrecedence() -> int { @@ -93,18 +93,18 @@ auto Parser::GetTokPrecedence() -> int { } /** - * @brief + * @brief Parse the number expression. * @return * numberexpr ::= number */ std::unique_ptr Parser::ParseNumberExpr() { auto Result = std::make_unique(Lexer::NumVal); Lexer::getNextToken(); // consume the number - return std::move(Result); + return Result; } /** - * @brief + * @brief Parse the parenthesis expression. * @return * parenexpr ::= '(' expression ')' */ @@ -123,7 +123,7 @@ std::unique_ptr Parser::ParseParenExpr() { } /** - * @brief + * @brief Parse the identifier expression. * @return * identifierexpr * ::= identifier @@ -170,7 +170,7 @@ std::unique_ptr Parser::ParseIdentifierExpr() { } /** - * @brief + * @brief Parse the `if` expression. * @return * ifexpr ::= 'if' expression 'then' expression 'else' expression */ @@ -222,7 +222,7 @@ std::unique_ptr Parser::ParseIfExpr() { } /** - * @brief + * @brief Parse the `for` expression. * @return * forexpr ::= 'for' identifier '=' expr ',' expr (',' expr)? 'in' expression */ @@ -284,7 +284,7 @@ std::unique_ptr Parser::ParseForExpr() { } /** - * @brief + * @brief Parse the `var` declaration expression. * @return * varexpr ::= 'var' identifier ('=' expression)? * (',' identifier ('=' expression)?)* 'in' expression @@ -343,7 +343,7 @@ std::unique_ptr Parser::ParseVarExpr() { } /** - * @brief + * @brief Parse the primary expression. * @return * primary * ::= identifierexpr @@ -382,7 +382,7 @@ std::unique_ptr Parser::ParsePrimary() { } /** - * @brief + * @brief Parse a unary expression. * @return * unary * ::= primary @@ -405,9 +405,9 @@ std::unique_ptr Parser::ParseUnary() { } /** - * @brief - * @param ExprPrec - * @param LHS + * @brief Parse a binary expression. + * @param ExprPrec Expression Pression (deprecated) + * @param LHS Left hand side Expression * @return * binoprhs * ::= ('+' unary)* @@ -452,7 +452,7 @@ std::unique_ptr Parser::ParseBinOpRHS( } /** - * @brief + * @brief Parse an expression. * @return * expression * ::= unary binoprhs @@ -468,7 +468,7 @@ std::unique_ptr Parser::ParseExpression() { } /** - * @brief + * @brief Parse an extern prototype expression. * @return * prototype * ::= id '(' id* ')' @@ -511,7 +511,7 @@ std::unique_ptr Parser::ParseExternPrototype() { } /** - * @brief + * @brief Parse the prototype expression. * @return * prototype * ::= id '(' id* ')' @@ -561,7 +561,7 @@ std::unique_ptr Parser::ParsePrototype() { } /** - * @brief + * @brief Parse the function definition expression. * @return * definition ::= 'function' prototype expression */ @@ -579,7 +579,7 @@ std::unique_ptr Parser::ParseDefinition() { } /** - * @brief + * @brief Parse the top level expression. * @return * toplevelexpr ::= expression */ @@ -595,7 +595,7 @@ std::unique_ptr Parser::ParseTopLevelExpr() { } /** - * @brief + * @brief Parse the extern expression; * @return * external ::= 'extern' prototype */ @@ -621,13 +621,13 @@ auto Parser::parse() -> TreeAST* { // ignore top-level semicolons. break; case tok_function: - ast->nodes.emplace_back(std::move(Parser::ParseDefinition())); + ast->nodes.emplace_back(Parser::ParseDefinition()); break; case tok_extern: - ast->nodes.emplace_back(std::move(Parser::ParseExtern())); + ast->nodes.emplace_back(Parser::ParseExtern()); break; default: - ast->nodes.emplace_back(std::move(Parser::ParseTopLevelExpr())); + ast->nodes.emplace_back(Parser::ParseTopLevelExpr()); break; } } diff --git a/src/parser.h b/src/parser.h index 4e55c87..358aa7e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -58,7 +58,7 @@ class ExprAST { SourceLocation Loc; /** - * @param Loc + * @param Loc The token location */ ExprAST(SourceLocation Loc = Lexer::CurLoc) : Loc(Loc) { this->kind = ExprKind::GenericKind; @@ -84,10 +84,6 @@ class ExprAST { */ class NumberExprAST : public ExprAST { public: - /** - * - * @return - */ double Val; NumberExprAST(double Val) : Val(Val) { @@ -104,8 +100,8 @@ class VariableExprAST : public ExprAST { std::string Name; /** - * @param Loc - * @param Name + * @param Loc The token location + * @param Name The variable name */ VariableExprAST(SourceLocation Loc, std::string Name) : ExprAST(Loc), Name(std::move(Name)) { @@ -127,8 +123,8 @@ class UnaryExprAST : public ExprAST { std::unique_ptr Operand; /** - * @param Opcode - * @param Operand + * @param Opcode The operator code + * @param Operand The operand expression */ UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) { @@ -146,10 +142,10 @@ class BinaryExprAST : public ExprAST { std::unique_ptr LHS, RHS; /** - * @param Loc - * @param Op - * @param LHS - * @param RHS + * @param Loc The token location + * @param Op The operator + * @param LHS The left hand side expression + * @param RHS The right hand side expression */ BinaryExprAST( SourceLocation Loc, @@ -171,9 +167,9 @@ class CallExprAST : public ExprAST { std::vector> Args; /** - * @param Loc - * @param Callee - * @param Args + * @param Loc The token location + * @param Callee The function name + * @param Args The function arguments */ CallExprAST( SourceLocation Loc, @@ -193,10 +189,10 @@ class IfExprAST : public ExprAST { std::unique_ptr Cond, Then, Else; /** - * @param Loc - * @param Cond - * @param Then - * @param Else + * @param Loc The token location + * @param Cond The conditional expression + * @param Then The `then` branch expression + * @param Else The `else` branch expression */ IfExprAST( SourceLocation Loc, @@ -222,11 +218,11 @@ class ForExprAST : public ExprAST { std::unique_ptr Start, End, Step, Body; /** - * @param VarName - * @param Start - * @param End - * @param Step - * @param Body + * @param VarName The variable name + * @param Start The `start` parameter for the loop + * @param End The `end` parameter for the loop + * @param Step The incremental value for the loop + * @param Body The body of the for the loop. */ ForExprAST( std::string VarName, @@ -254,8 +250,8 @@ class VarExprAST : public ExprAST { std::unique_ptr Body; /** - * @param VarNames - * @param Body + * @param VarNames Variable names + * @param Body Body of the variables */ VarExprAST( std::vector>> VarNames, @@ -278,9 +274,9 @@ class PrototypeAST : public ExprAST { int Line; /** - * @param Loc - * @param Name - * @param Args + * @param Loc The token location + * @param Name The prototype name + * @param Args The prototype arguments */ PrototypeAST( SourceLocation Loc, std::string Name, std::vector Args) @@ -308,8 +304,8 @@ class FunctionAST : public ExprAST { std::unique_ptr Body; /** - * @param Proto - * @param Body + * @param Proto The function prototype + * @param Body The function body */ FunctionAST( std::unique_ptr Proto, std::unique_ptr Body) diff --git a/src/utils.cpp b/src/utils.cpp index 1f855d7..0cea0a4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -8,10 +8,10 @@ extern std::string ARX_VERSION; /** - * @brief - * @param O - * @param size - * @return + * @brief Ident the output. + * @param O Buffer used by the indentation. + * @param size Buffer size. + * @return a buffer with the indentation with given width. * */ auto indent(llvm::raw_ostream& O, int size) -> llvm::raw_ostream& { @@ -19,7 +19,7 @@ auto indent(llvm::raw_ostream& O, int size) -> llvm::raw_ostream& { } /** - * @brief + * @brief Show the Arx version. * */ auto show_version() -> void { diff --git a/tests/main-objects/print-star.cpp b/tests/main-objects/print-star.cpp index a600b06..5e99b77 100644 --- a/tests/main-objects/print-star.cpp +++ b/tests/main-objects/print-star.cpp @@ -5,7 +5,7 @@ double print_star(double); } extern "C" auto putchard(double X) -> double { - fputc((char) X, stderr); + fputc(static_cast(X), stderr); return 0; }