hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
Formatter Class Reference

#include <formatter.hpp>

Collaboration diagram for Formatter:

Public Member Functions

 Formatter (std::wostream &os, FormatOption option)
 
 Formatter (std::wostream &os, FormatOption option, vec< lexer::Comment > comments)
 
void format (const lexer::token &token)
 
void format (basicLiterals *node)
 
void format (identifier *node)
 
void format (identifierWithTypeSpec *node)
 
void format (defTemplateArgSpec *node)
 
void format (defTemplateArg *node)
 
void format (templateArgSpec *node)
 
void format (templateArg *node)
 
void format (invocationArguments *node)
 
void format (definitionArguments *node)
 
void format (funcTypeSpec *node)
 
void format (typeSpec *node)
 
void format (decltypeExpr *node)
 
void format (subscript *node)
 
void format (identifierWithTemplateArg *node)
 
void format (identifierWithDefTemplateArg *node)
 
void format (subscriptExpr *node)
 
void format (memberExpr *node)
 
void format (primary *node)
 
void format (uniqueExpr *node)
 
void format (mulExpr *node)
 
void format (addExpr *node)
 
void format (shiftExpr *node)
 
void format (relationalExpr *node)
 
void format (equalityExpr *node)
 
void format (andExpr *node)
 
void format (exclusiveExpr *node)
 
void format (inclusiveExpr *node)
 
void format (logicalAndExpr *node)
 
void format (logicalOrExpr *node)
 
void format (rExpr *node)
 
void format (codeBlock *node)
 
void format (useStmt *node)
 
void format (funcDefStmt *node)
 
void format (interfaceDefInnerPair *node)
 
void format (interfaceDefInner *node)
 
void format (interfaceDefStmt *node)
 
void format (structDefInnerPair *node)
 
void format (structDefInner *node)
 
void format (structDefStmt *node)
 
void format (dataStructDefStmt *node)
 
void format (implInnerPair *node)
 
void format (implInner *node)
 
void format (implStmt *node)
 
void format (letAssignmentPair *node)
 
void format (letStmt *node)
 
void format (globalStmt *node)
 
void format (ifStmt *node)
 
void format (whileStmt *node)
 
void format (forStmt *node)
 
void format (forEachStmt *node)
 
void format (returnStmt *node)
 
void format (continueStmt *node)
 
void format (breakStmt *node)
 
void format (inCodeBlockStmt *node)
 
void format (leftExpr *node)
 
void format (externModuleAccessExpression *node)
 
void format (exportDecl *node)
 
void format (importDecl *node)
 
void format (importInner *node)
 
void format (throwStmt *node)
 
void format (catchParam *node)
 
void format (tryCatchStmt *node)
 
void format (dynCastExpression *node)
 
void format (typeIdExpression *node)
 
void format (newExpression *node)
 
void format (abstractExpr *node)
 
void format (lambdaExpr *node)
 
void format (unnamedDefinitionArguments *node)
 
void format (marcoPair *node)
 
void format (marcoDescriptor *node)
 
void format (typeAliasStmt *node)
 
void format (finalizerDef *node)
 
void format (finalizerDecl *node)
 
void format (funcExpr *node)
 
void format (letAssignmentPairLHS *node)
 
void format (enumerationDefinition *node)
 
void format (enumerationPair *node)
 
void format (bracedInitalizerList *node)
 
void format (hoshiModule *node)
 
void format (innerMethodDecl *node)
 
void format (innerMethodDef *node)
 
void format (constructorDecl *node)
 
void format (constructorDef *node)
 
void format (yieldStmt *node)
 
void format (conceptStmt *node)
 
void format (satisfyStmt *node)
 
void format (satisfyClause *node)
 
void format (conceptDefinition *node)
 
void format (lambdaCapture *node)
 

Public Attributes

FormatOption option
 
std::wostream & os
 
vec< lexer::Commentcomments
 

Private Member Functions

void indent ()
 
void newLine ()
 
void write (const yoi::wstr &s)
 
bool printComments (AST *node)
 
bool printComments (uint64_t line, uint64_t col)
 
bool willFit (invocationArguments *node)
 

Private Attributes

size_t indentLevel {0}
 
size_t currentColumn {0}
 
size_t lastCommentIdx {0}
 
uint64_t lastLine {0}
 

Detailed Description

Definition at line 31 of file formatter.hpp.

Constructor & Destructor Documentation

◆ Formatter() [1/2]

Formatter ( std::wostream &  os,
FormatOption  option 
)

Definition at line 314 of file formatter.cpp.

◆ Formatter() [2/2]

Formatter ( std::wostream &  os,
FormatOption  option,
vec< lexer::Comment comments 
)

Definition at line 316 of file formatter.cpp.

Member Function Documentation

◆ format() [1/90]

void format ( abstractExpr node)

◆ format() [2/90]

void format ( addExpr node)

◆ format() [3/90]

void format ( andExpr node)

◆ format() [4/90]

void format ( basicLiterals node)

Definition at line 386 of file formatter.cpp.

References basicLiterals::node.

◆ format() [5/90]

void format ( bracedInitalizerList node)

Definition at line 1146 of file formatter.cpp.

References bracedInitalizerList::exprs.

◆ format() [6/90]

void format ( breakStmt node)

Definition at line 717 of file formatter.cpp.

◆ format() [7/90]

void format ( catchParam node)

Definition at line 978 of file formatter.cpp.

References catchParam::block, catchParam::name, and catchParam::type.

◆ format() [8/90]

void format ( codeBlock node)

Definition at line 633 of file formatter.cpp.

References FormatOption::NewLine, and codeBlock::stmts.

◆ format() [9/90]

◆ format() [10/90]

◆ format() [11/90]

void format ( const lexer::token token)

Definition at line 370 of file formatter.cpp.

References yoi::formatToken().

Referenced by main(), and Formatter::willFit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format() [12/90]

void format ( constructorDecl node)

Definition at line 1208 of file formatter.cpp.

References constructorDecl::args, and constructorDecl::tempArgs.

◆ format() [13/90]

void format ( constructorDef node)

◆ format() [14/90]

void format ( continueStmt node)

Definition at line 712 of file formatter.cpp.

◆ format() [15/90]

void format ( dataStructDefStmt node)

Definition at line 852 of file formatter.cpp.

References dataStructDefStmt::id, and dataStructDefStmt::inner.

◆ format() [16/90]

void format ( decltypeExpr node)

Definition at line 1229 of file formatter.cpp.

References decltypeExpr::expr.

◆ format() [17/90]

void format ( definitionArguments node)

Definition at line 460 of file formatter.cpp.

References definitionArguments::spec.

◆ format() [18/90]

void format ( defTemplateArg node)

Definition at line 412 of file formatter.cpp.

References defTemplateArg::spec.

◆ format() [19/90]

void format ( defTemplateArgSpec node)

Definition at line 403 of file formatter.cpp.

References defTemplateArgSpec::id, and defTemplateArgSpec::satisfyCondition.

◆ format() [20/90]

void format ( dynCastExpression node)

Definition at line 1002 of file formatter.cpp.

References dynCastExpression::expr, and dynCastExpression::type.

◆ format() [21/90]

void format ( enumerationDefinition node)

Definition at line 1117 of file formatter.cpp.

References enumerationDefinition::name, and enumerationDefinition::values.

◆ format() [22/90]

void format ( enumerationPair node)

Definition at line 1137 of file formatter.cpp.

References yoi::formatToken(), lexer::token::kind, enumerationPair::name, lexer::token::unknown, and enumerationPair::value.

Here is the call graph for this function:

◆ format() [23/90]

void format ( equalityExpr node)

◆ format() [24/90]

void format ( exclusiveExpr node)

◆ format() [25/90]

void format ( exportDecl node)

Definition at line 946 of file formatter.cpp.

References exportDecl::as, exportDecl::attrs, yoi::formatToken(), and exportDecl::from.

Here is the call graph for this function:

◆ format() [26/90]

void format ( externModuleAccessExpression node)

Definition at line 625 of file formatter.cpp.

References externModuleAccessExpression::terms.

◆ format() [27/90]

void format ( finalizerDecl node)

Definition at line 1091 of file formatter.cpp.

◆ format() [28/90]

void format ( finalizerDef node)

Definition at line 1085 of file formatter.cpp.

References finalizerDef::block.

◆ format() [29/90]

void format ( forEachStmt node)

Definition at line 693 of file formatter.cpp.

References forEachStmt::block, forEachStmt::container, and forEachStmt::var.

◆ format() [30/90]

void format ( forStmt node)

Definition at line 681 of file formatter.cpp.

References forStmt::afterStmt, forStmt::block, forStmt::cond, and forStmt::initStmt.

◆ format() [31/90]

void format ( funcDefStmt node)

Definition at line 753 of file formatter.cpp.

References funcDefStmt::args, funcDefStmt::attrs, funcDefStmt::block, yoi::formatToken(), funcDefStmt::id, and funcDefStmt::resultType.

Here is the call graph for this function:

◆ format() [32/90]

void format ( funcExpr node)

Definition at line 1096 of file formatter.cpp.

References funcExpr::args, and funcExpr::name.

◆ format() [33/90]

void format ( funcTypeSpec node)

Definition at line 472 of file formatter.cpp.

References funcTypeSpec::args, and funcTypeSpec::resultType.

◆ format() [34/90]

◆ format() [35/90]

void format ( hoshiModule node)

Definition at line 1156 of file formatter.cpp.

References globalStmt::importDecl, hoshiModule::stmts, and globalStmt::useStmt.

◆ format() [36/90]

void format ( identifier node)

Definition at line 391 of file formatter.cpp.

References identifier::node.

◆ format() [37/90]

void format ( identifierWithDefTemplateArg node)

Definition at line 523 of file formatter.cpp.

References identifierWithDefTemplateArg::arg, identifierWithDefTemplateArg::hasDefTemplateArg(), and identifierWithDefTemplateArg::id.

Here is the call graph for this function:

◆ format() [38/90]

void format ( identifierWithTemplateArg node)

Definition at line 515 of file formatter.cpp.

References identifierWithTemplateArg::arg, identifierWithTemplateArg::hasTemplateArg(), and identifierWithTemplateArg::id.

Here is the call graph for this function:

◆ format() [39/90]

void format ( identifierWithTypeSpec node)

Definition at line 396 of file formatter.cpp.

References identifierWithTypeSpec::id, and identifierWithTypeSpec::spec.

◆ format() [40/90]

void format ( ifStmt node)

Definition at line 655 of file formatter.cpp.

References ifStmt::ifBlock::block, ifStmt::ifBlock::cond, ifStmt::elifB, ifStmt::elseB, ifStmt::hasElseBlock(), and ifStmt::ifB.

Here is the call graph for this function:

◆ format() [41/90]

void format ( implInner node)

Definition at line 866 of file formatter.cpp.

References implInner::inner, and FormatOption::NewLine.

◆ format() [42/90]

void format ( implInnerPair node)

◆ format() [43/90]

void format ( implStmt node)

Definition at line 892 of file formatter.cpp.

References implStmt::inner, implStmt::interfaceName, and implStmt::structName.

◆ format() [44/90]

void format ( importDecl node)

Definition at line 960 of file formatter.cpp.

References importDecl::from_path, importDecl::inner, and lexer::token::strVal.

◆ format() [45/90]

void format ( importInner *  node)

Definition at line 969 of file formatter.cpp.

◆ format() [46/90]

void format ( inclusiveExpr node)

◆ format() [47/90]

◆ format() [48/90]

void format ( innerMethodDecl node)

Definition at line 1179 of file formatter.cpp.

References innerMethodDecl::args, innerMethodDecl::attrs, yoi::formatToken(), innerMethodDecl::name, and innerMethodDecl::resultType.

Here is the call graph for this function:

◆ format() [49/90]

void format ( innerMethodDef node)

Definition at line 1193 of file formatter.cpp.

References innerMethodDef::args, innerMethodDef::attrs, innerMethodDef::block, yoi::formatToken(), innerMethodDef::name, and innerMethodDef::resultType.

Here is the call graph for this function:

◆ format() [50/90]

void format ( interfaceDefInner node)

Definition at line 776 of file formatter.cpp.

References interfaceDefInner::inner, and FormatOption::NewLine.

◆ format() [51/90]

void format ( interfaceDefInnerPair node)

Definition at line 767 of file formatter.cpp.

References interfaceDefInnerPair::isMethod(), interfaceDefInnerPair::method, and interfaceDefInnerPair::var.

Here is the call graph for this function:

◆ format() [52/90]

void format ( interfaceDefStmt node)

Definition at line 798 of file formatter.cpp.

References interfaceDefStmt::id, and interfaceDefStmt::inner.

◆ format() [53/90]

void format ( invocationArguments node)

Definition at line 437 of file formatter.cpp.

References invocationArguments::arg.

◆ format() [54/90]

◆ format() [55/90]

void format ( lambdaExpr node)

◆ format() [56/90]

void format ( leftExpr node)

Definition at line 585 of file formatter.cpp.

References leftExpr::hasRhs(), leftExpr::lhs, leftExpr::op, and leftExpr::rhs.

Here is the call graph for this function:

◆ format() [57/90]

void format ( letAssignmentPair node)

◆ format() [58/90]

void format ( letAssignmentPairLHS node)

Definition at line 1103 of file formatter.cpp.

References yoi::formatToken(), letAssignmentPairLHS::id, letAssignmentPairLHS::identifier, letAssignmentPairLHS::kind, and letAssignmentPairLHS::list.

Here is the call graph for this function:

◆ format() [59/90]

void format ( letStmt node)

Definition at line 918 of file formatter.cpp.

References letStmt::terms.

◆ format() [60/90]

void format ( logicalAndExpr node)

◆ format() [61/90]

void format ( logicalOrExpr node)

◆ format() [62/90]

void format ( marcoDescriptor node)

Definition at line 1067 of file formatter.cpp.

References marcoDescriptor::pairs.

◆ format() [63/90]

◆ format() [64/90]

void format ( memberExpr node)

Definition at line 539 of file formatter.cpp.

References memberExpr::terms.

◆ format() [65/90]

void format ( mulExpr node)

◆ format() [66/90]

void format ( newExpression node)

Definition at line 1026 of file formatter.cpp.

References newExpression::args, newExpression::length, and newExpression::type.

◆ format() [67/90]

◆ format() [68/90]

void format ( relationalExpr node)

◆ format() [69/90]

void format ( returnStmt node)

Definition at line 703 of file formatter.cpp.

References returnStmt::hasValue(), and returnStmt::value.

Here is the call graph for this function:

◆ format() [70/90]

void format ( rExpr node)

Definition at line 620 of file formatter.cpp.

◆ format() [71/90]

void format ( satisfyClause node)

Definition at line 1283 of file formatter.cpp.

References satisfyClause::emaes.

◆ format() [72/90]

void format ( satisfyStmt node)

Definition at line 1278 of file formatter.cpp.

References satisfyStmt::emae.

◆ format() [73/90]

void format ( shiftExpr node)

◆ format() [74/90]

void format ( structDefInner node)

Definition at line 819 of file formatter.cpp.

References structDefInner::inner, and FormatOption::NewLine.

◆ format() [75/90]

◆ format() [76/90]

void format ( structDefStmt node)

Definition at line 845 of file formatter.cpp.

References structDefStmt::id, and structDefStmt::inner.

◆ format() [77/90]

void format ( subscript node)

Definition at line 504 of file formatter.cpp.

References subscript::args, subscript::expr, and subscript::isInvocation().

Here is the call graph for this function:

◆ format() [78/90]

void format ( subscriptExpr node)

Definition at line 531 of file formatter.cpp.

References subscriptExpr::id, and subscriptExpr::subscriptVal.

◆ format() [79/90]

void format ( templateArg node)

Definition at line 427 of file formatter.cpp.

References templateArg::spec.

◆ format() [80/90]

void format ( templateArgSpec node)

Definition at line 422 of file formatter.cpp.

References templateArgSpec::spec.

◆ format() [81/90]

void format ( throwStmt node)

Definition at line 972 of file formatter.cpp.

References throwStmt::expr.

◆ format() [82/90]

void format ( tryCatchStmt node)

◆ format() [83/90]

void format ( typeAliasStmt node)

Definition at line 1077 of file formatter.cpp.

References typeAliasStmt::lhs, and typeAliasStmt::rhs.

◆ format() [84/90]

void format ( typeIdExpression node)

Definition at line 1011 of file formatter.cpp.

References typeIdExpression::expr, and typeIdExpression::type.

◆ format() [85/90]

◆ format() [86/90]

void format ( uniqueExpr node)

◆ format() [87/90]

void format ( unnamedDefinitionArguments node)

Definition at line 1048 of file formatter.cpp.

References unnamedDefinitionArguments::types.

◆ format() [88/90]

void format ( useStmt node)

Definition at line 744 of file formatter.cpp.

References yoi::escapeString(), useStmt::name, useStmt::path, and lexer::token::strVal.

Here is the call graph for this function:

◆ format() [89/90]

void format ( whileStmt node)

Definition at line 673 of file formatter.cpp.

References whileStmt::block, and whileStmt::cond.

◆ format() [90/90]

void format ( yieldStmt node)

Definition at line 1223 of file formatter.cpp.

References yieldStmt::expr.

◆ indent()

void indent ( )
private

Definition at line 319 of file formatter.cpp.

References FormatOption::Space.

◆ newLine()

void newLine ( )
private

Definition at line 327 of file formatter.cpp.

◆ printComments() [1/2]

bool printComments ( AST node)
private

Definition at line 338 of file formatter.cpp.

References AST::getColumn(), and AST::getLine().

Here is the call graph for this function:

◆ printComments() [2/2]

bool printComments ( uint64_t  line,
uint64_t  col 
)
private

Definition at line 343 of file formatter.cpp.

References yoi::trim().

Here is the call graph for this function:

◆ willFit()

bool willFit ( invocationArguments node)
private

Definition at line 376 of file formatter.cpp.

References Formatter::format(), and FormatOption::maxWidth.

Here is the call graph for this function:

◆ write()

void write ( const yoi::wstr s)
private

Definition at line 333 of file formatter.cpp.

Member Data Documentation

◆ comments

vec<lexer::Comment> comments

Definition at line 35 of file formatter.hpp.

◆ currentColumn

size_t currentColumn {0}
private

Definition at line 43 of file formatter.hpp.

◆ indentLevel

size_t indentLevel {0}
private

Definition at line 42 of file formatter.hpp.

◆ lastCommentIdx

size_t lastCommentIdx {0}
private

Definition at line 44 of file formatter.hpp.

◆ lastLine

uint64_t lastLine {0}
private

Definition at line 45 of file formatter.hpp.

◆ option

FormatOption option

Definition at line 33 of file formatter.hpp.

◆ os

std::wostream& os

Definition at line 34 of file formatter.hpp.


The documentation for this class was generated from the following files: