When compiling multiple source files
Jacob Carlborg
doob at me.com
Mon Aug 19 04:01:53 PDT 2013
On 2013-08-18 17:31, ProgrammingGhost wrote:
> How does the compiler do static typing of multiple source files?
> I heard D malloc memory and doesn't free to speed up compilation
> but I am guessing every instance doesn't compile just one source
> file? My question is if I have a function in this file and
> another in a different file what does the compiler do when both
> files needs to know the definition of another? Also how does it
> handle modules?
>
> From another thing I heard text parsing can be ridiculously fast
> so there may be no need for a binary representation of each file
> parsed. Does the D compiler read all source files into memory
> generate the AST then starts compiling each file? I know there
> more than one compiler but I wouldn't mind hearing from either or
> both if they differ.
The compiler will start compiling the files passed on the command line.
It will read the files asynchronously and then lex, parse build an AST
and do semantic analyze.
When the semantic analyze is done it will have access to all import
declarations. It basically starts the same processes for all these
imports, recursively.
The reason for waiting until semantic analyze is done because you can
have code looking like this:
mixin("import foo;");
The expansion of the mixin and other similar features are done in the
semantic analyze phase.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list