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
- classCParser(AST): Parser!AST;
- 
- booladdFuncName;
- add declaration of _func__ to function symbol table
- boolimportBuiltins;
- 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.StatementcparseStatement(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 flagsPSxxxx const(char)** endPtrstore location of closing brace Loc* pEndlocif { ... statements ... }, store location of closing brace, otherwise loc of last token of statement Returns:parsed statement
- AST.ExpressioncparseExpression();
- Expression ParserC11 6.5.17 expression: assignment-expression expression , assignment-expression
- AST.ExpressioncparsePrimaryExp();
- C11 6.5.1 primary-expression: identifier constant string-literal ( expression ) generic-selection _builtin_va_arg(assign_expression, type)
- AST.ExpressioncparseAssignExp();
- C11 6.5.16 assignment-expression: conditional-expression unary-expression assignment-operator assignment-expressionassignment-operator: = *= /= %= += -= <<= >>= &= ^= |=
- voidcparseDeclaration(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 leveldeclaration context 
- AST.DsymbolcparseFunctionDefinition(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 idfunction identifier AST.TypeFunction ftfunction type Specifier specifierfunction specifiers Returns:Dsymbol for the function
- AST.InitializercparseInitializer();
- 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
- MODcparseTypeQualifierList();
- C11 6.7.3 type-qualifier: const restrict volatile Atomic _stdcall
- AST.TypecparseTypeName();
- C11 6.7.7
- AST.TypecparseSpecifierQualifierList(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 leveldeclaration context Specifier specifierspecifiers in and out Returns:resulting type, null if not specified
- AST.ParameterListcparseParameterList();
- C11 6.7.6.3 ( parameter-type-list ) ( identifier-list (opt) )
- voidcparseStructDeclaration(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* memberswhere to put the fields (members) 
- boolisDeclarationList(ref Token*pt);
- See if declaration-list is present.Returns:true if declaration-list is present, even an empty one
- enumLVL;
- MoreDeclaration context- global
- global
- parameter
- function parameter (declarations for function identifier-list)
- prototype
- function prototype
- local
- local
- member
- struct member
 
- enumDTR;
- 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
 
- enumSCW: uint;
- C11 6.7.1 Storage-class specifiers
- enumMOD: uint;
- C11 6.7.3 Type qualifiers
- structSpecifier;
- Aggregate for all the various specifiers- boolnoreturn;
- noreturn attribute
- boolnaked;
- naked attribute
- bool_nothrow;
- nothrow attribute
- bool_pure;
- pure attribute
- booldllimport;
- dllimport attribute
- booldllexport;
- dllexport attribute
- bool_deprecated;
- deprecated attribute
- AST.ExpressiondepMsg;
- deprecated message
- uintvector_size;
- positive power of 2 multipe of base type size
- SCWscw;
- storage-class specifiers
- MODmod;
- type qualifiers
- AST.Expressions*alignExps;
- alignment
- structalign_tpackalign;
- #pragma pack alignment value
 
- StorageClassspecifiersToSTC(LVLlevel, const ref Specifierspecifier);
- Convert from C specifiers to D storage classParameters:LVL leveldeclaration context Specifier specifierspecifiers, context, etc. Returns:corresponding D storage class
- voidspecifiersToFuncDeclaration(AST.FuncDeclarationfd, const ref Specifierspecifier);
- Add attributes from Specifier to functionParameters:AST.FuncDeclaration fdfunction to apply them to Specifier specifierspecifiers 
- voidspecifiersToVarDeclaration(AST.VarDeclarationvd, const ref Specifierspecifier);
- Add attributes from Specifier to variableParameters:AST.VarDeclaration vdfunction to apply them to Specifier specifierspecifiers 
- voidpanic();
- After encountering an error, scan forward until a right brace or ; is found or the end of the file.
- boolisFunctionTypedef(AST.Typet);
- typedefTab symbol tableDetermines if type t is a function type.Parameters:AST.Type ttype to test Returns:true if it represents a function
- boolisTypedef(Identifierid);
- Determine ifidis a symbol for a Typedef.Parameters:Identifier idpossible typedef Returns:true if id is a Type
- voidinsertIdToTypedefTab(Identifierid);
- Addidto typedefTab[], but only if it will mask an existing typedef.Parameters:Identifier ididentifier for non-typedef symbol 
- voidinsertTypedefToTypedefTab(Identifierid, AST.Typet);
- Addidto typedefTab[]Parameters:Identifier ididentifier for typedef symbol AST.Type ttype 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.
- boolparseSpecialTokenSequence();
- Directive Parser
- voidaddDefines();
- #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 (no date time)