-
Notifications
You must be signed in to change notification settings - Fork 3
Code Style
The CircuitKernel uses a specific coding style which is uncommon among the C programmers.
Although the kernel is built using C++, the C coding style is allowed (for non-core code) and is supported using function-attribute macros -
decl_c ret_type PlainCFunctionName(args);
import_asm ret_type PlainAsmFunctionName(args);
export_asm ret_type PlainCFunctionName(args);
Here,
- decl_c means the function is to declared in "C" style and to be used in *.c files.
- import_asm means the function is implemented in assembly files.
- export_asm means the function will be used by assembly files.
A structure is always typedef-ed, if it is abstract, and is declared as -
/**
* Struct: DataTypeName / Type: ABSTRACT_TYPE
* Attributes: file-only (iff not in header)
*
* Summary:
* blah-blah-blah
*
* Version: x.y.z
* Since: Circuit X.xy,++
* Author: Shukant Pal
*/
struct DataTypeName {
VAR_TYPE variableName;
struct ChildStruct otherStruct;
} ABSTRACT_TYPE;/* Used only if the type is opaque! */
Structures are a fundamental part of the coding style, as only they are supported in data structures. The kernel does not (like) use of templates for widely-used classes, thus, the Void *pointer (instead of template-types). All stuff that needs to be stored in a data structure should be organized into a struct declaration.
A global function is defined as
function_attribute retType PlainCFunctionName(args);
All function names are written in PascalCase for differentiating with C++ class functions which are in camelCase.
A class is defined as (source or header) -
/**
* Class: ClassName
*
* Summary:
* This class implements the management of ....
*
* Important Functions:
* functionName -
*
* Version: Version of class
* Since: Circuit x.yz,++
* Author: Implementor's Name
*/
class ClassName {
public:
varType variable;
retType functionName(args);
private:
};
A function is declared differently than definition -
/**
* Function: Class::function OR Function: CGlobalFunction
*
* Summary:
* What does it do? Why does it do?
*
* Effects:
* Changes to be noted by client
*
* Changes:
* Changes done to implementation recently
*
* NOTE:
* Any special notes
*
* Version:
* Since:
* Author:
*/
retType functionName(
argType argName, // 2-indentations b/w function & args
){
}