2024-04-21 22:24:35 +08:00
|
|
|
|
using Canon.Core.CodeGenerators;
|
|
|
|
|
using Canon.Core.Enums;
|
|
|
|
|
using Canon.Core.LexicalParser;
|
2024-04-07 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Canon.Core.SyntaxNodes;
|
|
|
|
|
|
|
|
|
|
public class AddOperator : NonTerminatedSyntaxNode
|
|
|
|
|
{
|
|
|
|
|
public override NonTerminatorType Type => NonTerminatorType.AddOperator;
|
|
|
|
|
|
|
|
|
|
public static AddOperator Create(List<SyntaxNodeBase> children)
|
|
|
|
|
{
|
|
|
|
|
return new AddOperator { Children = children };
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
|
|
|
|
|
public override void GenerateCCode(CCodeBuilder builder)
|
|
|
|
|
{
|
2024-04-22 21:48:57 +08:00
|
|
|
|
var token = Children[0].Convert<TerminatedSyntaxNode>().Token;
|
|
|
|
|
if (token.TokenType == SemanticTokenType.Operator)
|
2024-04-21 22:24:35 +08:00
|
|
|
|
{
|
2024-04-22 21:48:57 +08:00
|
|
|
|
var operatorType = token.Convert<OperatorSemanticToken>().OperatorType;
|
|
|
|
|
if (operatorType == OperatorType.Plus)
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" +");
|
|
|
|
|
}
|
|
|
|
|
else if (operatorType == OperatorType.Minus)
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" -");
|
|
|
|
|
}
|
2024-04-21 22:24:35 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
builder.AddString(" ||");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-07 16:47:28 +08:00
|
|
|
|
}
|