LCOV - app.info - js/src/jsopcodeinlines.h

LCOV - code coverage report
| Current view: | directory - js/src - jsopcodeinlines.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 37 | 36 | 97.3 %
| Date: | 2012-04-07 | Functions: | 11 | 10 | 90.9 %

           1                 : /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
           2                 :  *
           3                 :  * ***** BEGIN LICENSE BLOCK *****
           4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           5                 :  *
           6                 :  * The contents of this file are subject to the Mozilla Public License Version
           7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           8                 :  * the License. You may obtain a copy of the License at
           9                 :  * http://www.mozilla.org/MPL/
          10                 :  *
          11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          13                 :  * for the specific language governing rights and limitations under the
          14                 :  * License.
          15                 :  *
          16                 :  * The Original Code is the Mozilla SpiderMonkey JaegerMonkey implementation
          17                 :  *
          18                 :  * The Initial Developer of the Original Code is
          19                 :  *   Mozilla Foundation
          20                 :  * Portions created by the Initial Developer are Copyright (C) 2002-2010
          21                 :  * the Initial Developer. All Rights Reserved.
          22                 :  *
          23                 :  * Contributor(s):
          24                 :  *
          25                 :  * Alternatively, the contents of this file may be used under the terms of
          26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          29                 :  * of those above. If you wish to allow use of your version of this file only
          30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          31                 :  * use your version of this file under the terms of the MPL, indicate your
          32                 :  * decision by deleting the provisions above and replace them with the notice
          33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          34                 :  * the provisions above, a recipient may use your version of this file under
          35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          36                 :  *
          37                 :  * ***** END LICENSE BLOCK ***** */
          38                 :
          39                 : #include "jsautooplen.h"
          40                 :
          41                 : #include "frontend/BytecodeEmitter.h"
          42                 :
          43                 : namespace js {
          44                 :
          45                 : static inline PropertyName *
          46         5037393 : GetNameFromBytecode(JSContext *cx, jsbytecode *pc, JSOp op, const JSCodeSpec &cs)
          47                 : {
          48         5037393 :     if (op == JSOP_LENGTH)
          49            2095 :         return cx->runtime->atomState.lengthAtom;
          50                 :
          51                 :     // The method JIT's implementation of instanceof contains an internal lookup
          52                 :     // of the prototype property.
          53         5035298 :     if (op == JSOP_INSTANCEOF)
          54             419 :         return cx->runtime->atomState.classPrototypeAtom;
          55                 :
          56         5034879 :     JSScript *script = cx->stack.currentScriptWithDiagnostics();
          57                 :     PropertyName *name;
          58         5034879 :     GET_NAME_FROM_BYTECODE(script, pc, 0, name);
          59         5034879 :     return name;
          60                 : }
          61                 :
          62                 : class BytecodeRange {
          63                 :   public:
          64            4689 :     BytecodeRange(JSScript *script)
          65            4689 :       : script(script), pc(script->code), end(pc + script->length) {}
          66        17816238 :     bool empty() const { return pc == end; }
          67         6231033 :     jsbytecode *frontPC() const { return pc; }
          68         2969784 :     JSOp frontOpcode() const { return JSOp(*pc); }
          69        11874825 :     size_t frontOffset() const { return pc - script->code; }
          70        11871981 :     void popFront() { pc += GetBytecodeLength(pc); }
          71                 :
          72                 :   private:
          73                 :     JSScript *script;
          74                 :     jsbytecode *pc, *end;
          75                 : };
          76                 :
          77                 : class SrcNoteLineScanner
          78                 : {
          79                 :     /* offset of the current JSOp in the bytecode */
          80                 :     ptrdiff_t offset;
          81                 :
          82                 :     /* next src note to process */
          83                 :     jssrcnote *sn;
          84                 :
          85                 :     /* line number of the current JSOp */
          86                 :     uint32_t lineno;
          87                 :
          88                 :     /*
          89                 :      * Is the current op the first one after a line change directive? Note that
          90                 :      * multiple ops may be "first" if a line directive is used to return to a
          91                 :      * previous line (eg, with a for loop increment expression.)
          92                 :      */
          93                 :     bool lineHeader;
          94                 :
          95                 : public:
          96           96663 :     SrcNoteLineScanner(jssrcnote *sn, uint32_t lineno)
          97           96663 :         : offset(0), sn(sn), lineno(lineno)
          98                 :     {
          99           96663 :     }
         100                 :
         101                 :     /*
         102                 :      * This is called repeatedly with always-advancing relpc values. The src
         103                 :      * notes are tuples of <PC offset from prev src note, type, args>. Scan
         104                 :      * through, updating the lineno, until the next src note is for a later
         105                 :      * bytecode.
         106                 :      *
         107                 :      * When looking at the desired PC offset ('relpc'), the op is first in that
         108                 :      * line iff there is a SRC_SETLINE or SRC_NEWLINE src note for that exact
         109                 :      * bytecode.
         110                 :      *
         111                 :      * Note that a single bytecode may have multiple line-modifying notes (even
         112                 :      * though only one should ever be needed.)
         113                 :      */
         114         4118172 :     void advanceTo(ptrdiff_t relpc) {
         115                 :         // Must always advance! If the same or an earlier PC is erroneously
         116                 :         // passed in, we will already be past the relevant src notes
         117         4118172 :         JS_ASSERT_IF(offset > 0, relpc > offset);
         118                 :
         119                 :         // Next src note should be for after the current offset
         120         4118172 :         JS_ASSERT_IF(offset > 0, SN_IS_TERMINATOR(sn) || SN_DELTA(sn) > 0);
         121                 :
         122                 :         // The first PC requested is always considered to be a line header
         123         4118172 :         lineHeader = (offset == 0);
         124                 :
         125         4118172 :         if (SN_IS_TERMINATOR(sn))
         126          197284 :             return;
         127                 :
         128                 :         ptrdiff_t nextOffset;
         129        10836993 :         while ((nextOffset = offset + SN_DELTA(sn)) <= relpc && !SN_IS_TERMINATOR(sn)) {
         130         2995217 :             offset = nextOffset;
         131         2995217 :             SrcNoteType type = (SrcNoteType) SN_TYPE(sn);
         132         2995217 :             if (type == SRC_SETLINE || type == SRC_NEWLINE) {
         133         1163459 :                 if (type == SRC_SETLINE)
         134          274785 :                     lineno = js_GetSrcNoteOffset(sn, 0);
         135                 :                 else
         136          888674 :                     lineno++;
         137                 :
         138         1163459 :                 if (offset == relpc)
         139          603720 :                     lineHeader = true;
         140                 :             }
         141                 :
         142         2995217 :             sn = SN_NEXT(sn);
         143                 :         }
         144                 :     }
         145                 :
         146             141 :     bool isLineHeader() const {
         147             141 :         return lineHeader;
         148                 :     }
         149                 :
         150               0 :     uint32_t getLine() const { return lineno; }
         151                 : };
         152                 :
         153                 : }

Generated by: LCOV version 1.7