OpenASIP
2.0
|
#include <AssemblerParser.hh>
Public Member Functions | |
PrintString (const char *aStr) | |
PrintString actor. More... | |
PrintString (std::string &string) | |
void | operator() (const char *, const char *) const |
Private Attributes | |
const char * | str_ |
Something about functors from Sprit manual (those little classes below that can be used as like callback functions with Spirit).
With functors, take note that the operator() should be const. This implies that functors are immutable. One may wish to have some member variables that are modified when the action gets called. This is not a good idea. First of all, functors are preferably lightweight. Functors are passed around a lot and it would incur a lot of overhead if the functors are heavily laden. Second, functors are passed by value. Thus, the actual functor object that finally attaches to the parser, will surely not be the original instance supplied by the client. What this means is that changes to a functor's state will not affect the original functor that the client passed in since they are distinct copies. If a functor needs to update some state variables, which is often the case, it is better to use references to external data.
Personal notes:
I preferred to use predefined functors, which can do some stl container operations and assignments...
I came across with few problems with spirit, I tried to do parser that would have used pointer assignments and dynamic binding. Parser seems to hard code some addresses, because address pointers and copy parameters didn't seen to work too well.
Here is some examples that didn't work.
[assign_a(pointer, &object)] in this case I tried to set destination for parsing to be object. I manage do this kind of assignment when I wrote special actor for that.
[assign_a(pointer->structField)] This doesn't work either. If you want to set field through pointer, you have to create actor for that.
Copying by passing pointers and references and and dynamic binding is seems to be possible with Spirit, but you have to write a lot more code. So I always copied parsed values that I used. Prints given string to std::cerr. Used for syntax error.
Definition at line 195 of file AssemblerParser.hh.
PrintString::PrintString | ( | const char * | aStr | ) |
PrintString actor.
Constructor of actor.
aStr | String to print. |
Definition at line 54 of file AssemblerParser.cc.
PrintString::PrintString | ( | std::string & | aStr | ) |
Constructor of actor.
aStr | String to print. |
Definition at line 63 of file AssemblerParser.cc.
void PrintString::operator() | ( | const char * | , |
const char * | |||
) | const |
|
private |
Definition at line 202 of file AssemblerParser.hh.
Referenced by operator()().