codemod 2010-2016 to 2010-present
[hiphop-php.git] / hphp / compiler / statement / break_statement.cpp
blob6ef5861b7e6a97adddf5c6ca7ae59f010244b14c
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/compiler/statement/break_statement.h"
18 #include "hphp/compiler/expression/scalar_expression.h"
20 using namespace HPHP;
22 ///////////////////////////////////////////////////////////////////////////////
23 // constructors/destructors
25 BreakStatement::BreakStatement
26 (STATEMENT_CONSTRUCTOR_BASE_PARAMETERS, uint64_t depth)
27 : Statement(STATEMENT_CONSTRUCTOR_BASE_PARAMETER_VALUES),
28 m_depth(depth) {
29 m_name = "break";
32 BreakStatement::BreakStatement
33 (STATEMENT_CONSTRUCTOR_PARAMETERS, uint64_t depth)
34 : Statement(STATEMENT_CONSTRUCTOR_PARAMETER_VALUES(BreakStatement)),
35 m_depth(depth) {
36 m_name = "break";
39 StatementPtr BreakStatement::clone() {
40 BreakStatementPtr stmt(new BreakStatement(*this));
41 stmt->m_depth = m_depth;
42 stmt->m_name = m_name;
43 return stmt;
46 ///////////////////////////////////////////////////////////////////////////////
47 // parser functions
49 ///////////////////////////////////////////////////////////////////////////////
50 // static analysis functions
52 void BreakStatement::analyzeProgram(AnalysisResultPtr ar) {
55 ConstructPtr BreakStatement::getNthKid(int n) const {
56 always_assert(false);
59 int BreakStatement::getKidCount() const {
60 return 0;
63 void BreakStatement::setNthKid(int n, ConstructPtr cp) {
64 always_assert(false);
67 uint64_t BreakStatement::getDepth() {
68 return m_depth;
71 StatementPtr BreakStatement::preOptimize(AnalysisResultConstPtr ar) {
72 return StatementPtr();
75 ///////////////////////////////////////////////////////////////////////////////
76 // code generation functions
78 void BreakStatement::outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) {
79 if (m_depth != 1) {
80 cg_printf("%s %" PRIu64 ";\n", m_name, m_depth);
81 } else {
82 cg_printf("%s;\n", m_name);