On Sun, 23 Jan 2011, leledumbo wrote:
WARNING: it won't be simple
I'm using visitor pattern in my project and to the best of my knowledge, the
visitor should be implemented as an interface.
Why ?
tiOPF uses the visitor pattern extensively, and it is implemented as a class.
After everything goes
compiled, I found out a weird behavior. That is, all the change during
accept-visit is gone after control goes back to the initiator (first
accept). Even worse, I can't free the object! It causes access violation.
I attach the project that shows this. The project is quite big, but you can
focus to only two units (more precisely, to their interface as seen in the
attached diff): ast and cg. I create two versions of both units (the other
using class with abstract methods) and their diff is attached. Try compiling
with both versions (by renaming the one you want to compile to the right
name, e.g. without .tmp suffix). Ensure linguc.lpr on line 118 is commented
when you're using the interface version (it causes access violation as I
state above).
Attachment:
http://free-pascal-general.1045716.n5.nabble.com/file/n3353651/intf.zip
intf.zip
It doesn't compile for me. What version of FPC did you use ?
home: >fpc linguc.lpr
ast.pp(529,19) Error: Cannot find an enumerator for the type "TFPGObjectList$TASTVarDecl"
ast.pp(531,15) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTStatement"
ast.pp(540,19) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTVarDecl"
ast.pp(542,15) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTStatement"
ast.pp(568,16) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTVarDecl"
ast.pp(623,15) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTMethod"
ast.pp(632,15) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTMethod"
ast.pp(651,14) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTClass"
ast.pp(659,14) Error: Cannot find an enumerator for the type
"TFPGObjectList$TASTClass"
ast.pp(676) Fatal: There were 9 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode (normal if you did not
specify a source file to be compiled)
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal