12 : indentType(indentType), indentSize(indentSize), braceType(braceType), maxWidth(maxWidth) {}
178 os << L
"constructor";
268 os << L
"always_inline";
280 os << L
"interfaceof";
317 : os(os), option(option), comments(
std::move(comments)), lastLine(-1) {}
320 for (
size_t i = 0; i < indentLevel * option.indentSize; ++i) {
335 currentColumn += s.length();
339 if (!node)
return false;
344 bool printedStandalone =
false;
345 while (lastCommentIdx < comments.size() &&
346 (comments[lastCommentIdx].line < line ||
347 (comments[lastCommentIdx].line == line && comments[lastCommentIdx].col < col))) {
349 const auto &comment = comments[lastCommentIdx++];
350 if (lastLine != (uint64_t)-1) {
351 if (comment.line > lastLine) {
357 write(
trim(comment.text));
358 lastLine = comment.line;
359 if (comment.line < line) {
360 printedStandalone =
true;
363 if (printedStandalone) {
371 std::wstringstream ss;
377 if (!node || option.maxWidth == (
size_t)-1)
return true;
378 std::wstringstream ss;
383 return currentColumn + ss.str().length() <= option.maxWidth;
413 if (!node || node->
spec.empty())
return;
415 for (
size_t i = 0; i < node->
spec.size(); ++i) {
416 format(node->
spec[i]);
417 if (i < node->spec.size() - 1) write(L
", ");
428 if (!node || node->
spec.empty())
return;
430 for (
size_t i = 0; i < node->
spec.size(); ++i) {
431 format(node->
spec[i]);
432 if (i < node->spec.size() - 1) write(L
", ");
441 for (
size_t i = 0; i < node->
arg.size(); ++i) {
442 format(node->
arg[i]);
443 if (i < node->arg.size() - 1) write(L
", ");
449 for (
size_t i = 0; i < node->
arg.size(); ++i) {
451 format(node->
arg[i]);
452 if (i < node->arg.size() - 1) write(L
",");
465 for (
size_t i = 0; i < node->
spec.size(); ++i) {
466 format(node->
spec[i]);
467 if (i < node->spec.size() - 1) write(L
", ");
485 }
else if (node->
isNull) {
541 for (
size_t i = 0; i < node->
terms.size(); ++i) {
542 format(node->
terms[i]);
543 if (i < node->terms.size() - 1) write(L
".");
549 switch (node->
kind) {
596#define FORMAT_BINARY_EXPR(NODE_TYPE) \
597void yoi::Formatter::format(NODE_TYPE *node) { \
599 for (size_t i = 0; i < node->terms.size(); ++i) { \
600 format(node->terms[i]); \
601 if (i < node->ops.size()) { \
603 format(node->ops[i]); \
627 for (
size_t i = 0; i < node->
terms.size(); ++i) {
628 format(node->
terms[i]);
629 if (i < node->terms.size() - 1) write(L
".");
642 for (
auto stmt : node->
stmts) {
643 if (!printComments(stmt)) {
647 lastLine = std::max(lastLine, stmt->getLine());
648 printComments(stmt->getLine(), -1);
661 for (
auto &elif : node->
elifB) {
727 switch (node->
kind) {
756 for (
auto &attr : node->
attrs) {
785 for (
auto pair : node->
inner) {
786 if (!printComments(pair)) {
790 lastLine = std::max(lastLine, pair->getLine());
791 printComments(pair->getLine(), -1);
800 write(L
"interface ");
807 switch (node->
kind) {
813 case 1: format(node->
con);
break;
814 case 2: format(node->
method);
break;
828 for (
auto it = node->
inner.begin(); it != node->
inner.end(); it++) {
830 if (!printComments(pair)) {
834 if (it + 1 != node->
inner.end()) {
837 lastLine = std::max(lastLine, pair->getLine());
838 printComments(pair->getLine(), -1);
854 write(L
"datastruct ");
875 for (
auto it = node->
inner.begin(); it != node->
inner.end(); it++) {
877 if (!printComments(pair)) {
881 if (it + 1 != node->
inner.end()) {
884 lastLine = std::max(lastLine, pair->getLine());
885 printComments(pair->getLine(), -1);
921 for (
size_t i = 0; i < node->
terms.size(); ++i) {
922 format(node->
terms[i]);
923 if (i < node->terms.size() - 1) os << L
", ";
930 switch (node->
kind) {
948 for (
auto &attr : node->
attrs) {
1031 if (node->
args) format(node->
args);
1037 for (
size_t i = 0; i < node->
captures.size(); ++i) {
1039 if (i < node->captures.size() - 1) os << L
", ";
1045 format(node->
block);
1051 for (
size_t i = 0; i < node->
types.size(); ++i) {
1052 format(node->
types[i]);
1053 if (i < node->types.size() - 1) write(L
", ");
1068 if (!node || node->
pairs.empty())
return;
1070 for (
size_t i = 0; i < node->
pairs.size(); ++i) {
1071 format(node->
pairs[i]);
1072 if (i < node->pairs.size() - 1) os << L
", ";
1088 format(node->
block);
1109 for (
size_t i = 0; i < node->
list.size(); ++i) {
1111 if (i < node->list.size() - 1) os << L
", ";
1123 for (
size_t i = 0; i < node->
values.size(); ++i) {
1124 if (!printComments(node->
values[i])) {
1128 if (i < node->values.size() - 1) os << L
",";
1129 lastLine = std::max(lastLine, node->
values[i]->getLine());
1130 printComments(node->
values[i]->getLine(), -1);
1149 for (
size_t i = 0; i < node->
exprs.size(); ++i) {
1150 format(node->
exprs[i]);
1151 if (i < node->exprs.size() - 1) os << L
", ";
1158 for (
auto it = node->
stmts.begin(); it != node->
stmts.end(); ++it) {
1159 if (it != node->
stmts.begin()) {
1160 auto prev = std::prev(it);
1171 bool printedStandalone = printComments(*it);
1173 lastLine = std::max(lastLine, (*it)->getLine());
1174 printComments((*it)->getLine(), -1);
1176 printComments(-1, -1);
1181 for (
auto &attr : node->
attrs) {
1195 for (
auto &attr : node->
attrs) {
1205 format(node->
block);
1210 os << L
"constructor";
1217 os << L
"constructor";
1220 format(node->
block);
1237 os << L
"concept " << node->
name.
strVal << L
"<";
1264 switch (node->
kind) {
1285 for (
auto it = node->
emaes.begin(); it != node->
emaes.end(); it++) {
1286 if (it != node->
emaes.begin()) {
1295 switch (node->
attr) {
1300 os << L
"datafield ";
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
structDefInnerPair::Modifier attr
yoi::identifier * identifier
vec< yoi::lambdaCapture * > 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