coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
reference.h
Go to the documentation of this file.
1 #ifndef REFERENCE_H
2 #define REFERENCE_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
6  * All rights reserved. *
7  * *
8  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
9  * *
10  * Redistribution and use in source and binary forms, with or without *
11  * modification, are permitted provided that the following conditions *
12  * are met: *
13  * *
14  * Redistributions of source code must retain the above copyright *
15  * notice, this list of conditions and the following disclaimer. *
16  * *
17  * Redistributions in binary form must reproduce the above copyright *
18  * notice, this list of conditions and the following disclaimer in the *
19  * documentation and/or other materials provided with the distribution. *
20  * *
21  * Neither the name of Mike Kinghan nor the names of its contributors *
22  * may be used to endorse or promote products derived from this software *
23  * without specific prior written permission. *
24  * *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
32  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
33  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
34  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
36  * DAMAGE. *
37  * *
38  **************************************************************************/
39 
40 #include "prohibit.h"
41 #include "symbol.h"
42 #include "argument_list.h"
43 #include "reference_cache.h"
44 #include <string>
45 
46 
56 struct reference
57 {
60 
71  explicit
72  reference(symbol::locator loc, reference const * invoker = nullptr)
73  : _referee(loc),
74  _args(_referee->parameters()),
75  _invoker(invoker),
76  _key(_referee.id() + _args.str()){}
77 
78 
83  symbol::locator loc,
84  argument_list const & args,
85  reference const * invoker = nullptr)
86  : _referee(loc),_args(args),
87  _invoker(invoker),
88  _key(_referee.id() + _args.str()){
90  }
91 
92 
104  template<class CharSeq>
106  symbol::locator loc,
107  chewer<CharSeq> & chew,
108  reference const * invoker = nullptr)
109  : _referee(loc),_args(chew),
110  _invoker(invoker),_key(_referee.id() + _args.str()) {
112  ">:[");
114  }
115 
116  virtual ~reference() = default;
117 
125  bool operator==(reference const & other) const {
126  return _referee.id() == other._referee.id() &&
127  _args == other._args;
128  }
129 
131  bool operator!=(reference const & other) const {
132  return !(*this == other);
133  }
134 
137  symbol::locator const & callee() const {
138  return _referee;
139  }
141  return _referee;
142  }
144 
146  std::string const & id() const {
147  return _referee.id();
148  }
149 
152  argument_list const & args() const {
153  return _args;
154  }
155  argument_list & args() {
156  return _args;
157  }
159 
161  virtual std::string const & invocation() const {
162  return _key;
163  }
164 
166  std::string const & expansion() {
167  return lookup().first->second.expansion();
168  }
169 
171  evaluation const & eval() {
172  return lookup().first->second.eval();
173  }
174 
176  bool reported() {
177  return lookup().first->second.reported();
178  }
179 
181  bool complete() {
182  return lookup().first->second.complete();
183  }
184 
186  void report() {
187  if (reportable()) {
188  do_report();
189  }
190  }
191 
192 protected:
193 
195  bool explain() const {
196  return _referee->configured() && explaining();
197  }
198 
202  bool explaining() const;
203 
205  bool reportable() const;
206 
208  void do_report();
209 
210 
214  }
215 
227 
230 
237 
243  evaluation validate() const;
244 
254  std::string _key;
255 };
256 
257 #endif //EOF
template struct traits::is_random_access_char_sequence<T> exports a static const boolean member value...
Definition: traits.h:166
bool operator!=(reference const &other) const
Inequality.
Definition: reference.h:131
reference(symbol::locator loc, reference const *invoker=nullptr)
Construct given a symbol locator.
Definition: reference.h:72
virtual std::string const & invocation() const
Get a string representation of the reference.
Definition: reference.h:161
void report()
Report this reference appropriately.
Definition: reference.h:186
void do_report()
Do reporting of the reference if reportable.
Definition: reference.cpp:144
argument_list const & args() const
Get a [const] reference to the argument_list of the reference.
Definition: reference.h:152
struct symbol::locator encapsulates a symbol table entry.
Definition: symbol.h:79
static iterator lower_bound(std::string const &key)
Get an iteraror to the lower bound of a key in the cache.
symbol::locator const & callee() const
Get a [const] the state of the referenced symbol.
Definition: reference.h:137
map::iterator iterator
Iterator type on map
bool configured() const
Say whether the symbol is configured.
Definition: symbol.h:258
map::value_type value_type
Value-type of map
Class argument_list encapsulates a list of macro arguments, i.e. the arguments to a macro reference...
Definition: argument_list.h:50
bool reportable() const
Say whether this reference is eligible for reporting.
Definition: reference.cpp:137
evaluation const & eval()
Get the evaluation of the expansion.
Definition: reference.h:171
reference_cache::insert_result lookup()
Lookup the reference in the cache.
Definition: reference.cpp:67
reference_cache::insert_result insert_result
Type of result from cache insertion.
Definition: reference.h:59
symbol::locator _referee
The symbol_state of the referenced symbol.
Definition: reference.h:246
bool complete()
Say whether this reference has been fully expanded.
Definition: reference.h:181
reference_cache::value_type digest()
Return a cache entry for this reference.
Definition: reference.cpp:86
std::string const & id() const
Get the name of the symbol.
Definition: symbol.h:151
void set_invoked(bool value=true)
Mark the symbol as invoked, or not.
Definition: symbol.h:463
reference_cache::iterator lower_bound() const
Get a lower bound to this reference in the reference cache.
Definition: reference.h:212
reference_cache::entry expand(bool explain)
Expand the reference.
Definition: reference.cpp:115
reference(symbol::locator loc, chewer< CharSeq > &chew, reference const *invoker=nullptr)
Construct given a symbol locator, a chewer<CharSeq>, and optional parent reference.
Definition: reference.h:105
std::string const & expansion()
Get the expansion of the reference.
Definition: reference.h:166
std::string _key
Key to this reference in the reference cache.
Definition: reference.h:254
bool reported()
Say whether this reference has been reported.
Definition: reference.h:176
std::string const & id() const
Get the name of the symbol referenced.
Definition: reference.h:146
argument_list _args
The argument_list of the reference.
Definition: reference.h:248
bool operator==(reference const &other) const
Equality.
Definition: reference.h:125
std::pair< iterator, bool > insert_result
Type of result of insertion.
`template struct chewer<CharSeq> is a cursor-like type that is associated with a character-sequence t...
Definition: chew.h:248
evaluation validate() const
Diagnose a syntactically invalid reference.
Definition: reference.cpp:212
reference(symbol::locator loc, argument_list const &args, reference const *invoker=nullptr)
Construct given a symbol locator argument_list and optional parent reference.
Definition: reference.h:82
Encapsulates an entry in the reference cache.
reference const * _invoker
Pointer to the reference that invokes this one, if any, else null.
Definition: reference.h:252
struct evaluation represents the result of evaluating a putative expression.
Definition: evaluation.h:48
bool explain() const
Say whether we are to explain this reference.
Definition: reference.h:195
bool explaining() const
Say whether this reference is to be explained or is descended from one being explained.
Definition: reference.cpp:54