This file is indexed.

/usr/include/KF5/kjs/CompileState.h is in libkf5kjs-dev 5.28.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/*
 *  This file is part of the KDE libraries
 *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
 *  Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
 *  Copyright (C) 2007, 2008 Maksim Orlovich (maksim@kde.org)
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */
#ifndef COMPILE_STATE_H
#define COMPILE_STATE_H

#include "ExecState.h" // For codetype... Kinda odd.

#include "opcodes.h"
#include "bytecode/opargs.h"

#include <wtf/Assertions.h>
#include <wtf/HashSet.h>
#include <wtf/HashMap.h>

using WTF::HashSet;
using WTF::HashMap;
using WTF::Vector;

namespace KJS
{

class RegDescriptor;
class FunctionBodyNode;

enum CompileType {
    NotCompiled,
    Release,
    Debug
};

class CompileState
{
public:
    CompileState(CodeType ctype, CompileType compType, FunctionBodyNode *fbody, Register initialMaxTemp):
        localScopeVal(0), thisVal(0), globalScopeVal(0), evalResRegister(0),
        ctype(ctype), compType(compType), locals(initialMaxTemp, 0), initialMaxTemp(initialMaxTemp),
        maxTemp(initialMaxTemp), fbody(fbody), scopeDepth(0), finallyDepth(0), neededClosures(false)
    { }

    FunctionBodyNode *functionBody()
    {
        return fbody;
    }

    CodeType codeType() const
    {
        return ctype;
    }

    CodeBlock &codeBlock();

    CompileType compileType() const
    {
        return compType;
    }

    ~CompileState();

    // Returns true if the register is a formal temporary.
    bool isTemporaryReg(Register regNum)
    {
        return regNum >= initialMaxTemp;
    }

    // We distinguish two kinds of temporaries --- markable and not. They'll get
    // corresponding bits set in localStore when that's initialized.
    void requestTemporary(OpType type, OpValue *value, OpValue *reference);

    // This method is used to acquire a read value of a local...
    OpValue localReadVal(Register regNum);

    // And this one returns a reference, acquiring it for (immediate) write.
    // If there are any active read copies, we will backup the old value to
    // a temporary, and petchup their register descriptor to point to the backup.
    OpValue localWriteRef(CodeBlock &block, Register regNum);

    // This forces all live locals to temporaries.
    void localFlushAll(CodeBlock &block);

    // This sets the registers containing the local scope and
    // 'this' values... It should be the rvalue, not the regnums
    void setPreloadRegs(OpValue *localReg, OpValue *globalReg, OpValue *thisReg)
    {
        localScopeVal  = localReg;
        globalScopeVal = globalReg;
        thisVal        = thisReg;
    }

    OpValue *localScope()
    {
        return localScopeVal;
    }

    OpValue *thisValue()
    {
        return thisVal;
    }

    OpValue *globalScope()
    {
        return globalScopeVal;
    }

    void setEvalResultRegister(OpValue *val)
    {
        evalResRegister = val;
    }

    OpValue *evalResultReg()
    {
        return evalResRegister;
    }

    // To properly implement operations like continue and break, we need to keep track whether we
    // are nested inside with, try-catch and try-finally operations.
    // This serves two purposes:
    // 1) if we're not jumping out of a try-finally, we have to unwind the cleanup stacks
    // 2) if we're inside a try-finally, we have to jump to the finally and not
    //    do the normal operation (this applies to return as well)
    // Also, if we're inside a 'with' or a catch we cannot optimize local variable access.

    enum NestType {
        Scope,
        OtherCleanup,
        TryFinally,
        ContBreakTarget
    };

    void pushNest(NestType type, Node *node = 0);
    void popNest();

    struct NestInfo {
        NestType type;
        Node    *node;
    };

    bool inNestedScope()
    {
        return scopeDepth > 0;
    }

    bool inTryFinally()
    {
        return finallyDepth > 0;
    }

    const WTF::Vector<NestInfo>  &nestStack()
    {
        return nests;
    }

    // Some constructs can be detected at compile time to involve
    // taking of closures. We keep track of that and avoid stack-allocation
    // if those are present.
    bool needsClosures()
    {
        return neededClosures;
    }

    void setNeedsClosures()
    {
        neededClosures = true;
    }

    // Label stuff....

    // Registers a pending label. Returns true if the label is OK, false if it's a duplicate.
    // If it fails, the label stack isn't touched!
    bool pushLabel(const Identifier &label);
    void popLabel();

    // Binds all the labels to the given node
    void bindLabels(Node *node);

    // Returns destination for the label (node will be 0 if not found)
    Node *resolveContinueLabel(Identifier label);
    Node *resolveBreakLabel(Identifier label);

    // Sets the targets for break/continues w/o label name
    void pushDefaultBreak(Node *node);
    void pushDefaultContinue(Node *node);
    void popDefaultBreak();
    void popDefaultContinue();

    // Helpers for these and resolvePendingBreak
    void enterLoop(Node *node)
    {
        pushNest(ContBreakTarget, node);
        pushDefaultBreak(node);
        pushDefaultContinue(node);
    }

    void exitLoop(Node *node)
    {
        popNest();
        popDefaultBreak();
        popDefaultContinue();
        resolvePendingBreaks(node, CodeGen::nextPC(this));
    }

    // Adds break/continue as needing relevant target for given node
    void addPendingBreak(Node *node, Addr addr);
    void addPendingContinue(Node *node, Addr addr);

    // Patches up all pending break/continue statements to given destination.
    // LabelNode takes care of the breaks itself, the loops need to deal
    // with continue, though.
    void resolvePendingBreaks(Node *node, Addr dest);
    void resolvePendingContinues(Node *node, Addr dest);
private:
    OpValue *localScopeVal;
    OpValue *thisVal;
    OpValue *globalScopeVal;
    OpValue *evalResRegister;

    CodeType ctype;
    CompileType compType;

    // Makes sure that any values of a local are
    void flushLocal(CodeBlock &block, Register reg);

    friend class RegDescriptor;
    WTF::Vector<RegDescriptor *> locals;
    WTF::Vector<RegDescriptor *> freeMarkTemps;
    WTF::Vector<RegDescriptor *> freeNonMarkTemps;
    Register initialMaxTemp;
    Register maxTemp;

    FunctionBodyNode *fbody;

    void reuse(RegDescriptor *desc, bool markable)
    {
        if (markable) {
            freeMarkTemps.append(desc);
        } else {
            freeNonMarkTemps.append(desc);
        }
    }

    // Cached version of #of Scopes's from below.
    int scopeDepth;

    // Cached version of #of Finally's from below...
    int finallyDepth;

    WTF::Vector<NestInfo> nests;

    // This is true if we see code constructs that require taking a closure
    // inside here, which means we should not stack-allocate activations.
    bool neededClosures;

    // Label resolution..
    WTF::HashSet<Identifier> seenLabels;    // all labels we're inside
    WTF::Vector <Identifier> seenLabelsStack;
    WTF::Vector <Identifier> pendingLabels; // labels tha that haven't been bound to
    // a statement yet.

    // Targets for continue/break w/o destination.
    WTF::Vector<Node *> defaultBreakTargets;
    WTF::Vector<Node *> defaultContinueTargets;

    // Named label targets
    WTF::HashMap<Identifier, Node *> labelTargets;

    WTF::HashMap<Node *, WTF::Vector<Addr>* > pendingBreaks;
    WTF::HashMap<Node *, WTF::Vector<Addr>* > pendingContinues;
};

// We used register descriptors for two reasons:
// 1) For temporaries, we ref-counted them by OpValue in order to manage their lifetime
// 2) For locals, we use them to do COW of values...
class RegDescriptor
{
public:
    RegDescriptor(CompileState *owner, Register reg, bool markable, bool temp = true):
        owner(owner), regNo(reg), temp(temp), markable(markable), killed(false), refCount(0)
    {}

    Register reg() const
    {
        return regNo;
    }

    void ref()
    {
        ++refCount;
    }

    void deref()
    {
        --refCount;
        if (refCount == 0) {
            if (killed) {
                delete this;
            } else if (temp) {
                owner->reuse(this, markable);
            }
        }
    }

    bool live()
    {
        return refCount > 0;
    }

    void adopt(RegDescriptor *other)
    {
        // Make this point to the same as an another descriptor, which is about to die..
        temp     = other->temp;
        markable = other->markable;
        regNo    = other->regNo;

        // Mark the other descriptor as killed, as we took ownership of this.
        other->killed = true;
    }
private:
    CompileState *owner;
    Register      regNo;
    bool temp;
    bool markable;
    bool killed;
    int  refCount;
};

inline OpValue OpValue::immInt32(int32_t in)
{
    OpValue res;
    initImm(&res, OpType_int32);
    res.value.narrow.int32Val = in;
    return res;
}

inline OpValue OpValue::immNumber(double in)
{
    OpValue res;
    initImm(&res, OpType_number);
    res.value.wide.numberVal = in;
    return res;
}

inline OpValue OpValue::immValue(JSValue *in)
{
    assert(in);
    OpValue res;
    initImm(&res, OpType_value);
    res.value.wide.valueVal = in;
    return res;
}

inline OpValue OpValue::immBool(bool in)
{
    OpValue res;
    initImm(&res, OpType_bool);
    res.value.narrow.boolVal = in;
    return res;
}

inline OpValue OpValue::immString(UString *in)
{
    OpValue res;
    initImm(&res, OpType_string);
    res.value.wide.stringVal = in;
    return res;
}

inline OpValue OpValue::immIdent(Identifier *in)
{
    OpValue res;
    initImm(&res, OpType_ident);
    res.value.wide.identVal = in;
    return res;
}

inline OpValue OpValue::immNode(KJS::Node *in)
{
    OpValue res;
    initImm(&res, OpType_node);
    res.value.wide.nodeVal = in;
    return res;
}

inline OpValue OpValue::immCStr(const char *in)
{
    OpValue res;
    initImm(&res, OpType_cstr);
    res.value.wide.cstrVal = in;
    return res;
}

inline OpValue OpValue::immAddr(Addr in)
{
    OpValue res;
    initImm(&res, OpType_addr);
    res.value.narrow.addrVal = in;
    return res;
}

inline OpValue::OpValue(): type(OpType_void) {} // since should never occur as an argument..

}

#endif