codemod 2010-2016 to 2010-present
[hiphop-php.git] / hphp / runtime / base / tv-arith.h
bloba27409562e46a29fade83eb0ba3d6d7e8a991075
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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_RUNTIME_BASE_TV_ARITH_H_
17 #define incl_HPHP_RUNTIME_BASE_TV_ARITH_H_
19 #include "hphp/runtime/base/tv-helpers.h"
20 #include "hphp/runtime/base/type-variant.h"
21 #include "hphp/runtime/base/typed-value.h"
23 namespace HPHP {
25 //////////////////////////////////////////////////////////////////////
28 * These functions return Cells by value. In cases where they may
29 * return reference counted types, the value is already incRef'd when
30 * returned.
34 * PHP operator +
36 * Returns a TypedNum, unless both arguments are KindOfArray, in which
37 * case it returns an Cell that contains an Array.
39 Cell cellAdd(Cell, Cell);
42 * PHP operators - and *.
44 * These arithmetic operators on any php value only return numbers.
46 TypedNum cellSub(Cell, Cell);
47 TypedNum cellMul(Cell, Cell);
50 * Same as their corresponding non-O functions, but will cast their sources to
51 * doubles instead of doing integer overflow.
53 Cell cellAddO(Cell, Cell);
54 TypedNum cellSubO(Cell, Cell);
55 TypedNum cellMulO(Cell, Cell);
58 * PHP operators / and %.
60 * The operators return numbers unless the second argument converts to
61 * zero, in which case they return boolean false.
63 Cell cellDiv(Cell, Cell);
64 Cell cellMod(Cell, Cell);
67 * PHP Operator **.
69 * Always returns a TypedNum.
71 Cell cellPow(Cell, Cell);
74 * PHP operators &, |, and ^.
76 * These operators return a KindOfInt64, unless both arguments are
77 * KindOfString, in which case they return a KindOfString that the caller owns
78 * a reference to.
80 Cell cellBitAnd(Cell, Cell);
81 Cell cellBitOr(Cell, Cell);
82 Cell cellBitXor(Cell, Cell);
85 * PHP operators << and >>.
87 * These operators always return a KindOfInt64.
89 Cell cellShl(Cell, Cell);
90 Cell cellShr(Cell, Cell);
92 //////////////////////////////////////////////////////////////////////
95 * PHP operator +=
97 * Mutates the first argument in place, by adding the second argument
98 * to it in the sense of php's operator +=.
100 * Post: isTypedNum(c1), unless both arguments are KindOfArray, in
101 * which case it will contain a Cell of KindOfArray.
103 void cellAddEq(Cell& c1, Cell);
106 * PHP operators -= and *=.
108 * Mutates the first argument in place, by combining the second
109 * argument with it in the sense of either php operator -= or *=.
111 * Post: isTypedNum(c1)
113 void cellSubEq(Cell& c1, Cell);
114 void cellMulEq(Cell& c1, Cell);
117 * Same as their corresponding non-O functions, but will cast their sources to
118 * doubles instead of doing integer overflow.
120 void cellAddEqO(Cell& c1, Cell c2);
121 void cellSubEqO(Cell& c1, Cell c2);
122 void cellMulEqO(Cell& c1, Cell c2);
125 * PHP operators /= and %=.
127 * Mutates the first argument in place, by combining the second
128 * argument with it in the sense of either php operator /= or %=.
130 * Post: isTypedNum(c1), unless the second argument converts to zero,
131 * in which case c1 will contain boolean false.
133 void cellDivEq(Cell& c1, Cell);
134 void cellModEq(Cell& c1, Cell);
137 * PHP operator **=.
139 * Mutates the first argument in place, by combining the second
140 * argument with it in the of php operator **=.
142 void cellPowEq(Cell& c1, Cell);
145 * PHP operators &=, |=, and ^=.
147 * Mutates the first argument in place, by combining the second
148 * argument with it in the sense of the appropriate operator.
150 * Post: c1.m_type == KindOfString || c1.m_type == KindOfInt64
152 void cellBitAndEq(Cell& c1, Cell);
153 void cellBitOrEq(Cell& c1, Cell);
154 void cellBitXorEq(Cell& c1, Cell);
157 * PHP operators <<= and >>=.
159 * Mutates the first argument in place, by combining the second argument
160 * with it in the sense of the appropriate operator.
162 * Post: c1.m_type == KindOfInt64
164 void cellShlEq(Cell& c1, Cell);
165 void cellShrEq(Cell& c1, Cell);
168 * PHP operator .=.
170 * Mutates the first argument in place, by concatenating the second argument
171 * onto its end.
173 * Post: lhs.m_type == KindOfString
175 inline void cellConcatEq(Cell& lhs, Cell rhs) {
176 concat_assign(tvAsVariant(&lhs), cellAsCVarRef(rhs).toString());
179 //////////////////////////////////////////////////////////////////////
182 * PHP operator ++ and --.
184 * Mutates the argument in place, with the effects of php's
185 * pre-increment or pre-decrement operators.
187 void cellInc(Cell&);
188 void cellDec(Cell&);
190 void cellIncO(Cell&);
191 void cellDecO(Cell&);
194 * PHP unary operator ~.
196 * Mutates the argument in place, with the effects of php's unary
197 * bitwise not operator.
199 void cellBitNot(Cell&);
201 //////////////////////////////////////////////////////////////////////
205 #endif