• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
            • Disambiguator
              • Dimb-exprs/decls/stmts
              • Dimb-make/adjust-expr-binary
              • Dimb-transunit
              • Dimb-params-to-names
              • Dimb-cast/call-to-call
              • Dimb-make/adjust-expr-cast
              • Dimb-fundef
                • Dimb-make/adjust-expr-unary
                • Dimb-expr
                • Dimb-dirdeclor
                • Dimb-amb-declor/absdeclor
                • Dimb-cast/call-to-cast
                • Dimb-cast/addsub-to-cast
                • Dimb-cast/addsub-to-addsub
                • Dimb-transunit-ensemble
                • Dimb-add-ident
                • Dimb-kind
                • Dimb-declor
                • Dimb-amb-expr/tyname
                • Dimb-cast/mul-to-cast
                • Dimb-cast/and-to-cast
                • Dimb-cast/mul-to-mul
                • Dimb-cast/and-to-and
                • Dimb-kind-option
                • Dimb-type-spec
                • Dimb-extdecl-list
                • Dimb-extdecl
                • Dimb-lookup-ident
                • Dimb-param-declor
                • Dimb-decl-spec
                • Dimb-add-idents-objfun
                • Dimb-param-declon
                • Dimb-add-ident-objfun
                • Dimb-table
                • Dimb-amb-decl/stmt
                • Dimb-pop-scope
                • Dimb-push-scope
                • Dimb-initdeclor
                • Dimb-declor-option
                • Dimb-enumspec
                • Dimb-decl
                • Dimb-stmt
                • Dimb-scope
                • Dimb-structdeclor
                • Dimb-initdeclor-list
                • Dimb-decl-spec-list
                • Dimb-absdeclor
                • Dimb-init-table
                • Dimb-dirabsdeclor
                • Dimb-align-spec
                • Dimb-strunispec
                • Irr-dimb-table
                • Irr-dimb-kind
                • Dimb-spec/qual-list
                • Dimb-spec/qual
                • Dimb-param-declon-list
                • Dimb-label
                • Dimb-enumer-list
                • Dimb-enumer
                • Dimb-dirabsdeclor-option
                • Dimb-block-item
                • Dimb-structdeclor-list
                • Dimb-structdecl-list
                • Dimb-statassert
                • Dimb-desiniter-list
                • Dimb-desiniter
                • Dimb-decl-list
                • Dimb-const-expr-option
                • Dimb-absdeclor-option
                • Dimb-structdecl
                • Dimb-member-designor
                • Dimb-initer-option
                • Dimb-initer
                • Dimb-genassoc-list
                • Dimb-genassoc
                • Dimb-expr-option
                • Dimb-expr-list
                • Dimb-designor-list
                • Dimb-designor
                • Dimb-const-expr
                • Dimb-block-item-list
                • Dimb-tyname
              • Abstract-syntax
              • Parser
              • Validator
              • Printer
              • Formalized-subset
              • Mapping-to-language-definition
              • Input-files
              • Defpred
              • Output-files
              • Abstract-syntax-operations
              • Validation-information
              • Implementation-environments
              • Concrete-syntax
              • Unambiguity
              • Ascii-identifiers
              • Preprocessing
              • Abstraction-mapping
            • Atc
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Disambiguator

    Dimb-fundef

    Disambiguate a function definition.

    Signature
    (dimb-fundef fundef table) → (mv erp new-fundef new-table)
    Arguments
    fundef — Guard (fundefp fundef).
    table — Guard (dimb-tablep table).
    Returns
    new-fundef — Type (fundefp new-fundef).
    new-table — Type (dimb-tablep new-table).

    We process the declaration specifiers, obtaining the kind of the identifier declared by the declarator, which in valid code must be :objfun, but we do not check this explicitly.

    Then we process the declarator, passing t as the fundefp flag, because we are processing the declarator of a defined function. In valid code, this declarator will include a function declarator with either parameter declarations or identifiers, after it has been processed. Because of the fundefp flag set to t, the disambiguation table returned from dimb-declor will contain a newly pushed scope for the function definition. If the (disambiguated) declarator has parameter declarations, those will have added the formal parameters of the function to that scope. If instead the (disambiguated) declarator has just identifiers, the new scope will be empty, but the declarator will be followed, in the function definition, by declarations for the identifiers (again, assuming the code is valid).

    We process those declarations, which will add the function parameters to the scope that was added when processing the declarator.

    Then we add the declared function to the disambiguation table, so that it can be referenced from the body, in a recursive call.

    We extend the disambiguation table with the identifier __func__ [C17:6.4.2.2].

    After all of that, we disambiguate the body of the function definition, which is a block (i.e. compound statement) in valid code. But we do not push a new scope for the block, because the scope pushed by dimb-declor is already the one for the function body.

    At the end, we pop the scope for the function definition, and we add the function to the table, so that it is available in the rest of the translation unit.

    Definitions and Theorems

    Function: dimb-fundef

    (defun dimb-fundef (fundef table)
     (declare (xargs :guard (and (fundefp fundef)
                                 (dimb-tablep table))))
     (let ((__function__ 'dimb-fundef))
      (declare (ignorable __function__))
      (b*
       (((reterr) (irr-fundef) (irr-dimb-table))
        ((fundef fundef) fundef)
        ((erp new-spec & table)
         (dimb-decl-spec-list fundef.spec (dimb-kind-objfun)
                              table))
        ((erp new-declor ident table)
         (dimb-declor fundef.declor t table))
        ((erp new-decls table)
         (dimb-decl-list fundef.decls table))
        (table (dimb-add-ident-objfun ident table)
    )
        (table (dimb-add-ident-objfun (ident "__func__")
                                      table)
    )
        ((unless (stmt-case fundef.body :compound))
         (reterr
          (msg
           "The body of the function definition ~x0 ~
                          is not a compound statement; ~
                          the code is invalid."
           (fundef-fix fundef))))
        ((erp new-items table)
         (dimb-block-item-list (stmt-compound->items fundef.body)
                               table))
        (table (dimb-pop-scope table))
        (table (dimb-add-ident ident (dimb-kind-objfun)
                               table)
    ))
       (retok (make-fundef :extension fundef.extension
                           :spec new-spec
                           :declor new-declor
                           :decls new-decls
                           :body (stmt-compound new-items))
              table))))

    Theorem: fundefp-of-dimb-fundef.new-fundef

    (defthm fundefp-of-dimb-fundef.new-fundef
      (b* (((mv acl2::?erp ?new-fundef ?new-table)
            (dimb-fundef fundef table)))
        (fundefp new-fundef))
      :rule-classes :rewrite)

    Theorem: dimb-tablep-of-dimb-fundef.new-table

    (defthm dimb-tablep-of-dimb-fundef.new-table
      (b* (((mv acl2::?erp ?new-fundef ?new-table)
            (dimb-fundef fundef table)))
        (dimb-tablep new-table))
      :rule-classes :rewrite)

    Theorem: fundef-unambp-of-dimb-fundef

    (defthm fundef-unambp-of-dimb-fundef
      (b* (((mv acl2::?erp ?new-fundef ?new-table)
            (dimb-fundef fundef table)))
        (implies (not erp)
                 (fundef-unambp new-fundef))))

    Theorem: dimb-fundef-of-fundef-fix-fundef

    (defthm dimb-fundef-of-fundef-fix-fundef
      (equal (dimb-fundef (fundef-fix fundef) table)
             (dimb-fundef fundef table)))

    Theorem: dimb-fundef-fundef-equiv-congruence-on-fundef

    (defthm dimb-fundef-fundef-equiv-congruence-on-fundef
      (implies (fundef-equiv fundef fundef-equiv)
               (equal (dimb-fundef fundef table)
                      (dimb-fundef fundef-equiv table)))
      :rule-classes :congruence)

    Theorem: dimb-fundef-of-dimb-table-fix-table

    (defthm dimb-fundef-of-dimb-table-fix-table
      (equal (dimb-fundef fundef (dimb-table-fix table))
             (dimb-fundef fundef table)))

    Theorem: dimb-fundef-dimb-table-equiv-congruence-on-table

    (defthm dimb-fundef-dimb-table-equiv-congruence-on-table
      (implies (dimb-table-equiv table table-equiv)
               (equal (dimb-fundef fundef table)
                      (dimb-fundef fundef table-equiv)))
      :rule-classes :congruence)