12 : indentType(indentType), indentSize(indentSize), braceType(braceType), maxWidth(maxWidth) {}
178 os << L
"constructor";
268 os << L
"always_inline";
280 os << L
"interfaceof";
314 : os(os), option(option), comments(std::move(comments)), lastLine(-1) {}
317 for (
size_t i = 0; i < indentLevel * option.indentSize; ++i) {
332 currentColumn += s.length();
336 if (!node)
return false;
341 bool printedStandalone =
false;
342 while (lastCommentIdx < comments.size() &&
343 (comments[lastCommentIdx].line < line ||
344 (comments[lastCommentIdx].line == line && comments[lastCommentIdx].col < col))) {
346 const auto &comment = comments[lastCommentIdx++];
347 if (lastLine != (uint64_t)-1) {
348 if (comment.line > lastLine) {
354 write(
trim(comment.text));
355 lastLine = comment.line;
356 if (comment.line < line) {
357 printedStandalone =
true;
360 if (printedStandalone) {
368 std::wstringstream ss;
374 if (!node || option.maxWidth == (
size_t)-1)
return true;
375 std::wstringstream ss;
380 return currentColumn + ss.str().length() <= option.maxWidth;
410 if (!node || node->
spec.empty())
return;
412 for (
size_t i = 0; i < node->
spec.size(); ++i) {
413 format(node->
spec[i]);
414 if (i < node->spec.size() - 1) write(L
", ");
425 if (!node || node->
spec.empty())
return;
427 for (
size_t i = 0; i < node->
spec.size(); ++i) {
428 format(node->
spec[i]);
429 if (i < node->spec.size() - 1) write(L
", ");
438 for (
size_t i = 0; i < node->
arg.size(); ++i) {
439 format(node->
arg[i]);
440 if (i < node->arg.size() - 1) write(L
", ");
446 for (
size_t i = 0; i < node->
arg.size(); ++i) {
448 format(node->
arg[i]);
449 if (i < node->arg.size() - 1) write(L
",");
462 for (
size_t i = 0; i < node->
spec.size(); ++i) {
463 format(node->
spec[i]);
464 if (i < node->spec.size() - 1) write(L
", ");
482 }
else if (node->
isNull) {
538 for (
size_t i = 0; i < node->
terms.size(); ++i) {
539 format(node->
terms[i]);
540 if (i < node->terms.size() - 1) write(L
".");
546 switch (node->
kind) {
593#define FORMAT_BINARY_EXPR(NODE_TYPE) \
594void yoi::Formatter::format(NODE_TYPE *node) { \
596 for (size_t i = 0; i < node->terms.size(); ++i) { \
597 format(node->terms[i]); \
598 if (i < node->ops.size()) { \
600 format(node->ops[i]); \
624 for (
size_t i = 0; i < node->
terms.size(); ++i) {
625 format(node->
terms[i]);
626 if (i < node->terms.size() - 1) write(L
".");
639 for (
auto stmt : node->
stmts) {
640 if (!printComments(stmt)) {
644 lastLine = std::max(lastLine, stmt->getLine());
645 printComments(stmt->getLine(), -1);
658 for (
auto &elif : node->
elifB) {
724 switch (node->
kind) {
753 for (
auto &attr : node->
attrs) {
782 for (
auto pair : node->
inner) {
783 if (!printComments(pair)) {
787 lastLine = std::max(lastLine, pair->getLine());
788 printComments(pair->getLine(), -1);
797 write(L
"interface ");
804 switch (node->
kind) {
809 case 1: format(node->
con);
break;
810 case 2: format(node->
method);
break;
824 for (
auto it = node->
inner.begin(); it != node->
inner.end(); it++) {
826 if (!printComments(pair)) {
830 if (it + 1 != node->
inner.end()) {
833 lastLine = std::max(lastLine, pair->getLine());
834 printComments(pair->getLine(), -1);
850 write(L
"datastruct ");
871 for (
auto pair : node->
inner) {
872 if (!printComments(pair)) {
876 lastLine = std::max(lastLine, pair->getLine());
877 printComments(pair->getLine(), -1);
913 for (
size_t i = 0; i < node->
terms.size(); ++i) {
914 format(node->
terms[i]);
915 if (i < node->terms.size() - 1) os << L
", ";
922 switch (node->
kind) {
940 for (
auto &attr : node->
attrs) {
1023 if (node->
args) format(node->
args);
1029 for (
size_t i = 0; i < node->
captures.size(); ++i) {
1031 if (i < node->captures.size() - 1) os << L
", ";
1037 format(node->
block);
1043 for (
size_t i = 0; i < node->
types.size(); ++i) {
1044 format(node->
types[i]);
1045 if (i < node->types.size() - 1) write(L
", ");
1060 if (!node || node->
pairs.empty())
return;
1062 for (
size_t i = 0; i < node->
pairs.size(); ++i) {
1063 format(node->
pairs[i]);
1064 if (i < node->pairs.size() - 1) os << L
", ";
1080 format(node->
block);
1101 for (
size_t i = 0; i < node->
list.size(); ++i) {
1103 if (i < node->list.size() - 1) os << L
", ";
1115 for (
size_t i = 0; i < node->
values.size(); ++i) {
1116 if (!printComments(node->
values[i])) {
1120 if (i < node->values.size() - 1) os << L
",";
1121 lastLine = std::max(lastLine, node->
values[i]->getLine());
1122 printComments(node->
values[i]->getLine(), -1);
1141 for (
size_t i = 0; i < node->
exprs.size(); ++i) {
1142 format(node->
exprs[i]);
1143 if (i < node->exprs.size() - 1) os << L
", ";
1150 for (
auto it = node->
stmts.begin(); it != node->
stmts.end(); ++it) {
1151 if (it != node->
stmts.begin()) {
1152 auto prev = std::prev(it);
1163 bool printedStandalone = printComments(*it);
1165 lastLine = std::max(lastLine, (*it)->getLine());
1166 printComments((*it)->getLine(), -1);
1168 printComments(-1, -1);
1173 for (
auto &attr : node->
attrs) {
1187 for (
auto &attr : node->
attrs) {
1197 format(node->
block);
1202 os << L
"constructor";
1209 os << L
"constructor";
1212 format(node->
block);
1229 os << L
"concept " << node->
name.
strVal << L
"<";
1256 switch (node->
kind) {
1277 for (
auto it = node->
emaes.begin(); it != node->
emaes.end(); it++) {
1278 if (it != node->
emaes.begin()) {
externModuleAccessExpression * rhs
yoi::vec< yoi::rExpr * > exprs
vec< inCodeBlockStmt * > stmts
yoi::vec< identifierWithTypeSpec * > algebraParams
yoi::vec< lexer::token > typeParams
yoi::vec< conceptStmt * > conceptBlock
union yoi::conceptStmt::ConceptStmtValue value
enum yoi::conceptStmt::Kind kind
defTemplateArg * tempArgs
definitionArguments * args
definitionArguments * args
satisfyClause * satisfyCondition
vec< defTemplateArgSpec * > spec
vec< identifierWithTypeSpec * > spec
vec< enumerationPair * > values
yoi::vec< lexer::token > attrs
vec< identifierWithTemplateArg * > terms
inCodeBlockStmt * afterStmt
inCodeBlockStmt * initStmt
identifierWithDefTemplateArg * id
yoi::vec< lexer::token > attrs
definitionArguments * args
externModuleAccessExpression * name
unnamedDefinitionArguments * args
unnamedDefinitionArguments * args
union yoi::globalStmt::vValue value
enum yoi::globalStmt::vKind kind
vec< globalStmt * > stmts
bool hasDefTemplateArg() const
bool hasTemplateArg() const
bool hasElseBlock() const
bool isConstructor() const
vec< implInnerPair * > inner
externModuleAccessExpression * structName
externModuleAccessExpression * interfaceName
union yoi::inCodeBlockStmt::vValue value
enum yoi::inCodeBlockStmt::vKind kind
yoi::vec< lexer::token > attrs
identifierWithDefTemplateArg * name
definitionArguments * args
yoi::vec< lexer::token > attrs
definitionArguments * args
identifierWithTemplateArg * name
identifierWithTypeSpec * var
vec< interfaceDefInnerPair * > inner
identifierWithDefTemplateArg * id
interfaceDefInner * inner
vec< yoi::identifier * > captures
definitionArguments * args
enum yoi::letAssignmentPairLHS::vKind kind
letAssignmentPairLHS * lhs
vec< letAssignmentPair * > terms
yoi::vec< marcoPair * > pairs
vec< subscriptExpr * > terms
invocationArguments * args
externModuleAccessExpression * type
enum yoi::primary::primaryKind kind
bracedInitalizerList * bracedInitalizer
typeIdExpression * typeId
dynCastExpression * dynCast
yoi::vec< externModuleAccessExpression * > emaes
externModuleAccessExpression * emae
enum yoi::structDefInnerPair::Modifier modifier
finalizerDecl * finalizer
identifierWithTypeSpec * var
vec< structDefInnerPair * > inner
identifierWithDefTemplateArg * id
vec< subscript * > subscriptVal
identifierWithTemplateArg * id
bool isInvocation() const
invocationArguments * args
vec< templateArgSpec * > spec
vec< catchParam * > catchParams
yoi::identifierWithDefTemplateArg * lhs
decltypeExpr * decltypeExpression
yoi::vec< uint64_t > * arraySubscript
externModuleAccessExpression * member
enum yoi::typeSpec::typeSpecKind kind
std::wstring string2wstring(const std::string &v)
void formatToken(std::wostream &os, FormatOption option, const lexer::token &token)
wstr escapeString(const wstr &value)
std::basic_string< T > trim(const std::basic_string< T > &str)
enum yoi::lexer::token::tokenKind kind
@ multiplicationAssignment
union yoi::lexer::token::vBasicValue basicVal
satisfyStmt * satisfyStmt
dataStructDefStmt * dataStructDefStmtVal
enumerationDefinition * enumerationDefVal
interfaceDefStmt * interfaceDefStmtVal
conceptDefinition * conceptDefVal
funcDefStmt * funcDefStmtVal
typeAliasStmt * typeAliasStmtVal
exportDecl * exportDeclVal
structDefStmt * structDefStmtVal
importDecl * importDeclVal
forEachStmt * forEachStmtVal
returnStmt * returnStmtVal
continueStmt * continueStmtVal