//===- ExprObjC.h - Classes for representing ObjC expressions ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines the ExprObjC interface and subclasses. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_AST_EXPROBJC_H #define LLVM_CLANG_AST_EXPROBJC_H #include "clang/AST/ComputeDependence.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DependenceFlags.h" #include "clang/AST/Expr.h" #include "clang/AST/OperationKinds.h" #include "clang/AST/SelectorLocationsKind.h" #include "clang/AST/Stmt.h" #include "clang/AST/Type.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/TrailingObjects.h" #include "llvm/Support/VersionTuple.h" #include "llvm/Support/type_traits.h" #include <cassert> #include <cstddef> #include <cstdint> #include <optional> namespace clang { class ASTContext; class CXXBaseSpecifier; /// ObjCStringLiteral, used for Objective-C string literals /// i.e. @"foo". class ObjCStringLiteral : public Expr { … }; /// ObjCBoolLiteralExpr - Objective-C Boolean Literal. class ObjCBoolLiteralExpr : public Expr { … }; /// ObjCBoxedExpr - used for generalized expression boxing. /// as in: @(strdup("hello world")), @(random()) or @(view.frame) /// Also used for boxing non-parenthesized numeric literals; /// as in: @42 or \@true (c++/objc++) or \@__objc_yes (c/objc). class ObjCBoxedExpr : public Expr { … }; /// ObjCArrayLiteral - used for objective-c array containers; as in: /// @[@"Hello", NSApp, [NSNumber numberWithInt:42]]; class ObjCArrayLiteral final : public Expr, private llvm::TrailingObjects<ObjCArrayLiteral, Expr *> { … }; /// An element in an Objective-C dictionary literal. /// struct ObjCDictionaryElement { … }; } // namespace clang namespace clang { /// Internal struct for storing Key/value pair. struct ObjCDictionaryLiteral_KeyValuePair { … }; /// Internal struct to describes an element that is a pack /// expansion, used if any of the elements in the dictionary literal /// are pack expansions. struct ObjCDictionaryLiteral_ExpansionData { … }; /// ObjCDictionaryLiteral - AST node to represent objective-c dictionary /// literals; as in: @{@"name" : NSUserName(), @"date" : [NSDate date] }; class ObjCDictionaryLiteral final : public Expr, private llvm::TrailingObjects<ObjCDictionaryLiteral, ObjCDictionaryLiteral_KeyValuePair, ObjCDictionaryLiteral_ExpansionData> { … }; /// ObjCEncodeExpr, used for \@encode in Objective-C. \@encode has the same /// type and behavior as StringLiteral except that the string initializer is /// obtained from ASTContext with the encoding type as an argument. class ObjCEncodeExpr : public Expr { … }; /// ObjCSelectorExpr used for \@selector in Objective-C. class ObjCSelectorExpr : public Expr { … }; /// ObjCProtocolExpr used for protocol expression in Objective-C. /// /// This is used as: \@protocol(foo), as in: /// \code /// [obj conformsToProtocol:@protocol(foo)] /// \endcode /// /// The return type is "Protocol*". class ObjCProtocolExpr : public Expr { … }; /// ObjCIvarRefExpr - A reference to an ObjC instance variable. class ObjCIvarRefExpr : public Expr { … }; /// ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC /// property. class ObjCPropertyRefExpr : public Expr { … }; /// ObjCSubscriptRefExpr - used for array and dictionary subscripting. /// array[4] = array[3]; dictionary[key] = dictionary[alt_key]; class ObjCSubscriptRefExpr : public Expr { … }; /// An expression that sends a message to the given Objective-C /// object or class. /// /// The following contains two message send expressions: /// /// \code /// [[NSString alloc] initWithString:@"Hello"] /// \endcode /// /// The innermost message send invokes the "alloc" class method on the /// NSString class, while the outermost message send invokes the /// "initWithString" instance method on the object returned from /// NSString's "alloc". In all, an Objective-C message send can take /// on four different (although related) forms: /// /// 1. Send to an object instance. /// 2. Send to a class. /// 3. Send to the superclass instance of the current class. /// 4. Send to the superclass of the current class. /// /// All four kinds of message sends are modeled by the ObjCMessageExpr /// class, and can be distinguished via \c getReceiverKind(). Example: /// /// The "void *" trailing objects are actually ONE void * (the /// receiver pointer), and NumArgs Expr *. But due to the /// implementation of children(), these must be together contiguously. class ObjCMessageExpr final : public Expr, private llvm::TrailingObjects<ObjCMessageExpr, void *, SourceLocation> { … }; /// ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type. /// (similar in spirit to MemberExpr). class ObjCIsaExpr : public Expr { … }; /// ObjCIndirectCopyRestoreExpr - Represents the passing of a function /// argument by indirect copy-restore in ARC. This is used to support /// passing indirect arguments with the wrong lifetime, e.g. when /// passing the address of a __strong local variable to an 'out' /// parameter. This expression kind is only valid in an "argument" /// position to some sort of call expression. /// /// The parameter must have type 'pointer to T', and the argument must /// have type 'pointer to U', where T and U agree except possibly in /// qualification. If the argument value is null, then a null pointer /// is passed; otherwise it points to an object A, and: /// 1. A temporary object B of type T is initialized, either by /// zero-initialization (used when initializing an 'out' parameter) /// or copy-initialization (used when initializing an 'inout' /// parameter). /// 2. The address of the temporary is passed to the function. /// 3. If the call completes normally, A is move-assigned from B. /// 4. Finally, A is destroyed immediately. /// /// Currently 'T' must be a retainable object lifetime and must be /// __autoreleasing; this qualifier is ignored when initializing /// the value. class ObjCIndirectCopyRestoreExpr : public Expr { … }; /// An Objective-C "bridged" cast expression, which casts between /// Objective-C pointers and C pointers, transferring ownership in the process. /// /// \code /// NSString *str = (__bridge_transfer NSString *)CFCreateString(); /// \endcode class ObjCBridgedCastExpr final : public ExplicitCastExpr, private llvm::TrailingObjects<ObjCBridgedCastExpr, CXXBaseSpecifier *> { … }; /// A runtime availability query. /// /// There are 2 ways to spell this node: /// \code /// @available(macos 10.10, ios 8, *); // Objective-C /// __builtin_available(macos 10.10, ios 8, *); // C, C++, and Objective-C /// \endcode /// /// Note that we only need to keep track of one \c VersionTuple here, which is /// the one that corresponds to the current deployment target. This is meant to /// be used in the condition of an \c if, but it is also usable as top level /// expressions. /// class ObjCAvailabilityCheckExpr : public Expr { … }; } // namespace clang #endif // LLVM_CLANG_AST_EXPROBJC_H