coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
line_despatch.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004, 2006 Symbian Software Ltd. *
3  * All rights reserved. *
4  * Copyright (C) 2002, 2003 Tony Finch <dot@dotat.at>. *
5  * All rights reserved. *
6  * Copyright (C) 1985, 1993 The Regents of the University of California. *
7  * All rights reserved. *
8  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
9  * All rights reserved. *
10  * *
11  * Contributed by Mike Kinghan, imk@burroingroingjoing.com, *
12  * derived from the code of Tony Finch *
13  * *
14  * Redistribution and use in source and binary forms, with or without *
15  * modification, are permitted provided that the following conditions *
16  * are met: *
17  * *
18  * Redistributions of source code must retain the above copyright *
19  * notice, this list of conditions and the following disclaimer. *
20  * *
21  * Redistributions in binary form must reproduce the above copyright *
22  * notice, this list of conditions and the following disclaimer in the *
23  * documentation and/or other materials provided with the distribution. *
24  * *
25  * Neither the name of Mike Kinghan nor the names of its contributors *
26  * may be used to endorse or promote products derived from this software *
27  * without specific prior written permission. *
28  * *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
32  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
33  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
34  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
35  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
36  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
37  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
38  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
39  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
40  * DAMAGE. *
41  * *
42  **************************************************************************/
43 
44 #include "line_despatch.h"
45 #include "citable.h"
46 #include "io.h"
47 #include "contradiction.h"
48 #include "if_control.h"
49 #include "canonical.h"
50 #include "directive.h"
51 
55 using namespace std;
56 
59 std::unique_ptr<parsed_line> line_despatch::_cur_line_(nullptr);
60 
62 {
63  _cur_line_.reset(new parsed_line(io::input(),io::output()));
64 }
65 
66 void line_despatch::substitute(string const & replacement)
67 {
69  *io::output() << replacement;
70  --_lines_suppressed_;
71  ++_lines_changed_;
72  }
73 }
74 
76 {
77  if (!_cur_line_->get()) {
80  return LT_EOF;
81  }
82  chewer<parse_buffer> chew(!options::plaintext(),*_cur_line_);
83  line_type retval = LT_PLAIN;
84  chew(greyspace);
85  if (*chew != '#') {
87  chew(code);
88  return retval;
89  }
90  _cur_line_->indent() = size_t(chew);
91  chew(+1,greyspace);
92  size_t keyword_off = size_t(chew);
93  string keyword = canonical<symbol>(chew);
94  cur_line().mark_keyword(keyword_off,keyword.length());
95  retval = directive_base::eval(keyword,chew);
96  if (retval == LT_DIRECTIVE_KEEP) {
97  /* A non-if directive is the same as a non-directive for if-control */
98  retval = LT_PLAIN;
99  }
100  return retval;
101 }
102 
104  return citable(!options::plaintext(),_cur_line_->str());
105 }
106 
107 /* EOF*/
static bool plaintext()
Are we to omit parsing for C/C++ comments?
Definition: options.h:183
A directive line of no more specific type that is to be kept.
Definition: line_type.h:76
static void substitute(std::string const &replacement)
Substitute a diagnostic insert for the line in the line-buffer and print it to output.
static line_type next()
Process the current input line and return its line type.
static line_type eval(std::string keyword, chewer< parse_buffer > &chew)
Evaluate a directive.
Definition: directive.h:65
End of file.
Definition: line_type.h:72
std::string citable(chewer< std::string > &chew, size_t len=std::string::npos)
Make a citable version of length-delimited text.
static std::unique_ptr< parsed_line > _cur_line_
The current output line.
static void top()
Reinitialize the class static state.
chew_mode::greyspace const greyspace
An exemplar chew_mode::greyspace
Definition: chew.h:211
static void flush()
Discharge any pending contradiction.
chew_mode::code const code
An exemplar chew_mode::code
Definition: chew.h:227
`template struct chewer<CharSeq> is a cursor-like type that is associated with a character-sequence t...
Definition: chew.h:248
template class canonical<What> encapsulates the canonical representation of values of type What...
Definition: canonical.h:82
static bool have_source_output()
Say whether the current comment generates source code.
Definition: options.h:218
line_type
Enumeration of types of input lines.
Definition: line_type.h:52
static std::ostream * output()
Get a pointer to the output stream.
Definition: io.h:110
A non-directive line.
Definition: line_type.h:70
static unsigned _lines_changed_
Number of input lines changed.
static std::string pretty()
Get a pretty printable version of the current input line.
static void transition(line_type linetype)
Transition the if-control state given an evaluated line type.
Definition: if_control.cpp:310
static std::istream * input()
Get a pointer to the input stream.
Definition: io.h:115
static unsigned _lines_suppressed_
Number of input lines suppressed.