/usr/include/KF5/kjs/makenodes.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 | /*
* This file is part of the KDE libraries
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
* Copyright (C) 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef MAKENODES_H
#define MAKENODES_H
#include "nodes.h"
#include "identifier.h"
#define OPTIMIZE_NODES
//#define TRACE_OPTIMIZER
namespace KJS
{
// Shorthand wrappers for entering function contexts
static void inFuncExpr()
{
parser().pushFunctionContext(FuncFl_Expr);
}
static void inFuncDecl()
{
parser().pushFunctionContext(FuncFl_Decl);
}
static Node *makeAssignNode(Node *loc, Operator op, Node *expr)
{
return new AssignNode(loc, op, expr);
}
static Node *makeConditionalNode(Node *l, Node *e1, Node *e2)
{
return new ConditionalNode(l, e1, e2);
}
static Node *makePrefixNode(Node *expr, Operator op)
{
return new PrefixNode(expr, op);
}
static Node *makePostfixNode(Node *expr, Operator op)
{
return new PostfixNode(expr, op);
}
static Node *makeFunctionCallNode(Node *func, ArgumentsNode *args)
{
Node *n = func->nodeInsideAllParens();
if (!n->isLocation()) {
return new FunctionCallValueNode(func, args);
} else {
return new FunctionCallReferenceNode(func, args);
}
}
static Node *makeTypeOfNode(Node *expr)
{
Node *n = expr->nodeInsideAllParens();
// We only need to use the special path for variable references,
// since they may throw a ResolveError on evaluate where we don't
// want that...
if (n->isVarAccessNode()) {
return new TypeOfVarNode(static_cast<VarAccessNode *>(n));
} else {
return new TypeOfValueNode(expr);
}
}
static Node *makeDeleteNode(Node *expr)
{
Node *n = expr->nodeInsideAllParens();
if (!n->isLocation()) {
return new DeleteValueNode(expr);
} else {
return new DeleteReferenceNode(static_cast<LocationNode *>(n)); //### not 100% faithful listing?
}
}
static bool makeGetterOrSetterPropertyNode(PropertyNode *&result, Identifier &getOrSet, Identifier &name, ParameterNode *params, FunctionBodyNode *body)
{
PropertyNode::Type type;
if (getOrSet == "get") {
type = PropertyNode::Getter;
} else if (getOrSet == "set") {
type = PropertyNode::Setter;
} else {
return false;
}
result = new PropertyNode(new PropertyNameNode(name),
new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, body, params), type);
return true;
}
static Node *makeAddNode(Node *n1, Node *n2, Operator op)
{
#ifdef OPTIMIZE_NODES
if (n1->isNumber()) {
if (n2->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing ADDNODE NUMBER NUMBER as NUMBER\n");
#endif
NumberNode *number1 = static_cast< NumberNode * >(n1);
NumberNode *number2 = static_cast< NumberNode * >(n2);
double d1 = number1->value();
double d2 = number2->value();
number1->setValue(op == OpPlus ? d1 + d2 : d1 - d2);
return number1;
}
#ifdef TRACE_OPTIMIZER
printf("could optimize as ADD NODE NUMBER\n");
#endif
}
if (n2->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("could optimize as ADD NODE NUMBER\n");
#endif
}
if (op == OpPlus && n1->isString() && n2->isString()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing ADDNODE STRING STRING as STRING\n");
#endif
StringNode *str1 = static_cast<StringNode *>(n1);
StringNode *str2 = static_cast<StringNode *>(n2);
str1->setValue(str1->value() + str2->value());
return str1;
}
#endif
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeMultNode(Node *n1, Node *n2, Operator op)
{
#ifdef OPTIMIZE_NODES
if (n1->isNumber()) {
if (n2->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing MULTNODE NUMBER NUMBER as NUMBER\n");
#endif
NumberNode *number1 = static_cast< NumberNode * >(n1);
NumberNode *number2 = static_cast< NumberNode * >(n2);
double d1 = number1->value();
double d2 = number2->value();
double res;
if (op == OpMult) {
res = d1 * d2;
} else if (op == OpDiv) {
res = d1 / d2;
} else { // OpMod
res = fmod(d1, d2);
}
number1->setValue(res);
return number1;
}
#ifdef TRACE_OPTIMIZER
printf("could optimize as MULT NODE NUMBER\n");
#endif
}
if (n2->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("could optimize as MULT NODE NUMBER\n");
#endif
}
#endif
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeShiftNode(Node *n1, Node *n2, Operator op)
{
#ifdef OPTIMIZE_NODES
if (n1->isNumber() && n2->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing MULTNODE NUMBER NUMBER as NUMBER\n");
#endif
NumberNode *number1 = static_cast< NumberNode * >(n1);
NumberNode *number2 = static_cast< NumberNode * >(n2);
double val = number1->value();
uint32_t shiftAmount = toUInt32(number2->value());
switch (op) {
case OpLShift:
// operator <<
number1->setValue(toInt32(val) << (shiftAmount & 0x1f));
break;
case OpRShift:
// operator >>
number1->setValue(toInt32(val) >> (shiftAmount & 0x1f));
break;
case OpURShift:
// operator >>>
number1->setValue(toUInt32(val) >> (shiftAmount & 0x1f));
break;
default:
assert(false);
break;
}
return number1;
}
#endif
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeRelationalNode(Node *n1, Operator op, Node *n2)
{
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeEqualNode(Node *n1, Operator op, Node *n2)
{
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeBitOperNode(Node *n1, Operator op, Node *n2)
{
return new BinaryOperatorNode(n1, n2, op);
}
static Node *makeBinaryLogicalNode(Node *n1, Operator op, Node *n2)
{
return new BinaryLogicalNode(n1, op, n2);
}
static Node *makeUnaryPlusNode(Node *n)
{
#ifdef OPTIMIZE_NODES
if (n->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing UNARYPLUS NUMBER\n");
#endif
return n;
}
#endif
return new UnaryPlusNode(n);
}
static Node *makeNegateNode(Node *n)
{
#ifdef OPTIMIZE_NODES
if (n->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing NEGATE NUMBER\n");
#endif
NumberNode *number = static_cast <NumberNode *>(n);
number->setValue(-number->value());
return number;
}
#endif
return new NegateNode(n);
}
static Node *makeBitwiseNotNode(Node *n)
{
#ifdef OPTIMIZE_NODES
if (n->isNumber()) {
#ifdef TRACE_OPTIMIZER
printf("Optimizing BITWISENOT NUMBER\n");
#endif
NumberNode *number = static_cast <NumberNode *>(n);
number->setValue(~toInt32(number->value()));
return number;
}
#endif
return new BitwiseNotNode(n);
}
static Node *makeLogicalNotNode(Node *n)
{
return new LogicalNotNode(n);
}
static Node *makeGroupNode(Node *n)
{
if (n->isVarAccessNode() || n->isGroupNode()) {
return n;
}
return new GroupNode(n);
}
static StatementNode *makeIfNode(Node *e, StatementNode *s1, StatementNode *s2)
{
return new IfNode(e, s1, s2);
}
static StatementNode *makeImportNode(PackageNameNode *n,
bool wildcard, const Identifier &a)
{
ImportStatement *stat = new ImportStatement(n);
if (wildcard) {
stat->enableWildcard();
}
stat->setAlias(a);
return stat;
}
static StatementNode *makeLabelNode(const Identifier &l, StatementNode *s)
{
return new LabelNode(l, s);
}
} // namespace KJS
#endif
// vi: set sw=4 :
|