Skip to content

Commit

Permalink
format to 80 columns for terminal display
Browse files Browse the repository at this point in the history
  • Loading branch information
cromerc committed Feb 21, 2023
1 parent 09925b5 commit adc5042
Show file tree
Hide file tree
Showing 30 changed files with 412 additions and 194 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
BreakStringLiterals: false
ColumnLimit: 120
ColumnLimit: 80
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand Down Expand Up @@ -167,7 +167,7 @@ RawStringFormats:
- PROTO
CanonicalDelimiter: pb
ReferenceAlignment: Left
ReflowComments: false
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
Expand Down
9 changes: 6 additions & 3 deletions src/ast/call_expression_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace obelisk
/**
* @brief Get the callee.
*
* @return std::string Returns the name of the function being called.
* @return std::string Returns the name of the function being
* called.
*/
std::string getCallee();

Expand All @@ -45,7 +46,8 @@ namespace obelisk
/**
* @brief Get the arguments being used by the function.
*
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an AST expression containing the args.
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an
* AST expression containing the args.
*/
std::vector<std::unique_ptr<ExpressionAST>> getArgs();

Expand All @@ -63,7 +65,8 @@ namespace obelisk
* @param[in] callee The function to call.
* @param[in] args The args to pass into the function.
*/
CallExpressionAST(const std::string &callee, std::vector<std::unique_ptr<ExpressionAST>> args) :
CallExpressionAST(const std::string &callee,
std::vector<std::unique_ptr<ExpressionAST>> args) :
callee_(callee),
args_(std::move(args))
{
Expand Down
3 changes: 2 additions & 1 deletion src/ast/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace obelisk
* @brief Log an AST expression error.
*
* @param[in] str The error message.
* @return std::unique_ptr<ExpressionAST> Returns the AST expression that caused the error.
* @return std::unique_ptr<ExpressionAST> Returns the AST expression that
* caused the error.
*/
std::unique_ptr<ExpressionAST> LogError(const char *str);

Expand Down
3 changes: 2 additions & 1 deletion src/ast/expression_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace obelisk
/**
* @brief Generate LLVM IR code based on the AST expression.
*
* @return llvm::Value* Returns the LLVM code value from the expression.
* @return llvm::Value* Returns the LLVM code value from the
* expression.
*/
virtual llvm::Value *codegen() = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion src/ast/function_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ llvm::Function *obelisk::FunctionAST::codegen()
return nullptr;
}

llvm::BasicBlock *bB = llvm::BasicBlock::Create(*TheContext, "entry", theFunction);
llvm::BasicBlock *bB
= llvm::BasicBlock::Create(*TheContext, "entry", theFunction);
Builder->SetInsertPoint(bB);

NamedValues.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/ast/function_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ namespace obelisk
* @param[in] prototype The prototype of the function.
* @param[in] body The body of the function.
*/
FunctionAST(std::unique_ptr<PrototypeAST> prototype, std::unique_ptr<ExpressionAST> body) :
FunctionAST(std::unique_ptr<PrototypeAST> prototype,
std::unique_ptr<ExpressionAST> body) :
prototype_(std::move(prototype)),
body_(std::move(body))
{
Expand Down
13 changes: 10 additions & 3 deletions src/ast/prototype_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@

llvm::Function *obelisk::PrototypeAST::codegen()
{
std::vector<llvm::Type *> doubles(args_.size(), llvm::Type::getDoubleTy(*TheContext));
llvm::FunctionType *FT = llvm::FunctionType::get(llvm::Type::getDoubleTy(*TheContext), doubles, false);
std::vector<llvm::Type *> doubles(args_.size(),
llvm::Type::getDoubleTy(*TheContext));
llvm::FunctionType *FT
= llvm::FunctionType::get(llvm::Type::getDoubleTy(*TheContext),
doubles,
false);

llvm::Function *F = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, name_, obelisk::TheModule.get());
llvm::Function *F = llvm::Function::Create(FT,
llvm::Function::ExternalLinkage,
name_,
obelisk::TheModule.get());

unsigned idx = 0;
for (auto &arg : F->args())
Expand Down
3 changes: 2 additions & 1 deletion src/ast/prototype_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace obelisk
* @param[in] name The name of the prototype.
* @param[in] args The arguments the prototype accepts.
*/
PrototypeAST(const std::string& name, std::vector<std::string> args) :
PrototypeAST(const std::string& name,
std::vector<std::string> args) :
name_(name),
args_(std::move(args))
{
Expand Down
3 changes: 2 additions & 1 deletion src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ obelisk::Lexer::Lexer(const std::string& sourceFile)
fileStream_.open(sourceFile, std::ifstream::in);
if (!fileStream_)
{
throw obelisk::LexerException("could not open source file " + sourceFile);
throw obelisk::LexerException(
"could not open source file " + sourceFile);
}
}

Expand Down
21 changes: 14 additions & 7 deletions src/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ namespace obelisk
/**
* @brief Comment the rest of the line.
*
* @param[in] lastChar The char to check to see if it in the end of the line.
* @param[in] lastChar The char to check to see if it in the end of
* the line.
*/
void commentLine(int* lastChar);

public:
/**
* @brief These token represent recognized language keywords and language functionality.
* @brief These token represent recognized language keywords and
* language functionality.
*
*/
enum Token
{
/**
* @brief End of file is returned when the source code is finished.
* @brief End of file is returned when the source code is
* finished.
*
*/
kTokenEof = -1,
Expand All @@ -79,7 +82,8 @@ namespace obelisk
*/
kTokenFact = -2,
/**
* @brief A rule which is a relationship between a new fact a existing fact.
* @brief A rule which is a relationship between a new fact a
* existing fact.
*
*/
kTokenRule = -3,
Expand Down Expand Up @@ -133,14 +137,16 @@ namespace obelisk
* @brief Gets the next token in the source code.
*
* @throws LexerException when an invalid token is found.
* @return int Returns a Token value or char if no known token was found.
* @return int Returns a Token value or char if no known token was
* found.
*/
int getToken();

/**
* @brief Get the last identifier.
*
* @return const std::string& Returns a string that contains the last found identifier.
* @return const std::string& Returns a string that contains the
* last found identifier.
*/
const std::string& getIdentifier();

Expand Down Expand Up @@ -188,7 +194,8 @@ namespace obelisk
/**
* @brief Return the exception's error message.
*
* @return const char* Returns a string containing the error message.
* @return const char* Returns a string containing the error
* message.
*/
const char* what() const noexcept
{
Expand Down
6 changes: 4 additions & 2 deletions src/lib/include/obelisk.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include <string>

/**
* @brief The obelisk namespace contains everything needed to compile obelisk code.
* @brief The obelisk namespace contains everything needed to compile obelisk
* code.
*
*/
namespace obelisk
{
/**
* @brief The obelisk library provides everything needed to consult the KnowledgeBase.
* @brief The obelisk library provides everything needed to consult the
* KnowledgeBase.
*
*/
class Obelisk
Expand Down
32 changes: 24 additions & 8 deletions src/lib/knowledge_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ obelisk::KnowledgeBase::~KnowledgeBase()
void obelisk::KnowledgeBase::enableForeignKeys()
{
char* errmsg;
int result = sqlite3_exec(dbConnection_, "PRAGMA foreign_keys = ON;", NULL, NULL, &errmsg);
int result = sqlite3_exec(dbConnection_,
"PRAGMA foreign_keys = ON;",
NULL,
NULL,
&errmsg);
if (result != SQLITE_OK)
{
if (errmsg)
Expand Down Expand Up @@ -86,7 +90,9 @@ void obelisk::KnowledgeBase::addEntities(std::vector<obelisk::Entity>& entities)
catch (obelisk::DatabaseConstraintException& exception)
{
// ignore unique constraint error
if (std::strcmp(exception.what(), "UNIQUE constraint failed: entity.name") != 0)
if (std::strcmp(exception.what(),
"UNIQUE constraint failed: entity.name")
!= 0)
{
throw;
}
Expand All @@ -105,7 +111,9 @@ void obelisk::KnowledgeBase::addVerbs(std::vector<obelisk::Verb>& verbs)
catch (obelisk::DatabaseConstraintException& exception)
{
// ignore unique constraint error
if (std::strcmp(exception.what(), "UNIQUE constraint failed: verb.name") != 0)
if (std::strcmp(exception.what(),
"UNIQUE constraint failed: verb.name")
!= 0)
{
throw;
}
Expand All @@ -124,7 +132,9 @@ void obelisk::KnowledgeBase::addActions(std::vector<obelisk::Action>& actions)
catch (obelisk::DatabaseConstraintException& exception)
{
// ignore unique constraint error
if (std::strcmp(exception.what(), "UNIQUE constraint failed: action.name") != 0)
if (std::strcmp(exception.what(),
"UNIQUE constraint failed: action.name")
!= 0)
{
throw;
}
Expand Down Expand Up @@ -153,7 +163,8 @@ void obelisk::KnowledgeBase::addFacts(std::vector<obelisk::Fact>& facts)
}
}

void obelisk::KnowledgeBase::addSuggestActions(std::vector<obelisk::SuggestAction>& suggestActions)
void obelisk::KnowledgeBase::addSuggestActions(
std::vector<obelisk::SuggestAction>& suggestActions)
{
for (auto& suggestAction : suggestActions)
{
Expand Down Expand Up @@ -185,7 +196,9 @@ void obelisk::KnowledgeBase::addRules(std::vector<obelisk::Rule>& rules)
catch (obelisk::DatabaseConstraintException& exception)
{
// ignore unique constraint error
if (std::strcmp(exception.what(), "UNIQUE constraint failed: rule.fact, rule.reason") != 0)
if (std::strcmp(exception.what(),
"UNIQUE constraint failed: rule.fact, rule.reason")
!= 0)
{
throw;
}
Expand Down Expand Up @@ -213,7 +226,8 @@ void obelisk::KnowledgeBase::getFact(obelisk::Fact& fact)
fact.selectById(dbConnection_);
}

void obelisk::KnowledgeBase::getSuggestAction(obelisk::SuggestAction& suggestAction)
void obelisk::KnowledgeBase::getSuggestAction(
obelisk::SuggestAction& suggestAction)
{
suggestAction.selectById(dbConnection_);
}
Expand Down Expand Up @@ -245,7 +259,9 @@ void obelisk::KnowledgeBase::updateIsTrue(obelisk::Fact& fact)
fact.updateIsTrue(dbConnection_);
}

void obelisk::KnowledgeBase::getFloat(float& result1, float& result2, double var)
void obelisk::KnowledgeBase::getFloat(float& result1,
float& result2,
double var)
{
result1 = (float) var;
result2 = (float) (var - (double) result1);
Expand Down
Loading

0 comments on commit adc5042

Please sign in to comment.