dmd.cparse
Takes a token stream from the lexer, and parses it into an abstract syntax tree.
Specification: C11
License
Source: cparse.d
Documentation: https://dlang.org/phobos/dmd_cparse.html
-
Declaration
class
CParser
(AST): Parser!AST;-
Declaration
bool
addFuncName
;add declaration of _func__ to function symbol table
-
Declaration
bool
importBuiltins
;seen use of C compiler builtins, so import _builtins;
-
Declaration
AST.Dsymbols*
parseModule
();Parse translation unit. C11 6.9 translation-unit: external-declaration translation-unit external-declaration
Discussion
external-declaration: function-definition declaration
Return Value
array of Dsymbols that were declared
-
Declaration
AST.Statement
cparseStatement
(intflags
, const(char)**endPtr
= null, Loc*pEndloc
= null);Statement Parser
Discussion
C11 6.8 statement: labeled-statement compound-statement expression-statement selection-statement iteration-statement jump-statement
Parameters
int
flags
PSxxxx
const(char)**
endPtr
store location of closing brace
Loc*
pEndloc
if { ... statements ... }, store location of closing brace, otherwise loc of last token of statement
Return Value
parsed statement
-
Declaration
AST.Expression
cparseExpression
();Expression Parser
Discussion
C11 6.5.17 expression: assignment-expression expression , assignment-expression
-
Declaration
AST.Expression
cparsePrimaryExp
();C11 6.5.1 primary-expression: identifier constant string-literal ( expression ) generic-selection _builtin_va_arg(assign_expression, type)
-
Declaration
AST.Expression
cparseAssignExp
();C11 6.5.16 assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression
Discussion
assignment-operator: = *= /= %= += -= <<= >>= &= ^= |=
-
Declaration
void
cparseDeclaration
(LVLlevel
);Declaration Parser
Discussion
C11 6.7 declaration: declaration-specifiers init-declarator-list (opt) ; static_assert-declaration
init-declarator-list: init-declarator init-declarator-list , init-declarator
init-declarator: declarator declarator = initializerParameters
LVL
level
declaration context
-
Declaration
AST.Dsymbol
cparseFunctionDefinition
(Identifierid
, AST.TypeFunctionft
, ref Specifierspecifier
);C11 Function Definitions function-definition declaration-specifiers declarator declaration-list (opt) compound-statement
Discussion
declaration-list: declaration declaration-list declaration
It's already been parsed up to the declaration-list (opt). Pick it up from there.Parameters
Identifier
id
function identifier
AST.TypeFunction
ft
function type
Specifier
specifier
function specifiers
Return Value
Dsymbol for the function
-
Declaration
AST.Initializer
cparseInitializer
();C11 Initialization initializer: assignment-expression { initializer-list } { initializer-list , }
Discussion
initializer-list: designation (opt) initializer initializer-list , designation (opt) initializer
designation: designator-list =
designator-list: designator designator-list designator
designator: [ constant-expression ] . identifierReturn Value
initializer
-
Declaration
MOD
cparseTypeQualifierList
();C11 6.7.3 type-qualifier: const restrict volatile Atomic _stdcall
-
Declaration
AST.Type
cparseTypeName
();C11 6.7.7
-
Declaration
AST.Type
cparseSpecifierQualifierList
(LVLlevel
, ref Specifierspecifier
);C11 6.7.2.1
specifier
-qualifier-list: type-specifier
specifier
-qualifier-list (opt) type-qualifierspecifier
-qualifier-list (opt)Parameters
LVL
level
declaration context
Specifier
specifier
specifiers in and out
Return Value
resulting type,
null
if not specified -
Declaration
AST.ParameterList
cparseParameterList
();C11 6.7.6.3 ( parameter-type-list ) ( identifier-list (opt) )
-
Declaration
void
cparseStructDeclaration
(AST.Dsymbols*members
);C11 6.7.2.1 Parse a struct declaration member. struct-declaration: specifier-qualifier-list struct-declarator-list (opt) ; static_assert-declaration
Discussion
struct-declarator-list: struct-declarator struct-declarator-list , struct-declarator
struct-declarator: declarator declarator (opt) : constant-expressionParameters
AST.Dsymbols*
members
where to put the fields (
members
) -
Declaration
bool
isDeclarationList
(ref Token*pt
);See if declaration-list is present.
Return Value
true
if declaration-list is present, even an empty one -
Declaration
enum
LVL
; -
Declaration
enum
DTR
;Types of declarator to parse
-
Declaration
xdirect
C11 6.7.6 direct-declarator
-
Declaration
xabstract
C11 6.7.7 abstract-declarator
-
Declaration
xparameter
parameter declarator may be either direct or abstract
-
-
Declaration
enum
SCW
: uint;C11 6.7.1 Storage-class specifiers
-
Declaration
enum
MOD
: uint;C11 6.7.3 Type qualifiers
-
Declaration
struct
Specifier
;Aggregate for all the various specifiers
-
Declaration
bool
noreturn
;noreturn
attribute -
Declaration
SCW
scw
;storage-class specifiers
-
Declaration
MOD
mod
;type qualifiers
-
Declaration
AST.Expressions*
alignExps
;alignment
-
Declaration
structalign_t
packalign
;#pragma pack alignment value
-
-
Declaration
StorageClass
specifiersToSTC
(LVLlevel
, const ref Specifierspecifier
);Convert from C specifiers to D storage class
Parameters
LVL
level
declaration context
Specifier
specifier
specifiers, context, etc.
Return Value
corresponding D storage class
-
Declaration
void
panic
();After encountering an error, scan forward until a right brace or ; is found or the end of the file.
-