Difference between revisions of "LDC contributor's guide"

From D Wiki
Jump to: navigation, search
(Style guidelines)
(Style guidelines)
Line 2: Line 2:
  
 
== Style guidelines ==
 
== Style guidelines ==
 +
Generally, use your good taste and try to use a style similar to the surrounding code. Many parts of the [http://llvm.org/docs/CodingStandards.html LLVM Coding Standards] are directly applicable to LDC as well.
 +
 +
=== Formatting, etc. ===
 
* Hard rules: 4 spaces for indentation, LF newlines.
 
* Hard rules: 4 spaces for indentation, LF newlines.
* Generally, use your good taste and try to use a style similar to the surrounding code. Many parts of the [http://llvm.org/docs/CodingStandards.html LLVM Coding Standards] are directly applicable to LDC as well.
+
* Use include guards consistently, in the format ''LDC_<dir>_<filename>'', e.g. ''LDC_GEN_DVALUE_H''.
 +
* Includes are placed at the top of the file, sorted lexicographically and grouped in the following order:
 +
*# Main include corresponding to the .cpp file, if any.
 +
*# DMD and other LDC includes.
 +
*# LLVM/libconfig includes.
 +
*# System includes.
 +
 
 +
=== APIs and idioms ===
 
* Use [http://llvm.org/docs/doxygen/html/ErrorHandling_8h.html#ace243f5c25697a1107cce46626b3dc94 ''llvm_unreachable("message")''] instead of ''assert(0 && "message")'' (from ''llvm/Support/ErrorHandling.h''). Not only might it lead to slightly better codegen, it also prevents »variable might be used uninitialized« and similar compiler warnings.
 
* Use [http://llvm.org/docs/doxygen/html/ErrorHandling_8h.html#ace243f5c25697a1107cce46626b3dc94 ''llvm_unreachable("message")''] instead of ''assert(0 && "message")'' (from ''llvm/Support/ErrorHandling.h''). Not only might it lead to slightly better codegen, it also prevents »variable might be used uninitialized« and similar compiler warnings.
 
 
[[Category:LDC]]
 
[[Category:LDC]]

Revision as of 19:06, 7 February 2013

This page is a work-in-progress collection of tips for LDC contributors and development guidelines.

Style guidelines

Generally, use your good taste and try to use a style similar to the surrounding code. Many parts of the LLVM Coding Standards are directly applicable to LDC as well.

Formatting, etc.

  • Hard rules: 4 spaces for indentation, LF newlines.
  • Use include guards consistently, in the format LDC_<dir>_<filename>, e.g. LDC_GEN_DVALUE_H.
  • Includes are placed at the top of the file, sorted lexicographically and grouped in the following order:
    1. Main include corresponding to the .cpp file, if any.
    2. DMD and other LDC includes.
    3. LLVM/libconfig includes.
    4. System includes.

APIs and idioms

  • Use llvm_unreachable("message") instead of assert(0 && "message") (from llvm/Support/ErrorHandling.h). Not only might it lead to slightly better codegen, it also prevents »variable might be used uninitialized« and similar compiler warnings.