Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
dmd.cparse
Takes a token stream from the lexer, and parses it into an abstract syntax tree.
Specification C11
Authors:
License:
Source cparse.d
Documentation https://dlang.org/phobos/dmd_cparse.html
- class
CParser
(AST): Parser!AST; -
- bool
addFuncName
; - add declaration of _func__ to function symbol table
- bool
importBuiltins
; - seen use of C compiler builtins, so import _importc_builtins;
- Array!(void*)
typedefTab
; - Array of AST.Type[Identifier], typedef's indexed by Identifier
- AST.Dsymbols*
parseModule
(); - Parse translation unit. C11 6.9 translation-unit: external-declaration translation-unit external-declarationexternal-declaration: function-definition declarationReturns:array of Dsymbols that were declared
- AST.Statement
cparseStatement
(intflags
, const(char)**endPtr
= null, Loc*pEndloc
= null); - Statement ParserC11 6.8 statement: labeled-statement compound-statement expression-statement selection-statement iteration-statement jump-statementParameters:
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 Returns:parsed statement - AST.Expression
cparseExpression
(); - Expression ParserC11 6.5.17 expression: assignment-expression expression , assignment-expression
- AST.Expression
cparsePrimaryExp
(); - C11 6.5.1 primary-expression: identifier constant string-literal ( expression ) generic-selection _builtin_va_arg(assign_expression, type)
- AST.Expression
cparseAssignExp
(); - C11 6.5.16 assignment-expression: conditional-expression unary-expression assignment-operator assignment-expressionassignment-operator: = *= /= %= += -= <<= >>= &= ^= |=
- void
cparseDeclaration
(LVLlevel
); - Declaration ParserC11 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 - AST.Dsymbol
cparseFunctionDefinition
(Identifierid
, AST.TypeFunctionft
, ref Specifierspecifier
); - C11 Function Definitions function-definition declaration-specifiers declarator declaration-list (opt) compound-statementdeclaration-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 Returns:Dsymbol for the function - AST.Initializer
cparseInitializer
(); - C11 Initialization initializer: assignment-expression { } // C23 6.7.10 addition { initializer-list } { initializer-list , }initializer-list: designation (opt) initializer initializer-list , designation (opt) initializer designation: designator-list = designator-list: designator designator-list designator designator: [ constant-expression ] . identifierReturns:initializer
- MOD
cparseTypeQualifierList
(); - C11 6.7.3 type-qualifier: const restrict volatile Atomic _stdcall
- AST.Type
cparseTypeName
(); - C11 6.7.7
- AST.Type
cparseSpecifierQualifierList
(LVLlevel
, ref Specifierspecifier
); - C11 6.7.2.1 specifier-qualifier-list: type-specifier specifier-qualifier-list (opt) type-qualifier specifier-qualifier-list (opt)Parameters:
LVL level
declaration context Specifier specifier
specifiers in and out Returns:resulting type, null if not specified - AST.ParameterList
cparseParameterList
(); - C11 6.7.6.3 ( parameter-type-list ) ( identifier-list (opt) )
- 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-declarationstruct-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) - bool
isDeclarationList
(ref Token*pt
); - See if declaration-list is present.Returns:true if declaration-list is present, even an empty one
- enum
LVL
; - MoreDeclaration context
global
- global
parameter
- function parameter (declarations for function identifier-list)
prototype
- function prototype
local
- local
member
- struct member
- enum
DTR
; - Types of declarator to parse
xdirect
- C11 6.7.6 direct-declarator
xabstract
- C11 6.7.7 abstract-declarator
xparameter
- parameter declarator may be either direct or abstract
- enum
SCW
: uint; - C11 6.7.1 Storage-class specifiers
- enum
MOD
: uint; - C11 6.7.3 Type qualifiers
- struct
Specifier
; - Aggregate for all the various specifiers
- bool
noreturn
; - noreturn attribute
- bool
naked
; - naked attribute
- bool
_nothrow
; - nothrow attribute
- bool
_pure
; - pure attribute
- bool
dllimport
; - dllimport attribute
- bool
dllexport
; - dllexport attribute
- bool
_deprecated
; - deprecated attribute
- AST.Expression
depMsg
; - deprecated message
- uint
vector_size
; - positive power of 2 multipe of base type size
- SCW
scw
; - storage-class specifiers
- MOD
mod
; - type qualifiers
- AST.Expressions*
alignExps
; - alignment
- structalign_t
packalign
; - #pragma pack alignment value
- StorageClass
specifiersToSTC
(LVLlevel
, const ref Specifierspecifier
); - Convert from C specifiers to D storage classParameters:
LVL level
declaration context Specifier specifier
specifiers, context, etc. Returns:corresponding D storage class - void
specifiersToFuncDeclaration
(AST.FuncDeclarationfd
, const ref Specifierspecifier
); - Add attributes from Specifier to functionParameters:
AST.FuncDeclaration fd
function to apply them to Specifier specifier
specifiers - void
specifiersToVarDeclaration
(AST.VarDeclarationvd
, const ref Specifierspecifier
); - Add attributes from Specifier to variableParameters:
AST.VarDeclaration vd
function to apply them to Specifier specifier
specifiers - void
panic
(); - After encountering an error, scan forward until a right brace or ; is found or the end of the file.
- bool
isFunctionTypedef
(AST.Typet
); - typedefTab symbol tableDetermines if type t is a function type.Parameters:
AST.Type t
type to test Returns:true if it represents a function - bool
isTypedef
(Identifierid
); - Determine if
id
is a symbol for a Typedef.Parameters:Identifier id
possible typedef Returns:true if id is a Type - void
insertIdToTypedefTab
(Identifierid
); - Add
id
to typedefTab[], but only if it will mask an existing typedef.Parameters:Identifier id
identifier for non-typedef symbol - void
insertTypedefToTypedefTab
(Identifierid
, AST.Typet
); - Add
id
to typedefTab[]Parameters:Identifier id
identifier for typedef symbol AST.Type t
type of the typedef symbol - AST.Type*
lookupTypedef
(Identifierid
); - Lookup id in typedefTab[].Returns:if not found, then null. if found, then Type*. Deferencing it will yield null if it is not a typedef, and a type if it is a typedef.
- bool
parseSpecialTokenSequence
(); - Directive Parser
- void
addDefines
(); - #define ParserGo through the #define's in the defines buffer and see what we can convert to Dsymbols, which are then appended to symbols[]
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on Wed Dec 18 08:51:53 2024