@@ -514,8 +514,21 @@ $(H2 $(LNAME2 other-solutions, Other Solutions))
514
514
515
515
$(H2 $(LNAME2 internals, How ImportC Works))
516
516
517
- $(P This is a description of how ImportC is implemented, intended
518
- to remove the mystery of various design choices.)
517
+ $(P ImportC's implementation is based on the idea that D's semantics are very similar
518
+ to C's. ImportC gets its own parser, which converts the C syntax into the same AST
519
+ (Abstract Syntax Tree) that D uses. The lexer for ImportC is the same as for D, but with
520
+ some modifications here and there, such as the keywords and integer literals being different.
521
+ Where the semantics of C differ from D, there are adjustments in the semantic analysis
522
+ code in the D compiler.)
523
+
524
+ $(P This co-opting of the D semantic implementation allows ImportC to be able to do things
525
+ like handle forward references, CTFE (Compile Time Function Execution), and inlining of C functions
526
+ into D code. Being able to handle forward references means it is not necessary to even
527
+ write a .h file to be able to import C declarations into D. Being able to perform CTFE is
528
+ very handy for testing that ImportC is working without needing to generate an executable.
529
+ But, in general, the strong temptation to add D features to ImportC has been resisted.)
530
+
531
+ $(P The optimizer and code generator are, of course, the same as D uses.)
519
532
520
533
$(SPEC_SUBNAV_PREV_NEXT betterc, Better C, ob, Live Functions)
521
534
)
0 commit comments