Add CST definitions for record expressions and rename StructDeclaration
This commit is contained in:
parent
4a501c1f77
commit
4acb76159f
3 changed files with 108 additions and 28 deletions
|
@ -137,6 +137,8 @@ namespace bolt {
|
||||||
CallExpression,
|
CallExpression,
|
||||||
InfixExpression,
|
InfixExpression,
|
||||||
PrefixExpression,
|
PrefixExpression,
|
||||||
|
RecordExpressionField,
|
||||||
|
RecordExpression,
|
||||||
ExpressionStatement,
|
ExpressionStatement,
|
||||||
ReturnStatement,
|
ReturnStatement,
|
||||||
IfStatement,
|
IfStatement,
|
||||||
|
@ -146,8 +148,8 @@ namespace bolt {
|
||||||
LetBlockBody,
|
LetBlockBody,
|
||||||
LetExprBody,
|
LetExprBody,
|
||||||
LetDeclaration,
|
LetDeclaration,
|
||||||
StructDeclarationField,
|
RecordDeclarationField,
|
||||||
StructDeclaration,
|
RecordDeclaration,
|
||||||
ClassDeclaration,
|
ClassDeclaration,
|
||||||
InstanceDeclaration,
|
InstanceDeclaration,
|
||||||
SourceFile,
|
SourceFile,
|
||||||
|
@ -1366,6 +1368,49 @@ namespace bolt {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RecordExpressionField : public Node {
|
||||||
|
public:
|
||||||
|
|
||||||
|
Identifier* Name;
|
||||||
|
Equals* Equals;
|
||||||
|
Expression* E;
|
||||||
|
|
||||||
|
inline RecordExpressionField(
|
||||||
|
Identifier* Name,
|
||||||
|
class Equals* Equals,
|
||||||
|
Expression* E
|
||||||
|
): Node(NodeKind::RecordExpressionField),
|
||||||
|
Name(Name),
|
||||||
|
Equals(Equals),
|
||||||
|
E(E) {}
|
||||||
|
|
||||||
|
Token* getFirstToken() const override;
|
||||||
|
Token* getLastToken() const override;
|
||||||
|
|
||||||
|
inline Expression* getExpression() const {
|
||||||
|
return E;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class RecordExpression : public Expression {
|
||||||
|
public:
|
||||||
|
|
||||||
|
LBrace* LBrace;
|
||||||
|
std::vector<std::tuple<RecordExpressionField*, Comma*>> Fields;
|
||||||
|
RBrace* RBrace;
|
||||||
|
|
||||||
|
inline RecordExpression(
|
||||||
|
class LBrace* LBrace,
|
||||||
|
std::vector<std::tuple<RecordExpressionField*, Comma*>> Fields,
|
||||||
|
class RBrace* RBrace
|
||||||
|
): Expression(NodeKind::RecordExpression),
|
||||||
|
LBrace(LBrace),
|
||||||
|
Fields(Fields),
|
||||||
|
RBrace(RBrace) {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class Statement : public Node {
|
class Statement : public Node {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -1640,14 +1685,14 @@ namespace bolt {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StructDeclarationField : public Node {
|
class RecordDeclarationField : public Node {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StructDeclarationField(
|
RecordDeclarationField(
|
||||||
Identifier* Name,
|
Identifier* Name,
|
||||||
class Colon* Colon,
|
class Colon* Colon,
|
||||||
class TypeExpression* TypeExpression
|
class TypeExpression* TypeExpression
|
||||||
): Node(NodeKind::StructDeclarationField),
|
): Node(NodeKind::RecordDeclarationField),
|
||||||
Name(Name),
|
Name(Name),
|
||||||
Colon(Colon),
|
Colon(Colon),
|
||||||
TypeExpression(TypeExpression) {}
|
TypeExpression(TypeExpression) {}
|
||||||
|
@ -1661,22 +1706,22 @@ namespace bolt {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StructDeclaration : public Node {
|
class RecordDeclaration : public Node {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class PubKeyword* PubKeyword;
|
class PubKeyword* PubKeyword;
|
||||||
class StructKeyword* StructKeyword;
|
class StructKeyword* StructKeyword;
|
||||||
Identifier* Name;
|
Identifier* Name;
|
||||||
class BlockStart* BlockStart;
|
class BlockStart* BlockStart;
|
||||||
std::vector<StructDeclarationField*> Fields;
|
std::vector<RecordDeclarationField*> Fields;
|
||||||
|
|
||||||
StructDeclaration(
|
RecordDeclaration(
|
||||||
class PubKeyword* PubKeyword,
|
class PubKeyword* PubKeyword,
|
||||||
class StructKeyword* StructKeyword,
|
class StructKeyword* StructKeyword,
|
||||||
Identifier* Name,
|
Identifier* Name,
|
||||||
class BlockStart* BlockStart,
|
class BlockStart* BlockStart,
|
||||||
std::vector<StructDeclarationField*> Fields
|
std::vector<RecordDeclarationField*> Fields
|
||||||
): Node(NodeKind::StructDeclaration),
|
): Node(NodeKind::RecordDeclaration),
|
||||||
PubKeyword(PubKeyword),
|
PubKeyword(PubKeyword),
|
||||||
StructKeyword(StructKeyword),
|
StructKeyword(StructKeyword),
|
||||||
Name(Name),
|
Name(Name),
|
||||||
|
@ -1780,8 +1825,8 @@ namespace bolt {
|
||||||
template<> inline NodeKind getNodeType<LetBlockBody>() { return NodeKind::LetBlockBody; }
|
template<> inline NodeKind getNodeType<LetBlockBody>() { return NodeKind::LetBlockBody; }
|
||||||
template<> inline NodeKind getNodeType<LetExprBody>() { return NodeKind::LetExprBody; }
|
template<> inline NodeKind getNodeType<LetExprBody>() { return NodeKind::LetExprBody; }
|
||||||
template<> inline NodeKind getNodeType<LetDeclaration>() { return NodeKind::LetDeclaration; }
|
template<> inline NodeKind getNodeType<LetDeclaration>() { return NodeKind::LetDeclaration; }
|
||||||
template<> inline NodeKind getNodeType<StructDeclarationField>() { return NodeKind::StructDeclarationField; }
|
template<> inline NodeKind getNodeType<RecordDeclarationField>() { return NodeKind::RecordDeclarationField; }
|
||||||
template<> inline NodeKind getNodeType<StructDeclaration>() { return NodeKind::StructDeclaration; }
|
template<> inline NodeKind getNodeType<RecordDeclaration>() { return NodeKind::RecordDeclaration; }
|
||||||
template<> inline NodeKind getNodeType<ClassDeclaration>() { return NodeKind::ClassDeclaration; }
|
template<> inline NodeKind getNodeType<ClassDeclaration>() { return NodeKind::ClassDeclaration; }
|
||||||
template<> inline NodeKind getNodeType<InstanceDeclaration>() { return NodeKind::InstanceDeclaration; }
|
template<> inline NodeKind getNodeType<InstanceDeclaration>() { return NodeKind::InstanceDeclaration; }
|
||||||
template<> inline NodeKind getNodeType<SourceFile>() { return NodeKind::SourceFile; }
|
template<> inline NodeKind getNodeType<SourceFile>() { return NodeKind::SourceFile; }
|
||||||
|
|
|
@ -127,6 +127,10 @@ namespace bolt {
|
||||||
return static_cast<D*>(this)->visitInfixExpression(static_cast<InfixExpression*>(N));
|
return static_cast<D*>(this)->visitInfixExpression(static_cast<InfixExpression*>(N));
|
||||||
case NodeKind::PrefixExpression:
|
case NodeKind::PrefixExpression:
|
||||||
return static_cast<D*>(this)->visitPrefixExpression(static_cast<PrefixExpression*>(N));
|
return static_cast<D*>(this)->visitPrefixExpression(static_cast<PrefixExpression*>(N));
|
||||||
|
case NodeKind::RecordExpressionField:
|
||||||
|
return static_cast<D*>(this)->visitRecordExpressionField(static_cast<RecordExpressionField*>(N));
|
||||||
|
case NodeKind::RecordExpression:
|
||||||
|
return static_cast<D*>(this)->visitRecordExpression(static_cast<RecordExpression*>(N));
|
||||||
case NodeKind::ExpressionStatement:
|
case NodeKind::ExpressionStatement:
|
||||||
return static_cast<D*>(this)->visitExpressionStatement(static_cast<ExpressionStatement*>(N));
|
return static_cast<D*>(this)->visitExpressionStatement(static_cast<ExpressionStatement*>(N));
|
||||||
case NodeKind::ReturnStatement:
|
case NodeKind::ReturnStatement:
|
||||||
|
@ -145,10 +149,10 @@ namespace bolt {
|
||||||
return static_cast<D*>(this)->visitLetExprBody(static_cast<LetExprBody*>(N));
|
return static_cast<D*>(this)->visitLetExprBody(static_cast<LetExprBody*>(N));
|
||||||
case NodeKind::LetDeclaration:
|
case NodeKind::LetDeclaration:
|
||||||
return static_cast<D*>(this)->visitLetDeclaration(static_cast<LetDeclaration*>(N));
|
return static_cast<D*>(this)->visitLetDeclaration(static_cast<LetDeclaration*>(N));
|
||||||
case NodeKind::StructDeclarationField:
|
case NodeKind::RecordDeclarationField:
|
||||||
return static_cast<D*>(this)->visitStructDeclarationField(static_cast<StructDeclarationField*>(N));
|
return static_cast<D*>(this)->visitStructDeclarationField(static_cast<RecordDeclarationField*>(N));
|
||||||
case NodeKind::StructDeclaration:
|
case NodeKind::RecordDeclaration:
|
||||||
return static_cast<D*>(this)->visitStructDeclaration(static_cast<StructDeclaration*>(N));
|
return static_cast<D*>(this)->visitStructDeclaration(static_cast<RecordDeclaration*>(N));
|
||||||
case NodeKind::ClassDeclaration:
|
case NodeKind::ClassDeclaration:
|
||||||
return static_cast<D*>(this)->visitClassDeclaration(static_cast<ClassDeclaration*>(N));
|
return static_cast<D*>(this)->visitClassDeclaration(static_cast<ClassDeclaration*>(N));
|
||||||
case NodeKind::InstanceDeclaration:
|
case NodeKind::InstanceDeclaration:
|
||||||
|
@ -416,6 +420,14 @@ namespace bolt {
|
||||||
visitExpression(N);
|
visitExpression(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void visitRecordExpressionField(RecordExpressionField* N) {
|
||||||
|
visitNode(N);
|
||||||
|
}
|
||||||
|
|
||||||
|
void visitRecordExpression(RecordExpression* N) {
|
||||||
|
visitExpression(N);
|
||||||
|
}
|
||||||
|
|
||||||
void visitStatement(Statement* N) {
|
void visitStatement(Statement* N) {
|
||||||
visitNode(N);
|
visitNode(N);
|
||||||
}
|
}
|
||||||
|
@ -460,11 +472,11 @@ namespace bolt {
|
||||||
visitNode(N);
|
visitNode(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitStructDeclarationField(StructDeclarationField* N) {
|
void visitStructDeclarationField(RecordDeclarationField* N) {
|
||||||
visitNode(N);
|
visitNode(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitStructDeclaration(StructDeclaration* N) {
|
void visitStructDeclaration(RecordDeclaration* N) {
|
||||||
visitNode(N);
|
visitNode(N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,6 +670,12 @@ namespace bolt {
|
||||||
case NodeKind::PrefixExpression:
|
case NodeKind::PrefixExpression:
|
||||||
visitEachChild(static_cast<PrefixExpression*>(N));
|
visitEachChild(static_cast<PrefixExpression*>(N));
|
||||||
break;
|
break;
|
||||||
|
case NodeKind::RecordExpressionField:
|
||||||
|
visitEachChild(static_cast<RecordExpressionField*>(N));
|
||||||
|
break;
|
||||||
|
case NodeKind::RecordExpression:
|
||||||
|
visitEachChild(static_cast<RecordExpression*>(N));
|
||||||
|
break;
|
||||||
case NodeKind::ExpressionStatement:
|
case NodeKind::ExpressionStatement:
|
||||||
visitEachChild(static_cast<ExpressionStatement*>(N));
|
visitEachChild(static_cast<ExpressionStatement*>(N));
|
||||||
break;
|
break;
|
||||||
|
@ -685,11 +703,11 @@ namespace bolt {
|
||||||
case NodeKind::LetDeclaration:
|
case NodeKind::LetDeclaration:
|
||||||
visitEachChild(static_cast<LetDeclaration*>(N));
|
visitEachChild(static_cast<LetDeclaration*>(N));
|
||||||
break;
|
break;
|
||||||
case NodeKind::StructDeclaration:
|
case NodeKind::RecordDeclaration:
|
||||||
visitEachChild(static_cast<StructDeclaration*>(N));
|
visitEachChild(static_cast<RecordDeclaration*>(N));
|
||||||
break;
|
break;
|
||||||
case NodeKind::StructDeclarationField:
|
case NodeKind::RecordDeclarationField:
|
||||||
visitEachChild(static_cast<StructDeclarationField*>(N));
|
visitEachChild(static_cast<RecordDeclarationField*>(N));
|
||||||
break;
|
break;
|
||||||
case NodeKind::ClassDeclaration:
|
case NodeKind::ClassDeclaration:
|
||||||
visitEachChild(static_cast<ClassDeclaration*>(N));
|
visitEachChild(static_cast<ClassDeclaration*>(N));
|
||||||
|
@ -959,6 +977,23 @@ namespace bolt {
|
||||||
BOLT_VISIT(N->Argument);
|
BOLT_VISIT(N->Argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void visitEachChild(RecordExpressionField* N) {
|
||||||
|
BOLT_VISIT(N->Name);
|
||||||
|
BOLT_VISIT(N->Equals);
|
||||||
|
BOLT_VISIT(N->E);
|
||||||
|
}
|
||||||
|
|
||||||
|
void visitEachChild(RecordExpression* N) {
|
||||||
|
BOLT_VISIT(N->LBrace);
|
||||||
|
for (auto [Field, Comma]: N->Fields) {
|
||||||
|
BOLT_VISIT(Field);
|
||||||
|
if (Comma) {
|
||||||
|
BOLT_VISIT(Comma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOLT_VISIT(N->RBrace);
|
||||||
|
}
|
||||||
|
|
||||||
void visitEachChild(ExpressionStatement* N) {
|
void visitEachChild(ExpressionStatement* N) {
|
||||||
BOLT_VISIT(N->Expression);
|
BOLT_VISIT(N->Expression);
|
||||||
}
|
}
|
||||||
|
@ -1029,13 +1064,13 @@ namespace bolt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitEachChild(StructDeclarationField* N) {
|
void visitEachChild(RecordDeclarationField* N) {
|
||||||
BOLT_VISIT(N->Name);
|
BOLT_VISIT(N->Name);
|
||||||
BOLT_VISIT(N->Colon);
|
BOLT_VISIT(N->Colon);
|
||||||
BOLT_VISIT(N->TypeExpression);
|
BOLT_VISIT(N->TypeExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitEachChild(StructDeclaration* N) {
|
void visitEachChild(RecordDeclaration* N) {
|
||||||
if (N->PubKeyword) {
|
if (N->PubKeyword) {
|
||||||
BOLT_VISIT(N->PubKeyword);
|
BOLT_VISIT(N->PubKeyword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -514,22 +514,22 @@ namespace bolt {
|
||||||
return Pattern->getLastToken();
|
return Pattern->getLastToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* StructDeclarationField::getFirstToken() const {
|
Token* RecordDeclarationField::getFirstToken() const {
|
||||||
return Name;
|
return Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* StructDeclarationField::getLastToken() const {
|
Token* RecordDeclarationField::getLastToken() const {
|
||||||
return TypeExpression->getLastToken();
|
return TypeExpression->getLastToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* StructDeclaration::getFirstToken() const {
|
Token* RecordDeclaration::getFirstToken() const {
|
||||||
if (PubKeyword) {
|
if (PubKeyword) {
|
||||||
return PubKeyword;
|
return PubKeyword;
|
||||||
}
|
}
|
||||||
return StructKeyword;
|
return StructKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* StructDeclaration::getLastToken() const {
|
Token* RecordDeclaration::getLastToken() const {
|
||||||
if (Fields.size()) {
|
if (Fields.size()) {
|
||||||
Fields.back()->getLastToken();
|
Fields.back()->getLastToken();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue