• 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
            • Abstract-syntax
            • Parser
            • Validator
              • Valid-exprs/decls/stmts
              • Valid-stmt
              • Valid-expr
              • Valid-dirdeclor
              • Valid-type-spec
              • Valid-transunit
              • Valid-stor-spec-list
              • Valid-binary
              • Valid-unary
              • Valid-initdeclor
              • Valid-fundef
              • Valid-type-spec-list-residual
              • Valid-cond
              • Valid-lookup-ord
              • Valid-transunit-ensemble
              • Valid-declor
              • Valid-iconst
              • Valid-initer
              • Valid-c-char
              • Valid-stringlit-list
              • Valid-funcall
              • Valid-add-ord
              • Valid-arrsub
              • Valid-univ-char-name
              • Valid-extdecl
              • Valid-extdecl-list
              • Valid-cast
                • Valid-add-ord-file-scope
                • Valid-spec/qual
                • Valid-sizeof/alignof
                • Valid-memberp
                • Valid-decl-spec
                • Valid-var
                • Valid-param-declon
                • Valid-oct-escape
                • Valid-structdeclor
                • Valid-structdecl
                • Valid-designor
                • Valid-escape
                • Valid-enum-const
                • Valid-cconst
                • Valid-s-char
                • Valid-dec/oct/hex-const
                • Valid-const
                • Valid-gensel
                • Valid-decl-spec-list
                • Valid-lookup-ord-file-scope
                • Valid-member
                • Valid-param-declor
                • Valid-spec/qual-list
                • Valid-fconst
                • Valid-stringlit
                • Valid-s-char-list
                • Valid-c-char-list
                • Valid-block-item
                • Valid-structdeclor-list
                • Valid-simple-escape
                • Valid-align-spec
                • Valid-enumer
                • Valid-dirabsdeclor
                • Valid-decl
                • Valid-pop-scope
                • Valid-enumspec
                • Valid-declor-option
                • Valid-push-scope
                • Valid-initer-option
                • Valid-block-item-list
                • Valid-absdeclor
                • Valid-label
                • Valid-genassoc
                • Valid-tyname
                • Valid-strunispec
                • Valid-structdecl-list
                • Valid-genassoc-list
                • Valid-dirabsdeclor-option
                • Valid-designor-list
                • Valid-const-expr
                • Valid-initdeclor-list
                • Valid-desiniter-list
                • Valid-absdeclor-option
                • Valid-table-num-scopes
                • Valid-expr-list
                • Valid-param-declon-list
                • Valid-desiniter
                • Valid-const-expr-option
                • Valid-expr-option
                • Valid-statassert
                • Valid-enumer-list
                • Valid-init-table
                • Valid-empty-scope
                • Valid-member-designor
                • Valid-decl-list
              • 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
    • Validator

    Valid-cast

    Validate a cast expression, given the type denoted by the type name and the type of the argument expression.

    Signature
    (valid-cast expr type-cast type-arg) → (mv erp type1)
    Arguments
    expr — Guard (exprp expr).
    type-cast — Guard (typep type-cast).
    type-arg — Guard (typep type-arg).
    Returns
    type1 — Type (typep type1).

    The type name must denote the void type or a scalar type [C17:6.5.4/2]. The expression must have scalar type [C17:6.5.4/2]. Since scalar types involve pointers, we perform array-to-pointer and function-to-pointer conversions. The result is the type denoted by the type name.

    Definitions and Theorems

    Function: valid-cast

    (defun valid-cast (expr type-cast type-arg)
     (declare (xargs :guard (and (exprp expr)
                                 (typep type-cast)
                                 (typep type-arg))))
     (declare (xargs :guard (expr-case expr :cast)))
     (let ((__function__ 'valid-cast))
      (declare (ignorable __function__))
      (b*
       (((reterr) (irr-type))
        ((when (or (type-case type-cast :unknown)
                   (type-case type-arg :unknown)))
         (retok (type-unknown)))
        (type1-arg (type-fpconvert (type-apconvert type-cast)))
        ((unless (or (type-case type-cast :void)
                     (type-scalarp type-cast)))
         (reterr
          (msg
           "In the cast expression ~x0, ~
                          the cast type is ~x1."
           (expr-fix expr)
           (type-fix type-cast))))
        ((unless (type-scalarp type1-arg))
         (reterr
          (msg
           "In the cast expression ~x0, ~
                          the argument expression has type ~x1."
           (expr-fix expr)
           (type-fix type-arg)))))
       (retok (type-fix type-cast)))))

    Theorem: typep-of-valid-cast.type1

    (defthm typep-of-valid-cast.type1
      (b* (((mv acl2::?erp ?type1)
            (valid-cast expr type-cast type-arg)))
        (typep type1))
      :rule-classes :rewrite)

    Theorem: valid-cast-of-expr-fix-expr

    (defthm valid-cast-of-expr-fix-expr
      (equal (valid-cast (expr-fix expr)
                         type-cast type-arg)
             (valid-cast expr type-cast type-arg)))

    Theorem: valid-cast-expr-equiv-congruence-on-expr

    (defthm valid-cast-expr-equiv-congruence-on-expr
      (implies (expr-equiv expr expr-equiv)
               (equal (valid-cast expr type-cast type-arg)
                      (valid-cast expr-equiv type-cast type-arg)))
      :rule-classes :congruence)

    Theorem: valid-cast-of-type-fix-type-cast

    (defthm valid-cast-of-type-fix-type-cast
      (equal (valid-cast expr (type-fix type-cast)
                         type-arg)
             (valid-cast expr type-cast type-arg)))

    Theorem: valid-cast-type-equiv-congruence-on-type-cast

    (defthm valid-cast-type-equiv-congruence-on-type-cast
      (implies (type-equiv type-cast type-cast-equiv)
               (equal (valid-cast expr type-cast type-arg)
                      (valid-cast expr type-cast-equiv type-arg)))
      :rule-classes :congruence)

    Theorem: valid-cast-of-type-fix-type-arg

    (defthm valid-cast-of-type-fix-type-arg
      (equal (valid-cast expr type-cast (type-fix type-arg))
             (valid-cast expr type-cast type-arg)))

    Theorem: valid-cast-type-equiv-congruence-on-type-arg

    (defthm valid-cast-type-equiv-congruence-on-type-arg
      (implies (type-equiv type-arg type-arg-equiv)
               (equal (valid-cast expr type-cast type-arg)
                      (valid-cast expr type-cast type-arg-equiv)))
      :rule-classes :congruence)