// =========================================================================== // java_flow.h -- Java source-level definite-assignment/reachability model. // =========================================================================== // Source-semantic analysis only. No JVM/SLVM runtime is implied. #ifndef SLEELA_JAVA_FLOW_H #define SLEELA_JAVA_FLOW_H #include #include #include #include namespace sleela { enum class JavaFlowDiagnosticKind { UseBeforeAssignment, FinalReassignment, UnreachableStatement, InvalidBreak, InvalidContinue }; struct JavaFlowDiagnostic { JavaFlowDiagnosticKind kind = JavaFlowDiagnosticKind::UseBeforeAssignment; std::string variable; std::string message; bool error = true; }; struct JavaFlowFacts { std::set definitelyAssigned; std::set definitelyUnassigned; bool reachable = true; }; enum class JavaFlowExprKind { Literal, Variable, Assignment, CompoundAssignment, Unary, Binary, Conditional, Other }; struct JavaFlowExpr { JavaFlowExprKind kind = JavaFlowExprKind::Literal; std::string name; std::string op; std::vector children; }; enum class JavaFlowStmtKind { Empty, Block, LocalDeclaration, Expression, Assignment, If, While, Do, For, Switch, Break, Continue, Return, Throw, Assert, Try, Synchronized, Yield, Labeled }; struct JavaFlowStmt { JavaFlowStmtKind kind = JavaFlowStmtKind::Empty; std::string variable; bool finalVariable = false; bool hasInitializer = false; bool conditionConstant = false; bool conditionValue = false; JavaFlowExpr expression; JavaFlowExpr condition; // Explicit basic-for components. Empty condition means no condition. std::vector forInitialization; std::vector forUpdate; std::vector children; std::vector elseChildren; std::vector> switchCases; std::vector> catchBlocks; std::vector finallyBlock; std::string label; }; struct JavaFlowResult { JavaFlowFacts after; std::vector diagnostics; }; JavaFlowResult analyzeJavaFlow( const std::vector& statements, const std::set& initiallyAssigned = {}, const std::set& initiallyUnassigned = {}); const char* javaFlowDiagnosticName(JavaFlowDiagnosticKind kind); } // namespace sleela #endif