1
// Copyright (c) 1996 James Clark
2
// See the file copying.txt for copying permission.
4
#ifndef ProcessingMode_INCLUDED
5
#define ProcessingMode_INCLUDED 1
13
#include "NamedTable.h"
14
#include "Expression.h"
18
#include "FOTBuilder.h"
22
#ifdef DSSSL_NAMESPACE
23
namespace DSSSL_NAMESPACE {
29
class ProcessingMode : public Named {
35
enum { nRuleType = 2 };
42
bool toInitial_; // 1 if the match fell through from a named processing mode to
43
// the initial processing mode
45
size_t nextRuleIndex_;
46
friend class ProcessingMode;
49
class Action : public Resource {
51
Action(unsigned partIndex, Owner<Expression> &, const Location &);
52
void compile(Interpreter &, RuleType);
53
void get(InsnPtr &, SosofoObj *&) const;
54
const Location &location() const;
55
unsigned partIndex() const;
58
Owner<Expression> expr_;
59
// One of these will be non-null.
69
Rule(const Ptr<Action> &);
70
const Action &action() const;
72
virtual int compareSpecificity(const Rule &) const;
73
const Location &location() const;
79
class ElementRule : public Rule, public Pattern, public Link {
81
ElementRule(const Ptr<Action> &, Pattern &);
82
int compareSpecificity(const Rule &) const;
85
ProcessingMode(const StringC &, const ProcessingMode *initial = 0);
86
void addRule(bool matchesRoot, NCVector<Pattern> &, Owner<Expression> &expr,
87
RuleType, const Location &, Interpreter &);
88
// Specificity gives specificity of last match; gets specificity of current match.
89
const Rule *findMatch(const NodePtr &, Pattern::MatchContext &, Messenger &,
91
void compile(Interpreter &);
95
struct ElementRules : public Named {
97
ElementRules(const StringC &);
98
Vector<const ElementRule *> rules[nRuleType];
104
NamedTable<ElementRules> elementTable;
105
Vector<const ElementRule *> otherRules[nRuleType];
106
void build(const IList<ElementRule> *, const NodePtr &, Messenger &);
107
static void sortRules(Vector<const ElementRule *> &v);
110
const Rule *findElementMatch(const StringC &, const NodePtr &,
111
Pattern::MatchContext &, Messenger &,
112
Specificity &) const;
113
const Rule *findRootMatch(const NodePtr &, Pattern::MatchContext &, Messenger &,
114
Specificity &) const;
115
const GroveRules &groveRules(const NodePtr &, Messenger &) const;
116
static void elementRuleAdvance(const NodePtr &nd, Pattern::MatchContext &context,
117
Messenger &mgr, Specificity &specificity,
118
const Vector<const ElementRule *> &vec);
120
Vector<Rule> rootRules_[nRuleType];
121
IList<ElementRule> elementRules_[nRuleType];
122
NCVector<GroveRules> groveRules_;
123
const ProcessingMode *initial_; // 0 for initial mode
129
bool ProcessingMode::defined() const
135
void ProcessingMode::setDefined()
141
ProcessingMode::Specificity::Specificity()
142
: toInitial_(0), nextRuleIndex_(0), ruleType_(styleRule)
147
bool ProcessingMode::Specificity::isStyle() const
149
return ruleType_ == styleRule;
153
void ProcessingMode::Action::get(InsnPtr &insn, SosofoObj *&sosofo) const
160
const Location &ProcessingMode::Action::location() const
166
ProcessingMode::Action &ProcessingMode::Rule::action()
172
const ProcessingMode::Action &ProcessingMode::Rule::action() const
178
unsigned ProcessingMode::Action::partIndex() const
184
const Location &ProcessingMode::Rule::location() const
186
return action_->location();
190
void ProcessingMode::Rule::swap(Rule &r)
192
action_.swap(r.action_);
195
#ifdef DSSSL_NAMESPACE
199
#endif /* not ProcessingMode_INCLUDED */