mirror of
https://gitlab.com/fbb-git/cppannotations
synced 2024-11-16 07:48:44 +01:00
repaired missing parentheses etc.
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@146 f6dd340e-d3f9-0310-b409-bdd246841980
This commit is contained in:
parent
43024870ae
commit
a85691624c
13 changed files with 37 additions and 45 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class Data
|
||||
class Data
|
||||
{
|
||||
friend class Wrapper; // Our Wrapper class is allowed to access our data
|
||||
// too.
|
||||
|
@ -11,7 +11,7 @@ class Data
|
|||
vector<int> d_v; // here are Data's data
|
||||
|
||||
public:
|
||||
class Wrapper
|
||||
class Wrapper
|
||||
{
|
||||
Data & d_data;
|
||||
size_t d_index;
|
||||
|
@ -31,14 +31,14 @@ class Data
|
|||
|
||||
Wrapper &operator=(int value);
|
||||
// Our data as lvalue. This again is but one example. To
|
||||
// implement data[x] += y etc, those operators must be
|
||||
// implement data[x] += y etc, those operators must be
|
||||
// overloaded too.
|
||||
|
||||
|
||||
// There's only one situation where data[x] is used as rvalue:
|
||||
// when it's returning its data[x] element. This is
|
||||
// accomplished by defining the appropriate conversion
|
||||
// operator:
|
||||
// operator:
|
||||
|
||||
operator int() const;
|
||||
// Our data as rvalue. Can't use things like int &n =
|
||||
|
@ -49,8 +49,8 @@ class Data
|
|||
// like int &n = data.ref(3).
|
||||
|
||||
private:
|
||||
// nobody but Data has anything to do with Wrapper's
|
||||
// constructor so it's made private, declaring Data as its
|
||||
// nobody but Data has anything to do with Wrapper's
|
||||
// constructor so it's made private, declaring Data as its
|
||||
// friend.
|
||||
|
||||
friend class Data;
|
||||
|
@ -59,10 +59,10 @@ class Data
|
|||
};
|
||||
|
||||
Data();
|
||||
|
||||
|
||||
int operator[](size_t index) const;
|
||||
// Always rvalue: operator[] of const objects
|
||||
|
||||
|
||||
Wrapper operator[](size_t index);
|
||||
// With non-const objects: the Wrapper is returned, to which
|
||||
// a value can be assigned, in which case it's is an lvalue, or
|
||||
|
@ -74,8 +74,8 @@ class Data
|
|||
// I've defined all members inline, although you shouldn't do so in real life.
|
||||
|
||||
|
||||
inline Data::Wrapper &Data::Wrapper::operator=(Wrapper const &other)
|
||||
{
|
||||
inline Data::Wrapper &Data::Wrapper::operator=(Wrapper const &other)
|
||||
{
|
||||
cout << "data[x] = data[y], lvalue = rvalue\n";
|
||||
|
||||
d_data.d_v[d_index] = other.d_data.d_v[other.d_index];
|
||||
|
@ -102,26 +102,26 @@ inline Data::Wrapper::operator int() const
|
|||
}
|
||||
|
||||
inline Data::Wrapper::Wrapper(Data &data, size_t index)
|
||||
:
|
||||
d_data(data),
|
||||
d_index(index)
|
||||
:
|
||||
d_data(data),
|
||||
d_index(index)
|
||||
{}
|
||||
|
||||
inline Data::Data()
|
||||
:
|
||||
:
|
||||
d_v(5)
|
||||
{
|
||||
for (size_t idx = 0; idx < 5; ++idx) // assign some values
|
||||
d_v[idx] = 2 * idx;
|
||||
}
|
||||
|
||||
inline int Data::operator[](size_t index) const
|
||||
|
||||
inline int Data::operator[](size_t index) const
|
||||
{
|
||||
cout << "rvalue-only from const object\n";
|
||||
return d_v[index];
|
||||
}
|
||||
|
||||
inline Data::Wrapper Data::operator[](size_t index)
|
||||
inline Data::Wrapper Data::operator[](size_t index)
|
||||
{
|
||||
return Wrapper(*this, index);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ inline Data::Wrapper Data::operator[](size_t index)
|
|||
|
||||
|
||||
|
||||
int main()
|
||||
int main()
|
||||
{
|
||||
Data test; // a non-const object
|
||||
|
||||
|
@ -148,12 +148,12 @@ int main()
|
|||
test[1] = testConst[4];
|
||||
cout << "Resulting in: " << test[1] << "\n\n";
|
||||
|
||||
cout << "Direct assignment to test[0] (now " << test[0] <<
|
||||
cout << "Direct assignment to test[0] (now " << test[0] <<
|
||||
") as an lvalue:\n";
|
||||
test[0] = 11;
|
||||
cout << "Resulting in: " << test[0] << "\n\n";
|
||||
|
||||
cout << "Using test[1] (= " << test[1] <<
|
||||
cout << "Using test[1] (= " << test[1] <<
|
||||
" + 2) in an expression as rvalue\n";
|
||||
int n = test[1] + 2;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef INCLUDED_BASE_
|
||||
#define INCLUDED_BASE_
|
||||
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
|
@ -10,13 +10,13 @@
|
|||
virtual Base *clone() const = 0;
|
||||
virtual std::ostream &insert(std::ostream &os) const = 0;
|
||||
};
|
||||
|
||||
|
||||
inline Base::~Base()
|
||||
{}
|
||||
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out, Base const &obj)
|
||||
{
|
||||
return obj.insert(out);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include "base.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ inline Int::Int(int v)
|
|||
d_value(v)
|
||||
{}
|
||||
|
||||
inline Base *Int::clone() const
|
||||
inline Base *Int::clone() const
|
||||
{
|
||||
return new Int(*this);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class Parser: public ParserBase
|
|||
{
|
||||
// $insert scannerobject
|
||||
Scanner d_scanner;
|
||||
|
||||
|
||||
public:
|
||||
Parser();
|
||||
int parse();
|
||||
|
@ -20,7 +20,7 @@ class Parser: public ParserBase
|
|||
private:
|
||||
void error(char const *msg); // called on (syntax) errors
|
||||
int lex(); // returns the next token from the
|
||||
// lexical scanner.
|
||||
// lexical scanner.
|
||||
void print(); // use, e.g., d_token, d_loc
|
||||
|
||||
// support functions for parse():
|
||||
|
|
|
@ -4,4 +4,3 @@
|
|||
#include "parser.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <FlexLexer.h>
|
||||
#define SYSINC_FLEXLEXER_H_
|
||||
#endif
|
||||
|
||||
|
||||
class Scanner: public yyFlexLexer
|
||||
{
|
||||
Semantic *d_semval;
|
||||
|
@ -23,6 +23,3 @@ inline Scanner::Scanner(Semantic *semval)
|
|||
{}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,16 +18,13 @@
|
|||
make these values available. (Note that the need for these defines may be
|
||||
superfluous in the near future):
|
||||
*/
|
||||
// uncomment if you want to use YY_CURRENT_BUFFER in the scanner's members:
|
||||
// uncomment if you want to use YY_CURRENT_BUFFER in the scanner's members:
|
||||
/*
|
||||
#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
|
||||
? (yy_buffer_stack)[(yy_buffer_stack_top)] \
|
||||
: NULL)
|
||||
*/
|
||||
// uncomment if you want to use YY_START in the scanner's members:
|
||||
// uncomment if you want to use YY_START in the scanner's members:
|
||||
// #define YY_START (((yy_start) - 1) / 2)
|
||||
|
||||
// end of scanner.ih
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ inline Semantic::~Semantic()
|
|||
{
|
||||
delete d_bp;
|
||||
}
|
||||
|
||||
|
||||
inline Semantic::Semantic(Semantic const &other)
|
||||
{
|
||||
copy(other);
|
||||
|
@ -50,7 +50,7 @@ inline Semantic &Semantic::operator=(Semantic const &other)
|
|||
if (this != &other)
|
||||
{
|
||||
delete d_bp;
|
||||
copy(other);
|
||||
copy(other);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ inline Text::Text(char const *id)
|
|||
d_text(id)
|
||||
{}
|
||||
|
||||
inline Base *Text::clone() const
|
||||
inline Base *Text::clone() const
|
||||
{
|
||||
return new Text(*this);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ received by the Scanner's constructor:
|
|||
{}
|
||||
)
|
||||
|
||||
The scanner (generated by bf(flex)(1)hi(flex) recognizes input patterns,
|
||||
The scanner (generated by bf(flex)(1))hi(flex) recognizes input patterns,
|
||||
returns Parser tokens (e.g., Parser::INT), and returns a semantic value when
|
||||
applicable. E.g., when recognizing a tt(Parser::INT) the rule is:
|
||||
verb(
|
||||
|
|
|
@ -47,7 +47,7 @@ will read a blank-delimited word from the file, and will then write a string
|
|||
to the file, just beyond the point where the string just read terminated,
|
||||
followed by the reading of yet another string just beyond the location where
|
||||
the string just written ended (assuming that the file tt(filename) contains
|
||||
enough information for the extractions to succeed:
|
||||
enough information for the extractions to succeed):
|
||||
verb(
|
||||
fstream f("filename", ios::in | ios::out);
|
||||
string str;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
template <typename T>
|
||||
Derived<T>::Derived()
|
||||
{
|
||||
this->member(); // Using `this' implies <T> at
|
||||
this->member(); // Using `this' implies <T> at
|
||||
// instantiation time.
|
||||
Base<T>::member(); // Same.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue