public override void VisitNot(ASTNot n) { //evaluate expression n.Expression.Visit(this); //compare it with 0 to negate _gen.Emit(OpCodes.Ldc_I4_0); _gen.Emit(OpCodes.Ceq); _lastWalkedType = typeof(bool); }
public override void VisitNot(ASTNot n) { CFlatType t = CheckSubTree(n.Expression); if (t is TypeBool) { n.CFlatType = t; _lastSeenType = t; } else { ReportError(n.Location, "Operand for the not operator must be a boolean. Got type '{0}'", TypeToFriendlyName(t)); } }
protected override bool Visit(ASTNot node) { if (!Visit(node.Child)) { return(false); } var childType = node.Child.TypeInfo; if (!(childType is BooleanType)) { Error(node.Position, $"Cannot not none Boolean type {childType}"); return(false); } node.TypeInfo = childType; return(true); }
protected override bool Visit(ASTNot node) => EmitUnary <CNot>(node);
private ASTNode ParseUnary() { ASTUnary topPrefix = null, leafPrefix = null; for (;;) { ASTUnary res; if (EatToken(TokenKind.ExclamationMark)) { res = new ASTNot(EatenToken.Position); } else if (EatToken(TokenKind.KeywordNew)) { res = new ASTNew(EatenToken.Position); } else { break; } if (topPrefix == null) { topPrefix = res; leafPrefix = res; } else { leafPrefix.Child = res; leafPrefix = res; } } var result = ParseTerm(); if (result == null) { return(null); } ASTUnary topPostfix = null, leafPostfix = null; for (;;) { ASTUnary res; if (EatToken(TokenKind.SquareLeft)) { var expr = ParseExpression(); if (expr == null) { return(null); } if (!EatExpect(TokenKind.SquareRight)) { return(null); } res = new ASTIndexing(PeekToken().Position) { Value = expr }; } else if (EatToken(TokenKind.ParenthesesLeft)) { var start = EatenToken; var arguments = new List <ASTNode>(); while (!EatToken(TokenKind.ParenthesesRight)) { if (arguments.Count != 0 && !EatExpect(TokenKind.Comma)) { return(null); } var argument = ParseExpression(); if (argument == null) { return(null); } arguments.Add(argument); } res = new ASTCall(start.Position) { Arguments = arguments }; } else { break; } if (topPostfix == null) { leafPostfix = res; topPostfix = res; } else { res.Child = topPostfix; topPostfix = res; } } if (leafPostfix != null) { leafPostfix.Child = result; result = topPostfix; } if (leafPrefix != null) { leafPrefix.Child = result; result = topPrefix; } return(result); }
public bool Visit(ASTNot node) { throw new NotImplementedException(); }
protected abstract bool Visit(ASTNot node);