~ubuntu-branches/ubuntu/trusty/openjade1.3/trusty

« back to all changes in this revision

Viewing changes to style/ProcessingMode.h

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-04-09 00:01:50 UTC
  • Revision ID: james.westby@ubuntu.com-20020409000150-r9rkyalxlhvf9ba3
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1996 James Clark
 
2
// See the file copying.txt for copying permission.
 
3
 
 
4
#ifndef ProcessingMode_INCLUDED
 
5
#define ProcessingMode_INCLUDED 1
 
6
 
 
7
#include "Named.h"
 
8
#include "StringC.h"
 
9
#include "Location.h"
 
10
#include "Owner.h"
 
11
#include "Vector.h"
 
12
#include "NCVector.h"
 
13
#include "NamedTable.h"
 
14
#include "Expression.h"
 
15
#include "Insn.h"
 
16
#include "Boolean.h"
 
17
#include "Node.h"
 
18
#include "FOTBuilder.h"
 
19
#include "IList.h"
 
20
#include "Pattern.h"
 
21
 
 
22
#ifdef DSSSL_NAMESPACE
 
23
namespace DSSSL_NAMESPACE {
 
24
#endif
 
25
 
 
26
class Interpreter;
 
27
class SosofoObj;
 
28
 
 
29
class ProcessingMode : public Named {
 
30
public:
 
31
  enum RuleType {
 
32
    styleRule,
 
33
    constructionRule
 
34
  };
 
35
  enum { nRuleType = 2 };
 
36
 
 
37
  class Specificity {
 
38
  public:
 
39
    Specificity();
 
40
    bool isStyle() const;
 
41
  private:
 
42
    bool toInitial_; // 1 if the match fell through from a named processing mode to
 
43
                     // the initial processing mode
 
44
    RuleType ruleType_;
 
45
    size_t nextRuleIndex_;
 
46
    friend class ProcessingMode;
 
47
  };
 
48
 
 
49
  class Action : public Resource {
 
50
  public:
 
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;
 
56
  private:
 
57
    Location defLoc_;
 
58
    Owner<Expression> expr_;
 
59
    // One of these will be non-null.
 
60
    InsnPtr insn_;
 
61
    // must be permanent
 
62
    SosofoObj *sosofo_;
 
63
    unsigned partIndex_;
 
64
  };
 
65
 
 
66
  class Rule {
 
67
  public:
 
68
    Rule();
 
69
    Rule(const Ptr<Action> &);
 
70
    const Action &action() const;
 
71
    Action &action();
 
72
    virtual int compareSpecificity(const Rule &) const;
 
73
    const Location &location() const;
 
74
    void swap(Rule &);
 
75
  private:
 
76
    Ptr<Action> action_;
 
77
  };
 
78
 
 
79
  class ElementRule : public Rule, public Pattern, public Link {
 
80
  public:
 
81
    ElementRule(const Ptr<Action> &, Pattern &);
 
82
    int compareSpecificity(const Rule &) const;
 
83
  };
 
84
 
 
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 &,
 
90
                        Specificity &) const;
 
91
  void compile(Interpreter &);
 
92
  bool defined() const;
 
93
  void setDefined();
 
94
 
 
95
  struct ElementRules : public Named {
 
96
  public:
 
97
    ElementRules(const StringC &);
 
98
    Vector<const ElementRule *> rules[nRuleType];
 
99
  };
 
100
 
 
101
  struct GroveRules {
 
102
    GroveRules();
 
103
    bool built;
 
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);
 
108
  };
 
109
private:
 
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);
 
119
 
 
120
  Vector<Rule> rootRules_[nRuleType];
 
121
  IList<ElementRule> elementRules_[nRuleType];
 
122
  NCVector<GroveRules> groveRules_;
 
123
  const ProcessingMode *initial_; // 0 for initial mode
 
124
  bool defined_;
 
125
};
 
126
 
 
127
 
 
128
inline
 
129
bool ProcessingMode::defined() const
 
130
{
 
131
  return defined_;
 
132
}
 
133
 
 
134
inline
 
135
void ProcessingMode::setDefined()
 
136
{
 
137
  defined_ = 1;
 
138
}
 
139
 
 
140
inline
 
141
ProcessingMode::Specificity::Specificity()
 
142
: toInitial_(0), nextRuleIndex_(0), ruleType_(styleRule)
 
143
{
 
144
}
 
145
 
 
146
inline
 
147
bool ProcessingMode::Specificity::isStyle() const
 
148
{
 
149
  return ruleType_ == styleRule;
 
150
}
 
151
 
 
152
inline
 
153
void ProcessingMode::Action::get(InsnPtr &insn, SosofoObj *&sosofo) const
 
154
{
 
155
  insn = insn_;
 
156
  sosofo = sosofo_;
 
157
}
 
158
 
 
159
inline
 
160
const Location &ProcessingMode::Action::location() const
 
161
{
 
162
  return defLoc_;
 
163
}
 
164
 
 
165
inline
 
166
ProcessingMode::Action &ProcessingMode::Rule::action()
 
167
{
 
168
  return *action_;
 
169
}
 
170
 
 
171
inline
 
172
const ProcessingMode::Action &ProcessingMode::Rule::action() const
 
173
{
 
174
  return *action_;
 
175
}
 
176
 
 
177
inline
 
178
unsigned ProcessingMode::Action::partIndex() const
 
179
{
 
180
  return partIndex_;
 
181
}
 
182
 
 
183
inline
 
184
const Location &ProcessingMode::Rule::location() const
 
185
{
 
186
  return action_->location();
 
187
}
 
188
 
 
189
inline
 
190
void ProcessingMode::Rule::swap(Rule &r)
 
191
{
 
192
  action_.swap(r.action_);
 
193
}
 
194
 
 
195
#ifdef DSSSL_NAMESPACE
 
196
}
 
197
#endif
 
198
 
 
199
#endif /* not ProcessingMode_INCLUDED */