Clang-format run on whole project
All checks were successful
CI / build-and-test (push) Successful in 54s

This commit is contained in:
Johannes Janssen 2025-04-11 11:25:52 +02:00
parent 78c4afbf3d
commit 0815172912
6 changed files with 69 additions and 97 deletions

View File

@ -4,10 +4,7 @@
std::optional<faust::ApplicationInformation> appInfo;
void faust::setApplicationInformation(faust::ApplicationInformation&& newAppInfo) {
appInfo = newAppInfo;
}
void faust::setApplicationInformation(faust::ApplicationInformation &&newAppInfo) { appInfo = newAppInfo; }
faust::ApplicationInformation faust::getApplicationInformation() {
if (!appInfo.has_value()) {

View File

@ -1,7 +1,7 @@
#pragma once
#include "unicode/unistr.h"
#include "unicode/locid.h"
#include "unicode/unistr.h"
namespace faust {

View File

@ -5,10 +5,9 @@
#include <unicode/msgfmt.h>
faust::String faust::NamespaceAST::toString() const {
String outputString =
u"{"
u"\"astType\":\"Namespace\","
u"\"name\":\"";
String outputString = u"{"
u"\"astType\":\"Namespace\","
u"\"name\":\"";
outputString.append(name);
outputString.append("\",\"content\":[");
@ -16,7 +15,7 @@ faust::String faust::NamespaceAST::toString() const {
for (auto it = statements.begin(); it != statements.end(); ++it) {
outputString.append((*it)->toString());
if (std::next(it) != statements.end()) {
outputString.append(u",");
outputString.append(u",");
}
}
outputString.append(u"]}");
@ -32,8 +31,7 @@ faust::String faust::ImportAST::toString() const {
}
faust::String faust::VariableDeclAST::toString() const {
String outputString =
u"{\"astType\":\"Variable Declaration\",\"name\":\"";
String outputString = u"{\"astType\":\"Variable Declaration\",\"name\":\"";
outputString.append(name);
outputString.append(u"\",\"type\":\"");
@ -43,8 +41,7 @@ faust::String faust::VariableDeclAST::toString() const {
outputString.append(u"\",\"initValue\":");
if (initializationValue.has_value()) {
outputString.append((*initializationValue)->toString());
}
else {
} else {
outputString.append(u"\"__auto__\"");
}
outputString.append(u"}");
@ -58,8 +55,7 @@ faust::String faust::FunctionDeclAST::toString() const {
outputString.append(u"\",\"body\":");
if (body.has_value()) {
outputString.append((*body)->toString());
}
else {
} else {
outputString.append(u"\"__external__\"");
}
outputString.append(u",\"arguments\":[");
@ -68,7 +64,7 @@ faust::String faust::FunctionDeclAST::toString() const {
outputString.append((*it)->toString());
if (std::next(it) != arguments.end()) {
outputString.append(",");
}
}
}
outputString.append("]}");
@ -77,8 +73,7 @@ faust::String faust::FunctionDeclAST::toString() const {
}
faust::String faust::ExpressionBlockAST::toString() const {
String outputString =
u"{\"astType\":\"Expression Block\",\"expressions\":[";
String outputString = u"{\"astType\":\"Expression Block\",\"expressions\":[";
for (auto it = statements.begin(); it != statements.end(); ++it) {
outputString.append((*it)->toString());

View File

@ -22,27 +22,28 @@ enum AbstractSyntaxType {
class AbstractSyntaxNode {
public:
AbstractSyntaxNode(AbstractSyntaxType type, CodePosition position)
: astType(type), position(position) {}
AbstractSyntaxNode(AbstractSyntaxType type, CodePosition position) : astType(type), position(position) {}
virtual ~AbstractSyntaxNode() = default;
virtual String toString() const = 0;
inline AbstractSyntaxType getType() const { return astType; }
inline CodePosition getPosition() const { return position; }
private:
AbstractSyntaxType astType;
CodePosition position;
};
typedef std::unique_ptr<AbstractSyntaxNode> AstNodePtr;
typedef AbstractSyntaxNode* AstNodeWeakPtr;
typedef AbstractSyntaxNode *AstNodeWeakPtr;
class NamespaceAST : public AbstractSyntaxNode {
public:
inline NamespaceAST(CodePosition position, const String& namespaceName, Vector<std::unique_ptr<AbstractSyntaxNode>> &&statements)
: AbstractSyntaxNode(AST_PROGRAM, position)
, name(namespaceName), statements(std::move(statements)) {}
inline NamespaceAST(CodePosition position, const String &namespaceName,
Vector<std::unique_ptr<AbstractSyntaxNode>> &&statements)
: AbstractSyntaxNode(AST_PROGRAM, position), name(namespaceName), statements(std::move(statements)) {}
virtual ~NamespaceAST() = default;
virtual String toString() const override;
private:
String name;
Vector<std::unique_ptr<AbstractSyntaxNode>> statements;
@ -50,42 +51,29 @@ private:
class ImportAST : public AbstractSyntaxNode {
public:
inline ImportAST(CodePosition position, const String &path)
: AbstractSyntaxNode(AST_IMPORT, position)
, path(path) {}
inline ImportAST(CodePosition position, const String &path) : AbstractSyntaxNode(AST_IMPORT, position), path(path) {}
virtual ~ImportAST() = default;
virtual String toString() const override;
private:
String path;
};
class VariableDeclAST : public AbstractSyntaxNode {
public:
inline VariableDeclAST(CodePosition position,
const String &name,
AstNodePtr&& initValue,
const std::optional<String>& typeName,
bool isConstant
)
: AbstractSyntaxNode(AST_VARIABLE_DECL, position)
, name(name)
, type(typeName)
, constant(isConstant)
, initializationValue(std::move(initValue)) {}
inline VariableDeclAST(CodePosition position, const String &name, AstNodePtr &&initValue,
const std::optional<String> &typeName, bool isConstant)
: AbstractSyntaxNode(AST_VARIABLE_DECL, position), name(name), type(typeName), constant(isConstant),
initializationValue(std::move(initValue)) {}
inline VariableDeclAST(CodePosition position,
const String &name,
const std::optional<String>& typeName,
bool isConstant
)
: AbstractSyntaxNode(AST_VARIABLE_DECL, position)
, name(name)
, type(typeName)
, constant(isConstant)
, initializationValue(std::nullopt) {}
inline VariableDeclAST(CodePosition position, const String &name, const std::optional<String> &typeName,
bool isConstant)
: AbstractSyntaxNode(AST_VARIABLE_DECL, position), name(name), type(typeName), constant(isConstant),
initializationValue(std::nullopt) {}
virtual ~VariableDeclAST() = default;
virtual String toString() const override;
private:
String name;
// If type is explicitly declared store it here
@ -96,19 +84,16 @@ private:
class FunctionDeclAST : public AbstractSyntaxNode {
public:
inline FunctionDeclAST(CodePosition position, const String &name, Vector<AstNodePtr> &&arguments, AstNodePtr&& body)
: AbstractSyntaxNode(AST_FUNCTION_DECL, position)
, name(name)
, arguments(std::move(arguments))
, body(std::move(body)) {}
inline FunctionDeclAST(CodePosition position, const String &name, Vector<AstNodePtr> &&arguments, AstNodePtr &&body)
: AbstractSyntaxNode(AST_FUNCTION_DECL, position), name(name), arguments(std::move(arguments)),
body(std::move(body)) {}
inline FunctionDeclAST(CodePosition position, const String &name, Vector<AstNodePtr> &&arguments)
: AbstractSyntaxNode(AST_FUNCTION_DECL, position)
, name(name)
, arguments(std::move(arguments)) {}
: AbstractSyntaxNode(AST_FUNCTION_DECL, position), name(name), arguments(std::move(arguments)) {}
virtual ~FunctionDeclAST() = default;
virtual String toString() const override;
private:
String name;
Vector<AstNodePtr> arguments;
@ -117,12 +102,13 @@ private:
class ExpressionBlockAST : public AbstractSyntaxNode {
public:
inline ExpressionBlockAST(CodePosition position, Vector<AstNodePtr> &&statements, std::optional<AstNodePtr>&& finalStatement)
: AbstractSyntaxNode(AST_PROGRAM, position)
, finalStatement(std::move(finalStatement))
, statements(std::move(statements)) {}
inline ExpressionBlockAST(CodePosition position, Vector<AstNodePtr> &&statements,
std::optional<AstNodePtr> &&finalStatement)
: AbstractSyntaxNode(AST_PROGRAM, position), finalStatement(std::move(finalStatement)),
statements(std::move(statements)) {}
virtual ~ExpressionBlockAST() = default;
virtual String toString() const override;
private:
std::optional<AstNodePtr> finalStatement;
Vector<AstNodePtr> statements;

View File

@ -4,8 +4,8 @@
#include "faust-lib/common/core.h"
#include "faust-lib/parser/faustLexer.h"
#include "faust-lib/parser/abstractSyntaxNodes.h"
#include "faust-lib/parser/faustLexer.h"
#include "faust-lib/parser/lexer.h"
#include <string>
#include <unicode/utypes.h>
@ -25,24 +25,22 @@ struct ParserError {
String message;
};
inline ParserError createParserError(CodePosition position, const String &message) {
return {position, message};
}
inline ParserError createParserError(CodePosition position, const String &message) { return {position, message}; }
inline ParserError createUnexpectedTokenError(CodePosition position, faust::FaustTokens &token) {
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString pattern = u"Unexpected token: {0}";
icu::MessageFormat msgFormat(pattern, icu::Locale::getDefault(), status);
// Create argument with token value
icu::UnicodeString tokenStr = icu::UnicodeString::fromUTF8(std::to_string((static_cast<u32>(token))));
icu::Formattable args[] = {tokenStr};
// Format the message
icu::UnicodeString result;
icu::FieldPosition fieldPos;
msgFormat.format(args, 1, result, fieldPos, status);
return {position, result};
}
@ -65,9 +63,9 @@ private:
u64 position;
/// Helper functions
FaustLexeme& advance();
FaustLexeme &advance();
bool hasNext();
FaustLexeme& peek();
FaustLexeme &peek();
static String extractStringToken(String base);
/// Parsing states
@ -82,7 +80,6 @@ private:
// If the expression is not followed by a semicolon expect it to be block finalization.
// Errors are also treated as final expressions.
ExpressionParserResult parseExpression();
};
} // namespace faust

View File

@ -2,34 +2,31 @@
#include "faust-lib/parser/parser.h"
const icu::UnicodeString testText =
"import \"test\"; // Import some file \n"
"/* Multiline comment \n"
"Some multiline shenanigans */ \n"
"// Now going into a method \n"
"fn test /*before parameters */(const a, mut b /* implicitly null */) { // EOL\n"
" // first line of function \n"
" const c = 0; // some comment \n"
" mut d = 0; /* some comment */ \n"
" if (a == b) { // some comment \n"
" d = 1; \n"
" } else { \n"
" d = 2; \n"
" } \n"
" while (a == b) { // some comment \n"
" d = 3; \n"
" } \n"
" const strWithoutComment = \"//Hello/* world */\"; // some comment \n"
" check(a == b); // some comment \n"
" force(a == b); // some comment \n"
" return a + b; \n"
"} \n";
const icu::UnicodeString testText = "import \"test\"; // Import some file \n"
"/* Multiline comment \n"
"Some multiline shenanigans */ \n"
"// Now going into a method \n"
"fn test /*before parameters */(const a, mut b /* implicitly null */) { // EOL\n"
" // first line of function \n"
" const c = 0; // some comment \n"
" mut d = 0; /* some comment */ \n"
" if (a == b) { // some comment \n"
" d = 1; \n"
" } else { \n"
" d = 2; \n"
" } \n"
" while (a == b) { // some comment \n"
" d = 3; \n"
" } \n"
" const strWithoutComment = \"//Hello/* world */\"; // some comment \n"
" check(a == b); // some comment \n"
" force(a == b); // some comment \n"
" return a + b; \n"
"} \n";
class ParserTestInterface {
class ParserTestInterface {
public:
static faust::Vector<faust::FaustLexeme> getTokens(faust::Parser &parser) {
return parser.state;
}
static faust::Vector<faust::FaustLexeme> getTokens(faust::Parser &parser) { return parser.state; }
};
TEST(CommentFiltering, Parser) {