private string TraverseIfElseStmt(IfElseStmt ifElseStmt) { return(ifElseStmt.ElseBody != null ? string.Format("if({0}) {1} else {2}", TraverseStmt(ifElseStmt.Condition), GenerateSeparateStmt(ifElseStmt.ThenBody), GenerateSeparateStmt(ifElseStmt.ElseBody)) : string.Format("if({0}) {1}", TraverseStmt(ifElseStmt.Condition), GenerateSeparateStmt(ifElseStmt.ThenBody))); }
public override IAstNode VisitIfElseStmt(MicroCParser.IfElseStmtContext context) { var label = ++_label; IBExpr condition = Visit(context.b_expr()) as IBExpr; UnscopedBlock ifBody = Visit(context.ifBody) as UnscopedBlock; UnscopedBlock elseBody = Visit(context.elseBody) as UnscopedBlock; var ifElseStmt = new IfElseStmt(condition, ifBody, elseBody); ifElseStmt.Label = label; return(ifElseStmt); }
protected override ILattice <FVDomain> TransferFunctions(int label) { var block = GetBlock(label); var domain = _analysisCircle[label].GetDomain(); var newDomain = block switch { AssignStmt assignStmt => AssignTransfer(assignStmt, domain), RecAssignStmt recAssignStmt => RecAssignTransfer(recAssignStmt, domain), IfStmt ifStmt => ConditionTransfer(ifStmt.Condition, domain), IfElseStmt ifElseStmt => ConditionTransfer(ifElseStmt.Condition, domain), WhileStmt whileStmt => ConditionTransfer(whileStmt.Condition, domain), WriteStmt writeStmt => WriteTransfer(writeStmt, domain), ReadStmt readStmt => ReadTransfer(readStmt, domain), _ => new FVDomain(), }; return(new FVLattice(newDomain)); }
protected override ILattice <IADomain> TransferFunctions(int label) { var block = GetBlock(label); var domain = _analysisCircle[label].GetDomain(); var newDomain = block switch { IntDecl intDecl => IntDeclTransfer(intDecl, domain), ArrayDecl arrayDecl => ArrayDeclTransfer(arrayDecl, domain), RecordDecl recordDecl => RecDeclTransfer(recordDecl, domain), AssignStmt assignStmt => AssignTransfer(assignStmt, domain), RecAssignStmt recAssignStmt => RecAssignTransfer(recAssignStmt, domain), IfStmt ifStmt => IdTransfer(ifStmt, domain), IfElseStmt ifElseStmt => IdTransfer(ifElseStmt, domain), WhileStmt whileStmt => IdTransfer(whileStmt, domain), WriteStmt writeStmt => IdTransfer(writeStmt, domain), ReadStmt readStmt => ReadTransfer(readStmt, domain), _ => Bottom().GetDomain(), }; return(new IALattice(newDomain)); }
public static Int32 Parse(List<Token> src, Int32 begin, out Stmt stmt) { stmt = null; Int32 current; Expr expr; if (Parser.IsKeyword(src[begin], KeywordVal.SWITCH)) { // switch current = begin + 1; current = Parser.ParseParenExpr(src, current, out expr); if (current == -1) { return -1; } current = _statement.Parse(src, current, out stmt); if (current == -1) { return -1; } stmt = new SwitchStmt(expr, stmt); return current; } else if (Parser.IsKeyword(src[begin], KeywordVal.IF)) { // if current = begin + 1; current = Parser.ParseParenExpr(src, current, out expr); if (current == -1) { return -1; } Stmt true_stmt; current = _statement.Parse(src, current, out true_stmt); if (current == -1) { return -1; } if (!Parser.IsKeyword(src[current], KeywordVal.ELSE)) { stmt = new IfStmt(expr, true_stmt); return current; } current++; Stmt false_stmt; current = _statement.Parse(src, current, out false_stmt); if (current == -1) { return -1; } stmt = new IfElseStmt(expr, true_stmt, false_stmt); return current; } else { return -1; } }