xpcom/analysis/mayreturn.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/analysis/mayreturn.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/* May-return analysis.
     1.9 + * This makes sense only for functions that return a value. The analysis
    1.10 + * determines the set of variables that may transitively reach the return
    1.11 + * statement. */
    1.12 +
    1.13 +function MayReturnAnalysis() {
    1.14 +  BackwardAnalysis.apply(this, arguments);
    1.15 +  // May-return variables. We collect them all here.
    1.16 +  this.vbls = create_decl_set();
    1.17 +  // The return value variable itself
    1.18 +  this.retvar = undefined;
    1.19 +}
    1.20 +
    1.21 +MayReturnAnalysis.prototype = new BackwardAnalysis;
    1.22 +
    1.23 +MayReturnAnalysis.prototype.flowState = function(isn, state) {
    1.24 +  if (TREE_CODE(isn) == GIMPLE_RETURN) {
    1.25 +    let v = return_expr(isn);
    1.26 +    if (!v)
    1.27 +      return;
    1.28 +    if (v.tree_code() == RESULT_DECL) // only an issue with 4.3
    1.29 +      throw new Error("Weird case hit");
    1.30 +    this.vbls.add(v);
    1.31 +    state.add(v);
    1.32 +    this.retvar = v;
    1.33 +  } else if (TREE_CODE(isn) == GIMPLE_ASSIGN) {
    1.34 +    let lhs = gimple_op(isn, 0);
    1.35 +    let rhs = gimple_op(isn, 1);
    1.36 +    if (DECL_P(rhs) && DECL_P(lhs) && state.has(lhs)) {
    1.37 +      this.vbls.add(rhs);
    1.38 +      state.add(rhs);
    1.39 +    }
    1.40 +
    1.41 +    for (let e in isn_defs(isn, 'strong')) {
    1.42 +      if (DECL_P(e)) {
    1.43 +        state.remove(e);
    1.44 +      }
    1.45 +    }
    1.46 +  }
    1.47 +};

mercurial