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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
|
// Copyright (c) 1996 James Clark
// See the file copying.txt for copying permission.
#ifndef ELObj_INCLUDED
#define ELObj_INCLUDED 1
#include <OpenSP/types.h>
#include "Collector.h"
#include <OpenSP/OutputCharStream.h>
#include <OpenSP/Boolean.h>
#include <OpenSP/Location.h>
#include "Node.h"
#include "FOTBuilder.h"
#include <string.h>
#ifdef DSSSL_NAMESPACE
namespace DSSSL_NAMESPACE {
#endif
class Interpreter;
class EvalContext;
class Unit;
class PairObj;
class FunctionObj;
class SymbolObj;
class KeywordObj;
class BoxObj;
class StringObj;
class SosofoObj;
class AppendSosofoObj;
class ColorObj;
class ColorSpaceObj;
class StyleObj;
class AddressObj;
class NodeListObj;
class NamedNodeListObj;
class Identifier;
class LengthSpec;
class DisplaySpaceObj;
class InlineSpaceObj;
class GlyphSubstTableObj;
class VectorObj;
class LanguageObj;
class SubgroveSpecObj;
class CreateSpecObj;
class ELObj : public Collector::Object {
public:
ELObj();
void *operator new(size_t, Collector &c) {
return c.allocateObject(0);
}
#ifdef SP_HAVE_PLACEMENT_OPERATOR_DELETE
private:
void operator delete(void *p) { }
public:
void operator delete(void *p, Collector &c) {
c.unallocateObject(p);
}
#endif
virtual bool isNil() const;
virtual bool isList() const;
virtual bool isTrue() const;
virtual PairObj *asPair();
virtual SymbolObj *asSymbol();
virtual KeywordObj *asKeyword();
virtual FunctionObj *asFunction();
virtual SosofoObj *asSosofo();
virtual AppendSosofoObj *asAppendSosofo();
virtual ColorObj *asColor();
virtual ColorSpaceObj *asColorSpace();
virtual StyleObj *asStyle();
virtual AddressObj *asAddress();
virtual DisplaySpaceObj *asDisplaySpace();
virtual InlineSpaceObj *asInlineSpace();
virtual GlyphSubstTableObj *asGlyphSubstTable();
virtual NodeListObj *asNodeList();
virtual NamedNodeListObj *asNamedNodeList();
virtual StringObj *convertToString(); // either symbol or string
virtual BoxObj *asBox();
virtual VectorObj *asVector();
virtual LanguageObj *asLanguage();
virtual SubgroveSpecObj *asSubgroveSpec();
virtual CreateSpecObj *asCreateSpec();
virtual bool charValue(Char &);
virtual bool stringData(const Char *&, size_t &);
virtual void print(Interpreter &, OutputCharStream &);
virtual void print(Interpreter &, OutputCharStream &, unsigned);
virtual bool exactIntegerValue(long &);
virtual bool realValue(double &);
virtual bool inexactRealValue(double &);
virtual bool lengthValue(long &);
virtual const FOTBuilder::GlyphId *glyphId() const;
virtual const LengthSpec *lengthSpec() const;
enum QuantityType {
noQuantity,
longQuantity,
doubleQuantity
};
virtual QuantityType quantityValue(long &, double &, int &);
virtual ELObj *resolveQuantities(bool force, Interpreter &,
const Location &);
virtual bool optSingletonNodeList(EvalContext &, Interpreter &, NodePtr &);
static bool equal(ELObj &, ELObj &);
// Note that in DSSSL2 unlike Scheme eqv? for lists and strings is the same
// as equal?. Only for vectors do they differ.
static bool eqv(ELObj &, ELObj &);
protected:
// This checks for equality of *distinct* objects.
virtual bool isEqual(ELObj &);
// This checks for equivalence of *distinct* objects.
virtual bool isEquiv(ELObj &);
};
class ErrorObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
private:
ErrorObj();
friend class Interpreter;
};
class UnspecifiedObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
private:
UnspecifiedObj();
friend class Interpreter;
};
class NilObj : public ELObj {
public:
bool isNil() const;
bool isList() const;
void print(Interpreter &, OutputCharStream &);
private:
NilObj();
friend class Interpreter;
};
class TrueObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
private:
TrueObj();
friend class Interpreter;
};
class FalseObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
bool isTrue() const;
private:
FalseObj();
friend class Interpreter;
};
class StringObj;
class CharObj;
class SymbolObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
SymbolObj *asSymbol();
StringObj *convertToString();
StringObj *name() const;
void traceSubObjects(Collector &) const;
FOTBuilder::Symbol cValue() const;
void setCValue(FOTBuilder::Symbol);
static const StringC &key(const SymbolObj &);
private:
SymbolObj(StringObj *);
StringObj *name_;
FOTBuilder::Symbol cValue_;
friend class Interpreter;
};
class Identifier;
class KeywordObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
KeywordObj *asKeyword();
const Identifier *identifier() const;
bool isEqual(ELObj &);
private:
KeywordObj(const Identifier *);
const Identifier *ident_;
friend class Interpreter;
};
class PairObj : public ELObj {
public:
PairObj(ELObj *car, ELObj *cdr);
ELObj *car();
ELObj *cdr();
void setCar(ELObj *);
void setCdr(ELObj *);
PairObj *asPair();
bool isList() const;
void print(Interpreter &, OutputCharStream &);
void traceSubObjects(Collector &) const;
ELObj *resolveQuantities(bool force, Interpreter &, const Location &);
bool isEqual(ELObj &);
bool isEquiv(ELObj &);
private:
ELObj *car_;
ELObj *cdr_;
};
class VectorObj : public ELObj, public Vector<ELObj *> {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
VectorObj();
VectorObj(Vector<ELObj *> &v);
void traceSubObjects(Collector &) const;
VectorObj *asVector();
bool isEqual(ELObj &);
bool isEquiv(ELObj &);
void print(Interpreter &, OutputCharStream &);
ELObj *resolveQuantities(bool force, Interpreter &, const Location &);
};
class CharObj : public ELObj {
public:
Char ch();
void print(Interpreter &, OutputCharStream &);
void display(Interpreter &, OutputCharStream &) const;
bool isEqual(ELObj &);
bool charValue(Char &);
private:
CharObj(Char);
Char ch_;
friend class Interpreter;
};
class StringObj : public ELObj, public StringC {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
StringObj();
StringObj(const StringC &str);
StringObj(const Char *, size_t);
void print(Interpreter &, OutputCharStream &);
StringObj *convertToString();
bool stringData(const Char *&, size_t &);
bool isEqual(ELObj &);
};
class IntegerObj : public ELObj {
public:
void print(Interpreter &, OutputCharStream &);
void print(Interpreter &, OutputCharStream &, unsigned);
bool exactIntegerValue(long &);
bool realValue(double &);
QuantityType quantityValue(long &, double &, int &);
bool isEqual(ELObj &);
private:
friend class Interpreter;
IntegerObj();
IntegerObj(long);
long n_;
};
class RealObj : public ELObj {
public:
RealObj(double);
bool realValue(double &);
bool inexactRealValue(double &);
QuantityType quantityValue(long &, double &, int &);
bool isEqual(ELObj &);
void print(Interpreter &, OutputCharStream &);
private:
double n_;
};
class LengthObj : public ELObj {
public:
LengthObj(long units);
bool lengthValue(long &);
QuantityType quantityValue(long &, double &, int &);
void print(Interpreter &, OutputCharStream &);
bool isEqual(ELObj &);
private:
long n_;
};
class QuantityObj : public ELObj {
public:
QuantityObj(double, int);
QuantityType quantityValue(long &, double &, int &);
void print(Interpreter &, OutputCharStream &);
bool isEqual(ELObj &);
bool realValue(double &);
bool inexactRealValue(double &);
private:
// This is in units per inch.
double val_;
int dim_;
};
class LengthSpec {
public:
enum Unknown { displaySize = 1, tableUnit };
LengthSpec();
LengthSpec(double);
LengthSpec(Unknown, double);
void operator+=(const LengthSpec &);
void operator+=(double d) { val_[0] += d; }
void operator-=(const LengthSpec &);
void operator-=(double d) { val_[0] -= d; }
void operator*=(double);
void operator/=(double);
bool convert(FOTBuilder::LengthSpec &) const;
bool convert(FOTBuilder::TableLengthSpec &) const;
private:
enum { nVals = 3 };
double val_[nVals];
};
class LengthSpecObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
LengthSpecObj(const LengthSpec &);
const LengthSpec *lengthSpec() const;
private:
Owner<LengthSpec> lengthSpec_;
};
class DisplaySpaceObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
DisplaySpaceObj(const FOTBuilder::DisplaySpace &);
const FOTBuilder::DisplaySpace &displaySpace() const;
DisplaySpaceObj *asDisplaySpace();
private:
Owner<FOTBuilder::DisplaySpace> displaySpace_;
};
class InlineSpaceObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
InlineSpaceObj(const FOTBuilder::InlineSpace &);
const FOTBuilder::InlineSpace &inlineSpace() const;
InlineSpaceObj *asInlineSpace();
private:
Owner<FOTBuilder::InlineSpace> inlineSpace_;
};
class UnresolvedQuantityObj : public ELObj {
public:
UnresolvedQuantityObj(double, Unit *, int);
ELObj *resolveQuantities(bool force, Interpreter &, const Location &);
private:
double val_;
Unit *unit_;
int unitExp_;
};
class UnresolvedLengthObj : public ELObj {
public:
UnresolvedLengthObj(long val, int valExp, Unit *);
ELObj *resolveQuantities(bool force, Interpreter &, const Location &);
private:
long val_;
Unit *unit_;
int valExp_;
};
class GlyphIdObj : public ELObj {
public:
GlyphIdObj(const FOTBuilder::GlyphId &);
const FOTBuilder::GlyphId *glyphId() const;
bool isEqual(ELObj &);
private:
FOTBuilder::GlyphId glyphId_;
};
class GlyphSubstTableObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
GlyphSubstTableObj(const ConstPtr<FOTBuilder::GlyphSubstTable> &);
GlyphSubstTableObj *asGlyphSubstTable();
const ConstPtr<FOTBuilder::GlyphSubstTable> &glyphSubstTable() const;
private:
ConstPtr<FOTBuilder::GlyphSubstTable> table_;
};
class AddressObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
AddressObj(FOTBuilder::Address::Type,
const NodePtr & = NodePtr(),
const StringC & = StringC(),
const StringC & = StringC(),
const StringC & = StringC());
AddressObj *asAddress();
const FOTBuilder::Address &address() const;
private:
Owner<FOTBuilder::Address> address_;
};
class NodeListObj : public ELObj {
public:
NodeListObj *asNodeList();
bool optSingletonNodeList(EvalContext &, Interpreter &, NodePtr &);
virtual NodePtr nodeListFirst(EvalContext &, Interpreter &) = 0;
virtual NodeListObj *nodeListRest(EvalContext &, Interpreter &) = 0;
virtual NodeListObj *nodeListNoOrder(Collector &);
// If this node contains all the node in the chunk of the first node, then
// this *may* return the node list containing the nodes following the chunk;
// If so chunk, will be set to 1. Otherwise return nodeListRest() and set
// chunk to 0. If charChunk() returns a string of length n, then
// the chunk of the node is the node together with the n - 1 following siblings;
// otherwise the chunk of the node is the node itself.
virtual NodeListObj *nodeListChunkRest(EvalContext &, Interpreter &, bool &chunk);
virtual NodePtr nodeListRef(long, EvalContext &, Interpreter &);
virtual NodeListObj *nodeListReverse(EvalContext &, Interpreter &);
virtual long nodeListLength(EvalContext &, Interpreter &);
virtual bool suppressError();
virtual bool contains(EvalContext &, Interpreter &, const NodePtr &);
// check for a node of class id
virtual bool contains(EvalContext &, Interpreter &, ComponentName::Id id);
void print(Interpreter &, OutputCharStream &);
};
class NamedNodeListObj : public NodeListObj {
public:
NamedNodeListObj *asNamedNodeList();
virtual NodePtr namedNode(const Char *, size_t) = 0;
virtual bool nodeName(const NodePtr &, GroveString &) = 0;
virtual size_t normalize(Char *, size_t) = 0;
};
class NodePtrNodeListObj : public NodeListObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
NodePtrNodeListObj();
NodePtrNodeListObj(const NodePtr &);
NodePtr nodeListFirst(EvalContext &, Interpreter &);
NodeListObj *nodeListRest(EvalContext &, Interpreter &);
bool optSingletonNodeList(EvalContext &, Interpreter &, NodePtr &);
bool chunkComplete();
private:
// Null for no node.
NodePtr node_;
};
class NodeListPtrNodeListObj : public NodeListObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
NodeListPtrNodeListObj(const NodeListPtr &);
NodePtr nodeListFirst(EvalContext &, Interpreter &);
NodeListObj *nodeListRest(EvalContext &, Interpreter &);
NodeListObj *nodeListChunkRest(EvalContext &, Interpreter &, bool &);
NodePtr nodeListRef(long, EvalContext &, Interpreter &);
private:
// never null
NodeListPtr nodeList_;
};
class NamedNodeListPtrNodeListObj : public NamedNodeListObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
NamedNodeListPtrNodeListObj(const NamedNodeListPtr &);
NodePtr nodeListFirst(EvalContext &, Interpreter &);
NodeListObj *nodeListRest(EvalContext &, Interpreter &);
NodePtr namedNode(const Char *, size_t);
bool nodeName(const NodePtr &, GroveString &);
size_t normalize(Char *, size_t);
NodeListObj *nodeListNoOrder(Collector &);
private:
NamedNodeListPtr namedNodeList_;
// cached node list, null if not yet computed
NodeListPtr nodeList_;
};
class PairNodeListObj : public NodeListObj {
public:
PairNodeListObj(NodeListObj *, NodeListObj *);
NodePtr nodeListFirst(EvalContext &, Interpreter &);
NodeListObj *nodeListRest(EvalContext &, Interpreter &);
NodeListObj *nodeListChunkRest(EvalContext &, Interpreter &, bool &);
void traceSubObjects(Collector &) const;
bool contains(EvalContext &, Interpreter &, const NodePtr &);
private:
NodeListObj *head_; // may be null
NodeListObj *tail_;
};
class SubgroveSpecObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
SubgroveSpecObj(NodePtr node, NodePtr subgrove, SymbolObj *cls,
ELObj *add, ELObj *null, ELObj *remove, ELObj *sub,
ELObj *children, ELObj *label, FunctionObj *sort);
SubgroveSpecObj *asSubgroveSpec();
~SubgroveSpecObj();
void traceSubObjects(Collector &) const;
private:
struct SubgroveSpec {
NodePtr node;
NodePtr subgrove;
SymbolObj *cls;
ELObj *add;
ELObj *null;
ELObj *remove;
ELObj *sub;
ELObj *children;
ELObj *label;
FunctionObj *sort;
};
SubgroveSpec *spec_;
};
class CreateSpecObj : public ELObj {
public:
void *operator new(size_t, Collector &c) {
return c.allocateObject(1);
}
enum Type {
root,
sub,
preced,
follow,
};
CreateSpecObj(Type t, ELObj *id, NodePtr node, SubgroveSpecObj *sg,
StringObj *property, ELObj *label,
FunctionObj *resultPath, bool optional, bool unique);
~CreateSpecObj();
CreateSpecObj *asCreateSpec();
void traceSubObjects(Collector &) const;
private:
struct CreateSpec {
Type type;
ELObj *groveId;
NodePtr node;
SubgroveSpecObj *sg;
StringObj *property;
ELObj *label;
FunctionObj *resultPath;
bool optional;
bool unique;
};
CreateSpec *spec_;
};
inline
bool ELObj::equal(ELObj &obj1, ELObj &obj2)
{
return &obj1 == &obj2 || obj1.isEqual(obj2);
}
inline
bool ELObj::eqv(ELObj &obj1, ELObj &obj2)
{
return &obj1 == &obj2 || obj1.isEquiv(obj2);
}
inline
ELObj *PairObj::car()
{
return car_;
}
inline
ELObj *PairObj::cdr()
{
return cdr_;
}
inline
void PairObj::setCar(ELObj *car)
{
car_ = car;
}
inline
void PairObj::setCdr(ELObj *cdr)
{
cdr_ = cdr;
}
inline
StringObj *SymbolObj::name() const
{
return name_;
}
inline
FOTBuilder::Symbol SymbolObj::cValue() const
{
return cValue_;
}
inline
void SymbolObj::setCValue(FOTBuilder::Symbol sym)
{
cValue_ = sym;
}
inline
Char CharObj::ch()
{
return ch_;
}
inline
const StringC &SymbolObj::key(const SymbolObj &sym)
{
return *sym.name();
}
inline
const Identifier *KeywordObj::identifier() const
{
return ident_;
}
inline
const FOTBuilder::Address &AddressObj::address() const
{
return *address_;
}
inline
const ConstPtr<FOTBuilder::GlyphSubstTable> &
GlyphSubstTableObj::glyphSubstTable() const
{
return table_;
}
#ifdef DSSSL_NAMESPACE
}
#endif
#endif /* not ELObj_INCLUDED */
|