Page 1 of 1
[Implemented] XIncludeFile with the main source file
Posted: Fri Jul 22, 2011 1:55 am
by CSHW89
Hi people,
It would be nice if 'XIncludeFile' doesn't try to include the main source file.
Here's what I mean:
File ClassA.pb:
Code: Select all
XIncludeFile "ClassB.pb"
Interface ClassA
EndInterface
Procedure ClassA_AddB(*this.ClassA, *add)
;...
EndProcedure
File ClassB.pb:
Code: Select all
XIncludeFile "ClassA.pb"
Interface ClassB
EndInterface
Procedure ClassB_AddA(*this.ClassB, *add)
;...
EndProcedure
If I compile "ClassA.pb", the compiler tries to include "ClassA.pb", too.
Thanks
Kevin
Re: XIncludeFile with the main source file
Posted: Fri Jul 22, 2011 2:41 am
by citystate
so...
you'd like Purebasic to account for bad programming?

Re: XIncludeFile with the main source file
Posted: Fri Jul 22, 2011 5:21 pm
by kenmo
Although it's not really a bug, it shouldn't be too difficult for the team to "fix"...
Assuming that XIncludeFile keeps some sort of list of which files have already been included, why not add the main source file to the list at the very beginning of compilation?
(But normally your code should have some sort of hierarchy... included sub-files shouldn't be trying to re-include your main file!)
Re: XIncludeFile with the main source file
Posted: Sat Jul 23, 2011 2:26 pm
by CSHW89
kenmo wrote:Although it's not really a bug, it shouldn't be too difficult for the team to "fix"...
Assuming that XIncludeFile keeps some sort of list of which files have already been included, why not add the main source file to the list at the very beginning of compilation?
Thanks. Yes, I hope.
kenmo wrote:(But normally your code should have some sort of hierarchy... included sub-files shouldn't be trying to re-include your main file!)
Recursive data structures, e.g. Nondeterministic Finite Automata:
NFA.pb:
Code: Select all
XIncludeFile "NFAState.pb"
Structure NFA
List state.NFAState()
EndStructure
NFAState.pb:
Code: Select all
XIncludeFile "NFATrans.pb"
Structure NFAState
List trans.NFATrans()
EndStructure
NFATrans.pb:
Code: Select all
XIncludeFile "NFA.pb"
Structure NFATrans
*value
*goal.NFAState
EndStructure
Re: XIncludeFile with the main source file
Posted: Sat Jul 23, 2011 3:30 pm
by Demivec
CSHW89 wrote:Recursive data structures, e.g. Nondeterministic Finite Automata:
Your example with NFA.pb ,NFAState.pb, and NFATrans.pb, would never be compilable. Each of the files requires all of the other files (and itself) to be included before continuing. It is a clear example for the need of better programming structure because the improvements to XIncludeFile still wouldn't make it possible.
PureBasic is a one-pass compiler, not a recursive one.
I know you didn't ask for it but I might as well suggest it anyway. Until XIncludeFile is improved as you suggested you can define constants that can be tested with CompileIf's.
It would look like this:
Code: Select all
;//NFA.pb:
CompilerIf Defined(include_NFA, #PB_Constant)
CompilerElse
#include_NFA = 1
XIncludeFile "NFAState.pb"
Structure NFA
List state.NFAState()
EndStructure
CompilerEndIf
Code: Select all
;//NFAState.pb:
CompilerIf Defined(include_NFAState, #PB_Constant)
CompilerElse
#include_NFAState = 1
XIncludeFile "NFATrans.pb"
Structure NFAState
List trans.NFATrans()
EndStructure
CompilerEndIf
Code: Select all
;//NFATrans.pb:
CompilerIf Defined(include_NFATrans, #PB_Constant)
CompilerElse
#include_NFATrans = 1
XIncludeFile "NFA.pb"
Structure NFATrans
*value
*goal.NFAState
EndStructure
CompilerEndIf
Re: XIncludeFile with the main source file
Posted: Sat Jul 23, 2011 6:43 pm
by kenmo
Yeah, Demivec's way is the way it's usually done in C, etc. (#ifdef)
PS. You can use Defined(include_NFA, #PB_Constant) = 0 instead of an immediate CompilerElse, it looks a tiny bit nicer.
Re: XIncludeFile with the main source file
Posted: Sat Jul 23, 2011 7:09 pm
by Demivec
kenmo wrote:PS. You can use Defined(include_NFA, #PB_Constant) = 0 instead of an immediate CompilerElse, it looks a tiny bit nicer.
That would be nicer. I considered using
CompilerIf Not Defined(include_NFA, #PB_Constant), but realized that the
Not operator hasn't yet been implemented for that purpose. I had overlooked simply comparing the results with zero. Thanks for pointing it out.