dmd.cparse

Takes a token stream from the lexer, and parses it into an abstract syntax tree.

Specification: C11

Authors

Walter Bright

Source: cparse.d

  • Declaration

    class CParser(AST): Parser!AST;

    • Declaration

      bool addFuncName;

      add declaration of _func__ to function symbol table

    • 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(int flags, 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

    • Declaration

      AST.Expression cparseAssignExp();

      C11 6.5.16 assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression

      Discussion

      assignment-operator: = *= /= %= += -= <<= >>= &= ^= |=

    • Declaration

      void cparseDeclaration(LVL level);

      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 = initializer

      Parameters

      LVL level

      declaration context

    • Declaration

      AST.Dsymbol cparseFunctionDefinition(Identifier id, AST.TypeFunction ft, ref Specifier specifier);

      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 ] . identifier

      Return Value

      initializer

    • Declaration

      MOD cparseTypeQualifierList();

      C11 6.7.3 type-qualifier: const restrict volatile Atomic

    • Declaration

      AST.Type cparseTypeName();

      C11 6.7.7

    • Declaration

      AST.Type cparseSpecifierQualifierList(LVL level, ref Specifier specifier);

      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

      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();

      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-expression

    • Declaration

      bool isDeclarationList(ref Token* pt);

      See if declaration-list is present.

      Return Value

      true if declaration-list is present, even an empty one

    • LVL

      Declaration

      enum LVL;

      More

      Discussion

      Declaration context

      • Declaration

        global

        global

      • Declaration

        parameter

        function parameter (declarations for function identifier-list)

      • Declaration

        prototype

        function prototype

      • Declaration

        local

        local

      • Declaration

        member

        struct member

    • DTR

      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

    • SCW

      Declaration

      enum SCW: uint;

      C11 6.7.1 Storage-class specifiers

    • MOD

      Declaration

      enum MOD: uint;

      C11 6.7.3 Type qualifiers

    • Declaration

      struct Specifier;

      Aggregate for all the various specifiers

      • Declaration

        bool noreturn;

        noreturn attribute

      • scw

        Declaration

        SCW scw;

        storage-class specifiers

      • mod

        Declaration

        MOD mod;

        type qualifiers

      • Declaration

        AST.Expressions* alignExps;

        alignment

      • Declaration

        structalign_t packalign;

        #pragma pack alignment value

    • Declaration

      StorageClass specifiersToSTC(LVL level, const ref Specifier specifier);

      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.