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)
 

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 311 of file formatter.cpp.

◆ Formatter() [2/2]

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

Definition at line 313 of file formatter.cpp.

Member Function Documentation

◆ format() [1/89]

void format ( abstractExpr node)

◆ format() [2/89]

void format ( addExpr node)

◆ format() [3/89]

void format ( andExpr node)

◆ format() [4/89]

void format ( basicLiterals node)

Definition at line 383 of file formatter.cpp.

References basicLiterals::node.

◆ format() [5/89]

void format ( bracedInitalizerList node)

Definition at line 1138 of file formatter.cpp.

References bracedInitalizerList::exprs.

◆ format() [6/89]

void format ( breakStmt node)

Definition at line 714 of file formatter.cpp.

◆ format() [7/89]

void format ( catchParam node)

Definition at line 970 of file formatter.cpp.

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

◆ format() [8/89]

void format ( codeBlock node)

Definition at line 630 of file formatter.cpp.

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

◆ format() [9/89]

◆ format() [10/89]

◆ format() [11/89]

void format ( const lexer::token token)

Definition at line 367 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/89]

void format ( constructorDecl node)

Definition at line 1200 of file formatter.cpp.

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

◆ format() [13/89]

void format ( constructorDef node)

◆ format() [14/89]

void format ( continueStmt node)

Definition at line 709 of file formatter.cpp.

◆ format() [15/89]

void format ( dataStructDefStmt node)

Definition at line 848 of file formatter.cpp.

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

◆ format() [16/89]

void format ( decltypeExpr node)

Definition at line 1221 of file formatter.cpp.

References decltypeExpr::expr.

◆ format() [17/89]

void format ( definitionArguments node)

Definition at line 457 of file formatter.cpp.

References definitionArguments::spec.

◆ format() [18/89]

void format ( defTemplateArg node)

Definition at line 409 of file formatter.cpp.

References defTemplateArg::spec.

◆ format() [19/89]

void format ( defTemplateArgSpec node)

Definition at line 400 of file formatter.cpp.

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

◆ format() [20/89]

void format ( dynCastExpression node)

Definition at line 994 of file formatter.cpp.

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

◆ format() [21/89]

void format ( enumerationDefinition node)

Definition at line 1109 of file formatter.cpp.

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

◆ format() [22/89]

void format ( enumerationPair node)

Definition at line 1129 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/89]

void format ( equalityExpr node)

◆ format() [24/89]

void format ( exclusiveExpr node)

◆ format() [25/89]

void format ( exportDecl node)

Definition at line 938 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [26/89]

void format ( externModuleAccessExpression node)

Definition at line 622 of file formatter.cpp.

References externModuleAccessExpression::terms.

◆ format() [27/89]

void format ( finalizerDecl node)

Definition at line 1083 of file formatter.cpp.

◆ format() [28/89]

void format ( finalizerDef node)

Definition at line 1077 of file formatter.cpp.

References finalizerDef::block.

◆ format() [29/89]

void format ( forEachStmt node)

Definition at line 690 of file formatter.cpp.

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

◆ format() [30/89]

void format ( forStmt node)

Definition at line 678 of file formatter.cpp.

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

◆ format() [31/89]

void format ( funcDefStmt node)

Definition at line 750 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/89]

void format ( funcExpr node)

Definition at line 1088 of file formatter.cpp.

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

◆ format() [33/89]

void format ( funcTypeSpec node)

Definition at line 469 of file formatter.cpp.

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

◆ format() [34/89]

◆ format() [35/89]

void format ( hoshiModule node)

Definition at line 1148 of file formatter.cpp.

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

◆ format() [36/89]

void format ( identifier node)

Definition at line 388 of file formatter.cpp.

References identifier::node.

◆ format() [37/89]

void format ( identifierWithDefTemplateArg node)

Definition at line 520 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [38/89]

void format ( identifierWithTemplateArg node)

Definition at line 512 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [39/89]

void format ( identifierWithTypeSpec node)

Definition at line 393 of file formatter.cpp.

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

◆ format() [40/89]

void format ( ifStmt node)

Definition at line 652 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/89]

void format ( implInner node)

Definition at line 862 of file formatter.cpp.

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

◆ format() [42/89]

void format ( implInnerPair node)

◆ format() [43/89]

void format ( implStmt node)

Definition at line 884 of file formatter.cpp.

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

◆ format() [44/89]

void format ( importDecl node)

Definition at line 952 of file formatter.cpp.

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

◆ format() [45/89]

void format ( importInner *  node)

Definition at line 961 of file formatter.cpp.

◆ format() [46/89]

void format ( inclusiveExpr node)

◆ format() [47/89]

◆ format() [48/89]

void format ( innerMethodDecl node)

Definition at line 1171 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/89]

void format ( innerMethodDef node)

Definition at line 1185 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/89]

void format ( interfaceDefInner node)

Definition at line 773 of file formatter.cpp.

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

◆ format() [51/89]

void format ( interfaceDefInnerPair node)

Definition at line 764 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [52/89]

void format ( interfaceDefStmt node)

Definition at line 795 of file formatter.cpp.

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

◆ format() [53/89]

void format ( invocationArguments node)

Definition at line 434 of file formatter.cpp.

References invocationArguments::arg.

◆ format() [54/89]

void format ( lambdaExpr node)

◆ format() [55/89]

void format ( leftExpr node)

Definition at line 582 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [56/89]

void format ( letAssignmentPair node)

◆ format() [57/89]

void format ( letAssignmentPairLHS node)

Definition at line 1095 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() [58/89]

void format ( letStmt node)

Definition at line 910 of file formatter.cpp.

References letStmt::terms.

◆ format() [59/89]

void format ( logicalAndExpr node)

◆ format() [60/89]

void format ( logicalOrExpr node)

◆ format() [61/89]

void format ( marcoDescriptor node)

Definition at line 1059 of file formatter.cpp.

References marcoDescriptor::pairs.

◆ format() [62/89]

◆ format() [63/89]

void format ( memberExpr node)

Definition at line 536 of file formatter.cpp.

References memberExpr::terms.

◆ format() [64/89]

void format ( mulExpr node)

◆ format() [65/89]

void format ( newExpression node)

Definition at line 1018 of file formatter.cpp.

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

◆ format() [66/89]

◆ format() [67/89]

void format ( relationalExpr node)

◆ format() [68/89]

void format ( returnStmt node)

Definition at line 700 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [69/89]

void format ( rExpr node)

Definition at line 617 of file formatter.cpp.

◆ format() [70/89]

void format ( satisfyClause node)

Definition at line 1275 of file formatter.cpp.

References satisfyClause::emaes.

◆ format() [71/89]

void format ( satisfyStmt node)

Definition at line 1270 of file formatter.cpp.

References satisfyStmt::emae.

◆ format() [72/89]

void format ( shiftExpr node)

◆ format() [73/89]

void format ( structDefInner node)

Definition at line 815 of file formatter.cpp.

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

◆ format() [74/89]

◆ format() [75/89]

void format ( structDefStmt node)

Definition at line 841 of file formatter.cpp.

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

◆ format() [76/89]

void format ( subscript node)

Definition at line 501 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [77/89]

void format ( subscriptExpr node)

Definition at line 528 of file formatter.cpp.

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

◆ format() [78/89]

void format ( templateArg node)

Definition at line 424 of file formatter.cpp.

References templateArg::spec.

◆ format() [79/89]

void format ( templateArgSpec node)

Definition at line 419 of file formatter.cpp.

References templateArgSpec::spec.

◆ format() [80/89]

void format ( throwStmt node)

Definition at line 964 of file formatter.cpp.

References throwStmt::expr.

◆ format() [81/89]

void format ( tryCatchStmt node)

◆ format() [82/89]

void format ( typeAliasStmt node)

Definition at line 1069 of file formatter.cpp.

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

◆ format() [83/89]

void format ( typeIdExpression node)

Definition at line 1003 of file formatter.cpp.

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

◆ format() [84/89]

◆ format() [85/89]

void format ( uniqueExpr node)

◆ format() [86/89]

void format ( unnamedDefinitionArguments node)

Definition at line 1040 of file formatter.cpp.

References unnamedDefinitionArguments::types.

◆ format() [87/89]

void format ( useStmt node)

Definition at line 741 of file formatter.cpp.

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

Here is the call graph for this function:

◆ format() [88/89]

void format ( whileStmt node)

Definition at line 670 of file formatter.cpp.

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

◆ format() [89/89]

void format ( yieldStmt node)

Definition at line 1215 of file formatter.cpp.

References yieldStmt::expr.

◆ indent()

void indent ( )
private

Definition at line 316 of file formatter.cpp.

References FormatOption::Space.

◆ newLine()

void newLine ( )
private

Definition at line 324 of file formatter.cpp.

◆ printComments() [1/2]

bool printComments ( AST node)
private

Definition at line 335 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 340 of file formatter.cpp.

References yoi::trim().

Here is the call graph for this function:

◆ willFit()

bool willFit ( invocationArguments node)
private

Definition at line 373 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 330 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: