diff
stringlengths
41
2.03M
msg
stringlengths
1
1.5k
repo
stringlengths
5
40
sha
stringlengths
40
40
time
stringlengths
20
20
mmm a / tensorflow / python / autograph / impl / api . py <nl> ppp b / tensorflow / python / autograph / impl / api . py <nl> <nl> # TODO ( mdan ) : This should behave like to_graph ( e . g . convert statically ) . <nl> # TODO ( znado ) : Make an alias so can write Verbosity directly without needing <nl> # to write converter . <nl> - def convert ( recursive = False , verbose = converter . Verbosity . VERBOSE ) : <nl> + def convert ( <nl> + recursive = False , <nl> + verbose = converter . Verbosity . BRIEF , <nl> + optional_features = converter . Feature . ALL ) : <nl> " " " Decorator that compiles a function to use TensorFlow ops . <nl> <nl> The decorator is dynamic - it recompiles the target whenever the decorated <nl> def convert ( recursive = False , verbose = converter . Verbosity . VERBOSE ) : <nl> recursive : bool , whether to recursively convert any functions or classes <nl> that the converted function may use . <nl> verbose : converter . Verbosity , the level of verbosity . <nl> + optional_features : converted . Feature , allows toggling optional or <nl> + experimental features . When set to None , only the core features are <nl> + enabled . <nl> <nl> Returns : <nl> Callable , a decorator that converts the given function into an equivalent <nl> def wrapper ( * args , * * kwargs ) : <nl> recursive = recursive , <nl> verbose = verbose , <nl> force_conversion = True , <nl> - optional_features = converter . Feature . ALL , <nl> + optional_features = optional_features , <nl> ) , * args , * * kwargs ) <nl> <nl> wrapper = tf_decorator . make_decorator ( f , wrapper ) <nl>
Allow toggling optional features in @ convert .
tensorflow/tensorflow
369d30289c4ad1b69f6d04227b9a6a9ebdf349d0
2018-12-06T02:46:11Z
mmm a / src / Storages / StorageDistributed . cpp <nl> ppp b / src / Storages / StorageDistributed . cpp <nl> void StorageDistributed : : alter ( const AlterCommands & params , const Context & con <nl> void StorageDistributed : : startup ( ) <nl> { <nl> if ( remote_database . empty ( ) & & ! remote_table_function_ptr ) <nl> - LOG_INFO ( log , " Name of remote database is empty . Default database will be used implicitly . " ) ; <nl> + LOG_WARNING ( log , " Name of remote database is empty . Default database will be used implicitly . " ) ; <nl> <nl> if ( ! volume ) <nl> return ; <nl> mmm a / tests / queries / 0_stateless / 01231_distributed_aggregation_memory_efficient_mix_levels . sql <nl> ppp b / tests / queries / 0_stateless / 01231_distributed_aggregation_memory_efficient_mix_levels . sql <nl> <nl> + set send_logs_level = ' error ' ; <nl> + <nl> create database if not exists shard_0 ; <nl> create database if not exists shard_1 ; <nl> <nl>
Review fixes .
ClickHouse/ClickHouse
4fd5ef8bad188a9bd0f4b7bc5d686a0c8761cc39
2020-04-06T18:05:45Z
mmm a / doc / man / bitcoin - cli . 1 <nl> ppp b / doc / man / bitcoin - cli . 1 <nl> <nl> - . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 4 . <nl> - . TH BITCOIN - CLI " 1 " " September 2017 " " bitcoin - cli v0 . 15 . 99 . 0 " " User Commands " <nl> + . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 3 . <nl> + . TH BITCOIN - CLI " 1 " " January 2018 " " bitcoin - cli v0 . 16 . 99 . 0 " " User Commands " <nl> . SH NAME <nl> - bitcoin - cli \ - manual page for bitcoin - cli v0 . 15 . 99 . 0 <nl> + bitcoin - cli \ - manual page for bitcoin - cli v0 . 16 . 99 . 0 <nl> . SH DESCRIPTION <nl> - Bitcoin Core RPC client version v0 . 15 . 99 . 0 <nl> + Bitcoin Core RPC client version v0 . 16 . 99 . 0 <nl> . SS " Usage : " <nl> . TP <nl> bitcoin \ - cli [ options ] < command > [ params ] <nl> Specify configuration file ( default : bitcoin . conf ) <nl> \ fB \ - datadir = \ fR < dir > <nl> . IP <nl> Specify data directory <nl> + . HP <nl> + \ fB \ - getinfo \ fR <nl> + . IP <nl> + Get general information from the remote server . Note that unlike <nl> + server \ - side RPC calls , the results of \ fB \ - getinfo \ fR is the result of <nl> + multiple non \ - atomic requests . Some entries in the result may <nl> + represent results from different states ( e . g . wallet balance may <nl> + be as of a different block from the chain state reported ) <nl> . PP <nl> Chain selection options : <nl> . HP <nl> Send RPC for non \ - default wallet on RPC server ( argument is wallet <nl> filename in bitcoind directory , required if bitcoind / \ - Qt runs <nl> with multiple wallets ) <nl> . SH COPYRIGHT <nl> - Copyright ( C ) 2009 - 2017 The Bitcoin Core developers <nl> + Copyright ( C ) 2009 - 2018 The Bitcoin Core developers <nl> <nl> Please contribute if you find Bitcoin Core useful . Visit <nl> < https : / / bitcoincore . org > for further information about the software . <nl> mmm a / doc / man / bitcoin - qt . 1 <nl> ppp b / doc / man / bitcoin - qt . 1 <nl> <nl> - . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 4 . <nl> - . TH BITCOIN - QT " 1 " " September 2017 " " bitcoin - qt v0 . 15 . 99 . 0 " " User Commands " <nl> + . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 3 . <nl> + . TH BITCOIN - QT " 1 " " January 2018 " " bitcoin - qt v0 . 16 . 99 . 0 " " User Commands " <nl> . SH NAME <nl> - bitcoin - qt \ - manual page for bitcoin - qt v0 . 15 . 99 . 0 <nl> + bitcoin - qt \ - manual page for bitcoin - qt v0 . 16 . 99 . 0 <nl> . SH DESCRIPTION <nl> - Bitcoin Core version v0 . 15 . 99 . 0 ( 64 \ - bit ) <nl> + Bitcoin Core version v0 . 16 . 99 . 0 ( 64 \ - bit ) <nl> Usage : <nl> . IP <nl> bitcoin \ - qt [ command \ - line options ] <nl> block hash ) <nl> If this block is in the chain assume that it and its ancestors are valid <nl> and potentially skip their script verification ( 0 to verify all , <nl> default : <nl> - 0000000000000000003b9ce759c2a087d52abc4266f8f4ebd6d768b89defa50a , <nl> + 0000000000000000005214481d2d96f898e3d5416e43359c145944a909d242e0 , <nl> testnet : <nl> 0000000002e9e7b00e1f6dc5123a04aad68dd0f0968d8c7aa45f6640795c37b1 ) <nl> . HP <nl> Set database cache size in megabytes ( 4 to 16384 , default : 450 ) <nl> . IP <nl> Imports blocks from external blk000 ? ? . dat file on startup <nl> . HP <nl> + \ fB \ - debuglogfile = \ fR < file > <nl> + . IP <nl> + Specify location of debug log file : this can be an absolute path or a <nl> + path relative to the data directory ( default : debug . log ) <nl> + . HP <nl> \ fB \ - maxorphantx = \ fR < n > <nl> . IP <nl> Keep at most < n > unconnectable transactions in memory ( default : 100 ) <nl> Extra transactions to keep in memory for compact block reconstructions <nl> . HP <nl> \ fB \ - par = \ fR < n > <nl> . IP <nl> - Set the number of script verification threads ( \ fB \ - 2 \ fR to 16 , 0 = auto , < 0 = <nl> + Set the number of script verification threads ( \ fB \ - 6 \ fR to 16 , 0 = auto , < 0 = <nl> leave that many cores free , default : 0 ) <nl> . HP <nl> \ fB \ - pid = \ fR < file > <nl> Connection options : <nl> . HP <nl> \ fB \ - addnode = \ fR < ip > <nl> . IP <nl> - Add a node to connect to and attempt to keep the connection open <nl> + Add a node to connect to and attempt to keep the connection open ( see <nl> + the ` addnode ` RPC command help for more info ) <nl> . HP <nl> \ fB \ - banscore = \ fR < n > <nl> . IP <nl> for IPv6 <nl> \ fB \ - connect = \ fR < ip > <nl> . IP <nl> Connect only to the specified node ( s ) ; \ fB \ - connect \ fR = \ fI \ , 0 \ / \ fR disables automatic <nl> - connections <nl> + connections ( the rules for this peer are the same as for <nl> + \ fB \ - addnode \ fR ) <nl> . HP <nl> \ fB \ - discover \ fR <nl> . IP <nl> Tries to keep outbound traffic under the given target ( in MiB per 24h ) , <nl> . PP <nl> Wallet options : <nl> . HP <nl> + \ fB \ - addresstype \ fR <nl> + . IP <nl> + What type of addresses to use ( " legacy " , " p2sh \ - segwit " , or " bech32 " , <nl> + default : " p2sh \ - segwit " ) <nl> + . HP <nl> + \ fB \ - changetype \ fR <nl> + . IP <nl> + What type of change to use ( " legacy " , " p2sh \ - segwit " , or " bech32 " ) . <nl> + Default is same as \ fB \ - addresstype \ fR , except when <nl> + \ fB \ - addresstype \ fR = \ fI \ , p2sh \ - segwit \ / \ fR a native segwit output is used when <nl> + sending to a native segwit address ) <nl> + . HP <nl> \ fB \ - disablewallet \ fR <nl> . IP <nl> Do not load the wallet and disable wallet RPC calls <nl> confirmation on average within n blocks ( default : 6 ) <nl> . HP <nl> \ fB \ - walletrbf \ fR <nl> . IP <nl> - Send transactions with full \ - RBF opt \ - in enabled ( default : 0 ) <nl> + Send transactions with full \ - RBF opt \ - in enabled ( RPC only , default : 0 ) <nl> . HP <nl> \ fB \ - upgradewallet \ fR <nl> . IP <nl> Specify wallet file ( within data directory ) ( default : wallet . dat ) <nl> . IP <nl> Make the wallet broadcast transactions ( default : 1 ) <nl> . HP <nl> + \ fB \ - walletdir = \ fR < dir > <nl> + . IP <nl> + Specify directory to hold wallets ( default : < datadir > / wallets if it <nl> + exists , otherwise < datadir > ) <nl> + . HP <nl> \ fB \ - walletnotify = \ fR < cmd > <nl> . IP <nl> Execute command when a wallet transaction changes ( % s in cmd is replaced <nl> Show splash screen on startup ( default : 1 ) <nl> . IP <nl> Reset all settings changed in the GUI <nl> . SH COPYRIGHT <nl> - Copyright ( C ) 2009 - 2017 The Bitcoin Core developers <nl> + Copyright ( C ) 2009 - 2018 The Bitcoin Core developers <nl> <nl> Please contribute if you find Bitcoin Core useful . Visit <nl> < https : / / bitcoincore . org > for further information about the software . <nl> mmm a / doc / man / bitcoin - tx . 1 <nl> ppp b / doc / man / bitcoin - tx . 1 <nl> <nl> - . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 4 . <nl> - . TH BITCOIN - TX " 1 " " September 2017 " " bitcoin - tx v0 . 15 . 99 . 0 " " User Commands " <nl> + . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 3 . <nl> + . TH BITCOIN - TX " 1 " " January 2018 " " bitcoin - tx v0 . 16 . 99 . 0 " " User Commands " <nl> . SH NAME <nl> - bitcoin - tx \ - manual page for bitcoin - tx v0 . 15 . 99 . 0 <nl> + bitcoin - tx \ - manual page for bitcoin - tx v0 . 16 . 99 . 0 <nl> . SH DESCRIPTION <nl> - Bitcoin Core bitcoin \ - tx utility version v0 . 15 . 99 . 0 <nl> + Bitcoin Core bitcoin \ - tx utility version v0 . 16 . 99 . 0 <nl> . SS " Usage : " <nl> . TP <nl> bitcoin \ - tx [ options ] < hex \ - tx > [ commands ] <nl> set = NAME : JSON \ - STRING <nl> . IP <nl> Set register NAME to given JSON \ - STRING <nl> . SH COPYRIGHT <nl> - Copyright ( C ) 2009 - 2017 The Bitcoin Core developers <nl> + Copyright ( C ) 2009 - 2018 The Bitcoin Core developers <nl> <nl> Please contribute if you find Bitcoin Core useful . Visit <nl> < https : / / bitcoincore . org > for further information about the software . <nl> mmm a / doc / man / bitcoind . 1 <nl> ppp b / doc / man / bitcoind . 1 <nl> <nl> - . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 4 . <nl> - . TH BITCOIND " 1 " " September 2017 " " bitcoind v0 . 15 . 99 . 0 " " User Commands " <nl> + . \ " DO NOT MODIFY THIS FILE ! It was generated by help2man 1 . 47 . 3 . <nl> + . TH BITCOIND " 1 " " January 2018 " " bitcoind v0 . 16 . 99 . 0 " " User Commands " <nl> . SH NAME <nl> - bitcoind \ - manual page for bitcoind v0 . 15 . 99 . 0 <nl> + bitcoind \ - manual page for bitcoind v0 . 16 . 99 . 0 <nl> . SH DESCRIPTION <nl> - Bitcoin Core Daemon version v0 . 15 . 99 . 0 <nl> + Bitcoin Core Daemon version v0 . 16 . 99 . 0 <nl> . SS " Usage : " <nl> . TP <nl> bitcoind [ options ] <nl> block hash ) <nl> If this block is in the chain assume that it and its ancestors are valid <nl> and potentially skip their script verification ( 0 to verify all , <nl> default : <nl> - 0000000000000000003b9ce759c2a087d52abc4266f8f4ebd6d768b89defa50a , <nl> + 0000000000000000005214481d2d96f898e3d5416e43359c145944a909d242e0 , <nl> testnet : <nl> 0000000002e9e7b00e1f6dc5123a04aad68dd0f0968d8c7aa45f6640795c37b1 ) <nl> . HP <nl> Set database cache size in megabytes ( 4 to 16384 , default : 450 ) <nl> . IP <nl> Imports blocks from external blk000 ? ? . dat file on startup <nl> . HP <nl> + \ fB \ - debuglogfile = \ fR < file > <nl> + . IP <nl> + Specify location of debug log file : this can be an absolute path or a <nl> + path relative to the data directory ( default : debug . log ) <nl> + . HP <nl> \ fB \ - maxorphantx = \ fR < n > <nl> . IP <nl> Keep at most < n > unconnectable transactions in memory ( default : 100 ) <nl> Extra transactions to keep in memory for compact block reconstructions <nl> . HP <nl> \ fB \ - par = \ fR < n > <nl> . IP <nl> - Set the number of script verification threads ( \ fB \ - 2 \ fR to 16 , 0 = auto , < 0 = <nl> + Set the number of script verification threads ( \ fB \ - 6 \ fR to 16 , 0 = auto , < 0 = <nl> leave that many cores free , default : 0 ) <nl> . HP <nl> \ fB \ - pid = \ fR < file > <nl> Connection options : <nl> . HP <nl> \ fB \ - addnode = \ fR < ip > <nl> . IP <nl> - Add a node to connect to and attempt to keep the connection open <nl> + Add a node to connect to and attempt to keep the connection open ( see <nl> + the ` addnode ` RPC command help for more info ) <nl> . HP <nl> \ fB \ - banscore = \ fR < n > <nl> . IP <nl> for IPv6 <nl> \ fB \ - connect = \ fR < ip > <nl> . IP <nl> Connect only to the specified node ( s ) ; \ fB \ - connect \ fR = \ fI \ , 0 \ / \ fR disables automatic <nl> - connections <nl> + connections ( the rules for this peer are the same as for <nl> + \ fB \ - addnode \ fR ) <nl> . HP <nl> \ fB \ - discover \ fR <nl> . IP <nl> Tries to keep outbound traffic under the given target ( in MiB per 24h ) , <nl> . PP <nl> Wallet options : <nl> . HP <nl> + \ fB \ - addresstype \ fR <nl> + . IP <nl> + What type of addresses to use ( " legacy " , " p2sh \ - segwit " , or " bech32 " , <nl> + default : " p2sh \ - segwit " ) <nl> + . HP <nl> + \ fB \ - changetype \ fR <nl> + . IP <nl> + What type of change to use ( " legacy " , " p2sh \ - segwit " , or " bech32 " ) . <nl> + Default is same as \ fB \ - addresstype \ fR , except when <nl> + \ fB \ - addresstype \ fR = \ fI \ , p2sh \ - segwit \ / \ fR a native segwit output is used when <nl> + sending to a native segwit address ) <nl> + . HP <nl> \ fB \ - disablewallet \ fR <nl> . IP <nl> Do not load the wallet and disable wallet RPC calls <nl> confirmation on average within n blocks ( default : 6 ) <nl> . HP <nl> \ fB \ - walletrbf \ fR <nl> . IP <nl> - Send transactions with full \ - RBF opt \ - in enabled ( default : 0 ) <nl> + Send transactions with full \ - RBF opt \ - in enabled ( RPC only , default : 0 ) <nl> . HP <nl> \ fB \ - upgradewallet \ fR <nl> . IP <nl> Specify wallet file ( within data directory ) ( default : wallet . dat ) <nl> . IP <nl> Make the wallet broadcast transactions ( default : 1 ) <nl> . HP <nl> + \ fB \ - walletdir = \ fR < dir > <nl> + . IP <nl> + Specify directory to hold wallets ( default : < datadir > / wallets if it <nl> + exists , otherwise < datadir > ) <nl> + . HP <nl> \ fB \ - walletnotify = \ fR < cmd > <nl> . IP <nl> Execute command when a wallet transaction changes ( % s in cmd is replaced <nl> non \ - verbose mode , non \ - segwit ( 0 ) or segwit ( 1 ) ( default : 1 ) <nl> . IP <nl> Set the number of threads to service RPC calls ( default : 4 ) <nl> . SH COPYRIGHT <nl> - Copyright ( C ) 2009 - 2017 The Bitcoin Core developers <nl> + Copyright ( C ) 2009 - 2018 The Bitcoin Core developers <nl> <nl> Please contribute if you find Bitcoin Core useful . Visit <nl> < https : / / bitcoincore . org > for further information about the software . <nl>
doc : Update manpages to 0 . 16 . 99
bitcoin/bitcoin
9cb2309050880c2887b4b5f7a7231e4fc6dc3f47
2018-01-30T13:24:59Z
mmm a / package . json <nl> ppp b / package . json <nl> <nl> " version " : " 0 . 12 . 2 " , <nl> " subversion " : { <nl> " browser " : " 0 . 5 . 0 " , <nl> - " framework " : " 0 . 21 . 9 " , <nl> + " framework " : " 0 . 21 . 10 " , <nl> " vue - render " : " 0 . 12 . 3 " , <nl> " transformer " : " > = 0 . 1 . 5 < 0 . 5 " <nl> } , <nl>
* [ jsfm ] release v0 . 21 . 10
apache/incubator-weex
faca5562b8f595e0f95693f35757b6d04ae71b9f
2017-08-17T04:37:13Z
mmm a / stdlib / public / core / FloatingPointTypes . swift . gyb <nl> ppp b / stdlib / public / core / FloatingPointTypes . swift . gyb <nl> extension $ { Self } : BinaryFloatingPoint { <nl> public var significandWidth : Int { <nl> let trailingZeros = significandBitPattern . countTrailingZeros <nl> if isNormal { <nl> + guard significandBitPattern ! = 0 else { return 0 } <nl> return $ { Self } . significandBitCount - trailingZeros <nl> } <nl> if isSubnormal { <nl> mmm a / test / stdlib / FloatingPoint . swift . gyb <nl> ppp b / test / stdlib / FloatingPoint . swift . gyb <nl> FloatingPoint . test ( " $ { Self } / LosslessStringConvertible " ) { <nl> checkLosslessStringConvertible ( instances ) <nl> expectTrue ( Float ( String ( Float . nan ) ) ! . isNaN ) <nl> } <nl> + <nl> + FloatingPoint . test ( " $ { Self } . significandWidth " ) { <nl> + expectEqual ( - 1 , $ { Self } ( 0 ) . significandWidth ) <nl> + expectEqual ( - 1 , $ { Self } . infinity . significandWidth ) <nl> + expectEqual ( - 1 , $ { Self } . nan . significandWidth ) <nl> + expectEqual ( $ { Self } . significandBitCount , $ { Self } ( 1 ) . nextUp . significandWidth ) <nl> + expectEqual ( $ { Self } . significandBitCount , $ { Self } ( 1 ) . nextDown . significandWidth ) <nl> + expectEqual ( 0 , $ { Self } . ulpOfOne . significandWidth ) <nl> + expectEqual ( 0 , $ { Self } ( 1 ) . significandWidth ) <nl> + expectEqual ( 0 , $ { Self } ( 2 ) . significandWidth ) <nl> + expectEqual ( 1 , $ { Self } ( 3 ) . significandWidth ) <nl> + } <nl> % if Self = = ' Float80 ' : <nl> # endif <nl> % end <nl>
Make . significandWidth do the right thing for exact powers of two
apple/swift
d7d05e1a92ddb932989961b57d731075be1321ea
2016-12-08T19:49:19Z
mmm a / bson / bsonelement . h <nl> ppp b / bson / bsonelement . h <nl> namespace mongo { <nl> } <nl> } <nl> <nl> - bool BSONElement : : trueValue ( ) const { <nl> + inline bool BSONElement : : trueValue ( ) const { <nl> switch ( type ( ) ) { <nl> case NumberLong : <nl> return * reinterpret_cast < const long long * > ( value ( ) ) ! = 0 ; <nl>
inline
mongodb/mongo
c0081cc3c54c630190e29f9dca5d3259bfb850b5
2010-04-21T19:09:28Z
mmm a / . travis . yml <nl> ppp b / . travis . yml <nl> matrix : <nl> # - env : GODOT_TARGET = windows TOOLS = yes <nl> # os : linux <nl> # compiler : gcc <nl> + - env : GODOT_TARGET = android TOOLS = no <nl> + os : linux <nl> + compiler : gcc <nl> - env : GODOT_TARGET = osx TOOLS = yes <nl> os : osx <nl> compiler : clang <nl> - # - env : GODOT_TARGET = android TOOLS = no <nl> - # os : osx <nl> - # compiler : clang <nl> # - env : GODOT_TARGET = iphone TOOLS = no <nl> # os : osx <nl> # compiler : clang <nl> addons : <nl> # For style checks . <nl> - clang - format - 3 . 9 <nl> <nl> + install : <nl> + - if [ " $ TRAVIS_OS_NAME " = " linux " ] & & [ " $ GODOT_TARGET " = " android " ] ; then <nl> + misc / travis / android - tools - linux . sh ; <nl> + fi <nl> + - if [ " $ TRAVIS_OS_NAME " = " osx " ] ; then <nl> + misc / travis / scons - local - osx . sh ; <nl> + misc / travis / ccache - osx . sh ; <nl> + fi <nl> + - if [ " $ TRAVIS_OS_NAME " = " osx " ] & & [ " $ GODOT_TARGET " = " android " ] ; then <nl> + misc / travis / android - tools - osx . sh ; <nl> + fi <nl> + <nl> before_script : <nl> + - if [ " $ TRAVIS_OS_NAME " = " linux " ] ; then <nl> + export CCACHE = " / usr / bin / ccache " ; <nl> + fi <nl> - if [ " $ TRAVIS_OS_NAME " = " osx " ] ; then <nl> - brew update ; brew install scons ccache ; <nl> + export CCACHE = " / usr / local / bin / ccache " ; <nl> export PATH = " / usr / local / opt / ccache / libexec : $ PATH " ; <nl> fi <nl> - - if [ " $ TRAVIS_OS_NAME " = " osx " ] & & [ " $ GODOT_TARGET " = " android " ] ; then <nl> - brew update ; brew install - v android - sdk ; <nl> - brew install - v android - ndk | grep - v " inflating : " | grep - v " creating : " ; <nl> - export ANDROID_HOME = / usr / local / opt / android - sdk ; export ANDROID_NDK_ROOT = / usr / local / opt / android - ndk ; <nl> + - if [ " $ GODOT_TARGET " = " android " ] ; then <nl> + export ANDROID_HOME = $ TRAVIS_BUILD_DIR / godot - dev / build - tools / android - sdk ; <nl> + export ANDROID_NDK_ROOT = $ TRAVIS_BUILD_DIR / godot - dev / build - tools / android - ndk ; <nl> fi <nl> <nl> script : <nl> script : <nl> else <nl> scons - j2 CC = $ CC CXX = $ CXX platform = $ GODOT_TARGET TOOLS = $ TOOLS verbose = yes progress = no ; <nl> fi <nl> + <nl> + after_success : <nl> + - if [ " $ STATIC_CHECKS " ! = " yes " ] & & [ $ ( command - v ccache ) ] ; then <nl> + which ccache ; <nl> + ccache - - version | grep " ccache version " ; <nl> + ccache - s ; <nl> + fi ; <nl> new file mode 100755 <nl> index 00000000000 . . 04fb2eee210 <nl> mmm / dev / null <nl> ppp b / misc / travis / android - tools - linux . sh <nl> <nl> + # ! / bin / bash <nl> + <nl> + # SDK <nl> + # https : / / dl . google . com / android / repository / sdk - tools - linux - 3859397 . zip <nl> + # SHA - 256 444e22ce8ca0f67353bda4b85175ed3731cae3ffa695ca18119cbacef1c1bea0 <nl> + # latest version available here : https : / / developer . android . com / studio / index . html <nl> + <nl> + # NDK <nl> + # https : / / dl . google . com / android / repository / android - ndk - r15c - linux - x86_64 . zip <nl> + # SHA - 1 0bf02d4e8b85fd770fd7b9b2cdec57f9441f27a2 <nl> + # latest version available here : https : / / developer . android . com / ndk / downloads / index . html <nl> + <nl> + BASH_RC = ~ / . bashrc <nl> + GODOT_BUILD_TOOLS_PATH = . / godot - dev / build - tools <nl> + mkdir - p $ GODOT_BUILD_TOOLS_PATH <nl> + cd $ GODOT_BUILD_TOOLS_PATH <nl> + <nl> + ANDROID_BASE_URL = http : / / dl . google . com / android / repository <nl> + <nl> + ANDROID_SDK_RELEASE = 3859397 <nl> + ANDROID_SDK_DIR = android - sdk <nl> + ANDROID_SDK_FILENAME = sdk - tools - linux - $ ANDROID_SDK_RELEASE . zip <nl> + ANDROID_SDK_URL = $ ANDROID_BASE_URL / $ ANDROID_SDK_FILENAME <nl> + ANDROID_SDK_PATH = $ GODOT_BUILD_TOOLS_PATH / $ ANDROID_SDK_DIR <nl> + ANDROID_SDK_SHA256 = 444e22ce8ca0f67353bda4b85175ed3731cae3ffa695ca18119cbacef1c1bea0 <nl> + <nl> + ANDROID_NDK_RELEASE = r15c <nl> + ANDROID_NDK_DIR = android - ndk <nl> + ANDROID_NDK_FILENAME = android - ndk - $ ANDROID_NDK_RELEASE - linux - x86_64 . zip <nl> + ANDROID_NDK_URL = $ ANDROID_BASE_URL / $ ANDROID_NDK_FILENAME <nl> + ANDROID_NDK_PATH = $ GODOT_BUILD_TOOLS_PATH / $ ANDROID_NDK_DIR <nl> + ANDROID_NDK_SHA1 = 0bf02d4e8b85fd770fd7b9b2cdec57f9441f27a2 <nl> + <nl> + echo <nl> + echo " Download and install Android development tools . . . " <nl> + echo <nl> + <nl> + if [ ! - e $ ANDROID_SDK_FILENAME ] ; then <nl> + echo " Downloading : Android SDK . . . " <nl> + curl - L - O $ ANDROID_SDK_URL <nl> + else <nl> + echo $ ANDROID_SDK_SHA1 $ ANDROID_SDK_FILENAME > $ ANDROID_SDK_FILENAME . sha1 <nl> + if [ $ ( shasum - a 256 < $ ANDROID_SDK_FILENAME | awk ' { print $ 1 ; } ' ) ! = $ ANDROID_SDK_SHA1 ] ; then <nl> + echo " Downloading : Android SDK . . . " <nl> + curl - L - O $ ANDROID_SDK_URL <nl> + fi <nl> + fi <nl> + <nl> + if [ ! - d $ ANDROID_SDK_DIR ] ; then <nl> + echo " Extracting : Android SDK . . . " <nl> + unzip - qq $ ANDROID_SDK_FILENAME - d $ ANDROID_SDK_DIR <nl> + echo <nl> + fi <nl> + <nl> + if [ ! - e $ ANDROID_NDK_FILENAME ] ; then <nl> + echo " Downloading : Android NDK . . . " <nl> + curl - L - O $ ANDROID_NDK_URL <nl> + else <nl> + echo $ ANDROID_NDK_MD5 $ ANDROID_NDK_FILENAME > $ ANDROID_NDK_FILENAME . md5 <nl> + if [ $ ( shasum - a 1 < $ ANDROID_NDK_FILENAME | awk ' { print $ 1 ; } ' ) ! = $ ANDROID_NDK_SHA1 ] ; then <nl> + echo " Downloading : Android NDK . . . " <nl> + curl - L - O $ ANDROID_NDK_URL <nl> + fi <nl> + fi <nl> + <nl> + if [ ! - d $ ANDROID_NDK_DIR ] ; then <nl> + echo " Extracting : Android NDK . . . " <nl> + unzip - qq $ ANDROID_NDK_FILENAME <nl> + mv android - ndk - $ ANDROID_NDK_RELEASE $ ANDROID_NDK_DIR <nl> + echo <nl> + fi <nl> + <nl> + echo " Installing : Android Tools . . . " <nl> + # $ ANDROID_SDK_DIR / tools / bin / sdkmanager - - all <nl> + yes | $ ANDROID_SDK_DIR / tools / bin / sdkmanager - - licenses > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' tools ' > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' platform - tools ' > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' build - tools ; 26 . 0 . 2 ' > / dev / null <nl> + echo <nl> + <nl> + EXPORT_VAL = " export ANDROID_HOME = $ ANDROID_SDK_PATH " <nl> + if ! grep - q " ^ $ EXPORT_VAL " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export ANDROID_NDK_ROOT = $ ANDROID_NDK_PATH " <nl> + if ! grep - q " ^ $ EXPORT_VAL " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export PATH = $ PATH : $ ANDROID_SDK_PATH / tools " <nl> + if ! grep - q " ^ export PATH = . * $ ANDROID_SDK_PATH / tools . * " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export PATH = $ PATH : $ ANDROID_SDK_PATH / tools / bin " <nl> + if ! grep - q " ^ export PATH = . * $ ANDROID_SDK_PATH / tools / bin . * " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + echo <nl> + echo " Done ! " <nl> + echo <nl> new file mode 100755 <nl> index 00000000000 . . 96125a3a3f7 <nl> mmm / dev / null <nl> ppp b / misc / travis / android - tools - osx . sh <nl> <nl> + # ! / bin / bash <nl> + <nl> + # SDK <nl> + # https : / / dl . google . com / android / repository / sdk - tools - darwin - 3859397 . zip <nl> + # SHA - 256 4a81754a760fce88cba74d69c364b05b31c53d57b26f9f82355c61d5fe4b9df9 <nl> + # latest version available here : https : / / developer . android . com / studio / index . html <nl> + <nl> + # NDK <nl> + # https : / / dl . google . com / android / repository / android - ndk - r15c - darwin - x86_64 . zip <nl> + # SHA - 1 ea4b5d76475db84745aa8828000d009625fc1f98 <nl> + # latest version available here : https : / / developer . android . com / ndk / downloads / index . html <nl> + <nl> + BASH_RC = ~ / . bashrc <nl> + GODOT_BUILD_TOOLS_PATH = . / godot - dev / build - tools <nl> + mkdir - p $ GODOT_BUILD_TOOLS_PATH <nl> + cd $ GODOT_BUILD_TOOLS_PATH <nl> + <nl> + ANDROID_BASE_URL = http : / / dl . google . com / android / repository <nl> + <nl> + ANDROID_SDK_RELEASE = 3859397 <nl> + ANDROID_SDK_DIR = android - sdk <nl> + ANDROID_SDK_FILENAME = sdk - tools - darwin - $ ANDROID_SDK_RELEASE . zip <nl> + ANDROID_SDK_URL = $ ANDROID_BASE_URL / $ ANDROID_SDK_FILENAME <nl> + ANDROID_SDK_PATH = $ GODOT_BUILD_TOOLS_PATH / $ ANDROID_SDK_DIR <nl> + ANDROID_SDK_SHA256 = 4a81754a760fce88cba74d69c364b05b31c53d57b26f9f82355c61d5fe4b9df9 <nl> + <nl> + ANDROID_NDK_RELEASE = r15c <nl> + ANDROID_NDK_DIR = android - ndk <nl> + ANDROID_NDK_FILENAME = android - ndk - $ ANDROID_NDK_RELEASE - darwin - x86_64 . zip <nl> + ANDROID_NDK_URL = $ ANDROID_BASE_URL / $ ANDROID_NDK_FILENAME <nl> + ANDROID_NDK_PATH = $ GODOT_BUILD_TOOLS_PATH / $ ANDROID_NDK_DIR <nl> + ANDROID_NDK_SHA1 = ea4b5d76475db84745aa8828000d009625fc1f98 <nl> + <nl> + echo <nl> + echo " Download and install Android development tools . . . " <nl> + echo <nl> + <nl> + if [ ! - e $ ANDROID_SDK_FILENAME ] ; then <nl> + echo " Downloading : Android SDK . . . " <nl> + curl - L - O $ ANDROID_SDK_URL <nl> + else <nl> + echo $ ANDROID_SDK_SHA1 $ ANDROID_SDK_FILENAME > $ ANDROID_SDK_FILENAME . sha1 <nl> + if [ $ ( shasum - a 256 < $ ANDROID_SDK_FILENAME | awk ' { print $ 1 ; } ' ) ! = $ ANDROID_SDK_SHA1 ] ; then <nl> + echo " Downloading : Android SDK . . . " <nl> + curl - L - O $ ANDROID_SDK_URL <nl> + fi <nl> + fi <nl> + <nl> + if [ ! - d $ ANDROID_SDK_DIR ] ; then <nl> + echo " Extracting : Android SDK . . . " <nl> + mkdir - p $ ANDROID_SDK_DIR & & tar - xf $ ANDROID_SDK_FILENAME - C $ ANDROID_SDK_DIR <nl> + echo <nl> + fi <nl> + <nl> + if [ ! - e $ ANDROID_NDK_FILENAME ] ; then <nl> + echo " Downloading : Android NDK . . . " <nl> + curl - L - O $ ANDROID_NDK_URL <nl> + else <nl> + echo $ ANDROID_NDK_MD5 $ ANDROID_NDK_FILENAME > $ ANDROID_NDK_FILENAME . md5 <nl> + if [ $ ( shasum - a 1 < $ ANDROID_NDK_FILENAME | awk ' { print $ 1 ; } ' ) ! = $ ANDROID_NDK_SHA1 ] ; then <nl> + echo " Downloading : Android NDK . . . " <nl> + curl - L - O $ ANDROID_NDK_URL <nl> + fi <nl> + fi <nl> + <nl> + if [ ! - d $ ANDROID_NDK_DIR ] ; then <nl> + echo " Extracting : Android NDK . . . " <nl> + tar - xf $ ANDROID_NDK_FILENAME <nl> + mv android - ndk - $ ANDROID_NDK_RELEASE $ ANDROID_NDK_DIR <nl> + echo <nl> + fi <nl> + <nl> + echo " Installing : Android Tools . . . " <nl> + # $ ANDROID_SDK_DIR / tools / bin / sdkmanager - - all <nl> + yes | $ ANDROID_SDK_DIR / tools / bin / sdkmanager - - licenses > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' tools ' > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' platform - tools ' > / dev / null <nl> + $ ANDROID_SDK_DIR / tools / bin / sdkmanager ' build - tools ; 26 . 0 . 2 ' > / dev / null <nl> + echo <nl> + <nl> + EXPORT_VAL = " export ANDROID_HOME = $ ANDROID_SDK_PATH " <nl> + if ! grep - q " ^ $ EXPORT_VAL " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export ANDROID_NDK_ROOT = $ ANDROID_NDK_PATH " <nl> + if ! grep - q " ^ $ EXPORT_VAL " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export PATH = $ PATH : $ ANDROID_SDK_PATH / tools " <nl> + if ! grep - q " ^ export PATH = . * $ ANDROID_SDK_PATH / tools . * " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + EXPORT_VAL = " export PATH = $ PATH : $ ANDROID_SDK_PATH / tools / bin " <nl> + if ! grep - q " ^ export PATH = . * $ ANDROID_SDK_PATH / tools / bin . * " $ BASH_RC ; then <nl> + echo $ EXPORT_VAL > > $ BASH_RC <nl> + fi <nl> + # eval $ EXPORT_VAL <nl> + <nl> + echo <nl> + echo " Done ! " <nl> + echo <nl> new file mode 100755 <nl> index 00000000000 . . 5ce7a80cbc0 <nl> mmm / dev / null <nl> ppp b / misc / travis / ccache - osx . sh <nl> <nl> + # ! / bin / bash <nl> + <nl> + echo <nl> + echo " Download and install ccache . . . " <nl> + echo <nl> + <nl> + echo " Downloading sources . . . " <nl> + curl - L - O https : / / www . samba . org / ftp / ccache / ccache - 3 . 3 . 4 . tar . gz # latest version available here : https : / / ccache . samba . org / download . html <nl> + <nl> + echo " Extracting to build directory . . . " <nl> + tar xzf ccache - 3 . 3 . 4 . tar . gz <nl> + cd ccache - 3 . 3 . 4 <nl> + <nl> + echo " Compiling sources . . . " <nl> + . / configure - - prefix = / usr / local - - with - bundled - zlib > / dev / null <nl> + make <nl> + <nl> + echo " Installing . . . " <nl> + <nl> + mkdir / usr / local / opt / ccache <nl> + <nl> + mkdir / usr / local / opt / ccache / bin <nl> + cp ccache / usr / local / opt / ccache / bin <nl> + ln - s / usr / local / opt / ccache / bin / ccache / usr / local / bin / ccache <nl> + <nl> + mkdir / usr / local / opt / ccache / libexec <nl> + links = ( <nl> + clang <nl> + clang + + <nl> + cc <nl> + gcc gcc2 gcc3 gcc - 3 . 3 gcc - 4 . 0 gcc - 4 . 2 gcc - 4 . 3 gcc - 4 . 4 gcc - 4 . 5 gcc - 4 . 6 gcc - 4 . 7 gcc - 4 . 8 gcc - 4 . 9 gcc - 5 gcc - 6 gcc - 7 <nl> + c + + c + + 3 c + + - 3 . 3 c + + - 4 . 0 c + + - 4 . 2 c + + - 4 . 3 c + + - 4 . 4 c + + - 4 . 5 c + + - 4 . 6 c + + - 4 . 7 c + + - 4 . 8 c + + - 4 . 9 c + + - 5 c + + - 6 c + + - 7 <nl> + g + + g + + 2 g + + 3 g + + - 3 . 3 g + + - 4 . 0 g + + - 4 . 2 g + + - 4 . 3 g + + - 4 . 4 g + + - 4 . 5 g + + - 4 . 6 g + + - 4 . 7 g + + - 4 . 8 g + + - 4 . 9 g + + - 5 g + + - 6 g + + - 7 <nl> + ) <nl> + for link in " $ { links [ @ ] } " ; do <nl> + ln - s . . / bin / ccache / usr / local / opt / ccache / libexec / $ link <nl> + done <nl> + # / usr / local / bin / ccache - M 2G <nl> + cd $ TRAVIS_BUILD_DIR <nl> + <nl> + echo <nl> + echo " Done ! " <nl> + echo <nl> new file mode 100755 <nl> index 00000000000 . . d9d7d98b389 <nl> mmm / dev / null <nl> ppp b / misc / travis / scons - local - osx . sh <nl> <nl> + # ! / bin / bash <nl> + <nl> + echo <nl> + echo " Download and install Scons local package . . . " <nl> + echo <nl> + <nl> + echo " Downloading sources . . . " <nl> + curl - L - O http : / / prdownloads . sourceforge . net / scons / scons - local - 3 . 0 . 0 . zip # latest version available here : http : / / scons . org / pages / download . html <nl> + <nl> + echo " Extracting to build directory . . . " <nl> + unzip - qq - n scons - local - 3 . 0 . 0 . zip - d $ TRAVIS_BUILD_DIR / scons - local <nl> + <nl> + echo " Installing symlinks . . . " <nl> + ln - s $ TRAVIS_BUILD_DIR / scons - local / scons . py / usr / local / bin / scons <nl> + <nl> + echo <nl> + echo " Done ! " <nl> + echo <nl> mmm a / platform / android / detect . py <nl> ppp b / platform / android / detect . py <nl> def mySpawn ( sh , escape , cmd , args , env ) : <nl> # For Clang to find NDK tools in preference of those system - wide <nl> env . PrependENVPath ( ' PATH ' , tools_path ) <nl> <nl> - env [ ' CC ' ] = compiler_path + ' / clang ' <nl> - env [ ' CXX ' ] = compiler_path + ' / clang + + ' <nl> + ccache_path = os . environ . get ( " CCACHE " ) <nl> + if ccache_path = = None : <nl> + env [ ' CC ' ] = compiler_path + ' / clang ' <nl> + env [ ' CXX ' ] = compiler_path + ' / clang + + ' <nl> + else : <nl> + # there aren ' t any ccache wrappers available for Android , <nl> + # to enable caching we need to prepend the path to the ccache binary <nl> + env [ ' CC ' ] = ccache_path + ' ' + compiler_path + ' / clang ' <nl> + env [ ' CXX ' ] = ccache_path + ' ' + compiler_path + ' / clang + + ' <nl> env [ ' AR ' ] = tools_path + " / ar " <nl> env [ ' RANLIB ' ] = tools_path + " / ranlib " <nl> env [ ' AS ' ] = tools_path + " / as " <nl> mmm a / platform / iphone / detect . py <nl> ppp b / platform / iphone / detect . py <nl> def configure ( env ) : <nl> <nl> env [ ' ENV ' ] [ ' PATH ' ] = env [ ' IPHONEPATH ' ] + " / Developer / usr / bin / : " + env [ ' ENV ' ] [ ' PATH ' ] <nl> <nl> - env [ ' CC ' ] = ' $ IPHONEPATH / usr / bin / $ { ios_triple } clang ' <nl> - env [ ' CXX ' ] = ' $ IPHONEPATH / usr / bin / $ { ios_triple } clang + + ' <nl> - env [ ' AR ' ] = ' $ IPHONEPATH / usr / bin / $ { ios_triple } ar ' <nl> - env [ ' RANLIB ' ] = ' $ IPHONEPATH / usr / bin / $ { ios_triple } ranlib ' <nl> - env [ ' S_compiler ' ] = ' $ IPHONEPATH / Developer / usr / bin / gcc ' <nl> + compiler_path = ' $ IPHONEPATH / usr / bin / $ { ios_triple } ' <nl> + s_compiler_path = ' $ IPHONEPATH / Developer / usr / bin / ' <nl> + <nl> + ccache_path = os . environ . get ( " CCACHE " ) <nl> + if ccache_path = = None : <nl> + env [ ' CC ' ] = compiler_path + ' clang ' <nl> + env [ ' CXX ' ] = compiler_path + ' clang + + ' <nl> + env [ ' S_compiler ' ] = s_compiler_path + ' gcc ' <nl> + else : <nl> + # there aren ' t any ccache wrappers available for iOS , <nl> + # to enable caching we need to prepend the path to the ccache binary <nl> + env [ ' CC ' ] = ccache_path + ' ' + compiler_path + ' clang ' <nl> + env [ ' CXX ' ] = ccache_path + ' ' + compiler_path + ' clang + + ' <nl> + env [ ' S_compiler ' ] = ccache_path + ' ' + s_compiler_path + ' gcc ' <nl> + env [ ' AR ' ] = compiler_path + ' ar ' <nl> + env [ ' RANLIB ' ] = compiler_path + ' ranlib ' <nl> <nl> # # Compile flags <nl> <nl> mmm a / platform / osx / detect . py <nl> ppp b / platform / osx / detect . py <nl> def configure ( env ) : <nl> else : # 64 - bit , default <nl> basecmd = root + " / target / bin / x86_64 - apple - " + env [ " osxcross_sdk " ] + " - " <nl> <nl> - env [ ' CC ' ] = basecmd + " cc " <nl> - env [ ' CXX ' ] = basecmd + " c + + " <nl> + ccache_path = os . environ . get ( " CCACHE " ) <nl> + if ccache_path = = None : <nl> + env [ ' CC ' ] = basecmd + " cc " <nl> + env [ ' CXX ' ] = basecmd + " c + + " <nl> + else : <nl> + # there aren ' t any ccache wrappers available for OS X cross - compile , <nl> + # to enable caching we need to prepend the path to the ccache binary <nl> + env [ ' CC ' ] = ccache_path + ' ' + basecmd + " cc " <nl> + env [ ' CXX ' ] = ccache_path + ' ' + basecmd + " c + + " <nl> env [ ' AR ' ] = basecmd + " ar " <nl> env [ ' RANLIB ' ] = basecmd + " ranlib " <nl> env [ ' AS ' ] = basecmd + " as " <nl>
Merge pull request from rraallvv / osx_android_travis
godotengine/godot
ba7e00dfef30573a9bc8b25cb51a86cd1eed4042
2017-11-13T20:44:23Z
mmm a / fdbserver / DBCoreState . h <nl> ppp b / fdbserver / DBCoreState . h <nl> struct CoreTLogSet { <nl> <nl> template < class Archive > <nl> void serialize ( Archive & ar ) { <nl> - if ( ar . isDeserializing & & ar . protocolVersion ( ) < 0x0FDB00B061030001LL ) { <nl> serializer ( ar , tLogs , tLogWriteAntiQuorum , tLogReplicationFactor , tLogPolicy , tLogLocalities , isLocal , locality , startVersion , satelliteTagLocations ) ; <nl> + if ( ar . isDeserializing & & ar . protocolVersion ( ) < 0x0FDB00B061030001LL ) { <nl> tLogVersion = TLogVersion : : V2 ; <nl> } else { <nl> - serializer ( ar , tLogs , tLogWriteAntiQuorum , tLogReplicationFactor , tLogPolicy , tLogLocalities , isLocal , locality , startVersion , satelliteTagLocations , tLogVersion ) ; <nl> + serializer ( ar , tLogVersion ) ; <nl> } <nl> } <nl> } ; <nl> mmm a / fdbserver / LogSystemConfig . h <nl> ppp b / fdbserver / LogSystemConfig . h <nl> struct TLogSet { <nl> <nl> template < class Ar > <nl> void serialize ( Ar & ar ) { <nl> + serializer ( ar , tLogs , logRouters , tLogWriteAntiQuorum , tLogReplicationFactor , tLogPolicy , tLogLocalities , isLocal , locality , startVersion , satelliteTagLocations ) ; <nl> if ( ar . isDeserializing & & ar . protocolVersion ( ) < 0x0FDB00B061030001LL ) { <nl> - serializer ( ar , tLogs , logRouters , tLogWriteAntiQuorum , tLogReplicationFactor , tLogPolicy , tLogLocalities , isLocal , locality , startVersion , satelliteTagLocations ) ; <nl> tLogVersion = TLogVersion : : V2 ; <nl> } else { <nl> - serializer ( ar , tLogs , logRouters , tLogWriteAntiQuorum , tLogReplicationFactor , tLogPolicy , tLogLocalities , isLocal , locality , startVersion , satelliteTagLocations , tLogVersion ) ; <nl> + serializer ( ar , tLogVersion ) ; <nl> } <nl> ASSERT ( tLogPolicy . getPtr ( ) = = nullptr | | tLogVersion ! = TLogVersion : : UNSET ) ; <nl> } <nl> mmm a / fdbserver / SimulatedCluster . actor . cpp <nl> ppp b / fdbserver / SimulatedCluster . actor . cpp <nl> void SimulationConfig : : generateNormalConfig ( int minimumReplication , int minimumR <nl> ASSERT ( false ) ; / / Programmer forgot to adjust cases . <nl> } <nl> <nl> - / / FIXME : test not setting log_spill . <nl> - if ( g_random - > random01 ( ) < 0 . 5 ) { <nl> - if ( g_random - > random01 ( ) < 0 . 5 ) { <nl> + int logSpillType = g_random - > randomInt ( 0 , 3 ) ; <nl> + switch ( logSpillType ) { <nl> + case 0 : <nl> + / / Let both be the default . <nl> + break ; <nl> + case 1 : { <nl> + set_config ( " log_spill : = 1 " ) ; / / VALUE <nl> + int logVersion = g_random - > randomInt ( 0 , 3 ) ; <nl> + switch ( logVersion ) { <nl> + case 0 : <nl> + break ; <nl> + case 1 : <nl> set_config ( " log_version : = 2 " ) ; / / 6 . 0 <nl> - } else { <nl> + break ; <nl> + case 2 : <nl> set_config ( " log_version : = 3 " ) ; / / 6 . 1 <nl> + break ; <nl> } <nl> - set_config ( " log_spill : = 1 " ) ; / / VALUE <nl> - } else { <nl> + break ; <nl> + } <nl> + case 2 : <nl> set_config ( " log_version : = 3 " ) ; / / 6 . 1 <nl> set_config ( " log_spill : = 2 " ) ; / / REFERENCE <nl> + break ; <nl> } <nl> <nl> if ( generateFearless | | ( datacenters = = 2 & & g_random - > random01 ( ) < 0 . 5 ) ) { <nl>
Let log_spill / log_version default in config , and clean up serialization .
apple/foundationdb
d4fe9f905c1e9b72b80d70316eacc1b1d426ee98
2019-02-27T01:14:41Z
mmm a / lib / AST / ASTDumper . cpp <nl> ppp b / lib / AST / ASTDumper . cpp <nl> class PrintExpr : public ExprVisitor < PrintExpr > { <nl> OS < < E - > getAccessSemantics ( ) ; <nl> if ( E - > isSuper ( ) ) <nl> OS < < " super " ; <nl> + if ( E - > hasDecl ( ) ) { <nl> + OS < < " decl = " ; <nl> + E - > getDecl ( ) . dump ( OS ) ; <nl> + } <nl> OS < < ' \ n ' ; <nl> printRec ( E - > getBase ( ) ) ; <nl> OS < < ' \ n ' ; <nl> mmm a / lib / Sema / CSRanking . cpp <nl> ppp b / lib / Sema / CSRanking . cpp <nl> SolutionCompareResult ConstraintSystem : : compareSolutions ( <nl> / / protocol members , let the checks below determine if the two choices are <nl> / / ' identical ' or not . This allows us to structurally unify disparate <nl> / / protocol members during overload resolution . <nl> + / / FIXME : Along with the FIXME below , this is a hack to work around <nl> + / / problems with restating requirements in protocols . <nl> + bool decl1InSubprotocol = false ; <nl> + bool decl2InSubprotocol = false ; <nl> if ( ( dc1 - > getContextKind ( ) = = DeclContextKind : : NominalTypeDecl ) & & <nl> ( dc1 - > getContextKind ( ) = = dc2 - > getContextKind ( ) ) ) { <nl> <nl> - auto ntd1 = dyn_cast < NominalTypeDecl > ( dc1 ) ; <nl> - auto ntd2 = dyn_cast < NominalTypeDecl > ( dc2 ) ; <nl> - <nl> - identical = ( ntd1 ! = ntd2 ) & & <nl> - ( ntd1 - > getKind ( ) = = DeclKind : : Protocol ) & & <nl> - ( ntd2 - > getKind ( ) = = DeclKind : : Protocol ) ; <nl> + auto ntd1 = dyn_cast < NominalTypeDecl > ( dc1 ) ; <nl> + auto ntd2 = dyn_cast < NominalTypeDecl > ( dc2 ) ; <nl> <nl> + identical = ( ntd1 ! = ntd2 ) & & <nl> + ( ntd1 - > getKind ( ) = = DeclKind : : Protocol ) & & <nl> + ( ntd2 - > getKind ( ) = = DeclKind : : Protocol ) ; <nl> + <nl> + / / FIXME : This hack tells us to prefer members of subprotocols over <nl> + / / those of the protocols they inherit , if all else fails . <nl> + / / If we were properly handling overrides of protocol members when <nl> + / / requirements get restated , it would not be necessary . <nl> + if ( identical ) { <nl> + decl1InSubprotocol = cast < ProtocolDecl > ( ntd1 ) - > inheritsFrom ( <nl> + cast < ProtocolDecl > ( ntd2 ) ) ; <nl> + decl2InSubprotocol = cast < ProtocolDecl > ( ntd2 ) - > inheritsFrom ( <nl> + cast < ProtocolDecl > ( ntd1 ) ) ; <nl> + } <nl> } else { <nl> identical = false ; <nl> } <nl> SolutionCompareResult ConstraintSystem : : compareSolutions ( <nl> } <nl> } <nl> <nl> + / / FIXME : The rest of the hack for restating requirements . <nl> + if ( ! ( foundRefinement1 & & foundRefinement2 ) ) { <nl> + if ( identical & & decl1InSubprotocol ! = decl2InSubprotocol ) { <nl> + foundRefinement1 = decl1InSubprotocol ; <nl> + foundRefinement2 = decl2InSubprotocol ; <nl> + } <nl> + } <nl> + <nl> / / FIXME : Lousy hack for ? ? to prefer the catamorphism ( flattening ) <nl> / / over the mplus ( non - flattening ) overload if all else is equal . <nl> if ( decl1 - > getName ( ) . str ( ) = = " ? ? " ) { <nl> mmm a / test / decl / protocol / protocol_overload_selection . swift <nl> ppp b / test / decl / protocol / protocol_overload_selection . swift <nl> C : MutableCollectionType <nl> ) { <nl> var _ : C . Generator . Element = elements [ i ] / / should not error <nl> } <nl> + <nl> + / / rdar : / / problem / 21322215 <nl> + protocol FactoryType { <nl> + typealias Item <nl> + } <nl> + <nl> + protocol MyCollectionType : Swift . CollectionType { } <nl> + <nl> + struct TestClass < <nl> + Factory : FactoryType , <nl> + NodeCollection : MyCollectionType <nl> + where <nl> + NodeCollection . Generator . Element = = Factory . Item <nl> + > { <nl> + var flattenedNodes : NodeCollection <nl> + <nl> + func test ( ) { <nl> + let node1 = self . flattenedNodes [ self . flattenedNodes . startIndex ] <nl> + let typecheck1 : NodeCollection . Generator . Element = node1 <nl> + _ = typecheck1 <nl> + } <nl> + } <nl>
Extend the heinous hack for overloading with redeclared protocol requirements .
apple/swift
bd891ea8f3fa64c9380d6d4dc7b0c0b107d3f115
2015-06-29T19:54:32Z
mmm a / src / mongo / db / concurrency / locker_noop . h <nl> ppp b / src / mongo / db / concurrency / locker_noop . h <nl> class LockerNoop : public Locker { <nl> LockMode mode , <nl> unsigned timeoutMs , <nl> bool checkDeadlock ) { <nl> - invariant ( false ) ; <nl> + return LockResult : : LOCK_OK ; <nl> } <nl> <nl> virtual void downgrade ( ResourceId resId , LockMode newMode ) { <nl> class LockerNoop : public Locker { <nl> } <nl> <nl> virtual bool unlock ( ResourceId resId ) { <nl> - invariant ( false ) ; <nl> + return true ; <nl> } <nl> <nl> virtual LockMode getLockMode ( ResourceId resId ) const { <nl> mmm a / src / mongo / db / storage / README . md <nl> ppp b / src / mongo / db / storage / README . md <nl> details . <nl> <nl> * [ KVEngine ] ( kv / kv_engine . h ) <nl> * [ RecordStore ] ( record_store . h ) <nl> - * [ RecoveryUnit ] ( ecovery_unit . h ) <nl> + * [ RecoveryUnit ] ( recovery_unit . h ) <nl> * [ SeekableRecordCursor ] ( record_store . h ) <nl> * [ SortedDataInterface ] ( sorted_data_interface . h ) <nl> * [ ServerStatusSection ] ( . . / commands / server_status . h ) <nl> mmm a / src / mongo / db / storage / ephemeral_for_test / SConscript <nl> ppp b / src / mongo / db / storage / ephemeral_for_test / SConscript <nl> env . Library ( <nl> ] , <nl> LIBDEPS = [ <nl> ' $ BUILD_DIR / mongo / base ' , <nl> + ' $ BUILD_DIR / mongo / db / concurrency / lock_manager ' , <nl> ' $ BUILD_DIR / mongo / db / storage / oplog_hack ' , <nl> ] <nl> ) <nl> mmm a / src / mongo / db / storage / ephemeral_for_test / ephemeral_for_test_record_store . cpp <nl> ppp b / src / mongo / db / storage / ephemeral_for_test / ephemeral_for_test_record_store . cpp <nl> <nl> <nl> # include " mongo / db / storage / ephemeral_for_test / ephemeral_for_test_record_store . h " <nl> <nl> - <nl> # include " mongo / db / jsobj . h " <nl> # include " mongo / db / namespace_string . h " <nl> # include " mongo / db / operation_context . h " <nl> using std : : shared_ptr ; <nl> <nl> class EphemeralForTestRecordStore : : InsertChange : public RecoveryUnit : : Change { <nl> public : <nl> - InsertChange ( Data * data , RecordId loc ) : _data ( data ) , _loc ( loc ) { } <nl> + InsertChange ( OperationContext * opCtx , Data * data , RecordId loc ) <nl> + : _opCtx ( opCtx ) , _data ( data ) , _loc ( loc ) { } <nl> virtual void commit ( ) { } <nl> virtual void rollback ( ) { <nl> + Lock : : ExclusiveLock lk ( _opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> Records : : iterator it = _data - > records . find ( _loc ) ; <nl> if ( it ! = _data - > records . end ( ) ) { <nl> _data - > dataSize - = it - > second . size ; <nl> class EphemeralForTestRecordStore : : InsertChange : public RecoveryUnit : : Change { <nl> } <nl> <nl> private : <nl> + OperationContext * _opCtx ; <nl> Data * const _data ; <nl> const RecordId _loc ; <nl> } ; <nl> class EphemeralForTestRecordStore : : InsertChange : public RecoveryUnit : : Change { <nl> / / Works for both removes and updates <nl> class EphemeralForTestRecordStore : : RemoveChange : public RecoveryUnit : : Change { <nl> public : <nl> - RemoveChange ( Data * data , RecordId loc , const EphemeralForTestRecord & rec ) <nl> - : _data ( data ) , _loc ( loc ) , _rec ( rec ) { } <nl> + RemoveChange ( OperationContext * opCtx , <nl> + Data * data , <nl> + RecordId loc , <nl> + const EphemeralForTestRecord & rec ) <nl> + : _opCtx ( opCtx ) , _data ( data ) , _loc ( loc ) , _rec ( rec ) { } <nl> <nl> virtual void commit ( ) { } <nl> virtual void rollback ( ) { <nl> + Lock : : ExclusiveLock lk ( _opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> Records : : iterator it = _data - > records . find ( _loc ) ; <nl> if ( it ! = _data - > records . end ( ) ) { <nl> _data - > dataSize - = it - > second . size ; <nl> class EphemeralForTestRecordStore : : RemoveChange : public RecoveryUnit : : Change { <nl> } <nl> <nl> private : <nl> + OperationContext * _opCtx ; <nl> Data * const _data ; <nl> const RecordId _loc ; <nl> const EphemeralForTestRecord _rec ; <nl> class EphemeralForTestRecordStore : : RemoveChange : public RecoveryUnit : : Change { <nl> <nl> class EphemeralForTestRecordStore : : TruncateChange : public RecoveryUnit : : Change { <nl> public : <nl> - TruncateChange ( Data * data ) : _data ( data ) , _dataSize ( 0 ) { <nl> + TruncateChange ( OperationContext * opCtx , Data * data ) : _opCtx ( opCtx ) , _data ( data ) , _dataSize ( 0 ) { <nl> using std : : swap ; <nl> + <nl> + Lock : : ExclusiveLock lk ( _opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> swap ( _dataSize , _data - > dataSize ) ; <nl> swap ( _records , _data - > records ) ; <nl> } <nl> class EphemeralForTestRecordStore : : TruncateChange : public RecoveryUnit : : Change <nl> virtual void commit ( ) { } <nl> virtual void rollback ( ) { <nl> using std : : swap ; <nl> + <nl> + Lock : : ExclusiveLock lk ( _opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> swap ( _dataSize , _data - > dataSize ) ; <nl> swap ( _records , _data - > records ) ; <nl> } <nl> <nl> private : <nl> + OperationContext * _opCtx ; <nl> Data * const _data ; <nl> int64_t _dataSize ; <nl> Records _records ; <nl> EphemeralForTestRecordStore : : EphemeralForTestRecordStore ( StringData ns , <nl> _cappedMaxDocs ( cappedMaxDocs ) , <nl> _cappedCallback ( cappedCallback ) , <nl> _data ( * dataInOut ? static_cast < Data * > ( dataInOut - > get ( ) ) <nl> - : new Data ( NamespaceString : : oplog ( ns ) ) ) { <nl> + : new Data ( ns , NamespaceString : : oplog ( ns ) ) ) { <nl> if ( ! * dataInOut ) { <nl> dataInOut - > reset ( _data ) ; / / takes ownership <nl> } <nl> const char * EphemeralForTestRecordStore : : name ( ) const { <nl> <nl> RecordData EphemeralForTestRecordStore : : dataFor ( OperationContext * opCtx , <nl> const RecordId & loc ) const { <nl> + Lock : : SharedLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> return recordFor ( loc ) - > toRecordData ( ) ; <nl> } <nl> <nl> EphemeralForTestRecordStore : : EphemeralForTestRecord * EphemeralForTestRecordStore <nl> bool EphemeralForTestRecordStore : : findRecord ( OperationContext * opCtx , <nl> const RecordId & loc , <nl> RecordData * rd ) const { <nl> + Lock : : SharedLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> Records : : const_iterator it = _data - > records . find ( loc ) ; <nl> if ( it = = _data - > records . end ( ) ) { <nl> return false ; <nl> bool EphemeralForTestRecordStore : : findRecord ( OperationContext * opCtx , <nl> } <nl> <nl> void EphemeralForTestRecordStore : : deleteRecord ( OperationContext * opCtx , const RecordId & loc ) { <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> EphemeralForTestRecord * rec = recordFor ( loc ) ; <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( _data , loc , * rec ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( opCtx , _data , loc , * rec ) ) ; <nl> _data - > dataSize - = rec - > size ; <nl> invariant ( _data - > records . erase ( loc ) = = 1 ) ; <nl> } <nl> StatusWith < RecordId > EphemeralForTestRecordStore : : insertRecord ( OperationContext * <nl> return StatusWith < RecordId > ( ErrorCodes : : BadValue , " object to insert exceeds cappedMaxSize " ) ; <nl> } <nl> <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> EphemeralForTestRecord rec ( len ) ; <nl> memcpy ( rec . data . get ( ) , data , len ) ; <nl> <nl> StatusWith < RecordId > EphemeralForTestRecordStore : : insertRecord ( OperationContext * <nl> loc = allocateLoc ( ) ; <nl> } <nl> <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new InsertChange ( _data , loc ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new InsertChange ( opCtx , _data , loc ) ) ; <nl> _data - > dataSize + = len ; <nl> _data - > records [ loc ] = rec ; <nl> <nl> Status EphemeralForTestRecordStore : : insertRecordsWithDocWriter ( OperationContext * <nl> const DocWriter * const * docs , <nl> size_t nDocs , <nl> RecordId * idsOut ) { <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> for ( size_t i = 0 ; i < nDocs ; i + + ) { <nl> const int len = docs [ i ] - > documentSize ( ) ; <nl> if ( _isCapped & & len > _cappedMaxSize ) { <nl> Status EphemeralForTestRecordStore : : insertRecordsWithDocWriter ( OperationContext * <nl> loc = allocateLoc ( ) ; <nl> } <nl> <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new InsertChange ( _data , loc ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new InsertChange ( opCtx , _data , loc ) ) ; <nl> _data - > dataSize + = len ; <nl> _data - > records [ loc ] = rec ; <nl> <nl> Status EphemeralForTestRecordStore : : updateRecord ( OperationContext * opCtx , <nl> int len , <nl> bool enforceQuota , <nl> UpdateNotifier * notifier ) { <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> EphemeralForTestRecord * oldRecord = recordFor ( loc ) ; <nl> int oldLen = oldRecord - > size ; <nl> <nl> Status EphemeralForTestRecordStore : : updateRecord ( OperationContext * opCtx , <nl> EphemeralForTestRecord newRecord ( len ) ; <nl> memcpy ( newRecord . data . get ( ) , data , len ) ; <nl> <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( _data , loc , * oldRecord ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( opCtx , _data , loc , * oldRecord ) ) ; <nl> _data - > dataSize + = len - oldLen ; <nl> * oldRecord = newRecord ; <nl> <nl> StatusWith < RecordData > EphemeralForTestRecordStore : : updateWithDamages ( <nl> const RecordData & oldRec , <nl> const char * damageSource , <nl> const mutablebson : : DamageVector & damages ) { <nl> + <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> EphemeralForTestRecord * oldRecord = recordFor ( loc ) ; <nl> const int len = oldRecord - > size ; <nl> <nl> EphemeralForTestRecord newRecord ( len ) ; <nl> memcpy ( newRecord . data . get ( ) , oldRecord - > data . get ( ) , len ) ; <nl> <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( _data , loc , * oldRecord ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( opCtx , _data , loc , * oldRecord ) ) ; <nl> * oldRecord = newRecord ; <nl> <nl> cappedDeleteAsNeeded ( opCtx ) ; <nl> std : : unique_ptr < SeekableRecordCursor > EphemeralForTestRecordStore : : getCursor ( <nl> Status EphemeralForTestRecordStore : : truncate ( OperationContext * opCtx ) { <nl> / / Unlike other changes , TruncateChange mutates _data on construction to perform the <nl> / / truncate <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new TruncateChange ( _data ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( new TruncateChange ( opCtx , _data ) ) ; <nl> return Status : : OK ( ) ; <nl> } <nl> <nl> void EphemeralForTestRecordStore : : cappedTruncateAfter ( OperationContext * opCtx , <nl> RecordId end , <nl> bool inclusive ) { <nl> + Lock : : ExclusiveLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> Records : : iterator it = <nl> inclusive ? _data - > records . lower_bound ( end ) : _data - > records . upper_bound ( end ) ; <nl> while ( it ! = _data - > records . end ( ) ) { <nl> - opCtx - > recoveryUnit ( ) - > registerChange ( new RemoveChange ( _data , it - > first , it - > second ) ) ; <nl> + opCtx - > recoveryUnit ( ) - > registerChange ( <nl> + new RemoveChange ( opCtx , _data , it - > first , it - > second ) ) ; <nl> _data - > dataSize - = it - > second . size ; <nl> _data - > records . erase ( it + + ) ; <nl> } <nl> Status EphemeralForTestRecordStore : : validate ( OperationContext * opCtx , <nl> ValidateAdaptor * adaptor , <nl> ValidateResults * results , <nl> BSONObjBuilder * output ) { <nl> + Lock : : SharedLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> + <nl> results - > valid = true ; <nl> if ( level = = kValidateFull ) { <nl> for ( Records : : const_iterator it = _data - > records . begin ( ) ; it ! = _data - > records . end ( ) ; <nl> boost : : optional < RecordId > EphemeralForTestRecordStore : : oplogStartHack ( <nl> if ( ! _data - > isOplog ) <nl> return boost : : none ; <nl> <nl> + Lock : : SharedLock lk ( opCtx - > lockState ( ) , _data - > recordsMutex ) ; <nl> const Records & records = _data - > records ; <nl> <nl> if ( records . empty ( ) ) <nl> mmm a / src / mongo / db / storage / ephemeral_for_test / ephemeral_for_test_record_store . h <nl> ppp b / src / mongo / db / storage / ephemeral_for_test / ephemeral_for_test_record_store . h <nl> <nl> # include < boost / shared_array . hpp > <nl> # include < map > <nl> <nl> + # include " mongo / db / concurrency / d_concurrency . h " <nl> # include " mongo / db / storage / capped_callback . h " <nl> # include " mongo / db / storage / record_store . h " <nl> <nl> class EphemeralForTestRecordStore : public RecordStore { <nl> <nl> / / This is the " persistent " data . <nl> struct Data { <nl> - Data ( bool isOplog ) : dataSize ( 0 ) , nextId ( 1 ) , isOplog ( isOplog ) { } <nl> + Data ( StringData ns , bool isOplog ) <nl> + : dataSize ( 0 ) , <nl> + recordsMutex ( str : : stream ( ) < < " recordsMutex_ " < < ns ) , <nl> + nextId ( 1 ) , <nl> + isOplog ( isOplog ) { } <nl> <nl> int64_t dataSize ; <nl> + Lock : : ResourceMutex recordsMutex ; <nl> Records records ; <nl> int64_t nextId ; <nl> const bool isOplog ; <nl> mmm a / src / mongo / db / storage / kv / kv_catalog . cpp <nl> ppp b / src / mongo / db / storage / kv / kv_catalog . cpp <nl> namespace { <nl> / / This is a global resource , which protects accesses to the catalog metadata ( instance - wide ) . <nl> / / It is never used with KVEngines that support doc - level locking so this should never conflict <nl> / / with anything else . <nl> - / / <nl> - / / NOTE : Must be locked * before * _identLock . <nl> - const ResourceId resourceIdCatalogMetadata ( RESOURCE_METADATA , 1ULL ) ; <nl> <nl> const char kIsFeatureDocumentFieldName [ ] = " isFeatureDoc " ; <nl> const char kNamespaceFieldName [ ] = " ns " ; <nl> bool KVCatalog : : FeatureTracker : : isFeatureDocument ( BSONObj obj ) { <nl> } <nl> <nl> Status KVCatalog : : FeatureTracker : : isCompatibleWithCurrentCode ( OperationContext * opCtx ) const { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk = stdx : : make_unique < Lock : : ResourceLock > ( <nl> - opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_S ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> <nl> uint64_t unrecognizedNonRepairableFeatures = <nl> std : : unique_ptr < KVCatalog : : FeatureTracker > KVCatalog : : FeatureTracker : : create ( <nl> <nl> bool KVCatalog : : FeatureTracker : : isNonRepairableFeatureInUse ( OperationContext * opCtx , <nl> NonRepairableFeature feature ) const { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_S ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> return versionInfo . nonRepairableFeatures & static_cast < NonRepairableFeatureMask > ( feature ) ; <nl> } <nl> <nl> void KVCatalog : : FeatureTracker : : markNonRepairableFeatureAsInUse ( OperationContext * opCtx , <nl> NonRepairableFeature feature ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> versionInfo . nonRepairableFeatures | = static_cast < NonRepairableFeatureMask > ( feature ) ; <nl> putInfo ( opCtx , versionInfo ) ; <nl> void KVCatalog : : FeatureTracker : : markNonRepairableFeatureAsInUse ( OperationContext <nl> <nl> void KVCatalog : : FeatureTracker : : markNonRepairableFeatureAsNotInUse ( OperationContext * opCtx , <nl> NonRepairableFeature feature ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> versionInfo . nonRepairableFeatures & = ~ static_cast < NonRepairableFeatureMask > ( feature ) ; <nl> putInfo ( opCtx , versionInfo ) ; <nl> void KVCatalog : : FeatureTracker : : markNonRepairableFeatureAsNotInUse ( OperationCont <nl> <nl> bool KVCatalog : : FeatureTracker : : isRepairableFeatureInUse ( OperationContext * opCtx , <nl> RepairableFeature feature ) const { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_S ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> return versionInfo . repairableFeatures & static_cast < RepairableFeatureMask > ( feature ) ; <nl> } <nl> <nl> void KVCatalog : : FeatureTracker : : markRepairableFeatureAsInUse ( OperationContext * opCtx , <nl> RepairableFeature feature ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> versionInfo . repairableFeatures | = static_cast < RepairableFeatureMask > ( feature ) ; <nl> putInfo ( opCtx , versionInfo ) ; <nl> void KVCatalog : : FeatureTracker : : markRepairableFeatureAsInUse ( OperationContext * o <nl> <nl> void KVCatalog : : FeatureTracker : : markRepairableFeatureAsNotInUse ( OperationContext * opCtx , <nl> RepairableFeature feature ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> FeatureBits versionInfo = getInfo ( opCtx ) ; <nl> versionInfo . repairableFeatures & = ~ static_cast < RepairableFeatureMask > ( feature ) ; <nl> putInfo ( opCtx , versionInfo ) ; <nl> void KVCatalog : : FeatureTracker : : markRepairableFeatureAsNotInUse ( OperationContext <nl> <nl> KVCatalog : : FeatureTracker : : FeatureBits KVCatalog : : FeatureTracker : : getInfo ( <nl> OperationContext * opCtx ) const { <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - invariant ( opCtx - > lockState ( ) - > isLockHeldForMode ( resourceIdCatalogMetadata , MODE_S ) ) ; <nl> - } <nl> - <nl> if ( _rid . isNull ( ) ) { <nl> return { } ; <nl> } <nl> KVCatalog : : FeatureTracker : : FeatureBits KVCatalog : : FeatureTracker : : getInfo ( <nl> } <nl> <nl> void KVCatalog : : FeatureTracker : : putInfo ( OperationContext * opCtx , const FeatureBits & versionInfo ) { <nl> - if ( ! _catalog - > _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - invariant ( opCtx - > lockState ( ) - > isLockHeldForMode ( resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> BSONObjBuilder bob ; <nl> bob . appendBool ( kIsFeatureDocumentFieldName , true ) ; <nl> / / We intentionally include the " ns " field with a null value in the feature document to prevent <nl> void KVCatalog : : FeatureTracker : : putInfo ( OperationContext * opCtx , const FeatureBi <nl> } <nl> } <nl> <nl> - KVCatalog : : KVCatalog ( RecordStore * rs , <nl> - bool isRsThreadSafe , <nl> - bool directoryPerDb , <nl> - bool directoryForIndexes ) <nl> + KVCatalog : : KVCatalog ( RecordStore * rs , bool directoryPerDb , bool directoryForIndexes ) <nl> : _rs ( rs ) , <nl> - _isRsThreadSafe ( isRsThreadSafe ) , <nl> _directoryPerDb ( directoryPerDb ) , <nl> _directoryForIndexes ( directoryForIndexes ) , <nl> _rand ( _newRand ( ) ) { } <nl> Status KVCatalog : : newCollection ( OperationContext * opCtx , <nl> invariant ( opCtx - > lockState ( ) = = NULL | | <nl> opCtx - > lockState ( ) - > isDbLockedForMode ( nsToDatabaseSubstring ( ns ) , MODE_X ) ) ; <nl> <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> const string ident = _newUniqueIdent ( ns , " collection " ) ; <nl> <nl> stdx : : lock_guard < stdx : : mutex > lk ( _identsLock ) ; <nl> std : : string KVCatalog : : getIndexIdent ( OperationContext * opCtx , <nl> } <nl> <nl> BSONObj KVCatalog : : _findEntry ( OperationContext * opCtx , StringData ns , RecordId * out ) const { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_S ) ) ; <nl> - } <nl> - <nl> RecordId dl ; <nl> { <nl> stdx : : lock_guard < stdx : : mutex > lk ( _identsLock ) ; <nl> const BSONCollectionCatalogEntry : : MetaData KVCatalog : : getMetaData ( OperationConte <nl> void KVCatalog : : putMetaData ( OperationContext * opCtx , <nl> StringData ns , <nl> BSONCollectionCatalogEntry : : MetaData & md ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> RecordId loc ; <nl> BSONObj obj = _findEntry ( opCtx , ns , & loc ) ; <nl> <nl> Status KVCatalog : : renameCollection ( OperationContext * opCtx , <nl> StringData fromNS , <nl> StringData toNS , <nl> bool stayTemp ) { <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> RecordId loc ; <nl> BSONObj old = _findEntry ( opCtx , fromNS , & loc ) . getOwned ( ) ; <nl> { <nl> Status KVCatalog : : renameCollection ( OperationContext * opCtx , <nl> Status KVCatalog : : dropCollection ( OperationContext * opCtx , StringData ns ) { <nl> invariant ( opCtx - > lockState ( ) = = NULL | | <nl> opCtx - > lockState ( ) - > isDbLockedForMode ( nsToDatabaseSubstring ( ns ) , MODE_X ) ) ; <nl> - std : : unique_ptr < Lock : : ResourceLock > rLk ; <nl> - if ( ! _isRsThreadSafe & & opCtx - > lockState ( ) ) { <nl> - rLk . reset ( new Lock : : ResourceLock ( opCtx - > lockState ( ) , resourceIdCatalogMetadata , MODE_X ) ) ; <nl> - } <nl> - <nl> stdx : : lock_guard < stdx : : mutex > lk ( _identsLock ) ; <nl> const NSToIdentMap : : iterator it = _idents . find ( ns . toString ( ) ) ; <nl> if ( it = = _idents . end ( ) ) { <nl> mmm a / src / mongo / db / storage / kv / kv_catalog . h <nl> ppp b / src / mongo / db / storage / kv / kv_catalog . h <nl> class KVCatalog { <nl> class FeatureTracker ; <nl> <nl> / * * <nl> - * @ param rs - does NOT take ownership <nl> + * @ param rs - does NOT take ownership . The RecordStore must be thread - safe , in particular <nl> + * with concurrent calls to RecordStore : : find , updateRecord , insertRecord , deleteRecord and <nl> + * dataFor . The KVCatalog does not utilize Cursors and those methods may omit further <nl> + * protection . <nl> * / <nl> - KVCatalog ( RecordStore * rs , bool isRsThreadSafe , bool directoryPerDb , bool directoryForIndexes ) ; <nl> + KVCatalog ( RecordStore * rs , bool directoryPerDb , bool directoryForIndexes ) ; <nl> ~ KVCatalog ( ) ; <nl> <nl> void init ( OperationContext * opCtx ) ; <nl> class KVCatalog { <nl> bool _hasEntryCollidingWithRand ( ) const ; <nl> <nl> RecordStore * _rs ; / / not owned <nl> - const bool _isRsThreadSafe ; <nl> const bool _directoryPerDb ; <nl> const bool _directoryForIndexes ; <nl> <nl> mmm a / src / mongo / db / storage / kv / kv_catalog_feature_tracker_test . cpp <nl> ppp b / src / mongo / db / storage / kv / kv_catalog_feature_tracker_test . cpp <nl> class KVCatalogFeatureTrackerTest : public unittest : : Test { <nl> wuow . commit ( ) ; <nl> } <nl> <nl> - _catalog = stdx : : make_unique < KVCatalog > ( _rs . get ( ) , true , false , false ) ; <nl> + _catalog = stdx : : make_unique < KVCatalog > ( _rs . get ( ) , false , false ) ; <nl> _catalog - > init ( opCtx . get ( ) ) ; <nl> <nl> { <nl> mmm a / src / mongo / db / storage / kv / kv_engine_test_harness . cpp <nl> ppp b / src / mongo / db / storage / kv / kv_engine_test_harness . cpp <nl> TEST ( KVCatalogTest , Coll1 ) { <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> ASSERT_OK ( engine - > createRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ) ; <nl> rs = engine - > getRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , false , false ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , false , false ) ) ; <nl> uow . commit ( ) ; <nl> } <nl> <nl> TEST ( KVCatalogTest , Coll1 ) { <nl> { <nl> MyOperationContext opCtx ( engine ) ; <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , false , false ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , false , false ) ) ; <nl> catalog - > init ( & opCtx ) ; <nl> uow . commit ( ) ; <nl> } <nl> TEST ( KVCatalogTest , Idx1 ) { <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> ASSERT_OK ( engine - > createRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ) ; <nl> rs = engine - > getRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , false , false ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , false , false ) ) ; <nl> uow . commit ( ) ; <nl> } <nl> <nl> TEST ( KVCatalogTest , DirectoryPerDb1 ) { <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> ASSERT_OK ( engine - > createRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ) ; <nl> rs = engine - > getRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , true , false ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , true , false ) ) ; <nl> uow . commit ( ) ; <nl> } <nl> <nl> TEST ( KVCatalogTest , Split1 ) { <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> ASSERT_OK ( engine - > createRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ) ; <nl> rs = engine - > getRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , false , true ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , false , true ) ) ; <nl> uow . commit ( ) ; <nl> } <nl> <nl> TEST ( KVCatalogTest , DirectoryPerAndSplit1 ) { <nl> WriteUnitOfWork uow ( & opCtx ) ; <nl> ASSERT_OK ( engine - > createRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ) ; <nl> rs = engine - > getRecordStore ( & opCtx , " catalog " , " catalog " , CollectionOptions ( ) ) ; <nl> - catalog . reset ( new KVCatalog ( rs . get ( ) , true , true , true ) ) ; <nl> + catalog . reset ( new KVCatalog ( rs . get ( ) , true , true ) ) ; <nl> uow . commit ( ) ; <nl> } <nl> <nl> mmm a / src / mongo / db / storage / kv / kv_storage_engine . cpp <nl> ppp b / src / mongo / db / storage / kv / kv_storage_engine . cpp <nl> KVStorageEngine : : KVStorageEngine ( <nl> <nl> _catalogRecordStore = <nl> _engine - > getRecordStore ( & opCtx , catalogInfo , catalogInfo , CollectionOptions ( ) ) ; <nl> - _catalog . reset ( new KVCatalog ( _catalogRecordStore . get ( ) , <nl> - _supportsDocLocking , <nl> - _options . directoryPerDB , <nl> - _options . directoryForIndexes ) ) ; <nl> + _catalog . reset ( new KVCatalog ( <nl> + _catalogRecordStore . get ( ) , _options . directoryPerDB , _options . directoryForIndexes ) ) ; <nl> _catalog - > init ( & opCtx ) ; <nl> <nl> std : : vector < std : : string > collections ; <nl> mmm a / src / mongo / db / storage / record_store . h <nl> ppp b / src / mongo / db / storage / record_store . h <nl> class SeekableRecordCursor : public RecordCursor { <nl> * Many methods take an OperationContext parameter . This contains the RecoveryUnit , with <nl> * all RecordStore specific transaction information , as well as the LockState . Methods that take <nl> * an OperationContext may throw a WriteConflictException . <nl> + * <nl> + * This class must be thread - safe for document - level locking storage engines . In addition , for <nl> + * storage engines implementing the KVEngine some methods must be thread safe , see KVCatalog . Only <nl> + * for MMAPv1 is this class not thread - safe . <nl> * / <nl> class RecordStore { <nl> MONGO_DISALLOW_COPYING ( RecordStore ) ; <nl>
SERVER - 27831 : Push threadsafety responsibility inside of KVCatalog ' s RecordStore
mongodb/mongo
71a149b45c8bb019cbc8179f4a411be66bda2062
2017-03-29T14:30:56Z
new file mode 100644 <nl> index 000000000 . . 3b5227544 <nl> mmm / dev / null <nl> ppp b / examples / serverkeepalive . js <nl> <nl> + var port , server , service ; <nl> + <nl> + if ( phantom . args . length ! = = 1 ) { <nl> + console . log ( ' Usage : serverkeepalive . js < portnumber > ' ) ; <nl> + phantom . exit ( ) ; <nl> + } else { <nl> + port = phantom . args [ 0 ] ; <nl> + server = require ( ' webserver ' ) . create ( ) ; <nl> + <nl> + service = server . listen ( port , { " keep - alive " : true } , function ( request , response ) { <nl> + console . log ( ' Request at ' + new Date ( ) ) ; <nl> + console . log ( JSON . stringify ( request , null , 4 ) ) ; <nl> + <nl> + var body = JSON . stringify ( request , null , 4 ) ; <nl> + response . statusCode = 200 ; <nl> + response . headers = { <nl> + ' Cache ' : ' no - cache ' , <nl> + ' Content - Type ' : ' text / plain ' , <nl> + ' Connection ' : ' Keep - Alive ' , <nl> + ' Keep - Alive ' : ' timeout = 5 , max = 100 ' , <nl> + ' Content - Length ' : body . length <nl> + } ; <nl> + response . write ( body ) ; <nl> + response . close ( ) ; <nl> + } ) ; <nl> + <nl> + if ( service ) { <nl> + console . log ( ' Web server running on port ' + port ) ; <nl> + } else { <nl> + console . log ( ' Error : Could not create web server listening on port ' + port ) ; <nl> + phantom . exit ( ) ; <nl> + } <nl> + } <nl>
Add example for keep - alive enabled webserver .
ariya/phantomjs
7b909bfe452cdb0329884ee7f6ea5e4d8711f7c5
2012-03-14T02:01:24Z
mmm a / tensorflow / compiler / mlir / tools / kernel_gen / ir / tf_framework_ops . h <nl> ppp b / tensorflow / compiler / mlir / tools / kernel_gen / ir / tf_framework_ops . h <nl> namespace tf_framework { <nl> <nl> namespace TFFrameworkTypes { <nl> enum Kind { <nl> - / / TODO ( pifon ) : Replace enum value with <nl> - / / OpKernelContextType = Type : : FIRST_TF_FRAMEWORK_TYPE , <nl> - / / after DialectSymbolRegistry . def is updated . <nl> - OpKernelContextType = Type : : FIRST_PRIVATE_EXPERIMENTAL_0_TYPE , <nl> + OpKernelContextType = Type : : FIRST_TF_FRAMEWORK_TYPE , <nl> } ; <nl> } / / namespace TFFrameworkTypes <nl> <nl>
[ MLIR ] [ KERNEL_GEN ] Use TF_FRAMEWORK_TYPE instead of PRIVATE_EXPERIMENTAL_0 .
tensorflow/tensorflow
4305e83f8cc65d9bf941b7136859fc9397368da6
2020-08-03T09:45:58Z
mmm a / CMakeLists . txt <nl> ppp b / CMakeLists . txt <nl> include ( CMakeDependentOption ) <nl> option ( BUILD_TORCH " Build Torch " OFF ) <nl> option ( ATEN_NO_TEST " Do not build ATen test binaries " OFF ) <nl> option ( BUILD_ATEN_MOBILE " Build ATen for Android and iOS " OFF ) <nl> + option ( BUILD_ATEN_ONLY " Build only a subset focused on ATen only " OFF ) <nl> option ( BUILD_BINARY " Build C + + binaries " OFF ) <nl> option ( BUILD_DOCS " Build Caffe2 documentation " OFF ) <nl> option ( BUILD_CUSTOM_PROTOBUF " Build and use Caffe2 ' s own protobuf under third_party " ON ) <nl> if ( ANDROID OR IOS ) <nl> set ( BUILD_ATEN_MOBILE ON ) <nl> endif ( ) <nl> <nl> + if ( BUILD_ATEN_ONLY ) <nl> + set ( BUILD_CAFFE2_OPS OFF ) <nl> + set ( BUILD_PYTHON OFF ) <nl> + set ( USE_NUMA OFF ) <nl> + set ( USE_LEVELDB OFF ) <nl> + set ( USE_GFLAGS OFF ) <nl> + set ( USE_GLOG OFF ) <nl> + set ( USE_NCCL OFF ) <nl> + set ( USE_NNPACK OFF ) <nl> + set ( USE_NUMPY OFF ) <nl> + set ( USE_OPENCV OFF ) <nl> + set ( USE_IDEEP OFF ) <nl> + set ( USE_MKLML OFF ) <nl> + set ( USE_DISTRIBUTED OFF ) <nl> + set ( USE_LMDB OFF ) <nl> + endif ( ) <nl> + <nl> # mmm [ Utils <nl> # TODO : merge the following 3 files into cmake / public / utils . cmake . <nl> include ( cmake / Utils . cmake ) <nl> if ( APPLE ) <nl> set ( CMAKE_CXX_FLAGS " $ { CMAKE_CXX_FLAGS } - Wno - constexpr - not - const " ) <nl> endif ( ) <nl> <nl> + if ( EMSCRIPTEN ) <nl> + set ( CMAKE_CXX_FLAGS " $ { CMAKE_CXX_FLAGS } - Wno - implicit - function - declaration - DEMSCRIPTEN - s DISABLE_EXCEPTION_CATCHING = 0 " ) <nl> + endif ( ) <nl> + <nl> if ( CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7 . 0 . 0 ) <nl> set ( CMAKE_CXX_FLAGS " $ { CMAKE_CXX_FLAGS } - Wno - stringop - overflow " ) <nl> endif ( ) <nl> mmm a / aten / src / ATen / core / Error . cpp <nl> ppp b / aten / src / ATen / core / Error . cpp <nl> std : : string GetExceptionString ( const std : : exception & e ) { <nl> # endif / / __GXX_RTTI <nl> } <nl> <nl> + std : : function < std : : string ( void ) > * GetFetchStackTrace ( ) { <nl> + static std : : function < std : : string ( void ) > func = [ ] ( ) { return " " ; } ; <nl> + return & func ; <nl> + } ; <nl> + <nl> + void ThrowEnforceNotMet ( <nl> + const char * file , <nl> + const int line , <nl> + const char * condition , <nl> + const std : : string & msg , <nl> + const void * caller ) <nl> + { <nl> + at : : Error e ( file , line , condition , msg , ( * GetFetchStackTrace ( ) ) ( ) , caller ) ; <nl> + throw e ; <nl> + } <nl> + <nl> } / / namespace at <nl> mmm a / aten / src / ATen / core / Error . h <nl> ppp b / aten / src / ATen / core / Error . h <nl> class CAFFE2_API Warning { <nl> / / exception type before its what ( ) content <nl> CAFFE2_API std : : string GetExceptionString ( const std : : exception & e ) ; <nl> <nl> + CAFFE2_API void ThrowEnforceNotMet ( <nl> + const char * file , <nl> + const int line , <nl> + const char * condition , <nl> + const std : : string & msg , <nl> + const void * caller ) ; <nl> + <nl> } / / namespace at <nl> <nl> / / TODO : variants that print the expression tested and thus don ' t require <nl> / / strings <nl> - / / TODO : CAFFE_ENFORCE_WITH_CALLER style macro <nl> + <nl> + # define AT_ENFORCE ( condition , . . . ) \ <nl> + do { \ <nl> + if ( ! ( condition ) ) { \ <nl> + at : : ThrowEnforceNotMet ( \ <nl> + __FILE__ , __LINE__ , # condition , at : : str ( __VA_ARGS__ ) , nullptr ) ; \ <nl> + } \ <nl> + } while ( false ) <nl> + <nl> + # define AT_ENFORCE_WITH_CALLER ( condition , . . . ) \ <nl> + do { \ <nl> + if ( ! ( condition ) ) { \ <nl> + at : : ThrowEnforceNotMet ( \ <nl> + __FILE__ , \ <nl> + __LINE__ , \ <nl> + # condition , \ <nl> + at : : str ( __VA_ARGS__ ) , \ <nl> + this ) ; \ <nl> + } \ <nl> + } while ( false ) <nl> + <nl> + # define AT_ENFORCE_GT ( x , y , . . . ) \ <nl> + AT_ENFORCE ( x > y , __VA_ARGS__ ) <nl> + <nl> + # define AT_ENFORCE_GE ( x , y , . . . ) \ <nl> + AT_ENFORCE ( x > = y , __VA_ARGS__ ) <nl> + <nl> + # define AT_ENFORCE_LT ( x , y , . . . ) \ <nl> + AT_ENFORCE ( x < y , __VA_ARGS__ ) <nl> + <nl> + # define AT_ENFORCE_GE_WITH_CALLER ( x , y , . . . ) \ <nl> + AT_ENFORCE_WITH_CALLER ( x > = y , __VA_ARGS__ ) <nl> + <nl> + # define AT_ENFORCE_EQ_WITH_CALLER ( x , y , . . . ) \ <nl> + AT_ENFORCE_WITH_CALLER ( x = = y , __VA_ARGS__ ) <nl> <nl> # define AT_ERROR ( . . . ) \ <nl> throw at : : Error ( { __func__ , __FILE__ , __LINE__ } , at : : str ( __VA_ARGS__ ) ) <nl> mmm a / aten / src / ATen / core / TensorImpl . h <nl> ppp b / aten / src / ATen / core / TensorImpl . h <nl> inline int64_t size_from_dim_ ( int k , IntList dims ) { <nl> <nl> / / Product of all dims up to k ( not including dims [ k ] ) <nl> inline int64_t size_to_dim_ ( int k , IntList dims ) { <nl> - CAFFE_ENFORCE ( ( unsigned ) k < = dims . size ( ) ) ; <nl> + AT_ENFORCE ( ( unsigned ) k < = dims . size ( ) ) ; <nl> int64_t r = 1 ; <nl> for ( int i = 0 ; i < k ; + + i ) { <nl> r * = dims [ i ] ; <nl> inline int64_t size_to_dim_ ( int k , IntList dims ) { <nl> <nl> / / Product of all dims between k and l ( not including dims [ k ] and dims [ l ] ) <nl> inline int64_t size_between_dim_ ( int k , int l , IntList dims ) { <nl> - CAFFE_ENFORCE ( ( unsigned ) l < dims . size ( ) ) ; <nl> + AT_ENFORCE ( ( unsigned ) l < dims . size ( ) ) ; <nl> int64_t r = 1 ; <nl> if ( k < l ) { <nl> for ( int i = k + 1 ; i < l ; + + i ) { <nl> inline int64_t size_between_dim_ ( int k , int l , IntList dims ) { <nl> <nl> / / Wrap around axis_index if it is negative , s . t . , - 1 is the last dim <nl> inline int canonical_axis_index_ ( int axis_index , int ndims ) { <nl> - CAFFE_ENFORCE_GE ( axis_index , - ndims ) ; <nl> - CAFFE_ENFORCE_LT ( axis_index , ndims ) ; <nl> + AT_ENFORCE_GE ( axis_index , - ndims ) ; <nl> + AT_ENFORCE_LT ( axis_index , ndims ) ; <nl> if ( axis_index < 0 ) { <nl> return axis_index + ndims ; <nl> } <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> template < typename T > <nl> inline T * data ( ) const { <nl> AT_ASSERT ( ! is_variable ( ) ) ; <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> storage_ . data ( ) | | numel_ = = 0 , <nl> " The tensor has a non - zero number of elements , but its data is not allocated yet . " <nl> " Caffe2 uses a lazy allocation , so you will need to call " <nl> " mutable_data ( ) or raw_mutable_data ( ) to actually allocate memory . " ) ; <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> storage_ . IsType < T > ( ) , <nl> " Tensor type mismatch , caller expects elements to be " , <nl> caffe2 : : TypeMeta : : TypeName < T > ( ) , <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> <nl> inline void * data ( ) const { <nl> AT_ASSERT ( ! is_variable ( ) ) ; <nl> - CAFFE_ENFORCE_WITH_CALLER ( storage_ . data ( ) | | numel_ = = 0 ) ; <nl> + AT_ENFORCE_WITH_CALLER ( storage_ . data ( ) | | numel_ = = 0 ) ; <nl> return static_cast < void * > ( <nl> static_cast < char * > ( storage_ . data ( ) ) + <nl> data_type_ . itemsize ( ) * storage_offset_ ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> return ; <nl> } <nl> if ( data_type_ ! = src . dtype ( ) ) { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> src . is_contiguous ( ) , <nl> " Right now only copy of contiguous source Tensor is supported . " ) ; <nl> storage_ = at : : Storage ( device_type ( ) , src . dtype ( ) ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> Resize ( src . sizes ( ) ) ; <nl> if ( numel ( ) > 0 ) { <nl> if ( data_type_ . copy ( ) ) { <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> device_type ( ) = = : : at : : DeviceType : : CPU , <nl> " In CopyFrom source and dest tensors must both be CPU for meta copy " ) ; <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> src . device_type ( ) = = : : at : : DeviceType : : CPU , <nl> " In CopyFrom source and dest tensors must both be CPU for meta copy " ) ; <nl> data_type_ . copy ( ) ( src . data ( ) , raw_mutable_data ( data_type_ ) , numel ( ) ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> raw_mutable_data ( data_type_ ) , <nl> device_type ( ) ) ; <nl> } else { <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> context - > device_type ( ) = = src . device_type ( ) , <nl> " Type for provided context does not match the type of source " ) ; <nl> context - > CopyBytesToDevice ( <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> * complexity . <nl> * / <nl> void Extend ( int64_t num , float growthPct , at : : BaseContext * context ) { <nl> - CAFFE_ENFORCE_GE_WITH_CALLER ( sizes_ . size ( ) , 1u ) ; <nl> - CAFFE_ENFORCE_GE_WITH_CALLER ( <nl> + AT_ENFORCE_GE_WITH_CALLER ( sizes_ . size ( ) , 1u ) ; <nl> + AT_ENFORCE_GE_WITH_CALLER ( <nl> num , 0 , " ` num ` must be non - negative for Extend " ) ; <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> is_contiguous_ , <nl> " Right now Extend is only supported for contiguous Tensor . " ) ; <nl> auto newDims = sizes_ ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> auto oldDims = sizes_ ; <nl> Resize ( newCapacity ) ; <nl> auto * newData = raw_mutable_data ( data_type_ ) ; <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> context ! = nullptr , " Context must be provided to Extend the tensor " ) ; <nl> context - > CopyItemsSameDevice ( <nl> data_type_ , oldSize , oldData . get ( ) , newData ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> * / <nl> template < class T > <nl> void ReserveSpace ( const T & outer_dim ) { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> is_contiguous_ , <nl> " Right now ReserveSpace is only supported for contiguous Tensor . " ) ; <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> numel_ ! = - 1 , " size should be initialized before calling ReserveSpace " ) ; <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> storage_ . unique ( ) , " Can ' t call ReserveSpace on shared storage . " ) ; <nl> auto newCapacity = sizes_ ; <nl> newCapacity [ 0 ] = outer_dim ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> * This requires the total size of the tensor to remains constant . <nl> * / <nl> inline void Reshape ( const std : : vector < int64_t > & dims ) { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> is_contiguous_ , <nl> " Right now Reshape is only supported for contiguous Tensor . " ) ; <nl> int64_t new_size = 1 ; <nl> for ( auto d : dims ) { <nl> - CAFFE_ENFORCE_GE_WITH_CALLER ( d , 0 ) ; <nl> + AT_ENFORCE_GE_WITH_CALLER ( d , 0 ) ; <nl> new_size * = d ; <nl> } <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> new_size = = numel_ , <nl> " New size and old size are not equal . You cannot use Reshape , " <nl> " but should use Resize . " <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> / / Right now , we are assuming the device_type are the same , since it is <nl> / / inherently the same in the non - templatized code . We should probably add <nl> / / an ENFORCE here which might affect perf a little bit . <nl> - CAFFE_ENFORCE_EQ_WITH_CALLER ( <nl> + AT_ENFORCE_EQ_WITH_CALLER ( <nl> src . numel_ , <nl> numel_ , <nl> " Size mismatch - did you call reshape before sharing the data ? " ) ; <nl> / / It is possible that the source tensor hasn ' t called mutable_data ( ) yet , <nl> / / in which case ShareData ( ) doesn ' t make much sense since we don ' t really <nl> / / know what to share yet . <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> src . storage_ . data ( ) | | src . numel_ = = 0 , <nl> " Source tensor has no content and has size > 0 " ) ; <nl> / / Finally , do sharing . <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> at : : DataPtr & & data_ptr , <nl> const caffe2 : : TypeMeta & data_type , <nl> size_t capacity ) { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> data_type . id ( ) ! = caffe2 : : TypeIdentifier : : uninitialized ( ) , <nl> " To share with a raw external pointer you need to pass in an " <nl> " initialized data_type ( TypeMeta ) . " ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> capacity = numel_ * data_type . itemsize ( ) ; <nl> } <nl> if ( storage_ . unique ( ) ) { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> numel_ > = 0 , <nl> " To share data with a raw pointer , you need to set shape first . " ) ; <nl> storage_ . UniqueStorageShareExternalPointer ( <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> if ( data_type_ = = meta & & ( storage_ . data ( ) | | numel_ = = 0 ) ) { <nl> return static_cast < void * > ( static_cast < char * > ( storage_ . data ( ) ) + storage_offset_ * meta . itemsize ( ) ) ; <nl> } else { <nl> - CAFFE_ENFORCE_WITH_CALLER ( <nl> + AT_ENFORCE_WITH_CALLER ( <nl> numel_ > = 0 , <nl> " Tensor is not initialized . You probably need to call Resize ( ) " <nl> " before calling mutable_data ( ) " ) ; <nl> struct CAFFE2_API TensorImpl : public c10 : : intrusive_ptr_target { <nl> } <nl> const at : : Allocator * allocator = storage_ . allocator ( ) ; <nl> / / TODO : Get rid of StaticContext <nl> - CAFFE_ENFORCE ( <nl> + AT_ENFORCE ( <nl> allocator = = nullptr , <nl> " Allocator is not used within Caffe2 functions , please use StaticContext instead . " ) ; <nl> allocator = caffe2 : : GetAllocator ( storage_ . device_type ( ) ) ; <nl> mmm a / c10 / macros / Export . h <nl> ppp b / c10 / macros / Export . h <nl> <nl> / / and export . <nl> <nl> / / This one is being used by libc10 . so <nl> - # ifdef C10_BUILD_MAIN_DLL <nl> + # ifdef C10_BUILD_MAIN_LIB <nl> # define C10_API C10_EXPORT <nl> # else <nl> # define C10_API C10_IMPORT <nl> mmm a / caffe2 / CMakeLists . txt <nl> ppp b / caffe2 / CMakeLists . txt <nl> endif ( ) <nl> # mmm [ Caffe2 build <nl> # Note : the folders that are being commented out have not been properly <nl> # addressed yet . <nl> - add_subdirectory ( proto ) <nl> - add_subdirectory ( contrib ) <nl> - add_subdirectory ( core ) <nl> - add_subdirectory ( utils ) <nl> - add_subdirectory ( predictor ) <nl> - add_subdirectory ( core / nomnigraph ) <nl> - add_subdirectory ( core / dispatch ) <nl> - if ( USE_NVRTC ) <nl> - add_subdirectory ( cuda_rtc ) <nl> - endif ( ) <nl> - add_subdirectory ( db ) <nl> - add_subdirectory ( distributed ) <nl> - # add_subdirectory ( experiments ) # note , we may remove this folder at some point <nl> - add_subdirectory ( ideep ) <nl> - add_subdirectory ( image ) <nl> - add_subdirectory ( video ) <nl> - add_subdirectory ( mkl ) <nl> - add_subdirectory ( mobile ) <nl> - add_subdirectory ( mpi ) <nl> - add_subdirectory ( observers ) <nl> - add_subdirectory ( onnx ) <nl> - if ( BUILD_CAFFE2_OPS ) <nl> - add_subdirectory ( operators ) <nl> - add_subdirectory ( operators / rnn ) <nl> + if ( NOT BUILD_ATEN_ONLY ) <nl> + add_subdirectory ( proto ) <nl> + add_subdirectory ( contrib ) <nl> + add_subdirectory ( core ) <nl> + add_subdirectory ( utils ) <nl> + add_subdirectory ( predictor ) <nl> + add_subdirectory ( core / nomnigraph ) <nl> + add_subdirectory ( core / dispatch ) <nl> + if ( USE_NVRTC ) <nl> + add_subdirectory ( cuda_rtc ) <nl> + endif ( ) <nl> + add_subdirectory ( db ) <nl> + add_subdirectory ( distributed ) <nl> + # add_subdirectory ( experiments ) # note , we may remove this folder at some point <nl> + add_subdirectory ( ideep ) <nl> + add_subdirectory ( image ) <nl> + add_subdirectory ( video ) <nl> + add_subdirectory ( mkl ) <nl> + add_subdirectory ( mobile ) <nl> + add_subdirectory ( mpi ) <nl> + add_subdirectory ( observers ) <nl> + add_subdirectory ( onnx ) <nl> + if ( BUILD_CAFFE2_OPS ) <nl> + add_subdirectory ( operators ) <nl> + add_subdirectory ( operators / rnn ) <nl> + endif ( ) <nl> + add_subdirectory ( opt ) <nl> + add_subdirectory ( perfkernels ) <nl> + add_subdirectory ( python ) <nl> + add_subdirectory ( queue ) <nl> + add_subdirectory ( sgd ) <nl> + add_subdirectory ( share ) <nl> + # add_subdirectory ( test ) # todo : use caffe2_gtest_main instead of gtest_main because we will need to call GlobalInit <nl> + add_subdirectory ( transforms ) <nl> endif ( ) <nl> - add_subdirectory ( opt ) <nl> - add_subdirectory ( perfkernels ) <nl> - add_subdirectory ( python ) <nl> - add_subdirectory ( queue ) <nl> - add_subdirectory ( sgd ) <nl> - add_subdirectory ( share ) <nl> - # add_subdirectory ( test ) # todo : use caffe2_gtest_main instead of gtest_main because we will need to call GlobalInit <nl> - add_subdirectory ( transforms ) <nl> <nl> # Advanced : if we have white list specified , we will do intersections for all <nl> # main lib srcs . <nl> if ( FALSE ) <nl> endif ( ) <nl> <nl> # mmm [ List of libraries to link with <nl> - add_library ( caffe2_protos STATIC $ < TARGET_OBJECTS : Caffe2_PROTO > ) <nl> - add_dependencies ( caffe2_protos Caffe2_PROTO ) <nl> - # If we are going to link protobuf locally inside caffe2 libraries , what we will do is <nl> - # to create a helper static library that always contains libprotobuf source files , and <nl> - # link the caffe2 related dependent libraries to it . <nl> - target_include_directories ( caffe2_protos INTERFACE $ < INSTALL_INTERFACE : include > ) <nl> - # Reason for this public dependency is as follows : <nl> - # ( 1 ) Strictly speaking , we should not expose any Protobuf related functions . We should <nl> - # only use function interfaces wrapped with our own public API , and link protobuf <nl> - # locally . <nl> - # ( 2 ) However , currently across the Caffe2 codebase , we have extensive use of protobuf <nl> - # functionalities . For example , not only libcaffe2 . so uses it , but also other <nl> - # binaries such as python extensions etc . As a result , we will have to have a <nl> - # transitive dependency to libprotobuf . <nl> - # <nl> - # Good thing is that , if we specify CAFFE2_LINK_LOCAL_PROTOBUF , then we do not need to <nl> - # separately deploy protobuf binaries - libcaffe2 . so will contain all functionalities <nl> - # one needs . One can verify this via ldd . <nl> - # <nl> - # TODO item in the future includes : <nl> - # ( 1 ) Enable using lite protobuf <nl> - # ( 2 ) Properly define public API that do not directly depend on protobuf itself . <nl> - # ( 3 ) Expose the libprotobuf . a file for dependent libraries to link to . <nl> - # <nl> - # What it means for users / developers ? <nl> - # ( 1 ) Users : nothing affecting the users , other than the fact that CAFFE2_LINK_LOCAL_PROTOBUF <nl> - # avoids the need to deploy protobuf . <nl> - # ( 2 ) Developers : if one simply uses core caffe2 functionality without using protobuf , <nl> - # nothing changes . If one has a dependent library that uses protobuf , then one needs to <nl> - # have the right protobuf version as well as linking to libprotobuf . a . <nl> - target_link_libraries ( caffe2_protos PUBLIC protobuf : : libprotobuf ) <nl> + if ( NOT BUILD_ATEN_ONLY ) <nl> + add_library ( caffe2_protos STATIC $ < TARGET_OBJECTS : Caffe2_PROTO > ) <nl> + add_dependencies ( caffe2_protos Caffe2_PROTO ) <nl> + # If we are going to link protobuf locally inside caffe2 libraries , what we will do is <nl> + # to create a helper static library that always contains libprotobuf source files , and <nl> + # link the caffe2 related dependent libraries to it . <nl> + target_include_directories ( caffe2_protos INTERFACE $ < INSTALL_INTERFACE : include > ) <nl> + # Reason for this public dependency is as follows : <nl> + # ( 1 ) Strictly speaking , we should not expose any Protobuf related functions . We should <nl> + # only use function interfaces wrapped with our own public API , and link protobuf <nl> + # locally . <nl> + # ( 2 ) However , currently across the Caffe2 codebase , we have extensive use of protobuf <nl> + # functionalities . For example , not only libcaffe2 . so uses it , but also other <nl> + # binaries such as python extensions etc . As a result , we will have to have a <nl> + # transitive dependency to libprotobuf . <nl> + # <nl> + # Good thing is that , if we specify CAFFE2_LINK_LOCAL_PROTOBUF , then we do not need to <nl> + # separately deploy protobuf binaries - libcaffe2 . so will contain all functionalities <nl> + # one needs . One can verify this via ldd . <nl> + # <nl> + # TODO item in the future includes : <nl> + # ( 1 ) Enable using lite protobuf <nl> + # ( 2 ) Properly define public API that do not directly depend on protobuf itself . <nl> + # ( 3 ) Expose the libprotobuf . a file for dependent libraries to link to . <nl> + # <nl> + # What it means for users / developers ? <nl> + # ( 1 ) Users : nothing affecting the users , other than the fact that CAFFE2_LINK_LOCAL_PROTOBUF <nl> + # avoids the need to deploy protobuf . <nl> + # ( 2 ) Developers : if one simply uses core caffe2 functionality without using protobuf , <nl> + # nothing changes . If one has a dependent library that uses protobuf , then one needs to <nl> + # have the right protobuf version as well as linking to libprotobuf . a . <nl> + target_link_libraries ( caffe2_protos PUBLIC protobuf : : libprotobuf ) <nl> + endif ( ) <nl> <nl> # Compile exposed libraries . <nl> add_library ( caffe2 $ { Caffe2_CPU_SRCS } ) <nl> if ( NOT WIN32 ) <nl> target_compile_options ( caffe2 PRIVATE " - fvisibility = hidden " ) <nl> endif ( ) <nl> - caffe2_interface_library ( caffe2_protos caffe2_protos_whole ) <nl> - target_link_libraries ( caffe2 PRIVATE caffe2_protos_whole ) <nl> - if ( $ { CAFFE2_LINK_LOCAL_PROTOBUF } ) <nl> - target_link_libraries ( caffe2 INTERFACE protobuf : : libprotobuf ) <nl> - else ( ) <nl> - target_link_libraries ( caffe2 PUBLIC protobuf : : libprotobuf ) <nl> + <nl> + if ( NOT BUILD_ATEN_ONLY ) <nl> + caffe2_interface_library ( caffe2_protos caffe2_protos_whole ) <nl> + target_link_libraries ( caffe2 PRIVATE caffe2_protos_whole ) <nl> + if ( $ { CAFFE2_LINK_LOCAL_PROTOBUF } ) <nl> + target_link_libraries ( caffe2 INTERFACE protobuf : : libprotobuf ) <nl> + else ( ) <nl> + target_link_libraries ( caffe2 PUBLIC protobuf : : libprotobuf ) <nl> + endif ( ) <nl> endif ( ) <nl> + <nl> target_link_libraries ( caffe2 PUBLIC c10 ) <nl> target_link_libraries ( caffe2 PUBLIC $ { Caffe2_PUBLIC_DEPENDENCY_LIBS } ) <nl> target_link_libraries ( caffe2 PRIVATE $ { Caffe2_DEPENDENCY_LIBS } ) <nl> mmm a / cmake / Dependencies . cmake <nl> ppp b / cmake / Dependencies . cmake <nl> macro ( enable_ubsan ) <nl> endif ( ) <nl> endmacro ( ) <nl> <nl> + if ( NOT BUILD_ATEN_ONLY ) <nl> # mmm [ Custom Protobuf <nl> if ( CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO ) <nl> disable_ubsan ( ) <nl> include ( $ { CMAKE_CURRENT_LIST_DIR } / ProtoBuf . cmake ) <nl> enable_ubsan ( ) <nl> endif ( ) <nl> + endif ( ) <nl> <nl> # mmm [ Threads <nl> include ( $ { CMAKE_CURRENT_LIST_DIR } / public / threads . cmake ) <nl> if ( USE_ZSTD ) <nl> endif ( ) <nl> <nl> # mmm [ Onnx <nl> + if ( NOT BUILD_ATEN_ONLY ) <nl> if ( CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO ) <nl> if ( EXISTS " $ { CAFFE2_CUSTOM_PROTOC_EXECUTABLE } " ) <nl> set ( ONNX_CUSTOM_PROTOC_EXECUTABLE $ { CAFFE2_CUSTOM_PROTOC_EXECUTABLE } ) <nl> if ( CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO ) <nl> # Recover the build shared libs option . <nl> set ( BUILD_SHARED_LIBS $ { TEMP_BUILD_SHARED_LIBS } ) <nl> endif ( ) <nl> + endif ( ) <nl> <nl> # - - [ TensorRT integration with onnx - trt <nl> if ( CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO ) <nl> mmm a / cmake / Summary . cmake <nl> ppp b / cmake / Summary . cmake <nl> function ( caffe2_print_configuration_summary ) <nl> message ( STATUS " TORCH_VERSION : $ { TORCH_VERSION } " ) <nl> message ( STATUS " CAFFE2_VERSION : $ { CAFFE2_VERSION } " ) <nl> message ( STATUS " BUILD_ATEN_MOBILE : $ { BUILD_ATEN_MOBILE } " ) <nl> + message ( STATUS " BUILD_ATEN_ONLY : $ { BUILD_ATEN_ONLY } " ) <nl> message ( STATUS " BUILD_BINARY : $ { BUILD_BINARY } " ) <nl> message ( STATUS " BUILD_CUSTOM_PROTOBUF : $ { BUILD_CUSTOM_PROTOBUF } " ) <nl> if ( $ { CAFFE2_LINK_LOCAL_PROTOBUF } ) <nl>
Introduce BUILD_ATEN_ONLY cmake option ( )
pytorch/pytorch
0d50c117db6353021346d28d5872db15bf069bdb
2018-10-10T19:54:19Z
mmm a / tensorflow / contrib / data / python / kernel_tests / map_dataset_op_test . py <nl> ppp b / tensorflow / contrib / data / python / kernel_tests / map_dataset_op_test . py <nl> def _map_fn ( x ) : <nl> with self . assertRaises ( errors . OutOfRangeError ) : <nl> sess . run ( get_next ) <nl> <nl> + def testReturnList ( self ) : <nl> + iterator = ( dataset_ops . Dataset . range ( 10 ) <nl> + . map ( lambda x : [ x , constant_op . constant ( 37 . 0 ) ] ) <nl> + . make_initializable_iterator ( ) ) <nl> + init_op = iterator . initializer <nl> + get_next = iterator . get_next ( ) <nl> + <nl> + with self . test_session ( ) as sess : <nl> + sess . run ( init_op ) <nl> + for i in range ( 10 ) : <nl> + self . assertEqual ( ( i , 37 . 0 ) , sess . run ( get_next ) ) <nl> + with self . assertRaises ( errors . OutOfRangeError ) : <nl> + sess . run ( get_next ) <nl> + <nl> + def testMultiOutputPyFunc ( self ) : <nl> + # The ` tf . py_func ( ) ` op returns a list of tensors for its outputs . <nl> + def _map_fn ( x_tensor ) : <nl> + def _map_py_func ( x ) : <nl> + return x , np . array ( 37 . 0 , dtype = np . float64 ) <nl> + return script_ops . py_func ( <nl> + _map_py_func , [ x_tensor ] , [ dtypes . int64 , dtypes . float64 ] ) <nl> + <nl> + iterator = ( dataset_ops . Dataset . range ( 10 ) <nl> + . map ( _map_fn ) <nl> + . make_initializable_iterator ( ) ) <nl> + init_op = iterator . initializer <nl> + get_next = iterator . get_next ( ) <nl> + <nl> + with self . test_session ( ) as sess : <nl> + sess . run ( init_op ) <nl> + for i in range ( 10 ) : <nl> + self . assertEqual ( ( i , 37 . 0 ) , sess . run ( get_next ) ) <nl> + with self . assertRaises ( errors . OutOfRangeError ) : <nl> + sess . run ( get_next ) <nl> + <nl> <nl> if __name__ = = " __main__ " : <nl> test . main ( ) <nl> mmm a / tensorflow / contrib / data / python / ops / dataset_ops . py <nl> ppp b / tensorflow / contrib / data / python / ops / dataset_ops . py <nl> def tf_map_func ( * args ) : <nl> else : <nl> ret = map_func ( nested_args ) <nl> <nl> + # If ` map_func ` returns a list of tensors , ` nest . flatten ( ) ` and <nl> + # ` ops . convert_to_tensor ( ) ` would conspire to attempt to stack <nl> + # those tensors into a single tensor , because the customized <nl> + # version of ` nest . flatten ( ) ` does not recurse into lists . Since <nl> + # it is more likely that the list arose from returning the <nl> + # result of an operation ( such as ` tf . py_func ( ) ` ) that returns a <nl> + # list of not - necessarily - stackable tensors , we treat the <nl> + # returned value is a ` tuple ` instead . A user wishing to pack <nl> + # the return value into a single tensor can use an explicit <nl> + # ` tf . stack ( ) ` before returning . <nl> + if isinstance ( ret , list ) : <nl> + ret = tuple ( ret ) <nl> + <nl> # Extract shape information from the returned values . <nl> flattened_ret = [ ops . convert_to_tensor ( t ) for t in nest . flatten ( ret ) ] <nl> self . _output_shapes = nest . pack_sequence_as ( <nl>
[ tf . contrib . data ] Fix handling of multi - output tf . py_func ( ) in Dataset . map ( ) .
tensorflow/tensorflow
d001b58de9d0d99ef34637b9a9bed5763875f655
2017-08-18T18:45:10Z
mmm a / filament / backend / src / vulkan / VulkanHandles . cpp <nl> ppp b / filament / backend / src / vulkan / VulkanHandles . cpp <nl> VulkanTexture : : VulkanTexture ( VulkanContext & context , SamplerType target , uint8_t <nl> } <nl> if ( target = = SamplerType : : SAMPLER_2D_ARRAY ) { <nl> imageInfo . arrayLayers = depth ; <nl> + imageInfo . extent . depth = 1 ; <nl> / / NOTE : We do not use VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT here because : <nl> / / <nl> / / ( a ) MoltenVK does not support it , and <nl> VulkanTexture : : VulkanTexture ( VulkanContext & context , SamplerType target , uint8_t <nl> <nl> if ( any ( usage & ( TextureUsage : : COLOR_ATTACHMENT | TextureUsage : : DEPTH_ATTACHMENT ) ) ) { <nl> auto transition = [ = ] ( VulkanCommandBuffer commands ) { <nl> + / / If this is a SAMPLER_2D_ARRAY texture , then the depth argument stores the number of <nl> + / / texture layers . <nl> + const uint32_t layers = target = = SamplerType : : SAMPLER_2D_ARRAY ? depth : 1 ; <nl> VulkanTexture : : transitionImageLayout ( commands . cmdbuffer , textureImage , <nl> - VK_IMAGE_LAYOUT_UNDEFINED , getTextureLayout ( usage ) , 0 , 1 , levels , mAspect ) ; <nl> + VK_IMAGE_LAYOUT_UNDEFINED , getTextureLayout ( usage ) , 0 , layers , levels , mAspect ) ; <nl> } ; <nl> if ( mContext . currentCommands ) { <nl> transition ( * mContext . currentCommands ) ; <nl>
Fix Vulkan crash when using shadow cascades ( )
google/filament
bd625e42e986474343cb1e5d473fa59cddcd4944
2020-10-07T21:36:45Z
mmm a / lib / SILAnalysis / RefCountState . cpp <nl> ppp b / lib / SILAnalysis / RefCountState . cpp <nl> void BottomUpRefCountState : : clear ( ) { <nl> SuperTy : : clear ( ) ; <nl> } <nl> <nl> + / / / If advance the state ' s sequence appropriately for a decrement . If we do <nl> + / / / advance return true . Otherwise return false . <nl> + bool BottomUpRefCountState : : isRefCountStateModified ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : Decremented : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : MightBeDecremented : <nl> + case LatticeState : : MightBeUsed : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + / / / Returns true if given the current lattice state , do we care if the value <nl> + / / / we are tracking is decremented . <nl> + bool BottomUpRefCountState : : valueCanBeDecrementedGivenLatticeState ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : MightBeUsed : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : MightBeDecremented : <nl> + case LatticeState : : Decremented : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> / / / If advance the state ' s sequence appropriately for a decrement . If we do <nl> / / / advance return true . Otherwise return false . <nl> bool BottomUpRefCountState : : <nl> handleDecrement ( SILInstruction * PotentialDecrement ) { <nl> } <nl> } <nl> <nl> + / / / Returns true if given the current lattice state , do we care if the value we <nl> + / / / are tracking is used . <nl> + bool BottomUpRefCountState : : valueCanBeUsedGivenLatticeState ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : Decremented : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : MightBeDecremented : <nl> + case LatticeState : : MightBeUsed : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> / / / Given the current lattice state , if we have seen a use , advance the <nl> / / / lattice state . Return true if we do so and false otherwise . <nl> bool <nl> void TopDownRefCountState : : clear ( ) { <nl> SuperTy : : clear ( ) ; <nl> } <nl> <nl> + / / / Can we gaurantee that the given reference counted value has been modified ? <nl> + bool TopDownRefCountState : : isRefCountStateModified ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : Incremented : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : MightBeDecremented : <nl> + case LatticeState : : MightBeUsed : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + / / / Returns true if given the current lattice state , do we care if the value <nl> + / / / we are tracking is decremented . <nl> + bool TopDownRefCountState : : valueCanBeDecrementedGivenLatticeState ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : Incremented : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : MightBeDecremented : <nl> + case LatticeState : : MightBeUsed : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> / / / If advance the state ' s sequence appropriately for a decrement . If we do <nl> / / / advance return true . Otherwise return false . <nl> bool TopDownRefCountState : : handleDecrement ( SILInstruction * PotentialDecrement ) { <nl> bool TopDownRefCountState : : handleDecrement ( SILInstruction * PotentialDecrement ) { <nl> } <nl> } <nl> <nl> + / / / Returns true if given the current lattice state , do we care if the value <nl> + / / / we are tracking is used . <nl> + bool TopDownRefCountState : : valueCanBeUsedGivenLatticeState ( ) const { <nl> + switch ( LatState ) { <nl> + case LatticeState : : MightBeDecremented : <nl> + return true ; <nl> + case LatticeState : : None : <nl> + case LatticeState : : Incremented : <nl> + case LatticeState : : MightBeUsed : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> / / / Given the current lattice state , if we have seen a use , advance the <nl> / / / lattice state . Return true if we do so and false otherwise . <nl> bool TopDownRefCountState : : handleUser ( SILInstruction * PotentialUser , <nl> mmm a / lib / SILAnalysis / RefCountState . h <nl> ppp b / lib / SILAnalysis / RefCountState . h <nl> struct BottomUpRefCountState : RefCountState < BottomUpRefCountState > { <nl> void clear ( ) ; <nl> <nl> / / / Can we gaurantee that the given reference counted value has been modified ? <nl> - bool isRefCountStateModified ( ) const { <nl> - return LatState = = LatticeState : : Decremented ; <nl> - } <nl> + bool isRefCountStateModified ( ) const ; <nl> <nl> / / / Returns true if given the current lattice state , do we care if the value <nl> / / / we are tracking is decremented . <nl> - bool valueCanBeDecrementedGivenLatticeState ( ) const { <nl> - return LatState = = LatticeState : : MightBeUsed ; <nl> - } <nl> + bool valueCanBeDecrementedGivenLatticeState ( ) const ; <nl> <nl> / / / If advance the state ' s sequence appropriately for a decrement . If we do <nl> / / / advance return true . Otherwise return false . <nl> struct BottomUpRefCountState : RefCountState < BottomUpRefCountState > { <nl> <nl> / / / Returns true if given the current lattice state , do we care if the value <nl> / / / we are tracking is used . <nl> - bool valueCanBeUsedGivenLatticeState ( ) const { <nl> - return LatState = = LatticeState : : Decremented ; <nl> - } <nl> + bool valueCanBeUsedGivenLatticeState ( ) const ; <nl> <nl> / / / Given the current lattice state , if we have seen a use , advance the <nl> / / / lattice state . Return true if we do so and false otherwise . <nl> struct TopDownRefCountState : RefCountState < TopDownRefCountState > { <nl> void clear ( ) ; <nl> <nl> / / / Can we gaurantee that the given reference counted value has been modified ? <nl> - bool isRefCountStateModified ( ) const { <nl> - return LatState = = LatticeState : : Incremented ; <nl> - } <nl> + bool isRefCountStateModified ( ) const ; <nl> <nl> / / / Returns true if given the current lattice state , do we care if the value <nl> / / / we are tracking is decremented . <nl> - bool valueCanBeDecrementedGivenLatticeState ( ) const { <nl> - return LatState = = LatticeState : : Incremented ; <nl> - } <nl> + bool valueCanBeDecrementedGivenLatticeState ( ) const ; <nl> <nl> / / / If advance the state ' s sequence appropriately for a decrement . If we do <nl> / / / advance return true . Otherwise return false . <nl> struct TopDownRefCountState : RefCountState < TopDownRefCountState > { <nl> <nl> / / / Returns true if given the current lattice state , do we care if the value <nl> / / / we are tracking is used . <nl> - bool valueCanBeUsedGivenLatticeState ( ) const { <nl> - return LatState = = LatticeState : : MightBeDecremented ; <nl> - } <nl> + bool valueCanBeUsedGivenLatticeState ( ) const ; <nl> <nl> / / / Given the current lattice state , if we have seen a use , advance the <nl> / / / lattice state . Return true if we do so and false otherwise . <nl>
[ g - arc - opts ] Change all boolean LatticeState queries to use covered switches . NFC .
apple/swift
4c4d1b3fb4578197e632d543677a927fd3c394ad
2015-04-05T05:20:24Z
new file mode 100644 <nl> index 00000000000 . . b31c09d1dff <nl> mmm / dev / null <nl> ppp b / Marlin / scripts / findMissingTranslations . sh <nl> <nl> + # ! / bin / bash <nl> + IGNORE_DEFINES = " LANGUAGE_EN_H MAPPER_NON SIMULATE_ROMFONT DISPLAY_CHARSET_ISO10646_1 MSG_H1 MSG_H2 MSG_H3 MSG_H4 MSG_MOVE_E1 MSG_MOVE_E2 MSG_MOVE_E3 MSG_MOVE_E4 MSG_N1 MSG_N2 MSG_N3 MSG_N4 MSG_DIAM_E1 MSG_DIAM_E2 MSG_DIAM_E3 MSG_DIAM_E4 MSG_E1 MSG_E2 MSG_E3 MSG_E4 " <nl> + <nl> + for i in ` awk ' / # define / { print $ 2 } ' language_en . h ` ; do <nl> + for j in ` ls language_ * . h | grep - v language_en . h ` ; do <nl> + t = $ ( grep - c " $ { i } " $ { j } ) <nl> + if [ " $ t " - eq 0 ] ; then <nl> + for k in $ { IGNORE_DEFINES } ; do <nl> + [ " $ { k } " = = " $ { i } " ] & & continue 2 ; <nl> + done <nl> + echo " $ { j } , $ { i } " <nl> + fi <nl> + done <nl> + done <nl>
Added a script to check all language files for missing translations
MarlinFirmware/Marlin
f94900ee79de055b8379fa22aafd25426aebd0a1
2016-04-04T03:46:04Z
mmm a / src / IO / ReadHelpers . h <nl> ppp b / src / IO / ReadHelpers . h <nl> ReturnType readIntTextImpl ( T & x , ReadBuffer & buf ) <nl> switch ( * buf . position ( ) ) <nl> { <nl> case ' + ' : <nl> + { <nl> break ; <nl> + } <nl> case ' - ' : <nl> + { <nl> if constexpr ( is_signed_v < T > ) <nl> negative = true ; <nl> else <nl> ReturnType readIntTextImpl ( T & x , ReadBuffer & buf ) <nl> return ReturnType ( false ) ; <nl> } <nl> break ; <nl> + } <nl> case ' 0 ' : [ [ fallthrough ] ] ; <nl> case ' 1 ' : [ [ fallthrough ] ] ; <nl> case ' 2 ' : [ [ fallthrough ] ] ; <nl> ReturnType readIntTextImpl ( T & x , ReadBuffer & buf ) <nl> case ' 7 ' : [ [ fallthrough ] ] ; <nl> case ' 8 ' : [ [ fallthrough ] ] ; <nl> case ' 9 ' : <nl> + { <nl> if constexpr ( check_overflow = = ReadIntTextCheckOverflow : : CHECK_OVERFLOW ) <nl> { <nl> - / / perform relativelly slow overflow check only when number of decimal digits so far is close to the max for given type . <nl> - if ( buf . count ( ) - initial_pos > = std : : numeric_limits < T > : : max_digits10 ) <nl> + / / / Perform relativelly slow overflow check only when <nl> + / / / number of decimal digits so far is close to the max for given type . <nl> + / / / Example : 20 * 10 will overflow Int8 . <nl> + <nl> + if ( buf . count ( ) - initial_pos + 1 > = std : : numeric_limits < T > : : max_digits10 ) <nl> { <nl> - if ( common : : mulOverflow ( res , static_cast < decltype ( res ) > ( 10 ) , res ) <nl> - | | common : : addOverflow ( res , static_cast < decltype ( res ) > ( * buf . position ( ) - ' 0 ' ) , res ) ) <nl> + T signed_res = res ; <nl> + if ( common : : mulOverflow < T > ( signed_res , 10 , signed_res ) <nl> + | | common : : addOverflow < T > ( signed_res , ( * buf . position ( ) - ' 0 ' ) , signed_res ) ) <nl> return ReturnType ( false ) ; <nl> + res = signed_res ; <nl> break ; <nl> } <nl> } <nl> res * = 10 ; <nl> res + = * buf . position ( ) - ' 0 ' ; <nl> break ; <nl> + } <nl> default : <nl> goto end ; <nl> } <nl> ReturnType readIntTextImpl ( T & x , ReadBuffer & buf ) <nl> } <nl> <nl> end : <nl> - x = negative ? - res : res ; <nl> + if ( ! negative ) <nl> + { <nl> + x = res ; <nl> + } <nl> + else <nl> + { <nl> + if constexpr ( check_overflow = = ReadIntTextCheckOverflow : : CHECK_OVERFLOW ) <nl> + { <nl> + x = res ; <nl> + if ( common : : mulOverflow < T > ( x , - 1 , x ) ) <nl> + return ReturnType ( false ) ; <nl> + } <nl> + else <nl> + { <nl> + x = - res ; <nl> + } <nl> + } <nl> <nl> return ReturnType ( true ) ; <nl> } <nl> inline ReturnType readDateTimeTextImpl ( DateTime64 & datetime64 , UInt32 scale , Re <nl> buf . ignore ( 1 ) ; / / skip separator <nl> const auto pos_before_fractional = buf . count ( ) ; <nl> if ( ! tryReadIntText < ReadIntTextCheckOverflow : : CHECK_OVERFLOW > ( c . fractional , buf ) ) <nl> - { <nl> return ReturnType ( false ) ; <nl> - } <nl> <nl> / / Adjust fractional part to the scale , since decimalFromComponents knows nothing <nl> / / about convention of ommiting trailing zero on fractional part <nl> inline ReturnType readDateTimeTextImpl ( DateTime64 & datetime64 , UInt32 scale , Re <nl> / / If scale is 3 , but we read ' 12 ' , promote fractional part to ' 120 ' . <nl> / / And vice versa : if we read ' 1234 ' , denote it to ' 123 ' . <nl> const auto fractional_length = static_cast < Int32 > ( buf . count ( ) - pos_before_fractional ) ; <nl> - if ( const auto adjust_scale = static_cast < Int32 > ( scale ) - fractional_length ; adjust_scale > 0 ) <nl> + <nl> + const auto adjust_scale = static_cast < Int32 > ( scale ) - fractional_length ; <nl> + if ( adjust_scale > 0 ) <nl> { <nl> c . fractional * = common : : exp10_i64 ( adjust_scale ) ; <nl> } <nl> else if ( adjust_scale < 0 ) <nl> { <nl> - c . fractional / = common : : exp10_i64 ( - 1 * adjust_scale ) ; <nl> + c . fractional / = common : : exp10_i64 ( - adjust_scale ) ; <nl> } <nl> } <nl> <nl>
Fix bugs in DateTime64 parsing
ClickHouse/ClickHouse
4ace4b4c752d52b41eec295e44f5f9bce0b26c80
2020-06-22T20:54:36Z
mmm a / tensorflow / compiler / aot / tfcompile . bzl <nl> ppp b / tensorflow / compiler / aot / tfcompile . bzl <nl> def tf_library ( <nl> tfcompile_tool = " / / tensorflow / compiler / aot : tfcompile " , <nl> include_standard_runtime_deps = True , <nl> enable_xla_hlo_profiling = False , <nl> - enable_tracemes = False , <nl> mlir_components = " None " , <nl> deps = None , <nl> tags = [ ] ) : <nl> def tf_library ( <nl> enable_xla_hlo_profiling : Enable XLA HLO profiling in the generated <nl> program , and emit metadata that lets us pretty - print the gathered <nl> profile counters . <nl> - enable_tracemes : Tell tfcompile to generate calls to <nl> - TraceMe : : Activity { Start | End } around HLO instructions that can be used by <nl> - Xprof to construct profiler timelines . <nl> mlir_components : When the value is " None " , no components use MLIR . When <nl> the value is " Bridge " , use MLIR to translate GraphDef to HLO . <nl> deps : a list of deps to include on the build rules for the generated <nl> def tf_library ( <nl> else : <nl> profiling_flag = " " <nl> <nl> - if enable_tracemes : <nl> - traceme_flag = " - - xla_cpu_enable_xprof_traceme = true " <nl> - else : <nl> - traceme_flag = " - - xla_cpu_enable_xprof_traceme = false " <nl> - <nl> mlir_flag = " - - mlir_components = " + mlir_components <nl> <nl> srcs = [ tfcompile_graph , config ] <nl> def tf_library ( <nl> " - - out_header = $ ( @ D ) / " + header_file + <nl> " - - out_metadata_object = $ ( @ D ) / " + metadata_object_file + <nl> " - - out_function_object = $ ( @ D ) / " + function_object_file + <nl> - " " + flags + " " + profiling_flag + " " + mlir_flag + " " + traceme_flag <nl> + " " + flags + " " + profiling_flag + " " + mlir_flag <nl> ) , <nl> tools = [ tfcompile_tool ] , <nl> visibility = visibility , <nl> mmm a / tensorflow / compiler / xla / debug_options_flags . cc <nl> ppp b / tensorflow / compiler / xla / debug_options_flags . cc <nl> DebugOptions DefaultDebugOptionsIgnoringFlags ( ) { <nl> opts . set_xla_allow_excess_precision ( true ) ; <nl> opts . set_xla_force_host_platform_device_count ( 1 ) ; <nl> opts . set_xla_gpu_deterministic_reductions ( false ) ; <nl> - opts . set_xla_cpu_enable_xprof_traceme ( true ) ; <nl> - <nl> return opts ; <nl> } <nl> <nl> static void AllocateFlags ( ) { <nl> flag_values - > xla_gpu_algorithm_blacklist_path ( ) , <nl> " An AlgorithmBlacklist text proto file as a blacklist " <nl> " of convolutions to avoid to use . " ) , <nl> + <nl> tensorflow : : Flag ( <nl> " xla_gpu_deterministic_reductions " , <nl> bool_setter_for ( & DebugOptions : : set_xla_gpu_deterministic_reductions ) , <nl> static void AllocateFlags ( ) { <nl> bool_setter_for ( & DebugOptions : : set_xla_tpu_detect_inf ) , <nl> flag_values - > xla_tpu_detect_inf ( ) , <nl> " Trigger error on execution on TPU if a INF value is detected " ) , <nl> - tensorflow : : Flag ( <nl> - " xla_cpu_enable_xprof_traceme " , <nl> - bool_setter_for ( & DebugOptions : : set_xla_cpu_enable_xprof_traceme ) , <nl> - flag_values - > xla_cpu_enable_xprof_traceme ( ) , <nl> - " If true , XLA CPU generates code to call " <nl> - " TraceMe : : Activity { Start | End } around HLO operations . " ) , <nl> } ) ; <nl> ParseFlagsFromEnvAndDieIfUnknown ( " XLA_FLAGS " , * flag_objects ) ; <nl> } <nl> mmm a / tensorflow / compiler / xla / service / cpu / ir_emitter . cc <nl> ppp b / tensorflow / compiler / xla / service / cpu / ir_emitter . cc <nl> StatusOr < llvm : : Function * > IrEmitter : : EmitComputation ( <nl> arch_type_ = = llvm : : Triple : : ArchType : : x86_64 ; <nl> profiling_state_ = ProfilingState ( use_rdtscp ) ; <nl> <nl> - tracing_state_ . set_enabled ( <nl> - computation - > parent ( ) - > config ( ) . cpu_traceme_enabled ( ) ) ; <nl> + bool emit_tracing = <nl> + hlo_module_config_ . hlo_profiling_enabled ( ) & & <nl> + hlo_module_config_ . debug_options ( ) . xla_backend_extra_options ( ) . count ( <nl> + " xla_hlo_trace " ) ; <nl> + tracing_state_ . set_enabled ( emit_tracing ) ; <nl> <nl> TF_RETURN_IF_ERROR ( computation - > AcceptOrdered ( this , instruction_order ) ) ; <nl> llvm : : Function * ir_function = compute_function_ - > function ( ) ; <nl> mmm a / tensorflow / compiler / xla / service / hlo_module_config . h <nl> ppp b / tensorflow / compiler / xla / service / hlo_module_config . h <nl> class HloModuleConfig { <nl> return debug_options_ . xla_hlo_profile ( ) ; <nl> } <nl> <nl> - bool cpu_traceme_enabled ( ) const { <nl> - return debug_options_ . xla_cpu_enable_xprof_traceme ( ) ; <nl> - } <nl> - <nl> / / Sets / returns the module seed set during execution . <nl> void set_seed ( uint64 seed ) { seed_ = seed ; } <nl> uint64 seed ( ) const { return seed_ ; } <nl> mmm a / tensorflow / compiler / xla / xla . proto <nl> ppp b / tensorflow / compiler / xla / xla . proto <nl> message DebugOptions { <nl> bool xla_tpu_detect_nan = 135 ; <nl> bool xla_tpu_detect_inf = 136 ; <nl> <nl> - / / True if TraceMe annotations are enabled for XLA : CPU . <nl> - bool xla_cpu_enable_xprof_traceme = 137 ; <nl> - <nl> - / / Next id : 138 <nl> + / / Next id : 137 <nl> <nl> / / Extra options to pass to the compilation backend ( e . g . LLVM ) ; specific <nl> / / interpretation of these values is left to the backend . <nl>
Have XLA CPU emit TraceMe calls by default in JIT mode
tensorflow/tensorflow
035e2160fedd6706b85a2fd8c46ec437bb6269c4
2020-04-10T02:28:51Z
mmm a / src / app / models / connectionsmanager . cpp <nl> ppp b / src / app / models / connectionsmanager . cpp <nl> void ConnectionsManager : : updateConnection ( const ServerConfig & config ) <nl> return ; <nl> <nl> serverItem - > setName ( config . name ( ) ) ; <nl> + auto operations = serverItem - > getOperations ( ) . dynamicCast < TreeOperations > ( ) ; <nl> + <nl> + if ( ! operations ) <nl> + return ; <nl> + <nl> + operations - > setConnection ( cloneConnection ( connection ) ) ; <nl> <nl> emit dataChanged ( index ( serverItem - > row ( ) , 0 , QModelIndex ( ) ) , <nl> index ( serverItem - > row ( ) , 0 , QModelIndex ( ) ) ) ; <nl> mmm a / src / app / models / treeoperations . cpp <nl> ppp b / src / app / models / treeoperations . cpp <nl> QString TreeOperations : : mode ( ) <nl> return QString ( " standalone " ) ; <nl> } <nl> } <nl> + <nl> + void TreeOperations : : setConnection ( QSharedPointer < RedisClient : : Connection > c ) <nl> + { <nl> + m_connection = c ; <nl> + } <nl> mmm a / src / app / models / treeoperations . h <nl> ppp b / src / app / models / treeoperations . h <nl> class TreeOperations : public QObject , public ConnectionsTree : : Operations , <nl> <nl> virtual QString mode ( ) override ; <nl> <nl> + void setConnection ( QSharedPointer < RedisClient : : Connection > c ) ; <nl> + <nl> private : <nl> QSharedPointer < RedisClient : : Connection > m_connection ; <nl> ConnectionsManager & m_manager ; <nl> mmm a / src / modules / connections - tree / items / serveritem . cpp <nl> ppp b / src / modules / connections - tree / items / serveritem . cpp <nl> bool ServerItem : : isDatabaseListLoaded ( ) const <nl> return isLocked ( ) = = false & & m_databases . size ( ) > 0 ; <nl> } <nl> <nl> + QSharedPointer < Operations > ServerItem : : getOperations ( ) <nl> + { <nl> + return m_operations ; <nl> + } <nl> + <nl> void ServerItem : : load ( ) <nl> { <nl> lock ( ) ; <nl> mmm a / src / modules / connections - tree / items / serveritem . h <nl> ppp b / src / modules / connections - tree / items / serveritem . h <nl> class ServerItem : public QObject , public TreeItem <nl> <nl> bool isDatabaseListLoaded ( ) const ; <nl> <nl> + QSharedPointer < Operations > getOperations ( ) ; <nl> + <nl> private slots : <nl> void load ( ) ; <nl> void unload ( ) ; <nl>
Fix 4173 : Update connection in operations class
uglide/RedisDesktopManager
bcb47eb06b6b6f721acc83a8b8fddfee872e2092
2018-08-06T16:00:22Z
mmm a / jstests / auth / adduser_helper . js <nl> ppp b / jstests / auth / adduser_helper . js <nl> var admin = conn . getDB ( ' admin ' ) ; <nl> db . dropDatabase ( ) ; <nl> admin . dropDatabase ( ) ; <nl> <nl> - / / Can ' t use old - form of addUser helper to make v0 users <nl> - assert . throws ( function ( ) { db . addUser ( ' spencer ' , ' password ' ) ; } ) ; <nl> - / / Can ' t create old - style entries with new addUser helper . <nl> - assert . throws ( function ( ) { db . addUser ( { user : ' noroles ' , pwd : ' password ' } ) ; } ) ; <nl> + / / Test that the deprecated ( username , password , readonly ) form of addUser still works <nl> + db . addUser ( ' dbReadWrite ' , ' x ' ) ; <nl> + var userObj = db . getUser ( ' dbReadWrite ' ) ; <nl> + assert . eq ( 1 , userObj . roles . length ) ; <nl> + assert . eq ( " dbOwner " , userObj . roles [ 0 ] . role ) ; <nl> + assert . eq ( db . getName ( ) , userObj . roles [ 0 ] . db ) ; <nl> + <nl> + db . addUser ( ' dbReadOnly ' , ' x ' , true ) ; <nl> + userObj = db . getUser ( ' dbReadOnly ' ) ; <nl> + assert . eq ( 1 , userObj . roles . length ) ; <nl> + assert . eq ( " read " , userObj . roles [ 0 ] . role ) ; <nl> + assert . eq ( db . getName ( ) , userObj . roles [ 0 ] . db ) ; <nl> + <nl> + admin . addUser ( ' adminReadWrite ' , ' x ' ) ; <nl> + userObj = admin . getUser ( ' adminReadWrite ' ) ; <nl> + assert . eq ( 1 , userObj . roles . length ) ; <nl> + assert . eq ( " root " , userObj . roles [ 0 ] . role ) ; <nl> + assert . eq ( " admin " , userObj . roles [ 0 ] . db ) ; <nl> + <nl> + admin . addUser ( ' adminReadOnly ' , ' x ' , true ) ; <nl> + userObj = admin . getUser ( ' adminReadOnly ' ) ; <nl> + assert . eq ( 1 , userObj . roles . length ) ; <nl> + assert . eq ( " readAnyDatabase " , userObj . roles [ 0 ] . role ) ; <nl> + assert . eq ( " admin " , userObj . roles [ 0 ] . db ) ; <nl> + <nl> + admin . dropDatabase ( ) ; <nl> <nl> / / Create valid V2 format user <nl> db . addUser ( { user : ' andy ' , pwd : ' password ' , roles : [ ' read ' ] } ) ; <nl> userObj = admin . system . users . findOne ( { user : ' spencer ' , db : ' $ external ' } ) ; <nl> assert . eq ( ' spencer ' , userObj [ ' user ' ] ) ; <nl> assert . eq ( ' $ external ' , userObj [ ' db ' ] ) ; <nl> assert ( ! userObj [ ' credentials ' ] ) ; <nl> - <nl> - <nl> - / / Create valid V2 format user using new helper format <nl> - db . addUser ( ' bob ' , ' password ' , [ ' read ' ] ) ; <nl> - assert . eq ( 3 , admin . system . users . count ( ) ) ; <nl> - userObj = admin . system . users . findOne ( { user : ' bob ' } ) ; <nl> - assert . eq ( ' bob ' , userObj [ ' user ' ] ) ; <nl> - assert . eq ( passwordHash ( ' bob ' , ' password ' ) , userObj [ ' credentials ' ] [ ' MONGODB - CR ' ] ) ; <nl> mmm a / jstests / auth / auth1 . js <nl> ppp b / jstests / auth / auth1 . js <nl> tRO = dbRO [ baseName ] ; <nl> <nl> db . dropAllUsers ( ) ; <nl> <nl> - db . getSisterDB ( " admin " ) . addUser ( " super " , " super " , [ " __system " ] ) ; <nl> + db . getSisterDB ( " admin " ) . addUser ( { user : " super " , pwd : " super " , roles : [ " __system " ] } ) ; <nl> db . getSisterDB ( " admin " ) . auth ( " super " , " super " ) ; <nl> - db . addUser ( " eliot " , " eliot " , jsTest . basicUserRoles ) ; <nl> - db . addUser ( " guest " , " guest " , jsTest . readOnlyUserRoles ) ; <nl> + db . addUser ( { user : " eliot " , pwd : " eliot " , roles : jsTest . basicUserRoles } ) ; <nl> + db . addUser ( { user : " guest " , pwd : " guest " , roles : jsTest . readOnlyUserRoles } ) ; <nl> db . getSisterDB ( " admin " ) . logout ( ) ; <nl> <nl> assert . throws ( function ( ) { t . findOne ( ) } , [ ] , " read without login " ) ; <nl> mmm a / jstests / auth / auth2 . js <nl> ppp b / jstests / auth / auth2 . js <nl> t . drop ( ) ; <nl> users = db . getCollection ( " system . users " ) ; <nl> assert . eq ( 0 , users . count ( ) ) ; <nl> <nl> - db . addUser ( " eliot " , " eliot " , jsTest . adminUserRoles ) ; <nl> + db . addUser ( { user : " eliot " , pwd : " eliot " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> assert . throws ( function ( ) { db . users . count ( ) ; } ) <nl> <nl> mmm a / jstests / auth / auth3 . js <nl> ppp b / jstests / auth / auth3 . js <nl> var conn = MongoRunner . runMongod ( { auth : " " , port : 31001 } ) ; <nl> <nl> var admin = conn . getDB ( " admin " ) ; <nl> <nl> - admin . addUser ( " foo " , " bar " , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> print ( " make sure curop , killop , and unlock fail " ) ; <nl> <nl> mmm a / jstests / auth / auth_helpers . js <nl> ppp b / jstests / auth / auth_helpers . js <nl> var admin = conn . getDB ( ' admin ' ) ; <nl> <nl> var testedSomething = false ; <nl> <nl> - admin . addUser ( ' andy ' , ' a ' , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : ' andy ' , pwd : ' a ' , roles : jsTest . adminUserRoles } ) ; <nl> <nl> / / If the server supports them MONGODB - CR , try all the ways to call db . auth that use MONGODB - CR . <nl> if ( hasMongoCR ) { <nl> mmm a / jstests / auth / basic_role_auth . js <nl> ppp b / jstests / auth / basic_role_auth . js <nl> var testOps = function ( db , allowedActions ) { <nl> } ) ; <nl> <nl> checkErr ( allowedActions . hasOwnProperty ( ' user_w ' ) , function ( ) { <nl> - db . addUser ( ' a ' , ' a ' , jsTest . basicUserRoles ) ; <nl> + db . addUser ( { user : ' a ' , pwd : ' a ' , roles : jsTest . basicUserRoles } ) ; <nl> db . dropUser ( ' a ' ) ; <nl> } , db ) ; <nl> <nl> var runTests = function ( conn ) { <nl> } <nl> <nl> adminDB . addUser ( { user : ' root ' , pwd : AUTH_INFO . admin . root . pwd , <nl> - roles : AUTH_INFO . admin . root . roles } ) ; <nl> + roles : AUTH_INFO . admin . root . roles } ) ; <nl> adminDB . auth ( ' root ' , AUTH_INFO . admin . root . pwd ) ; <nl> <nl> for ( var dbName in AUTH_INFO ) { <nl> mmm a / jstests / auth / db_multiple_login . js <nl> ppp b / jstests / auth / db_multiple_login . js <nl> var conn = MongoRunner . runMongod ( { auth : " " , smallfiles : " " } ) ; <nl> var admin = conn . getDB ( " admin " ) ; <nl> var test = conn . getDB ( " test " ) ; <nl> <nl> - admin . addUser ( ' admin ' , ' a ' , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : ' admin ' , pwd : ' a ' , roles : jsTest . adminUserRoles } ) ; <nl> assert ( admin . auth ( ' admin ' , ' a ' ) ) ; <nl> test . addUser ( { user : ' reader ' , pwd : ' a ' , roles : [ " read " ] } ) ; <nl> test . addUser ( { user : ' writer ' , pwd : ' a ' , roles : [ " readWrite " ] } ) ; <nl> mmm a / jstests / auth / js_scope_leak . js <nl> ppp b / jstests / auth / js_scope_leak . js <nl> var test = conn . getDB ( " test " ) ; <nl> test . foo . insert ( { a : 1 } ) ; <nl> test . getLastError ( ) ; <nl> assert . eq ( 1 , test . foo . findOne ( ) . a ) ; <nl> - test . addUser ( ' a ' , ' a ' , jsTest . basicUserRoles ) ; <nl> - test . addUser ( ' b ' , ' b ' , jsTest . basicUserRoles ) ; <nl> + test . addUser ( { user : ' a ' , pwd : ' a ' , roles : jsTest . basicUserRoles } ) ; <nl> + test . addUser ( { user : ' b ' , pwd : ' b ' , roles : jsTest . basicUserRoles } ) ; <nl> <nl> function missingOrEquals ( string ) { <nl> return ' function ( ) { ' <nl> mmm a / jstests / auth / localhostAuthBypass . js <nl> ppp b / jstests / auth / localhostAuthBypass . js <nl> var host = " localhost : " + port ; <nl> <nl> var addUser = function ( mongo ) { <nl> print ( " = = = = = = = = = = = = adding a user . " ) ; <nl> - mongo . getDB ( " admin " ) . addUser ( username , password , jsTest . adminUserRoles ) ; <nl> + mongo . getDB ( " admin " ) . addUser ( { user : username , pwd : password , roles : jsTest . adminUserRoles } ) ; <nl> } ; <nl> <nl> var assertCannotRunCommands = function ( mongo ) { <nl> mmm a / jstests / auth / log_user_basic . js <nl> ppp b / jstests / auth / log_user_basic . js <nl> var doTest = function ( conn1 , conn2 ) { <nl> <nl> var loginUser = function ( connInfo , connAuth ) { <nl> var db = connInfo . mongo . getDB ( connAuth . db ) ; <nl> - db . addUser ( connAuth . user , connAuth . pwd ) ; <nl> + db . addUser ( { user : connAuth . user , pwd : connAuth . pwd , roles : jsTest . adminUserRoles } ) ; <nl> db . auth ( connAuth . user , connAuth . pwd ) ; <nl> connInfo . users [ connAuth . db ] = connAuth . user ; <nl> } ; <nl> mmm a / jstests / auth / log_userid_off . js <nl> ppp b / jstests / auth / log_userid_off . js <nl> var doTest = function ( mongo , callSetParam ) { <nl> var TEST_PWD = ' bar ' ; <nl> var testDB = mongo . getDB ( ' test ' ) ; <nl> <nl> - testDB . addUser ( TEST_USER , TEST_PWD , jsTest . basicUserRoles ) ; <nl> + testDB . addUser ( { user : TEST_USER , pwd : TEST_PWD , roles : jsTest . basicUserRoles } ) ; <nl> testDB . auth ( TEST_USER , TEST_PWD ) ; <nl> <nl> testDB . runCommand ( { dbStats : 1 } ) ; <nl> mmm a / jstests / auth / mr_auth . js <nl> ppp b / jstests / auth / mr_auth . js <nl> for ( var i = 0 ; i < 1000 ; i + + ) t . insert ( { _id : i , x : i % 10 , y : i % 100 } ) ; <nl> assert . eq ( 1000 , t . count ( ) , " inserts failed " ) ; <nl> <nl> d . dropAllUsers ( ) ; <nl> - d . getSisterDB ( " admin " ) . addUser ( " admin " , " admin " , jsTest . adminUserRoles ) ; <nl> + d . getSisterDB ( " admin " ) . addUser ( { user : " admin " , pwd : " admin " , roles : jsTest . adminUserRoles } ) ; <nl> d . getSisterDB ( " admin " ) . auth ( ' admin ' , ' admin ' ) ; <nl> - d . addUser ( " write " , " write " , jsTest . basicUserRoles ) ; <nl> - d . addUser ( " read " , " read " , jsTest . readOnlyUserRoles ) ; <nl> + d . addUser ( { user : " write " , pwd : " write " , roles : jsTest . basicUserRoles } ) ; <nl> + d . addUser ( { user : " read " , pwd : " read " , roles : jsTest . readOnlyUserRoles } ) ; <nl> d . getSisterDB ( " admin " ) . logout ( ) ; <nl> <nl> t . mapReduce ( map , red , { out : { inline : 1 } } ) <nl> mmm a / jstests / auth / profile . js <nl> ppp b / jstests / auth / profile . js <nl> var conn = startMongodTest ( ) ; <nl> var db1 = conn . getDB ( " profile - a " ) ; <nl> var db2 = db1 . getSisterDB ( " profile - b " ) ; <nl> var username = " user " ; <nl> - db1 . addUser ( username , " password " , jsTest . basicUserRoles ) ; <nl> - db2 . addUser ( username , " password " , jsTest . basicUserRoles ) ; <nl> + db1 . addUser ( { user : username , pwd : " password " , roles : jsTest . basicUserRoles } ) ; <nl> + db2 . addUser ( { user : username , pwd : " password " , roles : jsTest . basicUserRoles } ) ; <nl> <nl> <nl> function lastOp ( db ) { <nl> mmm a / jstests / auth / readIndex . js <nl> ppp b / jstests / auth / readIndex . js <nl> var testDB = conn . getDB ( " testdb " ) ; <nl> testDB . foo . insert ( { a : 1 } ) ; <nl> <nl> testDB . addUser ( { user : ' dbAdmin ' , <nl> - pwd : ' password ' , <nl> - roles : [ ' dbAdmin ' ] } ) ; <nl> + pwd : ' password ' , <nl> + roles : [ ' dbAdmin ' ] } ) ; <nl> <nl> testDB . auth ( ' dbAdmin ' , ' password ' ) ; <nl> testDB . foo . ensureIndex ( { a : 1 } ) ; <nl> mmm a / jstests / auth / rename . js <nl> ppp b / jstests / auth / rename . js <nl> db2 = m . getDB ( baseName + ' _other ' ) <nl> admin = m . getDB ( ' admin ' ) <nl> <nl> / / Setup initial data <nl> - admin . addUser ( ' admin ' , ' password ' , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : ' admin ' , pwd : ' password ' , roles : jsTest . adminUserRoles } ) ; <nl> admin . auth ( ' admin ' , ' password ' ) <nl> <nl> - db1 . addUser ( " foo " , " bar " , jsTest . basicUserRoles ) ; <nl> - db2 . addUser ( " bar " , " foo " , jsTest . basicUserRoles ) ; <nl> + db1 . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . basicUserRoles } ) ; <nl> + db2 . addUser ( { user : " bar " , pwd : " foo " , roles : jsTest . basicUserRoles } ) ; <nl> <nl> printjson ( db1 . a . count ( ) ) ; <nl> db1 . a . save ( { } ) ; <nl> mmm a / jstests / auth / server - 4892 . js <nl> ppp b / jstests / auth / server - 4892 . js <nl> with_mongod ( [ ' - - noauth ' ] , function setupTest ( mongod ) { <nl> conn = new Mongo ( mongod . host ) ; <nl> admin = conn . getDB ( ' admin ' ) ; <nl> somedb = conn . getDB ( ' somedb ' ) ; <nl> - admin . addUser ( ' admin ' , ' admin ' , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : ' admin ' , pwd : ' admin ' , roles : jsTest . adminUserRoles } ) ; <nl> admin . auth ( ' admin ' , ' admin ' ) ; <nl> - somedb . addUser ( ' frim ' , ' fram ' , jsTest . basicUserRoles ) ; <nl> + somedb . addUser ( { user : ' frim ' , pwd : ' fram ' , roles : jsTest . basicUserRoles } ) ; <nl> somedb . data . drop ( ) ; <nl> for ( var i = 0 ; i < 10 ; + + i ) { <nl> somedb . data . insert ( { val : i } ) ; <nl> mmm a / jstests / auth / show_log_auth . js <nl> ppp b / jstests / auth / show_log_auth . js <nl> var baseName = " jstests_show_log_auth " ; <nl> var m = startMongod ( " - - auth " , " - - port " , port , " - - dbpath " , " / data / db / " + baseName , " - - nohttpinterface " , " - - bind_ip " , " 127 . 0 . 0 . 1 " , " - - nojournal " , " - - smallfiles " ) ; <nl> var db = m . getDB ( " admin " ) ; <nl> <nl> - db . addUser ( " admin " , " pass " , jsTest . adminUserRoles ) ; <nl> + db . addUser ( { user : " admin " , pwd : " pass " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> / / Temporarily capture this shell ' s print ( ) output <nl> var oldprint = print , printed = [ ] ; <nl> mmm a / jstests / auth / system_user_privileges . js <nl> ppp b / jstests / auth / system_user_privileges . js <nl> <nl> / / <nl> / / Preliminary set up . <nl> / / <nl> - admin . addUser ( ' admin ' , ' a ' , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : ' admin ' , pwd : ' a ' , roles : jsTest . adminUserRoles } ) ; <nl> admin . auth ( ' admin ' , ' a ' ) ; <nl> <nl> / / <nl> mmm a / jstests / auth1 . js <nl> ppp b / jstests / auth1 . js <nl> db . dropAllUsers ( ) ; <nl> pass = " a " + Math . random ( ) ; <nl> / / print ( " password [ " + pass + " ] " ) ; <nl> <nl> - db . addUser ( " eliot " , pass , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : " eliot " , pwd : pass , roles : jsTest . basicUserRoles } ) ; <nl> <nl> assert ( db . auth ( " eliot " , pass ) , " auth failed " ) ; <nl> assert ( ! db . auth ( " eliot " , pass + " a " ) , " auth should have failed " ) ; <nl> assert ( ! db . auth ( " eliot " , pass2 ) , " didn ' t drop user " ) ; <nl> var a = db . getMongo ( ) . getDB ( " admin " ) ; <nl> a . dropAllUsers ( ) ; <nl> pass = " c " + Math . random ( ) ; <nl> - a . addUser ( " super " , pass , jsTest . adminUserRoles , 1 ) ; <nl> + a . addUser ( { user : " super " , pwd : pass , roles : jsTest . adminUserRoles } ) ; <nl> assert ( a . auth ( " super " , pass ) , " auth failed " ) ; <nl> assert ( ! a . auth ( " super " , pass + " a " ) , " auth should have failed " ) ; <nl> <nl> db . dropAllUsers ( ) ; <nl> pass = " a " + Math . random ( ) ; <nl> <nl> - db . addUser ( " eliot " , pass , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : " eliot " , pwd : pass , roles : jsTest . basicUserRoles } ) ; <nl> <nl> assert . commandFailed ( db . runCommand ( { authenticate : 1 , user : " eliot " , nonce : " foo " , key : " bar " } ) ) ; <nl> <nl> assert . commandFailed ( db . runCommand ( { authenticate : 1 , user : " eliot " , nonce : " f <nl> before = a . system . users . count ( ) <nl> <nl> assert . throws ( function ( ) { <nl> - db . addUser ( " " , " abc " , jsTest . basicUserRoles , 1 ) <nl> + db . addUser ( { user : " " , pwd : " abc " , roles : jsTest . basicUserRoles } ) ; <nl> } , null , " C1 " ) <nl> assert . throws ( function ( ) { <nl> - db . addUser ( " abc " , " " , jsTest . basicUserRoles , 1 ) <nl> + db . addUser ( { user : " abc " , pwd : " " , roles : jsTest . basicUserRoles } ) ; <nl> } , null , " C2 " ) <nl> <nl> <nl> mmm a / jstests / auth_copydb2 . js <nl> ppp b / jstests / auth_copydb2 . js <nl> b . dropAllUsers ( ) ; <nl> <nl> a . foo . save ( { a : 1 } ) ; <nl> <nl> - a . addUser ( " chevy " , " chase " , jsTest . basicUserRoles , 1 ) ; <nl> + a . addUser ( { user : " chevy " , pwd : " chase " , roles : jsTest . basicUserRoles } ) ; <nl> <nl> assert . eq ( 1 , a . foo . count ( ) , " A " ) ; <nl> assert . eq ( 0 , b . foo . count ( ) , " B " ) ; <nl> mmm a / jstests / connection_status . js <nl> ppp b / jstests / connection_status . js <nl> var myDB = db . getSiblingDB ( dbName ) ; <nl> myDB . dropAllUsers ( ) ; <nl> <nl> function test ( userName ) { <nl> - myDB . addUser ( userName , " weak password " , jsTest . basicUserRoles ) ; <nl> + myDB . addUser ( { user : userName , pwd : " weak password " , roles : jsTest . basicUserRoles } ) ; <nl> myDB . auth ( userName , " weak password " ) ; <nl> <nl> var output = myDB . runCommand ( " connectionStatus " ) ; <nl> mmm a / jstests / evalb . js <nl> ppp b / jstests / evalb . js <nl> function lastOp ( ) { <nl> try { <nl> <nl> username = ' jstests_evalb_user ' ; <nl> - db . addUser ( username , ' password ' , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : username , pwd : ' password ' , roles : jsTest . basicUserRoles } ) ; <nl> db . auth ( username , ' password ' ) ; <nl> <nl> t = db . evalb ; <nl> mmm a / jstests / profile1 . js <nl> ppp b / jstests / profile1 . js <nl> db . dropDatabase ( ) ; <nl> try { <nl> <nl> username = " jstests_profile1_user " ; <nl> - db . addUser ( username , " password " , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : username , pwd : " password " , roles : jsTest . basicUserRoles } ) ; <nl> db . auth ( username , " password " ) ; <nl> <nl> function profileCursor ( query ) { <nl> mmm a / jstests / profile3 . js <nl> ppp b / jstests / profile3 . js <nl> profileCursor = function ( query ) { <nl> <nl> try { <nl> username = " jstests_profile3_user " ; <nl> - db . addUser ( username , " password " , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : username , pwd : " password " , roles : jsTest . basicUserRoles } ) ; <nl> db . auth ( username , " password " ) ; <nl> <nl> db . setProfilingLevel ( 0 ) ; <nl> mmm a / jstests / profile4 . js <nl> ppp b / jstests / profile4 . js <nl> function checkLastOp ( spec ) { <nl> <nl> try { <nl> username = " jstests_profile4_user " ; <nl> - db . addUser ( username , " password " , jsTest . basicUserRoles , 1 ) ; <nl> + db . addUser ( { user : username , pwd : " password " , roles : jsTest . basicUserRoles } ) ; <nl> db . auth ( username , " password " ) ; <nl> <nl> db . setProfilingLevel ( 0 ) ; <nl> mmm a / jstests / repl / repl_auth . js <nl> ppp b / jstests / repl / repl_auth . js <nl> var baseName = " jstests_repl11test " ; <nl> var keyFilePath = " jstests / libs / key1 " ; <nl> <nl> setAdmin = function ( n ) { <nl> - n . getDB ( " admin " ) . addUser ( " super " , " super " , jsTest . adminUserRoles , 3 ) ; <nl> + n . getDB ( " admin " ) . addUser ( { user : " super " , pwd : " super " , roles : jsTest . adminUserRoles } , 3 ) ; <nl> } <nl> <nl> auth = function ( n ) { <nl> doTest = function ( signal , extraOpts ) { <nl> rt = new ReplTest ( baseName ) ; <nl> <nl> m = rt . start ( true , { } , false , true ) ; <nl> - m . getDB ( baseName ) . addUser ( " test " , " test " , jsTest . basicUserRoles , 3 ) ; <nl> + m . getDB ( baseName ) . addUser ( { user : " test " , pwd : " test " , roles : jsTest . basicUserRoles } , 3 ) ; <nl> <nl> setAdmin ( m ) ; <nl> rt . stop ( true ) ; <nl> mmm a / jstests / replsets / auth1 . js <nl> ppp b / jstests / replsets / auth1 . js <nl> run ( " chmod " , " 600 " , path + " key2 " ) ; <nl> <nl> print ( " add a user to server0 : foo " ) ; <nl> m = startMongodTest ( port [ 0 ] , name + " - 0 " , 0 ) ; <nl> - m . getDB ( " admin " ) . addUser ( " foo " , " bar " , jsTest . adminUserRoles ) ; <nl> - m . getDB ( " test " ) . addUser ( " bar " , " baz " , jsTest . basicUserRoles ) ; <nl> + m . getDB ( " admin " ) . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . adminUserRoles } ) ; <nl> + m . getDB ( " test " ) . addUser ( { user : " bar " , pwd : " baz " , roles : jsTest . basicUserRoles } ) ; <nl> print ( " make sure user is written before shutting down " ) ; <nl> m . getDB ( " test " ) . getLastError ( ) ; <nl> stopMongod ( port [ 0 ] ) ; <nl> mmm a / jstests / replsets / auth2 . js <nl> ppp b / jstests / replsets / auth2 . js <nl> var rs = setupReplSet ( ) ; <nl> var master = rs . getMaster ( ) ; <nl> <nl> print ( " add an admin user " ) ; <nl> - master . getDB ( " admin " ) . addUser ( " foo " , " bar " , jsTest . adminUserRoles , 3 ) ; <nl> + master . getDB ( " admin " ) . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . adminUserRoles } , 3 ) ; <nl> m = rs . nodes [ 0 ] ; <nl> <nl> print ( " starting 1 and 2 with key file " ) ; <nl> mmm a / jstests / replsets / auth3 . js <nl> ppp b / jstests / replsets / auth3 . js <nl> rs . initiate ( ) ; <nl> <nl> master = rs . getMaster ( ) ; <nl> print ( " adding user " ) ; <nl> - master . getDB ( " admin " ) . addUser ( " foo " , " bar " , jsTest . adminUserRoles , 2 ) ; <nl> + master . getDB ( " admin " ) . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . adminUserRoles } , 2 ) ; <nl> <nl> var checkValidState = function ( i ) { <nl> assert . soon ( function ( ) { <nl> mmm a / jstests / replsets / localhostAuthBypass . js <nl> ppp b / jstests / replsets / localhostAuthBypass . js <nl> var password = " bar " ; <nl> <nl> var addUser = function ( mongo ) { <nl> print ( " = = = = = = = = = = = = adding a user . " ) ; <nl> - mongo . getDB ( " admin " ) . addUser ( username , password , jsTest . adminUserRoles ) ; <nl> + mongo . getDB ( " admin " ) . addUser ( { user : username , pwd : password , roles : jsTest . adminUserRoles } ) ; <nl> } ; <nl> <nl> var assertCannotRunCommands = function ( mongo ) { <nl> mmm a / jstests / sharding / auth . js <nl> ppp b / jstests / sharding / auth . js <nl> if ( user ) { <nl> } <nl> else { <nl> print ( " adding user " ) ; <nl> - s . getDB ( adminUser . db ) . addUser ( adminUser . username , adminUser . password , jsTest . adminUserRoles ) ; <nl> + s . getDB ( adminUser . db ) . addUser ( { user : adminUser . username , pwd : adminUser . password , roles : jsTest . adminUserRoles } ) ; <nl> } <nl> <nl> login ( adminUser ) ; <nl> s . getDB ( " admin " ) . runCommand ( { shardCollection : " test . foo " , key : { x : 1 } } ) ; <nl> <nl> d1 . waitForState ( d1 . getSecondaries ( ) , d1 . SECONDARY , 5 * 60 * 1000 ) <nl> <nl> - s . getDB ( testUser . db ) . addUser ( testUser . username , testUser . password , jsTest . basicUserRoles , 3 ) <nl> + s . getDB ( testUser . db ) . addUser ( { user : testUser . username , pwd : testUser . password , roles : jsTest . basicUserRoles } , 3 ) <nl> s . getDB ( testUserReadOnly . db ) . addUser ( testUserReadOnly . username , <nl> testUserReadOnly . password , <nl> jsTest . readOnlyUserRoles , <nl> mmm a / jstests / sharding / auth2 . js <nl> ppp b / jstests / sharding / auth2 . js <nl> var mongos = st . s ; <nl> var adminDB = mongos . getDB ( ' admin ' ) ; <nl> var db = mongos . getDB ( ' test ' ) <nl> <nl> - adminDB . addUser ( ' admin ' , ' password ' , jsTest . adminUserRoles ) ; <nl> + adminDB . addUser ( { user : ' admin ' , pwd : ' password ' , roles : jsTest . adminUserRoles } ) ; <nl> <nl> jsTestLog ( " Add user was successful " ) ; <nl> <nl> mmm a / jstests / sharding / authCommands . js <nl> ppp b / jstests / sharding / authCommands . js <nl> var rwUser = ' rwUser ' ; <nl> var roUser = ' roUser ' ; <nl> var password = ' password ' ; <nl> <nl> - adminDB . addUser ( rwUser , password , false , st . rs0 . numNodes ) ; <nl> + adminDB . addUser ( { user : rwUser , pwd : password , roles : jsTest . basicUserRoles } , st . rs0 . numNodes ) ; <nl> <nl> assert ( adminDB . auth ( rwUser , password ) ) ; <nl> adminDB . addUser ( roUser , password , true ) ; <nl> - testDB . addUser ( rwUser , password , false , st . rs0 . numNodes ) ; <nl> - testDB . addUser ( roUser , password , true , st . rs0 . numNodes ) ; <nl> + testDB . addUser ( { user : rwUser , pwd : password , roles : jsTest . basicUserRoles } , st . rs0 . numNodes ) ; <nl> + testDB . addUser ( { user : roUser , pwd : password , roles : jsTest . basicUserRoles } , st . rs0 . numNodes ) ; <nl> <nl> authenticatedConn = new Mongo ( mongos . host ) ; <nl> authenticatedConn . getDB ( ' admin ' ) . auth ( rwUser , password ) ; <nl> <nl> / / Add user to shards to prevent localhost connections from having automatic full access <nl> - st . rs0 . getPrimary ( ) . getDB ( ' admin ' ) . addUser ( ' user ' , ' password ' , false , 3 ) ; <nl> - st . rs1 . getPrimary ( ) . getDB ( ' admin ' ) . addUser ( ' user ' , ' password ' , false , 3 ) ; <nl> + st . rs0 . getPrimary ( ) . getDB ( ' admin ' ) . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . basicUserRoles } , 3 ) ; <nl> + st . rs1 . getPrimary ( ) . getDB ( ' admin ' ) . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . basicUserRoles } , 3 ) ; <nl> <nl> <nl> <nl> mmm a / jstests / sharding / authConnectionHook . js <nl> ppp b / jstests / sharding / authConnectionHook . js <nl> var mongos = st . s ; <nl> var adminDB = mongos . getDB ( ' admin ' ) ; <nl> var db = mongos . getDB ( ' test ' ) <nl> <nl> - adminDB . addUser ( ' admin ' , ' password ' , jsTest . adminUserRoles ) ; <nl> + adminDB . addUser ( { user : ' admin ' , pwd : ' password ' , roles : jsTest . adminUserRoles } ) ; <nl> <nl> adminDB . auth ( ' admin ' , ' password ' ) ; <nl> <nl> mmm a / jstests / sharding / auth_add_shard . js <nl> ppp b / jstests / sharding / auth_add_shard . js <nl> if ( user ) { <nl> } <nl> else { <nl> print ( " adding user " ) ; <nl> - mongos . getDB ( adminUser . db ) . addUser ( adminUser . username , adminUser . password , jsTest . adminUserRoles ) ; <nl> + mongos . getDB ( adminUser . db ) . addUser ( { user : adminUser . username , pwd : adminUser . password , roles : jsTest . adminUserRoles } ) ; <nl> } <nl> <nl> / / login as admin user <nl> mmm a / jstests / sharding / auth_copydb . js <nl> ppp b / jstests / sharding / auth_copydb . js <nl> var sourceTestDB = sourceMongodConn . getDB ( ' test ' ) ; <nl> <nl> sourceTestDB . foo . insert ( { a : 1 } ) ; <nl> <nl> - destAdminDB . addUser ( ' admin ' , ' password ' ) ; / / Turns on access control enforcement <nl> + destAdminDB . addUser ( { user : ' admin ' , pwd : ' password ' , roles : jsTest . adminUserRoles } ) ; / / Turns on access control enforcement <nl> <nl> jsTestLog ( " Running copydb that should fail " ) ; <nl> var res = destAdminDB . runCommand ( { copydb : 1 , <nl> mmm a / jstests / sharding / auth_repl . js <nl> ppp b / jstests / sharding / auth_repl . js <nl> assert ( doc ! = null ) ; <nl> <nl> / / Add admin user using direct connection to primary to simulate connection from remote host <nl> var adminDB = primary . getDB ( ' admin ' ) ; <nl> - adminDB . addUser ( ' user ' , ' user ' , jsTest . adminUserRoles , nodeCount ) ; <nl> + adminDB . addUser ( { user : ' user ' , pwd : ' user ' , roles : jsTest . adminUserRoles } , nodeCount ) ; <nl> adminDB . auth ( ' user ' , ' user ' ) ; <nl> <nl> var priTestDB = primary . getDB ( ' test ' ) ; <nl> - priTestDB . addUser ( ' a ' , ' a ' , jsTest . basicUserRoles , nodeCount ) ; <nl> + priTestDB . addUser ( { user : ' a ' , pwd : ' a ' , roles : jsTest . basicUserRoles } , nodeCount ) ; <nl> <nl> / / Authenticate the replSet connection <nl> assert . eq ( 1 , testDB . auth ( ' a ' , ' a ' ) ) ; <nl> mmm a / jstests / sharding / auth_slaveok_routing . js <nl> ppp b / jstests / sharding / auth_slaveok_routing . js <nl> var nodeCount = replTest . nodes . length ; <nl> * is no admin user . <nl> * / <nl> var adminDB = mongos . getDB ( ' admin ' ) <nl> - adminDB . addUser ( ' user ' , ' password ' , jsTest . adminUserRoles ) ; <nl> + adminDB . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . adminUserRoles } ) ; <nl> adminDB . auth ( ' user ' , ' password ' ) ; <nl> var priAdminDB = replTest . getPrimary ( ) . getDB ( ' admin ' ) ; <nl> - priAdminDB . addUser ( ' user ' , ' password ' , jsTest . adminUserRoles , 3 ) ; <nl> + priAdminDB . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . adminUserRoles } , 3 ) ; <nl> <nl> coll . drop ( ) ; <nl> coll . setSlaveOk ( true ) ; <nl> mmm a / jstests / sharding / localhostAuthBypass . js <nl> ppp b / jstests / sharding / localhostAuthBypass . js <nl> var password = " bar " ; <nl> <nl> var addUser = function ( mongo ) { <nl> print ( " = = = = = = = = = = = = adding a user . " ) ; <nl> - mongo . getDB ( " admin " ) . addUser ( username , password , jsTest . adminUserRoles ) ; <nl> + mongo . getDB ( " admin " ) . addUser ( { user : username , pwd : password , roles : jsTest . adminUserRoles } ) ; <nl> } ; <nl> <nl> var addUsersToEachShard = function ( st ) { <nl> for ( i = 0 ; i < numShards ; i + + ) { <nl> print ( " = = = = = = = = = = = = adding a user to shard " + i ) ; <nl> var d = st [ " shard " + i ] ; <nl> - d . getDB ( " admin " ) . addUser ( username , password , jsTest . adminUserRoles ) ; <nl> + d . getDB ( " admin " ) . addUser ( { user : username , pwd : password , roles : jsTest . adminUserRoles } ) ; <nl> } <nl> } ; <nl> <nl> mmm a / jstests / sharding / mrShardedOutputAuth . js <nl> ppp b / jstests / sharding / mrShardedOutputAuth . js <nl> var st = new ShardingTest ( testName = " mrShardedOutputAuth " , <nl> / / setup the users to the input , output and admin databases <nl> var mongos = st . s ; <nl> var adminDb = mongos . getDB ( " admin " ) ; <nl> - adminDb . addUser ( " user " , " pass " , jsTest . adminUserRoles ) ; <nl> + adminDb . addUser ( { user : " user " , pwd : " pass " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> var authenticatedConn = new Mongo ( mongos . host ) ; <nl> authenticatedConn . getDB ( ' admin ' ) . auth ( " user " , " pass " ) ; <nl> adminDb = authenticatedConn . getDB ( " admin " ) ; <nl> var configDb = authenticatedConn . getDB ( " config " ) ; <nl> <nl> var inputDb = authenticatedConn . getDB ( " input " ) <nl> - inputDb . addUser ( " user " , " pass " , jsTest . basicUserRoles , 1 ) ; <nl> + inputDb . addUser ( { user : " user " , pwd : " pass " , roles : jsTest . basicUserRoles } ) ; <nl> <nl> var outputDb = authenticatedConn . getDB ( " output " ) ; <nl> - outputDb . addUser ( " user " , " pass " , jsTest . basicUserRoles ) ; <nl> + outputDb . addUser ( { user : " user " , pwd : " pass " , roles : jsTest . basicUserRoles } ) ; <nl> <nl> / / setup the input db <nl> inputDb . numbers . drop ( ) ; <nl> mmm a / jstests / slowNightly / server7428 . js <nl> ppp b / jstests / slowNightly / server7428 . js <nl> var fromDb = MongoRunner . runMongod ( { port : 29000 } ) ; <nl> / / Setup toDb with auth <nl> var toDb = MongoRunner . runMongod ( { auth : " " , port : 31001 } ) ; <nl> var admin = toDb . getDB ( " admin " ) ; <nl> - admin . addUser ( " foo " , " bar " , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : " foo " , pwd : " bar " , roles : jsTest . adminUserRoles } ) ; <nl> admin . auth ( " foo " , " bar " ) ; <nl> <nl> admin . copyDatabase ( ' test ' , ' test ' , fromDb . host ) <nl> mmm a / jstests / tool / dumpauth . js <nl> ppp b / jstests / tool / dumpauth . js <nl> for ( var i = 0 ; i < 100 ; i + + ) { <nl> t [ " testcol " ] . save ( { " x " : i } ) ; <nl> } <nl> <nl> - db . addUser ( " testuser " , " testuser " , jsTest . adminUserRoles ) ; <nl> + db . addUser ( { user : " testuser " , pwd : " testuser " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> assert ( db . auth ( " testuser " , " testuser " ) , " auth failed " ) ; <nl> <nl> mmm a / jstests / tool / dumprestore5 . js <nl> ppp b / jstests / tool / dumprestore5 . js <nl> t . startDB ( " foo " ) ; <nl> <nl> db = t . db . getSiblingDB ( " admin " ) <nl> <nl> - db . addUser ( ' user ' , ' password ' , jsTest . basicUserRoles ) <nl> + db . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . basicUserRoles } ) ; <nl> <nl> assert . eq ( 1 , db . system . users . count ( ) , " setup " ) <nl> assert . eq ( 2 , db . system . indexes . count ( ) , " setup2 " ) <nl> assert . eq ( 1 , db . system . users . find ( { user : ' user ' } ) . count ( ) , " didn ' t restore users " <nl> assert . eq ( 2 , db . system . indexes . count ( ) , " didn ' t restore indexes " ) <nl> <nl> db . dropUser ( ' user ' ) <nl> - db . addUser ( ' user2 ' , ' password2 ' , jsTest . basicUserRoles ) <nl> + db . addUser ( { user : ' user2 ' , pwd : ' password2 ' , roles : jsTest . basicUserRoles } ) ; <nl> <nl> t . runTool ( " restore " , " - - dir " , t . ext , " - - drop " ) <nl> <nl> mmm a / jstests / tool / dumprestore_auth . js <nl> ppp b / jstests / tool / dumprestore_auth . js <nl> t = new ToolTest ( " dumprestore_auth " , { auth : " " } ) ; <nl> c = t . startDB ( " foo " ) ; <nl> <nl> adminDB = c . getDB ( ) . getSiblingDB ( ' admin ' ) ; <nl> - adminDB . addUser ( ' admin ' , ' password ' , [ ' __system ' ] ) ; <nl> + adminDB . addUser ( { user : ' admin ' , pwd : ' password ' , roles : [ ' __system ' ] } ) ; <nl> adminDB . auth ( ' admin ' , ' password ' ) ; <nl> <nl> assert . eq ( 0 , c . count ( ) , " setup1 " ) ; <nl> mmm a / jstests / tool / restorewithauth . js <nl> ppp b / jstests / tool / restorewithauth . js <nl> conn = startMongod ( " - - auth " , " - - port " , port , " - - dbpath " , " / data / db / " + baseName <nl> <nl> / / admin user <nl> var admin = conn . getDB ( " admin " ) <nl> - admin . addUser ( " admin " , " admin " , jsTest . adminUserRoles ) ; <nl> + admin . addUser ( { user : " admin " , pwd : " admin " , roles : jsTest . adminUserRoles } ) ; <nl> admin . auth ( " admin " , " admin " ) ; <nl> <nl> var foo = conn . getDB ( " foo " ) <nl> foo . dropDatabase ( ) ; <nl> assert . eq ( foo . system . namespaces . count ( { name : " foo . bar " } ) , 0 ) ; <nl> assert . eq ( foo . system . namespaces . count ( { name : " foo . baz " } ) , 0 ) ; <nl> <nl> - foo . addUser ( ' user ' , ' password ' , jsTest . basicUserRoles ) ; <nl> + foo . addUser ( { user : ' user ' , pwd : ' password ' , roles : jsTest . basicUserRoles } ) ; <nl> <nl> / / now try to restore dump with foo database credentials <nl> x = runMongoProgram ( " mongorestore " , <nl> mmm a / jstests / tool / stat1 . js <nl> ppp b / jstests / tool / stat1 . js <nl> t . drop ( ) ; <nl> <nl> db . dropAllUsers ( ) ; <nl> <nl> - db . addUser ( " eliot " , " eliot " , jsTest . adminUserRoles ) ; <nl> + db . addUser ( { user : " eliot " , pwd : " eliot " , roles : jsTest . adminUserRoles } ) ; <nl> <nl> assert ( db . auth ( " eliot " , " eliot " ) , " auth failed " ) ; <nl> <nl> mmm a / jstests / user_management_helpers . js <nl> ppp b / jstests / user_management_helpers . js <nl> function assertHasRole ( rolesArray , roleName , roleDB ) { <nl> db . dropDatabase ( ) ; <nl> db . dropAllUsers ( ) ; <nl> <nl> - db . addUser ( " spencer " , " password " , [ ' readWrite ' ] ) ; <nl> - db . addUser ( " andy " , " password " , [ ' readWrite ' ] ) ; <nl> + db . addUser ( { user : " spencer " , pwd : " password " , roles : [ ' readWrite ' ] } ) ; <nl> + db . addUser ( { user : " andy " , pwd : " password " , roles : [ ' readWrite ' ] } ) ; <nl> <nl> / / Test getUser <nl> var userObj = db . getUser ( ' spencer ' ) ; <nl> mmm a / src / mongo / shell / db . js <nl> ppp b / src / mongo / shell / db . js <nl> function printUserObj ( userObj ) { <nl> / * * <nl> * Used for creating users in systems with v1 style user information ( ie MongoDB v2 . 4 and prior ) <nl> * / <nl> - DB . prototype . _createUserV1 = function ( userObj , replicatedTo , timeout ) { <nl> + DB . prototype . _createUserWithInsert = function ( userObj , replicatedTo , timeout ) { <nl> var c = this . getCollection ( " system . users " ) ; <nl> var oldPwd ; <nl> if ( userObj . pwd ! = null ) { <nl> DB . prototype . _createUserV1 = function ( userObj , replicatedTo , timeout ) { <nl> } <nl> <nl> DB . prototype . _createUser = function ( userObj , replicatedTo , timeout ) { <nl> + var commandExisted = this . _createUserWithCommand ( userObj , replicatedTo , timeout ) ; <nl> + if ( ! commandExisted ) { <nl> + this . _createUserWithInsert ( userObj , replicatedTo , timeout ) ; <nl> + } <nl> + } <nl> + <nl> + / / Returns true if it worked , false if the createUser command wasn ' t found , and throws on all other <nl> + / / failures <nl> + DB . prototype . _createUserWithCommand = function ( userObj , replicatedTo , timeout ) { <nl> var name = userObj [ " user " ] ; <nl> var cmdObj = { createUser : name } ; <nl> cmdObj = Object . extend ( cmdObj , userObj ) ; <nl> DB . prototype . _createUser = function ( userObj , replicatedTo , timeout ) { <nl> <nl> if ( res . ok ) { <nl> printUserObj ( userObj ) ; <nl> - return ; <nl> + return true ; <nl> } <nl> <nl> if ( res . errmsg = = " no such cmd : createUser " ) { <nl> - return this . _createUserV1 ( userObj , replicatedTo , timeout ) ; <nl> + return false ; <nl> } <nl> <nl> / / We can ' t detect replica set shards via mongos , so we ' ll sometimes get this error <nl> DB . prototype . _createUser = function ( userObj , replicatedTo , timeout ) { <nl> / / the user has been written and we ' re happy <nl> if ( res . errmsg = = " norepl " | | res . errmsg = = " noreplset " ) { <nl> / / nothing we can do <nl> - return ; <nl> + return true ; <nl> } <nl> <nl> if ( res . errmsg = = " timeout " ) { <nl> - throw " timed out while waiting for user authentication to replicate - " + <nl> - " database will not be fully secured until replication finishes " <nl> + throw Error ( " timed out while waiting for user authentication to replicate - " + <nl> + " database will not be fully secured until replication finishes " ) ; <nl> } <nl> <nl> - throw " couldn ' t add user : " + res . errmsg ; <nl> + throw Error ( " couldn ' t add user : " + res . errmsg ) ; <nl> } <nl> <nl> function _hashPassword ( username , password ) { <nl> return hex_md5 ( username + " : mongo : " + password ) ; <nl> } <nl> <nl> - DB . prototype . _addUserExplicitArgs = function ( username , password , roles , replicatedTo , timeout ) { <nl> - if ( password = = null | | password . length = = 0 ) { <nl> - throw Error ( " password can ' t be empty " ) ; <nl> + / / We need to continue to support the addUser ( username , password , readOnly ) form of addUser for at <nl> + / / least one release , even though its behavior of creating a super - user by default is bad . <nl> + / / TODO ( spencer ) : remove this form from v2 . 8 <nl> + DB . prototype . _createUserDeprecatedV22Version = function ( username , pass , readOnly , replicatedTo , timeout ) { <nl> + print ( " WARNING : This form of the addUser shell helper ( that takes username , password , " + <nl> + " and readOnly boolean ) is DEPRECATED . Use the form that takes a user object instead " ) ; <nl> + <nl> + if ( pass = = null | | pass . length = = 0 ) <nl> + throw " password can ' t be empty " ; <nl> + <nl> + var userObjForCommand = { user : username , pwd : pass } ; <nl> + if ( this . getName ( ) = = " admin " ) { <nl> + if ( readOnly ) { <nl> + userObjForCommand [ " roles " ] = [ ' readAnyDatabase ' ] ; <nl> + } else { <nl> + userObjForCommand [ " roles " ] = [ ' root ' ] ; <nl> + } <nl> + } else { <nl> + if ( readOnly ) { <nl> + userObjForCommand [ " roles " ] = [ ' read ' ] ; <nl> + } else { <nl> + userObjForCommand [ " roles " ] = [ ' dbOwner ' ] ; <nl> + } <nl> + } <nl> + <nl> + var commandExisted = this . _createUserWithCommand ( userObjForCommand , replicatedTo , timeout ) ; <nl> + if ( ! commandExisted ) { <nl> + var userObjForInsert = { user : username , pwd : pass , readOnly : readOnly | | false } ; <nl> + this . _createUserWithInsert ( userObjForInsert , replicatedTo , timeout ) ; <nl> } <nl> - var userObj = { user : arguments [ 0 ] , pwd : arguments [ 1 ] , roles : arguments [ 2 ] } ; <nl> - this . _createUser ( userObj , replicatedTo , timeout ) ; <nl> } <nl> <nl> / / TODO ( spencer ) : properly handle write concern objects in addUser <nl> DB . prototype . addUser = function ( ) { <nl> <nl> if ( typeof arguments [ 0 ] = = " object " ) { <nl> this . _createUser . apply ( this , arguments ) ; <nl> - } else if ( Array . isArray ( arguments [ 2 ] ) ) { <nl> - this . _addUserExplicitArgs . apply ( this , arguments ) ; <nl> } else { <nl> - throw Error ( " Invalid arguments to addUser . addUser must either be run with a full user " + <nl> - " object or with a username , password , and roles array " ) ; <nl> - <nl> + this . _createUserDeprecatedV22Version . apply ( this , arguments ) ; <nl> } <nl> } <nl> <nl> DB . prototype . dropUser = function ( username , writeConcern ) { <nl> throw Error ( res . errmsg ) ; <nl> } <nl> <nl> + / * * <nl> + * Used for removing users in systems with V1 style user information <nl> + * ( ie MongoDB v2 . 4 and prior ) <nl> + * / <nl> DB . prototype . _removeUserV1 = function ( username , writeConcern ) { <nl> this . getCollection ( " system . users " ) . remove ( { user : username } ) ; <nl> <nl>
SERVER - 10794 Maintain backwards - compatible form of addUser for one more release
mongodb/mongo
f0c6cebd73410c711ff2fc1167f7bded692dad1e
2013-10-11T22:14:12Z
mmm a / xbmc / addons / interfaces / Filesystem . cpp <nl> ppp b / xbmc / addons / interfaces / Filesystem . cpp <nl> static void CFileItemListToVFSDirEntries ( VFSDirEntry * entries , <nl> } <nl> } <nl> <nl> - bool Interface_Filesystem : : get_directory ( void * kodiBase , const char * path , const char * mask , VFSDirEntry * * items , unsigned int * num_items ) <nl> + bool Interface_Filesystem : : get_directory ( void * kodiBase , const char * path , const char * mask , struct VFSDirEntry * * items , unsigned int * num_items ) <nl> { <nl> CAddonDll * addon = static_cast < CAddonDll * > ( kodiBase ) ; <nl> if ( addon = = nullptr | | path = = nullptr | | mask = = nullptr | | items = = nullptr | | num_items = = nullptr ) <nl> bool Interface_Filesystem : : get_directory ( void * kodiBase , const char * path , const <nl> return true ; <nl> } <nl> <nl> - void Interface_Filesystem : : free_directory ( void * kodiBase , VFSDirEntry * items , unsigned int num_items ) <nl> + void Interface_Filesystem : : free_directory ( void * kodiBase , struct VFSDirEntry * items , unsigned int num_items ) <nl> { <nl> CAddonDll * addon = static_cast < CAddonDll * > ( kodiBase ) ; <nl> if ( addon = = nullptr | | items = = nullptr ) <nl> mmm a / xbmc / addons / interfaces / Filesystem . h <nl> ppp b / xbmc / addons / interfaces / Filesystem . h <nl> struct Interface_Filesystem <nl> static bool get_directory ( void * kodiBase , <nl> const char * path , <nl> const char * mask , <nl> - VFSDirEntry * * items , <nl> + struct VFSDirEntry * * items , <nl> unsigned int * num_items ) ; <nl> - static void free_directory ( void * kodiBase , VFSDirEntry * items , unsigned int num_items ) ; <nl> + static void free_directory ( void * kodiBase , struct VFSDirEntry * items , unsigned int num_items ) ; <nl> <nl> static bool file_exists ( void * kodiBase , const char * filename , bool useCache ) ; <nl> static bool stat_file ( void * kodiBase , const char * filename , struct STAT_STRUCTURE * buffer ) ; <nl> mmm a / xbmc / addons / kodi - addon - dev - kit / include / kodi / Filesystem . h <nl> ppp b / xbmc / addons / kodi - addon - dev - kit / include / kodi / Filesystem . h <nl> <nl> <nl> # include " AddonBase . h " <nl> <nl> + # include < stdint . h > <nl> + # include < time . h > <nl> + <nl> + # ifdef __cplusplus <nl> # include < map > <nl> # include < vector > <nl> + # endif / * __cplusplus * / <nl> <nl> - # ifdef _WIN32 / / windows <nl> + # ifdef _WIN32 / / windows <nl> # ifndef _SSIZE_T_DEFINED <nl> typedef intptr_t ssize_t ; <nl> # define _SSIZE_T_DEFINED <nl> typedef intptr_t ssize_t ; <nl> * <nl> * Note : For add - on development itself this is not needed <nl> * / <nl> + <nl> + # ifdef __cplusplus <nl> extern " C " <nl> { <nl> + # endif / * __cplusplus * / <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / <nl> + / / / \ defgroup cpp_kodi_vfs Interface - kodi : : vfs <nl> + / / / \ ingroup cpp <nl> + / / / @ brief * * Virtual filesystem functions * * <nl> + / / / <nl> + / / / <nl> + / / / It has the header \ ref Filesystem . h " # include < kodi / Filesystem . h > " be <nl> + / / / included to enjoy it . <nl> + / / / <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / \ defgroup cpp_kodi_vfs_Defs Definitions , structures and enumerators <nl> + / / / \ ingroup cpp_kodi_vfs <nl> + / / / @ brief * * Virtual file Server definition values * * <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / <nl> + / / / @ ingroup cpp_kodi_vfs_Defs <nl> + / / / Flags to define way how file becomes opened with kodi : : vfs : : CFile : : OpenFile ( ) <nl> + / / / <nl> + / / / The values can be used together , e . g . < b > ` file . Open ( " myfile " , READ_TRUNCATED | READ_CHUNKED ) ; ` < / b > <nl> + / / / <nl> + typedef enum OpenFileFlags <nl> + { <nl> + / / / indicate that caller can handle truncated reads , where function returns <nl> + / / / before entire buffer has been filled <nl> + READ_TRUNCATED = 0x01 , <nl> + <nl> + / / / indicate that that caller support read in the minimum defined chunk size , <nl> + / / / this disables internal cache then <nl> + READ_CHUNKED = 0x02 , <nl> + <nl> + / / / use cache to access this file <nl> + READ_CACHED = 0x04 , <nl> + <nl> + / / / open without caching . regardless to file type <nl> + READ_NO_CACHE = 0x08 , <nl> + <nl> + / / / calcuate bitrate for file while reading <nl> + READ_BITRATE = 0x10 , <nl> + <nl> + / / / indicate to the caller we will seek between multiple streams in the file <nl> + / / / frequently <nl> + READ_MULTI_STREAM = 0x20 , <nl> + <nl> + / / / indicate to the caller file is audio and / or video ( and e . g . may grow ) <nl> + READ_AUDIO_VIDEO = 0x40 , <nl> + <nl> + / / / indicate that caller will do write operations before reading <nl> + READ_AFTER_WRITE = 0x80 , <nl> + <nl> + / / / indicate that caller want to reopen a file if its already open <nl> + READ_REOPEN = 0x100 <nl> + } OpenFileFlags ; <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / \ ingroup cpp_kodi_vfs_Defs <nl> + / / / @ brief CURL message types <nl> + / / / <nl> + / / / Used on kodi : : vfs : : CFile : : CURLAddOption ( ) <nl> + / / / <nl> + typedef enum CURLOptiontype <nl> + { <nl> + / / / Set a general option <nl> + ADDON_CURL_OPTION_OPTION , <nl> + <nl> + / / / Set a protocol option <nl> + / / / <nl> + / / / The following names for * ADDON_CURL_OPTION_PROTOCOL * are possible : <nl> + / / / <nl> + / / / | Option name | Description <nl> + / / / | mmmmmmmmmmmmmmmmmmmmmmmmmmm : | : mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> + / / / | accept - charset | Set the " accept - charset " header <nl> + / / / | acceptencoding or encoding | Set the " accept - encoding " header <nl> + / / / | active - remote | Set the " active - remote " header <nl> + / / / | auth | Set the authentication method . Possible values : any , anysafe , digest , ntlm <nl> + / / / | connection - timeout | Set the connection timeout in seconds <nl> + / / / | cookie | Set the " cookie " header <nl> + / / / | customrequest | Set a custom HTTP request like DELETE <nl> + / / / | noshout | Set to true if kodi detects a stream as shoutcast by mistake . <nl> + / / / | postdata | Set the post body ( value needs to be base64 encoded ) . ( Implicitly sets the request to POST ) <nl> + / / / | referer | Set the " referer " header <nl> + / / / | user - agent | Set the " user - agent " header <nl> + / / / | seekable | Set the stream seekable . 1 : enable , 0 : disable <nl> + / / / | sslcipherlist | Set list of accepted SSL ciphers . <nl> + / / / <nl> + ADDON_CURL_OPTION_PROTOCOL , <nl> + <nl> + / / / Set User and password <nl> + ADDON_CURL_OPTION_CREDENTIALS , <nl> + <nl> + / / / Add a Header <nl> + ADDON_CURL_OPTION_HEADER <nl> + } CURLOptiontype ; <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / \ ingroup cpp_kodi_vfs_Defs <nl> + / / / @ brief CURL message types <nl> + / / / <nl> + / / / Used on kodi : : vfs : : CFile : : GetPropertyValue ( ) and kodi : : vfs : : CFile : : GetPropertyValues ( ) <nl> + / / / <nl> + typedef enum FilePropertyTypes <nl> + { <nl> + / / / Get protocol response line <nl> + ADDON_FILE_PROPERTY_RESPONSE_PROTOCOL , <nl> + / / / Get a response header <nl> + ADDON_FILE_PROPERTY_RESPONSE_HEADER , <nl> + / / / Get file content type <nl> + ADDON_FILE_PROPERTY_CONTENT_TYPE , <nl> + / / / Get file content charset <nl> + ADDON_FILE_PROPERTY_CONTENT_CHARSET , <nl> + / / / Get file mime type <nl> + ADDON_FILE_PROPERTY_MIME_TYPE , <nl> + / / / Get file effective URL ( last one if redirected ) <nl> + ADDON_FILE_PROPERTY_EFFECTIVE_URL <nl> + } FilePropertyTypes ; <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + <nl> + / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + / / / <nl> + / / / \ ingroup cpp_kodi_vfs_Defs <nl> + / / / @ brief File information status <nl> + / / / <nl> + / / / Used on kodi : : vfs : : StatFile ( ) , all of these calls return a this stat <nl> + / / / structure , which contains the following fields : <nl> + / / / <nl> + struct STAT_STRUCTURE <nl> + { <nl> + / / / ID of device containing file <nl> + uint32_t deviceId ; <nl> + / / / Total size , in bytes <nl> + uint64_t size ; <nl> + / / / Time of last access <nl> + time_t accessTime ; <nl> + / / / Time of last modification <nl> + time_t modificationTime ; <nl> + / / / Time of last status change <nl> + time_t statusTime ; <nl> + / / / The stat url is a directory <nl> + bool isDirectory ; <nl> + / / / The stat url is a symbolic link <nl> + bool isSymLink ; <nl> + } ; <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> <nl> struct VFSProperty <nl> { <nl> extern " C " <nl> char * title ; / / ! < item title <nl> char * path ; / / ! < item path <nl> unsigned int num_props ; / / ! < Number of properties attached to item <nl> - VFSProperty * properties ; / / ! < Properties <nl> + struct VFSProperty * properties ; / / ! < Properties <nl> time_t date_time ; / / ! < file creation date & time <nl> bool folder ; / / ! < Item is a folder <nl> uint64_t size ; / / ! < Size of file represented by item <nl> extern " C " <nl> bool ( * create_directory ) ( void * kodiBase , const char * path ) ; <nl> bool ( * remove_directory ) ( void * kodiBase , const char * path ) ; <nl> bool ( * directory_exists ) ( void * kodiBase , const char * path ) ; <nl> - bool ( * get_directory ) ( void * kodiBase , const char * path , const char * mask , VFSDirEntry * * items , unsigned int * num_items ) ; <nl> - void ( * free_directory ) ( void * kodiBase , VFSDirEntry * items , unsigned int num_items ) ; <nl> + bool ( * get_directory ) ( void * kodiBase , const char * path , const char * mask , struct VFSDirEntry * * items , unsigned int * num_items ) ; <nl> + void ( * free_directory ) ( void * kodiBase , struct VFSDirEntry * items , unsigned int num_items ) ; <nl> <nl> bool ( * file_exists ) ( void * kodiBase , const char * filename , bool useCache ) ; <nl> bool ( * stat_file ) ( void * kodiBase , const char * filename , struct STAT_STRUCTURE * buffer ) ; <nl> extern " C " <nl> bool ( * curl_open ) ( void * kodiBase , void * file , unsigned int flags ) ; <nl> } AddonToKodiFuncTable_kodi_filesystem ; <nl> <nl> + # ifdef __cplusplus <nl> } / * extern " C " * / <nl> + # endif / * __cplusplus * / <nl> <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / <nl> - / / / \ defgroup cpp_kodi_vfs Interface - kodi : : vfs <nl> - / / / \ ingroup cpp <nl> - / / / @ brief * * Virtual filesystem functions * * <nl> - / / / <nl> - / / / <nl> - / / / It has the header \ ref Filesystem . h " # include < kodi / Filesystem . h > " be <nl> - / / / included to enjoy it . <nl> - / / / <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / \ defgroup cpp_kodi_vfs_Defs Definitions , structures and enumerators <nl> - / / / \ ingroup cpp_kodi_vfs <nl> - / / / @ brief * * Virtual file Server definition values * * <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / <nl> - / / / @ ingroup cpp_kodi_vfs_Defs <nl> - / / / Flags to define way how file becomes opened with kodi : : vfs : : CFile : : OpenFile ( ) <nl> - / / / <nl> - / / / The values can be used together , e . g . < b > ` file . Open ( " myfile " , READ_TRUNCATED | READ_CHUNKED ) ; ` < / b > <nl> - / / / <nl> - typedef enum OpenFileFlags <nl> - { <nl> - / / / indicate that caller can handle truncated reads , where function returns <nl> - / / / before entire buffer has been filled <nl> - READ_TRUNCATED = 0x01 , <nl> - <nl> - / / / indicate that that caller support read in the minimum defined chunk size , <nl> - / / / this disables internal cache then <nl> - READ_CHUNKED = 0x02 , <nl> + / / · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · <nl> <nl> - / / / use cache to access this file <nl> - READ_CACHED = 0x04 , <nl> - <nl> - / / / open without caching . regardless to file type <nl> - READ_NO_CACHE = 0x08 , <nl> - <nl> - / / / calcuate bitrate for file while reading <nl> - READ_BITRATE = 0x10 , <nl> - <nl> - / / / indicate to the caller we will seek between multiple streams in the file <nl> - / / / frequently <nl> - READ_MULTI_STREAM = 0x20 , <nl> - <nl> - / / / indicate to the caller file is audio and / or video ( and e . g . may grow ) <nl> - READ_AUDIO_VIDEO = 0x40 , <nl> - <nl> - / / / indicate that caller will do write operations before reading <nl> - READ_AFTER_WRITE = 0x80 , <nl> - <nl> - / / / indicate that caller want to reopen a file if its already open <nl> - READ_REOPEN = 0x100 <nl> - } OpenFileFlags ; <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / \ ingroup cpp_kodi_vfs_Defs <nl> - / / / @ brief CURL message types <nl> - / / / <nl> - / / / Used on kodi : : vfs : : CFile : : CURLAddOption ( ) <nl> - / / / <nl> - typedef enum CURLOptiontype <nl> - { <nl> - / / / Set a general option <nl> - ADDON_CURL_OPTION_OPTION , <nl> - <nl> - / / / Set a protocol option <nl> - / / / <nl> - / / / The following names for * ADDON_CURL_OPTION_PROTOCOL * are possible : <nl> - / / / <nl> - / / / | Option name | Description <nl> - / / / | mmmmmmmmmmmmmmmmmmmmmmmmmmm : | : mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> - / / / | accept - charset | Set the " accept - charset " header <nl> - / / / | acceptencoding or encoding | Set the " accept - encoding " header <nl> - / / / | active - remote | Set the " active - remote " header <nl> - / / / | auth | Set the authentication method . Possible values : any , anysafe , digest , ntlm <nl> - / / / | connection - timeout | Set the connection timeout in seconds <nl> - / / / | cookie | Set the " cookie " header <nl> - / / / | customrequest | Set a custom HTTP request like DELETE <nl> - / / / | noshout | Set to true if kodi detects a stream as shoutcast by mistake . <nl> - / / / | postdata | Set the post body ( value needs to be base64 encoded ) . ( Implicitly sets the request to POST ) <nl> - / / / | referer | Set the " referer " header <nl> - / / / | user - agent | Set the " user - agent " header <nl> - / / / | seekable | Set the stream seekable . 1 : enable , 0 : disable <nl> - / / / | sslcipherlist | Set list of accepted SSL ciphers . <nl> - / / / <nl> - ADDON_CURL_OPTION_PROTOCOL , <nl> - <nl> - / / / Set User and password <nl> - ADDON_CURL_OPTION_CREDENTIALS , <nl> - <nl> - / / / Add a Header <nl> - ADDON_CURL_OPTION_HEADER <nl> - } CURLOptiontype ; <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / \ ingroup cpp_kodi_vfs_Defs <nl> - / / / @ brief CURL message types <nl> - / / / <nl> - / / / Used on kodi : : vfs : : CFile : : GetPropertyValue ( ) and kodi : : vfs : : CFile : : GetPropertyValues ( ) <nl> - / / / <nl> - typedef enum FilePropertyTypes <nl> - { <nl> - / / / Get protocol response line <nl> - ADDON_FILE_PROPERTY_RESPONSE_PROTOCOL , <nl> - / / / Get a response header <nl> - ADDON_FILE_PROPERTY_RESPONSE_HEADER , <nl> - / / / Get file content type <nl> - ADDON_FILE_PROPERTY_CONTENT_TYPE , <nl> - / / / Get file content charset <nl> - ADDON_FILE_PROPERTY_CONTENT_CHARSET , <nl> - / / / Get file mime type <nl> - ADDON_FILE_PROPERTY_MIME_TYPE , <nl> - / / / Get file effective URL ( last one if redirected ) <nl> - ADDON_FILE_PROPERTY_EFFECTIVE_URL <nl> - } FilePropertyTypes ; <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> - <nl> - / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> - / / / <nl> - / / / \ ingroup cpp_kodi_vfs_Defs <nl> - / / / @ brief File information status <nl> - / / / <nl> - / / / Used on kodi : : vfs : : StatFile ( ) , all of these calls return a this stat <nl> - / / / structure , which contains the following fields : <nl> - / / / <nl> - struct STAT_STRUCTURE <nl> - { <nl> - / / / ID of device containing file <nl> - uint32_t deviceId ; <nl> - / / / Total size , in bytes <nl> - uint64_t size ; <nl> - / / / Time of last access <nl> - time_t accessTime ; <nl> - / / / Time of last modification <nl> - time_t modificationTime ; <nl> - / / / Time of last status change <nl> - time_t statusTime ; <nl> - / / / The stat url is a directory <nl> - bool isDirectory ; <nl> - / / / The stat url is a symbolic link <nl> - bool isSymLink ; <nl> - } ; <nl> - / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm <nl> + # ifdef __cplusplus <nl> <nl> namespace kodi <nl> { <nl> class FileStatus : public kodi : : addon : : CStructHdl < FileStatus , STAT_STRUCTURE > <nl> <nl> } / * namespace vfs * / <nl> } / * namespace kodi * / <nl> + <nl> + # endif / * __cplusplus * / <nl>
[ addons ] [ filesystem ] make interface " C " conform
xbmc/xbmc
4def627a13ad7fc2afb6172b2f7e2dc2c856d784
2020-05-17T11:24:33Z
mmm a / include / swift / AST / Identifier . h <nl> ppp b / include / swift / AST / Identifier . h <nl> class Identifier { <nl> if ( isOperatorStartCodePoint ( C ) ) <nl> return true ; <nl> <nl> - / / Unicode combining characters . <nl> + / / Unicode combining characters and variation selectors . <nl> return ( C > = 0x0300 & & C < = 0x036F ) <nl> | | ( C > = 0x1DC0 & & C < = 0x1DFF ) <nl> | | ( C > = 0x20D0 & & C < = 0x20FF ) <nl> - | | ( C > = 0xFE20 & & C < = 0xFE2F ) ; <nl> + | | ( C > = 0xFE00 & & C < = 0xFE0F ) <nl> + | | ( C > = 0xFE20 & & C < = 0xFE2F ) <nl> + | | ( C > = 0xE0100 & & C < = 0xE01EF ) ; <nl> } <nl> <nl> void * getAsOpaquePointer ( ) const { return ( void * ) Pointer ; } <nl>
Lexer : Accept variation selectors as continuations of operators .
apple/swift
e733f1e816050774055c578ea87f9b76170522bc
2014-05-09T22:03:24Z
mmm a / . gitignore <nl> ppp b / . gitignore <nl> bin / <nl> obj / <nl> assets / <nl> . classpath <nl> - . project <nl> \ No newline at end of file <nl> + . project <nl> + . cproject <nl>
Added . cproject to the . gitignore file
cocos2d/cocos2d-x
10d1844cfb660eb2b2409ea306a01e59a79228f9
2011-02-05T23:49:12Z
mmm a / brightray / browser / url_request_context_getter . cc <nl> ppp b / brightray / browser / url_request_context_getter . cc <nl> const char kHostRules [ ] = " host - rules " ; <nl> / / other proxy server flags that are passed . <nl> const char kNoProxyServer [ ] = " no - proxy - server " ; <nl> <nl> + / / Uses a specified proxy server , overrides system settings . This switch only <nl> + / / affects HTTP and HTTPS requests . <nl> + const char kProxyServer [ ] = " proxy - server " ; <nl> + <nl> } / / namespace <nl> <nl> URLRequestContextGetter : : URLRequestContextGetter ( <nl> net : : URLRequestContext * URLRequestContextGetter : : GetURLRequestContext ( ) { <nl> net : : DhcpProxyScriptFetcherFactory dhcp_factory ; <nl> if ( command_line . HasSwitch ( kNoProxyServer ) ) <nl> storage_ - > set_proxy_service ( net : : ProxyService : : CreateDirect ( ) ) ; <nl> + else if ( command_line . HasSwitch ( kProxyServer ) ) <nl> + storage_ - > set_proxy_service ( net : : ProxyService : : CreateFixed ( <nl> + command_line . GetSwitchValueASCII ( kProxyServer ) ) ) ; <nl> else <nl> storage_ - > set_proxy_service ( <nl> net : : CreateProxyServiceUsingV8ProxyResolver ( <nl>
Add - - proxy - server switch .
electron/electron
44bfa328f18ab426fd82141754f90f6e33938193
2014-08-20T03:49:18Z
mmm a / src / IO / parseDateTimeBestEffort . cpp <nl> ppp b / src / IO / parseDateTimeBestEffort . cpp <nl> ReturnType parseDateTimeBestEffortImpl ( <nl> char c = * in . position ( ) ; <nl> <nl> / / / ' T ' is a separator between date and time according to ISO 8601 . <nl> - / / / But don ' t skip it if we didn ' t read the date part yet , because ' T ' is also a prefix or ' Tue ' and ' Thu ' . <nl> + / / / But don ' t skip it if we didn ' t read the date part yet , because ' T ' is also a prefix for ' Tue ' and ' Thu ' . <nl> <nl> if ( c = = ' ' | | ( c = = ' T ' & & year & & ! has_time ) ) <nl> { <nl>
Update parseDateTimeBestEffort . cpp
ClickHouse/ClickHouse
3f1658c0e931e8c7467ac959ec2ab175a90d3663
2020-04-12T19:35:23Z
mmm a / ports / protobuf / 001 - add - compiler - flag . patch <nl> ppp b / ports / protobuf / 001 - add - compiler - flag . patch <nl> include ( tests . cmake ) <nl> <nl> - + mmm a / cmake / install . cmake <nl> ppp b / cmake / install . cmake <nl> <nl> include ( GNUInstallDirs ) <nl> <nl> - - configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / protobuf . pc . cmake <nl> + set ( LIBRARIES_TO_SET_DEST libprotobuf - lite libprotobuf ) <nl> + if ( protobuf_BUILD_COMPILER ) <nl> + list ( APPEND LIBRARIES_TO_SET_DEST libprotoc ) <nl> + endif ( ) <nl> + <nl> - + configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / libprotobuf . cmake <nl> + configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / protobuf . pc . cmake <nl> $ { CMAKE_CURRENT_BINARY_DIR } / protobuf . pc @ ONLY ) <nl> - - configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / protobuf - lite . pc . cmake <nl> - + configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / libprotobuf - lite . cmake <nl> + configure_file ( $ { CMAKE_CURRENT_SOURCE_DIR } / protobuf - lite . pc . cmake <nl> $ { CMAKE_CURRENT_BINARY_DIR } / protobuf - lite . pc @ ONLY ) <nl> <nl> foreach ( _library <nl> mmm a / ports / protobuf / CONTROL <nl> ppp b / ports / protobuf / CONTROL <nl> <nl> Source : protobuf <nl> - Version : 3 . 4 . 0 - 2 <nl> + Version : 3 . 4 . 1 - 1 <nl> Build - Depends : zlib <nl> Description : Protocol Buffers - Google ' s data interchange format <nl> mmm a / ports / protobuf / portfile . cmake <nl> ppp b / ports / protobuf / portfile . cmake <nl> <nl> include ( vcpkg_common_functions ) <nl> <nl> - set ( PROTOBUF_VERSION 3 . 4 . 0 ) <nl> + set ( PROTOBUF_VERSION 3 . 4 . 1 ) <nl> <nl> vcpkg_download_distfile ( ARCHIVE_FILE <nl> URLS " https : / / github . com / google / protobuf / releases / download / v $ { PROTOBUF_VERSION } / protobuf - cpp - $ { PROTOBUF_VERSION } . tar . gz " <nl> FILENAME " protobuf - cpp - $ { PROTOBUF_VERSION } . tar . gz " <nl> - SHA512 ce9bd9bc818c4a8e8b08c83e8a4eba6fca008a64a5ad9d322b19683b1de2b5fa622ed99093323f3c9d0820ef23430f7ee07f6930f7f877d334e5d36df9b0be0e <nl> + SHA512 6189e23c7e381f62e971bd0e35ad9c3ed8effe584755357013887c6a582cb5a9a654c39affa2a073b658854138f31bfb70f89fa1df494e9386f1d64fd73d07d2 <nl> ) <nl> vcpkg_download_distfile ( TOOL_ARCHIVE_FILE <nl> URLS " https : / / github . com / google / protobuf / releases / download / v $ { PROTOBUF_VERSION } / protoc - $ { PROTOBUF_VERSION } - win32 . zip " <nl> - FILENAME " protoc - $ { PROTOBUF_VERSION } - win32 . zip " <nl> + FILENAME " protoc - 3 . 4 . 0 - win32 . zip " <nl> SHA512 b874c3f47b39ac78f5675e05220318683004a365c248bf47ba50d8c66c8ed7763432451bab30524e131e1185a2bdaa6e6071b389eb61ad58b1b95974cf39d41b <nl> ) <nl> <nl>
protobuf : update to 3 . 4 . 1
microsoft/vcpkg
d40f2a4a5d51e28b322c5c63771af3e8de302c45
2017-09-21T15:30:11Z
mmm a / ports / cpprestsdk / CONTROL <nl> ppp b / ports / cpprestsdk / CONTROL <nl> <nl> Source : cpprestsdk <nl> - Version : 2 . 10 . 13 <nl> - Build - Depends : zlib , openssl ( ! uwp & ! windows ) , boost - system ( ! uwp & ! windows ) , boost - date - time ( ! uwp & ! windows ) , boost - regex ( ! uwp & ! windows ) , boost - thread ( ! uwp & ! windows ) , boost - filesystem ( ! uwp & ! windows ) , boost - random ( ! uwp & ! windows ) , boost - chrono ( ! uwp & ! windows ) <nl> + Version : 2 . 10 . 13 - 1 <nl> + Build - Depends : zlib , openssl ( ! uwp & ! windows ) , boost - system ( ! uwp & ! windows ) , boost - date - time ( ! uwp & ! windows ) , boost - regex ( ! uwp & ! windows ) , boost - thread ( ! uwp & ! windows ) , boost - filesystem ( ! uwp & ! windows ) , boost - random ( ! uwp & ! windows ) , boost - chrono ( ! uwp & ! windows ) , boost - asio ( ! uwp & ! windows ) <nl> Description : C + + 11 JSON , REST , and OAuth library <nl> The C + + REST SDK is a Microsoft project for cloud - based client - server communication in native code using a modern asynchronous C + + API design . This project aims to help C + + developers connect to and interact with services . <nl> Default - Features : default - features <nl>
[ cpprestsdk ] Add boost - asio dependency on linux ( )
microsoft/vcpkg
0022e0b0ac96d1ebe514a757b670e09b0a148dc8
2019-05-10T05:53:36Z
new file mode 100644 <nl> index 000000000000 . . 0836066952fe <nl> mmm / dev / null <nl> ppp b / validation - test / compiler_crashers / 28736 - anonymous - namespacesilverifier - require . swift <nl> <nl> + / / This source file is part of the Swift . org open source project <nl> + / / Copyright ( c ) 2014 - 2017 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See https : / / swift . org / LICENSE . txt for license information <nl> + / / See https : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / RUN : not - - crash % target - swift - frontend - primary - file % s - emit - ir - O <nl> + / / non - fuzz ( @ dusek ) <nl> + <nl> + func f < T > ( _ a : T ) - > Void { f ( nil as [ Any ] ? ) } <nl>
Merge pull request from practicalswift / swiftc - 28736 - anonymous - namespacesilverifier - require
apple/swift
35ab53b7562adb5a76d88101ac1e81023b9c9750
2017-04-13T11:09:51Z
mmm a / scene / gui / control . cpp <nl> ppp b / scene / gui / control . cpp <nl> <nl> # include < stdio . h > <nl> <nl> <nl> - class TooltipPanel : public Panel { <nl> - <nl> - OBJ_TYPE ( TooltipPanel , Panel ) <nl> - public : <nl> - TooltipPanel ( ) { } ; <nl> - <nl> - } ; <nl> - <nl> - class TooltipLabel : public Label { <nl> - <nl> - OBJ_TYPE ( TooltipLabel , Label ) <nl> - public : <nl> - TooltipLabel ( ) { } ; <nl> - <nl> - } ; <nl> - <nl> - Control : : Window : : Window ( ) { <nl> - <nl> - <nl> - mouse_focus = NULL ; <nl> - mouse_focus_button = - 1 ; <nl> - key_focus = NULL ; <nl> - mouse_over = NULL ; <nl> - disable_input = false ; <nl> - <nl> - cancelled_input_ID = 0 ; <nl> - tooltip = NULL ; <nl> - tooltip_popup = NULL ; <nl> - tooltip_label = NULL ; <nl> - subwindow_order_dirty = false ; <nl> - } <nl> <nl> <nl> Variant Control : : edit_get_state ( ) const { <nl> Control * Control : : get_parent_control ( ) const { <nl> return data . parent ; <nl> } <nl> <nl> - void Control : : _input_text ( const String & p_text ) { <nl> - <nl> - if ( ! window ) <nl> - return ; <nl> - if ( window - > key_focus ) <nl> - window - > key_focus - > call ( " set_text " , p_text ) ; <nl> - <nl> - } <nl> - <nl> - void Control : : _gui_input ( const InputEvent & p_event ) { <nl> - <nl> - _window_input_event ( p_event ) ; <nl> - } <nl> <nl> void Control : : _resize ( const Size2 & p_size ) { <nl> <nl> void Control : : _notification ( int p_notification ) { <nl> <nl> case NOTIFICATION_ENTER_TREE : { <nl> <nl> - if ( data . window = = this ) { <nl> - <nl> - window = memnew ( Window ) ; <nl> - add_to_group ( " _vp_gui_input " + itos ( get_viewport ( ) - > get_instance_ID ( ) ) ) ; <nl> - add_to_group ( " windows " ) ; <nl> - <nl> - window - > tooltip_timer = memnew ( Timer ) ; <nl> - add_child ( window - > tooltip_timer ) ; <nl> - window - > tooltip_timer - > force_parent_owned ( ) ; <nl> - window - > tooltip_timer - > set_wait_time ( GLOBAL_DEF ( " display / tooltip_delay " , 0 . 7 ) ) ; <nl> - window - > tooltip_timer - > connect ( " timeout " , this , " _window_show_tooltip " ) ; <nl> - window - > tooltip = NULL ; <nl> - window - > tooltip_popup = memnew ( TooltipPanel ) ; <nl> - add_child ( window - > tooltip_popup ) ; <nl> - window - > tooltip_popup - > force_parent_owned ( ) ; <nl> - window - > tooltip_label = memnew ( TooltipLabel ) ; <nl> - window - > tooltip_popup - > add_child ( window - > tooltip_label ) ; <nl> - window - > tooltip_popup - > set_as_toplevel ( true ) ; <nl> - window - > tooltip_popup - > hide ( ) ; <nl> - window - > drag_attempted = false ; <nl> - window - > drag_preview = NULL ; <nl> - <nl> - if ( get_tree ( ) - > is_editor_hint ( ) ) { <nl> - <nl> - Node * n = this ; <nl> - while ( n ) { <nl> - <nl> - if ( n - > has_meta ( " _editor_disable_input " ) ) { <nl> - window - > disable_input = true ; <nl> - break ; <nl> - } <nl> - n = n - > get_parent ( ) ; <nl> - } <nl> - } <nl> - <nl> - } else { <nl> - window = NULL ; <nl> - } <nl> - <nl> _size_changed ( ) ; <nl> <nl> } break ; <nl> case NOTIFICATION_EXIT_TREE : { <nl> <nl> - if ( data . window ) { <nl> - <nl> - if ( data . window - > window - > mouse_focus = = this ) <nl> - data . window - > window - > mouse_focus = NULL ; <nl> - if ( data . window - > window - > key_focus = = this ) <nl> - data . window - > window - > key_focus = NULL ; <nl> - if ( data . window - > window - > mouse_over = = this ) <nl> - data . window - > window - > mouse_over = NULL ; <nl> - if ( data . window - > window - > tooltip = = this ) <nl> - data . window - > window - > tooltip = NULL ; <nl> - } <nl> - <nl> - if ( window ) { <nl> - <nl> - remove_from_group ( " _vp_gui_input " + itos ( get_viewport ( ) - > get_instance_ID ( ) ) ) ; <nl> - remove_from_group ( " windows " ) ; <nl> - if ( window - > tooltip_timer ) <nl> - memdelete ( window - > tooltip_timer ) ; <nl> - window - > tooltip_timer = NULL ; <nl> - window - > tooltip = NULL ; <nl> - if ( window - > tooltip_popup ) <nl> - memdelete ( window - > tooltip_popup ) ; <nl> - window - > tooltip_popup = NULL ; <nl> - <nl> - memdelete ( window ) ; <nl> - window = NULL ; <nl> - <nl> - } <nl> - <nl> + get_viewport ( ) - > _gui_remove_control ( this ) ; <nl> <nl> <nl> } break ; <nl> void Control : : _notification ( int p_notification ) { <nl> <nl> case NOTIFICATION_ENTER_CANVAS : { <nl> <nl> - data . window = NULL ; <nl> - data . viewport = NULL ; <nl> - data . parent = NULL ; <nl> + data . parent = get_parent ( ) - > cast_to < Control > ( ) ; <nl> <nl> - Control * _window = this ; <nl> - bool gap = false ; <nl> - bool gap_valid = true ; <nl> - bool window_found = false ; <nl> - <nl> - Node * parent = _window - > get_parent ( ) ; <nl> - if ( parent & & parent - > cast_to < Control > ( ) ) { <nl> + if ( is_set_as_toplevel ( ) ) { <nl> + data . SI = get_viewport ( ) - > _gui_add_subwindow_control ( this ) ; <nl> + } else { <nl> <nl> - data . parent = parent - > cast_to < Control > ( ) ; <nl> - } <nl> <nl> - Viewport * viewport = NULL ; <nl> + Node * parent = this ; / / meh <nl> + Node * parent_control = NULL ; <nl> + bool subwindow = false ; <nl> <nl> - parent = this ; / / meh <nl> + while ( parent ) { <nl> <nl> - while ( parent ) { <nl> + parent = parent - > get_parent ( ) ; <nl> <nl> - Control * c = parent - > cast_to < Control > ( ) ; <nl> + if ( ! parent ) <nl> + break ; <nl> <nl> - if ( ! window_found & & c ) { <nl> - if ( ! gap & & c ! = this ) { <nl> - gap_valid = false ; <nl> + CanvasItem * ci = parent - > cast_to < CanvasItem > ( ) ; <nl> + if ( ci & & ci - > is_set_as_toplevel ( ) ) { <nl> + subwindow = true ; <nl> + break ; <nl> } <nl> <nl> - _window = c ; <nl> - } <nl> - <nl> - CanvasItem * ci = parent - > cast_to < CanvasItem > ( ) ; <nl> + if ( parent - > cast_to < Control > ( ) ) { <nl> + parent_control = parent - > cast_to < Control > ( ) ; <nl> + break ; <nl> + } else if ( ci ) { <nl> <nl> - if ( ( ci & & ci - > is_set_as_toplevel ( ) ) | | ! ci ) { <nl> - gap = true ; <nl> + } else { <nl> + break ; <nl> + } <nl> } <nl> <nl> - if ( parent - > cast_to < CanvasLayer > ( ) ) { <nl> - window_found = true ; / / don ' t go beyond canvas layer <nl> - } <nl> <nl> - viewport = parent - > cast_to < Viewport > ( ) ; <nl> - if ( viewport ) { <nl> - break ; / / no go beyond viewport either <nl> + if ( parent_control ) { <nl> + / / do nothing , has a parent control <nl> + } else if ( subwindow ) { <nl> + / / is a subwindow ( process input before other controls for that canvas ) <nl> + data . SI = get_viewport ( ) - > _gui_add_subwindow_control ( this ) ; <nl> + } else { <nl> + / / is a regular root control <nl> + data . RI = get_viewport ( ) - > _gui_add_root_control ( this ) ; <nl> } <nl> <nl> - parent = parent - > get_parent ( ) ; <nl> - } <nl> - <nl> - data . window = _window ; <nl> - data . viewport = viewport ; <nl> - data . parent_canvas_item = get_parent_item ( ) ; <nl> - <nl> - if ( data . parent_canvas_item ) { <nl> - <nl> - data . parent_canvas_item - > connect ( " item_rect_changed " , this , " _size_changed " ) ; <nl> - } else if ( data . viewport ) { <nl> + data . parent_canvas_item = get_parent_item ( ) ; <nl> <nl> - / / connect viewport <nl> - data . viewport - > connect ( " size_changed " , this , " _size_changed " ) ; <nl> - } else { <nl> + if ( data . parent_canvas_item ) { <nl> <nl> + data . parent_canvas_item - > connect ( " item_rect_changed " , this , " _size_changed " ) ; <nl> + } else { <nl> + / / connect viewport <nl> + get_viewport ( ) - > connect ( " size_changed " , this , " _size_changed " ) ; <nl> + } <nl> } <nl> <nl> <nl> - if ( gap & & gap_valid & & data . window ! = this ) { <nl> - / / is a subwindow , conditions to meet subwindow status are quite complex . . <nl> - data . SI = data . window - > window - > subwindows . push_back ( this ) ; <nl> - data . window - > window - > subwindow_order_dirty = true ; <nl> - <nl> - } <nl> - <nl> <nl> } break ; <nl> case NOTIFICATION_EXIT_CANVAS : { <nl> <nl> - <nl> if ( data . parent_canvas_item ) { <nl> <nl> data . parent_canvas_item - > disconnect ( " item_rect_changed " , this , " _size_changed " ) ; <nl> data . parent_canvas_item = NULL ; <nl> - } else if ( data . viewport ) { <nl> - <nl> - / / disconnect viewport <nl> - data . viewport - > disconnect ( " size_changed " , this , " _size_changed " ) ; <nl> } else { <nl> + / / disconnect viewport <nl> + get_viewport ( ) - > disconnect ( " size_changed " , this , " _size_changed " ) ; <nl> <nl> } <nl> <nl> if ( data . MI ) { <nl> - <nl> - if ( data . window & & data . window - > window ) <nl> - data . window - > window - > modal_stack . erase ( data . MI ) ; <nl> + get_viewport ( ) - > _gui_remove_modal_control ( data . MI ) ; <nl> data . MI = NULL ; <nl> } <nl> <nl> if ( data . SI ) { <nl> - / / erase from subwindows <nl> - if ( data . window & & data . window - > window ) <nl> - data . window - > window - > subwindows . erase ( data . SI ) ; <nl> + get_viewport ( ) - > _gui_remove_subwindow_control ( data . SI ) ; <nl> data . SI = NULL ; <nl> } <nl> <nl> - data . viewport = NULL ; <nl> - data . window = NULL ; <nl> + if ( data . RI ) { <nl> + get_viewport ( ) - > _gui_remove_root_control ( data . RI ) ; <nl> + data . RI = NULL ; <nl> + } <nl> + <nl> data . parent = NULL ; <nl> + data . parent_canvas_item = NULL ; <nl> <nl> } break ; <nl> <nl> void Control : : _notification ( int p_notification ) { <nl> data . parent - > update ( ) ; <nl> update ( ) ; <nl> <nl> - if ( data . SI & & data . window ) { <nl> - data . window - > window - > subwindow_order_dirty = true ; <nl> + if ( data . SI ) { <nl> + get_viewport ( ) - > _gui_set_subwindow_order_dirty ( ) ; <nl> + } <nl> + if ( data . RI ) { <nl> + get_viewport ( ) - > _gui_set_root_order_dirty ( ) ; <nl> } <nl> <nl> } break ; <nl> void Control : : _notification ( int p_notification ) { <nl> <nl> if ( ! is_visible ( ) ) { <nl> <nl> - if ( data . window - > window - > mouse_focus = = this ) { <nl> - data . window - > window - > mouse_focus = NULL ; <nl> - } <nl> - if ( data . window = = this ) { <nl> - window - > drag_data = Variant ( ) ; <nl> - if ( window - > drag_preview ) { <nl> - memdelete ( window - > drag_preview ) ; <nl> - window - > drag_preview = NULL ; <nl> - } <nl> - } <nl> - <nl> - if ( data . window - > window - > key_focus = = this ) <nl> - data . window - > window - > key_focus = NULL ; <nl> - if ( data . window - > window - > mouse_over = = this ) <nl> - data . window - > window - > mouse_over = NULL ; <nl> - if ( data . window - > window - > tooltip = = this ) <nl> - data . window - > window - > tooltip = NULL ; <nl> - if ( data . window - > window - > tooltip = = this ) <nl> - data . window - > window - > tooltip = NULL ; <nl> <nl> + get_viewport ( ) - > _gui_hid_control ( this ) ; <nl> _modal_stack_remove ( ) ; <nl> minimum_size_changed ( ) ; <nl> <nl> void Control : : _notification ( int p_notification ) { <nl> } break ; <nl> case SceneTree : : NOTIFICATION_WM_UNFOCUS_REQUEST : { <nl> <nl> - if ( ! window ) <nl> - return ; <nl> - if ( window - > key_focus ) <nl> - window - > key_focus - > release_focus ( ) ; <nl> + get_viewport ( ) - > _gui_unfocus_control ( this ) ; <nl> <nl> } break ; <nl> <nl> void Control : : drop_data ( const Point2 & p_point , const Variant & p_data ) { <nl> void Control : : force_drag ( const Variant & p_data , Control * p_control ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> - ERR_FAIL_COND ( ! data . window ) ; <nl> ERR_FAIL_COND ( p_data . get_type ( ) = = Variant : : NIL ) ; <nl> <nl> + get_viewport ( ) - > _gui_force_drag ( p_data , p_control ) ; <nl> <nl> - <nl> - data . window - > window - > drag_data = p_data ; <nl> - data . window - > window - > mouse_focus = NULL ; <nl> - <nl> - if ( p_control ) { <nl> - data . window - > set_drag_preview ( p_control ) ; <nl> - } <nl> } <nl> <nl> void Control : : set_drag_preview ( Control * p_control ) { <nl> <nl> - ERR_FAIL_NULL ( p_control ) ; <nl> - ERR_FAIL_COND ( ! ( ( Object * ) p_control ) - > cast_to < Control > ( ) ) ; <nl> - ERR_FAIL_COND ( ! is_inside_tree ( ) | | ! data . window ) ; <nl> - ERR_FAIL_COND ( p_control - > is_inside_tree ( ) ) ; <nl> - ERR_FAIL_COND ( p_control - > get_parent ( ) ! = NULL ) ; <nl> - <nl> - if ( data . window - > window - > drag_preview ) { <nl> - memdelete ( data . window - > window - > drag_preview ) ; <nl> - } <nl> - p_control - > set_as_toplevel ( true ) ; <nl> - p_control - > set_pos ( data . window - > window - > last_mouse_pos ) ; <nl> - data . window - > add_child ( p_control ) ; <nl> - if ( data . window - > window - > drag_preview ) { <nl> - memdelete ( data . window - > window - > drag_preview ) ; <nl> - } <nl> - <nl> - data . window - > window - > drag_preview = p_control ; <nl> - <nl> - } <nl> - <nl> - <nl> - Control * Control : : _find_next_visible_control_at_pos ( Node * p_node , const Point2 & p_global , Matrix32 & r_xform ) const { <nl> - <nl> - return NULL ; <nl> + ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> + get_viewport ( ) - > _gui_set_drag_preview ( p_control ) ; <nl> } <nl> <nl> - Control * Control : : _find_control_at_pos ( CanvasItem * p_node , const Point2 & p_global , const Matrix32 & p_xform , Matrix32 & r_inv_xform ) { <nl> - <nl> - if ( p_node - > cast_to < Viewport > ( ) ) <nl> - return NULL ; <nl> - <nl> - Control * c = p_node - > cast_to < Control > ( ) ; <nl> - <nl> - if ( c ) { <nl> - / / print_line ( " at " + String ( c - > get_path ( ) ) + " POS " + c - > get_pos ( ) + " bt " + p_xform ) ; <nl> - } <nl> - <nl> - if ( c = = data . window ) { <nl> - / / try subwindows first ! ! <nl> - <nl> - c - > _window_sort_subwindows ( ) ; / / sort them <nl> - <nl> - for ( List < Control * > : : Element * E = c - > window - > subwindows . back ( ) ; E ; E = E - > prev ( ) ) { <nl> - <nl> - Control * sw = E - > get ( ) ; <nl> - if ( ! sw - > is_visible ( ) ) <nl> - continue ; <nl> - <nl> - Matrix32 xform ; <nl> - CanvasItem * pci = sw - > get_parent_item ( ) ; <nl> - if ( pci ) <nl> - xform = pci - > get_global_transform ( ) ; <nl> - <nl> - Control * ret = _find_control_at_pos ( sw , p_global , xform , r_inv_xform ) ; <nl> - if ( ret ) <nl> - return ret ; <nl> - <nl> - } <nl> - } <nl> - <nl> - if ( p_node - > is_hidden ( ) ) { <nl> - / / return _find_next_visible_control_at_pos ( p_node , p_global , r_inv_xform ) ; <nl> - return NULL ; / / canvas item hidden , discard <nl> - } <nl> - <nl> - Matrix32 matrix = p_xform * p_node - > get_transform ( ) ; <nl> - <nl> - if ( ! c | | ! c - > clips_input ( ) | | c - > has_point ( matrix . affine_inverse ( ) . xform ( p_global ) ) ) { <nl> - <nl> - for ( int i = p_node - > get_child_count ( ) - 1 ; i > = 0 ; i - - ) { <nl> - <nl> - if ( p_node = = data . window - > window - > tooltip_popup ) <nl> - continue ; <nl> - <nl> - CanvasItem * ci = p_node - > get_child ( i ) - > cast_to < CanvasItem > ( ) ; <nl> - if ( ! ci | | ci - > is_set_as_toplevel ( ) ) <nl> - continue ; <nl> - <nl> - Control * ret = _find_control_at_pos ( ci , p_global , matrix , r_inv_xform ) ; ; <nl> - if ( ret ) <nl> - return ret ; <nl> - } <nl> - } <nl> - <nl> - if ( ! c ) <nl> - return NULL ; <nl> - <nl> - matrix . affine_invert ( ) ; <nl> - <nl> - / / conditions for considering this as a valid control for return <nl> - if ( ! c - > data . ignore_mouse & & c - > has_point ( matrix . xform ( p_global ) ) & & ( ! window - > drag_preview | | ( c ! = window - > drag_preview & & ! window - > drag_preview - > is_a_parent_of ( c ) ) ) ) { <nl> - r_inv_xform = matrix ; <nl> - return c ; <nl> - } else <nl> - return NULL ; <nl> - } <nl> - <nl> - void Control : : _window_cancel_input_ID ( int p_input ) { <nl> <nl> - window - > cancelled_input_ID = ( unsigned int ) p_input ; <nl> - } <nl> <nl> - void Control : : _window_remove_focus ( ) { <nl> - <nl> - if ( window - > key_focus ) { <nl> - <nl> - Node * f = window - > key_focus ; <nl> - window - > key_focus = NULL ; <nl> - f - > notification ( NOTIFICATION_FOCUS_EXIT , true ) ; <nl> - <nl> - } <nl> - } <nl> <nl> - bool Control : : window_has_modal_stack ( ) const { <nl> - <nl> - <nl> - if ( ! data . window ) <nl> - return false ; <nl> - return data . window - > window - > modal_stack . size ( ) ; <nl> - } <nl> <nl> bool Control : : is_window_modal_on_top ( ) const { <nl> <nl> - if ( window_has_modal_stack ( ) ) <nl> - return data . window - > window - > modal_stack . back ( ) - > get ( ) = = this ; <nl> - return false ; <nl> - } <nl> - <nl> - void Control : : _window_cancel_tooltip ( ) { <nl> - <nl> - window - > tooltip = NULL ; <nl> - if ( window - > tooltip_timer ) <nl> - window - > tooltip_timer - > stop ( ) ; <nl> - if ( window - > tooltip_popup ) <nl> - window - > tooltip_popup - > hide ( ) ; <nl> - <nl> - } <nl> - <nl> - void Control : : _window_show_tooltip ( ) { <nl> - <nl> - if ( ! window - > tooltip ) { <nl> - return ; <nl> - } <nl> - <nl> - String tooltip = window - > tooltip - > get_tooltip ( window - > tooltip - > get_global_transform ( ) . xform_inv ( window - > tooltip_pos ) ) ; <nl> - if ( tooltip . length ( ) = = 0 ) <nl> - return ; / / bye <nl> - <nl> - <nl> - if ( ! window - > tooltip_label ) { <nl> - return ; <nl> - } <nl> - Ref < StyleBox > ttp = get_stylebox ( " panel " , " TooltipPanel " ) ; <nl> - <nl> - window - > tooltip_label - > set_anchor_and_margin ( MARGIN_LEFT , ANCHOR_BEGIN , ttp - > get_margin ( MARGIN_LEFT ) ) ; <nl> - window - > tooltip_label - > set_anchor_and_margin ( MARGIN_TOP , ANCHOR_BEGIN , ttp - > get_margin ( MARGIN_TOP ) ) ; <nl> - window - > tooltip_label - > set_anchor_and_margin ( MARGIN_RIGHT , ANCHOR_END , ttp - > get_margin ( MARGIN_RIGHT ) ) ; <nl> - window - > tooltip_label - > set_anchor_and_margin ( MARGIN_BOTTOM , ANCHOR_END , ttp - > get_margin ( MARGIN_BOTTOM ) ) ; <nl> - window - > tooltip_label - > set_text ( tooltip ) ; <nl> - Rect2 r ( window - > tooltip_pos + Point2 ( 10 , 10 ) , window - > tooltip_label - > get_combined_minimum_size ( ) + ttp - > get_minimum_size ( ) ) ; <nl> - Rect2 vr = get_viewport_rect ( ) ; <nl> - if ( r . size . x + r . pos . x > vr . size . x ) <nl> - r . pos . x = vr . size . x - r . size . x ; <nl> - else if ( r . pos . x < 0 ) <nl> - r . pos . x = 0 ; <nl> - <nl> - if ( r . size . y + r . pos . y > vr . size . y ) <nl> - r . pos . y = vr . size . y - r . size . y ; <nl> - else if ( r . pos . y < 0 ) <nl> - r . pos . y = 0 ; <nl> - <nl> - window - > tooltip_popup - > set_pos ( r . pos ) ; <nl> - window - > tooltip_popup - > set_size ( r . size ) ; <nl> - <nl> - window - > tooltip_popup - > raise ( ) ; <nl> - <nl> - window - > tooltip_popup - > show ( ) ; <nl> - } <nl> - <nl> - <nl> - void Control : : _window_call_input ( Control * p_control , const InputEvent & p_input ) { <nl> - <nl> - / / _block ( ) ; <nl> - <nl> - while ( p_control ) { <nl> - <nl> - p_control - > call_multilevel ( SceneStringNames : : get_singleton ( ) - > _input_event , p_input ) ; <nl> - if ( window - > key_event_accepted ) <nl> - break ; <nl> - p_control - > emit_signal ( SceneStringNames : : get_singleton ( ) - > input_event , p_input ) ; <nl> - if ( p_control - > is_set_as_toplevel ( ) ) { <nl> - break ; <nl> - } <nl> - if ( window - > key_event_accepted ) <nl> - break ; <nl> - if ( p_control - > data . stop_mouse & & ( p_input . type = = InputEvent : : MOUSE_BUTTON | | p_input . type = = InputEvent : : MOUSE_MOTION ) ) <nl> - break ; <nl> - p_control = p_control - > data . parent ; <nl> - } <nl> - <nl> - / / _unblock ( ) ; <nl> - <nl> - } <nl> - <nl> - void Control : : _window_input_event ( InputEvent p_event ) { <nl> - <nl> - <nl> - <nl> - if ( ! window ) <nl> - return ; <nl> - <nl> - if ( window - > disable_input ) <nl> - return ; <nl> - <nl> - if ( p_event . ID = = window - > cancelled_input_ID ) { <nl> - return ; <nl> - } <nl> - if ( ! is_visible ( ) ) { <nl> - return ; / / simple and plain <nl> - } <nl> - switch ( p_event . type ) { <nl> - <nl> - case InputEvent : : MOUSE_BUTTON : { <nl> - <nl> - <nl> - window - > key_event_accepted = false ; <nl> - <nl> - Point2 mpos = ( get_canvas_transform ( ) ) . affine_inverse ( ) . xform ( Point2 ( p_event . mouse_button . x , p_event . mouse_button . y ) ) ; <nl> - if ( p_event . mouse_button . pressed ) { <nl> - <nl> - <nl> - <nl> - Size2 pos = mpos ; <nl> - if ( window - > mouse_focus & & p_event . mouse_button . button_index ! = window - > mouse_focus_button ) { <nl> - <nl> - / / do not steal mouse focus and stuff <nl> - <nl> - } else { <nl> - <nl> - <nl> - _window_sort_modal_stack ( ) ; <nl> - while ( ! window - > modal_stack . empty ( ) ) { <nl> - <nl> - Control * top = window - > modal_stack . back ( ) - > get ( ) ; <nl> - if ( ! top - > has_point ( top - > get_global_transform ( ) . affine_inverse ( ) . xform ( pos ) ) ) { <nl> - <nl> - if ( top - > data . modal_exclusive ) { <nl> - / / cancel event , sorry , modal exclusive EATS UP ALL <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - get_tree ( ) - > set_input_as_handled ( ) ; <nl> - return ; / / no one gets the event if exclusive NO ONE <nl> - } <nl> - <nl> - top - > notification ( NOTIFICATION_MODAL_CLOSE ) ; <nl> - top - > _modal_stack_remove ( ) ; <nl> - top - > hide ( ) ; <nl> - } else { <nl> - break ; <nl> - } <nl> - } <nl> - <nl> - <nl> - <nl> - Matrix32 parent_xform ; <nl> - <nl> - if ( data . parent_canvas_item ) <nl> - parent_xform = data . parent_canvas_item - > get_global_transform ( ) ; <nl> - <nl> - <nl> - <nl> - window - > mouse_focus = _find_control_at_pos ( this , pos , parent_xform , window - > focus_inv_xform ) ; <nl> - / / print_line ( " has mf " + itos ( window - > mouse_focus ! = NULL ) ) ; <nl> - window - > mouse_focus_button = p_event . mouse_button . button_index ; <nl> - <nl> - if ( ! window - > mouse_focus ) { <nl> - break ; <nl> - } <nl> - <nl> - if ( p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> - window - > drag_accum = Vector2 ( ) ; <nl> - window - > drag_attempted = false ; <nl> - window - > drag_data = Variant ( ) ; <nl> - } <nl> - <nl> - <nl> - } <nl> - <nl> - p_event . mouse_button . global_x = pos . x ; <nl> - p_event . mouse_button . global_y = pos . y ; <nl> - <nl> - pos = window - > focus_inv_xform . xform ( pos ) ; <nl> - p_event . mouse_button . x = pos . x ; <nl> - p_event . mouse_button . y = pos . y ; <nl> - <nl> - # ifdef DEBUG_ENABLED <nl> - if ( ScriptDebugger : : get_singleton ( ) ) { <nl> - <nl> - Array arr ; <nl> - arr . push_back ( window - > mouse_focus - > get_path ( ) ) ; <nl> - arr . push_back ( window - > mouse_focus - > get_type ( ) ) ; <nl> - ScriptDebugger : : get_singleton ( ) - > send_message ( " click_ctrl " , arr ) ; <nl> - } <nl> - <nl> - / * if ( bool ( GLOBAL_DEF ( " debug / print_clicked_control " , false ) ) ) { <nl> - <nl> - print_line ( String ( window - > mouse_focus - > get_path ( ) ) + " - " + pos ) ; <nl> - } * / <nl> - # endif <nl> - <nl> - if ( window - > mouse_focus - > get_focus_mode ( ) ! = FOCUS_NONE & & window - > mouse_focus ! = window - > key_focus & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> - / / also get keyboard focus <nl> - window - > mouse_focus - > grab_focus ( ) ; <nl> - } <nl> - <nl> - <nl> - if ( window - > mouse_focus - > can_process ( ) ) { <nl> - _window_call_input ( window - > mouse_focus , p_event ) ; <nl> - } <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - get_tree ( ) - > set_input_as_handled ( ) ; <nl> - <nl> - window - > tooltip_popup - > hide ( ) ; <nl> - <nl> - } else { <nl> - <nl> - if ( window - > drag_preview & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> - memdelete ( window - > drag_preview ) ; <nl> - window - > drag_preview = NULL ; <nl> - } <nl> - <nl> - if ( ! window - > mouse_focus ) { <nl> - <nl> - if ( window - > mouse_over & & window - > drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> - <nl> - Size2 pos = mpos ; <nl> - pos = window - > focus_inv_xform . xform ( pos ) ; <nl> - <nl> - window - > mouse_over - > drop_data ( pos , window - > drag_data ) ; <nl> - window - > drag_data = Variant ( ) ; <nl> - / / change mouse accordingly <nl> - } <nl> - <nl> - break ; <nl> - } <nl> - <nl> - Size2 pos = mpos ; <nl> - p_event . mouse_button . global_x = pos . x ; <nl> - p_event . mouse_button . global_y = pos . y ; <nl> - pos = window - > focus_inv_xform . xform ( pos ) ; <nl> - p_event . mouse_button . x = pos . x ; <nl> - p_event . mouse_button . y = pos . y ; <nl> - <nl> - if ( window - > mouse_focus - > can_process ( ) ) { <nl> - _window_call_input ( window - > mouse_focus , p_event ) ; <nl> - } <nl> - <nl> - if ( p_event . mouse_button . button_index = = window - > mouse_focus_button ) { <nl> - window - > mouse_focus = NULL ; <nl> - window - > mouse_focus_button = - 1 ; <nl> - } <nl> - <nl> - if ( window - > drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> - window - > drag_data = Variant ( ) ; / / always clear <nl> - } <nl> - <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - get_tree ( ) - > set_input_as_handled ( ) ; <nl> - <nl> - } <nl> - } break ; <nl> - case InputEvent : : MOUSE_MOTION : { <nl> - <nl> - window - > key_event_accepted = false ; <nl> - <nl> - Matrix32 localizer = ( get_canvas_transform ( ) ) . affine_inverse ( ) ; <nl> - Size2 pos = localizer . xform ( Size2 ( p_event . mouse_motion . x , p_event . mouse_motion . y ) ) ; <nl> - Vector2 speed = localizer . basis_xform ( Point2 ( p_event . mouse_motion . speed_x , p_event . mouse_motion . speed_y ) ) ; <nl> - Vector2 rel = localizer . basis_xform ( Point2 ( p_event . mouse_motion . relative_x , p_event . mouse_motion . relative_y ) ) ; <nl> - <nl> - window - > last_mouse_pos = pos ; <nl> - <nl> - Control * over = NULL ; <nl> - <nl> - Matrix32 parent_xform ; <nl> - if ( data . parent_canvas_item ) <nl> - parent_xform = data . parent_canvas_item - > get_global_transform ( ) ; <nl> - <nl> - / / D & D <nl> - if ( ! window - > drag_attempted & & window - > mouse_focus & & p_event . mouse_motion . button_mask & BUTTON_MASK_LEFT ) { <nl> - <nl> - window - > drag_accum + = rel ; <nl> - float len = window - > drag_accum . length ( ) ; <nl> - if ( len > 10 ) { <nl> - window - > drag_data = window - > mouse_focus - > get_drag_data ( window - > focus_inv_xform . xform ( pos ) - window - > drag_accum ) ; <nl> - if ( window - > drag_data . get_type ( ) ! = Variant : : NIL ) { <nl> - <nl> - window - > mouse_focus = NULL ; <nl> - } <nl> - window - > drag_attempted = true ; <nl> - } <nl> - } <nl> - <nl> - <nl> - if ( window - > mouse_focus ) { <nl> - over = window - > mouse_focus ; <nl> - / / recompute focus_inv_xform again here <nl> - <nl> - } else { <nl> - <nl> - over = _find_control_at_pos ( this , pos , parent_xform , window - > focus_inv_xform ) ; <nl> - } <nl> - <nl> - <nl> - if ( window - > drag_data . get_type ( ) = = Variant : : NIL & & over & & ! window - > modal_stack . empty ( ) ) { <nl> - <nl> - Control * top = window - > modal_stack . back ( ) - > get ( ) ; <nl> - if ( over ! = top & & ! top - > is_a_parent_of ( over ) ) { <nl> - <nl> - break ; / / don ' t send motion event to anything below modal stack top <nl> - } <nl> - } <nl> - <nl> - if ( over ! = window - > mouse_over ) { <nl> - <nl> - if ( window - > mouse_over ) <nl> - window - > mouse_over - > notification ( NOTIFICATION_MOUSE_EXIT ) ; <nl> - <nl> - if ( over ) <nl> - over - > notification ( NOTIFICATION_MOUSE_ENTER ) ; <nl> - <nl> - } <nl> - <nl> - window - > mouse_over = over ; <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_tooltip " ) ; <nl> - <nl> - if ( window - > drag_preview ) { <nl> - window - > drag_preview - > set_pos ( pos ) ; <nl> - } <nl> - <nl> - if ( ! over ) { <nl> - OS : : get_singleton ( ) - > set_cursor_shape ( OS : : CURSOR_ARROW ) ; <nl> - break ; <nl> - } <nl> - <nl> - p_event . mouse_motion . global_x = pos . x ; <nl> - p_event . mouse_motion . global_y = pos . y ; <nl> - p_event . mouse_motion . speed_x = speed . x ; <nl> - p_event . mouse_motion . speed_y = speed . y ; <nl> - p_event . mouse_motion . relative_x = rel . x ; <nl> - p_event . mouse_motion . relative_y = rel . y ; <nl> - <nl> - if ( p_event . mouse_motion . button_mask = = 0 & & window - > tooltip_timer ) { <nl> - / / nothing pressed <nl> - <nl> - bool can_tooltip = true ; <nl> - <nl> - if ( ! window - > modal_stack . empty ( ) ) { <nl> - if ( window - > modal_stack . back ( ) - > get ( ) ! = over & & ! window - > modal_stack . back ( ) - > get ( ) - > is_a_parent_of ( over ) ) <nl> - can_tooltip = false ; <nl> - <nl> - } <nl> - <nl> - <nl> - if ( can_tooltip ) { <nl> - <nl> - window - > tooltip = over ; <nl> - window - > tooltip_pos = ( parent_xform * get_transform ( ) ) . affine_inverse ( ) . xform ( pos ) ; <nl> - window - > tooltip_timer - > start ( ) ; <nl> - } <nl> - } <nl> - <nl> - <nl> - pos = window - > focus_inv_xform . xform ( pos ) ; <nl> - <nl> - <nl> - p_event . mouse_motion . x = pos . x ; <nl> - p_event . mouse_motion . y = pos . y ; <nl> - <nl> - <nl> - CursorShape cursor_shape = over - > get_cursor_shape ( pos ) ; <nl> - OS : : get_singleton ( ) - > set_cursor_shape ( ( OS : : CursorShape ) cursor_shape ) ; <nl> - <nl> - <nl> - if ( over - > can_process ( ) ) { <nl> - _window_call_input ( over , p_event ) ; <nl> - } <nl> - <nl> - <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - get_tree ( ) - > set_input_as_handled ( ) ; <nl> - <nl> - <nl> - if ( window - > drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_motion . button_mask & BUTTON_MASK_LEFT ) { <nl> - <nl> - / * bool can_drop = * / over - > can_drop_data ( pos , window - > drag_data ) ; <nl> - / / change mouse accordingly i guess <nl> - } <nl> - <nl> - } break ; <nl> - case InputEvent : : ACTION : <nl> - case InputEvent : : JOYSTICK_BUTTON : <nl> - case InputEvent : : KEY : { <nl> - <nl> - if ( window - > key_focus ) { <nl> - <nl> - window - > key_event_accepted = false ; <nl> - if ( window - > key_focus - > can_process ( ) ) { <nl> - window - > key_focus - > call_multilevel ( " _input_event " , p_event ) ; <nl> - if ( window - > key_focus ) / / maybe lost it <nl> - window - > key_focus - > emit_signal ( SceneStringNames : : get_singleton ( ) - > input_event , p_event ) ; <nl> - } <nl> - <nl> - <nl> - if ( window - > key_event_accepted ) { <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - break ; <nl> - } <nl> - } <nl> - <nl> - <nl> - if ( p_event . is_pressed ( ) & & p_event . is_action ( " ui_cancel " ) & & ! window - > modal_stack . empty ( ) ) { <nl> - <nl> - _window_sort_modal_stack ( ) ; <nl> - Control * top = window - > modal_stack . back ( ) - > get ( ) ; <nl> - if ( ! top - > data . modal_exclusive ) { <nl> - <nl> - top - > notification ( NOTIFICATION_MODAL_CLOSE ) ; <nl> - top - > _modal_stack_remove ( ) ; <nl> - top - > hide ( ) ; <nl> - } <nl> - } <nl> - <nl> - <nl> - Control * from = window - > key_focus ? window - > key_focus : NULL ; / / hmm <nl> - <nl> - / / keyboard focus <nl> - / / if ( from & & p_event . key . pressed & & ! p_event . key . mod . alt & & ! p_event . key . mod . meta & & ! p_event . key . mod . command ) { <nl> - <nl> - if ( from & & p_event . is_pressed ( ) ) { <nl> - Control * next = NULL ; <nl> - <nl> - if ( p_event . is_action ( " ui_focus_next " ) ) { <nl> - <nl> - next = from - > find_next_valid_focus ( ) ; <nl> - } <nl> - <nl> - if ( p_event . is_action ( " ui_focus_prev " ) ) { <nl> - <nl> - next = from - > find_prev_valid_focus ( ) ; <nl> - } <nl> - <nl> - if ( p_event . is_action ( " ui_up " ) ) { <nl> - <nl> - next = from - > _get_focus_neighbour ( MARGIN_TOP ) ; <nl> - } <nl> - <nl> - if ( p_event . is_action ( " ui_left " ) ) { <nl> - <nl> - next = from - > _get_focus_neighbour ( MARGIN_LEFT ) ; <nl> - } <nl> - <nl> - if ( p_event . is_action ( " ui_right " ) ) { <nl> - <nl> - next = from - > _get_focus_neighbour ( MARGIN_RIGHT ) ; <nl> - } <nl> - <nl> - if ( p_event . is_action ( " ui_down " ) ) { <nl> - <nl> - next = from - > _get_focus_neighbour ( MARGIN_BOTTOM ) ; <nl> - } <nl> - <nl> - <nl> - if ( next ) { <nl> - next - > grab_focus ( ) ; <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> - } <nl> - } <nl> - <nl> - } break ; <nl> - } <nl> - } <nl> + if ( ! is_inside_tree ( ) ) <nl> + return false ; <nl> <nl> - Control * Control : : get_window ( ) const { <nl> - <nl> - return data . window ; <nl> + return get_viewport ( ) - > _gui_is_modal_on_top ( this ) ; <nl> } <nl> <nl> - bool Control : : is_window ( ) const { <nl> - <nl> - return ( is_inside_tree ( ) & & window ) ; <nl> - } <nl> <nl> <nl> Size2 Control : : get_minimum_size ( ) const { <nl> Size2 Control : : get_parent_area_size ( ) const { <nl> if ( data . parent_canvas_item ) { <nl> <nl> parent_size = data . parent_canvas_item - > get_item_rect ( ) . size ; <nl> - } else if ( data . viewport ) { <nl> + } else { <nl> <nl> - parent_size = data . viewport - > get_visible_rect ( ) . size ; <nl> + parent_size = get_viewport ( ) - > get_visible_rect ( ) . size ; <nl> } <nl> return parent_size ; <nl> <nl> float Control : : _get_parent_range ( int p_idx ) const { <nl> } if ( data . parent_canvas_item ) { <nl> <nl> return data . parent_canvas_item - > get_item_rect ( ) . size [ p_idx & 1 ] ; <nl> - } else if ( data . viewport ) { <nl> - return data . viewport - > get_visible_rect ( ) . size [ p_idx & 1 ] ; <nl> + } else { <nl> + return get_viewport ( ) - > get_visible_rect ( ) . size [ p_idx & 1 ] ; <nl> } <nl> <nl> return 1 . 0 ; <nl> Rect2 Control : : get_global_rect ( ) const { <nl> } <nl> <nl> Rect2 Control : : get_window_rect ( ) const { <nl> - <nl> + ERR_FAIL_COND_V ( ! is_inside_tree ( ) , Rect2 ( ) ) ; <nl> Rect2 gr = get_global_rect ( ) ; <nl> - if ( data . viewport ) <nl> - gr . pos + = data . viewport - > get_visible_rect ( ) . pos ; <nl> + gr . pos + = get_viewport ( ) - > get_visible_rect ( ) . pos ; <nl> return gr ; <nl> } <nl> <nl> Control * Control : : find_next_valid_focus ( ) const { <nl> } <nl> <nl> if ( ! next_child ) { <nl> - next_child = get_window ( ) ; <nl> + <nl> + next_child = const_cast < Control * > ( this ) ; ; <nl> + while ( next_child ) { <nl> + <nl> + if ( next_child - > data . SI | | next_child - > data . RI ) <nl> + break ; <nl> + next_child = next_child - > get_parent_control ( ) ; <nl> + <nl> + } <nl> + <nl> + <nl> } <nl> } <nl> <nl> Control : : FocusMode Control : : get_focus_mode ( ) const { <nl> } <nl> bool Control : : has_focus ( ) const { <nl> <nl> - return ( data . window & & data . window - > window - > key_focus = = this ) ; <nl> + return is_inside_tree ( ) & & get_viewport ( ) - > _gui_control_has_focus ( this ) ; <nl> } <nl> <nl> void Control : : grab_focus ( ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> - ERR_FAIL_COND ( ! data . window ) ; <nl> - <nl> if ( data . focus_mode = = FOCUS_NONE ) <nl> return ; <nl> - <nl> - / / no need for change <nl> - if ( data . window - > window - > key_focus & & data . window - > window - > key_focus = = this ) <nl> - return ; <nl> - <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _window_remove_focus " ) ; <nl> - data . window - > window - > key_focus = this ; <nl> - notification ( NOTIFICATION_FOCUS_ENTER ) ; <nl> - # ifdef DEBUG_ENABLED <nl> - if ( GLOBAL_DEF ( " debug / print_clicked_control " , false ) ) { <nl> - print_line ( String ( get_path ( ) ) + " - focus " ) ; <nl> - } ; <nl> - # endif <nl> - update ( ) ; <nl> + <nl> + get_viewport ( ) - > _gui_control_grab_focus ( this ) ; <nl> <nl> } <nl> <nl> void Control : : release_focus ( ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> - ERR_FAIL_COND ( ! data . window ) ; <nl> <nl> if ( ! has_focus ( ) ) <nl> return ; <nl> <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _window_remove_focus " ) ; <nl> - / / data . window - > window - > key_focus = this ; <nl> - / / notification ( NOTIFICATION_FOCUS_ENTER ) ; <nl> + get_viewport ( ) - > _gui_remove_focus ( ) ; <nl> update ( ) ; <nl> <nl> } <nl> <nl> bool Control : : is_toplevel_control ( ) const { <nl> <nl> - return is_inside_tree ( ) & & ( ! data . parent_canvas_item & & ! window & & is_set_as_toplevel ( ) ) ; <nl> + return is_inside_tree ( ) & & ( ! data . parent_canvas_item & & ! data . RI & & is_set_as_toplevel ( ) ) ; <nl> } <nl> <nl> void Control : : show_modal ( bool p_exclusive ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> - ERR_FAIL_COND ( ! data . SI & & data . window ! = this ) ; <nl> - ERR_FAIL_COND ( ! data . window ) ; <nl> + ERR_FAIL_COND ( ! data . SI ) ; <nl> <nl> if ( is_visible ( ) ) <nl> hide ( ) ; <nl> <nl> - ERR_FAIL_COND ( data . MI ) ; <nl> + ERR_FAIL_COND ( data . MI ! = NULL ) ; <nl> show ( ) ; <nl> raise ( ) ; <nl> - <nl> - data . window - > window - > modal_stack . push_back ( this ) ; <nl> - data . MI = data . window - > window - > modal_stack . back ( ) ; <nl> data . modal_exclusive = p_exclusive ; <nl> - if ( data . window - > window - > key_focus ) <nl> - data . modal_prev_focus_owner = data . window - > window - > key_focus - > get_instance_ID ( ) ; <nl> - else <nl> - data . modal_prev_focus_owner = 0 ; <nl> + data . MI = get_viewport ( ) - > _gui_show_modal ( this ) ; <nl> <nl> } <nl> <nl> - void Control : : _window_sort_subwindows ( ) { <nl> - <nl> - if ( ! window - > subwindow_order_dirty ) <nl> - return ; <nl> - <nl> - <nl> - window - > modal_stack . sort_custom < CComparator > ( ) ; <nl> - window - > subwindows . sort_custom < CComparator > ( ) ; <nl> - <nl> - window - > subwindow_order_dirty = false ; <nl> - <nl> - } <nl> - <nl> - void Control : : _window_sort_modal_stack ( ) { <nl> - <nl> - window - > modal_stack . sort_custom < CComparator > ( ) ; <nl> + void Control : : _modal_set_prev_focus_owner ( ObjectID p_prev ) { <nl> + data . modal_prev_focus_owner = p_prev ; <nl> } <nl> <nl> void Control : : _modal_stack_remove ( ) { <nl> <nl> <nl> - List < Control * > : : Element * next = NULL ; / / transfer the focus stack to the next <nl> - <nl> - <nl> - if ( data . window & & data . MI ) { <nl> - <nl> - next = data . MI - > next ( ) ; <nl> - <nl> - <nl> - data . window - > window - > modal_stack . erase ( data . MI ) ; <nl> - data . MI = NULL ; <nl> - } <nl> - <nl> - if ( data . modal_prev_focus_owner ) { <nl> - <nl> - if ( ! next ) { / / top of stack <nl> + ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> <nl> - Object * pfo = ObjectDB : : get_instance ( data . modal_prev_focus_owner ) ; <nl> - Control * pfoc = pfo - > cast_to < Control > ( ) ; <nl> - if ( ! pfoc ) <nl> - return ; <nl> + if ( ! data . MI ) <nl> + return ; <nl> <nl> - if ( ! pfoc - > is_inside_tree ( ) | | ! pfoc - > is_visible ( ) ) <nl> - return ; <nl> - pfoc - > grab_focus ( ) ; <nl> - } else { <nl> + get_viewport ( ) - > _gui_remove_from_modal_stack ( data . MI , data . modal_prev_focus_owner ) ; <nl> <nl> - next - > get ( ) - > data . modal_prev_focus_owner = data . modal_prev_focus_owner ; <nl> - } <nl> + data . MI = NULL ; <nl> + data . modal_prev_focus_owner = 0 ; <nl> <nl> - data . modal_prev_focus_owner = 0 ; <nl> - } <nl> } <nl> <nl> void Control : : _propagate_theme_changed ( Control * p_owner ) { <nl> void Control : : set_theme ( const Ref < Theme > & p_theme ) { <nl> <nl> } <nl> <nl> - void Control : : _window_accept_event ( ) { <nl> + void Control : : accept_event ( ) { <nl> <nl> - window - > key_event_accepted = true ; <nl> if ( is_inside_tree ( ) ) <nl> - get_tree ( ) - > set_input_as_handled ( ) ; <nl> + get_viewport ( ) - > _gui_accept_event ( ) ; <nl> <nl> - } <nl> - void Control : : accept_event ( ) { <nl> - <nl> - if ( is_inside_tree ( ) & & get_window ( ) ) <nl> - get_window ( ) - > _window_accept_event ( ) ; <nl> <nl> } <nl> <nl> Control * Control : : _get_focus_neighbour ( Margin p_margin , int p_count ) { <nl> if ( c ) { <nl> if ( c - > data . SI ) <nl> break ; <nl> - if ( c = = data . window ) <nl> + if ( c - > data . RI ) <nl> break ; <nl> } <nl> base = base - > get_parent ( ) ; <nl> void Control : : grab_click_focus ( ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> <nl> - if ( data . window & & data . window - > window - > mouse_focus ) { <nl> - <nl> - Window * w = data . window - > window ; <nl> - if ( w - > mouse_focus = = this ) <nl> - return ; <nl> - InputEvent ie ; <nl> - ie . type = InputEvent : : MOUSE_BUTTON ; <nl> - InputEventMouseButton & mb = ie . mouse_button ; <nl> - <nl> - / / send unclic <nl> - <nl> - Point2 click = w - > mouse_focus - > get_global_transform ( ) . affine_inverse ( ) . xform ( w - > last_mouse_pos ) ; <nl> - mb . x = click . x ; <nl> - mb . y = click . y ; <nl> - mb . button_index = w - > mouse_focus_button ; <nl> - mb . pressed = false ; <nl> - w - > mouse_focus - > call_deferred ( " _input_event " , ie ) ; <nl> + get_viewport ( ) - > _gui_grab_click_focus ( this ) ; <nl> <nl> - <nl> - w - > mouse_focus = this ; <nl> - w - > focus_inv_xform = w - > mouse_focus - > get_global_transform ( ) . affine_inverse ( ) ; <nl> - click = w - > mouse_focus - > get_global_transform ( ) . affine_inverse ( ) . xform ( w - > last_mouse_pos ) ; <nl> - mb . x = click . x ; <nl> - mb . y = click . y ; <nl> - mb . button_index = w - > mouse_focus_button ; <nl> - mb . pressed = true ; <nl> - w - > mouse_focus - > call_deferred ( " _input_event " , ie ) ; <nl> - <nl> - } <nl> } <nl> <nl> void Control : : minimum_size_changed ( ) { <nl> bool Control : : is_stopping_mouse ( ) const { <nl> Control * Control : : get_focus_owner ( ) const { <nl> <nl> ERR_FAIL_COND_V ( ! is_inside_tree ( ) , NULL ) ; <nl> - ERR_FAIL_COND_V ( ! data . window , NULL ) ; <nl> - return data . window - > window - > key_focus ; <nl> + return get_viewport ( ) - > _gui_get_focus_owner ( ) ; <nl> } <nl> <nl> <nl> Vector2 Control : : get_scale ( ) const { <nl> <nl> void Control : : _bind_methods ( ) { <nl> <nl> - ObjectTypeDB : : bind_method ( _MD ( " _window_input_event " ) , & Control : : _window_input_event ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _gui_input " ) , & Control : : _gui_input ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _input_text " ) , & Control : : _input_text ) ; <nl> + <nl> / / ObjectTypeDB : : bind_method ( _MD ( " _window_resize_event " ) , & Control : : _window_resize_event ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _window_remove_focus " ) , & Control : : _window_remove_focus ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _cancel_input_ID " ) , & Control : : _window_cancel_input_ID ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _cancel_tooltip " ) , & Control : : _window_cancel_tooltip ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " _window_show_tooltip " ) , & Control : : _window_show_tooltip ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " _size_changed " ) , & Control : : _size_changed ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " _update_minimum_size " ) , & Control : : _update_minimum_size ) ; <nl> <nl> ObjectTypeDB : : bind_method ( _MD ( " accept_event " ) , & Control : : accept_event ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " get_minimum_size " ) , & Control : : get_minimum_size ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " get_combined_minimum_size " ) , & Control : : get_combined_minimum_size ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " is_window " ) , & Control : : is_window ) ; <nl> - ObjectTypeDB : : bind_method ( _MD ( " get_window " ) , & Control : : get_window ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " set_anchor " , " margin " , " anchor_mode " ) , & Control : : set_anchor ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " get_anchor " , " margin " ) , & Control : : get_anchor ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " set_margin " , " margin " , " offset " ) , & Control : : set_margin ) ; <nl> void Control : : _bind_methods ( ) { <nl> } <nl> Control : : Control ( ) { <nl> <nl> - data . parent = NULL ; <nl> - data . window = NULL ; <nl> - data . viewport = NULL ; <nl> + data . parent = NULL ; <nl> + <nl> data . ignore_mouse = false ; <nl> data . stop_mouse = true ; <nl> - window = NULL ; <nl> + <nl> <nl> data . SI = NULL ; <nl> data . MI = NULL ; <nl> + data . RI = NULL ; <nl> data . modal = false ; <nl> data . theme_owner = NULL ; <nl> data . modal_exclusive = false ; <nl> Control : : Control ( ) { <nl> data . expand = 1 ; <nl> data . pending_min_size_update = false ; <nl> data . rotation = 0 ; <nl> + data . parent_canvas_item = NULL ; <nl> data . scale = Vector2 ( 1 , 1 ) ; <nl> <nl> <nl> mmm a / scene / gui / control . h <nl> ppp b / scene / gui / control . h <nl> class Control : public CanvasItem { <nl> bool stop_mouse ; <nl> <nl> Control * parent ; <nl> - Control * window ; <nl> bool modal ; <nl> bool modal_exclusive ; <nl> Ref < Theme > theme ; <nl> class Control : public CanvasItem { <nl> <nl> List < Control * > : : Element * MI ; / / modal item <nl> List < Control * > : : Element * SI ; <nl> + List < Control * > : : Element * RI ; <nl> <nl> CanvasItem * parent_canvas_item ; <nl> <nl> - Viewport * viewport ; <nl> - <nl> ObjectID modal_prev_focus_owner ; <nl> <nl> NodePath focus_neighbour [ 4 ] ; <nl> class Control : public CanvasItem { <nl> HashMap < StringName , Color , StringNameHasher > color_override ; <nl> HashMap < StringName , int , StringNameHasher > constant_override ; <nl> } data ; <nl> - <nl> - struct Window { <nl> - / / info used when this is a window <nl> - <nl> - bool key_event_accepted ; <nl> - Control * mouse_focus ; <nl> - int mouse_focus_button ; <nl> - Control * key_focus ; <nl> - Control * mouse_over ; <nl> - Control * tooltip ; <nl> - Panel * tooltip_popup ; <nl> - Label * tooltip_label ; <nl> - Point2 tooltip_pos ; <nl> - Point2 last_mouse_pos ; <nl> - Point2 drag_accum ; <nl> - bool drag_attempted ; <nl> - Variant drag_data ; <nl> - Control * drag_preview ; <nl> - Timer * tooltip_timer ; <nl> - List < Control * > modal_stack ; <nl> - unsigned int cancelled_input_ID ; <nl> - Matrix32 focus_inv_xform ; <nl> - bool subwindow_order_dirty ; <nl> - List < Control * > subwindows ; <nl> - bool disable_input ; <nl> - <nl> - Window ( ) ; <nl> - } ; <nl> - <nl> - Window * window ; <nl> - <nl> + <nl> / / used internally <nl> - Control * _find_next_visible_control_at_pos ( Node * p_node , const Point2 & p_global , Matrix32 & r_xform ) const ; <nl> Control * _find_control_at_pos ( CanvasItem * p_node , const Point2 & p_pos , const Matrix32 & p_xform , Matrix32 & r_inv_xform ) ; <nl> <nl> <nl> - void _window_sort_subwindows ( ) ; <nl> - void _window_accept_event ( ) ; <nl> - void _window_remove_focus ( ) ; <nl> - void _window_cancel_input_ID ( int p_input ) ; <nl> - void _window_sort_modal_stack ( ) ; <nl> void _window_find_focus_neighbour ( const Vector2 & p_dir , Node * p_at , const Point2 * p_points , float p_min , float & r_closest_dist , Control * * r_closest ) ; <nl> Control * _get_focus_neighbour ( Margin p_margin , int p_count = 0 ) ; <nl> - void _window_call_input ( Control * p_control , const InputEvent & p_input ) ; <nl> + <nl> <nl> float _get_parent_range ( int p_idx ) const ; <nl> float _get_range ( int p_idx ) const ; <nl> float _s2a ( float p_val , AnchorType p_anchor , float p_range ) const ; <nl> float _a2s ( float p_val , AnchorType p_anchor , float p_range ) const ; <nl> - void _modal_stack_remove ( ) ; <nl> void _propagate_theme_changed ( Control * p_owner ) ; <nl> <nl> void _change_notify_margins ( ) ; <nl> - void _window_cancel_tooltip ( ) ; <nl> - void _window_show_tooltip ( ) ; <nl> void _update_minimum_size ( ) ; <nl> <nl> void _update_scroll ( ) ; <nl> - void _gui_input ( const InputEvent & p_event ) ; / / used by scene main loop <nl> - void _input_text ( const String & p_text ) ; <nl> void _resize ( const Size2 & p_size ) ; <nl> <nl> void _size_changed ( ) ; <nl> class Control : public CanvasItem { <nl> void _set_rotation_deg ( float p_rot ) ; <nl> float _get_rotation_deg ( ) const ; <nl> <nl> + friend class Viewport ; <nl> + void _modal_stack_remove ( ) ; <nl> + void _modal_set_prev_focus_owner ( ObjectID p_prev ) ; <nl> + <nl> protected : <nl> - bool window_has_modal_stack ( ) const ; <nl> <nl> - virtual void _window_input_event ( InputEvent p_event ) ; <nl> + / / virtual void _window_input_event ( InputEvent p_event ) ; <nl> <nl> bool _set ( const StringName & p_name , const Variant & p_value ) ; <nl> bool _get ( const StringName & p_name , Variant & r_ret ) const ; <nl> class Control : public CanvasItem { <nl> <nl> bool is_window_modal_on_top ( ) const ; <nl> <nl> - bool is_window ( ) const ; <nl> - Control * get_window ( ) const ; <nl> Control * get_parent_control ( ) const ; <nl> <nl> <nl> mmm a / scene / gui / popup . cpp <nl> ppp b / scene / gui / popup . cpp <nl> void Popup : : _notification ( int p_what ) { <nl> <nl> void Popup : : _fix_size ( ) { <nl> <nl> - Control * window = get_window ( ) ; <nl> - ERR_FAIL_COND ( ! window ) ; <nl> <nl> # if 0 <nl> Point2 pos = get_pos ( ) ; <nl> void Popup : : popup_centered_minsize ( const Size2 & p_minsize ) { <nl> <nl> void Popup : : popup_centered ( const Size2 & p_size ) { <nl> <nl> - Control * window = get_window ( ) ; <nl> - ERR_FAIL_COND ( ! window ) ; <nl> - <nl> + Point2 window_size = get_viewport_rect ( ) . size ; <nl> <nl> emit_signal ( " about_to_show " ) ; <nl> Rect2 rect ; <nl> rect . size = p_size = = Size2 ( ) ? get_size ( ) : p_size ; <nl> - Point2 window_size = window = = this ? get_parent_area_size ( ) : window - > get_size ( ) ; <nl> + <nl> rect . pos = ( ( window_size - rect . size ) / 2 . 0 ) . floor ( ) ; <nl> set_pos ( rect . pos ) ; <nl> set_size ( rect . size ) ; <nl> void Popup : : popup_centered ( const Size2 & p_size ) { <nl> void Popup : : popup_centered_ratio ( float p_screen_ratio ) { <nl> <nl> <nl> - Control * window = get_window ( ) ; <nl> - ERR_FAIL_COND ( ! window ) ; <nl> <nl> emit_signal ( " about_to_show " ) ; <nl> <nl> Rect2 rect ; <nl> - Point2 window_size = window = = this ? get_parent_area_size ( ) : window - > get_size ( ) ; <nl> + Point2 window_size = get_viewport_rect ( ) . size ; <nl> rect . size = ( window_size * p_screen_ratio ) . floor ( ) ; <nl> rect . pos = ( ( window_size - rect . size ) / 2 . 0 ) . floor ( ) ; <nl> set_pos ( rect . pos ) ; <nl> mmm a / scene / main / scene_main_loop . cpp <nl> ppp b / scene / main / scene_main_loop . cpp <nl> void SceneTree : : input_text ( const String & p_text ) { <nl> <nl> root_lock + + ; <nl> <nl> - call_group ( GROUP_CALL_REALTIME | GROUP_CALL_MULIILEVEL , " input " , p_text ) ; <nl> + call_group ( GROUP_CALL_REALTIME , " _viewports " , " _vp_input_text " , p_text ) ; / / special one for GUI , as controls use their own process check <nl> + <nl> root_lock - - ; <nl> <nl> } <nl> mmm a / scene / main / viewport . cpp <nl> ppp b / scene / main / viewport . cpp <nl> <nl> <nl> # include " scene / 2d / collision_object_2d . h " <nl> <nl> + # include " scene / gui / panel . h " <nl> + # include " scene / gui / label . h " <nl> + # include " scene / main / timer . h " <nl> + # include " scene / scene_string_names . h " <nl> + <nl> + # include " globals . h " <nl> + <nl> int RenderTargetTexture : : get_width ( ) const { <nl> <nl> ERR_FAIL_COND_V ( ! vp , 0 ) ; <nl> RenderTargetTexture : : RenderTargetTexture ( Viewport * p_vp ) { <nl> flags = 0 ; <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + class TooltipPanel : public Panel { <nl> + <nl> + OBJ_TYPE ( TooltipPanel , Panel ) <nl> + public : <nl> + TooltipPanel ( ) { } ; <nl> + <nl> + } ; <nl> + <nl> + class TooltipLabel : public Label { <nl> + <nl> + OBJ_TYPE ( TooltipLabel , Label ) <nl> + public : <nl> + TooltipLabel ( ) { } ; <nl> + <nl> + } ; <nl> + <nl> + <nl> + Viewport : : GUI : : GUI ( ) { <nl> + <nl> + <nl> + mouse_focus = NULL ; <nl> + mouse_focus_button = - 1 ; <nl> + key_focus = NULL ; <nl> + mouse_over = NULL ; <nl> + <nl> + cancelled_input_ID = 0 ; <nl> + tooltip = NULL ; <nl> + tooltip_popup = NULL ; <nl> + tooltip_label = NULL ; <nl> + subwindow_order_dirty = false ; <nl> + } <nl> <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void Viewport : : _update_stretch_transform ( ) { <nl> <nl> if ( size_override_stretch & & size_override ) { <nl> void Viewport : : _make_input_local ( InputEvent & ev ) { <nl> <nl> } <nl> <nl> + void Viewport : : _vp_input_text ( const String & p_text ) { <nl> + <nl> + if ( gui . key_focus ) { <nl> + gui . key_focus - > call ( " set_text " , p_text ) ; <nl> + } <nl> + } <nl> <nl> void Viewport : : _vp_input ( const InputEvent & p_ev ) { <nl> <nl> + if ( disable_input ) <nl> + return ; <nl> + <nl> if ( render_target & & to_screen_rect = = Rect2 ( ) ) <nl> return ; / / if render target , can ' t get input events <nl> <nl> / / this one handles system input , p_ev are in system coordinates <nl> / / they are converted to viewport coordinates <nl> <nl> + <nl> InputEvent ev = p_ev ; <nl> _make_input_local ( ev ) ; <nl> input ( ev ) ; <nl> void Viewport : : warp_mouse ( const Vector2 & p_pos ) { <nl> Input : : get_singleton ( ) - > warp_mouse_pos ( gpos ) ; <nl> } <nl> <nl> + <nl> + <nl> + void Viewport : : _gui_sort_subwindows ( ) { <nl> + <nl> + if ( ! gui . subwindow_order_dirty ) <nl> + return ; <nl> + <nl> + <nl> + gui . modal_stack . sort_custom < Control : : CComparator > ( ) ; <nl> + gui . subwindows . sort_custom < Control : : CComparator > ( ) ; <nl> + <nl> + gui . subwindow_order_dirty = false ; <nl> + } <nl> + <nl> + void Viewport : : _gui_sort_modal_stack ( ) { <nl> + <nl> + gui . modal_stack . sort_custom < Control : : CComparator > ( ) ; <nl> + } <nl> + <nl> + <nl> + void Viewport : : _gui_sort_roots ( ) { <nl> + <nl> + if ( ! gui . roots_order_dirty ) <nl> + return ; <nl> + <nl> + gui . roots . sort_custom < Control : : CComparator > ( ) ; <nl> + <nl> + gui . roots_order_dirty = false ; <nl> + } <nl> + <nl> + <nl> + void Viewport : : _gui_cancel_tooltip ( ) { <nl> + <nl> + gui . tooltip = NULL ; <nl> + if ( gui . tooltip_timer ) <nl> + gui . tooltip_timer - > stop ( ) ; <nl> + if ( gui . tooltip_popup ) <nl> + gui . tooltip_popup - > hide ( ) ; <nl> + <nl> + } <nl> + <nl> + void Viewport : : _gui_show_tooltip ( ) { <nl> + <nl> + if ( ! gui . tooltip ) { <nl> + return ; <nl> + } <nl> + <nl> + String tooltip = gui . tooltip - > get_tooltip ( gui . tooltip - > get_global_transform ( ) . xform_inv ( gui . tooltip_pos ) ) ; <nl> + if ( tooltip . length ( ) = = 0 ) <nl> + return ; / / bye <nl> + <nl> + <nl> + if ( ! gui . tooltip_label ) { <nl> + return ; <nl> + } <nl> + Ref < StyleBox > ttp = gui . tooltip_label - > get_stylebox ( " panel " , " TooltipPanel " ) ; <nl> + <nl> + gui . tooltip_label - > set_anchor_and_margin ( MARGIN_LEFT , Control : : ANCHOR_BEGIN , ttp - > get_margin ( MARGIN_LEFT ) ) ; <nl> + gui . tooltip_label - > set_anchor_and_margin ( MARGIN_TOP , Control : : ANCHOR_BEGIN , ttp - > get_margin ( MARGIN_TOP ) ) ; <nl> + gui . tooltip_label - > set_anchor_and_margin ( MARGIN_RIGHT , Control : : ANCHOR_END , ttp - > get_margin ( MARGIN_RIGHT ) ) ; <nl> + gui . tooltip_label - > set_anchor_and_margin ( MARGIN_BOTTOM , Control : : ANCHOR_END , ttp - > get_margin ( MARGIN_BOTTOM ) ) ; <nl> + gui . tooltip_label - > set_text ( tooltip ) ; <nl> + Rect2 r ( gui . tooltip_pos + Point2 ( 10 , 10 ) , gui . tooltip_label - > get_combined_minimum_size ( ) + ttp - > get_minimum_size ( ) ) ; <nl> + Rect2 vr = gui . tooltip_label - > get_viewport_rect ( ) ; <nl> + if ( r . size . x + r . pos . x > vr . size . x ) <nl> + r . pos . x = vr . size . x - r . size . x ; <nl> + else if ( r . pos . x < 0 ) <nl> + r . pos . x = 0 ; <nl> + <nl> + if ( r . size . y + r . pos . y > vr . size . y ) <nl> + r . pos . y = vr . size . y - r . size . y ; <nl> + else if ( r . pos . y < 0 ) <nl> + r . pos . y = 0 ; <nl> + <nl> + gui . tooltip_popup - > set_pos ( r . pos ) ; <nl> + gui . tooltip_popup - > set_size ( r . size ) ; <nl> + <nl> + gui . tooltip_popup - > raise ( ) ; <nl> + <nl> + gui . tooltip_popup - > show ( ) ; <nl> + } <nl> + <nl> + <nl> + void Viewport : : _gui_call_input ( Control * p_control , const InputEvent & p_input ) { <nl> + <nl> + / / _block ( ) ; <nl> + <nl> + while ( p_control ) { <nl> + <nl> + p_control - > call_multilevel ( SceneStringNames : : get_singleton ( ) - > _input_event , p_input ) ; <nl> + if ( gui . key_event_accepted ) <nl> + break ; <nl> + if ( ! p_control - > is_inside_tree ( ) ) <nl> + break ; <nl> + p_control - > emit_signal ( SceneStringNames : : get_singleton ( ) - > input_event , p_input ) ; <nl> + if ( ! p_control - > is_inside_tree ( ) | | p_control - > is_set_as_toplevel ( ) ) { <nl> + break ; <nl> + } <nl> + if ( gui . key_event_accepted ) <nl> + break ; <nl> + if ( p_control - > data . stop_mouse & & ( p_input . type = = InputEvent : : MOUSE_BUTTON | | p_input . type = = InputEvent : : MOUSE_MOTION ) ) <nl> + break ; <nl> + p_control = p_control - > data . parent ; <nl> + } <nl> + <nl> + / / _unblock ( ) ; <nl> + <nl> + } <nl> + <nl> + Control * Viewport : : _gui_find_control ( const Point2 & p_global ) { <nl> + <nl> + _gui_sort_subwindows ( ) ; <nl> + <nl> + for ( List < Control * > : : Element * E = gui . subwindows . back ( ) ; E ; E = E - > prev ( ) ) { <nl> + <nl> + Control * sw = E - > get ( ) ; <nl> + if ( ! sw - > is_visible ( ) ) <nl> + continue ; <nl> + <nl> + Matrix32 xform ; <nl> + CanvasItem * pci = sw - > get_parent_item ( ) ; <nl> + if ( pci ) <nl> + xform = pci - > get_global_transform ( ) ; <nl> + <nl> + <nl> + Control * ret = _gui_find_control_at_pos ( sw , p_global , xform , gui . focus_inv_xform ) ; <nl> + if ( ret ) <nl> + return ret ; <nl> + } <nl> + <nl> + for ( List < Control * > : : Element * E = gui . roots . back ( ) ; E ; E = E - > prev ( ) ) { <nl> + <nl> + Control * sw = E - > get ( ) ; <nl> + if ( ! sw - > is_visible ( ) ) <nl> + continue ; <nl> + <nl> + Matrix32 xform ; <nl> + CanvasItem * pci = sw - > get_parent_item ( ) ; <nl> + if ( pci ) <nl> + xform = pci - > get_global_transform ( ) ; <nl> + <nl> + <nl> + Control * ret = _gui_find_control_at_pos ( sw , p_global , xform , gui . focus_inv_xform ) ; <nl> + if ( ret ) <nl> + return ret ; <nl> + } <nl> + <nl> + return NULL ; <nl> + <nl> + } <nl> + <nl> + <nl> + Control * Viewport : : _gui_find_control_at_pos ( CanvasItem * p_node , const Point2 & p_global , const Matrix32 & p_xform , Matrix32 & r_inv_xform ) { <nl> + <nl> + if ( p_node - > cast_to < Viewport > ( ) ) <nl> + return NULL ; <nl> + <nl> + Control * c = p_node - > cast_to < Control > ( ) ; <nl> + <nl> + if ( c ) { <nl> + / / print_line ( " at " + String ( c - > get_path ( ) ) + " POS " + c - > get_pos ( ) + " bt " + p_xform ) ; <nl> + } <nl> + <nl> + / / subwindows first ! ! <nl> + <nl> + if ( p_node - > is_hidden ( ) ) { <nl> + / / return _find_next_visible_control_at_pos ( p_node , p_global , r_inv_xform ) ; <nl> + return NULL ; / / canvas item hidden , discard <nl> + } <nl> + <nl> + Matrix32 matrix = p_xform * p_node - > get_transform ( ) ; <nl> + <nl> + if ( ! c | | ! c - > clips_input ( ) | | c - > has_point ( matrix . affine_inverse ( ) . xform ( p_global ) ) ) { <nl> + <nl> + for ( int i = p_node - > get_child_count ( ) - 1 ; i > = 0 ; i - - ) { <nl> + <nl> + if ( p_node = = gui . tooltip_popup ) <nl> + continue ; <nl> + <nl> + CanvasItem * ci = p_node - > get_child ( i ) - > cast_to < CanvasItem > ( ) ; <nl> + if ( ! ci | | ci - > is_set_as_toplevel ( ) ) <nl> + continue ; <nl> + <nl> + Control * ret = _gui_find_control_at_pos ( ci , p_global , matrix , r_inv_xform ) ; ; <nl> + if ( ret ) <nl> + return ret ; <nl> + } <nl> + } <nl> + <nl> + if ( ! c ) <nl> + return NULL ; <nl> + <nl> + matrix . affine_invert ( ) ; <nl> + <nl> + / / conditions for considering this as a valid control for return <nl> + if ( ! c - > data . ignore_mouse & & c - > has_point ( matrix . xform ( p_global ) ) & & ( ! gui . drag_preview | | ( c ! = gui . drag_preview & & ! gui . drag_preview - > is_a_parent_of ( c ) ) ) ) { <nl> + r_inv_xform = matrix ; <nl> + return c ; <nl> + } else <nl> + return NULL ; <nl> + } <nl> + <nl> + void Viewport : : _gui_input_event ( InputEvent p_event ) { <nl> + <nl> + <nl> + <nl> + if ( p_event . ID = = gui . cancelled_input_ID ) { <nl> + return ; <nl> + } <nl> + / / ? <nl> + / / if ( ! is_visible ( ) ) { <nl> + / / return ; / / simple and plain <nl> + / / } <nl> + <nl> + <nl> + switch ( p_event . type ) { <nl> + <nl> + case InputEvent : : MOUSE_BUTTON : { <nl> + <nl> + <nl> + gui . key_event_accepted = false ; <nl> + <nl> + Point2 mpos = Point2 ( p_event . mouse_button . x , p_event . mouse_button . y ) ; <nl> + if ( p_event . mouse_button . pressed ) { <nl> + <nl> + <nl> + <nl> + Size2 pos = mpos ; <nl> + if ( gui . mouse_focus & & p_event . mouse_button . button_index ! = gui . mouse_focus_button ) { <nl> + <nl> + / / do not steal mouse focus and stuff <nl> + <nl> + } else { <nl> + <nl> + <nl> + _gui_sort_modal_stack ( ) ; <nl> + while ( ! gui . modal_stack . empty ( ) ) { <nl> + <nl> + Control * top = gui . modal_stack . back ( ) - > get ( ) ; <nl> + Vector2 pos = top - > get_global_transform_with_canvas ( ) . affine_inverse ( ) . xform ( mpos ) ; <nl> + if ( ! top - > has_point ( pos ) ) { <nl> + <nl> + print_line ( " NO POINT " ) ; <nl> + if ( top - > data . modal_exclusive ) { <nl> + / / cancel event , sorry , modal exclusive EATS UP ALL <nl> + / / get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + get_tree ( ) - > set_input_as_handled ( ) ; <nl> + return ; / / no one gets the event if exclusive NO ONE <nl> + } <nl> + <nl> + top - > notification ( Control : : NOTIFICATION_MODAL_CLOSE ) ; <nl> + top - > _modal_stack_remove ( ) ; <nl> + top - > hide ( ) ; <nl> + } else { <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + <nl> + <nl> + Matrix32 parent_xform ; <nl> + <nl> + / / if ( data . parent_canvas_item ) <nl> + / / parent_xform = data . parent_canvas_item - > get_global_transform ( ) ; <nl> + <nl> + <nl> + <nl> + gui . mouse_focus = _gui_find_control ( pos ) ; <nl> + / / print_line ( " has mf " + itos ( gui . mouse_focus ! = NULL ) ) ; <nl> + gui . mouse_focus_button = p_event . mouse_button . button_index ; <nl> + <nl> + if ( ! gui . mouse_focus ) { <nl> + break ; <nl> + } <nl> + <nl> + if ( p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> + gui . drag_accum = Vector2 ( ) ; <nl> + gui . drag_attempted = false ; <nl> + gui . drag_data = Variant ( ) ; <nl> + } <nl> + <nl> + <nl> + } <nl> + <nl> + p_event . mouse_button . global_x = pos . x ; <nl> + p_event . mouse_button . global_y = pos . y ; <nl> + <nl> + pos = gui . focus_inv_xform . xform ( pos ) ; <nl> + p_event . mouse_button . x = pos . x ; <nl> + p_event . mouse_button . y = pos . y ; <nl> + <nl> + # ifdef DEBUG_ENABLED <nl> + if ( ScriptDebugger : : get_singleton ( ) ) { <nl> + <nl> + Array arr ; <nl> + arr . push_back ( gui . mouse_focus - > get_path ( ) ) ; <nl> + arr . push_back ( gui . mouse_focus - > get_type ( ) ) ; <nl> + ScriptDebugger : : get_singleton ( ) - > send_message ( " click_ctrl " , arr ) ; <nl> + } <nl> + <nl> + / * if ( bool ( GLOBAL_DEF ( " debug / print_clicked_control " , false ) ) ) { <nl> + <nl> + print_line ( String ( gui . mouse_focus - > get_path ( ) ) + " - " + pos ) ; <nl> + } * / <nl> + # endif <nl> + <nl> + if ( gui . mouse_focus - > get_focus_mode ( ) ! = Control : : FOCUS_NONE & & gui . mouse_focus ! = gui . key_focus & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> + / / also get keyboard focus <nl> + gui . mouse_focus - > grab_focus ( ) ; <nl> + } <nl> + <nl> + <nl> + if ( gui . mouse_focus - > can_process ( ) ) { <nl> + _gui_call_input ( gui . mouse_focus , p_event ) ; <nl> + } <nl> + <nl> + get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + get_tree ( ) - > set_input_as_handled ( ) ; <nl> + <nl> + gui . tooltip_popup - > hide ( ) ; <nl> + <nl> + } else { <nl> + <nl> + if ( gui . drag_preview & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> + memdelete ( gui . drag_preview ) ; <nl> + gui . drag_preview = NULL ; <nl> + } <nl> + <nl> + if ( ! gui . mouse_focus ) { <nl> + <nl> + if ( gui . mouse_over & & gui . drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> + <nl> + Size2 pos = mpos ; <nl> + pos = gui . focus_inv_xform . xform ( pos ) ; <nl> + <nl> + gui . mouse_over - > drop_data ( pos , gui . drag_data ) ; <nl> + gui . drag_data = Variant ( ) ; <nl> + / / change mouse accordingly <nl> + } <nl> + <nl> + break ; <nl> + } <nl> + <nl> + Size2 pos = mpos ; <nl> + p_event . mouse_button . global_x = pos . x ; <nl> + p_event . mouse_button . global_y = pos . y ; <nl> + pos = gui . focus_inv_xform . xform ( pos ) ; <nl> + p_event . mouse_button . x = pos . x ; <nl> + p_event . mouse_button . y = pos . y ; <nl> + <nl> + if ( gui . mouse_focus - > can_process ( ) ) { <nl> + _gui_call_input ( gui . mouse_focus , p_event ) ; <nl> + } <nl> + <nl> + if ( p_event . mouse_button . button_index = = gui . mouse_focus_button ) { <nl> + gui . mouse_focus = NULL ; <nl> + gui . mouse_focus_button = - 1 ; <nl> + } <nl> + <nl> + if ( gui . drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_button . button_index = = BUTTON_LEFT ) { <nl> + gui . drag_data = Variant ( ) ; / / always clear <nl> + } <nl> + <nl> + <nl> + get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + get_tree ( ) - > set_input_as_handled ( ) ; <nl> + <nl> + } <nl> + } break ; <nl> + case InputEvent : : MOUSE_MOTION : { <nl> + <nl> + gui . key_event_accepted = false ; <nl> + Point2 mpos = Point2 ( p_event . mouse_motion . x , p_event . mouse_motion . y ) ; <nl> + <nl> + gui . last_mouse_pos = mpos ; <nl> + <nl> + Control * over = NULL ; <nl> + <nl> + <nl> + / / D & D <nl> + if ( ! gui . drag_attempted & & gui . mouse_focus & & p_event . mouse_motion . button_mask & BUTTON_MASK_LEFT ) { <nl> + <nl> + gui . drag_accum + = Point2 ( p_event . mouse_motion . relative_x , p_event . mouse_motion . relative_y ) ; ; <nl> + float len = gui . drag_accum . length ( ) ; <nl> + if ( len > 10 ) { <nl> + gui . drag_data = gui . mouse_focus - > get_drag_data ( gui . focus_inv_xform . xform ( mpos ) - gui . drag_accum ) ; <nl> + if ( gui . drag_data . get_type ( ) ! = Variant : : NIL ) { <nl> + <nl> + gui . mouse_focus = NULL ; <nl> + } <nl> + gui . drag_attempted = true ; <nl> + } <nl> + } <nl> + <nl> + <nl> + if ( gui . mouse_focus ) { <nl> + over = gui . mouse_focus ; <nl> + / / recompute focus_inv_xform again here <nl> + <nl> + } else { <nl> + <nl> + over = _gui_find_control ( mpos ) ; <nl> + } <nl> + <nl> + <nl> + if ( gui . drag_data . get_type ( ) = = Variant : : NIL & & over & & ! gui . modal_stack . empty ( ) ) { <nl> + <nl> + Control * top = gui . modal_stack . back ( ) - > get ( ) ; <nl> + if ( over ! = top & & ! top - > is_a_parent_of ( over ) ) { <nl> + <nl> + break ; / / don ' t send motion event to anything below modal stack top <nl> + } <nl> + } <nl> + <nl> + if ( over ! = gui . mouse_over ) { <nl> + <nl> + if ( gui . mouse_over ) <nl> + gui . mouse_over - > notification ( Control : : NOTIFICATION_MOUSE_EXIT ) ; <nl> + <nl> + if ( over ) <nl> + over - > notification ( Control : : NOTIFICATION_MOUSE_ENTER ) ; <nl> + <nl> + } <nl> + <nl> + gui . mouse_over = over ; <nl> + <nl> + _gui_cancel_tooltip ( ) ; <nl> + <nl> + if ( gui . drag_preview ) { <nl> + gui . drag_preview - > set_pos ( mpos ) ; <nl> + } <nl> + <nl> + if ( ! over ) { <nl> + OS : : get_singleton ( ) - > set_cursor_shape ( OS : : CURSOR_ARROW ) ; <nl> + break ; <nl> + } <nl> + <nl> + <nl> + Matrix32 localizer = over - > get_canvas_transform ( ) . affine_inverse ( ) ; <nl> + Size2 pos = localizer . xform ( mpos ) ; <nl> + Vector2 speed = localizer . basis_xform ( Point2 ( p_event . mouse_motion . speed_x , p_event . mouse_motion . speed_y ) ) ; <nl> + Vector2 rel = localizer . basis_xform ( Point2 ( p_event . mouse_motion . relative_x , p_event . mouse_motion . relative_y ) ) ; <nl> + <nl> + <nl> + p_event . mouse_motion . global_x = mpos . x ; <nl> + p_event . mouse_motion . global_y = mpos . y ; <nl> + p_event . mouse_motion . speed_x = speed . x ; <nl> + p_event . mouse_motion . speed_y = speed . y ; <nl> + p_event . mouse_motion . relative_x = rel . x ; <nl> + p_event . mouse_motion . relative_y = rel . y ; <nl> + <nl> + if ( p_event . mouse_motion . button_mask = = 0 & & gui . tooltip_timer ) { <nl> + / / nothing pressed <nl> + <nl> + bool can_tooltip = true ; <nl> + <nl> + if ( ! gui . modal_stack . empty ( ) ) { <nl> + if ( gui . modal_stack . back ( ) - > get ( ) ! = over & & ! gui . modal_stack . back ( ) - > get ( ) - > is_a_parent_of ( over ) ) <nl> + can_tooltip = false ; <nl> + <nl> + } <nl> + <nl> + <nl> + if ( can_tooltip ) { <nl> + <nl> + gui . tooltip = over ; <nl> + gui . tooltip_pos = mpos ; / / ( parent_xform * get_transform ( ) ) . affine_inverse ( ) . xform ( pos ) ; <nl> + gui . tooltip_timer - > start ( ) ; <nl> + } <nl> + } <nl> + <nl> + <nl> + pos = gui . focus_inv_xform . xform ( pos ) ; <nl> + <nl> + <nl> + p_event . mouse_motion . x = pos . x ; <nl> + p_event . mouse_motion . y = pos . y ; <nl> + <nl> + <nl> + Control : : CursorShape cursor_shape = over - > get_cursor_shape ( pos ) ; <nl> + <nl> + OS : : get_singleton ( ) - > set_cursor_shape ( ( OS : : CursorShape ) cursor_shape ) ; <nl> + <nl> + <nl> + if ( over - > can_process ( ) ) { <nl> + _gui_call_input ( over , p_event ) ; <nl> + } <nl> + <nl> + <nl> + <nl> + / / get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + get_tree ( ) - > set_input_as_handled ( ) ; <nl> + <nl> + <nl> + if ( gui . drag_data . get_type ( ) ! = Variant : : NIL & & p_event . mouse_motion . button_mask & BUTTON_MASK_LEFT ) { <nl> + <nl> + / * bool can_drop = * / over - > can_drop_data ( pos , gui . drag_data ) ; <nl> + / / change mouse accordingly i guess <nl> + } <nl> + <nl> + } break ; <nl> + case InputEvent : : ACTION : <nl> + case InputEvent : : JOYSTICK_BUTTON : <nl> + case InputEvent : : KEY : { <nl> + <nl> + if ( gui . key_focus ) { <nl> + <nl> + gui . key_event_accepted = false ; <nl> + if ( gui . key_focus - > can_process ( ) ) { <nl> + gui . key_focus - > call_multilevel ( " _input_event " , p_event ) ; <nl> + if ( gui . key_focus ) / / maybe lost it <nl> + gui . key_focus - > emit_signal ( SceneStringNames : : get_singleton ( ) - > input_event , p_event ) ; <nl> + } <nl> + <nl> + <nl> + if ( gui . key_event_accepted ) { <nl> + <nl> + get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + <nl> + if ( p_event . is_pressed ( ) & & p_event . is_action ( " ui_cancel " ) & & ! gui . modal_stack . empty ( ) ) { <nl> + <nl> + _gui_sort_modal_stack ( ) ; <nl> + Control * top = gui . modal_stack . back ( ) - > get ( ) ; <nl> + if ( ! top - > data . modal_exclusive ) { <nl> + <nl> + top - > notification ( Control : : NOTIFICATION_MODAL_CLOSE ) ; <nl> + top - > _modal_stack_remove ( ) ; <nl> + top - > hide ( ) ; <nl> + } <nl> + } <nl> + <nl> + <nl> + Control * from = gui . key_focus ? gui . key_focus : NULL ; / / hmm <nl> + <nl> + / / keyboard focus <nl> + / / if ( from & & p_event . key . pressed & & ! p_event . key . mod . alt & & ! p_event . key . mod . meta & & ! p_event . key . mod . command ) { <nl> + <nl> + if ( from & & p_event . is_pressed ( ) ) { <nl> + Control * next = NULL ; <nl> + <nl> + if ( p_event . is_action ( " ui_focus_next " ) ) { <nl> + <nl> + next = from - > find_next_valid_focus ( ) ; <nl> + } <nl> + <nl> + if ( p_event . is_action ( " ui_focus_prev " ) ) { <nl> + <nl> + next = from - > find_prev_valid_focus ( ) ; <nl> + } <nl> + <nl> + if ( p_event . is_action ( " ui_up " ) ) { <nl> + <nl> + next = from - > _get_focus_neighbour ( MARGIN_TOP ) ; <nl> + } <nl> + <nl> + if ( p_event . is_action ( " ui_left " ) ) { <nl> + <nl> + next = from - > _get_focus_neighbour ( MARGIN_LEFT ) ; <nl> + } <nl> + <nl> + if ( p_event . is_action ( " ui_right " ) ) { <nl> + <nl> + next = from - > _get_focus_neighbour ( MARGIN_RIGHT ) ; <nl> + } <nl> + <nl> + if ( p_event . is_action ( " ui_down " ) ) { <nl> + <nl> + next = from - > _get_focus_neighbour ( MARGIN_BOTTOM ) ; <nl> + } <nl> + <nl> + <nl> + if ( next ) { <nl> + next - > grab_focus ( ) ; <nl> + get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _cancel_input_ID " , p_event . ID ) ; <nl> + } <nl> + } <nl> + <nl> + } break ; <nl> + } <nl> + } <nl> + <nl> + <nl> + List < Control * > : : Element * Viewport : : _gui_add_root_control ( Control * p_control ) { <nl> + <nl> + gui . roots_order_dirty = true ; <nl> + return gui . roots . push_back ( p_control ) ; <nl> + } <nl> + <nl> + List < Control * > : : Element * Viewport : : _gui_add_subwindow_control ( Control * p_control ) { <nl> + <nl> + gui . subwindow_order_dirty = true ; <nl> + return gui . subwindows . push_back ( p_control ) ; <nl> + <nl> + } <nl> + <nl> + void Viewport : : _gui_set_subwindow_order_dirty ( ) { <nl> + gui . subwindow_order_dirty = true ; <nl> + } <nl> + <nl> + void Viewport : : _gui_set_root_order_dirty ( ) { <nl> + gui . roots_order_dirty = true ; <nl> + } <nl> + <nl> + void Viewport : : _gui_remove_modal_control ( List < Control * > : : Element * MI ) { <nl> + <nl> + gui . modal_stack . erase ( MI ) ; <nl> + } <nl> + <nl> + void Viewport : : _gui_remove_from_modal_stack ( List < Control * > : : Element * MI , ObjectID p_prev_focus_owner ) { <nl> + <nl> + / / transfer the focus stack to the next <nl> + <nl> + List < Control * > : : Element * next = MI - > next ( ) ; <nl> + <nl> + gui . modal_stack . erase ( MI ) ; <nl> + MI = NULL ; <nl> + <nl> + if ( p_prev_focus_owner ) { <nl> + <nl> + / / for previous window in stack , pass the focus so it feels more <nl> + / / natural <nl> + <nl> + if ( ! next ) { / / top of stack <nl> + <nl> + Object * pfo = ObjectDB : : get_instance ( p_prev_focus_owner ) ; <nl> + Control * pfoc = pfo - > cast_to < Control > ( ) ; <nl> + if ( ! pfoc ) <nl> + return ; <nl> + <nl> + if ( ! pfoc - > is_inside_tree ( ) | | ! pfoc - > is_visible ( ) ) <nl> + return ; <nl> + pfoc - > grab_focus ( ) ; <nl> + } else { <nl> + <nl> + next - > get ( ) - > _modal_set_prev_focus_owner ( p_prev_focus_owner ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + void Viewport : : _gui_force_drag ( const Variant & p_data , Control * p_control ) { <nl> + <nl> + gui . drag_data = p_data ; <nl> + gui . mouse_focus = NULL ; <nl> + <nl> + if ( p_control ) { <nl> + _gui_set_drag_preview ( p_control ) ; <nl> + } <nl> + } <nl> + <nl> + void Viewport : : _gui_set_drag_preview ( Control * p_control ) { <nl> + <nl> + ERR_FAIL_NULL ( p_control ) ; <nl> + ERR_FAIL_COND ( ! ( ( Object * ) p_control ) - > cast_to < Control > ( ) ) ; <nl> + ERR_FAIL_COND ( p_control - > is_inside_tree ( ) ) ; <nl> + ERR_FAIL_COND ( p_control - > get_parent ( ) ! = NULL ) ; <nl> + <nl> + if ( gui . drag_preview ) { <nl> + memdelete ( gui . drag_preview ) ; <nl> + } <nl> + p_control - > set_as_toplevel ( true ) ; <nl> + p_control - > set_pos ( gui . last_mouse_pos ) ; <nl> + add_child ( p_control ) ; / / add as child of viewport <nl> + p_control - > raise ( ) ; <nl> + if ( gui . drag_preview ) { <nl> + memdelete ( gui . drag_preview ) ; <nl> + } <nl> + gui . drag_preview = p_control ; <nl> + } <nl> + <nl> + <nl> + void Viewport : : _gui_remove_root_control ( List < Control * > : : Element * RI ) { <nl> + <nl> + gui . roots . erase ( RI ) ; <nl> + } <nl> + <nl> + void Viewport : : _gui_remove_subwindow_control ( List < Control * > : : Element * SI ) { <nl> + <nl> + gui . subwindows . erase ( SI ) ; <nl> + } <nl> + <nl> + void Viewport : : _gui_unfocus_control ( Control * p_control ) { <nl> + <nl> + if ( gui . key_focus = = p_control ) { <nl> + gui . key_focus - > release_focus ( ) ; <nl> + } <nl> + } <nl> + <nl> + void Viewport : : _gui_hid_control ( Control * p_control ) { <nl> + <nl> + if ( gui . mouse_focus = = p_control ) { <nl> + gui . mouse_focus = NULL ; <nl> + } <nl> + <nl> + / * ? ? ? <nl> + if ( data . window = = p_control ) { <nl> + window - > drag_data = Variant ( ) ; <nl> + if ( window - > drag_preview ) { <nl> + memdelete ( window - > drag_preview ) ; <nl> + window - > drag_preview = NULL ; <nl> + } <nl> + } <nl> + * / <nl> + <nl> + if ( gui . key_focus = = p_control ) <nl> + gui . key_focus = NULL ; <nl> + if ( gui . mouse_over = = p_control ) <nl> + gui . mouse_over = NULL ; <nl> + if ( gui . tooltip = = p_control ) <nl> + gui . tooltip = NULL ; <nl> + if ( gui . tooltip = = p_control ) <nl> + gui . tooltip = NULL ; <nl> + <nl> + } <nl> + <nl> + void Viewport : : _gui_remove_control ( Control * p_control ) { <nl> + <nl> + <nl> + if ( gui . mouse_focus = = p_control ) <nl> + gui . mouse_focus = NULL ; <nl> + if ( gui . key_focus = = p_control ) <nl> + gui . key_focus = NULL ; <nl> + if ( gui . mouse_over = = p_control ) <nl> + gui . mouse_over = NULL ; <nl> + if ( gui . tooltip = = p_control ) <nl> + gui . tooltip = NULL ; <nl> + <nl> + <nl> + } <nl> + <nl> + void Viewport : : _gui_remove_focus ( ) { <nl> + <nl> + if ( gui . key_focus ) { <nl> + Node * f = gui . key_focus ; <nl> + gui . key_focus = NULL ; <nl> + f - > notification ( Control : : NOTIFICATION_FOCUS_EXIT , true ) ; <nl> + <nl> + <nl> + } <nl> + } <nl> + <nl> + bool Viewport : : _gui_is_modal_on_top ( const Control * p_control ) { <nl> + <nl> + return ( gui . modal_stack . size ( ) & & gui . modal_stack . back ( ) - > get ( ) = = p_control ) ; <nl> + <nl> + } <nl> + <nl> + bool Viewport : : _gui_control_has_focus ( const Control * p_control ) { <nl> + <nl> + return gui . key_focus = = p_control ; <nl> + } <nl> + <nl> + void Viewport : : _gui_control_grab_focus ( Control * p_control ) { <nl> + <nl> + <nl> + / / no need for change <nl> + if ( gui . key_focus & & gui . key_focus = = p_control ) <nl> + return ; <nl> + <nl> + _gui_remove_focus ( ) ; <nl> + get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REALTIME , " windows " , " _gui_remove_focus " ) ; <nl> + gui . key_focus = p_control ; <nl> + p_control - > notification ( Control : : NOTIFICATION_FOCUS_ENTER ) ; <nl> + p_control - > update ( ) ; <nl> + <nl> + } <nl> + <nl> + void Viewport : : _gui_accept_event ( ) { <nl> + <nl> + gui . key_event_accepted = true ; <nl> + if ( is_inside_tree ( ) ) <nl> + get_tree ( ) - > set_input_as_handled ( ) ; <nl> + } <nl> + <nl> + <nl> + List < Control * > : : Element * Viewport : : _gui_show_modal ( Control * p_control ) { <nl> + <nl> + gui . modal_stack . push_back ( p_control ) ; <nl> + if ( gui . key_focus ) <nl> + p_control - > _modal_set_prev_focus_owner ( gui . key_focus - > get_instance_ID ( ) ) ; <nl> + else <nl> + p_control - > _modal_set_prev_focus_owner ( 0 ) ; <nl> + <nl> + return gui . modal_stack . back ( ) ; <nl> + } <nl> + <nl> + Control * Viewport : : _gui_get_focus_owner ( ) { <nl> + <nl> + return gui . key_focus ; <nl> + } <nl> + <nl> + void Viewport : : _gui_grab_click_focus ( Control * p_control ) { <nl> + <nl> + if ( gui . mouse_focus ) { <nl> + <nl> + <nl> + if ( gui . mouse_focus = = p_control ) <nl> + return ; <nl> + InputEvent ie ; <nl> + ie . type = InputEvent : : MOUSE_BUTTON ; <nl> + InputEventMouseButton & mb = ie . mouse_button ; <nl> + <nl> + / / send unclic <nl> + <nl> + Point2 click = gui . mouse_focus - > get_global_transform ( ) . affine_inverse ( ) . xform ( gui . last_mouse_pos ) ; <nl> + mb . x = click . x ; <nl> + mb . y = click . y ; <nl> + mb . button_index = gui . mouse_focus_button ; <nl> + mb . pressed = false ; <nl> + gui . mouse_focus - > call_deferred ( " _input_event " , ie ) ; <nl> + <nl> + <nl> + gui . mouse_focus = p_control ; <nl> + gui . focus_inv_xform = gui . mouse_focus - > get_global_transform ( ) . affine_inverse ( ) ; <nl> + click = gui . mouse_focus - > get_global_transform ( ) . affine_inverse ( ) . xform ( gui . last_mouse_pos ) ; <nl> + mb . x = click . x ; <nl> + mb . y = click . y ; <nl> + mb . button_index = gui . mouse_focus_button ; <nl> + mb . pressed = true ; <nl> + gui . mouse_focus - > call_deferred ( " _input_event " , ie ) ; <nl> + <nl> + } <nl> + } <nl> + <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + <nl> void Viewport : : input ( const InputEvent & p_event ) { <nl> <nl> ERR_FAIL_COND ( ! is_inside_tree ( ) ) ; <nl> - get_tree ( ) - > _call_input_pause ( input_group , " _input " , p_event ) ; <nl> - get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REVERSE | SceneTree : : GROUP_CALL_REALTIME | SceneTree : : GROUP_CALL_MULIILEVEL , gui_input_group , " _gui_input " , p_event ) ; / / special one for GUI , as controls use their own process check <nl> + get_tree ( ) - > _call_input_pause ( input_group , " _input " , p_event ) ; <nl> + _gui_input_event ( p_event ) ; <nl> + / / get_tree ( ) - > call_group ( SceneTree : : GROUP_CALL_REVERSE | SceneTree : : GROUP_CALL_REALTIME | SceneTree : : GROUP_CALL_MULIILEVEL , gui_input_group , " _gui_input " , p_event ) ; / / special one for GUI , as controls use their own process check <nl> } <nl> <nl> void Viewport : : unhandled_input ( const InputEvent & p_event ) { <nl> bool Viewport : : get_physics_object_picking ( ) { <nl> return physics_object_picking ; <nl> } <nl> <nl> + bool Viewport : : gui_has_modal_stack ( ) const { <nl> + <nl> + return gui . modal_stack . size ( ) ; <nl> + } <nl> + <nl> + void Viewport : : set_disable_input ( bool p_disable ) { <nl> + disable_input = p_disable ; <nl> + } <nl> + <nl> + bool Viewport : : is_input_disabled ( ) const { <nl> + <nl> + return disable_input ; <nl> + } <nl> <nl> void Viewport : : _bind_methods ( ) { <nl> <nl> void Viewport : : _bind_methods ( ) { <nl> <nl> ObjectTypeDB : : bind_method ( _MD ( " _parent_resized " ) , & Viewport : : _parent_resized ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " _vp_input " ) , & Viewport : : _vp_input ) ; <nl> + ObjectTypeDB : : bind_method ( _MD ( " _vp_input_text " , " text " ) , & Viewport : : _vp_input_text ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " _vp_unhandled_input " ) , & Viewport : : _vp_unhandled_input ) ; <nl> <nl> ObjectTypeDB : : bind_method ( _MD ( " set_size_override " , " enable " , " size " , " margin " ) , & Viewport : : set_size_override , DEFVAL ( Size2 ( - 1 , - 1 ) ) , DEFVAL ( Size2 ( 0 , 0 ) ) ) ; <nl> void Viewport : : _bind_methods ( ) { <nl> ObjectTypeDB : : bind_method ( _MD ( " get_mouse_pos " ) , & Viewport : : get_mouse_pos ) ; <nl> ObjectTypeDB : : bind_method ( _MD ( " warp_mouse " , " to_pos " ) , & Viewport : : warp_mouse ) ; <nl> <nl> + ObjectTypeDB : : bind_method ( _MD ( " gui_has_modal_stack " ) , & Viewport : : gui_has_modal_stack ) ; <nl> + <nl> + ObjectTypeDB : : bind_method ( _MD ( " set_disable_input " , " disable " ) , & Viewport : : set_disable_input ) ; <nl> + ObjectTypeDB : : bind_method ( _MD ( " is_input_disabled " ) , & Viewport : : is_input_disabled ) ; <nl> + <nl> + ObjectTypeDB : : bind_method ( _MD ( " _gui_show_tooltip " ) , & Viewport : : _gui_show_tooltip ) ; <nl> + <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : RECT2 , " rect " ) , _SCS ( " set_rect " ) , _SCS ( " get_rect " ) ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " own_world " ) , _SCS ( " set_use_own_world " ) , _SCS ( " is_using_own_world " ) ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " world " , PROPERTY_HINT_RESOURCE_TYPE , " World " ) , _SCS ( " set_world " ) , _SCS ( " get_world " ) ) ; <nl> void Viewport : : _bind_methods ( ) { <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " audio_listener / enable_2d " ) , _SCS ( " set_as_audio_listener_2d " ) , _SCS ( " is_audio_listener_2d " ) ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " audio_listener / enable_3d " ) , _SCS ( " set_as_audio_listener " ) , _SCS ( " is_audio_listener " ) ) ; <nl> ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " physics / object_picking " ) , _SCS ( " set_physics_object_picking " ) , _SCS ( " get_physics_object_picking " ) ) ; <nl> + ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " gui / disable_input " ) , _SCS ( " set_disable_input " ) , _SCS ( " is_input_disabled " ) ) ; <nl> <nl> ADD_SIGNAL ( MethodInfo ( " size_changed " ) ) ; <nl> <nl> void Viewport : : _bind_methods ( ) { <nl> <nl> Viewport : : Viewport ( ) { <nl> <nl> + <nl> world_2d = Ref < World2D > ( memnew ( World2D ) ) ; <nl> <nl> viewport = VisualServer : : get_singleton ( ) - > viewport_create ( ) ; <nl> Viewport : : Viewport ( ) { <nl> unhandled_input_group = " _vp_unhandled_input " + id ; <nl> unhandled_key_input_group = " _vp_unhandled_key_input " + id ; <nl> <nl> - <nl> + disable_input = false ; <nl> + <nl> + / / window tooltip <nl> + gui . tooltip_timer = memnew ( Timer ) ; <nl> + add_child ( gui . tooltip_timer ) ; <nl> + gui . tooltip_timer - > force_parent_owned ( ) ; <nl> + gui . tooltip_timer - > set_wait_time ( GLOBAL_DEF ( " display / tooltip_delay " , 0 . 7 ) ) ; <nl> + gui . tooltip_timer - > connect ( " timeout " , this , " _gui_show_tooltip " ) ; <nl> + gui . tooltip = NULL ; <nl> + gui . tooltip_popup = memnew ( TooltipPanel ) ; <nl> + add_child ( gui . tooltip_popup ) ; <nl> + gui . tooltip_popup - > force_parent_owned ( ) ; <nl> + gui . tooltip_label = memnew ( TooltipLabel ) ; <nl> + gui . tooltip_popup - > add_child ( gui . tooltip_label ) ; <nl> + gui . tooltip_popup - > set_as_toplevel ( true ) ; <nl> + gui . tooltip_popup - > hide ( ) ; <nl> + gui . drag_attempted = false ; <nl> + gui . drag_preview = NULL ; <nl> <nl> <nl> } <nl> mmm a / scene / main / viewport . h <nl> ppp b / scene / main / viewport . h <nl> <nl> * / <nl> <nl> class Camera ; <nl> + class Control ; <nl> + class CanvasItem ; <nl> + class Panel ; <nl> + class Label ; <nl> + class Timer ; <nl> class Viewport ; <nl> <nl> class RenderTargetTexture : public Texture { <nl> friend class RenderTargetTexture ; <nl> Ref < RenderTargetTexture > render_target_texture ; <nl> <nl> <nl> + struct GUI { <nl> + / / info used when this is a window <nl> + <nl> + bool key_event_accepted ; <nl> + Control * mouse_focus ; <nl> + int mouse_focus_button ; <nl> + Control * key_focus ; <nl> + Control * mouse_over ; <nl> + Control * tooltip ; <nl> + Panel * tooltip_popup ; <nl> + Label * tooltip_label ; <nl> + Point2 tooltip_pos ; <nl> + Point2 last_mouse_pos ; <nl> + Point2 drag_accum ; <nl> + bool drag_attempted ; <nl> + Variant drag_data ; <nl> + Control * drag_preview ; <nl> + Timer * tooltip_timer ; <nl> + List < Control * > modal_stack ; <nl> + unsigned int cancelled_input_ID ; <nl> + Matrix32 focus_inv_xform ; <nl> + bool subwindow_order_dirty ; <nl> + List < Control * > subwindows ; <nl> + bool roots_order_dirty ; <nl> + List < Control * > roots ; <nl> + <nl> + <nl> + GUI ( ) ; <nl> + } gui ; <nl> + <nl> + bool disable_input ; <nl> + <nl> + void _gui_call_input ( Control * p_control , const InputEvent & p_input ) ; <nl> + void _gui_sort_subwindows ( ) ; <nl> + void _gui_sort_roots ( ) ; <nl> + void _gui_sort_modal_stack ( ) ; <nl> + Control * _gui_find_control ( const Point2 & p_global ) ; <nl> + Control * _gui_find_control_at_pos ( CanvasItem * p_node , const Point2 & p_global , const Matrix32 & p_xform , Matrix32 & r_inv_xform ) ; <nl> + <nl> + void _gui_input_event ( InputEvent p_event ) ; <nl> + <nl> + <nl> void update_worlds ( ) ; <nl> <nl> _FORCE_INLINE_ Matrix32 _get_input_pre_xform ( ) const ; <nl> friend class RenderTargetTexture ; <nl> void _vp_exit_tree ( ) ; <nl> <nl> void _vp_input ( const InputEvent & p_ev ) ; <nl> + void _vp_input_text ( const String & p_text ) ; <nl> void _vp_unhandled_input ( const InputEvent & p_ev ) ; <nl> void _make_input_local ( InputEvent & ev ) ; <nl> <nl> + <nl> + friend class Control ; <nl> + <nl> + List < Control * > : : Element * _gui_add_root_control ( Control * p_control ) ; <nl> + List < Control * > : : Element * _gui_add_subwindow_control ( Control * p_control ) ; <nl> + <nl> + void _gui_set_subwindow_order_dirty ( ) ; <nl> + void _gui_set_root_order_dirty ( ) ; <nl> + <nl> + <nl> + void _gui_remove_modal_control ( List < Control * > : : Element * MI ) ; <nl> + void _gui_remove_from_modal_stack ( List < Control * > : : Element * MI , ObjectID p_prev_focus_owner ) ; <nl> + void _gui_remove_root_control ( List < Control * > : : Element * RI ) ; <nl> + void _gui_remove_subwindow_control ( List < Control * > : : Element * SI ) ; <nl> + <nl> + void _gui_cancel_tooltip ( ) ; <nl> + void _gui_show_tooltip ( ) ; <nl> + <nl> + <nl> + void _gui_remove_control ( Control * p_control ) ; <nl> + void _gui_hid_control ( Control * p_control ) ; <nl> + <nl> + void _gui_force_drag ( const Variant & p_data , Control * p_control ) ; <nl> + void _gui_set_drag_preview ( Control * p_control ) ; <nl> + <nl> + bool _gui_is_modal_on_top ( const Control * p_control ) ; <nl> + List < Control * > : : Element * _gui_show_modal ( Control * p_control ) ; <nl> + <nl> + void _gui_remove_focus ( ) ; <nl> + void _gui_unfocus_control ( Control * p_control ) ; <nl> + bool _gui_control_has_focus ( const Control * p_control ) ; <nl> + void _gui_control_grab_focus ( Control * p_control ) ; <nl> + void _gui_grab_click_focus ( Control * p_control ) ; <nl> + void _gui_accept_event ( ) ; <nl> + <nl> + Control * _gui_get_focus_owner ( ) ; <nl> + <nl> friend class Camera ; <nl> void _camera_transform_changed_notify ( ) ; <nl> void _set_camera ( Camera * p_camera ) ; <nl> friend class Camera ; <nl> void input ( const InputEvent & p_event ) ; <nl> void unhandled_input ( const InputEvent & p_event ) ; <nl> <nl> + void set_disable_input ( bool p_disable ) ; <nl> + bool is_input_disabled ( ) const ; <nl> + <nl> void set_render_target_to_screen_rect ( const Rect2 & p_rect ) ; <nl> Rect2 get_render_target_to_screen_rect ( ) const ; <nl> <nl> friend class Camera ; <nl> void set_physics_object_picking ( bool p_enable ) ; <nl> bool get_physics_object_picking ( ) ; <nl> <nl> + bool gui_has_modal_stack ( ) const ; <nl> + <nl> + <nl> Viewport ( ) ; <nl> ~ Viewport ( ) ; <nl> <nl> mmm a / tools / editor / editor_node . cpp <nl> ppp b / tools / editor / editor_node . cpp <nl> EditorNode : : EditorNode ( ) { <nl> <nl> <nl> / / scene_root_base - > add_child ( scene_root ) ; <nl> - scene_root - > set_meta ( " _editor_disable_input " , true ) ; <nl> + / / scene_root - > set_meta ( " _editor_disable_input " , true ) ; <nl> VisualServer : : get_singleton ( ) - > viewport_set_hide_scenario ( scene_root - > get_viewport ( ) , true ) ; <nl> + scene_root - > set_disable_input ( true ) ; <nl> scene_root - > set_as_audio_listener_2d ( true ) ; <nl> scene_root - > set_size_override ( true , Size2 ( Globals : : get_singleton ( ) - > get ( " display / width " ) , Globals : : get_singleton ( ) - > get ( " display / height " ) ) ) ; <nl> <nl> mmm a / tools / editor / plugins / canvas_item_editor_plugin . cpp <nl> ppp b / tools / editor / plugins / canvas_item_editor_plugin . cpp <nl> void CanvasItemEditor : : _edit_set_pivot ( const Vector2 & mouse_pos ) { <nl> <nl> void CanvasItemEditor : : _unhandled_key_input ( const InputEvent & p_ev ) { <nl> <nl> - if ( ! is_visible ( ) | | window_has_modal_stack ( ) ) <nl> + if ( ! is_visible ( ) | | get_viewport ( ) - > gui_has_modal_stack ( ) ) <nl> return ; <nl> if ( p_ev . key . mod . control ) <nl> / / prevent to change tool mode when control key is pressed <nl> mmm a / tools / editor / plugins / spatial_editor_plugin . cpp <nl> ppp b / tools / editor / plugins / spatial_editor_plugin . cpp <nl> void SpatialEditor : : _instance_scene ( ) { <nl> <nl> void SpatialEditor : : _unhandled_key_input ( InputEvent p_event ) { <nl> <nl> - if ( ! is_visible ( ) | | window_has_modal_stack ( ) ) <nl> + if ( ! is_visible ( ) | | get_viewport ( ) - > gui_has_modal_stack ( ) ) <nl> return ; <nl> <nl> { <nl> mmm a / tools / editor / scene_tree_editor . cpp <nl> ppp b / tools / editor / scene_tree_editor . cpp <nl> <nl> Node * SceneTreeEditor : : get_scene_node ( ) { <nl> <nl> ERR_FAIL_COND_V ( ! is_inside_tree ( ) , NULL ) ; <nl> - if ( get_tree ( ) - > get_root ( ) - > get_child_count ( ) & & get_tree ( ) - > get_root ( ) - > get_child ( 0 ) - > cast_to < EditorNode > ( ) ) <nl> - return get_tree ( ) - > get_root ( ) - > get_child ( 0 ) - > cast_to < EditorNode > ( ) - > get_edited_scene ( ) ; <nl> - else <nl> - return get_tree ( ) - > get_root ( ) ; <nl> <nl> - return NULL ; <nl> + return get_tree ( ) - > get_edited_scene_root ( ) ; <nl> } <nl> <nl> <nl>
- Moved all the " root " input handling for GUI from individual Controls to Viewport .
godotengine/godot
72fcb8a35beab251d01864bc67da3e3a8e75aed6
2016-01-17T01:41:10Z
mmm a / jstests / clone / clonecollection . js <nl> ppp b / jstests / clone / clonecollection . js <nl> for ( i = 0 ; i < 200000 ; + + i ) { <nl> doParallel ( " assert . commandFailed ( db . runCommand ( { cloneCollection : \ " jstests_clonecollection . a \ " , from : \ " localhost : " + ports [ 0 ] + " \ " , logSizeMb : 1 } ) ) ; " ) ; <nl> <nl> sleep ( 200 ) ; <nl> - for ( i = 200000 ; i < 210000 ; + + i ) { <nl> + for ( i = 200000 ; i < 250000 ; + + i ) { <nl> f . a . save ( { i : i } ) ; <nl> } <nl> <nl> for ( i = 0 ; i < 200000 ; + + i ) { <nl> doParallel ( " assert . commandWorked ( db . cloneCollection ( \ " localhost : " + ports [ 0 ] + " \ " , \ " a \ " ) ) ; " ) ; <nl> <nl> sleep ( 200 ) ; <nl> - for ( i = 200000 ; i < 210000 ; + + i ) { <nl> + for ( i = 200000 ; i < 250000 ; + + i ) { <nl> f . a . save ( { i : i } ) ; <nl> } <nl> <nl> waitParallel ( ) ; <nl> - assert . eq ( 210000 , t . a . find ( ) . count ( ) ) ; <nl> + assert . eq ( 250000 , t . a . find ( ) . count ( ) ) ; <nl> <nl> / / Test startCloneCollection and finishCloneCollection commands . <nl> f . a . drop ( ) ; <nl>
write more data in log exhaustion test , to prevent spurious test failure MINOR
mongodb/mongo
a9645eda8a3478d5fbff03545de0368e23f09b91
2009-05-28T18:15:56Z
mmm a / docs / AccessControlInStdlib . rst <nl> ppp b / docs / AccessControlInStdlib . rst <nl> To document the reason for marking symbols public , we use comments : <nl> * symbols that are SPIs for the module X : : <nl> <nl> public / / SPI ( X ) <nl> - public _foo ( ) { . . . } <nl> + func _foo ( ) { . . . } <nl> <nl> ` internal ` <nl> = = = = = = = = = = <nl>
Fix AccessControlInStdlib SPI example
apple/swift
3e5c0120e0a2cd3ac136013d51e2bf538f434a18
2015-12-05T22:32:47Z
mmm a / cmake / OpenCVDetectCUDA . cmake <nl> ppp b / cmake / OpenCVDetectCUDA . cmake <nl> if ( CUDA_FOUND ) <nl> # we remove - frtti because it ' s used for C + + compiler <nl> # but NVCC uses C compiler by default <nl> string ( REPLACE " - frtti " " " $ { var } " $ { $ { var } } " ) <nl> + <nl> + string ( REPLACE " - fvisibility - inlines - hidden " " " $ { var } " $ { $ { var } } " ) <nl> endforeach ( ) <nl> <nl> if ( BUILD_SHARED_LIBS ) <nl> mmm a / cmake / OpenCVModule . cmake <nl> ppp b / cmake / OpenCVModule . cmake <nl> macro ( ocv_glob_module_sources ) <nl> ocv_source_group ( " Src " DIRBASE " $ { CMAKE_CURRENT_LIST_DIR } / src " FILES $ { lib_srcs } $ { lib_int_hdrs } ) <nl> ocv_source_group ( " Include " DIRBASE " $ { CMAKE_CURRENT_LIST_DIR } / include " FILES $ { lib_hdrs } $ { lib_hdrs_detail } ) <nl> <nl> - if ( exclude_cuda EQUAL - 1 ) <nl> + set ( lib_cuda_srcs " " ) <nl> + set ( lib_cuda_hdrs " " ) <nl> + if ( HAVE_CUDA AND exclude_cuda EQUAL - 1 ) <nl> file ( GLOB lib_cuda_srcs <nl> " $ { CMAKE_CURRENT_LIST_DIR } / src / cuda / * . cu " <nl> ) <nl> - set ( cuda_objs " " ) <nl> - set ( lib_cuda_hdrs " " ) <nl> - if ( HAVE_CUDA ) <nl> - ocv_include_directories ( $ { CUDA_INCLUDE_DIRS } ) <nl> - file ( GLOB lib_cuda_hdrs <nl> - " $ { CMAKE_CURRENT_LIST_DIR } / src / cuda / * . hpp " <nl> - ) <nl> - <nl> - ocv_cuda_compile ( cuda_objs $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> - source_group ( " Src \ \ Cuda " FILES $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> - endif ( ) <nl> - else ( ) <nl> - set ( cuda_objs " " ) <nl> - set ( lib_cuda_srcs " " ) <nl> - set ( lib_cuda_hdrs " " ) <nl> + file ( GLOB lib_cuda_hdrs <nl> + " $ { CMAKE_CURRENT_LIST_DIR } / src / cuda / * . hpp " <nl> + ) <nl> + source_group ( " Src \ \ Cuda " FILES $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> endif ( ) <nl> <nl> file ( GLOB cl_kernels <nl> macro ( ocv_glob_module_sources ) <nl> endif ( ) <nl> <nl> ocv_set_module_sources ( $ { _argn } HEADERS $ { lib_hdrs } $ { lib_hdrs_detail } <nl> - SOURCES $ { lib_srcs } $ { lib_int_hdrs } $ { cuda_objs } $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> + SOURCES $ { lib_srcs } $ { lib_int_hdrs } $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> endmacro ( ) <nl> <nl> # creates OpenCV module in current folder <nl> mmm a / cmake / OpenCVUtils . cmake <nl> ppp b / cmake / OpenCVUtils . cmake <nl> function ( ocv_target_include_directories target ) <nl> list ( APPEND __params " $ { dir } " ) <nl> endif ( ) <nl> endforeach ( ) <nl> - if ( CMAKE_VERSION VERSION_LESS 2 . 8 . 11 ) <nl> + if ( HAVE_CUDA OR CMAKE_VERSION VERSION_LESS 2 . 8 . 11 ) <nl> include_directories ( $ { __params } ) <nl> else ( ) <nl> if ( TARGET $ { target } ) <nl> function ( ocv_add_executable target ) <nl> endfunction ( ) <nl> <nl> function ( ocv_add_library target ) <nl> - add_library ( $ { target } $ { ARGN } ) <nl> + set ( cuda_objs " " ) <nl> + if ( HAVE_CUDA ) <nl> + set ( cuda_srcs " " ) <nl> + <nl> + foreach ( var $ { ARGN } ) <nl> + if ( var MATCHES " . cu " ) <nl> + list ( APPEND cuda_srcs $ { var } ) <nl> + endif ( ) <nl> + endforeach ( ) <nl> + <nl> + if ( cuda_srcs ) <nl> + ocv_include_directories ( $ { CUDA_INCLUDE_DIRS } ) <nl> + ocv_cuda_compile ( cuda_objs $ { lib_cuda_srcs } $ { lib_cuda_hdrs } ) <nl> + endif ( ) <nl> + endif ( ) <nl> + <nl> + add_library ( $ { target } $ { ARGN } $ { cuda_objs } ) <nl> _ocv_append_target_includes ( $ { target } ) <nl> - endfunction ( ) <nl> \ No newline at end of file <nl> + endfunction ( ) <nl> mmm a / modules / cudabgsegm / include / opencv2 / cudabgsegm . hpp <nl> ppp b / modules / cudabgsegm / include / opencv2 / cudabgsegm . hpp <nl> namespace cv { namespace cuda { <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / MOG <nl> <nl> - class CV_EXPORTS BackgroundSubtractorMOG : public cv : : BackgroundSubtractorMOG <nl> + class CV_EXPORTS BackgroundSubtractorMOG : public cv : : BackgroundSubtractor <nl> { <nl> public : <nl> - using cv : : BackgroundSubtractorMOG : : apply ; <nl> - using cv : : BackgroundSubtractorMOG : : getBackgroundImage ; <nl> <nl> + using cv : : BackgroundSubtractor : : apply ; <nl> virtual void apply ( InputArray image , OutputArray fgmask , double learningRate , Stream & stream ) = 0 ; <nl> <nl> + using cv : : BackgroundSubtractor : : getBackgroundImage ; <nl> virtual void getBackgroundImage ( OutputArray backgroundImage , Stream & stream ) const = 0 ; <nl> + <nl> + virtual int getHistory ( ) const = 0 ; <nl> + virtual void setHistory ( int nframes ) = 0 ; <nl> + <nl> + virtual int getNMixtures ( ) const = 0 ; <nl> + virtual void setNMixtures ( int nmix ) = 0 ; <nl> + <nl> + virtual double getBackgroundRatio ( ) const = 0 ; <nl> + virtual void setBackgroundRatio ( double backgroundRatio ) = 0 ; <nl> + <nl> + virtual double getNoiseSigma ( ) const = 0 ; <nl> + virtual void setNoiseSigma ( double noiseSigma ) = 0 ; <nl> } ; <nl> <nl> CV_EXPORTS Ptr < cuda : : BackgroundSubtractorMOG > <nl> CV_EXPORTS Ptr < cuda : : BackgroundSubtractorMOG2 > <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / GMG <nl> <nl> - class CV_EXPORTS BackgroundSubtractorGMG : public cv : : BackgroundSubtractorGMG <nl> + class CV_EXPORTS BackgroundSubtractorGMG : public cv : : BackgroundSubtractor <nl> { <nl> public : <nl> - using cv : : BackgroundSubtractorGMG : : apply ; <nl> - <nl> + using cv : : BackgroundSubtractor : : apply ; <nl> virtual void apply ( InputArray image , OutputArray fgmask , double learningRate , Stream & stream ) = 0 ; <nl> + <nl> + virtual int getMaxFeatures ( ) const = 0 ; <nl> + virtual void setMaxFeatures ( int maxFeatures ) = 0 ; <nl> + <nl> + virtual double getDefaultLearningRate ( ) const = 0 ; <nl> + virtual void setDefaultLearningRate ( double lr ) = 0 ; <nl> + <nl> + virtual int getNumFrames ( ) const = 0 ; <nl> + virtual void setNumFrames ( int nframes ) = 0 ; <nl> + <nl> + virtual int getQuantizationLevels ( ) const = 0 ; <nl> + virtual void setQuantizationLevels ( int nlevels ) = 0 ; <nl> + <nl> + virtual double getBackgroundPrior ( ) const = 0 ; <nl> + virtual void setBackgroundPrior ( double bgprior ) = 0 ; <nl> + <nl> + virtual int getSmoothingRadius ( ) const = 0 ; <nl> + virtual void setSmoothingRadius ( int radius ) = 0 ; <nl> + <nl> + virtual double getDecisionThreshold ( ) const = 0 ; <nl> + virtual void setDecisionThreshold ( double thresh ) = 0 ; <nl> + <nl> + virtual bool getUpdateBackgroundModel ( ) const = 0 ; <nl> + virtual void setUpdateBackgroundModel ( bool update ) = 0 ; <nl> + <nl> + virtual double getMinVal ( ) const = 0 ; <nl> + virtual void setMinVal ( double val ) = 0 ; <nl> + <nl> + virtual double getMaxVal ( ) const = 0 ; <nl> + virtual void setMaxVal ( double val ) = 0 ; <nl> } ; <nl> <nl> CV_EXPORTS Ptr < cuda : : BackgroundSubtractorGMG > <nl> mmm a / modules / cudabgsegm / perf / perf_bgsegm . cpp <nl> ppp b / modules / cudabgsegm / perf / perf_bgsegm . cpp <nl> PERF_TEST_P ( Video_Cn_LearningRate , MOG , <nl> } <nl> else <nl> { <nl> - cv : : Ptr < cv : : BackgroundSubtractor > mog = cv : : createBackgroundSubtractorMOG ( ) ; <nl> - cv : : Mat foreground ; <nl> - <nl> - mog - > apply ( frame , foreground , learningRate ) ; <nl> - <nl> - int i = 0 ; <nl> - <nl> - / / collect performance data <nl> - for ( ; i < numIters ; + + i ) <nl> - { <nl> - cap > > frame ; <nl> - ASSERT_FALSE ( frame . empty ( ) ) ; <nl> - <nl> - if ( cn ! = 3 ) <nl> - { <nl> - cv : : Mat temp ; <nl> - if ( cn = = 1 ) <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2GRAY ) ; <nl> - else <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2BGRA ) ; <nl> - cv : : swap ( temp , frame ) ; <nl> - } <nl> - <nl> - startTimer ( ) ; <nl> - if ( ! next ( ) ) <nl> - break ; <nl> - <nl> - mog - > apply ( frame , foreground , learningRate ) ; <nl> - <nl> - stopTimer ( ) ; <nl> - } <nl> - <nl> - / / process last frame in sequence to get data for sanity test <nl> - for ( ; i < numIters ; + + i ) <nl> - { <nl> - cap > > frame ; <nl> - ASSERT_FALSE ( frame . empty ( ) ) ; <nl> - <nl> - if ( cn ! = 3 ) <nl> - { <nl> - cv : : Mat temp ; <nl> - if ( cn = = 1 ) <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2GRAY ) ; <nl> - else <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2BGRA ) ; <nl> - cv : : swap ( temp , frame ) ; <nl> - } <nl> - <nl> - mog - > apply ( frame , foreground , learningRate ) ; <nl> - } <nl> - <nl> - CPU_SANITY_CHECK ( foreground ) ; <nl> + FAIL_NO_CPU ( ) ; <nl> } <nl> } <nl> <nl> PERF_TEST_P ( Video_Cn_MaxFeatures , GMG , <nl> cv : : cuda : : GpuMat d_frame ( frame ) ; <nl> cv : : cuda : : GpuMat foreground ; <nl> <nl> - cv : : Ptr < cv : : BackgroundSubtractorGMG > d_gmg = cv : : cuda : : createBackgroundSubtractorGMG ( ) ; <nl> + cv : : Ptr < cv : : cuda : : BackgroundSubtractorGMG > d_gmg = cv : : cuda : : createBackgroundSubtractorGMG ( ) ; <nl> d_gmg - > setMaxFeatures ( maxFeatures ) ; <nl> <nl> d_gmg - > apply ( d_frame , foreground ) ; <nl> PERF_TEST_P ( Video_Cn_MaxFeatures , GMG , <nl> } <nl> else <nl> { <nl> - cv : : Mat foreground ; <nl> - cv : : Mat zeros ( frame . size ( ) , CV_8UC1 , cv : : Scalar : : all ( 0 ) ) ; <nl> - <nl> - cv : : Ptr < cv : : BackgroundSubtractorGMG > gmg = cv : : createBackgroundSubtractorGMG ( ) ; <nl> - gmg - > setMaxFeatures ( maxFeatures ) ; <nl> - <nl> - gmg - > apply ( frame , foreground ) ; <nl> - <nl> - int i = 0 ; <nl> - <nl> - / / collect performance data <nl> - for ( ; i < numIters ; + + i ) <nl> - { <nl> - cap > > frame ; <nl> - if ( frame . empty ( ) ) <nl> - { <nl> - cap . release ( ) ; <nl> - cap . open ( inputFile ) ; <nl> - cap > > frame ; <nl> - } <nl> - <nl> - if ( cn ! = 3 ) <nl> - { <nl> - cv : : Mat temp ; <nl> - if ( cn = = 1 ) <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2GRAY ) ; <nl> - else <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2BGRA ) ; <nl> - cv : : swap ( temp , frame ) ; <nl> - } <nl> - <nl> - startTimer ( ) ; <nl> - if ( ! next ( ) ) <nl> - break ; <nl> - <nl> - gmg - > apply ( frame , foreground ) ; <nl> - <nl> - stopTimer ( ) ; <nl> - } <nl> - <nl> - / / process last frame in sequence to get data for sanity test <nl> - for ( ; i < numIters ; + + i ) <nl> - { <nl> - cap > > frame ; <nl> - if ( frame . empty ( ) ) <nl> - { <nl> - cap . release ( ) ; <nl> - cap . open ( inputFile ) ; <nl> - cap > > frame ; <nl> - } <nl> - <nl> - if ( cn ! = 3 ) <nl> - { <nl> - cv : : Mat temp ; <nl> - if ( cn = = 1 ) <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2GRAY ) ; <nl> - else <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2BGRA ) ; <nl> - cv : : swap ( temp , frame ) ; <nl> - } <nl> - <nl> - gmg - > apply ( frame , foreground ) ; <nl> - } <nl> - <nl> - CPU_SANITY_CHECK ( foreground ) ; <nl> + FAIL_NO_CPU ( ) ; <nl> } <nl> } <nl> <nl> mmm a / modules / cudabgsegm / test / test_bgsegm . cpp <nl> ppp b / modules / cudabgsegm / test / test_bgsegm . cpp <nl> using namespace cvtest ; <nl> # define BUILD_WITH_VIDEO_INPUT_SUPPORT 0 <nl> # endif <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / MOG <nl> - <nl> - # if BUILD_WITH_VIDEO_INPUT_SUPPORT <nl> - <nl> - namespace <nl> - { <nl> - IMPLEMENT_PARAM_CLASS ( UseGray , bool ) <nl> - IMPLEMENT_PARAM_CLASS ( LearningRate , double ) <nl> - } <nl> - <nl> - PARAM_TEST_CASE ( MOG , cv : : cuda : : DeviceInfo , std : : string , UseGray , LearningRate , UseRoi ) <nl> - { <nl> - cv : : cuda : : DeviceInfo devInfo ; <nl> - std : : string inputFile ; <nl> - bool useGray ; <nl> - double learningRate ; <nl> - bool useRoi ; <nl> - <nl> - virtual void SetUp ( ) <nl> - { <nl> - devInfo = GET_PARAM ( 0 ) ; <nl> - cv : : cuda : : setDevice ( devInfo . deviceID ( ) ) ; <nl> - <nl> - inputFile = std : : string ( cvtest : : TS : : ptr ( ) - > get_data_path ( ) ) + " video / " + GET_PARAM ( 1 ) ; <nl> - <nl> - useGray = GET_PARAM ( 2 ) ; <nl> - <nl> - learningRate = GET_PARAM ( 3 ) ; <nl> - <nl> - useRoi = GET_PARAM ( 4 ) ; <nl> - } <nl> - } ; <nl> - <nl> - CUDA_TEST_P ( MOG , Update ) <nl> - { <nl> - cv : : VideoCapture cap ( inputFile ) ; <nl> - ASSERT_TRUE ( cap . isOpened ( ) ) ; <nl> - <nl> - cv : : Mat frame ; <nl> - cap > > frame ; <nl> - ASSERT_FALSE ( frame . empty ( ) ) ; <nl> - <nl> - cv : : Ptr < cv : : BackgroundSubtractorMOG > mog = cv : : cuda : : createBackgroundSubtractorMOG ( ) ; <nl> - cv : : cuda : : GpuMat foreground = createMat ( frame . size ( ) , CV_8UC1 , useRoi ) ; <nl> - <nl> - cv : : Ptr < cv : : BackgroundSubtractorMOG > mog_gold = cv : : createBackgroundSubtractorMOG ( ) ; <nl> - cv : : Mat foreground_gold ; <nl> - <nl> - for ( int i = 0 ; i < 10 ; + + i ) <nl> - { <nl> - cap > > frame ; <nl> - ASSERT_FALSE ( frame . empty ( ) ) ; <nl> - <nl> - if ( useGray ) <nl> - { <nl> - cv : : Mat temp ; <nl> - cv : : cvtColor ( frame , temp , cv : : COLOR_BGR2GRAY ) ; <nl> - cv : : swap ( temp , frame ) ; <nl> - } <nl> - <nl> - mog - > apply ( loadMat ( frame , useRoi ) , foreground , learningRate ) ; <nl> - <nl> - mog_gold - > apply ( frame , foreground_gold , learningRate ) ; <nl> - <nl> - ASSERT_MAT_NEAR ( foreground_gold , foreground , 0 . 0 ) ; <nl> - } <nl> - } <nl> - <nl> - INSTANTIATE_TEST_CASE_P ( CUDA_BgSegm , MOG , testing : : Combine ( <nl> - ALL_DEVICES , <nl> - testing : : Values ( std : : string ( " 768x576 . avi " ) ) , <nl> - testing : : Values ( UseGray ( true ) , UseGray ( false ) ) , <nl> - testing : : Values ( LearningRate ( 0 . 0 ) , LearningRate ( 0 . 01 ) ) , <nl> - WHOLE_SUBMAT ) ) ; <nl> - <nl> - # endif <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / MOG2 <nl> <nl> # if BUILD_WITH_VIDEO_INPUT_SUPPORT <nl> <nl> namespace <nl> - { <nl> + { <nl> + IMPLEMENT_PARAM_CLASS ( UseGray , bool ) <nl> IMPLEMENT_PARAM_CLASS ( DetectShadow , bool ) <nl> } <nl> <nl> INSTANTIATE_TEST_CASE_P ( CUDA_BgSegm , MOG2 , testing : : Combine ( <nl> <nl> # endif <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GMG <nl> - <nl> - PARAM_TEST_CASE ( GMG , cv : : cuda : : DeviceInfo , cv : : Size , MatDepth , Channels , UseRoi ) <nl> - { <nl> - } ; <nl> - <nl> - CUDA_TEST_P ( GMG , Accuracy ) <nl> - { <nl> - const cv : : cuda : : DeviceInfo devInfo = GET_PARAM ( 0 ) ; <nl> - cv : : cuda : : setDevice ( devInfo . deviceID ( ) ) ; <nl> - const cv : : Size size = GET_PARAM ( 1 ) ; <nl> - const int depth = GET_PARAM ( 2 ) ; <nl> - const int channels = GET_PARAM ( 3 ) ; <nl> - const bool useRoi = GET_PARAM ( 4 ) ; <nl> - <nl> - const int type = CV_MAKE_TYPE ( depth , channels ) ; <nl> - <nl> - const cv : : Mat zeros ( size , CV_8UC1 , cv : : Scalar : : all ( 0 ) ) ; <nl> - const cv : : Mat fullfg ( size , CV_8UC1 , cv : : Scalar : : all ( 255 ) ) ; <nl> - <nl> - cv : : Mat frame = randomMat ( size , type , 0 , 100 ) ; <nl> - cv : : cuda : : GpuMat d_frame = loadMat ( frame , useRoi ) ; <nl> - <nl> - cv : : Ptr < cv : : BackgroundSubtractorGMG > gmg = cv : : cuda : : createBackgroundSubtractorGMG ( ) ; <nl> - gmg - > setNumFrames ( 5 ) ; <nl> - gmg - > setSmoothingRadius ( 0 ) ; <nl> - <nl> - cv : : cuda : : GpuMat d_fgmask = createMat ( size , CV_8UC1 , useRoi ) ; <nl> - <nl> - for ( int i = 0 ; i < gmg - > getNumFrames ( ) ; + + i ) <nl> - { <nl> - gmg - > apply ( d_frame , d_fgmask ) ; <nl> - <nl> - / / fgmask should be entirely background during training <nl> - ASSERT_MAT_NEAR ( zeros , d_fgmask , 0 ) ; <nl> - } <nl> - <nl> - frame = randomMat ( size , type , 160 , 255 ) ; <nl> - d_frame = loadMat ( frame , useRoi ) ; <nl> - gmg - > apply ( d_frame , d_fgmask ) ; <nl> - <nl> - / / now fgmask should be entirely foreground <nl> - ASSERT_MAT_NEAR ( fullfg , d_fgmask , 0 ) ; <nl> - } <nl> - <nl> - INSTANTIATE_TEST_CASE_P ( CUDA_BgSegm , GMG , testing : : Combine ( <nl> - ALL_DEVICES , <nl> - DIFFERENT_SIZES , <nl> - testing : : Values ( MatType ( CV_8U ) , MatType ( CV_16U ) , MatType ( CV_32F ) ) , <nl> - testing : : Values ( Channels ( 1 ) , Channels ( 3 ) , Channels ( 4 ) ) , <nl> - WHOLE_SUBMAT ) ) ; <nl> - <nl> # endif / / HAVE_CUDA <nl>
Merge pull request from jet47 : fix - cuda - compilation
opencv/opencv
cf4a536440b5dc52159a54b42163a21d0321fe8c
2014-08-14T10:05:49Z
mmm a / cmake / modules / AddSwift . cmake <nl> ppp b / cmake / modules / AddSwift . cmake <nl> function ( _add_variant_link_flags ) <nl> RESULT_VAR_NAME result ) <nl> <nl> if ( " $ { LFLAGS_SDK } " STREQUAL " LINUX " ) <nl> - list ( APPEND result " - lpthread " " - latomic " " - ldl " ) <nl> + list ( APPEND result " - lpthread " " - ldl " ) <nl> elseif ( " $ { LFLAGS_SDK } " STREQUAL " FREEBSD " ) <nl> list ( APPEND result " - lpthread " ) <nl> elseif ( " $ { LFLAGS_SDK } " STREQUAL " CYGWIN " ) <nl> mmm a / cmake / modules / AddSwiftUnittests . cmake <nl> ppp b / cmake / modules / AddSwiftUnittests . cmake <nl> function ( add_swift_unittest test_dirname ) <nl> if ( " $ { CMAKE_SYSTEM_NAME } " STREQUAL " Darwin " ) <nl> set_property ( TARGET " $ { test_dirname } " APPEND_STRING PROPERTY <nl> LINK_FLAGS " - Xlinker - rpath - Xlinker $ { SWIFT_LIBRARY_OUTPUT_INTDIR } / swift / macosx " ) <nl> - elseif ( " $ { CMAKE_SYSTEM_NAME } " STREQUAL " Linux " ) <nl> - set_property ( TARGET " $ { test_dirname } " APPEND_STRING PROPERTY <nl> - LINK_FLAGS " - latomic " ) <nl> endif ( ) <nl> <nl> if ( SWIFT_ENABLE_GOLD_LINKER AND <nl> mmm a / include / swift / Runtime / Concurrent . h <nl> ppp b / include / swift / Runtime / Concurrent . h <nl> class ConcurrentMapBase < EntryTy , false , Allocator > : protected Allocator { <nl> / / Destroy the node ' s payload . <nl> node - > ~ Node ( ) ; <nl> <nl> - / / Deallocate the node . The static_cast here is required <nl> - / / because LLVM ' s allocator API is insane . <nl> - this - > Deallocate ( static_cast < void * > ( node ) , allocSize ) ; <nl> + / / Deallocate the node . <nl> + this - > Deallocate ( node , allocSize ) ; <nl> } <nl> } ; <nl> <nl> mmm a / stdlib / public / runtime / Metadata . cpp <nl> ppp b / stdlib / public / runtime / Metadata . cpp <nl> swift : : swift_getGenericWitnessTable ( GenericWitnessTable * genericTable , <nl> } <nl> <nl> uint64_t swift : : RelativeDirectPointerNullPtr = 0 ; <nl> - <nl> - / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - / * * * Allocator implementation * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> - <nl> - namespace { <nl> - struct PoolRange { <nl> - static constexpr uintptr_t PageSize = 16 * 1024 ; <nl> - static constexpr uintptr_t MaxPoolAllocationSize = PageSize / 2 ; <nl> - <nl> - / / / The start of the allocation . <nl> - char * Begin ; <nl> - <nl> - / / / The number of bytes remaining . <nl> - size_t Remaining ; <nl> - } ; <nl> - } <nl> - <nl> - / / A statically - allocated pool . It ' s zero - initialized , so this <nl> - / / doesn ' t cost us anything in binary size . <nl> - LLVM_ALIGNAS ( alignof ( void * ) ) static char InitialAllocationPool [ 64 * 1024 ] ; <nl> - static std : : atomic < PoolRange > <nl> - AllocationPool { PoolRange { InitialAllocationPool , <nl> - sizeof ( InitialAllocationPool ) } } ; <nl> - <nl> - void * MetadataAllocator : : Allocate ( size_t size , size_t alignment ) { <nl> - assert ( alignment < = alignof ( void * ) ) ; <nl> - assert ( size % alignof ( void * ) = = 0 ) ; <nl> - <nl> - / / If the size is larger than the maximum , just use malloc . <nl> - if ( size > PoolRange : : MaxPoolAllocationSize ) <nl> - return malloc ( size ) ; <nl> - <nl> - / / Allocate out of the pool . <nl> - PoolRange curState = AllocationPool . load ( std : : memory_order_relaxed ) ; <nl> - while ( true ) { <nl> - char * allocation ; <nl> - PoolRange newState ; <nl> - bool allocatedNewPage ; <nl> - <nl> - / / Try to allocate out of the current page . <nl> - if ( size < = curState . Remaining ) { <nl> - allocatedNewPage = false ; <nl> - allocation = curState . Begin ; <nl> - newState = PoolRange { curState . Begin + size , curState . Remaining - size } ; <nl> - } else { <nl> - allocatedNewPage = true ; <nl> - allocation = new char [ PoolRange : : PageSize ] ; <nl> - newState = PoolRange { allocation + size , PoolRange : : PageSize - size } ; <nl> - __asan_poison_memory_region ( allocation , PoolRange : : PageSize ) ; <nl> - } <nl> - <nl> - / / Swap in the new state . <nl> - if ( std : : atomic_compare_exchange_weak_explicit ( & AllocationPool , <nl> - & curState , newState , <nl> - std : : memory_order_relaxed , <nl> - std : : memory_order_relaxed ) ) { <nl> - / / If that succeeded , we ' ve successfully allocated . <nl> - __msan_allocated_memory ( allocation , size ) ; <nl> - __asan_poison_memory_region ( allocation , size ) ; <nl> - return allocation ; <nl> - } <nl> - <nl> - / / If it failed , go back to a neutral state and try again . <nl> - if ( allocatedNewPage ) { <nl> - delete [ ] allocation ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - void MetadataAllocator : : Deallocate ( const void * allocation , size_t size ) { <nl> - __asan_poison_memory_region ( allocation , size ) ; <nl> - <nl> - if ( size > PoolRange : : MaxPoolAllocationSize ) { <nl> - free ( const_cast < void * > ( allocation ) ) ; <nl> - return ; <nl> - } <nl> - <nl> - / / Check whether the allocation pool is still in the state it was in <nl> - / / immediately after the given allocation . <nl> - PoolRange curState = AllocationPool . load ( std : : memory_order_relaxed ) ; <nl> - if ( reinterpret_cast < const char * > ( allocation ) + size ! = curState . Begin ) { <nl> - return ; <nl> - } <nl> - <nl> - / / Try to swap back to the pre - allocation state . If this fails , <nl> - / / don ' t bother trying again ; we ' ll just leak the allocation . <nl> - PoolRange newState = { reinterpret_cast < char * > ( const_cast < void * > ( allocation ) ) , <nl> - curState . Remaining + size } ; <nl> - ( void ) <nl> - std : : atomic_compare_exchange_strong_explicit ( & AllocationPool , <nl> - & curState , newState , <nl> - std : : memory_order_relaxed , <nl> - std : : memory_order_relaxed ) ; <nl> - } <nl> - <nl> mmm a / stdlib / public / runtime / MetadataCache . h <nl> ppp b / stdlib / public / runtime / MetadataCache . h <nl> <nl> <nl> namespace swift { <nl> <nl> - class MetadataAllocator : public llvm : : AllocatorBase < MetadataAllocator > { <nl> - public : <nl> - void Reset ( ) { } <nl> - <nl> - LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate ( size_t size , size_t alignment ) ; <nl> - using AllocatorBase < MetadataAllocator > : : Allocate ; <nl> - <nl> - void Deallocate ( const void * Ptr , size_t size ) ; <nl> - using AllocatorBase < MetadataAllocator > : : Deallocate ; <nl> - <nl> - void PrintStats ( ) const { } <nl> - } ; <nl> + / / For now , use malloc and free as our standard allocator for <nl> + / / metadata caches . It might make sense in the future to take <nl> + / / advantage of the fact that we know that most allocations here <nl> + / / won ' t ever be deallocated . <nl> + using MetadataAllocator = llvm : : MallocAllocator ; <nl> <nl> / / / A typedef for simple global caches . <nl> template < class EntryTy > <nl> mmm a / test / Driver / static - stdlib - linux . swift <nl> ppp b / test / Driver / static - stdlib - linux . swift <nl> <nl> / / Statically link a " hello world " program <nl> / / REQUIRES : OS = linux - gnu <nl> / / REQUIRES : static_stdlib <nl> - / / REQUIRES : rdar : / / 30250347 <nl> print ( " hello world ! " ) <nl> / / RUN : rm - rf % t & & mkdir - p % t <nl> / / RUN : % target - swiftc_driver - static - stdlib - o % t / static - stdlib % s <nl> mmm a / utils / gen - static - stdlib - link - args <nl> ppp b / utils / gen - static - stdlib - link - args <nl> function write_linkfile { <nl> - ldl <nl> - lpthread <nl> - lswiftCore <nl> - - latomic <nl> - lswiftImageInspectionShared <nl> $ ICU_LIBS <nl> - Xlinker <nl> mmm a / utils / static - executable - args . lnk <nl> ppp b / utils / static - executable - args . lnk <nl> <nl> - Xlinker <nl> - - defsym = __import_pthread_key_create = pthread_key_create <nl> - lpthread <nl> - - latomic <nl> - licui18n <nl> - licuuc <nl> - licudata <nl>
Merge pull request from rjmccall / revert - metadata - cache - allocator
apple/swift
9c083c23fc47dc7c46443f4700f39aa91ed12053
2017-01-29T05:36:48Z
mmm a / ci / build_container / build_container_common . sh <nl> ppp b / ci / build_container / build_container_common . sh <nl> SHA256 = 769b9757644a8ec9c4b07369fda4a3e6592639a1338a7a03225ceeedbc760b45 <nl> <nl> # buildifier <nl> curl - - location - - output / usr / local / bin / buildifier https : / / github . com / bazelbuild / buildtools / releases / download / " $ VERSION " / buildifier \ <nl> - & & echo " $ SHA256 " ' / usr / local / bin / buildifier ' | shasum - a 256 - - check \ <nl> + & & echo " $ SHA256 " ' / usr / local / bin / buildifier ' | sha256sum - - check \ <nl> & & chmod + x / usr / local / bin / buildifier <nl> <nl> # GCC for everything . <nl> mmm a / ci / build_container / build_recipes / cares . sh <nl> ppp b / ci / build_container / build_recipes / cares . sh <nl> CPPFLAGS = " $ ( for f in $ CXXFLAGS ; do if [ [ $ f = ~ - D . * ] ] ; then echo $ f ; fi ; done | <nl> CFLAGS = " $ ( for f in $ CXXFLAGS ; do if [ [ ! $ f = ~ - D . * ] ] ; then echo $ f ; fi ; done | tr ' \ n ' ' ' ) " <nl> <nl> curl https : / / github . com / c - ares / c - ares / archive / " $ VERSION " . tar . gz - sLo c - ares - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " c - ares - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " c - ares - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf c - ares - " $ VERSION " . tar . gz <nl> cd c - ares - " $ VERSION " <nl> <nl> mmm a / ci / build_container / build_recipes / gperftools . sh <nl> ppp b / ci / build_container / build_recipes / gperftools . sh <nl> VERSION = 2 . 7 <nl> SHA256 = 1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9 <nl> <nl> curl https : / / github . com / gperftools / gperftools / releases / download / gperftools - " $ VERSION " / gperftools - " $ VERSION " . tar . gz - sLo gperftools - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " gperftools - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " gperftools - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf gperftools - " $ VERSION " . tar . gz <nl> cd gperftools - " $ VERSION " <nl> <nl> mmm a / ci / build_container / build_recipes / libevent . sh <nl> ppp b / ci / build_container / build_recipes / libevent . sh <nl> VERSION = 2 . 1 . 8 - stable <nl> SHA256 = 316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d <nl> <nl> curl https : / / github . com / libevent / libevent / archive / release - " $ VERSION " . tar . gz - sLo libevent - release - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " libevent - release - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " libevent - release - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf libevent - release - " $ VERSION " . tar . gz <nl> cd libevent - release - " $ VERSION " <nl> <nl> mmm a / ci / build_container / build_recipes / luajit . sh <nl> ppp b / ci / build_container / build_recipes / luajit . sh <nl> VERSION = 2 . 0 . 5 <nl> SHA256 = 8bb29d84f06eb23c7ea4aa4794dbb248ede9fcb23b6989cbef81dc79352afc97 <nl> <nl> curl https : / / github . com / LuaJIT / LuaJIT / archive / v " $ VERSION " . tar . gz - sLo LuaJIT - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " LuaJIT - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " LuaJIT - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf LuaJIT - " $ VERSION " . tar . gz <nl> cd LuaJIT - " $ VERSION " <nl> <nl> mmm a / ci / build_container / build_recipes / nghttp2 . sh <nl> ppp b / ci / build_container / build_recipes / nghttp2 . sh <nl> VERSION = 1 . 33 . 0 <nl> SHA256 = 42fff7f290100c02234ac3b0095852e4392e6bfd95ebed900ca8bd630850d88c <nl> <nl> curl https : / / github . com / nghttp2 / nghttp2 / releases / download / v " $ VERSION " / nghttp2 - " $ VERSION " . tar . gz - sLo nghttp2 - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " nghttp2 - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " nghttp2 - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf nghttp2 - " $ VERSION " . tar . gz <nl> cd nghttp2 - " $ VERSION " <nl> <nl> mmm a / ci / build_container / build_recipes / yaml - cpp . sh <nl> ppp b / ci / build_container / build_recipes / yaml - cpp . sh <nl> COMMIT = 0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79 # 2018 - 06 - 30 <nl> SHA256 = 53dcffd55f3433b379fcc694f45c54898711c0e29159a7bd02e82a3e0253bac3 <nl> <nl> curl https : / / github . com / jbeder / yaml - cpp / archive / " $ COMMIT " . tar . gz - sLo yaml - cpp - " $ COMMIT " . tar . gz \ <nl> - & & echo " $ SHA256 " yaml - cpp - " $ COMMIT " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " yaml - cpp - " $ COMMIT " . tar . gz | sha256sum - - check <nl> tar xf yaml - cpp - " $ COMMIT " . tar . gz <nl> cd yaml - cpp - " $ COMMIT " <nl> <nl> mmm a / ci / build_container / build_recipes / zlib . sh <nl> ppp b / ci / build_container / build_recipes / zlib . sh <nl> VERSION = 1 . 2 . 11 <nl> SHA256 = 629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff <nl> <nl> curl https : / / github . com / madler / zlib / archive / v " $ VERSION " . tar . gz - sLo zlib - " $ VERSION " . tar . gz \ <nl> - & & echo " $ SHA256 " zlib - " $ VERSION " . tar . gz | shasum - a 256 - - check <nl> + & & echo " $ SHA256 " zlib - " $ VERSION " . tar . gz | sha256sum - - check <nl> tar xf zlib - " $ VERSION " . tar . gz <nl> cd zlib - " $ VERSION " <nl> <nl> mmm a / ci / build_container / recipe_wrapper . sh <nl> ppp b / ci / build_container / recipe_wrapper . sh <nl> <nl> PS4 = ' + $ ( date " + % s . % N " ) ' <nl> set - x <nl> <nl> + if [ [ ` uname ` = = " Darwin " ] ] ; then <nl> + function sha256sum { <nl> + gsha256sum <nl> + } <nl> + fi <nl> + <nl> . $ 1 <nl> <nl> echo DONE <nl>
build : remove build dependency of shasum ( )
envoyproxy/envoy
2029afbb36cd1e81340d85e665c68f26fca8355c
2018-10-05T16:22:30Z
mmm a / modules / planning / math / smoothing_spline / BUILD <nl> ppp b / modules / planning / math / smoothing_spline / BUILD <nl> cc_test ( <nl> ] , <nl> ) <nl> <nl> + cc_test ( <nl> + name = " spline_2d_kernel_test " , <nl> + size = " small " , <nl> + srcs = [ <nl> + " spline_2d_kernel_test . cc " , <nl> + ] , <nl> + deps = [ <nl> + " : spline_2d_kernel " , <nl> + " @ gtest / / : main " , <nl> + ] , <nl> + ) <nl> + <nl> cpplint ( ) <nl> new file mode 100644 <nl> index 00000000000 . . 013b30c6fbf <nl> mmm / dev / null <nl> ppp b / modules / planning / math / smoothing_spline / spline_2d_kernel_test . cc <nl> <nl> + / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + * Copyright 2017 The Apollo Authors . All Rights Reserved . <nl> + * <nl> + * Licensed under the Apache License , Version 2 . 0 ( the " License " ) ; <nl> + * you may not use this file except in compliance with the License . <nl> + * You may obtain a copy of the License at <nl> + * <nl> + * http : / / www . apache . org / licenses / LICENSE - 2 . 0 <nl> + * <nl> + * Unless required by applicable law or agreed to in writing , software <nl> + * distributed under the License is distributed on an " AS IS " BASIS , <nl> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied . <nl> + * See the License for the specific language governing permissions and <nl> + * limitations under the License . <nl> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> + <nl> + / * * <nl> + * @ file <nl> + * * / <nl> + # include " modules / planning / math / smoothing_spline / spline_2d_kernel . h " <nl> + <nl> + # include " glog / logging . h " <nl> + # include " gtest / gtest . h " <nl> + <nl> + namespace apollo { <nl> + namespace planning { <nl> + <nl> + TEST ( Spline2dKernel , add_regularization ) { <nl> + std : : vector < double > x_knots = { 0 . 0 , 1 . 0 , 2 . 0 , 3 . 0 } ; <nl> + int32_t spline_order = 4 ; <nl> + Spline2dKernel kernel ( x_knots , spline_order ) ; <nl> + <nl> + kernel . AddRegularization ( 0 . 2 ) ; <nl> + <nl> + std : : cout < < kernel . kernel_matrix ( ) < < std : : endl ; <nl> + <nl> + for ( int i = 0 ; i < kernel . kernel_matrix ( ) . rows ( ) ; + + i ) { <nl> + for ( int j = 0 ; j < kernel . kernel_matrix ( ) . cols ( ) ; + + j ) { <nl> + if ( i = = j ) { <nl> + EXPECT_DOUBLE_EQ ( kernel . kernel_matrix ( ) ( i , j ) , 0 . 4 ) ; <nl> + } else { <nl> + EXPECT_DOUBLE_EQ ( kernel . kernel_matrix ( ) ( i , j ) , 0 . 0 ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + for ( int i = 0 ; i < kernel . offset ( ) . rows ( ) ; + + i ) { <nl> + for ( int j = 0 ; j < kernel . offset ( ) . cols ( ) ; + + j ) { <nl> + EXPECT_DOUBLE_EQ ( kernel . offset ( ) ( i , j ) , 0 . 0 ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + } / / namespace planning <nl> + } / / namespace apollo <nl>
Planning : added a regularization test in spline_2d_kernel .
ApolloAuto/apollo
6709c69f17576287669e49a6feb3d25e0aaa4726
2017-10-09T21:49:26Z
mmm a / ios / sdk / WeexSDK / Sources / Component / WXTextInputComponent . m <nl> ppp b / ios / sdk / WeexSDK / Sources / Component / WXTextInputComponent . m <nl> <nl> # import " WXConvert . h " <nl> # import " WXUtility . h " <nl> # import " WXSDKInstance . h " <nl> + # import " WXDefine . h " <nl> <nl> @ interface WXTextInputView : UITextField <nl> @ property ( nonatomic , assign ) UIEdgeInsets border ; <nl> @ implementation WXTextInputComponent <nl> @ synthesize padding = _padding ; <nl> @ synthesize textStorage = _textStorage ; <nl> <nl> + WX_EXPORT_METHOD ( @ selector ( focus ) ) <nl> + WX_EXPORT_METHOD ( @ selector ( blur ) ) <nl> + <nl> - ( instancetype ) initWithRef : ( NSString * ) ref type : ( NSString * ) type styles : ( NSDictionary * ) styles attributes : ( NSDictionary * ) attributes events : ( NSArray * ) events weexInstance : ( WXSDKInstance * ) weexInstance <nl> { <nl> self = [ super initWithRef : ref type : type styles : styles attributes : attributes events : events weexInstance : weexInstance ] ; <nl> - ( void ) viewWillUnload <nl> object : nil ] ; <nl> } <nl> <nl> + - ( void ) focus <nl> + { <nl> + if ( self . view ) <nl> + { <nl> + [ self . view becomeFirstResponder ] ; <nl> + } <nl> + } <nl> + <nl> + - ( void ) blur <nl> + { <nl> + if ( self . view ) <nl> + { <nl> + [ self . view resignFirstResponder ] ; <nl> + } <nl> + } <nl> + <nl> # pragma mark - Add Event <nl> - ( void ) addEvent : ( NSString * ) eventName <nl> { <nl>
Merge pull request from alibaba / ios - feature - 20161118
apache/incubator-weex
e5e51daa10a24c5e138afee128214c9d43cd4566
2016-11-07T03:36:55Z
new file mode 100644 <nl> index 000000000000 . . be87a995380d <nl> mmm / dev / null <nl> ppp b / buildscripts / resmokeconfig / suites / sharded_collections_causally_consistent_jscore_txns_passthrough . yml <nl> <nl> + test_kind : js_test <nl> + selector : <nl> + roots : <nl> + - jstests / core / txns / * * / * . js <nl> + exclude_files : <nl> + # Profile can only be run against the admin database on mongos . <nl> + - jstests / core / txns / transactions_profiling . js <nl> + - jstests / core / txns / transactions_profiling_with_drops . js <nl> + <nl> + # No featureCompatibilityVersion parameter on mongos . <nl> + - jstests / core / txns / abort_transactions_on_FCV_downgrade . js <nl> + <nl> + # Mongos doesn ' t upconvert from local or majority level readConcern to snapshot . <nl> + - jstests / core / txns / upconvert_read_concern . js <nl> + <nl> + # Implicitly creates a database through a collection rename , which does not work in a sharded <nl> + # cluster . <nl> + - jstests / core / txns / transactions_block_ddl . js <nl> + <nl> + # TODO SERVER - 36124 : maxTimeMS doesn ' t work for insert on mongos . <nl> + - jstests / core / txns / write_conflicts_with_non_txns . js <nl> + <nl> + # TODO SERVER - 36120 : No doTxn command on mongos . <nl> + - jstests / core / txns / do_txn_atomicity . js <nl> + - jstests / core / txns / do_txn_basic . js <nl> + <nl> + # TODO SERVER - 36121 : Set the transactionLifetimeLimitSeconds parameter , which is not on mongos . <nl> + - jstests / core / txns / abort_expired_transaction . js <nl> + - jstests / core / txns / abort_transaction_thread_does_not_block_on_locks . js <nl> + - jstests / core / txns / kill_op_on_txn_expiry . js <nl> + <nl> + # Writes to the local database are not allowed through mongos . <nl> + # TODO SERVER - 28756 : Mongos CSRS write retry logic drops txnNumbers . <nl> + - jstests / core / txns / banned_txn_dbs . js <nl> + <nl> + # Uses hangAfterCollectionInserts failpoint not available on mongos . <nl> + - jstests / core / txns / speculative_snapshot_includes_all_writes . js <nl> + <nl> + # Cannot shard a capped collection . <nl> + - jstests / core / txns / ban_tailable_cursor . js <nl> + <nl> + # View tests aren ' t expected to work when collections are implicitly sharded . <nl> + - jstests / core / txns / view_reads_in_transaction . js <nl> + <nl> + # Does not use the transactions shell helpers so afterClusterTime read concern is incorrectly <nl> + # attached to statements in a transaction beyond the first one . <nl> + - jstests / core / txns / non_transactional_operations_on_session_with_transaction . js <nl> + exclude_with_any_tags : <nl> + - assumes_against_mongod_not_mongos <nl> + # Tests tagged with the following will fail because they assume collections are not sharded . <nl> + - assumes_no_implicit_collection_creation_after_drop <nl> + - assumes_no_implicit_index_creation <nl> + - assumes_unsharded_collection <nl> + - cannot_create_unique_index_when_using_hashed_shard_key <nl> + # Prepare is not a command on mongos . <nl> + - uses_prepare_transaction <nl> + executor : <nl> + archive : <nl> + hooks : <nl> + - ValidateCollections <nl> + config : <nl> + shell_options : <nl> + eval : > - <nl> + var testingReplication = true ; <nl> + load ( ' jstests / libs / override_methods / implicitly_shard_accessed_collections . js ' ) ; <nl> + readMode : commands <nl> + hooks : <nl> + # We don ' t execute dbHash or oplog consistency checks since there is only a single replica set <nl> + # node . <nl> + - class : ValidateCollections <nl> + - class : CleanEveryN <nl> + n : 20 <nl> + fixture : <nl> + class : ShardedClusterFixture <nl> + mongos_options : <nl> + set_parameters : <nl> + enableTestCommands : 1 <nl> + mongod_options : <nl> + set_parameters : <nl> + enableTestCommands : 1 <nl> + numInitialSyncAttempts : 1 <nl> + num_rs_nodes_per_shard : 2 <nl> + num_shards : 2 <nl> mmm a / etc / evergreen . yml <nl> ppp b / etc / evergreen . yml <nl> tasks : <nl> resmoke_args : - - suites = sharded_causally_consistent_jscore_txns_passthrough - - storageEngine = wiredTiger <nl> run_multiple_jobs : true <nl> <nl> + - < < : * task_template <nl> + name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> + commands : <nl> + - func : " do setup " <nl> + - func : " run tests " <nl> + vars : <nl> + resmoke_args : - - suites = sharded_collections_causally_consistent_jscore_txns_passthrough - - storageEngine = wiredTiger <nl> + run_multiple_jobs : true <nl> + <nl> - < < : * task_template <nl> name : replica_sets_jscore_passthrough <nl> depends_on : <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_auth_0 <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_auth <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : serial_run <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : sasl <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : sasl <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : replica_sets_auth <nl> - name : replica_sets_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharding_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : sasl <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> - name : sharded_collections_jscore_passthrough <nl> buildvariants : <nl> - name : slow1 <nl> - name : serial_run <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : sasl <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : sasl <nl> - name : session_jscore_passthrough <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl> buildvariants : <nl> - name : replica_sets_kill_secondaries_jscore_passthrough <nl> - name : sasl <nl> - name : sharded_causally_consistent_jscore_txns_passthrough <nl> + - name : sharded_collections_causally_consistent_jscore_txns_passthrough <nl> - name : sharded_collections_jscore_passthrough <nl> - name : sharded_jscore_txns <nl> - name : sharded_jscore_txns_sharded_collections <nl>
SERVER - 37879 Run sharded_causally_consistent_jscore_txns_passthrough against sharded collections
mongodb/mongo
064535356bfbeb9afe310944df4344574c9a6e8d
2018-11-30T14:56:29Z
mmm a / src / hydrogen . cc <nl> ppp b / src / hydrogen . cc <nl> bool HOptimizedGraphBuilder : : TryInlineBuiltinMethodCall ( <nl> ast_context ( ) - > ReturnValue ( result ) ; <nl> return true ; <nl> } <nl> + case kArrayIndexOf : <nl> + case kArrayLastIndexOf : { <nl> + if ( receiver_map . is_null ( ) ) return false ; <nl> + if ( receiver_map - > instance_type ( ) ! = JS_ARRAY_TYPE ) return false ; <nl> + ElementsKind kind = receiver_map - > elements_kind ( ) ; <nl> + if ( ! IsFastElementsKind ( kind ) ) return false ; <nl> + if ( receiver_map - > is_observed ( ) ) return false ; <nl> + if ( argument_count ! = 2 ) return false ; <nl> + ASSERT ( receiver_map - > is_extensible ( ) ) ; <nl> + <nl> + / / If there may be elements accessors in the prototype chain , the fast <nl> + / / inlined version can ' t be used . <nl> + if ( receiver_map - > DictionaryElementsInPrototypeChainOnly ( ) ) return false ; <nl> + <nl> + / / If there currently can be no elements accessors on the prototype chain , <nl> + / / it doesn ' t mean that there won ' t be any later . Install a full prototype <nl> + / / chain check to trap element accessors being installed on the prototype <nl> + / / chain , which would cause elements to go to dictionary mode and result <nl> + / / in a map change . <nl> + BuildCheckPrototypeMaps ( <nl> + handle ( JSObject : : cast ( receiver_map - > prototype ( ) ) , isolate ( ) ) , <nl> + Handle < JSObject > : : null ( ) ) ; <nl> + <nl> + HValue * search_element = Pop ( ) ; <nl> + HValue * receiver = Pop ( ) ; <nl> + Drop ( 1 ) ; / / Drop function . <nl> + <nl> + ArrayIndexOfMode mode = ( id = = kArrayIndexOf ) <nl> + ? kFirstIndexOf : kLastIndexOf ; <nl> + HValue * index = BuildArrayIndexOf ( receiver , search_element , kind , mode ) ; <nl> + <nl> + if ( ! ast_context ( ) - > IsEffect ( ) ) Push ( index ) ; <nl> + Add < HSimulate > ( expr - > id ( ) , REMOVABLE_SIMULATE ) ; <nl> + if ( ! ast_context ( ) - > IsEffect ( ) ) Drop ( 1 ) ; <nl> + ast_context ( ) - > ReturnValue ( index ) ; <nl> + return true ; <nl> + } <nl> default : <nl> / / Not yet supported for inlining . <nl> break ; <nl> void HOptimizedGraphBuilder : : BuildArrayCall ( Expression * expression , <nl> } <nl> <nl> <nl> + HValue * HOptimizedGraphBuilder : : BuildArrayIndexOf ( HValue * receiver , <nl> + HValue * search_element , <nl> + ElementsKind kind , <nl> + ArrayIndexOfMode mode ) { <nl> + ASSERT ( IsFastElementsKind ( kind ) ) ; <nl> + <nl> + NoObservableSideEffectsScope no_effects ( this ) ; <nl> + <nl> + HValue * elements = AddLoadElements ( receiver ) ; <nl> + HValue * length = AddLoadArrayLength ( receiver , kind ) ; <nl> + <nl> + HValue * initial ; <nl> + HValue * terminating ; <nl> + Token : : Value token ; <nl> + LoopBuilder : : Direction direction ; <nl> + if ( mode = = kFirstIndexOf ) { <nl> + initial = graph ( ) - > GetConstant0 ( ) ; <nl> + terminating = length ; <nl> + token = Token : : LT ; <nl> + direction = LoopBuilder : : kPostIncrement ; <nl> + } else { <nl> + ASSERT_EQ ( kLastIndexOf , mode ) ; <nl> + initial = length ; <nl> + terminating = graph ( ) - > GetConstant0 ( ) ; <nl> + token = Token : : GTE ; <nl> + direction = LoopBuilder : : kPreDecrement ; <nl> + } <nl> + <nl> + Push ( graph ( ) - > GetConstantMinus1 ( ) ) ; <nl> + if ( IsFastDoubleElementsKind ( kind ) | | IsFastSmiElementsKind ( kind ) ) { <nl> + LoopBuilder loop ( this , context ( ) , direction ) ; <nl> + { <nl> + HValue * index = loop . BeginBody ( initial , terminating , token ) ; <nl> + HValue * element = AddUncasted < HLoadKeyed > ( <nl> + elements , index , static_cast < HValue * > ( NULL ) , <nl> + kind , ALLOW_RETURN_HOLE ) ; <nl> + IfBuilder if_issame ( this ) ; <nl> + if ( IsFastDoubleElementsKind ( kind ) ) { <nl> + if_issame . If < HCompareNumericAndBranch > ( <nl> + element , search_element , Token : : EQ_STRICT ) ; <nl> + } else { <nl> + if_issame . If < HCompareObjectEqAndBranch > ( element , search_element ) ; <nl> + } <nl> + if_issame . Then ( ) ; <nl> + { <nl> + Drop ( 1 ) ; <nl> + Push ( index ) ; <nl> + loop . Break ( ) ; <nl> + } <nl> + if_issame . End ( ) ; <nl> + } <nl> + loop . EndBody ( ) ; <nl> + } else { <nl> + IfBuilder if_isstring ( this ) ; <nl> + if_isstring . If < HIsStringAndBranch > ( search_element ) ; <nl> + if_isstring . Then ( ) ; <nl> + { <nl> + LoopBuilder loop ( this , context ( ) , direction ) ; <nl> + { <nl> + HValue * index = loop . BeginBody ( initial , terminating , token ) ; <nl> + HValue * element = AddUncasted < HLoadKeyed > ( <nl> + elements , index , static_cast < HValue * > ( NULL ) , <nl> + kind , ALLOW_RETURN_HOLE ) ; <nl> + IfBuilder if_issame ( this ) ; <nl> + if_issame . If < HIsStringAndBranch > ( element ) ; <nl> + if_issame . AndIf < HStringCompareAndBranch > ( <nl> + element , search_element , Token : : EQ_STRICT ) ; <nl> + if_issame . Then ( ) ; <nl> + { <nl> + Drop ( 1 ) ; <nl> + Push ( index ) ; <nl> + loop . Break ( ) ; <nl> + } <nl> + if_issame . End ( ) ; <nl> + } <nl> + loop . EndBody ( ) ; <nl> + } <nl> + if_isstring . Else ( ) ; <nl> + { <nl> + IfBuilder if_isheapnumber ( this ) ; <nl> + if_isheapnumber . IfNot < HIsSmiAndBranch > ( search_element ) ; <nl> + HCompareMap * isheapnumber = if_isheapnumber . AndIf < HCompareMap > ( <nl> + search_element , isolate ( ) - > factory ( ) - > heap_number_map ( ) ) ; <nl> + if_isheapnumber . Then ( ) ; <nl> + { <nl> + HValue * search_number = Add < HLoadNamedField > ( <nl> + search_element , isheapnumber , <nl> + HObjectAccess : : ForHeapNumberValue ( ) ) ; <nl> + LoopBuilder loop ( this , context ( ) , direction ) ; <nl> + { <nl> + HValue * index = loop . BeginBody ( initial , terminating , token ) ; <nl> + HValue * element = AddUncasted < HLoadKeyed > ( <nl> + elements , index , static_cast < HValue * > ( NULL ) , <nl> + kind , ALLOW_RETURN_HOLE ) ; <nl> + IfBuilder if_issame ( this ) ; <nl> + HCompareMap * issame = if_issame . If < HCompareMap > ( <nl> + element , isolate ( ) - > factory ( ) - > heap_number_map ( ) ) ; <nl> + if_issame . And ( ) ; <nl> + HValue * number = Add < HLoadNamedField > ( <nl> + element , issame , HObjectAccess : : ForHeapNumberValue ( ) ) ; <nl> + if_issame . If < HCompareNumericAndBranch > ( <nl> + number , search_number , Token : : EQ_STRICT ) ; <nl> + if_issame . Then ( ) ; <nl> + { <nl> + Drop ( 1 ) ; <nl> + Push ( index ) ; <nl> + loop . Break ( ) ; <nl> + } <nl> + if_issame . End ( ) ; <nl> + } <nl> + loop . EndBody ( ) ; <nl> + } <nl> + if_isheapnumber . Else ( ) ; <nl> + { <nl> + LoopBuilder loop ( this , context ( ) , direction ) ; <nl> + { <nl> + HValue * index = loop . BeginBody ( initial , terminating , token ) ; <nl> + HValue * element = AddUncasted < HLoadKeyed > ( <nl> + elements , index , static_cast < HValue * > ( NULL ) , <nl> + kind , ALLOW_RETURN_HOLE ) ; <nl> + IfBuilder if_issame ( this ) ; <nl> + if_issame . If < HCompareObjectEqAndBranch > ( <nl> + element , search_element ) ; <nl> + if_issame . Then ( ) ; <nl> + { <nl> + Drop ( 1 ) ; <nl> + Push ( index ) ; <nl> + loop . Break ( ) ; <nl> + } <nl> + if_issame . End ( ) ; <nl> + } <nl> + loop . EndBody ( ) ; <nl> + } <nl> + if_isheapnumber . End ( ) ; <nl> + } <nl> + if_isstring . End ( ) ; <nl> + } <nl> + <nl> + return Pop ( ) ; <nl> + } <nl> + <nl> + <nl> bool HOptimizedGraphBuilder : : TryHandleArrayCall ( Call * expr , HValue * function ) { <nl> if ( ! array_function ( ) . is_identical_to ( expr - > target ( ) ) ) { <nl> return false ; <nl> mmm a / src / hydrogen . h <nl> ppp b / src / hydrogen . h <nl> class HOptimizedGraphBuilder : public HGraphBuilder , public AstVisitor { <nl> void BuildArrayCall ( Expression * expr , int arguments_count , HValue * function , <nl> Handle < AllocationSite > cell ) ; <nl> <nl> + enum ArrayIndexOfMode { kFirstIndexOf , kLastIndexOf } ; <nl> + HValue * BuildArrayIndexOf ( HValue * receiver , <nl> + HValue * search_element , <nl> + ElementsKind kind , <nl> + ArrayIndexOfMode mode ) ; <nl> + <nl> HValue * ImplicitReceiverFor ( HValue * function , <nl> Handle < JSFunction > target ) ; <nl> <nl> mmm a / src / objects . h <nl> ppp b / src / objects . h <nl> class Script : public Struct { <nl> / / <nl> / / Installation of ids for the selected builtin functions is handled <nl> / / by the bootstrapper . <nl> - # define FUNCTIONS_WITH_ID_LIST ( V ) \ <nl> - V ( Array . prototype , push , ArrayPush ) \ <nl> - V ( Array . prototype , pop , ArrayPop ) \ <nl> - V ( Array . prototype , shift , ArrayShift ) \ <nl> - V ( Function . prototype , apply , FunctionApply ) \ <nl> - V ( String . prototype , charCodeAt , StringCharCodeAt ) \ <nl> - V ( String . prototype , charAt , StringCharAt ) \ <nl> - V ( String , fromCharCode , StringFromCharCode ) \ <nl> - V ( Math , floor , MathFloor ) \ <nl> - V ( Math , round , MathRound ) \ <nl> - V ( Math , ceil , MathCeil ) \ <nl> - V ( Math , abs , MathAbs ) \ <nl> - V ( Math , log , MathLog ) \ <nl> - V ( Math , exp , MathExp ) \ <nl> - V ( Math , sqrt , MathSqrt ) \ <nl> - V ( Math , pow , MathPow ) \ <nl> - V ( Math , max , MathMax ) \ <nl> - V ( Math , min , MathMin ) \ <nl> + # define FUNCTIONS_WITH_ID_LIST ( V ) \ <nl> + V ( Array . prototype , indexOf , ArrayIndexOf ) \ <nl> + V ( Array . prototype , lastIndexOf , ArrayLastIndexOf ) \ <nl> + V ( Array . prototype , push , ArrayPush ) \ <nl> + V ( Array . prototype , pop , ArrayPop ) \ <nl> + V ( Array . prototype , shift , ArrayShift ) \ <nl> + V ( Function . prototype , apply , FunctionApply ) \ <nl> + V ( String . prototype , charCodeAt , StringCharCodeAt ) \ <nl> + V ( String . prototype , charAt , StringCharAt ) \ <nl> + V ( String , fromCharCode , StringFromCharCode ) \ <nl> + V ( Math , floor , MathFloor ) \ <nl> + V ( Math , round , MathRound ) \ <nl> + V ( Math , ceil , MathCeil ) \ <nl> + V ( Math , abs , MathAbs ) \ <nl> + V ( Math , log , MathLog ) \ <nl> + V ( Math , exp , MathExp ) \ <nl> + V ( Math , sqrt , MathSqrt ) \ <nl> + V ( Math , pow , MathPow ) \ <nl> + V ( Math , max , MathMax ) \ <nl> + V ( Math , min , MathMin ) \ <nl> V ( Math , imul , MathImul ) <nl> <nl> enum BuiltinFunctionId { <nl>
Inline fast path for Array . indexOf ( ) and Array . lastIndexOf ( ) .
v8/v8
2a2874b9c351a17dd3925ef0ccc4d22cec4ed4e0
2014-06-03T04:01:34Z
mmm a / dlib / svm / svm_c_linear_dcd_trainer . h <nl> ppp b / dlib / svm / svm_c_linear_dcd_trainer . h <nl> namespace dlib <nl> dlib : : rand rnd ; <nl> <nl> public : <nl> + <nl> + const std : : vector < scalar_type > & get_alpha ( ) const { return alpha ; } <nl> + <nl> friend void serialize ( const optimizer_state & item , std : : ostream & out ) <nl> { <nl> const int version = 1 ; <nl> mmm a / dlib / svm / svm_c_linear_dcd_trainer_abstract . h <nl> ppp b / dlib / svm / svm_c_linear_dcd_trainer_abstract . h <nl> namespace dlib <nl> ! * / <nl> <nl> / / optimizer_state is used to record the internal state of the SVM optimizer . It <nl> - / / can be used with the following train ( ) routine to warm - start the optimizer . <nl> - / / Note , that optimizer_state objects are serializable but are otherwise completely <nl> - / / opaque to the user . <nl> - class optimizer_state ; <nl> + / / can be used with the following train ( ) routine to warm - start the optimizer or <nl> + / / access the optimal alpha values ( see the Hsieh paper mentioned above ) . The <nl> + / / optimizer_state objects are serializable and allow you to get the alphas , but <nl> + / / are otherwise completely opaque to the user . <nl> + class optimizer_state <nl> + { <nl> + public : <nl> + const std : : vector < scalar_type > & get_alpha ( <nl> + ) const ; <nl> + } ; <nl> <nl> template < <nl> typename in_sample_vector_type , <nl> namespace dlib <nl> - # state = = the internal state of the optimizer at the solution to the SVM <nl> problem . Therefore , passing # state to a new call to train ( ) will start <nl> the optimizer from the current solution . <nl> + - # state . get_alpha ( ) . size ( ) = = x . size ( ) <nl> + - # state . get_alpha ( ) = = the optimal alpha / dual values learned by the optimizer . <nl> - returns a decision function F with the following properties : <nl> - F . alpha . size ( ) = = 1 <nl> - F . basis_vectors . size ( ) = = 1 <nl>
Made it so you can get the optimal alpha values .
davisking/dlib
3e9b7ebb6b7c6199c39c2877425c35c2f0790049
2016-02-18T15:21:50Z
new file mode 100644 <nl> index 000000000000 . . e9135b73c4da <nl> mmm / dev / null <nl> ppp b / validation - test / execution / sr9624 . swift <nl> <nl> + / / RUN : % target - run - simple - swift | % FileCheck % s <nl> + / / REQUIRES : executable_test <nl> + <nl> + protocol P { <nl> + associatedtype T <nl> + func foo ( t : inout T ) <nl> + } <nl> + struct S : P { <nl> + func foo ( t : inout ( ) - > Void ) { <nl> + t ( ) <nl> + t = { print ( " new " ) } <nl> + } <nl> + } <nl> + <nl> + func doTheFoo < SomeP : P > ( _ p : SomeP , _ value : SomeP . T ) - > SomeP . T { <nl> + var mutableValue = value <nl> + p . foo ( t : & mutableValue ) <nl> + return mutableValue <nl> + } <nl> + <nl> + print ( " START " ) <nl> + let newClosure = doTheFoo ( S ( ) , { print ( " old " ) } ) <nl> + newClosure ( ) <nl> + print ( " DONE " ) <nl> + <nl> + / / CHECK : START <nl> + / / CHECK - NEXT : old <nl> + / / CHECK - NEXT : new <nl> + / / CHECK - NEXT : DONE <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
6657d8c4943df944f2911862ffa886318d3dc925
2019-01-09T19:11:53Z
mmm a / dbms / programs / obfuscator / Obfuscator . cpp <nl> ppp b / dbms / programs / obfuscator / Obfuscator . cpp <nl> <nl> # include < boost / algorithm / string . hpp > <nl> # include < boost / container / flat_map . hpp > <nl> <nl> - # include < common / iostream_debug_helpers . h > <nl> - <nl> <nl> static const char * documantation = R " ( <nl> Simple tool for table data obfuscation . <nl>
Data obfuscator : added documentation [ # CLICKHOUSE - 2 ]
ClickHouse/ClickHouse
fae4359ee14daddaea8dbedbee4416a6db7c7e0d
2018-06-16T01:45:19Z
mmm a / lib / AST / Module . cpp <nl> ppp b / lib / AST / Module . cpp <nl> SourceFile : : ~ SourceFile ( ) = default ; <nl> class swift : : SourceLookupCache { <nl> / / / A lookup map for value decls . When declarations are added they are added <nl> / / / under all variants of the name they can be found under . <nl> - class DeclMap { <nl> - llvm : : DenseMap < DeclName , TinyPtrVector < ValueDecl * > > Members ; <nl> + class ValueDeclMap { <nl> + llvm : : DenseMap < DeclName , TinyPtrVector < ValueDecl * > > Members ; <nl> <nl> public : <nl> void add ( ValueDecl * VD ) { <nl> class swift : : SourceLookupCache { <nl> } <nl> } ; <nl> <nl> - DeclMap TopLevelValues ; <nl> - DeclMap ClassMembers ; <nl> + ValueDeclMap TopLevelValues ; <nl> + ValueDeclMap ClassMembers ; <nl> bool MemberCachePopulated = false ; <nl> <nl> + template < typename T > <nl> + using OperatorMap = llvm : : DenseMap < Identifier , TinyPtrVector < T * > > ; <nl> + OperatorMap < OperatorDecl > Operators ; <nl> + OperatorMap < PrecedenceGroupDecl > PrecedenceGroups ; <nl> + <nl> template < typename Range > <nl> void addToUnqualifiedLookupCache ( Range decls , bool onlyOperators ) ; <nl> template < typename Range > <nl> class swift : : SourceLookupCache { <nl> <nl> void lookupValue ( DeclName Name , NLKind LookupKind , <nl> SmallVectorImpl < ValueDecl * > & Result ) ; <nl> - <nl> + <nl> + / / / Retrieves all the operator decls . The order of the results is not <nl> + / / / guaranteed to be meaningful . <nl> + void getOperatorDecls ( SmallVectorImpl < OperatorDecl * > & results ) ; <nl> + <nl> + / / / Retrieves all the precedence groups . The order of the results is not <nl> + / / / guaranteed to be meaningful . <nl> + void getPrecedenceGroups ( SmallVectorImpl < PrecedenceGroupDecl * > & results ) ; <nl> + <nl> + / / / Look up an operator declaration . <nl> + / / / <nl> + / / / \ param name The operator name ( " + " , " > > " , etc . ) <nl> + / / / \ param fixity The fixity of the operator ( infix , prefix or postfix ) . <nl> + void lookupOperator ( Identifier name , OperatorFixity fixity , <nl> + TinyPtrVector < OperatorDecl * > & results ) ; <nl> + <nl> + / / / Look up a precedence group . <nl> + / / / <nl> + / / / \ param name The operator name ( " + " , " > > " , etc . ) <nl> + void lookupPrecedenceGroup ( Identifier name , <nl> + TinyPtrVector < PrecedenceGroupDecl * > & results ) ; <nl> + <nl> void lookupVisibleDecls ( AccessPathTy AccessPath , <nl> VisibleDeclConsumer & Consumer , <nl> NLKind LookupKind ) ; <nl> void SourceLookupCache : : addToUnqualifiedLookupCache ( Range decls , <nl> if ( ! ED - > hasUnparsedMembers ( ) | | ED - > maybeHasOperatorDeclarations ( ) ) <nl> addToUnqualifiedLookupCache ( ED - > getMembers ( ) , true ) ; <nl> } <nl> + <nl> + if ( auto * OD = dyn_cast < OperatorDecl > ( D ) ) <nl> + Operators [ OD - > getName ( ) ] . push_back ( OD ) ; <nl> + <nl> + if ( auto * PG = dyn_cast < PrecedenceGroupDecl > ( D ) ) <nl> + PrecedenceGroups [ PG - > getName ( ) ] . push_back ( PG ) ; <nl> } <nl> } <nl> <nl> void SourceLookupCache : : lookupValue ( DeclName Name , NLKind LookupKind , <nl> Result . push_back ( Elt ) ; <nl> } <nl> <nl> + void SourceLookupCache : : getPrecedenceGroups ( <nl> + SmallVectorImpl < PrecedenceGroupDecl * > & results ) { <nl> + for ( auto & groups : PrecedenceGroups ) <nl> + results . append ( groups . second . begin ( ) , groups . second . end ( ) ) ; <nl> + } <nl> + <nl> + void SourceLookupCache : : getOperatorDecls ( <nl> + SmallVectorImpl < OperatorDecl * > & results ) { <nl> + for ( auto & ops : Operators ) <nl> + results . append ( ops . second . begin ( ) , ops . second . end ( ) ) ; <nl> + } <nl> + <nl> + void SourceLookupCache : : lookupOperator ( Identifier name , OperatorFixity fixity , <nl> + TinyPtrVector < OperatorDecl * > & results ) { <nl> + auto ops = Operators . find ( name ) ; <nl> + if ( ops = = Operators . end ( ) ) <nl> + return ; <nl> + <nl> + for ( auto * op : ops - > second ) <nl> + if ( op - > getFixity ( ) = = fixity ) <nl> + results . push_back ( op ) ; <nl> + } <nl> + <nl> + void SourceLookupCache : : lookupPrecedenceGroup ( <nl> + Identifier name , TinyPtrVector < PrecedenceGroupDecl * > & results ) { <nl> + auto groups = PrecedenceGroups . find ( name ) ; <nl> + if ( groups = = PrecedenceGroups . end ( ) ) <nl> + return ; <nl> + <nl> + for ( auto * group : groups - > second ) <nl> + results . push_back ( group ) ; <nl> + } <nl> + <nl> void SourceLookupCache : : lookupVisibleDecls ( AccessPathTy AccessPath , <nl> VisibleDeclConsumer & Consumer , <nl> NLKind LookupKind ) { <nl>
Add precedencegroup and operator decls to SourceLookupCache
apple/swift
6c3362fb55affe123a1f7254c7a39fc8c554a9bc
2020-03-27T16:44:55Z
new file mode 100644 <nl> index 000000000000 . . ca2bfe1a03ee <nl> mmm / dev / null <nl> ppp b / licenses / LICENSE_jsoncpp . txt <nl> <nl> + The JsonCpp library ' s source code , including accompanying documentation , <nl> + tests and demonstration applications , are licensed under the following <nl> + conditions . . . <nl> + <nl> + The author ( Baptiste Lepilleur ) explicitly disclaims copyright in all <nl> + jurisdictions which recognize such a disclaimer . In such jurisdictions , <nl> + this software is released into the Public Domain . <nl> + <nl> + In jurisdictions which do not recognize Public Domain property ( e . g . Germany as of <nl> + 2010 ) , this software is Copyright ( c ) 2007 - 2010 by Baptiste Lepilleur , and is <nl> + released under the terms of the MIT License ( see below ) . <nl> + <nl> + In jurisdictions which recognize Public Domain property , the user of this <nl> + software may choose to accept it either as 1 ) Public Domain , 2 ) under the <nl> + conditions of the MIT License ( see below ) , or 3 ) under the terms of dual <nl> + Public Domain / MIT License conditions described here , as they choose . <nl> + <nl> + The MIT License is about as close to Public Domain as a license can get , and is <nl> + described in clear , concise terms at : <nl> + <nl> + http : / / en . wikipedia . org / wiki / MIT_License <nl> + <nl> + The full text of the MIT License follows : <nl> + <nl> + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + Copyright ( c ) 2007 - 2010 Baptiste Lepilleur <nl> + <nl> + Permission is hereby granted , free of charge , to any person <nl> + obtaining a copy of this software and associated documentation <nl> + files ( the " Software " ) , to deal in the Software without <nl> + restriction , including without limitation the rights to use , copy , <nl> + modify , merge , publish , distribute , sublicense , and / or sell copies <nl> + of the Software , and to permit persons to whom the Software is <nl> + furnished to do so , subject to the following conditions : <nl> + <nl> + The above copyright notice and this permission notice shall be <nl> + included in all copies or substantial portions of the Software . <nl> + <nl> + THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , <nl> + EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF <nl> + MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND <nl> + NONINFRINGEMENT . IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS <nl> + BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN <nl> + ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN <nl> + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE <nl> + SOFTWARE . <nl> + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> + ( END LICENSE TEXT ) <nl> + <nl> + The MIT license is compatible with both the GPL and commercial <nl> + software , affording one all of the rights of Public Domain with the <nl> + minor nuisance of being required to keep the above copyright notice <nl> + and license text in the source code . Note also that by accepting the <nl> + Public Domain " license " you can re - license your copy using whatever <nl> + license you like . <nl> new file mode 100644 <nl> index 000000000000 . . 40501fa1a21c <nl> mmm / dev / null <nl> ppp b / licenses / LICENSE_sigslot . txt <nl> <nl> + License <nl> + <nl> + The sigslot library has been placed in the public domain . This means that you are free to use it however you like . <nl> + <nl> + The author takes no responsibility or liability of any kind for any use that you may make of this library . <nl> + <nl> + If you screw up , it ' s your fault . <nl> + <nl> + If the library screws up , you got it for free , so you should have tested it better - it ' s still your responsibility . <nl> \ No newline at end of file <nl>
fixed : Adding licenses of jsoncpp and sigslot .
cocos2d/cocos2d-x
67441deb03c9b66a881201046baff7de55ce00db
2013-06-09T03:13:45Z
mmm a / selfdrive / car / chrysler / carcontroller . py <nl> ppp b / selfdrive / car / chrysler / carcontroller . py <nl> <nl> <nl> class CarController ( ) : <nl> def __init__ ( self , dbc_name , CP , VM ) : <nl> - self . braking = False <nl> self . apply_steer_last = 0 <nl> self . ccframe = 0 <nl> self . prev_frame = - 1 <nl> mmm a / selfdrive / car / chrysler / interface . py <nl> ppp b / selfdrive / car / chrysler / interface . py <nl> def update ( self , c , can_strings ) : <nl> ret . buttonEvents = [ ] <nl> <nl> # events <nl> - events = self . create_common_events ( ret , extra_gears = [ car . CarState . GearShifter . low ] , gas_resume_speed = 2 . ) <nl> - <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - elif not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> + events = self . create_common_events ( ret , extra_gears = [ car . CarState . GearShifter . low ] , gas_resume_speed = 2 . ) <nl> <nl> if ret . vEgo < self . CP . minSteerSpeed : <nl> events . append ( create_event ( ' belowSteerSpeed ' , [ ET . WARNING ] ) ) <nl> <nl> ret . events = events <nl> <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - <nl> # copy back carState packet to CS <nl> self . CS . out = ret . as_reader ( ) <nl> <nl> mmm a / selfdrive / car / ford / interface . py <nl> ppp b / selfdrive / car / ford / interface . py <nl> def update ( self , c , can_strings ) : <nl> # events <nl> events = self . create_common_events ( ret ) <nl> <nl> - # enable request in prius is simple , as we activate when Toyota is active ( rising edge ) <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - elif not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> if self . CS . lkas_state not in [ 2 , 3 ] and ret . vEgo > 13 . * CV . MPH_TO_MS and ret . cruiseState . enabled : <nl> events . append ( create_event ( ' steerTempUnavailableMute ' , [ ET . WARNING ] ) ) <nl> <nl> ret . events = events <nl> <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - <nl> self . CS . out = ret . as_reader ( ) <nl> - <nl> return self . CS . out <nl> <nl> # pass in a car . CarControl <nl> mmm a / selfdrive / car / gm / interface . py <nl> ppp b / selfdrive / car / gm / interface . py <nl> def update ( self , c , can_strings ) : <nl> <nl> ret . buttonEvents = buttonEvents <nl> <nl> - events = self . create_common_events ( ret ) <nl> + supercruise = self . CS . car_fingerprint in SUPERCRUISE_CARS <nl> + events = self . create_common_events ( ret , pcm_enable = supercruise ) <nl> <nl> - if self . CS . car_fingerprint in SUPERCRUISE_CARS : <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - if not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> - else : <nl> + if not supercruise : <nl> # TODO : why is this only not supercruise ? ignore supercruise ? <nl> if ret . vEgo < self . CP . minEnableSpeed : <nl> events . append ( create_event ( ' speedTooLow ' , [ ET . NO_ENTRY ] ) ) <nl> def update ( self , c , can_strings ) : <nl> <nl> ret . events = events <nl> <nl> - # update previous brake / gas pressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - <nl> # copy back carState packet to CS <nl> self . CS . out = ret . as_reader ( ) <nl> <nl> mmm a / selfdrive / car / honda / interface . py <nl> ppp b / selfdrive / car / honda / interface . py <nl> def update ( self , c , can_strings ) : <nl> ret . buttonEvents = buttonEvents <nl> <nl> # events <nl> - events = self . create_common_events ( ret ) <nl> + events = self . create_common_events ( ret , pcm_enable = False ) <nl> if self . CS . brake_error : <nl> events . append ( create_event ( ' brakeUnavailable ' , [ ET . NO_ENTRY , ET . IMMEDIATE_DISABLE , ET . PERMANENT ] ) ) <nl> if self . CS . brake_hold and self . CS . CP . carFingerprint not in HONDA_BOSCH : <nl> def update ( self , c , can_strings ) : <nl> <nl> ret . events = events <nl> <nl> - # update previous brake / gas pressed <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - <nl> self . CS . out = ret . as_reader ( ) <nl> return self . CS . out <nl> <nl> mmm a / selfdrive / car / hyundai / interface . py <nl> ppp b / selfdrive / car / hyundai / interface . py <nl> def update ( self , c , can_strings ) : <nl> <nl> events = self . create_common_events ( ret ) <nl> <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - elif not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> # low speed steer alert hysteresis logic ( only for cars with steer cut off above 10 m / s ) <nl> if ret . vEgo < ( self . CP . minSteerSpeed + 2 . ) and self . CP . minSteerSpeed > 10 . : <nl> self . low_speed_alert = True <nl> def update ( self , c , can_strings ) : <nl> <nl> ret . events = events <nl> <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - <nl> self . CS . out = ret . as_reader ( ) <nl> return self . CS . out <nl> <nl> mmm a / selfdrive / car / interfaces . py <nl> ppp b / selfdrive / car / interfaces . py <nl> def __init__ ( self , CP , CarController , CarState ) : <nl> self . VM = VehicleModel ( CP ) <nl> <nl> self . frame = 0 <nl> - self . gas_pressed_prev = False <nl> - self . brake_pressed_prev = False <nl> - self . cruise_enabled_prev = False <nl> self . low_speed_alert = False <nl> <nl> self . CS = CarState ( CP ) <nl> def update ( self , c , can_strings ) : <nl> def apply ( self , c ) : <nl> raise NotImplementedError <nl> <nl> - def create_common_events ( self , cs_out , extra_gears = [ ] , gas_resume_speed = - 1 ) : <nl> + def create_common_events ( self , cs_out , extra_gears = [ ] , gas_resume_speed = - 1 , pcm_enable = True ) : <nl> events = [ ] <nl> <nl> if cs_out . doorOpen : <nl> def create_common_events ( self , cs_out , extra_gears = [ ] , gas_resume_speed = - 1 ) : <nl> # Disable on rising edge of gas or brake . Also disable on brake when speed > 0 . <nl> # Optionally allow to press gas at zero speed to resume . <nl> # e . g . Chrysler does not spam the resume button yet , so resuming with gas is handy . FIXME ! <nl> - if ( cs_out . gasPressed and ( not self . gas_pressed_prev ) and cs_out . vEgo > gas_resume_speed ) or \ <nl> - ( cs_out . brakePressed and ( not self . brake_pressed_prev or not cs_out . standstill ) ) : <nl> + if ( cs_out . gasPressed and ( not self . CS . out . gasPressed ) and cs_out . vEgo > gas_resume_speed ) or \ <nl> + ( cs_out . brakePressed and ( not self . CS . out . brakePressed or not cs_out . standstill ) ) : <nl> events . append ( create_event ( ' pedalPressed ' , [ ET . NO_ENTRY , ET . USER_DISABLE ] ) ) <nl> <nl> + # we engage when pcm is active ( rising edge ) <nl> + if pcm_enable : <nl> + if cs_out . cruiseState . enabled and not self . CS . out . cruiseState . enabled : <nl> + events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> + elif not cs_out . cruiseState . enabled : <nl> + events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> + <nl> return events <nl> <nl> class RadarInterfaceBase ( ) : <nl> def __init__ ( self , CP ) : <nl> self . CP = CP <nl> self . car_fingerprint = CP . carFingerprint <nl> self . cruise_buttons = 0 <nl> + self . out = car . CarState . new_message ( ) <nl> <nl> # Q = np . matrix ( [ [ 10 . 0 , 0 . 0 ] , [ 0 . 0 , 100 . 0 ] ] ) <nl> # R = 1e3 <nl> mmm a / selfdrive / car / nissan / interface . py <nl> ppp b / selfdrive / car / nissan / interface . py <nl> def update ( self , c , can_strings ) : <nl> <nl> events = self . create_common_events ( ret ) <nl> <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - if not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> if self . CS . lkas_enabled : <nl> events . append ( create_event ( ' invalidLkasSetting ' , [ ET . PERMANENT ] ) ) <nl> <nl> ret . events = events <nl> <nl> - # update previous brake / gas pressed <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - <nl> - <nl> self . CS . out = ret . as_reader ( ) <nl> return self . CS . out <nl> <nl> mmm a / selfdrive / car / subaru / interface . py <nl> ppp b / selfdrive / car / subaru / interface . py <nl> <nl> # ! / usr / bin / env python3 <nl> from cereal import car <nl> from selfdrive . config import Conversions as CV <nl> - from selfdrive . controls . lib . drive_helpers import create_event , EventTypes as ET <nl> from selfdrive . car . subaru . values import CAR <nl> from selfdrive . car import STD_CARGO_KG , scale_rot_inertia , scale_tire_stiffness , gen_empty_fingerprint <nl> from selfdrive . car . interfaces import CarInterfaceBase <nl> def update ( self , c , can_strings ) : <nl> be . type = car . CarState . ButtonEvent . Type . accelCruise <nl> buttonEvents . append ( be ) <nl> <nl> - events = self . create_common_events ( ret ) <nl> - <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - if not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> - ret . events = events <nl> - <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> + ret . events = self . create_common_events ( ret ) <nl> <nl> self . CS . out = ret . as_reader ( ) <nl> return self . CS . out <nl> mmm a / selfdrive / car / toyota / carcontroller . py <nl> ppp b / selfdrive / car / toyota / carcontroller . py <nl> def accel_hysteresis ( accel , accel_steady , enabled ) : <nl> return accel , accel_steady <nl> <nl> <nl> - def process_hud_alert ( hud_alert ) : <nl> - # initialize to no alert <nl> - steer = 0 <nl> - fcw = 0 <nl> - <nl> - if hud_alert = = VisualAlert . fcw : <nl> - fcw = 1 <nl> - elif hud_alert = = VisualAlert . steerRequired : <nl> - steer = 1 <nl> - <nl> - return steer , fcw <nl> - <nl> - <nl> class CarController ( ) : <nl> def __init__ ( self , dbc_name , CP , VM ) : <nl> - self . braking = False <nl> self . last_steer = 0 <nl> self . accel_steady = 0 . <nl> - self . car_fingerprint = CP . carFingerprint <nl> self . alert_active = False <nl> self . last_standstill = False <nl> self . standstill_req = False <nl> def update ( self , enabled , CS , frame , actuators , pcm_cancel_cmd , hud_alert , <nl> # ui mesg is at 100Hz but we send asap if : <nl> # - there is something to display <nl> # - there is something to stop displaying <nl> - alert_out = process_hud_alert ( hud_alert ) <nl> - steer , fcw = alert_out <nl> + fcw_alert = hud_alert = = VisualAlert . fcw <nl> + steer_alert = hud_alert = = VisualAlert . steerRequired <nl> <nl> - if ( any ( alert_out ) and not self . alert_active ) or \ <nl> - ( not any ( alert_out ) and self . alert_active ) : <nl> + send_ui = False <nl> + if ( ( fcw_alert or steer_alert ) and not self . alert_active ) or \ <nl> + ( not ( fcw_alert or steer_alert ) and self . alert_active ) : <nl> send_ui = True <nl> self . alert_active = not self . alert_active <nl> - else : <nl> - send_ui = False <nl> - <nl> - # disengage msg causes a bad fault sound so play a good sound instead <nl> - if pcm_cancel_cmd : <nl> + elif pcm_cancel_cmd : <nl> + # forcing the pcm to disengage causes a bad fault sound so play a good sound instead <nl> send_ui = True <nl> <nl> if ( frame % 100 = = 0 or send_ui ) and Ecu . fwdCamera in self . fake_ecus : <nl> - can_sends . append ( create_ui_command ( self . packer , steer , pcm_cancel_cmd , left_line , right_line , left_lane_depart , right_lane_depart ) ) <nl> + can_sends . append ( create_ui_command ( self . packer , steer_alert , pcm_cancel_cmd , left_line , right_line , left_lane_depart , right_lane_depart ) ) <nl> <nl> if frame % 100 = = 0 and Ecu . dsu in self . fake_ecus : <nl> - can_sends . append ( create_fcw_command ( self . packer , fcw ) ) <nl> + can_sends . append ( create_fcw_command ( self . packer , fcw_alert ) ) <nl> <nl> # * * * static msgs * * * <nl> <nl> for ( addr , ecu , cars , bus , fr_step , vl ) in STATIC_MSGS : <nl> - if frame % fr_step = = 0 and ecu in self . fake_ecus and self . car_fingerprint in cars : <nl> + if frame % fr_step = = 0 and ecu in self . fake_ecus and CS . CP . carFingerprint in cars : <nl> can_sends . append ( make_can_msg ( addr , vl , bus ) ) <nl> <nl> return can_sends <nl> mmm a / selfdrive / car / toyota / interface . py <nl> ppp b / selfdrive / car / toyota / interface . py <nl> def update ( self , c , can_strings ) : <nl> # while in standstill , send a user alert <nl> events . append ( create_event ( ' manualRestart ' , [ ET . WARNING ] ) ) <nl> <nl> - # enable request in prius is simple , as we activate when Toyota is active ( rising edge ) <nl> - if ret . cruiseState . enabled and not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - elif not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - <nl> ret . events = events <nl> <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> - <nl> self . CS . out = ret . as_reader ( ) <nl> return self . CS . out <nl> <nl> mmm a / selfdrive / car / volkswagen / interface . py <nl> ppp b / selfdrive / car / volkswagen / interface . py <nl> def update ( self , c , can_strings ) : <nl> if self . CS . steeringFault : <nl> events . append ( create_event ( ' steerTempUnavailable ' , [ ET . NO_ENTRY , ET . WARNING ] ) ) <nl> <nl> - # Engagement and longitudinal control using stock ACC . Make sure OP is <nl> - # disengaged if stock ACC is disengaged . <nl> - if not ret . cruiseState . enabled : <nl> - events . append ( create_event ( ' pcmDisable ' , [ ET . USER_DISABLE ] ) ) <nl> - # Attempt OP engagement only on rising edge of stock ACC engagement . <nl> - elif not self . cruise_enabled_prev : <nl> - events . append ( create_event ( ' pcmEnable ' , [ ET . ENABLE ] ) ) <nl> - <nl> ret . events = events <nl> ret . buttonEvents = buttonEvents <nl> ret . canMonoTimes = canMonoTimes <nl> <nl> # update previous car states <nl> - self . gas_pressed_prev = ret . gasPressed <nl> - self . brake_pressed_prev = ret . brakePressed <nl> - self . cruise_enabled_prev = ret . cruiseState . enabled <nl> self . displayMetricUnitsPrev = self . CS . displayMetricUnits <nl> self . buttonStatesPrev = self . CS . buttonStates . copy ( ) <nl> <nl>
Abstract pcmEnable and pcmDisable events ( )
commaai/openpilot
8d791d78dd4fbc973eb61ccd9df2ed4cf9bbbcd5
2020-04-10T23:12:58Z
mmm a / src / core / transport / chttp2 / hpack_encoder . c <nl> ppp b / src / core / transport / chttp2 / hpack_encoder . c <nl> static void emit_lithdr_incidx ( grpc_chttp2_hpack_compressor * c , <nl> len_val_len = GRPC_CHTTP2_VARINT_LENGTH ( ( uint32_t ) len_val , 1 ) ; <nl> GRPC_CHTTP2_WRITE_VARINT ( key_index , 2 , 0x40 , <nl> add_tiny_header_data ( st , len_pfx ) , len_pfx ) ; <nl> - GRPC_CHTTP2_WRITE_VARINT ( ( uint32_t ) len_val , 1 , 0x00 , <nl> + GRPC_CHTTP2_WRITE_VARINT ( ( uint32_t ) len_val , 1 , huffman_prefix , <nl> add_tiny_header_data ( st , len_val_len ) , len_val_len ) ; <nl> add_header_data ( st , gpr_slice_ref ( value_slice ) ) ; <nl> } <nl> static void emit_lithdr_noidx ( grpc_chttp2_hpack_compressor * c , <nl> len_val_len = GRPC_CHTTP2_VARINT_LENGTH ( ( uint32_t ) len_val , 1 ) ; <nl> GRPC_CHTTP2_WRITE_VARINT ( key_index , 4 , 0x00 , <nl> add_tiny_header_data ( st , len_pfx ) , len_pfx ) ; <nl> - GRPC_CHTTP2_WRITE_VARINT ( ( uint32_t ) len_val , 1 , 0x00 , <nl> + GRPC_CHTTP2_WRITE_VARINT ( ( uint32_t ) len_val , 1 , huffman_prefix , <nl> add_tiny_header_data ( st , len_val_len ) , len_val_len ) ; <nl> add_header_data ( st , gpr_slice_ref ( value_slice ) ) ; <nl> } <nl> mmm a / test / cpp / end2end / end2end_test . cc <nl> ppp b / test / cpp / end2end / end2end_test . cc <nl> class End2endTest : public : : testing : : TestWithParam < TestScenario > { <nl> TestServiceImplDupPkg dup_pkg_service_ ; <nl> } ; <nl> <nl> - static void SendRpc ( grpc : : testing : : EchoTestService : : Stub * stub , int num_rpcs ) { <nl> + static void SendRpc ( grpc : : testing : : EchoTestService : : Stub * stub , int num_rpcs , <nl> + bool with_binary_metadata ) { <nl> EchoRequest request ; <nl> EchoResponse response ; <nl> request . set_message ( " Hello hello hello hello " ) ; <nl> <nl> for ( int i = 0 ; i < num_rpcs ; + + i ) { <nl> ClientContext context ; <nl> + if ( with_binary_metadata ) { <nl> + char bytes [ 8 ] = { ' \ 0 ' , ' \ 1 ' , ' \ 2 ' , ' \ 3 ' , ' \ 4 ' , ' \ 5 ' , ' \ 6 ' , ( char ) i } ; <nl> + context . AddMetadata ( " custom - bin " , grpc : : string ( bytes , 8 ) ) ; <nl> + } <nl> context . set_compression_algorithm ( GRPC_COMPRESS_GZIP ) ; <nl> Status s = stub - > Echo ( & context , request , & response ) ; <nl> EXPECT_EQ ( response . message ( ) , request . message ( ) ) ; <nl> static void SendRpc ( grpc : : testing : : EchoTestService : : Stub * stub , int num_rpcs ) { <nl> } <nl> } <nl> <nl> + TEST_P ( End2endTest , MultipleRpcsWithVariedBinaryMetadataValue ) { <nl> + ResetStub ( ) ; <nl> + std : : vector < std : : thread * > threads ; <nl> + for ( int i = 0 ; i < 10 ; + + i ) { <nl> + threads . push_back ( new std : : thread ( SendRpc , stub_ . get ( ) , 10 , true ) ) ; <nl> + } <nl> + for ( int i = 0 ; i < 10 ; + + i ) { <nl> + threads [ i ] - > join ( ) ; <nl> + delete threads [ i ] ; <nl> + } <nl> + } <nl> + <nl> + TEST_P ( End2endTest , MultipleRpcs ) { <nl> + ResetStub ( ) ; <nl> + std : : vector < std : : thread * > threads ; <nl> + for ( int i = 0 ; i < 10 ; + + i ) { <nl> + threads . push_back ( new std : : thread ( SendRpc , stub_ . get ( ) , 10 , false ) ) ; <nl> + } <nl> + for ( int i = 0 ; i < 10 ; + + i ) { <nl> + threads [ i ] - > join ( ) ; <nl> + delete threads [ i ] ; <nl> + } <nl> + } <nl> + <nl> TEST_P ( End2endTest , RequestStreamOneRequest ) { <nl> ResetStub ( ) ; <nl> EchoRequest request ; <nl> class ProxyEnd2endTest : public End2endTest { <nl> <nl> TEST_P ( ProxyEnd2endTest , SimpleRpc ) { <nl> ResetStub ( ) ; <nl> - SendRpc ( stub_ . get ( ) , 1 ) ; <nl> + SendRpc ( stub_ . get ( ) , 1 , false ) ; <nl> } <nl> <nl> TEST_P ( ProxyEnd2endTest , MultipleRpcs ) { <nl> ResetStub ( ) ; <nl> std : : vector < std : : thread * > threads ; <nl> for ( int i = 0 ; i < 10 ; + + i ) { <nl> - threads . push_back ( new std : : thread ( SendRpc , stub_ . get ( ) , 10 ) ) ; <nl> + threads . push_back ( new std : : thread ( SendRpc , stub_ . get ( ) , 10 , false ) ) ; <nl> } <nl> for ( int i = 0 ; i < 10 ; + + i ) { <nl> threads [ i ] - > join ( ) ; <nl>
Merge pull request from yang - g / binary_metadata_crash
grpc/grpc
9070b4be0c9547daa22c3d6e73d5889854ad60a4
2016-02-01T15:02:24Z
mmm a / android / sdk / src / main / java / com / taobao / weex / ui / component / WXSlider . java <nl> ppp b / android / sdk / src / main / java / com / taobao / weex / ui / component / WXSlider . java <nl> <nl> public static final String INDEX = " index " ; <nl> public static final String SHOW_INDICATORS = " showIndicators " ; <nl> public static final String AUTO_PLAY = " autoPlay " ; <nl> + public static final String INTERVAL = " interval " ; <nl> Map < String , Object > params = new HashMap < > ( ) ; <nl> / * * <nl> * Scrollable sliderview <nl> public void onPageScrolled ( int arg0 , float arg1 , int arg2 ) { <nl> <nl> } <nl> <nl> + @ WXComponentProp ( name = INTERVAL ) <nl> + public void setInterval ( int intervalMS ) { <nl> + if ( mViewPager ! = null ) { <nl> + mViewPager . setIntervalTime ( intervalMS ) ; <nl> + } <nl> + } <nl> + <nl> @ WXComponentProp ( name = INDEX ) <nl> public void setIndex ( int index ) { <nl> if ( mViewPager ! = null ) { <nl>
* [ android ] add slider interval attribute
apache/incubator-weex
0ae39b7c78515b32df439f344f28d1ca110bda15
2016-07-18T13:01:59Z
mmm a / project / VS2010Express / XBMC . vcxproj <nl> ppp b / project / VS2010Express / XBMC . vcxproj <nl> <nl> < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controlcheckmark . cpp " > <nl> < AdditionalIncludeDirectories Condition = " ' $ ( Configuration ) | $ ( Platform ) ' = = ' Debug ( OpenGL ) | Win32 ' " > . . \ . . \ project \ BuildDependencies \ include \ python ; % ( AdditionalIncludeDirectories ) < / AdditionalIncludeDirectories > <nl> < / ClCompile > <nl> + < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controledit . cpp " > <nl> + < AdditionalIncludeDirectories Condition = " ' $ ( Configuration ) | $ ( Platform ) ' = = ' Debug ( OpenGL ) | Win32 ' " > . . \ . . \ project \ BuildDependencies \ include \ python ; % ( AdditionalIncludeDirectories ) < / AdditionalIncludeDirectories > <nl> + < / ClCompile > <nl> < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controlfadelabel . cpp " > <nl> < AdditionalIncludeDirectories Condition = " ' $ ( Configuration ) | $ ( Platform ) ' = = ' Debug ( OpenGL ) | Win32 ' " > . . \ . . \ project \ BuildDependencies \ include \ python ; % ( AdditionalIncludeDirectories ) < / AdditionalIncludeDirectories > <nl> < / ClCompile > <nl> mmm a / project / VS2010Express / XBMC . vcxproj . filters <nl> ppp b / project / VS2010Express / XBMC . vcxproj . filters <nl> <nl> < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controlcheckmark . cpp " > <nl> < Filter > interfaces \ python \ xbmcmodule < / Filter > <nl> < / ClCompile > <nl> + < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controledit . cpp " > <nl> + < Filter > interfaces \ python \ xbmcmodule < / Filter > <nl> + < / ClCompile > <nl> < ClCompile Include = " . . \ . . \ xbmc \ interfaces \ python \ xbmcmodule \ controlfadelabel . cpp " > <nl> < Filter > interfaces \ python \ xbmcmodule < / Filter > <nl> < / ClCompile > <nl> mmm a / xbmc / interfaces / python / xbmcmodule / Makefile . in <nl> ppp b / xbmc / interfaces / python / xbmcmodule / Makefile . in <nl> SRCS = action . cpp \ <nl> control . cpp \ <nl> controlbutton . cpp \ <nl> controlcheckmark . cpp \ <nl> + controledit . cpp \ <nl> controlfadelabel . cpp \ <nl> controlgroup . cpp \ <nl> controlimage . cpp \ <nl> mmm a / xbmc / interfaces / python / xbmcmodule / control . h <nl> ppp b / xbmc / interfaces / python / xbmcmodule / control . h <nl> class CGUIControl ; <nl> # define ControlSlider_Check ( op ) PyObject_TypeCheck ( op , & ControlSlider_Type ) <nl> # define ControlSlider_CheckExact ( op ) ( ( op ) - > ob_type = = & ControlSlider_Type ) <nl> <nl> + # define ControlEdit_Check ( op ) PyObject_TypeCheck ( op , & ControlEdit_Type ) <nl> + # define ControlEdit_CheckExact ( op ) ( ( op ) - > ob_type = = & ControlEdit_Type ) <nl> / / mmmmmmmmmmmmmmm - - <nl> <nl> / / hardcoded offsets for button controls ( and controls that use button controls ) <nl> namespace PYXBMC <nl> int iAngle ; <nl> } ControlLabel ; <nl> <nl> + typedef struct { <nl> + PyObject_HEAD_XBMC_CONTROL <nl> + std : : string strFont ; <nl> + std : : string strText ; <nl> + std : : string strTextureFocus ; <nl> + std : : string strTextureNoFocus ; <nl> + color_t textColor ; <nl> + color_t disabledColor ; <nl> + uint32_t align ; <nl> + bool bIsPassword ; <nl> + } ControlEdit ; <nl> <nl> typedef struct { <nl> PyObject_HEAD_XBMC_CONTROL <nl> namespace PYXBMC <nl> extern PyTypeObject ControlProgress_Type ; <nl> extern PyTypeObject ControlRadioButton_Type ; <nl> extern PyTypeObject ControlSlider_Type ; <nl> + extern PyTypeObject ControlEdit_Type ; <nl> <nl> CGUIControl * ControlLabel_Create ( ControlLabel * pControl ) ; <nl> CGUIControl * ControlFadeLabel_Create ( ControlFadeLabel * pControl ) ; <nl> namespace PYXBMC <nl> CGUIControl * ControlProgress_Create ( ControlProgress * pControl ) ; <nl> CGUIControl * ControlRadioButton_Create ( ControlRadioButton * pControl ) ; <nl> CGUIControl * ControlSlider_Create ( ControlSlider * pControl ) ; <nl> + CGUIControl * ControlEdit_Create ( ControlEdit * pControl ) ; <nl> <nl> void initControl_Type ( ) ; <nl> void initControlSpin_Type ( ) ; <nl> namespace PYXBMC <nl> void initControlProgress_Type ( ) ; <nl> void initControlRadioButton_Type ( ) ; <nl> void initControlSlider_Type ( ) ; <nl> + void initControlEdit_Type ( ) ; <nl> } <nl> <nl> # ifdef __cplusplus <nl> new file mode 100644 <nl> index 000000000000 . . b8a563eba3b1 <nl> mmm / dev / null <nl> ppp b / xbmc / interfaces / python / xbmcmodule / controledit . cpp <nl> <nl> + / * <nl> + * Copyright ( C ) 2005 - 2011 Team XBMC <nl> + * http : / / www . xbmc . org <nl> + * <nl> + * This Program is free software ; you can redistribute it and / or modify <nl> + * it under the terms of the GNU General Public License as published by <nl> + * the Free Software Foundation ; either version 2 , or ( at your option ) <nl> + * any later version . <nl> + * <nl> + * This Program is distributed in the hope that it will be useful , <nl> + * but WITHOUT ANY WARRANTY ; without even the implied warranty of <nl> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the <nl> + * GNU General Public License for more details . <nl> + * <nl> + * You should have received a copy of the GNU General Public License <nl> + * along with XBMC ; see the file COPYING . If not , write to <nl> + * the Free Software Foundation , 675 Mass Ave , Cambridge , MA 02139 , USA . <nl> + * http : / / www . gnu . org / copyleft / gpl . html <nl> + * <nl> + * / <nl> + <nl> + # include < Python . h > <nl> + <nl> + # include " guilib / GUIEditControl . h " <nl> + # include " guilib / GUIFontManager . h " <nl> + # include " guilib / GUIWindowManager . h " <nl> + # include " control . h " <nl> + # include " pyutil . h " <nl> + <nl> + using namespace std ; <nl> + <nl> + # ifndef __GNUC__ <nl> + # pragma code_seg ( " PY_TEXT " ) <nl> + # pragma data_seg ( " PY_DATA " ) <nl> + # pragma bss_seg ( " PY_BSS " ) <nl> + # pragma const_seg ( " PY_RDATA " ) <nl> + # endif <nl> + <nl> + # ifdef __cplusplus <nl> + extern " C " { <nl> + # endif <nl> + <nl> + namespace PYXBMC <nl> + { <nl> + PyObject * ControlEdit_New ( PyTypeObject * type , PyObject * args , PyObject * kwds ) <nl> + { <nl> + static const char * keywords [ ] = { <nl> + " x " , " y " , " width " , " height " , " label " , " font " , " textColor " , <nl> + " disabledColor " , " alignment " , " focusTexture " , " noFocusTexture " , " isPassword " , NULL } ; <nl> + <nl> + ControlEdit * self ; <nl> + char * cFont = NULL ; <nl> + char * cTextColor = NULL ; <nl> + char * cDisabledColor = NULL ; <nl> + PyObject * pObjectText ; <nl> + char * cTextureFocus = NULL ; <nl> + char * cTextureNoFocus = NULL ; <nl> + <nl> + self = ( ControlEdit * ) type - > tp_alloc ( type , 0 ) ; <nl> + if ( ! self ) return NULL ; <nl> + new ( & self - > strText ) string ( ) ; <nl> + new ( & self - > strFont ) string ( ) ; <nl> + new ( & self - > strTextureFocus ) string ( ) ; <nl> + new ( & self - > strTextureNoFocus ) string ( ) ; <nl> + <nl> + / / set up default values in case they are not supplied <nl> + self - > strFont = " font13 " ; <nl> + self - > textColor = 0xffffffff ; <nl> + self - > disabledColor = 0x60ffffff ; <nl> + self - > align = XBFONT_LEFT ; <nl> + <nl> + if ( ! PyArg_ParseTupleAndKeywords ( <nl> + args , <nl> + kwds , <nl> + ( char * ) " llllO | ssslssb " , <nl> + ( char * * ) keywords , <nl> + & self - > dwPosX , <nl> + & self - > dwPosY , <nl> + & self - > dwWidth , <nl> + & self - > dwHeight , <nl> + & pObjectText , <nl> + & cFont , <nl> + & cTextColor , <nl> + & cDisabledColor , <nl> + & self - > align , <nl> + & cTextureFocus , <nl> + & cTextureNoFocus , <nl> + & self - > bIsPassword ) ) <nl> + { <nl> + Py_DECREF ( self ) ; <nl> + return NULL ; <nl> + } <nl> + <nl> + if ( ! PyXBMCGetUnicodeString ( self - > strText , pObjectText , 5 ) ) <nl> + { <nl> + Py_DECREF ( self ) ; <nl> + return NULL ; <nl> + } <nl> + <nl> + self - > strTextureFocus = cTextureFocus ? <nl> + cTextureFocus : <nl> + PyXBMCGetDefaultImage ( ( char * ) " edit " , ( char * ) " texturefocus " , ( char * ) " button - focus . png " ) ; <nl> + self - > strTextureNoFocus = cTextureNoFocus ? <nl> + cTextureNoFocus : <nl> + PyXBMCGetDefaultImage ( ( char * ) " edit " , ( char * ) " texturenofocus " , ( char * ) " button - nofocus . jpg " ) ; <nl> + <nl> + <nl> + if ( cFont ) self - > strFont = cFont ; <nl> + if ( cTextColor ) sscanf ( cTextColor , " % x " , & self - > textColor ) ; <nl> + if ( cDisabledColor ) <nl> + { <nl> + sscanf ( cDisabledColor , " % x " , & self - > disabledColor ) ; <nl> + } <nl> + <nl> + return ( PyObject * ) self ; <nl> + } <nl> + <nl> + void ControlEdit_Dealloc ( ControlLabel * self ) <nl> + { <nl> + self - > strText . ~ string ( ) ; <nl> + self - > strFont . ~ string ( ) ; <nl> + self - > ob_type - > tp_free ( ( PyObject * ) self ) ; <nl> + } <nl> + <nl> + CGUIControl * ControlEdit_Create ( ControlEdit * pControl ) <nl> + { <nl> + CLabelInfo label ; <nl> + label . font = g_fontManager . GetFont ( pControl - > strFont ) ; <nl> + label . textColor = label . focusedColor = pControl - > textColor ; <nl> + label . disabledColor = pControl - > disabledColor ; <nl> + label . align = pControl - > align ; <nl> + <nl> + pControl - > pGUIControl = new CGUIEditControl ( <nl> + pControl - > iParentId , <nl> + pControl - > iControlId , <nl> + ( float ) pControl - > dwPosX , <nl> + ( float ) pControl - > dwPosY , <nl> + ( float ) pControl - > dwWidth , <nl> + ( float ) pControl - > dwHeight , <nl> + ( CStdString ) pControl - > strTextureFocus , <nl> + ( CStdString ) pControl - > strTextureNoFocus , <nl> + label , <nl> + pControl - > strText ) ; <nl> + if ( pControl - > bIsPassword ) <nl> + ( ( CGUIEditControl * ) pControl - > pGUIControl ) - > SetInputType ( CGUIEditControl : : INPUT_TYPE_PASSWORD , 0 ) ; <nl> + return pControl - > pGUIControl ; <nl> + } <nl> + <nl> + / / setLabel ( ) Method <nl> + PyDoc_STRVAR ( setLabel__doc__ , <nl> + " setLabel ( label ) - - Set ' s text heading for this edit control . \ n " <nl> + " \ n " <nl> + " label : string or unicode - text string . \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - self . edit . setLabel ( ' Status ' ) \ n " ) ; <nl> + <nl> + PyObject * ControlEdit_SetLabel ( ControlLabel * self , PyObject * args ) <nl> + { <nl> + PyObject * pObjectText ; <nl> + <nl> + if ( ! PyArg_ParseTuple ( args , ( char * ) " O " , & pObjectText ) ) return NULL ; <nl> + if ( ! PyXBMCGetUnicodeString ( self - > strText , pObjectText , 1 ) ) return NULL ; <nl> + <nl> + ControlLabel * pControl = ( ControlLabel * ) self ; <nl> + CGUIMessage msg ( GUI_MSG_LABEL_SET , pControl - > iParentId , pControl - > iControlId ) ; <nl> + msg . SetLabel ( self - > strText ) ; <nl> + g_windowManager . SendThreadMessage ( msg , pControl - > iParentId ) ; <nl> + <nl> + Py_INCREF ( Py_None ) ; <nl> + return Py_None ; <nl> + } <nl> + <nl> + / / getLabel ( ) Method <nl> + PyDoc_STRVAR ( getLabel__doc__ , <nl> + " getLabel ( ) - - Returns the text heading for this edit control . \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - label = self . edit . getLabel ( ) \ n " ) ; <nl> + <nl> + PyObject * ControlEdit_GetLabel ( ControlLabel * self , PyObject * args ) <nl> + { <nl> + if ( ! self - > pGUIControl ) return NULL ; <nl> + return Py_BuildValue ( ( char * ) " s " , self - > strText . c_str ( ) ) ; <nl> + } <nl> + <nl> + / / setLabel ( ) Method <nl> + PyDoc_STRVAR ( setText__doc__ , <nl> + " setText ( value ) - - Set ' s text value for this edit control . \ n " <nl> + " \ n " <nl> + " value : string or unicode - text string . \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - self . edit . setValue ( ' online ' ) \ n " ) ; <nl> + <nl> + PyObject * ControlEdit_SetText ( ControlLabel * self , PyObject * args ) <nl> + { <nl> + PyObject * pObjectText ; <nl> + std : : string strValue ; <nl> + if ( ! PyArg_ParseTuple ( args , ( char * ) " O " , & pObjectText ) ) return NULL ; <nl> + if ( ! PyXBMCGetUnicodeString ( strValue , pObjectText , 1 ) ) return NULL ; <nl> + <nl> + ControlLabel * pControl = ( ControlLabel * ) self ; <nl> + CGUIMessage msg ( GUI_MSG_LABEL2_SET , pControl - > iParentId , pControl - > iControlId ) ; <nl> + msg . SetLabel ( strValue ) ; <nl> + g_windowManager . SendThreadMessage ( msg , pControl - > iParentId ) ; <nl> + <nl> + Py_INCREF ( Py_None ) ; <nl> + return Py_None ; <nl> + } <nl> + <nl> + / / getText ( ) Method <nl> + PyDoc_STRVAR ( getText__doc__ , <nl> + " getText ( ) - - Returns the text value for this edit control . \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - value = self . edit . getText ( ) \ n " ) ; <nl> + <nl> + PyObject * ControlEdit_GetText ( ControlLabel * self , PyObject * args ) <nl> + { <nl> + if ( ! self - > pGUIControl ) return NULL ; <nl> + <nl> + ControlLabel * pControl = ( ControlLabel * ) self ; <nl> + CGUIMessage msg ( GUI_MSG_ITEM_SELECTED , pControl - > iParentId , pControl - > iControlId ) ; <nl> + g_windowManager . SendMessage ( msg , pControl - > iParentId ) ; <nl> + <nl> + return Py_BuildValue ( ( char * ) " s " , msg . GetLabel ( ) . c_str ( ) ) ; <nl> + } <nl> + <nl> + PyMethodDef ControlEdit_methods [ ] = { <nl> + { ( char * ) " setLabel " , ( PyCFunction ) ControlEdit_SetLabel , METH_VARARGS , setLabel__doc__ } , <nl> + { ( char * ) " getLabel " , ( PyCFunction ) ControlEdit_GetLabel , METH_VARARGS , getLabel__doc__ } , <nl> + { ( char * ) " setText " , ( PyCFunction ) ControlEdit_SetText , METH_VARARGS , setText__doc__ } , <nl> + { ( char * ) " getText " , ( PyCFunction ) ControlEdit_GetText , METH_VARARGS , getText__doc__ } , <nl> + { NULL , NULL , 0 , NULL } <nl> + } ; <nl> + <nl> + / / ControlEdit class <nl> + PyDoc_STRVAR ( controlEdit__doc__ , <nl> + " ControlEdit class . \ n " <nl> + " \ n " <nl> + " ControlEdit ( x , y , width , height , label [ , font , textColor , \ n " <nl> + " disabledColor , alignment , focusTexture , noFocusTexture ] ) \ n " <nl> + " \ n " <nl> + " x : integer - x coordinate of control . \ n " <nl> + " y : integer - y coordinate of control . \ n " <nl> + " width : integer - width of control . \ n " <nl> + " height : integer - height of control . \ n " <nl> + " label : string or unicode - text string . \ n " <nl> + " font : [ opt ] string - font used for label text . ( e . g . ' font13 ' ) \ n " <nl> + " textColor : [ opt ] hexstring - color of enabled label ' s label . ( e . g . ' 0xFFFFFFFF ' ) \ n " <nl> + " disabledColor : [ opt ] hexstring - color of disabled label ' s label . ( e . g . ' 0xFFFF3300 ' ) \ n " <nl> + " alignment : [ opt ] integer - alignment of label - * Note , see xbfont . h \ n " <nl> + " focusTexture : [ opt ] string - filename for focus texture . \ n " <nl> + " noFocusTexture : [ opt ] string - filename for no focus texture . \ n " <nl> + " isPassword : [ opt ] bool - if true , mask text value . \ n " <nl> + " \ n " <nl> + " * Note , You can use the above as keywords for arguments and skip certain optional arguments . \ n " <nl> + " Once you use a keyword , all following arguments require the keyword . \ n " <nl> + " After you create the control , you need to add it to the window with addControl ( ) . \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - self . edit = xbmcgui . ControlEdit ( 100 , 250 , 125 , 75 , ' Status ' ) \ n " ) ; <nl> + <nl> + / / Restore code and data sections to normal . <nl> + # ifndef __GNUC__ <nl> + # pragma code_seg ( ) <nl> + # pragma data_seg ( ) <nl> + # pragma bss_seg ( ) <nl> + # pragma const_seg ( ) <nl> + # endif <nl> + <nl> + PyTypeObject ControlEdit_Type ; <nl> + <nl> + void initControlEdit_Type ( ) <nl> + { <nl> + PyXBMCInitializeTypeObject ( & ControlEdit_Type ) ; <nl> + <nl> + ControlEdit_Type . tp_name = ( char * ) " xbmcgui . ControlEdit " ; <nl> + ControlEdit_Type . tp_basicsize = sizeof ( ControlEdit ) ; <nl> + ControlEdit_Type . tp_dealloc = ( destructor ) ControlEdit_Dealloc ; <nl> + ControlEdit_Type . tp_compare = 0 ; <nl> + ControlEdit_Type . tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ; <nl> + ControlEdit_Type . tp_doc = controlEdit__doc__ ; <nl> + ControlEdit_Type . tp_methods = ControlEdit_methods ; <nl> + ControlEdit_Type . tp_base = & Control_Type ; <nl> + ControlEdit_Type . tp_new = ControlEdit_New ; <nl> + } <nl> + } <nl> + <nl> + # ifdef __cplusplus <nl> + } <nl> + # endif <nl> mmm a / xbmc / interfaces / python / xbmcmodule / window . cpp <nl> ppp b / xbmc / interfaces / python / xbmcmodule / window . cpp <nl> <nl> # include " guilib / GUIButtonControl . h " <nl> # include " guilib / GUICheckMarkControl . h " <nl> # include " guilib / GUIRadioButtonControl . h " <nl> + # include " guilib / GUIEditControl . h " <nl> # include " guilib / GUIWindowManager . h " <nl> # include " settings / Settings . h " <nl> # include " Application . h " <nl> namespace PYXBMC <nl> if ( li . font ) ( ( ControlRadioButton * ) pControl ) - > strFont = li . font - > GetFontName ( ) ; <nl> ( ( ControlRadioButton * ) pControl ) - > align = li . align ; <nl> break ; <nl> + case CGUIControl : : GUICONTROL_EDIT : <nl> + pControl = ( Control * ) ControlEdit_Type . tp_alloc ( & ControlEdit_Type , 0 ) ; <nl> + new ( & ( ( ControlEdit * ) pControl ) - > strFont ) string ( ) ; <nl> + new ( & ( ( ControlEdit * ) pControl ) - > strText ) string ( ) ; <nl> + new ( & ( ( ControlEdit * ) pControl ) - > strTextureFocus ) string ( ) ; <nl> + new ( & ( ( ControlEdit * ) pControl ) - > strTextureNoFocus ) string ( ) ; <nl> + <nl> + li = ( ( CGUIEditControl * ) pGUIControl ) - > GetLabelInfo ( ) ; <nl> + <nl> + / / note : conversion from infocolors - > plain colors here <nl> + ( ( ControlEdit * ) pControl ) - > disabledColor = li . disabledColor ; <nl> + ( ( ControlEdit * ) pControl ) - > textColor = li . textColor ; <nl> + if ( li . font ) ( ( ControlEdit * ) pControl ) - > strFont = li . font - > GetFontName ( ) ; <nl> + ( ( ControlButton * ) pControl ) - > align = li . align ; <nl> + break ; <nl> default : <nl> break ; <nl> } <nl> namespace PYXBMC <nl> else if ( ControlRadioButton_Check ( pControl ) ) <nl> ControlRadioButton_Create ( ( ControlRadioButton * ) pControl ) ; <nl> <nl> + else if ( ControlEdit_Check ( pControl ) ) <nl> + ControlEdit_Create ( ( ControlEdit * ) pControl ) ; <nl> / / unknown control type to add , should not happen <nl> else <nl> { <nl> mmm a / xbmc / interfaces / python / xbmcmodule / xbmcguimodule . cpp <nl> ppp b / xbmc / interfaces / python / xbmcmodule / xbmcguimodule . cpp <nl> namespace PYXBMC <nl> initDialogProgress_Type ( ) ; <nl> initAction_Type ( ) ; <nl> initControlRadioButton_Type ( ) ; <nl> + initControlEdit_Type ( ) ; <nl> <nl> if ( PyType_Ready ( & Window_Type ) < 0 | | <nl> PyType_Ready ( & WindowDialog_Type ) < 0 | | <nl> namespace PYXBMC <nl> PyType_Ready ( & DialogProgress_Type ) < 0 | | <nl> PyType_Ready ( & ControlSlider_Type ) < 0 | | <nl> PyType_Ready ( & ControlRadioButton_Type ) < 0 | | <nl> + PyType_Ready ( & ControlEdit_Type ) < 0 | | <nl> PyType_Ready ( & Action_Type ) < 0 ) <nl> return ; <nl> <nl> namespace PYXBMC <nl> Py_INCREF ( & DialogProgress_Type ) ; <nl> Py_INCREF ( & Action_Type ) ; <nl> Py_INCREF ( & ControlRadioButton_Type ) ; <nl> + Py_INCREF ( & ControlEdit_Type ) ; <nl> <nl> pXbmcGuiModule = Py_InitModule3 ( ( char * ) " xbmcgui " , xbmcGuiMethods , xbmcgui_module_documentation ) ; <nl> <nl> namespace PYXBMC <nl> PyModule_AddObject ( pXbmcGuiModule , ( char * ) " DialogProgress " , ( PyObject * ) & DialogProgress_Type ) ; <nl> PyModule_AddObject ( pXbmcGuiModule , ( char * ) " Action " , ( PyObject * ) & Action_Type ) ; <nl> PyModule_AddObject ( pXbmcGuiModule , ( char * ) " ControlRadioButton " , ( PyObject * ) & ControlRadioButton_Type ) ; <nl> + PyModule_AddObject ( pXbmcGuiModule , ( char * ) " ControlEdit " , ( PyObject * ) & ControlEdit_Type ) ; <nl> <nl> PyModule_AddStringConstant ( pXbmcGuiModule , ( char * ) " __author__ " , ( char * ) PY_XBMC_AUTHOR ) ; <nl> PyModule_AddStringConstant ( pXbmcGuiModule , ( char * ) " __date__ " , ( char * ) " 14 July 2006 " ) ; <nl>
Merge pull request from pieh / python_editControl
xbmc/xbmc
78afc2272a54cffb690c32a0c531acb8e6e9a377
2011-06-27T15:48:31Z
mmm a / patches / node / build_add_gn_build_files . patch <nl> ppp b / patches / node / build_add_gn_build_files . patch <nl> index 0000000000000000000000000000000000000000 . . f13b471d17128468bed06e66bd03a2ea <nl> + } <nl> new file mode 100644 <nl> - index 0000000000000000000000000000000000000000 . . 78dff9e0458aaa6b864259f3001764c77b977e36 <nl> + index 0000000000000000000000000000000000000000 . . 6cfb94ab4a9f8ec62cd37efc616bac4fd1fb42f5 <nl> mmm / dev / null <nl> ppp b / filenames . json <nl> - <nl> + <nl> + / / This file is automatically generated by generate_gn_filenames_json . py <nl> + / / DO NOT EDIT <nl> + { <nl> index 0000000000000000000000000000000000000000 . . 78dff9e0458aaa6b864259f3001764c7 <nl> + { <nl> + " dest_dir " : " include / node / / cppgc / " , <nl> + " files " : [ <nl> - + " / / v8 / include / cppgc / finalizer - trait . h " <nl> + + " / / v8 / include / cppgc / allocation . h " , <nl> + + " / / v8 / include / cppgc / garbage - collected . h " , <nl> + + " / / v8 / include / cppgc / heap . h " , <nl> + + " / / v8 / include / cppgc / member . h " , <nl> + + " / / v8 / include / cppgc / platform . h " , <nl> + + " / / v8 / include / cppgc / source - location . h " , <nl> + + " / / v8 / include / cppgc / trace - trait . h " , <nl> + + " / / v8 / include / cppgc / type - traits . h " , <nl> + + " / / v8 / include / cppgc / visitor . h " <nl> + + ] <nl> + + } , <nl> + + { <nl> + + " dest_dir " : " include / node / / cppgc / internal / " , <nl> + + " files " : [ <nl> + + " / / v8 / include / cppgc / internal / accessors . h " , <nl> + + " / / v8 / include / cppgc / internal / api - constants . h " , <nl> + + " / / v8 / include / cppgc / internal / finalizer - trait . h " , <nl> + + " / / v8 / include / cppgc / internal / gc - info . h " , <nl> + + " / / v8 / include / cppgc / internal / pointer - policies . h " <nl> + ] <nl> + } , <nl> + { <nl>
ci : fix v8 cppgc file in wrong location ( )
electron/electron
f395775eb10957ab9b03a0c0e466457f0adececf
2020-04-14T21:27:11Z
mmm a / tests / runner . py <nl> ppp b / tests / runner . py <nl> def ll_to_js ( self , filename , extra_emscripten_args , post_build ) : <nl> transform = open ( transform_filename , ' w ' ) <nl> transform . write ( ' ' ' <nl> import sys <nl> - ' ' ' ) <nl> + sys . path + = [ ' % s ' ] <nl> + ' ' ' % path_from_root ( ' ' ) ) <nl> transform . write ( post_build ) <nl> transform . write ( ' ' ' <nl> process ( sys . argv [ 1 ] ) <nl>
fix tests that have js transforms that rely on being able to import from the emscripten dir
emscripten-core/emscripten
e1375560afb1768b26725ffb86d6b03457411e28
2012-01-04T23:15:49Z
mmm a / Makefile <nl> ppp b / Makefile <nl> slice_transform_test : util / slice_transform_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> <nl> - db_test : db / db_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> + db_test : db / db_test . o util / db_test_util . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> $ ( AM_LINK ) <nl> <nl> db_iter_test : db / db_iter_test . o $ ( LIBOBJECTS ) $ ( TESTHARNESS ) <nl> mmm a / db / db_test . cc <nl> ppp b / db / db_test . cc <nl> <nl> # include " table / block_based_table_factory . h " <nl> # include " table / mock_table . h " <nl> # include " table / plain_table_factory . h " <nl> + # include " util / db_test_util . h " <nl> # include " util / hash . h " <nl> # include " util / hash_linklist_rep . h " <nl> # include " utilities / merge_operators . h " <nl> <nl> <nl> namespace rocksdb { <nl> <nl> - static std : : string RandomString ( Random * rnd , int len ) { <nl> - std : : string r ; <nl> - test : : RandomString ( rnd , len , & r ) ; <nl> - return r ; <nl> - } <nl> - <nl> - namespace anon { <nl> - class AtomicCounter { <nl> - private : <nl> - Env * env_ ; <nl> - port : : Mutex mu_ ; <nl> - port : : CondVar cond_count_ ; <nl> - int count_ ; <nl> - public : <nl> - AtomicCounter ( Env * env = NULL ) : env_ ( env ) , cond_count_ ( & mu_ ) , count_ ( 0 ) { } <nl> - void Increment ( ) { <nl> - MutexLock l ( & mu_ ) ; <nl> - count_ + + ; <nl> - cond_count_ . SignalAll ( ) ; <nl> - } <nl> - int Read ( ) { <nl> - MutexLock l ( & mu_ ) ; <nl> - return count_ ; <nl> - } <nl> - bool WaitFor ( int count ) { <nl> - MutexLock l ( & mu_ ) ; <nl> - <nl> - uint64_t start = env_ - > NowMicros ( ) ; <nl> - while ( count_ < count ) { <nl> - uint64_t now = env_ - > NowMicros ( ) ; <nl> - const uint64_t elapsed_micros = ( now > start ) ? now - start : 0 ; <nl> - if ( elapsed_micros > / * 10s * / 10 * 000 * 000 ) { <nl> - return false ; <nl> - } <nl> - cond_count_ . TimedWait ( now + / * 1s * / 1 * 000 * 000 ) ; <nl> - if ( count_ < count ) { <nl> - GTEST_LOG_ ( WARNING ) < < " WaitFor is taking more time than usual " ; <nl> - } <nl> - } <nl> - <nl> - return true ; <nl> - } <nl> - void Reset ( ) { <nl> - MutexLock l ( & mu_ ) ; <nl> - count_ = 0 ; <nl> - cond_count_ . SignalAll ( ) ; <nl> - } <nl> - } ; <nl> - <nl> - struct OptionsOverride { <nl> - std : : shared_ptr < const FilterPolicy > filter_policy = nullptr ; <nl> - <nl> - / / Used as a bit mask of individual enums in which to skip an XF test point <nl> - int skip_policy = 0 ; <nl> - } ; <nl> - <nl> - } / / namespace anon <nl> - <nl> - static std : : string Key ( int i ) { <nl> - char buf [ 100 ] ; <nl> - snprintf ( buf , sizeof ( buf ) , " key % 06d " , i ) ; <nl> - return std : : string ( buf ) ; <nl> - } <nl> - <nl> - / / Special Env used to delay background operations <nl> - class SpecialEnv : public EnvWrapper { <nl> - public : <nl> - Random rnd_ ; <nl> - port : : Mutex rnd_mutex_ ; / / Lock to pretect rnd_ <nl> - <nl> - / / sstable Sync ( ) calls are blocked while this pointer is non - nullptr . <nl> - std : : atomic < bool > delay_sstable_sync_ ; <nl> - <nl> - / / Drop writes on the floor while this pointer is non - nullptr . <nl> - std : : atomic < bool > drop_writes_ ; <nl> - <nl> - / / Simulate no - space errors while this pointer is non - nullptr . <nl> - std : : atomic < bool > no_space_ ; <nl> - <nl> - / / Simulate non - writable file system while this pointer is non - nullptr <nl> - std : : atomic < bool > non_writable_ ; <nl> - <nl> - / / Force sync of manifest files to fail while this pointer is non - nullptr <nl> - std : : atomic < bool > manifest_sync_error_ ; <nl> - <nl> - / / Force write to manifest files to fail while this pointer is non - nullptr <nl> - std : : atomic < bool > manifest_write_error_ ; <nl> - <nl> - / / Force write to log files to fail while this pointer is non - nullptr <nl> - std : : atomic < bool > log_write_error_ ; <nl> - <nl> - / / Slow down every log write , in micro - seconds . <nl> - std : : atomic < int > log_write_slowdown_ ; <nl> - <nl> - bool count_random_reads_ ; <nl> - anon : : AtomicCounter random_read_counter_ ; <nl> - <nl> - bool count_sequential_reads_ ; <nl> - anon : : AtomicCounter sequential_read_counter_ ; <nl> - <nl> - anon : : AtomicCounter sleep_counter_ ; <nl> - <nl> - std : : atomic < int64_t > bytes_written_ ; <nl> - <nl> - std : : atomic < int > sync_counter_ ; <nl> - <nl> - std : : atomic < uint32_t > non_writeable_rate_ ; <nl> - <nl> - std : : atomic < uint32_t > new_writable_count_ ; <nl> - <nl> - std : : atomic < uint32_t > non_writable_count_ ; <nl> - <nl> - std : : function < void ( ) > * table_write_callback_ ; <nl> - <nl> - std : : atomic < int64_t > addon_time_ ; <nl> - bool no_sleep_ ; <nl> - <nl> - explicit SpecialEnv ( Env * base ) <nl> - : EnvWrapper ( base ) , <nl> - rnd_ ( 301 ) , <nl> - sleep_counter_ ( this ) , <nl> - addon_time_ ( 0 ) , <nl> - no_sleep_ ( false ) { <nl> - delay_sstable_sync_ . store ( false , std : : memory_order_release ) ; <nl> - drop_writes_ . store ( false , std : : memory_order_release ) ; <nl> - no_space_ . store ( false , std : : memory_order_release ) ; <nl> - non_writable_ . store ( false , std : : memory_order_release ) ; <nl> - count_random_reads_ = false ; <nl> - count_sequential_reads_ = false ; <nl> - manifest_sync_error_ . store ( false , std : : memory_order_release ) ; <nl> - manifest_write_error_ . store ( false , std : : memory_order_release ) ; <nl> - log_write_error_ . store ( false , std : : memory_order_release ) ; <nl> - log_write_slowdown_ = 0 ; <nl> - bytes_written_ = 0 ; <nl> - sync_counter_ = 0 ; <nl> - non_writeable_rate_ = 0 ; <nl> - new_writable_count_ = 0 ; <nl> - non_writable_count_ = 0 ; <nl> - table_write_callback_ = nullptr ; <nl> - } <nl> - <nl> - Status NewWritableFile ( const std : : string & f , unique_ptr < WritableFile > * r , <nl> - const EnvOptions & soptions ) override { <nl> - class SSTableFile : public WritableFile { <nl> - private : <nl> - SpecialEnv * env_ ; <nl> - unique_ptr < WritableFile > base_ ; <nl> - <nl> - public : <nl> - SSTableFile ( SpecialEnv * env , unique_ptr < WritableFile > & & base ) <nl> - : env_ ( env ) , <nl> - base_ ( std : : move ( base ) ) { <nl> - } <nl> - Status Append ( const Slice & data ) override { <nl> - if ( env_ - > table_write_callback_ ) { <nl> - ( * env_ - > table_write_callback_ ) ( ) ; <nl> - } <nl> - if ( env_ - > drop_writes_ . load ( std : : memory_order_acquire ) ) { <nl> - / / Drop writes on the floor <nl> - return Status : : OK ( ) ; <nl> - } else if ( env_ - > no_space_ . load ( std : : memory_order_acquire ) ) { <nl> - return Status : : IOError ( " No space left on device " ) ; <nl> - } else { <nl> - env_ - > bytes_written_ + = data . size ( ) ; <nl> - return base_ - > Append ( data ) ; <nl> - } <nl> - } <nl> - Status Close ( ) override { <nl> - / / Check preallocation size <nl> - / / preallocation size is never passed to base file . <nl> - size_t preallocation_size = preallocation_block_size ( ) ; <nl> - TEST_SYNC_POINT_CALLBACK ( " DBTestWritableFile . GetPreallocationStatus " , <nl> - & preallocation_size ) ; <nl> - return base_ - > Close ( ) ; <nl> - } <nl> - Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> - Status Sync ( ) override { <nl> - + + env_ - > sync_counter_ ; <nl> - while ( env_ - > delay_sstable_sync_ . load ( std : : memory_order_acquire ) ) { <nl> - env_ - > SleepForMicroseconds ( 100000 ) ; <nl> - } <nl> - return base_ - > Sync ( ) ; <nl> - } <nl> - void SetIOPriority ( Env : : IOPriority pri ) override { <nl> - base_ - > SetIOPriority ( pri ) ; <nl> - } <nl> - } ; <nl> - class ManifestFile : public WritableFile { <nl> - private : <nl> - SpecialEnv * env_ ; <nl> - unique_ptr < WritableFile > base_ ; <nl> - public : <nl> - ManifestFile ( SpecialEnv * env , unique_ptr < WritableFile > & & b ) <nl> - : env_ ( env ) , base_ ( std : : move ( b ) ) { } <nl> - Status Append ( const Slice & data ) override { <nl> - if ( env_ - > manifest_write_error_ . load ( std : : memory_order_acquire ) ) { <nl> - return Status : : IOError ( " simulated writer error " ) ; <nl> - } else { <nl> - return base_ - > Append ( data ) ; <nl> - } <nl> - } <nl> - Status Close ( ) override { return base_ - > Close ( ) ; } <nl> - Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> - Status Sync ( ) override { <nl> - + + env_ - > sync_counter_ ; <nl> - if ( env_ - > manifest_sync_error_ . load ( std : : memory_order_acquire ) ) { <nl> - return Status : : IOError ( " simulated sync error " ) ; <nl> - } else { <nl> - return base_ - > Sync ( ) ; <nl> - } <nl> - } <nl> - uint64_t GetFileSize ( ) override { return base_ - > GetFileSize ( ) ; } <nl> - } ; <nl> - class WalFile : public WritableFile { <nl> - private : <nl> - SpecialEnv * env_ ; <nl> - unique_ptr < WritableFile > base_ ; <nl> - public : <nl> - WalFile ( SpecialEnv * env , unique_ptr < WritableFile > & & b ) <nl> - : env_ ( env ) , base_ ( std : : move ( b ) ) { } <nl> - Status Append ( const Slice & data ) override { <nl> - if ( env_ - > log_write_error_ . load ( std : : memory_order_acquire ) ) { <nl> - return Status : : IOError ( " simulated writer error " ) ; <nl> - } else { <nl> - int slowdown = <nl> - env_ - > log_write_slowdown_ . load ( std : : memory_order_acquire ) ; <nl> - if ( slowdown > 0 ) { <nl> - env_ - > SleepForMicroseconds ( slowdown ) ; <nl> - } <nl> - return base_ - > Append ( data ) ; <nl> - } <nl> - } <nl> - Status Close ( ) override { return base_ - > Close ( ) ; } <nl> - Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> - Status Sync ( ) override { <nl> - + + env_ - > sync_counter_ ; <nl> - return base_ - > Sync ( ) ; <nl> - } <nl> - } ; <nl> - <nl> - if ( non_writeable_rate_ . load ( std : : memory_order_acquire ) > 0 ) { <nl> - uint32_t random_number ; <nl> - { <nl> - MutexLock l ( & rnd_mutex_ ) ; <nl> - random_number = rnd_ . Uniform ( 100 ) ; <nl> - } <nl> - if ( random_number < non_writeable_rate_ . load ( ) ) { <nl> - return Status : : IOError ( " simulated random write error " ) ; <nl> - } <nl> - } <nl> - <nl> - new_writable_count_ + + ; <nl> - <nl> - if ( non_writable_count_ . load ( ) > 0 ) { <nl> - non_writable_count_ - - ; <nl> - return Status : : IOError ( " simulated write error " ) ; <nl> - } <nl> - <nl> - Status s = target ( ) - > NewWritableFile ( f , r , soptions ) ; <nl> - if ( s . ok ( ) ) { <nl> - if ( strstr ( f . c_str ( ) , " . sst " ) ! = nullptr ) { <nl> - r - > reset ( new SSTableFile ( this , std : : move ( * r ) ) ) ; <nl> - } else if ( strstr ( f . c_str ( ) , " MANIFEST " ) ! = nullptr ) { <nl> - r - > reset ( new ManifestFile ( this , std : : move ( * r ) ) ) ; <nl> - } else if ( strstr ( f . c_str ( ) , " log " ) ! = nullptr ) { <nl> - r - > reset ( new WalFile ( this , std : : move ( * r ) ) ) ; <nl> - } <nl> - } <nl> - return s ; <nl> - } <nl> - <nl> - Status NewRandomAccessFile ( const std : : string & f , <nl> - unique_ptr < RandomAccessFile > * r , <nl> - const EnvOptions & soptions ) override { <nl> - class CountingFile : public RandomAccessFile { <nl> - private : <nl> - unique_ptr < RandomAccessFile > target_ ; <nl> - anon : : AtomicCounter * counter_ ; <nl> - public : <nl> - CountingFile ( unique_ptr < RandomAccessFile > & & target , <nl> - anon : : AtomicCounter * counter ) <nl> - : target_ ( std : : move ( target ) ) , counter_ ( counter ) { <nl> - } <nl> - virtual Status Read ( uint64_t offset , size_t n , Slice * result , <nl> - char * scratch ) const override { <nl> - counter_ - > Increment ( ) ; <nl> - return target_ - > Read ( offset , n , result , scratch ) ; <nl> - } <nl> - } ; <nl> - <nl> - Status s = target ( ) - > NewRandomAccessFile ( f , r , soptions ) ; <nl> - if ( s . ok ( ) & & count_random_reads_ ) { <nl> - r - > reset ( new CountingFile ( std : : move ( * r ) , & random_read_counter_ ) ) ; <nl> - } <nl> - return s ; <nl> - } <nl> - <nl> - Status NewSequentialFile ( const std : : string & f , unique_ptr < SequentialFile > * r , <nl> - const EnvOptions & soptions ) override { <nl> - class CountingFile : public SequentialFile { <nl> - private : <nl> - unique_ptr < SequentialFile > target_ ; <nl> - anon : : AtomicCounter * counter_ ; <nl> - <nl> - public : <nl> - CountingFile ( unique_ptr < SequentialFile > & & target , <nl> - anon : : AtomicCounter * counter ) <nl> - : target_ ( std : : move ( target ) ) , counter_ ( counter ) { } <nl> - virtual Status Read ( size_t n , Slice * result , char * scratch ) override { <nl> - counter_ - > Increment ( ) ; <nl> - return target_ - > Read ( n , result , scratch ) ; <nl> - } <nl> - virtual Status Skip ( uint64_t n ) override { return target_ - > Skip ( n ) ; } <nl> - } ; <nl> - <nl> - Status s = target ( ) - > NewSequentialFile ( f , r , soptions ) ; <nl> - if ( s . ok ( ) & & count_sequential_reads_ ) { <nl> - r - > reset ( new CountingFile ( std : : move ( * r ) , & sequential_read_counter_ ) ) ; <nl> - } <nl> - return s ; <nl> - } <nl> - <nl> - virtual void SleepForMicroseconds ( int micros ) override { <nl> - sleep_counter_ . Increment ( ) ; <nl> - if ( no_sleep_ ) { <nl> - addon_time_ . fetch_add ( micros ) ; <nl> - } else { <nl> - target ( ) - > SleepForMicroseconds ( micros ) ; <nl> - } <nl> - } <nl> - <nl> - virtual Status GetCurrentTime ( int64_t * unix_time ) override { <nl> - Status s = target ( ) - > GetCurrentTime ( unix_time ) ; <nl> - if ( s . ok ( ) ) { <nl> - * unix_time + = addon_time_ . load ( ) ; <nl> - } <nl> - return s ; <nl> - } <nl> - <nl> - virtual uint64_t NowNanos ( ) override { <nl> - return target ( ) - > NowNanos ( ) + addon_time_ . load ( ) * 1000 ; <nl> - } <nl> - <nl> - virtual uint64_t NowMicros ( ) override { <nl> - return target ( ) - > NowMicros ( ) + addon_time_ . load ( ) ; <nl> - } <nl> - } ; <nl> - <nl> - class DBTest : public testing : : Test { <nl> - protected : <nl> - / / Sequence of option configurations to try <nl> - enum OptionConfig { <nl> - kDefault = 0 , <nl> - kBlockBasedTableWithPrefixHashIndex = 1 , <nl> - kBlockBasedTableWithWholeKeyHashIndex = 2 , <nl> - kPlainTableFirstBytePrefix = 3 , <nl> - kPlainTableCappedPrefix = 4 , <nl> - kPlainTableAllBytesPrefix = 5 , <nl> - kVectorRep = 6 , <nl> - kHashLinkList = 7 , <nl> - kHashCuckoo = 8 , <nl> - kMergePut = 9 , <nl> - kFilter = 10 , <nl> - kFullFilter = 11 , <nl> - kUncompressed = 12 , <nl> - kNumLevel_3 = 13 , <nl> - kDBLogDir = 14 , <nl> - kWalDirAndMmapReads = 15 , <nl> - kManifestFileSize = 16 , <nl> - kCompactOnFlush = 17 , <nl> - kPerfOptions = 18 , <nl> - kDeletesFilterFirst = 19 , <nl> - kHashSkipList = 20 , <nl> - kUniversalCompaction = 21 , <nl> - kUniversalCompactionMultiLevel = 22 , <nl> - kCompressedBlockCache = 23 , <nl> - kInfiniteMaxOpenFiles = 24 , <nl> - kxxHashChecksum = 25 , <nl> - kFIFOCompaction = 26 , <nl> - kOptimizeFiltersForHits = 27 , <nl> - kRowCache = 28 , <nl> - kEnd = 29 <nl> - } ; <nl> - int option_config_ ; <nl> - <nl> - public : <nl> - std : : string dbname_ ; <nl> - std : : string alternative_wal_dir_ ; <nl> - MockEnv * mem_env_ ; <nl> - SpecialEnv * env_ ; <nl> - DB * db_ ; <nl> - std : : vector < ColumnFamilyHandle * > handles_ ; <nl> - <nl> - Options last_options_ ; <nl> - <nl> - / / Skip some options , as they may not be applicable to a specific test . <nl> - / / To add more skip constants , use values 4 , 8 , 16 , etc . <nl> - enum OptionSkip { <nl> - kNoSkip = 0 , <nl> - kSkipDeletesFilterFirst = 1 , <nl> - kSkipUniversalCompaction = 2 , <nl> - kSkipMergePut = 4 , <nl> - kSkipPlainTable = 8 , <nl> - kSkipHashIndex = 16 , <nl> - kSkipNoSeekToLast = 32 , <nl> - kSkipHashCuckoo = 64 , <nl> - kSkipFIFOCompaction = 128 , <nl> - kSkipMmapReads = 256 , <nl> - } ; <nl> - <nl> - <nl> - DBTest ( ) : option_config_ ( kDefault ) , <nl> - mem_env_ ( ! getenv ( " MEM_ENV " ) ? nullptr : <nl> - new MockEnv ( Env : : Default ( ) ) ) , <nl> - env_ ( new SpecialEnv ( mem_env_ ? mem_env_ : Env : : Default ( ) ) ) { <nl> - env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ; <nl> - env_ - > SetBackgroundThreads ( 1 , Env : : HIGH ) ; <nl> - dbname_ = test : : TmpDir ( env_ ) + " / db_test " ; <nl> - alternative_wal_dir_ = dbname_ + " / wal " ; <nl> - auto options = CurrentOptions ( ) ; <nl> - auto delete_options = options ; <nl> - delete_options . wal_dir = alternative_wal_dir_ ; <nl> - EXPECT_OK ( DestroyDB ( dbname_ , delete_options ) ) ; <nl> - / / Destroy it for not alternative WAL dir is used . <nl> - EXPECT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> - db_ = nullptr ; <nl> - Reopen ( options ) ; <nl> - } <nl> - <nl> - ~ DBTest ( ) { <nl> - rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ; <nl> - rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency ( { } ) ; <nl> - rocksdb : : SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ; <nl> - Close ( ) ; <nl> - Options options ; <nl> - options . db_paths . emplace_back ( dbname_ , 0 ) ; <nl> - options . db_paths . emplace_back ( dbname_ + " _2 " , 0 ) ; <nl> - options . db_paths . emplace_back ( dbname_ + " _3 " , 0 ) ; <nl> - options . db_paths . emplace_back ( dbname_ + " _4 " , 0 ) ; <nl> - EXPECT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> - delete env_ ; <nl> - } <nl> - <nl> - / / Switch to a fresh database with the next option configuration to <nl> - / / test . Return false if there are no more configurations to test . <nl> - bool ChangeOptions ( int skip_mask = kNoSkip ) { <nl> - for ( option_config_ + + ; option_config_ < kEnd ; option_config_ + + ) { <nl> - if ( ( skip_mask & kSkipDeletesFilterFirst ) & & <nl> - option_config_ = = kDeletesFilterFirst ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipUniversalCompaction ) & & <nl> - ( option_config_ = = kUniversalCompaction | | <nl> - option_config_ = = kUniversalCompactionMultiLevel ) ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipMergePut ) & & option_config_ = = kMergePut ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipNoSeekToLast ) & & <nl> - ( option_config_ = = kHashLinkList | | <nl> - option_config_ = = kHashSkipList ) ) { ; <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipPlainTable ) & & <nl> - ( option_config_ = = kPlainTableAllBytesPrefix | | <nl> - option_config_ = = kPlainTableFirstBytePrefix | | <nl> - option_config_ = = kPlainTableCappedPrefix ) ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipHashIndex ) & & <nl> - ( option_config_ = = kBlockBasedTableWithPrefixHashIndex | | <nl> - option_config_ = = kBlockBasedTableWithWholeKeyHashIndex ) ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipHashCuckoo ) & & ( option_config_ = = kHashCuckoo ) ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipFIFOCompaction ) & & <nl> - option_config_ = = kFIFOCompaction ) { <nl> - continue ; <nl> - } <nl> - if ( ( skip_mask & kSkipMmapReads ) & & <nl> - option_config_ = = kWalDirAndMmapReads ) { <nl> - continue ; <nl> - } <nl> - break ; <nl> - } <nl> - <nl> - if ( option_config_ > = kEnd ) { <nl> - Destroy ( last_options_ ) ; <nl> - return false ; <nl> - } else { <nl> - auto options = CurrentOptions ( ) ; <nl> - options . create_if_missing = true ; <nl> - DestroyAndReopen ( options ) ; <nl> - return true ; <nl> - } <nl> - } <nl> - <nl> - / / Switch between different compaction styles ( we have only 2 now ) . <nl> - bool ChangeCompactOptions ( ) { <nl> - if ( option_config_ = = kDefault ) { <nl> - option_config_ = kUniversalCompaction ; <nl> - Destroy ( last_options_ ) ; <nl> - auto options = CurrentOptions ( ) ; <nl> - options . create_if_missing = true ; <nl> - TryReopen ( options ) ; <nl> - return true ; <nl> - } else if ( option_config_ = = kUniversalCompaction ) { <nl> - option_config_ = kUniversalCompactionMultiLevel ; <nl> - Destroy ( last_options_ ) ; <nl> - auto options = CurrentOptions ( ) ; <nl> - options . create_if_missing = true ; <nl> - TryReopen ( options ) ; <nl> - return true ; <nl> - } else { <nl> - return false ; <nl> - } <nl> - } <nl> - <nl> - / / Switch between different filter policy <nl> - / / Jump from kDefault to kFilter to kFullFilter <nl> - bool ChangeFilterOptions ( ) { <nl> - if ( option_config_ = = kDefault ) { <nl> - option_config_ = kFilter ; <nl> - } else if ( option_config_ = = kFilter ) { <nl> - option_config_ = kFullFilter ; <nl> - } else { <nl> - return false ; <nl> - } <nl> - Destroy ( last_options_ ) ; <nl> - <nl> - auto options = CurrentOptions ( ) ; <nl> - options . create_if_missing = true ; <nl> - TryReopen ( options ) ; <nl> - return true ; <nl> - } <nl> - <nl> - / / Return the current option configuration . <nl> - Options CurrentOptions ( <nl> - const anon : : OptionsOverride & options_override = anon : : OptionsOverride ( ) ) { <nl> - Options options ; <nl> - return CurrentOptions ( options , options_override ) ; <nl> - } <nl> - <nl> - Options CurrentOptions ( <nl> - const Options & defaultOptions , <nl> - const anon : : OptionsOverride & options_override = anon : : OptionsOverride ( ) ) { <nl> - / / this redudant copy is to minimize code change w / o having lint error . <nl> - Options options = defaultOptions ; <nl> - XFUNC_TEST ( " " , " dbtest_options " , inplace_options1 , GetXFTestOptions , <nl> - reinterpret_cast < Options * > ( & options ) , <nl> - options_override . skip_policy ) ; <nl> - BlockBasedTableOptions table_options ; <nl> - bool set_block_based_table_factory = true ; <nl> - switch ( option_config_ ) { <nl> - case kHashSkipList : <nl> - options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> - options . memtable_factory . reset ( <nl> - NewHashSkipListRepFactory ( 16 ) ) ; <nl> - break ; <nl> - case kPlainTableFirstBytePrefix : <nl> - options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> - options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> - options . allow_mmap_reads = true ; <nl> - options . max_sequential_skip_in_iterations = 999999 ; <nl> - set_block_based_table_factory = false ; <nl> - break ; <nl> - case kPlainTableCappedPrefix : <nl> - options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> - options . prefix_extractor . reset ( NewCappedPrefixTransform ( 8 ) ) ; <nl> - options . allow_mmap_reads = true ; <nl> - options . max_sequential_skip_in_iterations = 999999 ; <nl> - set_block_based_table_factory = false ; <nl> - break ; <nl> - case kPlainTableAllBytesPrefix : <nl> - options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> - options . prefix_extractor . reset ( NewNoopTransform ( ) ) ; <nl> - options . allow_mmap_reads = true ; <nl> - options . max_sequential_skip_in_iterations = 999999 ; <nl> - set_block_based_table_factory = false ; <nl> - break ; <nl> - case kMergePut : <nl> - options . merge_operator = MergeOperators : : CreatePutOperator ( ) ; <nl> - break ; <nl> - case kFilter : <nl> - table_options . filter_policy . reset ( NewBloomFilterPolicy ( 10 , true ) ) ; <nl> - break ; <nl> - case kFullFilter : <nl> - table_options . filter_policy . reset ( NewBloomFilterPolicy ( 10 , false ) ) ; <nl> - break ; <nl> - case kUncompressed : <nl> - options . compression = kNoCompression ; <nl> - break ; <nl> - case kNumLevel_3 : <nl> - options . num_levels = 3 ; <nl> - break ; <nl> - case kDBLogDir : <nl> - options . db_log_dir = test : : TmpDir ( env_ ) ; <nl> - break ; <nl> - case kWalDirAndMmapReads : <nl> - options . wal_dir = alternative_wal_dir_ ; <nl> - / / mmap reads should be orthogonal to WalDir setting , so we piggyback to <nl> - / / this option config to test mmap reads as well <nl> - options . allow_mmap_reads = true ; <nl> - break ; <nl> - case kManifestFileSize : <nl> - options . max_manifest_file_size = 50 ; / / 50 bytes <nl> - case kCompactOnFlush : <nl> - options . purge_redundant_kvs_while_flush = <nl> - ! options . purge_redundant_kvs_while_flush ; <nl> - break ; <nl> - case kPerfOptions : <nl> - options . soft_rate_limit = 2 . 0 ; <nl> - options . delayed_write_rate = 8 * 1024 * 1024 ; <nl> - / / TODO - - test more options <nl> - break ; <nl> - case kDeletesFilterFirst : <nl> - options . filter_deletes = true ; <nl> - break ; <nl> - case kVectorRep : <nl> - options . memtable_factory . reset ( new VectorRepFactory ( 100 ) ) ; <nl> - break ; <nl> - case kHashLinkList : <nl> - options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> - options . memtable_factory . reset ( <nl> - NewHashLinkListRepFactory ( 4 , 0 , 3 , true , 4 ) ) ; <nl> - break ; <nl> - case kHashCuckoo : <nl> - options . memtable_factory . reset ( <nl> - NewHashCuckooRepFactory ( options . write_buffer_size ) ) ; <nl> - break ; <nl> - case kUniversalCompaction : <nl> - options . compaction_style = kCompactionStyleUniversal ; <nl> - options . num_levels = 1 ; <nl> - break ; <nl> - case kUniversalCompactionMultiLevel : <nl> - options . compaction_style = kCompactionStyleUniversal ; <nl> - options . num_levels = 8 ; <nl> - break ; <nl> - case kCompressedBlockCache : <nl> - options . allow_mmap_writes = true ; <nl> - table_options . block_cache_compressed = NewLRUCache ( 8 * 1024 * 1024 ) ; <nl> - break ; <nl> - case kInfiniteMaxOpenFiles : <nl> - options . max_open_files = - 1 ; <nl> - break ; <nl> - case kxxHashChecksum : { <nl> - table_options . checksum = kxxHash ; <nl> - break ; <nl> - } <nl> - case kFIFOCompaction : { <nl> - options . compaction_style = kCompactionStyleFIFO ; <nl> - break ; <nl> - } <nl> - case kBlockBasedTableWithPrefixHashIndex : { <nl> - table_options . index_type = BlockBasedTableOptions : : kHashSearch ; <nl> - options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> - break ; <nl> - } <nl> - case kBlockBasedTableWithWholeKeyHashIndex : { <nl> - table_options . index_type = BlockBasedTableOptions : : kHashSearch ; <nl> - options . prefix_extractor . reset ( NewNoopTransform ( ) ) ; <nl> - break ; <nl> - } <nl> - case kOptimizeFiltersForHits : { <nl> - options . optimize_filters_for_hits = true ; <nl> - set_block_based_table_factory = true ; <nl> - break ; <nl> - } <nl> - case kRowCache : { <nl> - options . row_cache = NewLRUCache ( 1024 * 1024 ) ; <nl> - break ; <nl> - } <nl> - <nl> - default : <nl> - break ; <nl> - } <nl> - <nl> - if ( options_override . filter_policy ) { <nl> - table_options . filter_policy = options_override . filter_policy ; <nl> - } <nl> - if ( set_block_based_table_factory ) { <nl> - options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ; <nl> - } <nl> - options . env = env_ ; <nl> - options . create_if_missing = true ; <nl> - return options ; <nl> - } <nl> - <nl> - DBImpl * dbfull ( ) { <nl> - return reinterpret_cast < DBImpl * > ( db_ ) ; <nl> - } <nl> - <nl> - void CreateColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> - const Options & options ) { <nl> - ColumnFamilyOptions cf_opts ( options ) ; <nl> - size_t cfi = handles_ . size ( ) ; <nl> - handles_ . resize ( cfi + cfs . size ( ) ) ; <nl> - for ( auto cf : cfs ) { <nl> - ASSERT_OK ( db_ - > CreateColumnFamily ( cf_opts , cf , & handles_ [ cfi + + ] ) ) ; <nl> - } <nl> - } <nl> - <nl> - void CreateAndReopenWithCF ( const std : : vector < std : : string > & cfs , <nl> - const Options & options ) { <nl> - CreateColumnFamilies ( cfs , options ) ; <nl> - std : : vector < std : : string > cfs_plus_default = cfs ; <nl> - cfs_plus_default . insert ( cfs_plus_default . begin ( ) , kDefaultColumnFamilyName ) ; <nl> - ReopenWithColumnFamilies ( cfs_plus_default , options ) ; <nl> - } <nl> - <nl> - void ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> - const std : : vector < Options > & options ) { <nl> - ASSERT_OK ( TryReopenWithColumnFamilies ( cfs , options ) ) ; <nl> - } <nl> - <nl> - void ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> - const Options & options ) { <nl> - ASSERT_OK ( TryReopenWithColumnFamilies ( cfs , options ) ) ; <nl> - } <nl> - <nl> - Status TryReopenWithColumnFamilies ( <nl> - const std : : vector < std : : string > & cfs , <nl> - const std : : vector < Options > & options ) { <nl> - Close ( ) ; <nl> - EXPECT_EQ ( cfs . size ( ) , options . size ( ) ) ; <nl> - std : : vector < ColumnFamilyDescriptor > column_families ; <nl> - for ( size_t i = 0 ; i < cfs . size ( ) ; + + i ) { <nl> - column_families . push_back ( ColumnFamilyDescriptor ( cfs [ i ] , options [ i ] ) ) ; <nl> - } <nl> - DBOptions db_opts = DBOptions ( options [ 0 ] ) ; <nl> - return DB : : Open ( db_opts , dbname_ , column_families , & handles_ , & db_ ) ; <nl> - } <nl> - <nl> - Status TryReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> - const Options & options ) { <nl> - Close ( ) ; <nl> - std : : vector < Options > v_opts ( cfs . size ( ) , options ) ; <nl> - return TryReopenWithColumnFamilies ( cfs , v_opts ) ; <nl> - } <nl> - <nl> - void Reopen ( const Options & options ) { <nl> - ASSERT_OK ( TryReopen ( options ) ) ; <nl> - } <nl> - <nl> - void Close ( ) { <nl> - for ( auto h : handles_ ) { <nl> - delete h ; <nl> - } <nl> - handles_ . clear ( ) ; <nl> - delete db_ ; <nl> - db_ = nullptr ; <nl> - } <nl> - <nl> - void DestroyAndReopen ( const Options & options ) { <nl> - / / Destroy using last options <nl> - Destroy ( last_options_ ) ; <nl> - ASSERT_OK ( TryReopen ( options ) ) ; <nl> - } <nl> - <nl> - void Destroy ( const Options & options ) { <nl> - Close ( ) ; <nl> - ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> - } <nl> - <nl> - Status ReadOnlyReopen ( const Options & options ) { <nl> - return DB : : OpenForReadOnly ( options , dbname_ , & db_ ) ; <nl> - } <nl> - <nl> - Status TryReopen ( const Options & options ) { <nl> - Close ( ) ; <nl> - last_options_ = options ; <nl> - return DB : : Open ( options , dbname_ , & db_ ) ; <nl> - } <nl> - <nl> - Status Flush ( int cf = 0 ) { <nl> - if ( cf = = 0 ) { <nl> - return db_ - > Flush ( FlushOptions ( ) ) ; <nl> - } else { <nl> - return db_ - > Flush ( FlushOptions ( ) , handles_ [ cf ] ) ; <nl> - } <nl> - } <nl> - <nl> - Status Put ( const Slice & k , const Slice & v , WriteOptions wo = WriteOptions ( ) ) { <nl> - if ( kMergePut = = option_config_ ) { <nl> - return db_ - > Merge ( wo , k , v ) ; <nl> - } else { <nl> - return db_ - > Put ( wo , k , v ) ; <nl> - } <nl> - } <nl> - <nl> - Status Put ( int cf , const Slice & k , const Slice & v , <nl> - WriteOptions wo = WriteOptions ( ) ) { <nl> - if ( kMergePut = = option_config_ ) { <nl> - return db_ - > Merge ( wo , handles_ [ cf ] , k , v ) ; <nl> - } else { <nl> - return db_ - > Put ( wo , handles_ [ cf ] , k , v ) ; <nl> - } <nl> - } <nl> - <nl> - Status Delete ( const std : : string & k ) { <nl> - return db_ - > Delete ( WriteOptions ( ) , k ) ; <nl> - } <nl> - <nl> - Status Delete ( int cf , const std : : string & k ) { <nl> - return db_ - > Delete ( WriteOptions ( ) , handles_ [ cf ] , k ) ; <nl> - } <nl> - <nl> - std : : string Get ( const std : : string & k , const Snapshot * snapshot = nullptr ) { <nl> - ReadOptions options ; <nl> - options . verify_checksums = true ; <nl> - options . snapshot = snapshot ; <nl> - std : : string result ; <nl> - Status s = db_ - > Get ( options , k , & result ) ; <nl> - if ( s . IsNotFound ( ) ) { <nl> - result = " NOT_FOUND " ; <nl> - } else if ( ! s . ok ( ) ) { <nl> - result = s . ToString ( ) ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - std : : string Get ( int cf , const std : : string & k , <nl> - const Snapshot * snapshot = nullptr ) { <nl> - ReadOptions options ; <nl> - options . verify_checksums = true ; <nl> - options . snapshot = snapshot ; <nl> - std : : string result ; <nl> - Status s = db_ - > Get ( options , handles_ [ cf ] , k , & result ) ; <nl> - if ( s . IsNotFound ( ) ) { <nl> - result = " NOT_FOUND " ; <nl> - } else if ( ! s . ok ( ) ) { <nl> - result = s . ToString ( ) ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - uint64_t GetNumSnapshots ( ) { <nl> - uint64_t int_num ; <nl> - EXPECT_TRUE ( dbfull ( ) - > GetIntProperty ( " rocksdb . num - snapshots " , & int_num ) ) ; <nl> - return int_num ; <nl> - } <nl> - <nl> - uint64_t GetTimeOldestSnapshots ( ) { <nl> - uint64_t int_num ; <nl> - EXPECT_TRUE ( <nl> - dbfull ( ) - > GetIntProperty ( " rocksdb . oldest - snapshot - time " , & int_num ) ) ; <nl> - return int_num ; <nl> - } <nl> - <nl> - / / Return a string that contains all key , value pairs in order , <nl> - / / formatted like " ( k1 - > v1 ) ( k2 - > v2 ) " . <nl> - std : : string Contents ( int cf = 0 ) { <nl> - std : : vector < std : : string > forward ; <nl> - std : : string result ; <nl> - Iterator * iter = ( cf = = 0 ) ? db_ - > NewIterator ( ReadOptions ( ) ) <nl> - : db_ - > NewIterator ( ReadOptions ( ) , handles_ [ cf ] ) ; <nl> - for ( iter - > SeekToFirst ( ) ; iter - > Valid ( ) ; iter - > Next ( ) ) { <nl> - std : : string s = IterStatus ( iter ) ; <nl> - result . push_back ( ' ( ' ) ; <nl> - result . append ( s ) ; <nl> - result . push_back ( ' ) ' ) ; <nl> - forward . push_back ( s ) ; <nl> - } <nl> - <nl> - / / Check reverse iteration results are the reverse of forward results <nl> - unsigned int matched = 0 ; <nl> - for ( iter - > SeekToLast ( ) ; iter - > Valid ( ) ; iter - > Prev ( ) ) { <nl> - EXPECT_LT ( matched , forward . size ( ) ) ; <nl> - EXPECT_EQ ( IterStatus ( iter ) , forward [ forward . size ( ) - matched - 1 ] ) ; <nl> - matched + + ; <nl> - } <nl> - EXPECT_EQ ( matched , forward . size ( ) ) ; <nl> - <nl> - delete iter ; <nl> - return result ; <nl> - } <nl> - <nl> - std : : string AllEntriesFor ( const Slice & user_key , int cf = 0 ) { <nl> - Arena arena ; <nl> - ScopedArenaIterator iter ; <nl> - if ( cf = = 0 ) { <nl> - iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena ) ) ; <nl> - } else { <nl> - iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena , handles_ [ cf ] ) ) ; <nl> - } <nl> - InternalKey target ( user_key , kMaxSequenceNumber , kTypeValue ) ; <nl> - iter - > Seek ( target . Encode ( ) ) ; <nl> - std : : string result ; <nl> - if ( ! iter - > status ( ) . ok ( ) ) { <nl> - result = iter - > status ( ) . ToString ( ) ; <nl> - } else { <nl> - result = " [ " ; <nl> - bool first = true ; <nl> - while ( iter - > Valid ( ) ) { <nl> - ParsedInternalKey ikey ( Slice ( ) , 0 , kTypeValue ) ; <nl> - if ( ! ParseInternalKey ( iter - > key ( ) , & ikey ) ) { <nl> - result + = " CORRUPTED " ; <nl> - } else { <nl> - if ( last_options_ . comparator - > Compare ( ikey . user_key , user_key ) ! = 0 ) { <nl> - break ; <nl> - } <nl> - if ( ! first ) { <nl> - result + = " , " ; <nl> - } <nl> - first = false ; <nl> - switch ( ikey . type ) { <nl> - case kTypeValue : <nl> - result + = iter - > value ( ) . ToString ( ) ; <nl> - break ; <nl> - case kTypeMerge : <nl> - / / keep it the same as kTypeValue for testing kMergePut <nl> - result + = iter - > value ( ) . ToString ( ) ; <nl> - break ; <nl> - case kTypeDeletion : <nl> - result + = " DEL " ; <nl> - break ; <nl> - default : <nl> - assert ( false ) ; <nl> - break ; <nl> - } <nl> - } <nl> - iter - > Next ( ) ; <nl> - } <nl> - if ( ! first ) { <nl> - result + = " " ; <nl> - } <nl> - result + = " ] " ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - int NumSortedRuns ( int cf = 0 ) { <nl> - ColumnFamilyMetaData cf_meta ; <nl> - if ( cf = = 0 ) { <nl> - db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> - } else { <nl> - db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> - } <nl> - int num_sr = static_cast < int > ( cf_meta . levels [ 0 ] . files . size ( ) ) ; <nl> - for ( size_t i = 1U ; i < cf_meta . levels . size ( ) ; i + + ) { <nl> - if ( cf_meta . levels [ i ] . files . size ( ) > 0 ) { <nl> - num_sr + + ; <nl> - } <nl> - } <nl> - return num_sr ; <nl> - } <nl> - <nl> - uint64_t TotalSize ( int cf = 0 ) { <nl> - ColumnFamilyMetaData cf_meta ; <nl> - if ( cf = = 0 ) { <nl> - db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> - } else { <nl> - db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> - } <nl> - return cf_meta . size ; <nl> - } <nl> - <nl> - int NumTableFilesAtLevel ( int level , int cf = 0 ) { <nl> - std : : string property ; <nl> - if ( cf = = 0 ) { <nl> - / / default cfd <nl> - EXPECT_TRUE ( db_ - > GetProperty ( <nl> - " rocksdb . num - files - at - level " + NumberToString ( level ) , & property ) ) ; <nl> - } else { <nl> - EXPECT_TRUE ( db_ - > GetProperty ( <nl> - handles_ [ cf ] , " rocksdb . num - files - at - level " + NumberToString ( level ) , <nl> - & property ) ) ; <nl> - } <nl> - return atoi ( property . c_str ( ) ) ; <nl> - } <nl> - <nl> - uint64_t SizeAtLevel ( int level ) { <nl> - std : : vector < LiveFileMetaData > metadata ; <nl> - db_ - > GetLiveFilesMetaData ( & metadata ) ; <nl> - uint64_t sum = 0 ; <nl> - for ( const auto & m : metadata ) { <nl> - if ( m . level = = level ) { <nl> - sum + = m . size ; <nl> - } <nl> - } <nl> - return sum ; <nl> - } <nl> - <nl> - int TotalLiveFiles ( int cf = 0 ) { <nl> - ColumnFamilyMetaData cf_meta ; <nl> - if ( cf = = 0 ) { <nl> - db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> - } else { <nl> - db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> - } <nl> - int num_files = 0 ; <nl> - for ( auto & level : cf_meta . levels ) { <nl> - num_files + = level . files . size ( ) ; <nl> - } <nl> - return num_files ; <nl> - } <nl> - <nl> - int TotalTableFiles ( int cf = 0 , int levels = - 1 ) { <nl> - if ( levels = = - 1 ) { <nl> - levels = CurrentOptions ( ) . num_levels ; <nl> - } <nl> - int result = 0 ; <nl> - for ( int level = 0 ; level < levels ; level + + ) { <nl> - result + = NumTableFilesAtLevel ( level , cf ) ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - / / Return spread of files per level <nl> - std : : string FilesPerLevel ( int cf = 0 ) { <nl> - int num_levels = <nl> - ( cf = = 0 ) ? db_ - > NumberLevels ( ) : db_ - > NumberLevels ( handles_ [ 1 ] ) ; <nl> - std : : string result ; <nl> - size_t last_non_zero_offset = 0 ; <nl> - for ( int level = 0 ; level < num_levels ; level + + ) { <nl> - int f = NumTableFilesAtLevel ( level , cf ) ; <nl> - char buf [ 100 ] ; <nl> - snprintf ( buf , sizeof ( buf ) , " % s % d " , ( level ? " , " : " " ) , f ) ; <nl> - result + = buf ; <nl> - if ( f > 0 ) { <nl> - last_non_zero_offset = result . size ( ) ; <nl> - } <nl> - } <nl> - result . resize ( last_non_zero_offset ) ; <nl> - return result ; <nl> - } <nl> - <nl> - size_t CountFiles ( ) { <nl> - std : : vector < std : : string > files ; <nl> - env_ - > GetChildren ( dbname_ , & files ) ; <nl> - <nl> - std : : vector < std : : string > logfiles ; <nl> - if ( dbname_ ! = last_options_ . wal_dir ) { <nl> - env_ - > GetChildren ( last_options_ . wal_dir , & logfiles ) ; <nl> - } <nl> - <nl> - return files . size ( ) + logfiles . size ( ) ; <nl> - } <nl> - <nl> - size_t CountLiveFiles ( ) { <nl> - std : : vector < LiveFileMetaData > metadata ; <nl> - db_ - > GetLiveFilesMetaData ( & metadata ) ; <nl> - return metadata . size ( ) ; <nl> - } <nl> - <nl> - uint64_t Size ( const Slice & start , const Slice & limit , int cf = 0 ) { <nl> - Range r ( start , limit ) ; <nl> - uint64_t size ; <nl> - if ( cf = = 0 ) { <nl> - db_ - > GetApproximateSizes ( & r , 1 , & size ) ; <nl> - } else { <nl> - db_ - > GetApproximateSizes ( handles_ [ 1 ] , & r , 1 , & size ) ; <nl> - } <nl> - return size ; <nl> - } <nl> - <nl> - void Compact ( int cf , const Slice & start , const Slice & limit , <nl> - uint32_t target_path_id ) { <nl> - CompactRangeOptions compact_options ; <nl> - compact_options . target_path_id = target_path_id ; <nl> - ASSERT_OK ( db_ - > CompactRange ( compact_options , handles_ [ cf ] , & start , & limit ) ) ; <nl> - } <nl> - <nl> - void Compact ( int cf , const Slice & start , const Slice & limit ) { <nl> - ASSERT_OK ( <nl> - db_ - > CompactRange ( CompactRangeOptions ( ) , handles_ [ cf ] , & start , & limit ) ) ; <nl> - } <nl> - <nl> - void Compact ( const Slice & start , const Slice & limit ) { <nl> - ASSERT_OK ( db_ - > CompactRange ( CompactRangeOptions ( ) , & start , & limit ) ) ; <nl> - } <nl> - <nl> - / / Do n memtable compactions , each of which produces an sstable <nl> - / / covering the range [ small , large ] . <nl> - void MakeTables ( int n , const std : : string & small , const std : : string & large , <nl> - int cf = 0 ) { <nl> - for ( int i = 0 ; i < n ; i + + ) { <nl> - ASSERT_OK ( Put ( cf , small , " begin " ) ) ; <nl> - ASSERT_OK ( Put ( cf , large , " end " ) ) ; <nl> - ASSERT_OK ( Flush ( cf ) ) ; <nl> - } <nl> - } <nl> - <nl> - / / Prevent pushing of new sstables into deeper levels by adding <nl> - / / tables that cover a specified range to all levels . <nl> - void FillLevels ( const std : : string & smallest , const std : : string & largest , <nl> - int cf ) { <nl> - MakeTables ( db_ - > NumberLevels ( handles_ [ cf ] ) , smallest , largest , cf ) ; <nl> - } <nl> - <nl> - void DumpFileCounts ( const char * label ) { <nl> - fprintf ( stderr , " mmm \ n % s : \ n " , label ) ; <nl> - fprintf ( stderr , " maxoverlap : % lld \ n " , <nl> - static_cast < long long > ( <nl> - dbfull ( ) - > TEST_MaxNextLevelOverlappingBytes ( ) ) ) ; <nl> - for ( int level = 0 ; level < db_ - > NumberLevels ( ) ; level + + ) { <nl> - int num = NumTableFilesAtLevel ( level ) ; <nl> - if ( num > 0 ) { <nl> - fprintf ( stderr , " level % 3d : % d files \ n " , level , num ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - std : : string DumpSSTableList ( ) { <nl> - std : : string property ; <nl> - db_ - > GetProperty ( " rocksdb . sstables " , & property ) ; <nl> - return property ; <nl> - } <nl> - <nl> - int GetSstFileCount ( std : : string path ) { <nl> - std : : vector < std : : string > files ; <nl> - env_ - > GetChildren ( path , & files ) ; <nl> - <nl> - int sst_count = 0 ; <nl> - uint64_t number ; <nl> - FileType type ; <nl> - for ( size_t i = 0 ; i < files . size ( ) ; i + + ) { <nl> - if ( ParseFileName ( files [ i ] , & number , & type ) & & type = = kTableFile ) { <nl> - sst_count + + ; <nl> - } <nl> - } <nl> - return sst_count ; <nl> - } <nl> - <nl> - / / this will generate non - overlapping files since it keeps increasing key_idx <nl> - void GenerateNewFile ( Random * rnd , int * key_idx , bool nowait = false ) { <nl> - for ( int i = 0 ; i < 11 ; i + + ) { <nl> - ASSERT_OK ( Put ( Key ( * key_idx ) , RandomString ( rnd , ( i = = 10 ) ? 1 : 10000 ) ) ) ; <nl> - ( * key_idx ) + + ; <nl> - } <nl> - if ( ! nowait ) { <nl> - dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ; <nl> - dbfull ( ) - > TEST_WaitForCompact ( ) ; <nl> - } <nl> - } <nl> - <nl> - void GenerateNewRandomFile ( Random * rnd , bool nowait = false ) { <nl> - for ( int i = 0 ; i < 100 ; i + + ) { <nl> - ASSERT_OK ( Put ( " key " + RandomString ( rnd , 7 ) , RandomString ( rnd , 1000 ) ) ) ; <nl> - } <nl> - ASSERT_OK ( Put ( " key " + RandomString ( rnd , 7 ) , RandomString ( rnd , 1 ) ) ) ; <nl> - if ( ! nowait ) { <nl> - dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ; <nl> - dbfull ( ) - > TEST_WaitForCompact ( ) ; <nl> - } <nl> - } <nl> - <nl> - std : : string IterStatus ( Iterator * iter ) { <nl> - std : : string result ; <nl> - if ( iter - > Valid ( ) ) { <nl> - result = iter - > key ( ) . ToString ( ) + " - > " + iter - > value ( ) . ToString ( ) ; <nl> - } else { <nl> - result = " ( invalid ) " ; <nl> - } <nl> - return result ; <nl> - } <nl> - <nl> - Options OptionsForLogIterTest ( ) { <nl> - Options options = CurrentOptions ( ) ; <nl> - options . create_if_missing = true ; <nl> - options . WAL_ttl_seconds = 1000 ; <nl> - return options ; <nl> - } <nl> - <nl> - std : : unique_ptr < TransactionLogIterator > OpenTransactionLogIter ( <nl> - const SequenceNumber seq ) { <nl> - unique_ptr < TransactionLogIterator > iter ; <nl> - Status status = dbfull ( ) - > GetUpdatesSince ( seq , & iter ) ; <nl> - EXPECT_OK ( status ) ; <nl> - EXPECT_TRUE ( iter - > Valid ( ) ) ; <nl> - return std : : move ( iter ) ; <nl> - } <nl> - <nl> - std : : string DummyString ( size_t len , char c = ' a ' ) { <nl> - return std : : string ( len , c ) ; <nl> - } <nl> - <nl> - void VerifyIterLast ( std : : string expected_key , int cf = 0 ) { <nl> - Iterator * iter ; <nl> - ReadOptions ro ; <nl> - if ( cf = = 0 ) { <nl> - iter = db_ - > NewIterator ( ro ) ; <nl> - } else { <nl> - iter = db_ - > NewIterator ( ro , handles_ [ cf ] ) ; <nl> - } <nl> - iter - > SeekToLast ( ) ; <nl> - ASSERT_EQ ( IterStatus ( iter ) , expected_key ) ; <nl> - delete iter ; <nl> - } <nl> - <nl> - / / Used to test InplaceUpdate <nl> - <nl> - / / If previous value is nullptr or delta is > than previous value , <nl> - / / sets newValue with delta <nl> - / / If previous value is not empty , <nl> - / / updates previous value with ' b ' string of previous value size - 1 . <nl> - static UpdateStatus <nl> - updateInPlaceSmallerSize ( char * prevValue , uint32_t * prevSize , <nl> - Slice delta , std : : string * newValue ) { <nl> - if ( prevValue = = nullptr ) { <nl> - * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> - return UpdateStatus : : UPDATED ; <nl> - } else { <nl> - * prevSize = * prevSize - 1 ; <nl> - std : : string str_b = std : : string ( * prevSize , ' b ' ) ; <nl> - memcpy ( prevValue , str_b . c_str ( ) , str_b . size ( ) ) ; <nl> - return UpdateStatus : : UPDATED_INPLACE ; <nl> - } <nl> - } <nl> - <nl> - static UpdateStatus <nl> - updateInPlaceSmallerVarintSize ( char * prevValue , uint32_t * prevSize , <nl> - Slice delta , std : : string * newValue ) { <nl> - if ( prevValue = = nullptr ) { <nl> - * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> - return UpdateStatus : : UPDATED ; <nl> - } else { <nl> - * prevSize = 1 ; <nl> - std : : string str_b = std : : string ( * prevSize , ' b ' ) ; <nl> - memcpy ( prevValue , str_b . c_str ( ) , str_b . size ( ) ) ; <nl> - return UpdateStatus : : UPDATED_INPLACE ; <nl> - } <nl> - } <nl> - <nl> - static UpdateStatus <nl> - updateInPlaceLargerSize ( char * prevValue , uint32_t * prevSize , <nl> - Slice delta , std : : string * newValue ) { <nl> - * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> - return UpdateStatus : : UPDATED ; <nl> - } <nl> - <nl> - static UpdateStatus <nl> - updateInPlaceNoAction ( char * prevValue , uint32_t * prevSize , <nl> - Slice delta , std : : string * newValue ) { <nl> - return UpdateStatus : : UPDATE_FAILED ; <nl> - } <nl> - <nl> - / / Utility method to test InplaceUpdate <nl> - void validateNumberOfEntries ( int numValues , int cf = 0 ) { <nl> - ScopedArenaIterator iter ; <nl> - Arena arena ; <nl> - if ( cf ! = 0 ) { <nl> - iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena , handles_ [ cf ] ) ) ; <nl> - } else { <nl> - iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena ) ) ; <nl> - } <nl> - iter - > SeekToFirst ( ) ; <nl> - ASSERT_EQ ( iter - > status ( ) . ok ( ) , true ) ; <nl> - int seq = numValues ; <nl> - while ( iter - > Valid ( ) ) { <nl> - ParsedInternalKey ikey ; <nl> - ikey . sequence = - 1 ; <nl> - ASSERT_EQ ( ParseInternalKey ( iter - > key ( ) , & ikey ) , true ) ; <nl> - <nl> - / / checks sequence number for updates <nl> - ASSERT_EQ ( ikey . sequence , ( unsigned ) seq - - ) ; <nl> - iter - > Next ( ) ; <nl> - } <nl> - ASSERT_EQ ( 0 , seq ) ; <nl> - } <nl> - <nl> - void CopyFile ( const std : : string & source , const std : : string & destination , <nl> - uint64_t size = 0 ) { <nl> - const EnvOptions soptions ; <nl> - unique_ptr < SequentialFile > srcfile ; <nl> - ASSERT_OK ( env_ - > NewSequentialFile ( source , & srcfile , soptions ) ) ; <nl> - unique_ptr < WritableFile > destfile ; <nl> - ASSERT_OK ( env_ - > NewWritableFile ( destination , & destfile , soptions ) ) ; <nl> - <nl> - if ( size = = 0 ) { <nl> - / / default argument means copy everything <nl> - ASSERT_OK ( env_ - > GetFileSize ( source , & size ) ) ; <nl> - } <nl> - <nl> - char buffer [ 4096 ] ; <nl> - Slice slice ; <nl> - while ( size > 0 ) { <nl> - uint64_t one = std : : min ( uint64_t ( sizeof ( buffer ) ) , size ) ; <nl> - ASSERT_OK ( srcfile - > Read ( one , & slice , buffer ) ) ; <nl> - ASSERT_OK ( destfile - > Append ( slice ) ) ; <nl> - size - = slice . size ( ) ; <nl> - } <nl> - ASSERT_OK ( destfile - > Close ( ) ) ; <nl> - } <nl> - <nl> - } ; <nl> - <nl> static long TestGetTickerCount ( const Options & options , Tickers ticker_type ) { <nl> return options . statistics - > getTickerCount ( ticker_type ) ; <nl> } <nl> uint64_t GetNumberOfSstFilesForColumnFamily ( DB * db , <nl> } <nl> } / / namespace <nl> <nl> + class DBTest : public DBTestBase { <nl> + public : <nl> + DBTest ( ) : DBTestBase ( " / db_test " ) { } <nl> + } ; <nl> + <nl> TEST_F ( DBTest , Empty ) { <nl> do { <nl> Options options ; <nl> mmm a / src . mk <nl> ppp b / src . mk <nl> TEST_BENCH_SOURCES = \ <nl> util / cache_test . cc \ <nl> util / coding_test . cc \ <nl> util / crc32c_test . cc \ <nl> + util / db_test_util . cc \ <nl> util / dynamic_bloom_test . cc \ <nl> util / env_test . cc \ <nl> util / filelock_test . cc \ <nl> new file mode 100644 <nl> index 0000000000 . . efdf089f61 <nl> mmm / dev / null <nl> ppp b / util / db_test_util . cc <nl> <nl> + / / Copyright ( c ) 2013 , Facebook , Inc . All rights reserved . <nl> + / / This source code is licensed under the BSD - style license found in the <nl> + / / LICENSE file in the root directory of this source tree . An additional grant <nl> + / / of patent rights can be found in the PATENTS file in the same directory . <nl> + / / <nl> + / / Copyright ( c ) 2011 The LevelDB Authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . See the AUTHORS file for names of contributors . <nl> + <nl> + # include " util / db_test_util . h " <nl> + <nl> + namespace rocksdb { <nl> + <nl> + / / Special Env used to delay background operations <nl> + <nl> + SpecialEnv : : SpecialEnv ( Env * base ) <nl> + : EnvWrapper ( base ) , <nl> + rnd_ ( 301 ) , <nl> + sleep_counter_ ( this ) , <nl> + addon_time_ ( 0 ) , <nl> + no_sleep_ ( false ) { <nl> + delay_sstable_sync_ . store ( false , std : : memory_order_release ) ; <nl> + drop_writes_ . store ( false , std : : memory_order_release ) ; <nl> + no_space_ . store ( false , std : : memory_order_release ) ; <nl> + non_writable_ . store ( false , std : : memory_order_release ) ; <nl> + count_random_reads_ = false ; <nl> + count_sequential_reads_ = false ; <nl> + manifest_sync_error_ . store ( false , std : : memory_order_release ) ; <nl> + manifest_write_error_ . store ( false , std : : memory_order_release ) ; <nl> + log_write_error_ . store ( false , std : : memory_order_release ) ; <nl> + log_write_slowdown_ = 0 ; <nl> + bytes_written_ = 0 ; <nl> + sync_counter_ = 0 ; <nl> + non_writeable_rate_ = 0 ; <nl> + new_writable_count_ = 0 ; <nl> + non_writable_count_ = 0 ; <nl> + table_write_callback_ = nullptr ; <nl> + } <nl> + <nl> + <nl> + DBTestBase : : DBTestBase ( const std : : string path ) : option_config_ ( kDefault ) , <nl> + mem_env_ ( ! getenv ( " MEM_ENV " ) ? nullptr : <nl> + new MockEnv ( Env : : Default ( ) ) ) , <nl> + env_ ( new SpecialEnv ( mem_env_ ? mem_env_ : Env : : Default ( ) ) ) { <nl> + env_ - > SetBackgroundThreads ( 1 , Env : : LOW ) ; <nl> + env_ - > SetBackgroundThreads ( 1 , Env : : HIGH ) ; <nl> + dbname_ = test : : TmpDir ( env_ ) + path ; <nl> + alternative_wal_dir_ = dbname_ + " / wal " ; <nl> + auto options = CurrentOptions ( ) ; <nl> + auto delete_options = options ; <nl> + delete_options . wal_dir = alternative_wal_dir_ ; <nl> + EXPECT_OK ( DestroyDB ( dbname_ , delete_options ) ) ; <nl> + / / Destroy it for not alternative WAL dir is used . <nl> + EXPECT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> + db_ = nullptr ; <nl> + Reopen ( options ) ; <nl> + } <nl> + <nl> + DBTestBase : : ~ DBTestBase ( ) { <nl> + rocksdb : : SyncPoint : : GetInstance ( ) - > DisableProcessing ( ) ; <nl> + rocksdb : : SyncPoint : : GetInstance ( ) - > LoadDependency ( { } ) ; <nl> + rocksdb : : SyncPoint : : GetInstance ( ) - > ClearAllCallBacks ( ) ; <nl> + Close ( ) ; <nl> + Options options ; <nl> + options . db_paths . emplace_back ( dbname_ , 0 ) ; <nl> + options . db_paths . emplace_back ( dbname_ + " _2 " , 0 ) ; <nl> + options . db_paths . emplace_back ( dbname_ + " _3 " , 0 ) ; <nl> + options . db_paths . emplace_back ( dbname_ + " _4 " , 0 ) ; <nl> + EXPECT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> + delete env_ ; <nl> + } <nl> + <nl> + / / Switch to a fresh database with the next option configuration to <nl> + / / test . Return false if there are no more configurations to test . <nl> + bool DBTestBase : : ChangeOptions ( int skip_mask ) { <nl> + for ( option_config_ + + ; option_config_ < kEnd ; option_config_ + + ) { <nl> + if ( ( skip_mask & kSkipDeletesFilterFirst ) & & <nl> + option_config_ = = kDeletesFilterFirst ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipUniversalCompaction ) & & <nl> + ( option_config_ = = kUniversalCompaction | | <nl> + option_config_ = = kUniversalCompactionMultiLevel ) ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipMergePut ) & & option_config_ = = kMergePut ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipNoSeekToLast ) & & <nl> + ( option_config_ = = kHashLinkList | | <nl> + option_config_ = = kHashSkipList ) ) { ; <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipPlainTable ) & & <nl> + ( option_config_ = = kPlainTableAllBytesPrefix | | <nl> + option_config_ = = kPlainTableFirstBytePrefix | | <nl> + option_config_ = = kPlainTableCappedPrefix ) ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipHashIndex ) & & <nl> + ( option_config_ = = kBlockBasedTableWithPrefixHashIndex | | <nl> + option_config_ = = kBlockBasedTableWithWholeKeyHashIndex ) ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipHashCuckoo ) & & ( option_config_ = = kHashCuckoo ) ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipFIFOCompaction ) & & <nl> + option_config_ = = kFIFOCompaction ) { <nl> + continue ; <nl> + } <nl> + if ( ( skip_mask & kSkipMmapReads ) & & <nl> + option_config_ = = kWalDirAndMmapReads ) { <nl> + continue ; <nl> + } <nl> + break ; <nl> + } <nl> + <nl> + if ( option_config_ > = kEnd ) { <nl> + Destroy ( last_options_ ) ; <nl> + return false ; <nl> + } else { <nl> + auto options = CurrentOptions ( ) ; <nl> + options . create_if_missing = true ; <nl> + DestroyAndReopen ( options ) ; <nl> + return true ; <nl> + } <nl> + } <nl> + <nl> + / / Switch between different compaction styles ( we have only 2 now ) . <nl> + bool DBTestBase : : ChangeCompactOptions ( ) { <nl> + if ( option_config_ = = kDefault ) { <nl> + option_config_ = kUniversalCompaction ; <nl> + Destroy ( last_options_ ) ; <nl> + auto options = CurrentOptions ( ) ; <nl> + options . create_if_missing = true ; <nl> + TryReopen ( options ) ; <nl> + return true ; <nl> + } else if ( option_config_ = = kUniversalCompaction ) { <nl> + option_config_ = kUniversalCompactionMultiLevel ; <nl> + Destroy ( last_options_ ) ; <nl> + auto options = CurrentOptions ( ) ; <nl> + options . create_if_missing = true ; <nl> + TryReopen ( options ) ; <nl> + return true ; <nl> + } else { <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + / / Switch between different filter policy <nl> + / / Jump from kDefault to kFilter to kFullFilter <nl> + bool DBTestBase : : ChangeFilterOptions ( ) { <nl> + if ( option_config_ = = kDefault ) { <nl> + option_config_ = kFilter ; <nl> + } else if ( option_config_ = = kFilter ) { <nl> + option_config_ = kFullFilter ; <nl> + } else { <nl> + return false ; <nl> + } <nl> + Destroy ( last_options_ ) ; <nl> + <nl> + auto options = CurrentOptions ( ) ; <nl> + options . create_if_missing = true ; <nl> + TryReopen ( options ) ; <nl> + return true ; <nl> + } <nl> + <nl> + / / Return the current option configuration . <nl> + Options DBTestBase : : CurrentOptions ( <nl> + const anon : : OptionsOverride & options_override ) { <nl> + Options options ; <nl> + return CurrentOptions ( options , options_override ) ; <nl> + } <nl> + <nl> + Options DBTestBase : : CurrentOptions ( <nl> + const Options & defaultOptions , <nl> + const anon : : OptionsOverride & options_override ) { <nl> + / / this redudant copy is to minimize code change w / o having lint error . <nl> + Options options = defaultOptions ; <nl> + XFUNC_TEST ( " " , " dbtest_options " , inplace_options1 , GetXFTestOptions , <nl> + reinterpret_cast < Options * > ( & options ) , <nl> + options_override . skip_policy ) ; <nl> + BlockBasedTableOptions table_options ; <nl> + bool set_block_based_table_factory = true ; <nl> + switch ( option_config_ ) { <nl> + case kHashSkipList : <nl> + options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> + options . memtable_factory . reset ( <nl> + NewHashSkipListRepFactory ( 16 ) ) ; <nl> + break ; <nl> + case kPlainTableFirstBytePrefix : <nl> + options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> + options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> + options . allow_mmap_reads = true ; <nl> + options . max_sequential_skip_in_iterations = 999999 ; <nl> + set_block_based_table_factory = false ; <nl> + break ; <nl> + case kPlainTableCappedPrefix : <nl> + options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> + options . prefix_extractor . reset ( NewCappedPrefixTransform ( 8 ) ) ; <nl> + options . allow_mmap_reads = true ; <nl> + options . max_sequential_skip_in_iterations = 999999 ; <nl> + set_block_based_table_factory = false ; <nl> + break ; <nl> + case kPlainTableAllBytesPrefix : <nl> + options . table_factory . reset ( new PlainTableFactory ( ) ) ; <nl> + options . prefix_extractor . reset ( NewNoopTransform ( ) ) ; <nl> + options . allow_mmap_reads = true ; <nl> + options . max_sequential_skip_in_iterations = 999999 ; <nl> + set_block_based_table_factory = false ; <nl> + break ; <nl> + case kMergePut : <nl> + options . merge_operator = MergeOperators : : CreatePutOperator ( ) ; <nl> + break ; <nl> + case kFilter : <nl> + table_options . filter_policy . reset ( NewBloomFilterPolicy ( 10 , true ) ) ; <nl> + break ; <nl> + case kFullFilter : <nl> + table_options . filter_policy . reset ( NewBloomFilterPolicy ( 10 , false ) ) ; <nl> + break ; <nl> + case kUncompressed : <nl> + options . compression = kNoCompression ; <nl> + break ; <nl> + case kNumLevel_3 : <nl> + options . num_levels = 3 ; <nl> + break ; <nl> + case kDBLogDir : <nl> + options . db_log_dir = test : : TmpDir ( env_ ) ; <nl> + break ; <nl> + case kWalDirAndMmapReads : <nl> + options . wal_dir = alternative_wal_dir_ ; <nl> + / / mmap reads should be orthogonal to WalDir setting , so we piggyback to <nl> + / / this option config to test mmap reads as well <nl> + options . allow_mmap_reads = true ; <nl> + break ; <nl> + case kManifestFileSize : <nl> + options . max_manifest_file_size = 50 ; / / 50 bytes <nl> + case kCompactOnFlush : <nl> + options . purge_redundant_kvs_while_flush = <nl> + ! options . purge_redundant_kvs_while_flush ; <nl> + break ; <nl> + case kPerfOptions : <nl> + options . soft_rate_limit = 2 . 0 ; <nl> + options . delayed_write_rate = 8 * 1024 * 1024 ; <nl> + / / TODO ( 3 . 13 ) - - test more options <nl> + break ; <nl> + case kDeletesFilterFirst : <nl> + options . filter_deletes = true ; <nl> + break ; <nl> + case kVectorRep : <nl> + options . memtable_factory . reset ( new VectorRepFactory ( 100 ) ) ; <nl> + break ; <nl> + case kHashLinkList : <nl> + options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> + options . memtable_factory . reset ( <nl> + NewHashLinkListRepFactory ( 4 , 0 , 3 , true , 4 ) ) ; <nl> + break ; <nl> + case kHashCuckoo : <nl> + options . memtable_factory . reset ( <nl> + NewHashCuckooRepFactory ( options . write_buffer_size ) ) ; <nl> + break ; <nl> + case kUniversalCompaction : <nl> + options . compaction_style = kCompactionStyleUniversal ; <nl> + options . num_levels = 1 ; <nl> + break ; <nl> + case kUniversalCompactionMultiLevel : <nl> + options . compaction_style = kCompactionStyleUniversal ; <nl> + options . num_levels = 8 ; <nl> + break ; <nl> + case kCompressedBlockCache : <nl> + options . allow_mmap_writes = true ; <nl> + table_options . block_cache_compressed = NewLRUCache ( 8 * 1024 * 1024 ) ; <nl> + break ; <nl> + case kInfiniteMaxOpenFiles : <nl> + options . max_open_files = - 1 ; <nl> + break ; <nl> + case kxxHashChecksum : { <nl> + table_options . checksum = kxxHash ; <nl> + break ; <nl> + } <nl> + case kFIFOCompaction : { <nl> + options . compaction_style = kCompactionStyleFIFO ; <nl> + break ; <nl> + } <nl> + case kBlockBasedTableWithPrefixHashIndex : { <nl> + table_options . index_type = BlockBasedTableOptions : : kHashSearch ; <nl> + options . prefix_extractor . reset ( NewFixedPrefixTransform ( 1 ) ) ; <nl> + break ; <nl> + } <nl> + case kBlockBasedTableWithWholeKeyHashIndex : { <nl> + table_options . index_type = BlockBasedTableOptions : : kHashSearch ; <nl> + options . prefix_extractor . reset ( NewNoopTransform ( ) ) ; <nl> + break ; <nl> + } <nl> + case kOptimizeFiltersForHits : { <nl> + options . optimize_filters_for_hits = true ; <nl> + set_block_based_table_factory = true ; <nl> + break ; <nl> + } <nl> + case kRowCache : { <nl> + options . row_cache = NewLRUCache ( 1024 * 1024 ) ; <nl> + break ; <nl> + } <nl> + <nl> + default : <nl> + break ; <nl> + } <nl> + <nl> + if ( options_override . filter_policy ) { <nl> + table_options . filter_policy = options_override . filter_policy ; <nl> + } <nl> + if ( set_block_based_table_factory ) { <nl> + options . table_factory . reset ( NewBlockBasedTableFactory ( table_options ) ) ; <nl> + } <nl> + options . env = env_ ; <nl> + options . create_if_missing = true ; <nl> + return options ; <nl> + } <nl> + <nl> + void DBTestBase : : CreateColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) { <nl> + ColumnFamilyOptions cf_opts ( options ) ; <nl> + size_t cfi = handles_ . size ( ) ; <nl> + handles_ . resize ( cfi + cfs . size ( ) ) ; <nl> + for ( auto cf : cfs ) { <nl> + ASSERT_OK ( db_ - > CreateColumnFamily ( cf_opts , cf , & handles_ [ cfi + + ] ) ) ; <nl> + } <nl> + } <nl> + <nl> + void DBTestBase : : CreateAndReopenWithCF ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) { <nl> + CreateColumnFamilies ( cfs , options ) ; <nl> + std : : vector < std : : string > cfs_plus_default = cfs ; <nl> + cfs_plus_default . insert ( cfs_plus_default . begin ( ) , kDefaultColumnFamilyName ) ; <nl> + ReopenWithColumnFamilies ( cfs_plus_default , options ) ; <nl> + } <nl> + <nl> + void DBTestBase : : ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const std : : vector < Options > & options ) { <nl> + ASSERT_OK ( TryReopenWithColumnFamilies ( cfs , options ) ) ; <nl> + } <nl> + <nl> + void DBTestBase : : ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) { <nl> + ASSERT_OK ( TryReopenWithColumnFamilies ( cfs , options ) ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : TryReopenWithColumnFamilies ( <nl> + const std : : vector < std : : string > & cfs , <nl> + const std : : vector < Options > & options ) { <nl> + Close ( ) ; <nl> + EXPECT_EQ ( cfs . size ( ) , options . size ( ) ) ; <nl> + std : : vector < ColumnFamilyDescriptor > column_families ; <nl> + for ( size_t i = 0 ; i < cfs . size ( ) ; + + i ) { <nl> + column_families . push_back ( ColumnFamilyDescriptor ( cfs [ i ] , options [ i ] ) ) ; <nl> + } <nl> + DBOptions db_opts = DBOptions ( options [ 0 ] ) ; <nl> + return DB : : Open ( db_opts , dbname_ , column_families , & handles_ , & db_ ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : TryReopenWithColumnFamilies ( <nl> + const std : : vector < std : : string > & cfs , <nl> + const Options & options ) { <nl> + Close ( ) ; <nl> + std : : vector < Options > v_opts ( cfs . size ( ) , options ) ; <nl> + return TryReopenWithColumnFamilies ( cfs , v_opts ) ; <nl> + } <nl> + <nl> + void DBTestBase : : Reopen ( const Options & options ) { <nl> + ASSERT_OK ( TryReopen ( options ) ) ; <nl> + } <nl> + <nl> + void DBTestBase : : Close ( ) { <nl> + for ( auto h : handles_ ) { <nl> + delete h ; <nl> + } <nl> + handles_ . clear ( ) ; <nl> + delete db_ ; <nl> + db_ = nullptr ; <nl> + } <nl> + <nl> + void DBTestBase : : DestroyAndReopen ( const Options & options ) { <nl> + / / Destroy using last options <nl> + Destroy ( last_options_ ) ; <nl> + ASSERT_OK ( TryReopen ( options ) ) ; <nl> + } <nl> + <nl> + void DBTestBase : : Destroy ( const Options & options ) { <nl> + Close ( ) ; <nl> + ASSERT_OK ( DestroyDB ( dbname_ , options ) ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : ReadOnlyReopen ( const Options & options ) { <nl> + return DB : : OpenForReadOnly ( options , dbname_ , & db_ ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : TryReopen ( const Options & options ) { <nl> + Close ( ) ; <nl> + last_options_ = options ; <nl> + return DB : : Open ( options , dbname_ , & db_ ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : Flush ( int cf ) { <nl> + if ( cf = = 0 ) { <nl> + return db_ - > Flush ( FlushOptions ( ) ) ; <nl> + } else { <nl> + return db_ - > Flush ( FlushOptions ( ) , handles_ [ cf ] ) ; <nl> + } <nl> + } <nl> + <nl> + Status DBTestBase : : Put ( const Slice & k , const Slice & v , WriteOptions wo ) { <nl> + if ( kMergePut = = option_config_ ) { <nl> + return db_ - > Merge ( wo , k , v ) ; <nl> + } else { <nl> + return db_ - > Put ( wo , k , v ) ; <nl> + } <nl> + } <nl> + <nl> + Status DBTestBase : : Put ( int cf , const Slice & k , const Slice & v , <nl> + WriteOptions wo ) { <nl> + if ( kMergePut = = option_config_ ) { <nl> + return db_ - > Merge ( wo , handles_ [ cf ] , k , v ) ; <nl> + } else { <nl> + return db_ - > Put ( wo , handles_ [ cf ] , k , v ) ; <nl> + } <nl> + } <nl> + <nl> + Status DBTestBase : : Delete ( const std : : string & k ) { <nl> + return db_ - > Delete ( WriteOptions ( ) , k ) ; <nl> + } <nl> + <nl> + Status DBTestBase : : Delete ( int cf , const std : : string & k ) { <nl> + return db_ - > Delete ( WriteOptions ( ) , handles_ [ cf ] , k ) ; <nl> + } <nl> + <nl> + std : : string DBTestBase : : Get ( const std : : string & k , const Snapshot * snapshot ) { <nl> + ReadOptions options ; <nl> + options . verify_checksums = true ; <nl> + options . snapshot = snapshot ; <nl> + std : : string result ; <nl> + Status s = db_ - > Get ( options , k , & result ) ; <nl> + if ( s . IsNotFound ( ) ) { <nl> + result = " NOT_FOUND " ; <nl> + } else if ( ! s . ok ( ) ) { <nl> + result = s . ToString ( ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + std : : string DBTestBase : : Get ( int cf , const std : : string & k , <nl> + const Snapshot * snapshot ) { <nl> + ReadOptions options ; <nl> + options . verify_checksums = true ; <nl> + options . snapshot = snapshot ; <nl> + std : : string result ; <nl> + Status s = db_ - > Get ( options , handles_ [ cf ] , k , & result ) ; <nl> + if ( s . IsNotFound ( ) ) { <nl> + result = " NOT_FOUND " ; <nl> + } else if ( ! s . ok ( ) ) { <nl> + result = s . ToString ( ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + uint64_t DBTestBase : : GetNumSnapshots ( ) { <nl> + uint64_t int_num ; <nl> + EXPECT_TRUE ( dbfull ( ) - > GetIntProperty ( " rocksdb . num - snapshots " , & int_num ) ) ; <nl> + return int_num ; <nl> + } <nl> + <nl> + uint64_t DBTestBase : : GetTimeOldestSnapshots ( ) { <nl> + uint64_t int_num ; <nl> + EXPECT_TRUE ( <nl> + dbfull ( ) - > GetIntProperty ( " rocksdb . oldest - snapshot - time " , & int_num ) ) ; <nl> + return int_num ; <nl> + } <nl> + <nl> + / / Return a string that contains all key , value pairs in order , <nl> + / / formatted like " ( k1 - > v1 ) ( k2 - > v2 ) " . <nl> + std : : string DBTestBase : : Contents ( int cf ) { <nl> + std : : vector < std : : string > forward ; <nl> + std : : string result ; <nl> + Iterator * iter = ( cf = = 0 ) ? db_ - > NewIterator ( ReadOptions ( ) ) <nl> + : db_ - > NewIterator ( ReadOptions ( ) , handles_ [ cf ] ) ; <nl> + for ( iter - > SeekToFirst ( ) ; iter - > Valid ( ) ; iter - > Next ( ) ) { <nl> + std : : string s = IterStatus ( iter ) ; <nl> + result . push_back ( ' ( ' ) ; <nl> + result . append ( s ) ; <nl> + result . push_back ( ' ) ' ) ; <nl> + forward . push_back ( s ) ; <nl> + } <nl> + <nl> + / / Check reverse iteration results are the reverse of forward results <nl> + unsigned int matched = 0 ; <nl> + for ( iter - > SeekToLast ( ) ; iter - > Valid ( ) ; iter - > Prev ( ) ) { <nl> + EXPECT_LT ( matched , forward . size ( ) ) ; <nl> + EXPECT_EQ ( IterStatus ( iter ) , forward [ forward . size ( ) - matched - 1 ] ) ; <nl> + matched + + ; <nl> + } <nl> + EXPECT_EQ ( matched , forward . size ( ) ) ; <nl> + <nl> + delete iter ; <nl> + return result ; <nl> + } <nl> + <nl> + std : : string DBTestBase : : AllEntriesFor ( const Slice & user_key , int cf ) { <nl> + Arena arena ; <nl> + ScopedArenaIterator iter ; <nl> + if ( cf = = 0 ) { <nl> + iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena ) ) ; <nl> + } else { <nl> + iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena , handles_ [ cf ] ) ) ; <nl> + } <nl> + InternalKey target ( user_key , kMaxSequenceNumber , kTypeValue ) ; <nl> + iter - > Seek ( target . Encode ( ) ) ; <nl> + std : : string result ; <nl> + if ( ! iter - > status ( ) . ok ( ) ) { <nl> + result = iter - > status ( ) . ToString ( ) ; <nl> + } else { <nl> + result = " [ " ; <nl> + bool first = true ; <nl> + while ( iter - > Valid ( ) ) { <nl> + ParsedInternalKey ikey ( Slice ( ) , 0 , kTypeValue ) ; <nl> + if ( ! ParseInternalKey ( iter - > key ( ) , & ikey ) ) { <nl> + result + = " CORRUPTED " ; <nl> + } else { <nl> + if ( last_options_ . comparator - > Compare ( ikey . user_key , user_key ) ! = 0 ) { <nl> + break ; <nl> + } <nl> + if ( ! first ) { <nl> + result + = " , " ; <nl> + } <nl> + first = false ; <nl> + switch ( ikey . type ) { <nl> + case kTypeValue : <nl> + result + = iter - > value ( ) . ToString ( ) ; <nl> + break ; <nl> + case kTypeMerge : <nl> + / / keep it the same as kTypeValue for testing kMergePut <nl> + result + = iter - > value ( ) . ToString ( ) ; <nl> + break ; <nl> + case kTypeDeletion : <nl> + result + = " DEL " ; <nl> + break ; <nl> + default : <nl> + assert ( false ) ; <nl> + break ; <nl> + } <nl> + } <nl> + iter - > Next ( ) ; <nl> + } <nl> + if ( ! first ) { <nl> + result + = " " ; <nl> + } <nl> + result + = " ] " ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + int DBTestBase : : NumSortedRuns ( int cf ) { <nl> + ColumnFamilyMetaData cf_meta ; <nl> + if ( cf = = 0 ) { <nl> + db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> + } else { <nl> + db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> + } <nl> + int num_sr = static_cast < int > ( cf_meta . levels [ 0 ] . files . size ( ) ) ; <nl> + for ( size_t i = 1U ; i < cf_meta . levels . size ( ) ; i + + ) { <nl> + if ( cf_meta . levels [ i ] . files . size ( ) > 0 ) { <nl> + num_sr + + ; <nl> + } <nl> + } <nl> + return num_sr ; <nl> + } <nl> + <nl> + uint64_t DBTestBase : : TotalSize ( int cf ) { <nl> + ColumnFamilyMetaData cf_meta ; <nl> + if ( cf = = 0 ) { <nl> + db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> + } else { <nl> + db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> + } <nl> + return cf_meta . size ; <nl> + } <nl> + <nl> + int DBTestBase : : NumTableFilesAtLevel ( int level , int cf ) { <nl> + std : : string property ; <nl> + if ( cf = = 0 ) { <nl> + / / default cfd <nl> + EXPECT_TRUE ( db_ - > GetProperty ( <nl> + " rocksdb . num - files - at - level " + NumberToString ( level ) , & property ) ) ; <nl> + } else { <nl> + EXPECT_TRUE ( db_ - > GetProperty ( <nl> + handles_ [ cf ] , " rocksdb . num - files - at - level " + NumberToString ( level ) , <nl> + & property ) ) ; <nl> + } <nl> + return atoi ( property . c_str ( ) ) ; <nl> + } <nl> + <nl> + uint64_t DBTestBase : : SizeAtLevel ( int level ) { <nl> + std : : vector < LiveFileMetaData > metadata ; <nl> + db_ - > GetLiveFilesMetaData ( & metadata ) ; <nl> + uint64_t sum = 0 ; <nl> + for ( const auto & m : metadata ) { <nl> + if ( m . level = = level ) { <nl> + sum + = m . size ; <nl> + } <nl> + } <nl> + return sum ; <nl> + } <nl> + <nl> + int DBTestBase : : TotalLiveFiles ( int cf ) { <nl> + ColumnFamilyMetaData cf_meta ; <nl> + if ( cf = = 0 ) { <nl> + db_ - > GetColumnFamilyMetaData ( & cf_meta ) ; <nl> + } else { <nl> + db_ - > GetColumnFamilyMetaData ( handles_ [ cf ] , & cf_meta ) ; <nl> + } <nl> + int num_files = 0 ; <nl> + for ( auto & level : cf_meta . levels ) { <nl> + num_files + = level . files . size ( ) ; <nl> + } <nl> + return num_files ; <nl> + } <nl> + <nl> + int DBTestBase : : TotalTableFiles ( int cf , int levels ) { <nl> + if ( levels = = - 1 ) { <nl> + levels = CurrentOptions ( ) . num_levels ; <nl> + } <nl> + int result = 0 ; <nl> + for ( int level = 0 ; level < levels ; level + + ) { <nl> + result + = NumTableFilesAtLevel ( level , cf ) ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + / / Return spread of files per level <nl> + std : : string DBTestBase : : FilesPerLevel ( int cf ) { <nl> + int num_levels = <nl> + ( cf = = 0 ) ? db_ - > NumberLevels ( ) : db_ - > NumberLevels ( handles_ [ 1 ] ) ; <nl> + std : : string result ; <nl> + size_t last_non_zero_offset = 0 ; <nl> + for ( int level = 0 ; level < num_levels ; level + + ) { <nl> + int f = NumTableFilesAtLevel ( level , cf ) ; <nl> + char buf [ 100 ] ; <nl> + snprintf ( buf , sizeof ( buf ) , " % s % d " , ( level ? " , " : " " ) , f ) ; <nl> + result + = buf ; <nl> + if ( f > 0 ) { <nl> + last_non_zero_offset = result . size ( ) ; <nl> + } <nl> + } <nl> + result . resize ( last_non_zero_offset ) ; <nl> + return result ; <nl> + } <nl> + <nl> + size_t DBTestBase : : CountFiles ( ) { <nl> + std : : vector < std : : string > files ; <nl> + env_ - > GetChildren ( dbname_ , & files ) ; <nl> + <nl> + std : : vector < std : : string > logfiles ; <nl> + if ( dbname_ ! = last_options_ . wal_dir ) { <nl> + env_ - > GetChildren ( last_options_ . wal_dir , & logfiles ) ; <nl> + } <nl> + <nl> + return files . size ( ) + logfiles . size ( ) ; <nl> + } <nl> + <nl> + size_t DBTestBase : : CountLiveFiles ( ) { <nl> + std : : vector < LiveFileMetaData > metadata ; <nl> + db_ - > GetLiveFilesMetaData ( & metadata ) ; <nl> + return metadata . size ( ) ; <nl> + } <nl> + <nl> + uint64_t DBTestBase : : Size ( const Slice & start , const Slice & limit , int cf ) { <nl> + Range r ( start , limit ) ; <nl> + uint64_t size ; <nl> + if ( cf = = 0 ) { <nl> + db_ - > GetApproximateSizes ( & r , 1 , & size ) ; <nl> + } else { <nl> + db_ - > GetApproximateSizes ( handles_ [ 1 ] , & r , 1 , & size ) ; <nl> + } <nl> + return size ; <nl> + } <nl> + <nl> + void DBTestBase : : Compact ( int cf , const Slice & start , const Slice & limit , <nl> + uint32_t target_path_id ) { <nl> + CompactRangeOptions compact_options ; <nl> + compact_options . target_path_id = target_path_id ; <nl> + ASSERT_OK ( db_ - > CompactRange ( compact_options , handles_ [ cf ] , & start , & limit ) ) ; <nl> + } <nl> + <nl> + void DBTestBase : : Compact ( int cf , const Slice & start , const Slice & limit ) { <nl> + ASSERT_OK ( <nl> + db_ - > CompactRange ( CompactRangeOptions ( ) , handles_ [ cf ] , & start , & limit ) ) ; <nl> + } <nl> + <nl> + void DBTestBase : : Compact ( const Slice & start , const Slice & limit ) { <nl> + ASSERT_OK ( db_ - > CompactRange ( CompactRangeOptions ( ) , & start , & limit ) ) ; <nl> + } <nl> + <nl> + / / Do n memtable compactions , each of which produces an sstable <nl> + / / covering the range [ small , large ] . <nl> + void DBTestBase : : MakeTables ( <nl> + int n , const std : : string & small , <nl> + const std : : string & large , int cf ) { <nl> + for ( int i = 0 ; i < n ; i + + ) { <nl> + ASSERT_OK ( Put ( cf , small , " begin " ) ) ; <nl> + ASSERT_OK ( Put ( cf , large , " end " ) ) ; <nl> + ASSERT_OK ( Flush ( cf ) ) ; <nl> + } <nl> + } <nl> + <nl> + / / Prevent pushing of new sstables into deeper levels by adding <nl> + / / tables that cover a specified range to all levels . <nl> + void DBTestBase : : FillLevels ( <nl> + const std : : string & smallest , const std : : string & largest , int cf ) { <nl> + MakeTables ( db_ - > NumberLevels ( handles_ [ cf ] ) , smallest , largest , cf ) ; <nl> + } <nl> + <nl> + void DBTestBase : : DumpFileCounts ( const char * label ) { <nl> + fprintf ( stderr , " mmm \ n % s : \ n " , label ) ; <nl> + fprintf ( stderr , " maxoverlap : % " PRIu64 " \ n " , <nl> + dbfull ( ) - > TEST_MaxNextLevelOverlappingBytes ( ) ) ; <nl> + for ( int level = 0 ; level < db_ - > NumberLevels ( ) ; level + + ) { <nl> + int num = NumTableFilesAtLevel ( level ) ; <nl> + if ( num > 0 ) { <nl> + fprintf ( stderr , " level % 3d : % d files \ n " , level , num ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + std : : string DBTestBase : : DumpSSTableList ( ) { <nl> + std : : string property ; <nl> + db_ - > GetProperty ( " rocksdb . sstables " , & property ) ; <nl> + return property ; <nl> + } <nl> + <nl> + int DBTestBase : : GetSstFileCount ( std : : string path ) { <nl> + std : : vector < std : : string > files ; <nl> + env_ - > GetChildren ( path , & files ) ; <nl> + <nl> + int sst_count = 0 ; <nl> + uint64_t number ; <nl> + FileType type ; <nl> + for ( size_t i = 0 ; i < files . size ( ) ; i + + ) { <nl> + if ( ParseFileName ( files [ i ] , & number , & type ) & & type = = kTableFile ) { <nl> + sst_count + + ; <nl> + } <nl> + } <nl> + return sst_count ; <nl> + } <nl> + <nl> + / / this will generate non - overlapping files since it keeps increasing key_idx <nl> + void DBTestBase : : GenerateNewFile ( Random * rnd , int * key_idx , bool nowait ) { <nl> + for ( int i = 0 ; i < 11 ; i + + ) { <nl> + ASSERT_OK ( Put ( Key ( * key_idx ) , RandomString ( rnd , ( i = = 10 ) ? 1 : 10000 ) ) ) ; <nl> + ( * key_idx ) + + ; <nl> + } <nl> + if ( ! nowait ) { <nl> + dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ; <nl> + dbfull ( ) - > TEST_WaitForCompact ( ) ; <nl> + } <nl> + } <nl> + <nl> + void DBTestBase : : GenerateNewRandomFile ( Random * rnd , bool nowait ) { <nl> + for ( int i = 0 ; i < 100 ; i + + ) { <nl> + ASSERT_OK ( Put ( " key " + RandomString ( rnd , 7 ) , RandomString ( rnd , 1000 ) ) ) ; <nl> + } <nl> + ASSERT_OK ( Put ( " key " + RandomString ( rnd , 7 ) , RandomString ( rnd , 1 ) ) ) ; <nl> + if ( ! nowait ) { <nl> + dbfull ( ) - > TEST_WaitForFlushMemTable ( ) ; <nl> + dbfull ( ) - > TEST_WaitForCompact ( ) ; <nl> + } <nl> + } <nl> + <nl> + std : : string DBTestBase : : IterStatus ( Iterator * iter ) { <nl> + std : : string result ; <nl> + if ( iter - > Valid ( ) ) { <nl> + result = iter - > key ( ) . ToString ( ) + " - > " + iter - > value ( ) . ToString ( ) ; <nl> + } else { <nl> + result = " ( invalid ) " ; <nl> + } <nl> + return result ; <nl> + } <nl> + <nl> + Options DBTestBase : : OptionsForLogIterTest ( ) { <nl> + Options options = CurrentOptions ( ) ; <nl> + options . create_if_missing = true ; <nl> + options . WAL_ttl_seconds = 1000 ; <nl> + return options ; <nl> + } <nl> + <nl> + std : : unique_ptr < TransactionLogIterator > DBTestBase : : OpenTransactionLogIter ( <nl> + const SequenceNumber seq ) { <nl> + unique_ptr < TransactionLogIterator > iter ; <nl> + Status status = dbfull ( ) - > GetUpdatesSince ( seq , & iter ) ; <nl> + EXPECT_OK ( status ) ; <nl> + EXPECT_TRUE ( iter - > Valid ( ) ) ; <nl> + return std : : move ( iter ) ; <nl> + } <nl> + <nl> + std : : string DBTestBase : : DummyString ( size_t len , char c ) { <nl> + return std : : string ( len , c ) ; <nl> + } <nl> + <nl> + void DBTestBase : : VerifyIterLast ( std : : string expected_key , int cf ) { <nl> + Iterator * iter ; <nl> + ReadOptions ro ; <nl> + if ( cf = = 0 ) { <nl> + iter = db_ - > NewIterator ( ro ) ; <nl> + } else { <nl> + iter = db_ - > NewIterator ( ro , handles_ [ cf ] ) ; <nl> + } <nl> + iter - > SeekToLast ( ) ; <nl> + ASSERT_EQ ( IterStatus ( iter ) , expected_key ) ; <nl> + delete iter ; <nl> + } <nl> + <nl> + / / Used to test InplaceUpdate <nl> + <nl> + / / If previous value is nullptr or delta is > than previous value , <nl> + / / sets newValue with delta <nl> + / / If previous value is not empty , <nl> + / / updates previous value with ' b ' string of previous value size - 1 . <nl> + UpdateStatus DBTestBase : : updateInPlaceSmallerSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) { <nl> + if ( prevValue = = nullptr ) { <nl> + * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> + return UpdateStatus : : UPDATED ; <nl> + } else { <nl> + * prevSize = * prevSize - 1 ; <nl> + std : : string str_b = std : : string ( * prevSize , ' b ' ) ; <nl> + memcpy ( prevValue , str_b . c_str ( ) , str_b . size ( ) ) ; <nl> + return UpdateStatus : : UPDATED_INPLACE ; <nl> + } <nl> + } <nl> + <nl> + UpdateStatus DBTestBase : : updateInPlaceSmallerVarintSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) { <nl> + if ( prevValue = = nullptr ) { <nl> + * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> + return UpdateStatus : : UPDATED ; <nl> + } else { <nl> + * prevSize = 1 ; <nl> + std : : string str_b = std : : string ( * prevSize , ' b ' ) ; <nl> + memcpy ( prevValue , str_b . c_str ( ) , str_b . size ( ) ) ; <nl> + return UpdateStatus : : UPDATED_INPLACE ; <nl> + } <nl> + } <nl> + <nl> + UpdateStatus DBTestBase : : updateInPlaceLargerSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) { <nl> + * newValue = std : : string ( delta . size ( ) , ' c ' ) ; <nl> + return UpdateStatus : : UPDATED ; <nl> + } <nl> + <nl> + UpdateStatus DBTestBase : : updateInPlaceNoAction ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) { <nl> + return UpdateStatus : : UPDATE_FAILED ; <nl> + } <nl> + <nl> + / / Utility method to test InplaceUpdate <nl> + void DBTestBase : : validateNumberOfEntries ( int numValues , int cf ) { <nl> + ScopedArenaIterator iter ; <nl> + Arena arena ; <nl> + if ( cf ! = 0 ) { <nl> + iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena , handles_ [ cf ] ) ) ; <nl> + } else { <nl> + iter . set ( dbfull ( ) - > TEST_NewInternalIterator ( & arena ) ) ; <nl> + } <nl> + iter - > SeekToFirst ( ) ; <nl> + ASSERT_EQ ( iter - > status ( ) . ok ( ) , true ) ; <nl> + int seq = numValues ; <nl> + while ( iter - > Valid ( ) ) { <nl> + ParsedInternalKey ikey ; <nl> + ikey . sequence = - 1 ; <nl> + ASSERT_EQ ( ParseInternalKey ( iter - > key ( ) , & ikey ) , true ) ; <nl> + <nl> + / / checks sequence number for updates <nl> + ASSERT_EQ ( ikey . sequence , ( unsigned ) seq - - ) ; <nl> + iter - > Next ( ) ; <nl> + } <nl> + ASSERT_EQ ( 0 , seq ) ; <nl> + } <nl> + <nl> + void DBTestBase : : CopyFile ( <nl> + const std : : string & source , const std : : string & destination , <nl> + uint64_t size ) { <nl> + const EnvOptions soptions ; <nl> + unique_ptr < SequentialFile > srcfile ; <nl> + ASSERT_OK ( env_ - > NewSequentialFile ( source , & srcfile , soptions ) ) ; <nl> + unique_ptr < WritableFile > destfile ; <nl> + ASSERT_OK ( env_ - > NewWritableFile ( destination , & destfile , soptions ) ) ; <nl> + <nl> + if ( size = = 0 ) { <nl> + / / default argument means copy everything <nl> + ASSERT_OK ( env_ - > GetFileSize ( source , & size ) ) ; <nl> + } <nl> + <nl> + char buffer [ 4096 ] ; <nl> + Slice slice ; <nl> + while ( size > 0 ) { <nl> + uint64_t one = std : : min ( uint64_t ( sizeof ( buffer ) ) , size ) ; <nl> + ASSERT_OK ( srcfile - > Read ( one , & slice , buffer ) ) ; <nl> + ASSERT_OK ( destfile - > Append ( slice ) ) ; <nl> + size - = slice . size ( ) ; <nl> + } <nl> + ASSERT_OK ( destfile - > Close ( ) ) ; <nl> + } <nl> + <nl> + } / / namespace rocksdb <nl> new file mode 100644 <nl> index 0000000000 . . c64c62a439 <nl> mmm / dev / null <nl> ppp b / util / db_test_util . h <nl> <nl> + / / Copyright ( c ) 2013 , Facebook , Inc . All rights reserved . <nl> + / / This source code is licensed under the BSD - style license found in the <nl> + / / LICENSE file in the root directory of this source tree . An additional grant <nl> + / / of patent rights can be found in the PATENTS file in the same directory . <nl> + / / <nl> + / / Copyright ( c ) 2011 The LevelDB Authors . All rights reserved . <nl> + / / Use of this source code is governed by a BSD - style license that can be <nl> + / / found in the LICENSE file . See the AUTHORS file for names of contributors . <nl> + <nl> + # pragma once <nl> + # ifndef __STDC_FORMAT_MACROS <nl> + # define __STDC_FORMAT_MACROS <nl> + # endif <nl> + <nl> + # include < fcntl . h > <nl> + # include < inttypes . h > <nl> + # include < unistd . h > <nl> + <nl> + # include < algorithm > <nl> + # include < set > <nl> + # include < string > <nl> + # include < thread > <nl> + # include < unordered_set > <nl> + # include < utility > <nl> + # include < vector > <nl> + <nl> + # include " db / db_impl . h " <nl> + # include " db / dbformat . h " <nl> + # include " db / filename . h " <nl> + # include " rocksdb / cache . h " <nl> + # include " rocksdb / compaction_filter . h " <nl> + # include " rocksdb / db . h " <nl> + # include " rocksdb / env . h " <nl> + # include " rocksdb / filter_policy . h " <nl> + # include " rocksdb / options . h " <nl> + # include " rocksdb / slice . h " <nl> + # include " rocksdb / table . h " <nl> + # include " rocksdb / utilities / checkpoint . h " <nl> + # include " rocksdb / utilities / convenience . h " <nl> + # include " table / block_based_table_factory . h " <nl> + # include " table / mock_table . h " <nl> + # include " table / plain_table_factory . h " <nl> + # include " util / compression . h " <nl> + # include " util / db_test_util . h " <nl> + # include " util / hash_linklist_rep . h " <nl> + # include " util / mock_env . h " <nl> + # include " util / mutexlock . h " <nl> + # include " util / scoped_arena_iterator . h " <nl> + # include " util / string_util . h " <nl> + # include " util / sync_point . h " <nl> + # include " util / testharness . h " <nl> + # include " util / testutil . h " <nl> + # include " util / xfunc . h " <nl> + # include " utilities / merge_operators . h " <nl> + <nl> + namespace rocksdb { <nl> + <nl> + static std : : string RandomString ( Random * rnd , int len ) { <nl> + std : : string r ; <nl> + test : : RandomString ( rnd , len , & r ) ; <nl> + return r ; <nl> + } <nl> + <nl> + namespace anon { <nl> + class AtomicCounter { <nl> + public : <nl> + explicit AtomicCounter ( Env * env = NULL ) <nl> + : env_ ( env ) , cond_count_ ( & mu_ ) , count_ ( 0 ) { } <nl> + <nl> + void Increment ( ) { <nl> + MutexLock l ( & mu_ ) ; <nl> + count_ + + ; <nl> + cond_count_ . SignalAll ( ) ; <nl> + } <nl> + <nl> + int Read ( ) { <nl> + MutexLock l ( & mu_ ) ; <nl> + return count_ ; <nl> + } <nl> + <nl> + bool WaitFor ( int count ) { <nl> + MutexLock l ( & mu_ ) ; <nl> + <nl> + uint64_t start = env_ - > NowMicros ( ) ; <nl> + while ( count_ < count ) { <nl> + uint64_t now = env_ - > NowMicros ( ) ; <nl> + cond_count_ . TimedWait ( now + / * 1s * / 1 * 000 * 000 ) ; <nl> + if ( env_ - > NowMicros ( ) - start > / * 10s * / 10 * 000 * 000 ) { <nl> + return false ; <nl> + } <nl> + if ( count_ < count ) { <nl> + GTEST_LOG_ ( WARNING ) < < " WaitFor is taking more time than usual " ; <nl> + } <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + void Reset ( ) { <nl> + MutexLock l ( & mu_ ) ; <nl> + count_ = 0 ; <nl> + cond_count_ . SignalAll ( ) ; <nl> + } <nl> + <nl> + private : <nl> + Env * env_ ; <nl> + port : : Mutex mu_ ; <nl> + port : : CondVar cond_count_ ; <nl> + int count_ ; <nl> + } ; <nl> + <nl> + struct OptionsOverride { <nl> + std : : shared_ptr < const FilterPolicy > filter_policy = nullptr ; <nl> + <nl> + / / Used as a bit mask of individual enums in which to skip an XF test point <nl> + int skip_policy = 0 ; <nl> + } ; <nl> + <nl> + } / / namespace anon <nl> + <nl> + static std : : string Key ( int i ) { <nl> + char buf [ 100 ] ; <nl> + snprintf ( buf , sizeof ( buf ) , " key % 06d " , i ) ; <nl> + return std : : string ( buf ) ; <nl> + } <nl> + <nl> + / / Special Env used to delay background operations <nl> + class SpecialEnv : public EnvWrapper { <nl> + public : <nl> + explicit SpecialEnv ( Env * base ) ; <nl> + <nl> + Status NewWritableFile ( const std : : string & f , unique_ptr < WritableFile > * r , <nl> + const EnvOptions & soptions ) override { <nl> + class SSTableFile : public WritableFile { <nl> + private : <nl> + SpecialEnv * env_ ; <nl> + unique_ptr < WritableFile > base_ ; <nl> + <nl> + public : <nl> + SSTableFile ( SpecialEnv * env , unique_ptr < WritableFile > & & base ) <nl> + : env_ ( env ) , <nl> + base_ ( std : : move ( base ) ) { <nl> + } <nl> + Status Append ( const Slice & data ) override { <nl> + if ( env_ - > table_write_callback_ ) { <nl> + ( * env_ - > table_write_callback_ ) ( ) ; <nl> + } <nl> + if ( env_ - > drop_writes_ . load ( std : : memory_order_acquire ) ) { <nl> + / / Drop writes on the floor <nl> + return Status : : OK ( ) ; <nl> + } else if ( env_ - > no_space_ . load ( std : : memory_order_acquire ) ) { <nl> + return Status : : IOError ( " No space left on device " ) ; <nl> + } else { <nl> + env_ - > bytes_written_ + = data . size ( ) ; <nl> + return base_ - > Append ( data ) ; <nl> + } <nl> + } <nl> + Status Close ( ) override { <nl> + / / Check preallocation size <nl> + / / preallocation size is never passed to base file . <nl> + size_t preallocation_size = preallocation_block_size ( ) ; <nl> + TEST_SYNC_POINT_CALLBACK ( " DBTestWritableFile . GetPreallocationStatus " , <nl> + & preallocation_size ) ; <nl> + return base_ - > Close ( ) ; <nl> + } <nl> + Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> + Status Sync ( ) override { <nl> + + + env_ - > sync_counter_ ; <nl> + while ( env_ - > delay_sstable_sync_ . load ( std : : memory_order_acquire ) ) { <nl> + env_ - > SleepForMicroseconds ( 100000 ) ; <nl> + } <nl> + return base_ - > Sync ( ) ; <nl> + } <nl> + void SetIOPriority ( Env : : IOPriority pri ) override { <nl> + base_ - > SetIOPriority ( pri ) ; <nl> + } <nl> + } ; <nl> + class ManifestFile : public WritableFile { <nl> + public : <nl> + ManifestFile ( SpecialEnv * env , unique_ptr < WritableFile > & & b ) <nl> + : env_ ( env ) , base_ ( std : : move ( b ) ) { } <nl> + Status Append ( const Slice & data ) override { <nl> + if ( env_ - > manifest_write_error_ . load ( std : : memory_order_acquire ) ) { <nl> + return Status : : IOError ( " simulated writer error " ) ; <nl> + } else { <nl> + return base_ - > Append ( data ) ; <nl> + } <nl> + } <nl> + Status Close ( ) override { return base_ - > Close ( ) ; } <nl> + Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> + Status Sync ( ) override { <nl> + + + env_ - > sync_counter_ ; <nl> + if ( env_ - > manifest_sync_error_ . load ( std : : memory_order_acquire ) ) { <nl> + return Status : : IOError ( " simulated sync error " ) ; <nl> + } else { <nl> + return base_ - > Sync ( ) ; <nl> + } <nl> + } <nl> + uint64_t GetFileSize ( ) override { return base_ - > GetFileSize ( ) ; } <nl> + <nl> + private : <nl> + SpecialEnv * env_ ; <nl> + unique_ptr < WritableFile > base_ ; <nl> + } ; <nl> + class WalFile : public WritableFile { <nl> + public : <nl> + WalFile ( SpecialEnv * env , unique_ptr < WritableFile > & & b ) <nl> + : env_ ( env ) , base_ ( std : : move ( b ) ) { } <nl> + Status Append ( const Slice & data ) override { <nl> + if ( env_ - > log_write_error_ . load ( std : : memory_order_acquire ) ) { <nl> + return Status : : IOError ( " simulated writer error " ) ; <nl> + } else { <nl> + int slowdown = <nl> + env_ - > log_write_slowdown_ . load ( std : : memory_order_acquire ) ; <nl> + if ( slowdown > 0 ) { <nl> + env_ - > SleepForMicroseconds ( slowdown ) ; <nl> + } <nl> + return base_ - > Append ( data ) ; <nl> + } <nl> + } <nl> + Status Close ( ) override { return base_ - > Close ( ) ; } <nl> + Status Flush ( ) override { return base_ - > Flush ( ) ; } <nl> + Status Sync ( ) override { <nl> + + + env_ - > sync_counter_ ; <nl> + return base_ - > Sync ( ) ; <nl> + } <nl> + <nl> + private : <nl> + SpecialEnv * env_ ; <nl> + unique_ptr < WritableFile > base_ ; <nl> + } ; <nl> + <nl> + if ( non_writeable_rate_ . load ( std : : memory_order_acquire ) > 0 ) { <nl> + uint32_t random_number ; <nl> + { <nl> + MutexLock l ( & rnd_mutex_ ) ; <nl> + random_number = rnd_ . Uniform ( 100 ) ; <nl> + } <nl> + if ( random_number < non_writeable_rate_ . load ( ) ) { <nl> + return Status : : IOError ( " simulated random write error " ) ; <nl> + } <nl> + } <nl> + <nl> + new_writable_count_ + + ; <nl> + <nl> + if ( non_writable_count_ . load ( ) > 0 ) { <nl> + non_writable_count_ - - ; <nl> + return Status : : IOError ( " simulated write error " ) ; <nl> + } <nl> + <nl> + Status s = target ( ) - > NewWritableFile ( f , r , soptions ) ; <nl> + if ( s . ok ( ) ) { <nl> + if ( strstr ( f . c_str ( ) , " . sst " ) ! = nullptr ) { <nl> + r - > reset ( new SSTableFile ( this , std : : move ( * r ) ) ) ; <nl> + } else if ( strstr ( f . c_str ( ) , " MANIFEST " ) ! = nullptr ) { <nl> + r - > reset ( new ManifestFile ( this , std : : move ( * r ) ) ) ; <nl> + } else if ( strstr ( f . c_str ( ) , " log " ) ! = nullptr ) { <nl> + r - > reset ( new WalFile ( this , std : : move ( * r ) ) ) ; <nl> + } <nl> + } <nl> + return s ; <nl> + } <nl> + <nl> + Status NewRandomAccessFile ( const std : : string & f , <nl> + unique_ptr < RandomAccessFile > * r , <nl> + const EnvOptions & soptions ) override { <nl> + class CountingFile : public RandomAccessFile { <nl> + public : <nl> + CountingFile ( unique_ptr < RandomAccessFile > & & target , <nl> + anon : : AtomicCounter * counter ) <nl> + : target_ ( std : : move ( target ) ) , counter_ ( counter ) { <nl> + } <nl> + virtual Status Read ( uint64_t offset , size_t n , Slice * result , <nl> + char * scratch ) const override { <nl> + counter_ - > Increment ( ) ; <nl> + return target_ - > Read ( offset , n , result , scratch ) ; <nl> + } <nl> + <nl> + private : <nl> + unique_ptr < RandomAccessFile > target_ ; <nl> + anon : : AtomicCounter * counter_ ; <nl> + } ; <nl> + <nl> + Status s = target ( ) - > NewRandomAccessFile ( f , r , soptions ) ; <nl> + if ( s . ok ( ) & & count_random_reads_ ) { <nl> + r - > reset ( new CountingFile ( std : : move ( * r ) , & random_read_counter_ ) ) ; <nl> + } <nl> + return s ; <nl> + } <nl> + <nl> + Status NewSequentialFile ( const std : : string & f , unique_ptr < SequentialFile > * r , <nl> + const EnvOptions & soptions ) override { <nl> + class CountingFile : public SequentialFile { <nl> + public : <nl> + CountingFile ( unique_ptr < SequentialFile > & & target , <nl> + anon : : AtomicCounter * counter ) <nl> + : target_ ( std : : move ( target ) ) , counter_ ( counter ) { } <nl> + virtual Status Read ( size_t n , Slice * result , char * scratch ) override { <nl> + counter_ - > Increment ( ) ; <nl> + return target_ - > Read ( n , result , scratch ) ; <nl> + } <nl> + virtual Status Skip ( uint64_t n ) override { return target_ - > Skip ( n ) ; } <nl> + <nl> + private : <nl> + unique_ptr < SequentialFile > target_ ; <nl> + anon : : AtomicCounter * counter_ ; <nl> + } ; <nl> + <nl> + Status s = target ( ) - > NewSequentialFile ( f , r , soptions ) ; <nl> + if ( s . ok ( ) & & count_sequential_reads_ ) { <nl> + r - > reset ( new CountingFile ( std : : move ( * r ) , & sequential_read_counter_ ) ) ; <nl> + } <nl> + return s ; <nl> + } <nl> + <nl> + <nl> + virtual void SleepForMicroseconds ( int micros ) override { <nl> + sleep_counter_ . Increment ( ) ; <nl> + if ( no_sleep_ ) { <nl> + addon_time_ . fetch_add ( micros ) ; <nl> + } else { <nl> + target ( ) - > SleepForMicroseconds ( micros ) ; <nl> + } <nl> + } <nl> + <nl> + virtual Status GetCurrentTime ( int64_t * unix_time ) override { <nl> + Status s = target ( ) - > GetCurrentTime ( unix_time ) ; <nl> + if ( s . ok ( ) ) { <nl> + * unix_time + = addon_time_ . load ( ) ; <nl> + } <nl> + return s ; <nl> + } <nl> + <nl> + virtual uint64_t NowNanos ( ) override { <nl> + return target ( ) - > NowNanos ( ) + addon_time_ . load ( ) * 1000 ; <nl> + } <nl> + <nl> + virtual uint64_t NowMicros ( ) override { <nl> + return target ( ) - > NowMicros ( ) + addon_time_ . load ( ) ; <nl> + } <nl> + <nl> + Random rnd_ ; <nl> + port : : Mutex rnd_mutex_ ; / / Lock to pretect rnd_ <nl> + <nl> + / / sstable Sync ( ) calls are blocked while this pointer is non - nullptr . <nl> + std : : atomic < bool > delay_sstable_sync_ ; <nl> + <nl> + / / Drop writes on the floor while this pointer is non - nullptr . <nl> + std : : atomic < bool > drop_writes_ ; <nl> + <nl> + / / Simulate no - space errors while this pointer is non - nullptr . <nl> + std : : atomic < bool > no_space_ ; <nl> + <nl> + / / Simulate non - writable file system while this pointer is non - nullptr <nl> + std : : atomic < bool > non_writable_ ; <nl> + <nl> + / / Force sync of manifest files to fail while this pointer is non - nullptr <nl> + std : : atomic < bool > manifest_sync_error_ ; <nl> + <nl> + / / Force write to manifest files to fail while this pointer is non - nullptr <nl> + std : : atomic < bool > manifest_write_error_ ; <nl> + <nl> + / / Force write to log files to fail while this pointer is non - nullptr <nl> + std : : atomic < bool > log_write_error_ ; <nl> + <nl> + / / Slow down every log write , in micro - seconds . <nl> + std : : atomic < int > log_write_slowdown_ ; <nl> + <nl> + bool count_random_reads_ ; <nl> + anon : : AtomicCounter random_read_counter_ ; <nl> + <nl> + bool count_sequential_reads_ ; <nl> + anon : : AtomicCounter sequential_read_counter_ ; <nl> + <nl> + anon : : AtomicCounter sleep_counter_ ; <nl> + <nl> + std : : atomic < int64_t > bytes_written_ ; <nl> + <nl> + std : : atomic < int > sync_counter_ ; <nl> + <nl> + std : : atomic < uint32_t > non_writeable_rate_ ; <nl> + <nl> + std : : atomic < uint32_t > new_writable_count_ ; <nl> + <nl> + std : : atomic < uint32_t > non_writable_count_ ; <nl> + <nl> + std : : function < void ( ) > * table_write_callback_ ; <nl> + <nl> + std : : atomic < int64_t > addon_time_ ; <nl> + bool no_sleep_ ; <nl> + } ; <nl> + <nl> + class DBTestBase : public testing : : Test { <nl> + protected : <nl> + / / Sequence of option configurations to try <nl> + enum OptionConfig { <nl> + kDefault = 0 , <nl> + kBlockBasedTableWithPrefixHashIndex = 1 , <nl> + kBlockBasedTableWithWholeKeyHashIndex = 2 , <nl> + kPlainTableFirstBytePrefix = 3 , <nl> + kPlainTableCappedPrefix = 4 , <nl> + kPlainTableAllBytesPrefix = 5 , <nl> + kVectorRep = 6 , <nl> + kHashLinkList = 7 , <nl> + kHashCuckoo = 8 , <nl> + kMergePut = 9 , <nl> + kFilter = 10 , <nl> + kFullFilter = 11 , <nl> + kUncompressed = 12 , <nl> + kNumLevel_3 = 13 , <nl> + kDBLogDir = 14 , <nl> + kWalDirAndMmapReads = 15 , <nl> + kManifestFileSize = 16 , <nl> + kCompactOnFlush = 17 , <nl> + kPerfOptions = 18 , <nl> + kDeletesFilterFirst = 19 , <nl> + kHashSkipList = 20 , <nl> + kUniversalCompaction = 21 , <nl> + kUniversalCompactionMultiLevel = 22 , <nl> + kCompressedBlockCache = 23 , <nl> + kInfiniteMaxOpenFiles = 24 , <nl> + kxxHashChecksum = 25 , <nl> + kFIFOCompaction = 26 , <nl> + kOptimizeFiltersForHits = 27 , <nl> + kRowCache = 28 , <nl> + kEnd = 29 <nl> + } ; <nl> + int option_config_ ; <nl> + <nl> + public : <nl> + std : : string dbname_ ; <nl> + std : : string alternative_wal_dir_ ; <nl> + MockEnv * mem_env_ ; <nl> + SpecialEnv * env_ ; <nl> + DB * db_ ; <nl> + std : : vector < ColumnFamilyHandle * > handles_ ; <nl> + <nl> + Options last_options_ ; <nl> + <nl> + / / Skip some options , as they may not be applicable to a specific test . <nl> + / / To add more skip constants , use values 4 , 8 , 16 , etc . <nl> + enum OptionSkip { <nl> + kNoSkip = 0 , <nl> + kSkipDeletesFilterFirst = 1 , <nl> + kSkipUniversalCompaction = 2 , <nl> + kSkipMergePut = 4 , <nl> + kSkipPlainTable = 8 , <nl> + kSkipHashIndex = 16 , <nl> + kSkipNoSeekToLast = 32 , <nl> + kSkipHashCuckoo = 64 , <nl> + kSkipFIFOCompaction = 128 , <nl> + kSkipMmapReads = 256 , <nl> + } ; <nl> + <nl> + explicit DBTestBase ( const std : : string path ) ; <nl> + <nl> + ~ DBTestBase ( ) ; <nl> + <nl> + / / Switch to a fresh database with the next option configuration to <nl> + / / test . Return false if there are no more configurations to test . <nl> + bool ChangeOptions ( int skip_mask = kNoSkip ) ; <nl> + <nl> + / / Switch between different compaction styles ( we have only 2 now ) . <nl> + bool ChangeCompactOptions ( ) ; <nl> + <nl> + / / Switch between different filter policy <nl> + / / Jump from kDefault to kFilter to kFullFilter <nl> + bool ChangeFilterOptions ( ) ; <nl> + <nl> + / / Return the current option configuration . <nl> + Options CurrentOptions ( <nl> + const anon : : OptionsOverride & options_override = anon : : OptionsOverride ( ) ) ; <nl> + <nl> + Options CurrentOptions ( <nl> + const Options & defaultOptions , <nl> + const anon : : OptionsOverride & options_override = anon : : OptionsOverride ( ) ) ; <nl> + <nl> + DBImpl * dbfull ( ) { <nl> + return reinterpret_cast < DBImpl * > ( db_ ) ; <nl> + } <nl> + <nl> + void CreateColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) ; <nl> + <nl> + void CreateAndReopenWithCF ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) ; <nl> + <nl> + void ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const std : : vector < Options > & options ) ; <nl> + <nl> + void ReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) ; <nl> + <nl> + Status TryReopenWithColumnFamilies ( <nl> + const std : : vector < std : : string > & cfs , <nl> + const std : : vector < Options > & options ) ; <nl> + <nl> + Status TryReopenWithColumnFamilies ( const std : : vector < std : : string > & cfs , <nl> + const Options & options ) ; <nl> + <nl> + void Reopen ( const Options & options ) ; <nl> + <nl> + void Close ( ) ; <nl> + <nl> + void DestroyAndReopen ( const Options & options ) ; <nl> + <nl> + void Destroy ( const Options & options ) ; <nl> + <nl> + Status ReadOnlyReopen ( const Options & options ) ; <nl> + <nl> + Status TryReopen ( const Options & options ) ; <nl> + <nl> + Status Flush ( int cf = 0 ) ; <nl> + <nl> + Status Put ( const Slice & k , const Slice & v , WriteOptions wo = WriteOptions ( ) ) ; <nl> + <nl> + Status Put ( int cf , const Slice & k , const Slice & v , <nl> + WriteOptions wo = WriteOptions ( ) ) ; <nl> + <nl> + Status Delete ( const std : : string & k ) ; <nl> + <nl> + Status Delete ( int cf , const std : : string & k ) ; <nl> + <nl> + std : : string Get ( const std : : string & k , const Snapshot * snapshot = nullptr ) ; <nl> + <nl> + std : : string Get ( int cf , const std : : string & k , <nl> + const Snapshot * snapshot = nullptr ) ; <nl> + <nl> + uint64_t GetNumSnapshots ( ) ; <nl> + <nl> + uint64_t GetTimeOldestSnapshots ( ) ; <nl> + <nl> + / / Return a string that contains all key , value pairs in order , <nl> + / / formatted like " ( k1 - > v1 ) ( k2 - > v2 ) " . <nl> + std : : string Contents ( int cf = 0 ) ; <nl> + <nl> + std : : string AllEntriesFor ( const Slice & user_key , int cf = 0 ) ; <nl> + <nl> + int NumSortedRuns ( int cf = 0 ) ; <nl> + <nl> + uint64_t TotalSize ( int cf = 0 ) ; <nl> + <nl> + int NumTableFilesAtLevel ( int level , int cf = 0 ) ; <nl> + <nl> + uint64_t SizeAtLevel ( int level ) ; <nl> + <nl> + int TotalLiveFiles ( int cf = 0 ) ; <nl> + <nl> + int TotalTableFiles ( int cf = 0 , int levels = - 1 ) ; <nl> + <nl> + / / Return spread of files per level <nl> + std : : string FilesPerLevel ( int cf = 0 ) ; <nl> + <nl> + size_t CountFiles ( ) ; <nl> + <nl> + size_t CountLiveFiles ( ) ; <nl> + <nl> + uint64_t Size ( const Slice & start , const Slice & limit , int cf = 0 ) ; <nl> + <nl> + void Compact ( int cf , const Slice & start , const Slice & limit , <nl> + uint32_t target_path_id ) ; <nl> + <nl> + void Compact ( int cf , const Slice & start , const Slice & limit ) ; <nl> + <nl> + void Compact ( const Slice & start , const Slice & limit ) ; <nl> + <nl> + / / Do n memtable compactions , each of which produces an sstable <nl> + / / covering the range [ small , large ] . <nl> + void MakeTables ( int n , const std : : string & small , const std : : string & large , <nl> + int cf = 0 ) ; <nl> + <nl> + / / Prevent pushing of new sstables into deeper levels by adding <nl> + / / tables that cover a specified range to all levels . <nl> + void FillLevels ( const std : : string & smallest , const std : : string & largest , <nl> + int cf ) ; <nl> + <nl> + void DumpFileCounts ( const char * label ) ; <nl> + <nl> + std : : string DumpSSTableList ( ) ; <nl> + <nl> + int GetSstFileCount ( std : : string path ) ; <nl> + <nl> + / / this will generate non - overlapping files since it keeps increasing key_idx <nl> + void GenerateNewFile ( Random * rnd , int * key_idx , bool nowait = false ) ; <nl> + <nl> + void GenerateNewRandomFile ( Random * rnd , bool nowait = false ) ; <nl> + <nl> + std : : string IterStatus ( Iterator * iter ) ; <nl> + <nl> + Options OptionsForLogIterTest ( ) ; <nl> + <nl> + std : : unique_ptr < TransactionLogIterator > OpenTransactionLogIter ( <nl> + const SequenceNumber seq ) ; <nl> + <nl> + std : : string DummyString ( size_t len , char c = ' a ' ) ; <nl> + <nl> + void VerifyIterLast ( std : : string expected_key , int cf = 0 ) ; <nl> + <nl> + / / Used to test InplaceUpdate <nl> + <nl> + / / If previous value is nullptr or delta is > than previous value , <nl> + / / sets newValue with delta <nl> + / / If previous value is not empty , <nl> + / / updates previous value with ' b ' string of previous value size - 1 . <nl> + static UpdateStatus updateInPlaceSmallerSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) ; <nl> + <nl> + static UpdateStatus updateInPlaceSmallerVarintSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) ; <nl> + <nl> + static UpdateStatus updateInPlaceLargerSize ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) ; <nl> + <nl> + static UpdateStatus updateInPlaceNoAction ( <nl> + char * prevValue , uint32_t * prevSize , <nl> + Slice delta , std : : string * newValue ) ; <nl> + <nl> + / / Utility method to test InplaceUpdate <nl> + void validateNumberOfEntries ( int numValues , int cf = 0 ) ; <nl> + <nl> + void CopyFile ( const std : : string & source , const std : : string & destination , <nl> + uint64_t size = 0 ) ; <nl> + } ; <nl> + <nl> + } / / namespace rocksdb <nl>
Move reusable part of db_test . cc to util / db_test_util . h
facebook/rocksdb
625467a08a648f1ac8c715a4622df83e8f7fccaa
2015-07-13T23:53:38Z
mmm a / filament / include / filament / SwapChain . h <nl> ppp b / filament / include / filament / SwapChain . h <nl> namespace filament { <nl> * When Engine : : create ( ) is used without specifying a Platform , the ` nativeWindow ` <nl> * parameter above must be of type : <nl> * <nl> - * Platform | nativeWindow type <nl> - * : mmmmmm - - | : mmmmmmmmmmmmmmmmmmmmmmmmmmm - : <nl> - * Android | ANativeWindow * <nl> - * OSX | NSView * <nl> - * IOS | CAEAGLLayer * <nl> - * X11 | Window <nl> - * Windows | HWND <nl> + * Platform | nativeWindow type <nl> + * : mmmmmmmmmmmmmmm | : mmmmmmmmmmmmmmmmmmmmmmmmmmm - : <nl> + * Android | ANativeWindow * <nl> + * macOS - OpenGL | NSView * <nl> + * macOS - Metal | CAMetalLayer * <nl> + * iOS - OpenGL | CAEAGLLayer * <nl> + * iOS - Metal | CAMetalLayer * <nl> + * X11 | Window <nl> + * Windows | HWND <nl> * <nl> * Otherwise , the ` nativeWindow ` is defined by the concrete implementation of Platform . <nl> * <nl>
Update native window documentation ( )
google/filament
f5f27749a49d88e47d1acf0020b6a0d5137e8eab
2020-11-23T22:03:10Z
mmm a / xbmc / cores / VideoPlayer / DVDInputStreams / DVDFactoryInputStream . cpp <nl> ppp b / xbmc / cores / VideoPlayer / DVDInputStreams / DVDFactoryInputStream . cpp <nl> CDVDInputStream * CDVDFactoryInputStream : : CreateInputStream ( IVideoPlayer * pPlayer <nl> { <nl> CURL finalUrl ( curlFile . GetURL ( ) ) ; <nl> finalUrl . SetProtocolOptions ( origUrl . GetProtocolOptions ( ) ) ; <nl> + finalUrl . SetUserName ( origUrl . GetUserName ( ) ) ; <nl> + finalUrl . SetPassword ( origUrl . GetPassWord ( ) ) ; <nl> finalFileitem . SetPath ( finalUrl . Get ( ) ) ; <nl> } <nl> curlFile . Close ( ) ; <nl>
VideoPlayer : add user name and password back to url after testing for redirect
xbmc/xbmc
a71a0257ca541a786a9185d0646cbcc3bedebfc7
2016-10-28T16:01:23Z
mmm a / aten / src / ATen / native / layer_norm . cpp <nl> ppp b / aten / src / ATen / native / layer_norm . cpp <nl> Tensor quantized_group_norm_impl ( <nl> return Y ; <nl> } <nl> <nl> + Tensor quantized_instance_norm_impl ( <nl> + const Tensor & qx , <nl> + const Tensor & weight , / / optional <nl> + const Tensor & bias , / / optional <nl> + double eps , <nl> + double output_scale , <nl> + int64_t output_zero_point ) { <nl> + <nl> + const auto input_ndim = qx . dim ( ) ; <nl> + TORCH_CHECK ( <nl> + input_ndim > = 3 , <nl> + " Expected normalized_shape to be at least 3 - dimensional " ) ; <nl> + const auto input_shape = qx . sizes ( ) ; <nl> + <nl> + / / IN is GN with num_groups = = num_channels <nl> + const auto num_channels = input_shape [ 1 ] ; <nl> + TORCH_CHECK ( num_channels > 0 , " Expected 2nd dimension to be positive " ) ; <nl> + <nl> + return quantized_group_norm_impl ( <nl> + qx , num_channels , weight , bias , eps , output_scale , output_zero_point ) ; <nl> + } <nl> + <nl> TORCH_LIBRARY_IMPL ( quantized , QuantizedCPU , m ) { <nl> / / TODO : this is kind of . . . blegh <nl> m . impl ( " layer_norm " , [ ] ( <nl> TORCH_LIBRARY_IMPL ( quantized , QuantizedCPU , m ) { <nl> return quantized_group_norm_impl ( <nl> qx , num_groups , weight , bias , eps , output_scale , output_zero_point ) ; <nl> } ) ; <nl> + m . impl ( " instance_norm " , [ ] ( <nl> + Tensor qx , <nl> + Tensor weight , <nl> + Tensor bias , <nl> + double eps , <nl> + double output_scale , <nl> + int64_t output_zero_point ) { <nl> + return quantized_instance_norm_impl ( <nl> + qx , weight , bias , eps , output_scale , output_zero_point ) ; <nl> + } ) ; <nl> } <nl> <nl> DEFINE_DISPATCH ( LayerNormKernel ) ; <nl> mmm a / aten / src / ATen / native / native_functions . yaml <nl> ppp b / aten / src / ATen / native / native_functions . yaml <nl> <nl> - func : instance_norm ( Tensor input , Tensor ? weight , Tensor ? bias , Tensor ? running_mean , Tensor ? running_var , bool use_input_stats , float momentum , float eps , bool cudnn_enabled ) - > Tensor <nl> variants : function <nl> <nl> + - func : quantized_instance_norm ( Tensor input , Tensor ? weight , Tensor ? bias , float eps , float output_scale , int output_zero_point ) - > Tensor <nl> + requires_tensor : True <nl> + dispatch : <nl> + QuantizedCPU : quantized_instance_norm_impl <nl> + <nl> - func : inverse ( Tensor self ) - > Tensor <nl> use_c10_dispatcher : full <nl> variants : function , method <nl> mmm a / aten / src / ATen / native / quantized / library . cpp <nl> ppp b / aten / src / ATen / native / quantized / library . cpp <nl> TORCH_LIBRARY ( quantized , m ) { <nl> m . def ( " conv3d_groups ( __torch__ . torch . classes . quantized . Conv3dPackedParamsBase packed_weights ) - > int " ) ; <nl> m . def ( " hardswish ( Tensor input , float output_scale , int output_zero_point ) - > Tensor " ) ; <nl> m . def ( " group_norm ( Tensor input , int num_groups , Tensor weight , Tensor bias , float eps , float output_scale , int output_zero_point ) - > Tensor " ) ; <nl> + m . def ( " instance_norm ( Tensor input , Tensor weight , Tensor bias , float eps , float output_scale , int output_zero_point ) - > Tensor " ) ; <nl> m . def ( " layer_norm ( Tensor input , int [ ] normalized_shape , Tensor weight , Tensor bias , float eps , float output_scale , int output_zero_point ) - > Tensor " ) ; <nl> m . def ( " linear ( Tensor X , Tensor W_prepack , float Y_scale_i , int Y_zero_point_i ) - > Tensor Y " ) ; <nl> m . def ( " linear_relu ( Tensor X , Tensor W_prepack , float Y_scale_i , int Y_zero_point_i ) - > Tensor Y " ) ; <nl> mmm a / benchmarks / operator_benchmark / benchmark_all_other_test . py <nl> ppp b / benchmarks / operator_benchmark / benchmark_all_other_test . py <nl> <nl> chunk_test , conv_test , diag_test , embeddingbag_test , fill_test , # noqa <nl> gather_test , linear_test , matmul_test , pool_test , # noqa <nl> softmax_test , hardsigmoid_test , hardswish_test , layernorm_test , # noqa <nl> - groupnorm_test # noqa <nl> + groupnorm_test , instancenorm_test # noqa <nl> ) <nl> <nl> if __name__ = = " __main__ " : <nl> mmm a / benchmarks / operator_benchmark / benchmark_all_quantized_test . py <nl> ppp b / benchmarks / operator_benchmark / benchmark_all_quantized_test . py <nl> <nl> qcomparators_test , <nl> qconv_test , <nl> qgroupnorm_test , <nl> + qinstancenorm_test , <nl> qinterpolate_test , <nl> qlayernorm_test , <nl> qlinear_test , <nl> new file mode 100644 <nl> index 000000000000 . . 1e2ee1ca7bb4 <nl> mmm / dev / null <nl> ppp b / benchmarks / operator_benchmark / pt / instancenorm_test . py <nl> <nl> + from __future__ import absolute_import <nl> + from __future__ import division <nl> + from __future__ import print_function <nl> + from __future__ import unicode_literals <nl> + <nl> + <nl> + import operator_benchmark as op_bench <nl> + import torch <nl> + import torch . nn . functional as F <nl> + <nl> + <nl> + " " " Microbenchmarks for instancenorm operator . " " " <nl> + <nl> + instancenorm_configs_short = op_bench . cross_product_configs ( <nl> + dims = ( <nl> + ( 32 , 8 , 16 ) , <nl> + ( 32 , 8 , 56 , 56 ) , <nl> + ) , <nl> + tags = [ " short " ] , <nl> + ) <nl> + <nl> + <nl> + class InstanceNormBenchmark ( op_bench . TorchBenchmarkBase ) : <nl> + def init ( self , dims ) : <nl> + self . X = ( torch . rand ( * dims ) - 0 . 5 ) * 256 <nl> + num_channels = dims [ 1 ] <nl> + self . weight = torch . rand ( num_channels , dtype = torch . float ) <nl> + self . bias = torch . rand ( num_channels , dtype = torch . float ) <nl> + self . eps = 1e - 5 <nl> + <nl> + def forward ( self ) : <nl> + return F . instance_norm ( <nl> + self . X , weight = self . weight , bias = self . bias , eps = self . eps ) <nl> + <nl> + <nl> + op_bench . generate_pt_test ( instancenorm_configs_short , InstanceNormBenchmark ) <nl> + <nl> + <nl> + if __name__ = = " __main__ " : <nl> + op_bench . benchmark_runner . main ( ) <nl> new file mode 100644 <nl> index 000000000000 . . 65cd4eff26ab <nl> mmm / dev / null <nl> ppp b / benchmarks / operator_benchmark / pt / qinstancenorm_test . py <nl> <nl> + from __future__ import absolute_import <nl> + from __future__ import division <nl> + from __future__ import print_function <nl> + from __future__ import unicode_literals <nl> + <nl> + <nl> + import operator_benchmark as op_bench <nl> + import torch <nl> + <nl> + <nl> + " " " Microbenchmarks for quantized instancenorm operator . " " " <nl> + <nl> + instancenorm_configs_short = op_bench . cross_product_configs ( <nl> + dims = ( <nl> + ( 32 , 8 , 16 ) , <nl> + ( 32 , 8 , 56 , 56 ) , <nl> + ) , <nl> + dtype = ( torch . qint8 , ) , <nl> + tags = [ " short " ] , <nl> + ) <nl> + <nl> + <nl> + class QInstanceNormBenchmark ( op_bench . TorchBenchmarkBase ) : <nl> + <nl> + def init ( self , dims , dtype ) : <nl> + X = ( torch . rand ( * dims ) - 0 . 5 ) * 256 <nl> + num_channels = dims [ 1 ] <nl> + scale = 1 . 0 <nl> + zero_point = 0 <nl> + self . qX = torch . quantize_per_tensor ( <nl> + X , scale = scale , zero_point = zero_point , dtype = dtype ) <nl> + self . weight = torch . rand ( num_channels , dtype = torch . float ) <nl> + self . bias = torch . rand ( num_channels , dtype = torch . float ) <nl> + self . eps = 1e - 5 <nl> + self . Y_scale = 0 . 1 <nl> + self . Y_zero_point = 0 <nl> + <nl> + def forward ( self ) : <nl> + return torch . ops . quantized . instance_norm ( <nl> + self . qX , weight = self . weight , bias = self . bias , <nl> + eps = self . eps , output_scale = self . Y_scale , <nl> + output_zero_point = self . Y_zero_point ) <nl> + <nl> + <nl> + op_bench . generate_pt_test ( instancenorm_configs_short , QInstanceNormBenchmark ) <nl> + <nl> + <nl> + if __name__ = = " __main__ " : <nl> + op_bench . benchmark_runner . main ( ) <nl> mmm a / test / quantization / test_quantized_op . py <nl> ppp b / test / quantization / test_quantized_op . py <nl> def test_group_norm ( self ) : <nl> self . assertTrue ( pct_diff < 1e - 6 ) <nl> self . assertTrue ( pct_diff_off_by_one < 0 . 01 ) <nl> <nl> + def test_instance_norm ( self ) : <nl> + if " fbgemm " not in torch . backends . quantized . supported_engines : <nl> + return <nl> + <nl> + max_sides = ( 4 , 5 ) <nl> + side_lens = ( 2 , 8 , 11 ) <nl> + torch_types = ( torch . qint8 , torch . quint8 ) <nl> + y_scales = ( 0 . 1 , 4 . 23 ) <nl> + y_zero_points = ( 0 , 1 ) <nl> + combined = [ max_sides , side_lens , torch_types , y_scales , y_zero_points ] <nl> + test_cases = itertools . product ( * combined ) <nl> + <nl> + with override_quantized_engine ( " fbgemm " ) : <nl> + for test_case in test_cases : <nl> + <nl> + max_side , side_len , torch_type , Y_scale , Y_zero_point = test_case <nl> + shapes = [ side_len ] * max_side <nl> + <nl> + # In the FP kernel , sums and sums of squares are calculated in floating point . <nl> + # In the int8 and uint8 versions of the quantized kernel , they are <nl> + # calculated in integer arithmetic ( which is exact ) . <nl> + # Because of this , the numerics do not always match exactly which is <nl> + # expected and acceptable . We do the following to whitelist this failure <nl> + # in this test : <nl> + # 1 . do not use Hypothesis to generate the input tensor . Hypothesis <nl> + # favors homogeneous inputs in its search strategies which isn ' t <nl> + # representative of the inputs we care about , and tends to maximize <nl> + # this particular numerics difference . <nl> + # 2 . whitelist a small % of off by Y_scale errors . Even when the <nl> + # variance of the input is high , there can be off by one errors <nl> + # in the result if the input value happens to fall exactly on <nl> + # the bin boundary of the output scale . <nl> + # <nl> + # If we want the numerics to match we could switch to calculating <nl> + # mean + var in floating point in the future , at the cost of speed . <nl> + X , X_scale , X_zero_point = \ <nl> + _get_random_tensor_and_q_params ( shapes , 1 . 0 , torch_type ) <nl> + <nl> + num_channels = shapes [ 1 ] <nl> + weight = torch . rand ( num_channels ) . float ( ) * 0 . 5 <nl> + bias = torch . rand ( num_channels ) . float ( ) <nl> + for i in range ( num_channels ) : <nl> + weight [ i ] * = i <nl> + bias [ i ] * = i <nl> + eps = 0 . 001 <nl> + <nl> + qX = torch . quantize_per_tensor ( X , X_scale , X_zero_point , torch_type ) <nl> + dqX = qX . dequantize ( ) <nl> + <nl> + # Enforce non - homogeneous inputs <nl> + batches = shapes [ 0 ] <nl> + for batch_idx in range ( batches ) : <nl> + for ch_idx in range ( num_channels ) : <nl> + ch_vals = dqX [ batch_idx ] [ ch_idx ] <nl> + assume ( <nl> + float ( torch . unique ( ch_vals ) . shape [ 0 ] ) / ch_vals . numel ( ) > 0 . 01 <nl> + or group_vals . numel ( ) < 5 ) <nl> + <nl> + qY = torch . ops . quantized . instance_norm ( qX , weight , bias , eps , Y_scale , Y_zero_point ) <nl> + <nl> + dqY_hat = F . instance_norm ( dqX , weight = weight , bias = bias , eps = eps ) <nl> + qY_hat = torch . quantize_per_tensor ( dqY_hat , Y_scale , Y_zero_point , torch_type ) <nl> + <nl> + # Due to the numerics difference mentioned above between calculating <nl> + # the variance in float vs int , the results can still be slightly <nl> + # different . <nl> + dqY = qY . dequantize ( ) <nl> + dqY_hat = qY_hat . dequantize ( ) <nl> + diff = dqY - dqY_hat <nl> + <nl> + # off - by - one errors are magnitude of Y_scale <nl> + num_diff = torch . sum ( diff > Y_scale * 1 . 0001 ) <nl> + pct_diff = float ( num_diff ) / ( diff . numel ( ) + 1e - 5 ) <nl> + num_diff_off_by_one = torch . sum ( ( diff > 0 ) * ( diff < = Y_scale ) ) <nl> + pct_diff_off_by_one = float ( num_diff_off_by_one ) / ( diff . numel ( ) + 1e - 5 ) <nl> + <nl> + self . assertTrue ( pct_diff < 1e - 6 ) <nl> + self . assertTrue ( pct_diff_off_by_one < 0 . 01 ) <nl> + <nl> def test_batch_norm2d_relu ( self ) : <nl> if " fbgemm " not in torch . backends . quantized . supported_engines : <nl> return <nl> mmm a / torch / _overrides . py <nl> ppp b / torch / _overrides . py <nl> def get_testing_overrides ( ) : <nl> torch . quantize_per_tensor : lambda input , scale , zero_point , dtype : - 1 , <nl> torch . quantized_batch_norm : lambda input , weight , bias , mean , var , eps , output_scale , output_zero_point : - 1 , <nl> torch . quantized_group_norm : lambda input , num_groups , weight , bias , eps , output_scale , output_zero_point : - 1 , <nl> + torch . quantized_instance_norm : lambda input , weight , bias , eps , output_scale , output_zero_point : - 1 , <nl> torch . quantized_layer_norm : lambda input , normalized_shape , weight , bias , eps , output_scale , output_zero_point : - 1 , <nl> <nl> torch . quantized_gru_cell : ( lambda input , hx , w_ih , w_hh , b_ih , b_hh , packed_ih , packed_hh , col_offsets_ih , <nl>
add quantized instancenorm operator ( )
pytorch/pytorch
4fa049c525fb5f999d3d19afd691c4dd00d7a30f
2020-05-07T02:01:33Z
mmm a / modules / perception / obstacle / fusion / async_fusion / async_fusion . cc <nl> ppp b / modules / perception / obstacle / fusion / async_fusion / async_fusion . cc <nl> <nl> # include < iomanip > <nl> # include < string > <nl> # include < vector > <nl> + <nl> # include " modules / common / log . h " <nl> # include " modules / common / macro . h " <nl> # include " modules / perception / lib / config_manager / config_manager . h " <nl> <nl> namespace apollo { <nl> namespace perception { <nl> <nl> - AsyncFusion : : AsyncFusion ( ) <nl> - : started_ ( false ) , matcher_ ( nullptr ) , track_manager_ ( nullptr ) { } <nl> - <nl> AsyncFusion : : ~ AsyncFusion ( ) { <nl> if ( matcher_ ) { <nl> delete matcher_ ; <nl> void AsyncFusion : : FuseFrame ( const PbfSensorFramePtr & frame ) { <nl> DecomposeFrameObjects ( objects , & foreground_objects , & background_objects ) ; <nl> <nl> Eigen : : Vector3d ref_point = frame - > sensor2world_pose . topRightCorner ( 3 , 1 ) ; <nl> - FuseForegroundObjects ( & foreground_objects , ref_point , frame - > sensor_type , <nl> - frame - > sensor_id , frame - > timestamp ) ; <nl> + FuseForegroundObjects ( ref_point , frame - > sensor_type , frame - > sensor_id , <nl> + frame - > timestamp , & foreground_objects ) ; <nl> track_manager_ - > RemoveLostTracks ( ) ; <nl> } <nl> <nl> void AsyncFusion : : CreateNewTracks ( <nl> const std : : vector < PbfSensorObjectPtr > & sensor_objects , <nl> const std : : vector < int > & unassigned_ids ) { <nl> - for ( size_t i = 0 ; i < unassigned_ids . size ( ) ; i + + ) { <nl> + for ( size_t i = 0 ; i < unassigned_ids . size ( ) ; + + i ) { <nl> int id = unassigned_ids [ i ] ; <nl> PbfTrackPtr track ( new PbfTrack ( sensor_objects [ id ] ) ) ; <nl> track_manager_ - > AddTrack ( track ) ; <nl> void AsyncFusion : : CreateNewTracks ( <nl> } <nl> <nl> void AsyncFusion : : UpdateAssignedTracks ( <nl> - std : : vector < PbfTrackPtr > * tracks , <nl> const std : : vector < PbfSensorObjectPtr > & sensor_objects , <nl> const std : : vector < TrackObjectPair > & assignments , <nl> - const std : : vector < double > & track_object_dist ) { <nl> + const std : : vector < double > & track_object_dist , <nl> + std : : vector < PbfTrackPtr > const * tracks ) { <nl> for ( size_t i = 0 ; i < assignments . size ( ) ; i + + ) { <nl> int local_track_index = assignments [ i ] . first ; <nl> int local_obj_index = assignments [ i ] . second ; <nl> void AsyncFusion : : DecomposeFrameObjects ( <nl> } <nl> <nl> void AsyncFusion : : FuseForegroundObjects ( <nl> - std : : vector < PbfSensorObjectPtr > * foreground_objects , <nl> - Eigen : : Vector3d ref_point , const SensorType & sensor_type , <nl> - const std : : string & sensor_id , double timestamp ) { <nl> + const Eigen : : Vector3d & ref_point , const SensorType & sensor_type , <nl> + const std : : string & sensor_id , const double timestamp , <nl> + std : : vector < PbfSensorObjectPtr > * foreground_objects ) { <nl> std : : vector < int > unassigned_tracks ; <nl> std : : vector < int > unassigned_objects ; <nl> std : : vector < TrackObjectPair > assignments ; <nl> void AsyncFusion : : FuseForegroundObjects ( <nl> < < " , unassigned_track_cnt = " < < unassigned_tracks . size ( ) <nl> < < " , unassigned_obj_cnt = " < < unassigned_objects . size ( ) ; <nl> <nl> - UpdateAssignedTracks ( & tracks , * foreground_objects , assignments , <nl> - track2measurements_dist ) ; <nl> + UpdateAssignedTracks ( * foreground_objects , assignments , <nl> + track2measurements_dist , & tracks ) ; <nl> <nl> UpdateUnassignedTracks ( & tracks , unassigned_tracks , track2measurements_dist , <nl> sensor_type , sensor_id , timestamp ) ; <nl> mmm a / modules / perception / obstacle / fusion / async_fusion / async_fusion . h <nl> ppp b / modules / perception / obstacle / fusion / async_fusion / async_fusion . h <nl> <nl> * limitations under the License . <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> - # ifndef MODULES_PERCEPTION_OBSTACLE_FUSION_IMF_FUSION_ASYNC_FUSION_H_ / / NOLINT <nl> - # define MODULES_PERCEPTION_OBSTACLE_FUSION_IMF_FUSION_ASYNC_FUSION_H_ / / NOLINT <nl> + # ifndef MODULES_PERCEPTION_OBSTACLE_FUSION_IMF_FUSION_ASYNC_FUSION_H_ <nl> + # define MODULES_PERCEPTION_OBSTACLE_FUSION_IMF_FUSION_ASYNC_FUSION_H_ <nl> <nl> # include < mutex > <nl> # include < string > <nl> # include < vector > <nl> + <nl> # include " modules / perception / lib / config_manager / config_manager . h " <nl> # include " modules / perception / obstacle / base / object . h " <nl> # include " modules / perception / obstacle / fusion / interface / base_fusion . h " <nl> class AsyncFusion : public BaseFusion { <nl> <nl> / * * @ brief update current tracks with matched objects * / <nl> void UpdateAssignedTracks ( <nl> - std : : vector < PbfTrackPtr > * tracks , <nl> const std : : vector < PbfSensorObjectPtr > & sensor_objects , <nl> const std : : vector < TrackObjectPair > & assignments , <nl> - const std : : vector < double > & track_objects_dist ) ; <nl> + const std : : vector < double > & track_objects_dist , <nl> + std : : vector < PbfTrackPtr > const * tracks ) ; <nl> <nl> / * * @ brief update current tracks which cannot find matched objects * / <nl> void UpdateUnassignedTracks ( std : : vector < PbfTrackPtr > * tracks , <nl> class AsyncFusion : public BaseFusion { <nl> std : : vector < PbfSensorObjectPtr > * background_objects ) ; <nl> <nl> void FuseForegroundObjects ( <nl> - std : : vector < PbfSensorObjectPtr > * foreground_objects , <nl> - Eigen : : Vector3d ref_point , const SensorType & sensor_type , <nl> - const std : : string & sensor_id , double timestamp ) ; <nl> + const Eigen : : Vector3d & ref_point , const SensorType & sensor_type , <nl> + const std : : string & sensor_id , const double timestamp , <nl> + std : : vector < PbfSensorObjectPtr > * foreground_objects ) ; <nl> <nl> PbfSensorFramePtr ConstructFrame ( const SensorObjects & obj ) ; <nl> <nl> protected : <nl> - bool started_ ; <nl> - PbfBaseTrackObjectMatcher * matcher_ ; <nl> - PbfTrackManager * track_manager_ ; <nl> + bool started_ = false ; <nl> + PbfBaseTrackObjectMatcher * matcher_ = nullptr ; <nl> + PbfTrackManager * track_manager_ = nullptr ; <nl> std : : mutex sensor_data_rw_mutex_ ; <nl> std : : mutex fusion_mutex_ ; <nl> <nl> REGISTER_FUSION ( AsyncFusion ) ; <nl> <nl> } / / namespace perception <nl> } / / namespace apollo <nl> + <nl> # endif / / MODULES_PERCEPTION_OBSTACLE_FUSION_IMF_FUSION_ASYNC_FUSION_H_ <nl> mmm a / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_base_track_object_matcher . cc <nl> ppp b / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_base_track_object_matcher . cc <nl> <nl> <nl> # include " modules / perception / obstacle / fusion / probabilistic_fusion / pbf_base_track_object_matcher . h " <nl> <nl> - # include < map > <nl> - # include < string > <nl> # include < numeric > <nl> + # include < string > <nl> + # include < unordered_map > <nl> <nl> namespace apollo { <nl> namespace perception { <nl> void PbfBaseTrackObjectMatcher : : IdAssign ( <nl> unassigned_fusion_tracks - > resize ( num_track ) ; <nl> unassigned_sensor_objects - > resize ( num_obj ) ; <nl> std : : iota ( unassigned_fusion_tracks - > begin ( ) , <nl> - unassigned_fusion_tracks - > end ( ) , <nl> - 0 ) ; <nl> + unassigned_fusion_tracks - > end ( ) , 0 ) ; <nl> std : : iota ( unassigned_sensor_objects - > begin ( ) , <nl> unassigned_sensor_objects - > end ( ) , 0 ) ; <nl> return ; <nl> void PbfBaseTrackObjectMatcher : : IdAssign ( <nl> const SensorType & sensor_type = sensor_objects [ 0 ] - > sensor_type ; <nl> const std : : string & sensor_id = sensor_objects [ 0 ] - > sensor_id ; <nl> <nl> - std : : map < int , int > sensor_id_2_track_ind ; <nl> - for ( size_t i = 0 ; i < num_track ; i + + ) { <nl> + std : : unordered_map < int , int > sensor_id_2_track_ind ; <nl> + for ( size_t i = 0 ; i < num_track ; + + i ) { <nl> PbfSensorObjectPtr obj = <nl> fusion_tracks [ i ] - > GetSensorObject ( sensor_type , sensor_id ) ; <nl> if ( obj = = nullptr ) { <nl> void PbfBaseTrackObjectMatcher : : IdAssign ( <nl> <nl> std : : vector < bool > fusion_used ( num_track , false ) ; <nl> std : : vector < bool > sensor_used ( num_obj , false ) ; <nl> - for ( size_t i = 0 ; i < num_obj ; i + + ) { <nl> + for ( size_t i = 0 ; i < num_obj ; + + i ) { <nl> int track_id = sensor_objects [ i ] - > object - > track_id ; <nl> auto it = sensor_id_2_track_ind . find ( track_id ) ; <nl> if ( it ! = sensor_id_2_track_ind . end ( ) ) { <nl> mmm a / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_base_track_object_matcher . h <nl> ppp b / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_base_track_object_matcher . h <nl> <nl> * limitations under the License . <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> - # ifndef MODULES_PERCEPTION_OBSTACLE_FUSION_PROBABILISTIC_FUSION_PBF_BASE_TRACK_OBJECT_MATCHER_H_ / / NOLINT <nl> - # define MODULES_PERCEPTION_OBSTACLE_FUSION_PROBABILISTIC_FUSION_PBF_BASE_TRACK_OBJECT_MATCHER_H_ / / NOLINT <nl> + # ifndef MODULES_PERCEPTION_OBSTACLE_FUSION_PROBABILISTIC_FUSION_PBF_BASE_TRACK_OBJECT_MATCHER_H_ / / NOLINT <nl> + # define MODULES_PERCEPTION_OBSTACLE_FUSION_PROBABILISTIC_FUSION_PBF_BASE_TRACK_OBJECT_MATCHER_H_ / / NOLINT <nl> + <nl> + # include < string > <nl> # include < utility > <nl> # include < vector > <nl> - # include < string > <nl> + <nl> # include " modules / common / macro . h " <nl> # include " modules / perception / obstacle / fusion / probabilistic_fusion / pbf_sensor_object . h " <nl> # include " modules / perception / obstacle / fusion / probabilistic_fusion / pbf_track . h " <nl> namespace perception { <nl> typedef std : : pair < int , int > TrackObjectPair ; <nl> <nl> struct TrackObjectMatcherOptions { <nl> - Eigen : : Vector3d * ref_point = nullptr ; <nl> + const Eigen : : Vector3d * ref_point = nullptr ; <nl> } ; <nl> <nl> class PbfBaseTrackObjectMatcher { <nl> mmm a / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_sensor . cc <nl> ppp b / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_sensor . cc <nl> <nl> - <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> * Copyright 2017 The Apollo Authors . All Rights Reserved . <nl> * <nl> void PbfSensor : : QueryLatestFrames ( double time_stamp , <nl> return ; <nl> } <nl> frames - > clear ( ) ; <nl> - for ( size_t i = 0 ; i < frames_ . size ( ) ; i + + ) { <nl> + for ( size_t i = 0 ; i < frames_ . size ( ) ; + + i ) { <nl> if ( frames_ [ i ] - > timestamp > latest_query_timestamp_ & & <nl> frames_ [ i ] - > timestamp < = time_stamp ) { <nl> ( * frames ) . push_back ( frames_ [ i ] ) ; <nl> void PbfSensor : : QueryLatestFrames ( double time_stamp , <nl> <nl> PbfSensorFramePtr PbfSensor : : QueryLatestFrame ( double time_stamp ) { <nl> PbfSensorFramePtr latest_frame = nullptr ; <nl> - for ( size_t i = 0 ; i < frames_ . size ( ) ; i + + ) { <nl> + for ( size_t i = 0 ; i < frames_ . size ( ) ; + + i ) { <nl> if ( frames_ [ i ] - > timestamp > latest_query_timestamp_ & & <nl> frames_ [ i ] - > timestamp < = time_stamp ) { <nl> latest_frame = frames_ [ i ] ; <nl> void PbfSensor : : AddFrame ( const SensorObjects & frame ) { <nl> pbf_frame - > seq_num = frame . seq_num ; <nl> <nl> pbf_frame - > objects . resize ( frame . objects . size ( ) ) ; <nl> - for ( size_t i = 0 ; i < frame . objects . size ( ) ; i + + ) { <nl> + for ( size_t i = 0 ; i < frame . objects . size ( ) ; + + i ) { <nl> PbfSensorObjectPtr obj ( new PbfSensorObject ( ) ) ; <nl> obj - > timestamp = frame . timestamp ; <nl> obj - > sensor_type = frame . sensor_type ; <nl> mmm a / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_sensor . h <nl> ppp b / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_sensor . h <nl> class PbfSensor { <nl> explicit PbfSensor ( const SensorType & type , const std : : string & sensor_id ) ; <nl> ~ PbfSensor ( ) ; <nl> <nl> - / * * @ brief query frames whose time stamp is in range ( latest_fused_time_stamp_ , <nl> - * time_stamp ] * / <nl> + / * @ brief query frames whose time stamp is in range ( latest_fused_time_stamp_ , <nl> + * time_stamp ) <nl> + * / <nl> void QueryLatestFrames ( double time_stamp , <nl> std : : vector < PbfSensorFramePtr > * frames ) ; <nl> <nl> mmm a / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_track_manager . cc <nl> ppp b / modules / perception / obstacle / fusion / probabilistic_fusion / pbf_track_manager . cc <nl> <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> # include " modules / perception / obstacle / fusion / probabilistic_fusion / pbf_track_manager . h " <nl> + <nl> # include " modules / common / log . h " <nl> <nl> namespace apollo { <nl> PbfTrackManager : : ~ PbfTrackManager ( ) { } <nl> <nl> int PbfTrackManager : : RemoveLostTracks ( ) { <nl> size_t track_count = 0 ; <nl> - for ( size_t i = 0 ; i < tracks_ . size ( ) ; i + + ) { <nl> + for ( size_t i = 0 ; i < tracks_ . size ( ) ; + + i ) { <nl> if ( ! tracks_ [ i ] - > IsDead ( ) ) { <nl> if ( i ! = track_count ) { <nl> tracks_ [ track_count ] = tracks_ [ i ] ; <nl> mmm a / modules / planning / reference_line / reference_point . cc <nl> ppp b / modules / planning / reference_line / reference_point . cc <nl> double ReferencePoint : : kappa ( ) const { return kappa_ ; } <nl> <nl> double ReferencePoint : : dkappa ( ) const { return dkappa_ ; } <nl> <nl> - double ReferencePoint : : lower_bound ( ) const { return lower_bound_ ; } <nl> - <nl> - double ReferencePoint : : upper_bound ( ) const { return upper_bound_ ; } <nl> - <nl> std : : string ReferencePoint : : DebugString ( ) const { <nl> - / / StrCat supports 9 arguments at most . <nl> - return StrCat ( StrCat ( " { x : " , x ( ) , <nl> - " , " <nl> - " y : " , <nl> - y ( ) , <nl> - " , " <nl> - " theta : " , <nl> - heading ( ) , <nl> - " , " <nl> - " kappa : " , <nl> - kappa ( ) , " , " ) , <nl> - StrCat ( " dkappa : " , dkappa ( ) , <nl> - " , " <nl> - " upper_bound : " , <nl> - upper_bound ( ) , <nl> - " , " <nl> - " lower_bound : " , <nl> - lower_bound ( ) , " } " ) ) ; <nl> + / / StrCat only support 9 parameters <nl> + return StrCat ( " { x : " , x ( ) , " , y : " , y ( ) , " , theta : " , heading ( ) ) + <nl> + StrCat ( " , kappa : " , kappa ( ) , " , dkappa : " , dkappa ( ) , " } " ) ; <nl> } <nl> <nl> void ReferencePoint : : RemoveDuplicates ( std : : vector < ReferencePoint > * points ) { <nl> mmm a / modules / planning / reference_line / reference_point . h <nl> ppp b / modules / planning / reference_line / reference_point . h <nl> class ReferencePoint : public hdmap : : MapPathPoint { <nl> double kappa ( ) const ; <nl> double dkappa ( ) const ; <nl> <nl> - double lower_bound ( ) const ; <nl> - double upper_bound ( ) const ; <nl> - <nl> std : : string DebugString ( ) const ; <nl> <nl> static void RemoveDuplicates ( std : : vector < ReferencePoint > * points ) ; <nl>
Planning : removed unused lower_bound and upper_bound .
ApolloAuto/apollo
936816527d20677226a6e2c083f23cdf284629bb
2018-03-22T00:48:30Z
mmm a / test / webpage - spec . js <nl> ppp b / test / webpage - spec . js <nl> describe ( " WebPage object " , function ( ) { <nl> } ) ; <nl> } ) ; <nl> <nl> - xit ( " should send proper key codes for text " , function ( ) { <nl> + it ( " should send proper key codes for text " , function ( ) { <nl> runs ( function ( ) { <nl> page . content = ' < input type = " text " > ' ; <nl> page . evaluate ( function ( ) { <nl> describe ( " WebPage object " , function ( ) { <nl> } ) ; <nl> } ) ; <nl> <nl> - xit ( ' should open url using secure connection ' , function ( ) { <nl> + it ( ' should open url using secure connection ' , function ( ) { <nl> var page = require ( ' webpage ' ) . create ( ) ; <nl> var url = ' https : / / httpbin . org / ' ; <nl> <nl> describe ( " WebPage object " , function ( ) { <nl> } ) ; <nl> <nl> <nl> - xit ( ' should able to abort a network request ' , function ( ) { <nl> + it ( ' should able to abort a network request ' , function ( ) { <nl> var page = require ( ' webpage ' ) . create ( ) ; <nl> var url = ' http : / / phantomjs . org ' ; <nl> var urlToBlockRexExp = / phantomjs - logo \ . png $ / i ; <nl> describe ( " WebPage object " , function ( ) { <nl> } ) ; <nl> } ) ; <nl> <nl> - xit ( ' should change the url of the request ' , function ( ) { <nl> + it ( ' should change the url of the request ' , function ( ) { <nl> var page = require ( ' webpage ' ) . create ( ) ; <nl> var url = ' http : / / phantomjs . org ' ; <nl> var urlToChange = ' http : / / phantomjs . org / img / phantomjs - logo . png ' ; <nl> describe ( " WebPage loading / loadingProgress properties " , function ( ) { <nl> } ) ; <nl> } ) ; <nl> <nl> - xdescribe ( " WebPage render image " , function ( ) { <nl> + describe ( " WebPage render image " , function ( ) { <nl> var TEST_FILE_DIR = " webpage - spec - renders / " ; <nl> <nl> var p = require ( " webpage " ) . create ( ) ; <nl> xdescribe ( " WebPage render image " , function ( ) { <nl> } , " page to be rendered " , 3000 ) ; <nl> } <nl> <nl> - it ( " should render PDF file " , function ( ) { <nl> + xit ( " should render PDF file " , function ( ) { <nl> render_test ( " pdf " ) ; <nl> } ) ; <nl> <nl> - it ( " should render PDF file with format option " , function ( ) { <nl> + xit ( " should render PDF file with format option " , function ( ) { <nl> render_test ( " pdf " , { format : " pdf " } ) ; <nl> } ) ; <nl> <nl> - it ( " should render PNG file " , function ( ) { <nl> + xit ( " should render PNG file " , function ( ) { <nl> render_test ( " png " ) ; <nl> } ) ; <nl> <nl> - it ( " should render PNG file with format option " , function ( ) { <nl> + xit ( " should render PNG file with format option " , function ( ) { <nl> render_test ( " png " , { format : " png " } ) ; <nl> } ) ; <nl> <nl>
Enable even more tests ( to 322 specs ) .
ariya/phantomjs
3a9fc4967913cf61f08539c921f467409adfcd0b
2014-08-25T03:24:39Z
mmm a / doc / gpu_object_detection . tex <nl> ppp b / doc / gpu_object_detection . tex <nl> <nl> \ section { Object Detection } <nl> <nl> \ cvclass { gpu : : HOGDescriptor } <nl> - \ href { http : / / www . acemedia . org / aceMedia / files / document / wp7 / 2005 / cvpr05 - inria . pdf } { Histogram of Oriented Gradients } descriptor and detector . <nl> + Histogram of Oriented Gradients \ cite { dalal_hog } descriptor and detector . <nl> <nl> \ begin { lstlisting } <nl> struct CV_EXPORTS HOGDescriptor <nl> mmm a / doc / opencv . bib <nl> ppp b / doc / opencv . bib <nl> @ article { felzenszwalb_bp <nl> month = { October } <nl> } <nl> <nl> + @ article { dalal_hog , <nl> + author = { Navneet Dalal and Bill Triggs } , <nl> + title = { Histogram of Oriented Gradients for Human Detection } , <nl> + booktitle = { CVPR } , <nl> + year = { 2005 } <nl> + } <nl> + <nl> # ' ' ' [ Bradski98 ] ' ' ' G . R . Bradski . Computer vision face tracking as a component of a perceptual user interface . In Workshop on Applications of Computer Vision , pages 214 ? 219 , Princeton , NJ , Oct . 1998 . < < BR > > Updated version can be found at http : / / www . intel . com / technology / itj / q21998 / articles / art \ _2 . htm . < < BR > > Also , it is included into OpenCV distribution ( [ [ attachment : camshift . pdf ] ] ) <nl> # ' ' ' [ Burt81 ] ' ' ' P . J . Burt , T . H . Hong , A . Rosenfeld . Segmentation and Estimation of Image Region Properties Through Cooperative Hierarchical Computation . IEEE Tran . On SMC , Vol . 11 , N . 12 , 1981 , pp . 802 - 809 . <nl> # ' ' ' [ Canny86 ] ' ' ' J . Canny . A Computational Approach to Edge Detection , IEEE Trans . on Pattern Analysis and Machine Intelligence , 8 ( 6 ) , pp . 679 - 698 ( 1986 ) . <nl>
added bib link to the article in GPU docs ( for HOG )
opencv/opencv
b7b21966c32a5496ed4ce8ff0a61043126028260
2011-01-27T07:26:38Z
mmm a / googletest / include / gtest / internal / gtest - internal . h <nl> ppp b / googletest / include / gtest / internal / gtest - internal . h <nl> struct FlatTupleBase < FlatTuple < T . . . > , IndexSequence < Idx . . . > > <nl> <nl> / / Analog to std : : tuple but with different tradeoffs . <nl> / / This class minimizes the template instantiation depth , thus allowing more <nl> - / / elements that std : : tuple would . std : : tuple has been seen to require an <nl> + / / elements than std : : tuple would . std : : tuple has been seen to require an <nl> / / instantiation depth of more than 10x the number of elements in some <nl> / / implementations . <nl> / / FlatTuple and ElemFromList are not recursive and have a fixed depth <nl> template < typename . . . T > <nl> class FlatTuple <nl> : private FlatTupleBase < FlatTuple < T . . . > , <nl> typename MakeIndexSequence < sizeof . . . ( T ) > : : type > { <nl> - using Indices = typename FlatTuple : : FlatTupleBase : : Indices ; <nl> + using Indices = typename FlatTupleBase < <nl> + FlatTuple < T . . . > , typename MakeIndexSequence < sizeof . . . ( T ) > : : type > : : Indices ; <nl> <nl> public : <nl> FlatTuple ( ) = default ; <nl>
Merge pull request from bgianfo : master
google/googletest
200ff599496e20f4e39566feeaf2f6734ca7570f
2019-11-20T19:16:54Z
mmm a / Code / CryEngine / CryCommon / CryEntitySystem / IEntityComponent . h <nl> ppp b / Code / CryEngine / CryCommon / CryEntitySystem / IEntityComponent . h <nl> struct IParticleEntityComponent : public IEntityComponent <nl> <nl> virtual void SetParticleEffectName ( const char * szEffectName ) = 0 ; <nl> } ; <nl> + <nl> + / / ! Component interface in order for Editor actions such as material drag and drop to work <nl> + struct IEditorEntityComponent : public IEntityComponent <nl> + { <nl> + static void ReflectType ( Schematyc : : CTypeDesc < IEditorEntityComponent > & desc ) <nl> + { <nl> + desc . SetGUID ( " { BB42BB62 - E91A - 4AD2 - A75F - 363C866A2332 } " _cry_guid ) ; <nl> + } <nl> + <nl> + / / ! Called to permanently set the material on a slot <nl> + / / ! Only handle this if your component owns the specified slot <nl> + virtual bool SetMaterial ( int slotId , const char * szMaterial ) = 0 ; <nl> + } ; <nl> \ No newline at end of file <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AdvancedAnimationComponent . cpp <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AdvancedAnimationComponent . cpp <nl> namespace Cry <nl> { <nl> LoadFromDisk ( ) ; <nl> ResetCharacter ( ) ; <nl> + <nl> + / / Update Editor UI to show the default object material <nl> + if ( m_materialPath . value . empty ( ) & & m_pCachedCharacter ! = nullptr ) <nl> + { <nl> + if ( IMaterial * pMaterial = m_pCachedCharacter - > GetMaterial ( ) ) <nl> + { <nl> + m_materialPath = pMaterial - > GetName ( ) ; <nl> + } <nl> + } <nl> } <nl> <nl> CBaseMeshComponent : : ProcessEvent ( event ) ; <nl> namespace Cry <nl> { <nl> m_defaultScopeSettings . m_fragmentName = szName ; <nl> } <nl> + <nl> + bool CAdvancedAnimationComponent : : SetMaterial ( int slotId , const char * szMaterial ) <nl> + { <nl> + if ( slotId = = GetEntitySlotId ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( szMaterial , false ) ) <nl> + { <nl> + m_materialPath = szMaterial ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + else if ( szMaterial [ 0 ] = = ' \ 0 ' ) <nl> + { <nl> + m_materialPath . value . clear ( ) ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , nullptr ) ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> } <nl> } <nl> \ No newline at end of file <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AdvancedAnimationComponent . h <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AdvancedAnimationComponent . h <nl> class CAdvancedAnimationComponent <nl> virtual uint64 GetEventMask ( ) const override ; <nl> / / ~ IEntityComponent <nl> <nl> + / / IEditorEntityComponent <nl> + virtual bool SetMaterial ( int slotId , const char * szMaterial ) override ; <nl> + / / ~ IEditorEntityComponent <nl> + <nl> public : <nl> struct SDefaultScopeSettings <nl> { <nl> class CAdvancedAnimationComponent <nl> desc . SetIcon ( " icons : General / Mannequin . ico " ) ; <nl> desc . SetComponentFlags ( { IEntityComponent : : EFlags : : Transform , IEntityComponent : : EFlags : : Socket , IEntityComponent : : EFlags : : Attach } ) ; <nl> <nl> + desc . AddBase < IEditorEntityComponent > ( ) ; <nl> + <nl> desc . AddMember ( & CAdvancedAnimationComponent : : m_type , ' type ' , " Type " , " Type " , " Determines the behavior of the static mesh " , EMeshType : : RenderAndCollider ) ; <nl> desc . AddMember ( & CAdvancedAnimationComponent : : m_characterFile , ' file ' , " Character " , " Character " , " Determines the character to load " , " " ) ; <nl> + desc . AddMember ( & CAdvancedAnimationComponent : : m_materialPath , ' mat ' , " Material " , " Material " , " Specifies the override material for the selected object " , " " ) ; <nl> desc . AddMember ( & CAdvancedAnimationComponent : : m_renderParameters , ' rend ' , " Render " , " Rendering Settings " , " Settings for the rendered representation of the component " , SRenderParameters ( ) ) ; <nl> <nl> desc . AddMember ( & CAdvancedAnimationComponent : : m_databasePath , ' dbpa ' , " DatabasePath " , " Animation Database " , " Path to the Mannequin . adb file " , " " ) ; <nl> class CAdvancedAnimationComponent <nl> } <nl> <nl> m_pEntity - > SetCharacter ( m_pCachedCharacter , GetOrMakeEntitySlotId ( ) , false ) ; <nl> + <nl> + if ( ! m_materialPath . value . empty ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( m_materialPath . value , false ) ) <nl> + { <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + } <nl> + <nl> SetAnimationDrivenMotion ( m_bAnimationDrivenMotion ) ; <nl> <nl> if ( m_pControllerDefinition ! = nullptr ) <nl> class CAdvancedAnimationComponent <nl> <nl> Schematyc : : CharacterFileName m_characterFile ; <nl> Schematyc : : MannequinAnimationDatabasePath m_databasePath ; <nl> + Schematyc : : MaterialFileName m_materialPath ; <nl> <nl> SDefaultScopeSettings m_defaultScopeSettings ; <nl> <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AlembicComponent . cpp <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AlembicComponent . cpp <nl> namespace Cry <nl> if ( m_filePath . value . size ( ) > 0 ) <nl> { <nl> m_pEntity - > LoadGeomCache ( GetOrMakeEntitySlotId ( ) , m_filePath . value ) ; <nl> + <nl> + if ( ! m_materialPath . value . empty ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( m_materialPath . value , false ) ) <nl> + { <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + } <nl> } <nl> } <nl> <nl> namespace Cry <nl> if ( event . event = = ENTITY_EVENT_COMPONENT_PROPERTY_CHANGED ) <nl> { <nl> Initialize ( ) ; <nl> + <nl> + / / Update Editor UI to show the default object material <nl> + if ( m_materialPath . value . empty ( ) ) <nl> + { <nl> + if ( IGeomCacheRenderNode * pRenderNode = m_pEntity - > GetGeomCacheRenderNode ( GetEntitySlotId ( ) ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = pRenderNode - > GetMaterial ( ) ) <nl> + { <nl> + m_materialPath = pMaterial - > GetName ( ) ; <nl> + } <nl> + } <nl> + } <nl> } <nl> } <nl> <nl> namespace Cry <nl> { <nl> m_filePath = szFilePath ; <nl> } <nl> + <nl> + bool CAlembicComponent : : SetMaterial ( int slotId , const char * szMaterial ) <nl> + { <nl> + if ( slotId = = GetEntitySlotId ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( szMaterial , false ) ) <nl> + { <nl> + m_materialPath = szMaterial ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + else if ( szMaterial [ 0 ] = = ' \ 0 ' ) <nl> + { <nl> + m_materialPath . value . clear ( ) ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , nullptr ) ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> } <nl> } <nl> \ No newline at end of file <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AlembicComponent . h <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AlembicComponent . h <nl> namespace Cry <nl> namespace DefaultComponents <nl> { <nl> class CAlembicComponent <nl> - : public IEntityComponent <nl> + : public IEditorEntityComponent <nl> { <nl> protected : <nl> friend CPlugin_CryDefaultEntities ; <nl> namespace Cry <nl> virtual uint64 GetEventMask ( ) const final ; <nl> / / ~ IEntityComponent <nl> <nl> + / / IEditorEntityComponent <nl> + virtual bool SetMaterial ( int slotId , const char * szMaterial ) override ; <nl> + / / ~ IEditorEntityComponent <nl> + <nl> public : <nl> CAlembicComponent ( ) { } <nl> virtual ~ CAlembicComponent ( ) { } <nl> namespace Cry <nl> desc . SetIcon ( " icons : ObjectTypes / object . ico " ) ; <nl> desc . SetComponentFlags ( { IEntityComponent : : EFlags : : Transform , IEntityComponent : : EFlags : : Socket , IEntityComponent : : EFlags : : Attach } ) ; <nl> <nl> + desc . AddBase < IEditorEntityComponent > ( ) ; <nl> + <nl> desc . AddMember ( & CAlembicComponent : : m_filePath , ' file ' , " FilePath " , " File " , " Determines the geom cache file ( abc / cbc ) to load " , " % ENGINE % / EngineAssets / GeomCaches / default . cbc " ) ; <nl> + desc . AddMember ( & CAlembicComponent : : m_materialPath , ' mat ' , " Material " , " Material " , " Specifies the override material for the selected object " , " " ) ; <nl> } <nl> <nl> virtual void Enable ( bool bEnable ) ; <nl> namespace Cry <nl> <nl> protected : <nl> Schematyc : : GeomCacheFileName m_filePath ; <nl> + Schematyc : : MaterialFileName m_materialPath ; <nl> } ; <nl> } <nl> } <nl> \ No newline at end of file <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AnimatedMeshComponent . cpp <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AnimatedMeshComponent . cpp <nl> void CAnimatedMeshComponent : : ResetObject ( ) <nl> <nl> m_pEntity - > SetCharacter ( m_pCachedCharacter , GetOrMakeEntitySlotId ( ) , false ) ; <nl> <nl> + if ( ! m_materialPath . value . empty ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( m_materialPath . value , false ) ) <nl> + { <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + } <nl> + <nl> if ( m_defaultAnimation . value . size ( ) > 0 ) <nl> { <nl> m_animationParams . m_fPlaybackSpeed = m_defaultAnimationSpeed ; <nl> void CAnimatedMeshComponent : : ProcessEvent ( const SEntityEvent & event ) <nl> <nl> LoadFromDisk ( ) ; <nl> ResetObject ( ) ; <nl> + <nl> + / / Update Editor UI to show the default object material <nl> + if ( m_materialPath . value . empty ( ) & & m_pCachedCharacter ! = nullptr ) <nl> + { <nl> + if ( IMaterial * pMaterial = m_pCachedCharacter - > GetMaterial ( ) ) <nl> + { <nl> + m_materialPath = pMaterial - > GetName ( ) ; <nl> + } <nl> + } <nl> } <nl> <nl> CBaseMeshComponent : : ProcessEvent ( event ) ; <nl> void CAnimatedMeshComponent : : SetDefaultAnimationName ( const char * szPath ) <nl> { <nl> m_defaultAnimation = szPath ; <nl> } <nl> + <nl> + bool CAnimatedMeshComponent : : SetMaterial ( int slotId , const char * szMaterial ) <nl> + { <nl> + if ( slotId = = GetEntitySlotId ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( szMaterial , false ) ) <nl> + { <nl> + m_materialPath = szMaterial ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + else if ( szMaterial [ 0 ] = = ' \ 0 ' ) <nl> + { <nl> + m_materialPath . value . clear ( ) ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , nullptr ) ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> } <nl> } <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AnimatedMeshComponent . h <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / AnimatedMeshComponent . h <nl> namespace Cry <nl> virtual void ProcessEvent ( const SEntityEvent & event ) final ; <nl> / / ~ IEntityComponent <nl> <nl> + / / IEditorEntityComponent <nl> + virtual bool SetMaterial ( int slotId , const char * szMaterial ) override ; <nl> + / / ~ IEditorEntityComponent <nl> + <nl> public : <nl> CAnimatedMeshComponent ( ) { } <nl> virtual ~ CAnimatedMeshComponent ( ) { } <nl> namespace Cry <nl> desc . SetDescription ( " A component containing a simple mesh that can be animated " ) ; <nl> desc . SetComponentFlags ( { IEntityComponent : : EFlags : : Transform , IEntityComponent : : EFlags : : Socket , IEntityComponent : : EFlags : : Attach } ) ; <nl> <nl> + desc . AddBase < IEditorEntityComponent > ( ) ; <nl> + <nl> desc . AddMember ( & CAnimatedMeshComponent : : m_type , ' type ' , " Type " , " Type " , " Determines the behavior of the static mesh " , EMeshType : : RenderAndCollider ) ; <nl> <nl> desc . AddMember ( & CAnimatedMeshComponent : : m_filePath , ' file ' , " FilePath " , " File " , " Determines the animated mesh to load " , " " ) ; <nl> + desc . AddMember ( & CAnimatedMeshComponent : : m_materialPath , ' mat ' , " Material " , " Material " , " Specifies the override material for the selected object " , " " ) ; <nl> desc . AddMember ( & CAnimatedMeshComponent : : m_renderParameters , ' rend ' , " Render " , " Rendering Settings " , " Settings for the rendered representation of the component " , SRenderParameters ( ) ) ; <nl> <nl> desc . AddMember ( & CAnimatedMeshComponent : : m_defaultAnimation , ' anim ' , " Animation " , " Default Animation " , " Specifies the animation we want to play by default " , " " ) ; <nl> namespace Cry <nl> CryCharAnimationParams m_animationParams ; <nl> <nl> Schematyc : : CharacterFileName m_filePath ; <nl> + Schematyc : : MaterialFileName m_materialPath ; <nl> <nl> Schematyc : : LowLevelAnimationName m_defaultAnimation ; <nl> bool m_bLoopDefaultAnimation = false ; <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / BaseMeshComponent . h <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / BaseMeshComponent . h <nl> static void ReflectType ( Schematyc : : CTypeDesc < SRenderParameters > & desc ) <nl> <nl> / / Base implementation for our physics mesh components <nl> class CBaseMeshComponent <nl> - : public IEntityComponent <nl> + : public IEditorEntityComponent <nl> { <nl> protected : <nl> / / IEntityComponent <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / StaticMeshComponent . cpp <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / StaticMeshComponent . cpp <nl> void CStaticMeshComponent : : SetFilePath ( const char * szPath ) <nl> { <nl> m_filePath . value = szPath ; <nl> } <nl> + <nl> + bool CStaticMeshComponent : : SetMaterial ( int slotId , const char * szMaterial ) <nl> + { <nl> + if ( slotId = = GetEntitySlotId ( ) ) <nl> + { <nl> + if ( IMaterial * pMaterial = gEnv - > p3DEngine - > GetMaterialManager ( ) - > LoadMaterial ( szMaterial , false ) ) <nl> + { <nl> + m_materialPath = szMaterial ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , pMaterial ) ; <nl> + } <nl> + else if ( szMaterial [ 0 ] = = ' \ 0 ' ) <nl> + { <nl> + m_materialPath . value . clear ( ) ; <nl> + m_pEntity - > SetSlotMaterial ( GetEntitySlotId ( ) , nullptr ) ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> } } / / namespace Cry : : DefaultComponents <nl> mmm a / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / StaticMeshComponent . h <nl> ppp b / Code / CryPlugins / CryDefaultEntities / Module / DefaultComponents / Geometry / StaticMeshComponent . h <nl> class CStaticMeshComponent <nl> # endif <nl> / / ~ IEntityComponent <nl> <nl> + / / IEditorEntityComponent <nl> + virtual bool SetMaterial ( int slotId , const char * szMaterial ) override ; <nl> + / / ~ IEditorEntityComponent <nl> + <nl> # ifndef RELEASE <nl> / / IEntityComponentPreviewer <nl> virtual void SerializeProperties ( Serialization : : IArchive & archive ) final { } <nl> class CStaticMeshComponent <nl> desc . SetIcon ( " icons : ObjectTypes / object . ico " ) ; <nl> desc . SetComponentFlags ( { IEntityComponent : : EFlags : : Transform , IEntityComponent : : EFlags : : Socket , IEntityComponent : : EFlags : : Attach } ) ; <nl> <nl> + desc . AddBase < IEditorEntityComponent > ( ) ; <nl> + <nl> desc . AddMember ( & CStaticMeshComponent : : m_type , ' type ' , " Type " , " Type " , " Determines the behavior of the static mesh " , EMeshType : : RenderAndCollider ) ; <nl> <nl> desc . AddMember ( & CStaticMeshComponent : : m_filePath , ' file ' , " FilePath " , " File " , " Determines the CGF to load " , " % ENGINE % / EngineAssets / Objects / primitive_sphere . cgf " ) ; <nl> mmm a / Code / Sandbox / EditorQt / LevelEditor / LevelEditorViewport . cpp <nl> ppp b / Code / Sandbox / EditorQt / LevelEditor / LevelEditorViewport . cpp <nl> static CPopupMenuItem & AddCheckbox ( CPopupMenuItem & menu , const char * text , int * <nl> <nl> namespace Private_AssetDrag <nl> { <nl> - static bool TryAssetDragCreate ( const CDragDropData * pDragDropData , string & className ) <nl> + static CAsset * GetAsset ( const CDragDropData * pDragDropData ) <nl> { <nl> if ( ! pDragDropData - > HasCustomData ( " Assets " ) ) <nl> { <nl> - return false ; <nl> + return nullptr ; <nl> } <nl> <nl> QVector < quintptr > assets ; <nl> static bool TryAssetDragCreate ( const CDragDropData * pDragDropData , string & class <nl> if ( assets . size ( ) > 1 ) <nl> { <nl> / / We do not handle multi - asset drops . <nl> - return false ; <nl> - } <nl> - <nl> - CAssetManager * const pAssetManager = GetIEditor ( ) - > GetAssetManager ( ) ; <nl> - <nl> - CAsset * const pAsset = ( CAsset * ) assets [ 0 ] ; <nl> - assert ( pAsset ) ; <nl> - <nl> - const char * szClassName = pAsset - > GetType ( ) - > GetObjectClassName ( ) ; <nl> - if ( ! szClassName ) <nl> - { <nl> - return false ; <nl> + return nullptr ; <nl> } <nl> <nl> - className = szClassName ; <nl> - return true ; <nl> + return reinterpret_cast < CAsset * > ( assets [ 0 ] ) ; <nl> } <nl> <nl> static bool TryObjectCreate ( const CDragDropData * pDragDropData , string & className ) <nl> bool CLevelEditorViewport : : DragEvent ( EDragEvent eventId , QEvent * event , int flag <nl> bool result = Super : : DragEvent ( eventId , event , flags ) ; <nl> if ( ! result ) <nl> { <nl> - return AssetDragCreate ( eventId , event , flags ) ; <nl> + return AssetDragEvent ( eventId , event , flags ) ; <nl> } <nl> return result ; <nl> } <nl> <nl> - bool CLevelEditorViewport : : AssetDragCreate ( EDragEvent eventId , QEvent * event , int flags ) <nl> + bool CLevelEditorViewport : : AssetDragEvent ( EDragEvent eventId , QEvent * event , int flags ) <nl> { <nl> using namespace Private_AssetDrag ; <nl> <nl> - QDropEvent * const pDragEvent = ( QDropEvent * ) event ; <nl> - const CDragDropData * const pDragDropData = CDragDropData : : FromMimeData ( pDragEvent - > mimeData ( ) ) ; <nl> + QDropEvent * const pDragEvent = eventId ! = EDragEvent : : eDragLeave ? ( QDropEvent * ) event : nullptr ; <nl> + const CDragDropData * const pDragDropData = pDragEvent ! = nullptr ? CDragDropData : : FromMimeData ( pDragEvent - > mimeData ( ) ) : nullptr ; <nl> <nl> string className ; <nl> + CAsset * pAsset = pDragDropData ! = nullptr ? GetAsset ( pDragDropData ) : nullptr ; <nl> + if ( pAsset ! = nullptr ) <nl> + { <nl> + QDropEvent * drop = static_cast < QDropEvent * > ( event ) ; <nl> + CPoint point ( drop - > pos ( ) . x ( ) , drop - > pos ( ) . y ( ) ) ; <nl> + HitContext hitContext ; <nl> + string dragText ; <nl> + if ( HitTest ( point , hitContext ) & & hitContext . object ! = nullptr & & hitContext . object - > CanApplyAsset ( * pAsset , & dragText ) ) <nl> + { <nl> + switch ( eventId ) <nl> + { <nl> + case eDragMove : <nl> + { <nl> + QDragMoveEvent * dragMove = static_cast < QDragMoveEvent * > ( event ) ; <nl> <nl> - if ( ! TryAssetDragCreate ( pDragDropData , className ) & & ! TryObjectCreate ( pDragDropData , className ) ) <nl> + CDragDropData : : ShowDragText ( GetViewWidget ( ) , QString ( dragText ) ) ; <nl> + } <nl> + break ; <nl> + case eDragLeave : <nl> + { <nl> + CDragDropData : : ClearDragTooltip ( GetViewWidget ( ) ) ; <nl> + } <nl> + break ; <nl> + case eDrop : <nl> + { <nl> + auto action = drop - > proposedAction ( ) ; <nl> + drop - > acceptProposedAction ( ) ; <nl> + <nl> + CUndo undo ( " Apply asset " ) ; <nl> + hitContext . object - > ApplyAsset ( * pAsset , & hitContext ) ; <nl> + } <nl> + break ; <nl> + } <nl> + <nl> + event - > accept ( ) ; <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + className = pAsset - > GetType ( ) - > GetObjectClassName ( ) ; <nl> + if ( className . empty ( ) ) <nl> + { <nl> + if ( eventId = = eDragEnter ) <nl> + { <nl> + event - > accept ( ) ; <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> + } <nl> + else if ( pDragDropData ! = nullptr & & ! TryObjectCreate ( pDragDropData , className ) ) <nl> { <nl> return false ; <nl> } <nl> mmm a / Code / Sandbox / EditorQt / LevelEditor / LevelEditorViewport . h <nl> ppp b / Code / Sandbox / EditorQt / LevelEditor / LevelEditorViewport . h <nl> class CLevelEditorViewport : public CRenderViewport <nl> void RenderSnappingGrid ( ) ; <nl> void AddCameraMenuItems ( CPopupMenuItem & menu ) ; <nl> <nl> - bool AssetDragCreate ( EDragEvent eventId , QEvent * event , int flags ) ; <nl> + bool AssetDragEvent ( EDragEvent eventId , QEvent * event , int flags ) ; <nl> <nl> float m_camFOV ; <nl> QViewportHeader * m_headerWidget ; <nl> mmm a / Code / Sandbox / EditorQt / Objects / EntityObject . cpp <nl> ppp b / Code / Sandbox / EditorQt / Objects / EntityObject . cpp <nl> bool CEntityObject : : HitTestCharacter ( ICharacterInstance * pCharacter , HitContext & <nl> <nl> bool CEntityObject : : HitTestEntity ( HitContext & hc , bool & bHavePhysics ) <nl> { <nl> + AABB bbox ; <nl> + m_pEntity - > GetLocalBounds ( bbox ) ; <nl> + <nl> Matrix34 invertedWorldTransform = m_pEntity - > GetWorldTM ( ) . GetInverted ( ) ; <nl> <nl> Vec3 raySrc = invertedWorldTransform . TransformPoint ( hc . raySrc ) ; <nl> Vec3 rayDir = invertedWorldTransform . TransformVector ( hc . rayDir ) . GetNormalized ( ) ; <nl> <nl> - AABB bbox ; <nl> - m_pEntity - > GetLocalBounds ( bbox ) ; <nl> - <nl> / / Early exit , check bounding box <nl> Vec3 point ; <nl> if ( ! Intersect : : Ray_AABB ( raySrc , rayDir , bbox , point ) ) <nl> bool CEntityObject : : HitTestEntity ( HitContext & hc , bool & bHavePhysics ) <nl> return false ; <nl> } <nl> <nl> - SRayHitInfo hitInfo ; <nl> - hitInfo . inReferencePoint = raySrc ; <nl> - hitInfo . inRay = Ray ( raySrc , rayDir ) ; <nl> - <nl> for ( int i = 0 , n = m_pEntity - > GetSlotCount ( ) ; i < n ; + + i ) <nl> { <nl> + invertedWorldTransform = m_pEntity - > GetSlotWorldTM ( i ) . GetInverted ( ) ; <nl> + <nl> + raySrc = invertedWorldTransform . TransformPoint ( hc . raySrc ) ; <nl> + rayDir = invertedWorldTransform . TransformVector ( hc . rayDir ) . GetNormalized ( ) ; <nl> + <nl> + SRayHitInfo hitInfo ; <nl> + hitInfo . inReferencePoint = raySrc ; <nl> + hitInfo . inRay = Ray ( raySrc , rayDir ) ; <nl> + <nl> if ( IStatObj * pStatObj = m_pEntity - > GetStatObj ( i ) ) <nl> { <nl> if ( pStatObj - > RayIntersection ( hitInfo ) ) <nl> void CEntityObject : : SetMaterial ( IEditorMaterial * mtl ) <nl> UpdateMaterialInfo ( ) ; <nl> } <nl> <nl> + class CUndoComponentSlotMaterialChange : public IUndoObject <nl> + { <nl> + public : <nl> + CUndoComponentSlotMaterialChange ( IEditorEntityComponent * pComponent , int slotIndex , const char * szMaterialName ) <nl> + : m_owningEntityGUID ( pComponent - > GetEntity ( ) - > GetGuid ( ) ) <nl> + , m_componentInstanceGUID ( pComponent - > GetGUID ( ) ) <nl> + , m_slotId ( slotIndex ) <nl> + , m_materialAfterChange ( szMaterialName ) <nl> + { <nl> + if ( IMaterial * pMaterial = pComponent - > GetEntity ( ) - > GetSlotMaterial ( slotIndex ) ) <nl> + { <nl> + m_materialBeforeChange = pMaterial - > GetName ( ) ; <nl> + } <nl> + } <nl> + <nl> + virtual void Undo ( bool bUndo ) override <nl> + { <nl> + CEntityObject * pEntityObject = static_cast < CEntityObject * > ( GetIEditor ( ) - > GetObjectManager ( ) - > FindObject ( m_owningEntityGUID ) ) ; <nl> + if ( pEntityObject = = nullptr ) <nl> + return ; <nl> + <nl> + IEntity * pEntity = pEntityObject - > GetIEntity ( ) ; <nl> + if ( pEntity = = nullptr ) <nl> + return ; <nl> + <nl> + IEditorEntityComponent * pComponent = static_cast < IEditorEntityComponent * > ( pEntity - > GetComponentByGUID ( m_componentInstanceGUID ) ) ; <nl> + if ( pComponent = = nullptr ) <nl> + return ; <nl> + <nl> + pComponent - > SetMaterial ( m_slotId , m_materialBeforeChange . c_str ( ) ) ; <nl> + GetIEditor ( ) - > GetObjectManager ( ) - > EmitPopulateInspectorEvent ( ) ; <nl> + } <nl> + <nl> + virtual void Redo ( ) override <nl> + { <nl> + CEntityObject * pEntityObject = static_cast < CEntityObject * > ( GetIEditor ( ) - > GetObjectManager ( ) - > FindObject ( m_owningEntityGUID ) ) ; <nl> + if ( pEntityObject = = nullptr ) <nl> + return ; <nl> + <nl> + IEntity * pEntity = pEntityObject - > GetIEntity ( ) ; <nl> + if ( pEntity = = nullptr ) <nl> + return ; <nl> + <nl> + if ( IEditorEntityComponent * pComponent = static_cast < IEditorEntityComponent * > ( pEntity - > GetComponentByGUID ( m_componentInstanceGUID ) ) ) <nl> + { <nl> + pComponent - > SetMaterial ( m_slotId , m_materialAfterChange . c_str ( ) ) ; <nl> + GetIEditor ( ) - > GetObjectManager ( ) - > EmitPopulateInspectorEvent ( ) ; <nl> + } <nl> + } <nl> + <nl> + private : <nl> + virtual int GetSize ( ) { return sizeof ( CUndoComponentSlotMaterialChange ) ; } <nl> + virtual const char * GetDescription ( ) { return " Entity Component Material Change " ; } <nl> + <nl> + const CryGUID & m_owningEntityGUID ; <nl> + CryGUID m_componentInstanceGUID ; <nl> + int m_slotId ; <nl> + string m_materialBeforeChange ; <nl> + string m_materialAfterChange ; <nl> + } ; <nl> + <nl> + bool CEntityObject : : ApplyAsset ( const CAsset & asset , HitContext * pHitContext ) <nl> + { <nl> + if ( ! strcmp ( asset . GetType ( ) - > GetTypeName ( ) , " Material " ) ) <nl> + { <nl> + / / This function will go through all slots in order to find out which sub - slot of the entity the material was dragged on to <nl> + / / We then apply the material to the component that owns that instance . <nl> + if ( m_pEntity ! = nullptr ) <nl> + { <nl> + int hitSlotIndex = - 1 ; <nl> + <nl> + for ( int slotIndex = 0 , slotCount = m_pEntity - > GetSlotCount ( ) ; slotIndex < slotCount ; + + slotIndex ) <nl> + { <nl> + Matrix34 invertedWorldTransform = m_pEntity - > GetSlotWorldTM ( slotIndex ) . GetInverted ( ) ; <nl> + <nl> + Vec3 raySrc = invertedWorldTransform . TransformPoint ( pHitContext - > raySrc ) ; <nl> + Vec3 rayDir = invertedWorldTransform . TransformVector ( pHitContext - > rayDir ) . GetNormalized ( ) ; <nl> + <nl> + SRayHitInfo hitInfo ; <nl> + hitInfo . inReferencePoint = raySrc ; <nl> + hitInfo . inRay = Ray ( raySrc , rayDir ) ; <nl> + <nl> + if ( IStatObj * pStatObj = m_pEntity - > GetStatObj ( slotIndex ) ) <nl> + { <nl> + if ( pStatObj - > RayIntersection ( hitInfo ) ) <nl> + { <nl> + float distance = pHitContext - > raySrc . GetDistance ( GetWorldTM ( ) . TransformPoint ( hitInfo . vHitPos ) ) ; <nl> + if ( isneg ( hitSlotIndex ) | | distance < pHitContext - > dist ) <nl> + { <nl> + hitSlotIndex = slotIndex ; <nl> + pHitContext - > dist = distance ; <nl> + } <nl> + } <nl> + } <nl> + else if ( ICharacterInstance * pCharacter = m_pEntity - > GetCharacter ( slotIndex ) ) <nl> + { <nl> + bool hasPhysics = false ; <nl> + if ( HitTestCharacter ( pCharacter , * pHitContext , hitInfo , hasPhysics ) ) <nl> + { <nl> + float distance = pHitContext - > raySrc . GetDistance ( GetWorldTM ( ) . TransformPoint ( hitInfo . vHitPos ) ) ; <nl> + if ( isneg ( hitSlotIndex ) | | distance < pHitContext - > dist ) <nl> + { <nl> + hitSlotIndex = slotIndex ; <nl> + pHitContext - > dist = distance ; <nl> + } <nl> + } <nl> + } <nl> + else if ( IGeomCacheRenderNode * pGeomCache = m_pEntity - > GetGeomCacheRenderNode ( slotIndex ) ) <nl> + { <nl> + if ( pGeomCache - > RayIntersection ( hitInfo ) ) <nl> + { <nl> + float distance = pHitContext - > raySrc . GetDistance ( GetWorldTM ( ) . TransformPoint ( hitInfo . vHitPos ) ) ; <nl> + if ( isneg ( hitSlotIndex ) | | distance < pHitContext - > dist ) <nl> + { <nl> + hitSlotIndex = slotIndex ; <nl> + pHitContext - > dist = distance ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl> + if ( ! isneg ( hitSlotIndex ) ) <nl> + { <nl> + DynArray < IEditorEntityComponent * > components ; <nl> + m_pEntity - > GetAllComponents ( components ) ; <nl> + <nl> + const char * szMaterialFileName = asset . GetFile ( 0 ) ; <nl> + if ( szMaterialFileName = = nullptr ) <nl> + { <nl> + szMaterialFileName = " " ; <nl> + } <nl> + <nl> + for ( IEditorEntityComponent * pComponent : components ) <nl> + { <nl> + CUndo : : Record ( new CUndoComponentSlotMaterialChange ( pComponent , hitSlotIndex , szMaterialFileName ) ) ; <nl> + <nl> + if ( pComponent - > SetMaterial ( hitSlotIndex , szMaterialFileName ) ) <nl> + { <nl> + GetIEditor ( ) - > GetObjectManager ( ) - > EmitPopulateInspectorEvent ( ) ; <nl> + return true ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl> + / / Fall back to setting legacy " global " material <nl> + return CBaseObject : : ApplyAsset ( asset ) ; <nl> + } <nl> + <nl> + return CBaseObject : : ApplyAsset ( asset ) ; <nl> + } <nl> + <nl> IEditorMaterial * CEntityObject : : GetRenderMaterial ( ) const <nl> { <nl> if ( GetMaterial ( ) ) <nl> mmm a / Code / Sandbox / EditorQt / Objects / EntityObject . h <nl> ppp b / Code / Sandbox / EditorQt / Objects / EntityObject . h <nl> class SANDBOX_API CEntityObject : public CBaseObject <nl> virtual void SetMaterial ( IEditorMaterial * mtl ) ; <nl> virtual IEditorMaterial * GetRenderMaterial ( ) const ; <nl> <nl> + virtual bool ApplyAsset ( const CAsset & asset , HitContext * pHitContext = nullptr ) override ; <nl> + <nl> virtual void InvalidateGeometryFile ( const string & gamePath ) override ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> mmm a / Code / Sandbox / Plugins / EditorCommon / Objects / BaseObject . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorCommon / Objects / BaseObject . cpp <nl> <nl> # include " UsedResources . h " <nl> # include " IEditorMaterial . h " <nl> # include " Grid . h " <nl> + # include " QtUtil . h " <nl> <nl> # include " IAIManager . h " <nl> # include " IUndoObject . h " <nl> void CBaseObject : : OnMtlResolved ( uint32 id , bool success , const char * orgName , co <nl> } <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + bool CBaseObject : : ApplyAsset ( const CAsset & asset , HitContext * pHitContext ) <nl> + { <nl> + if ( ! strcmp ( asset . GetType ( ) - > GetTypeName ( ) , " Material " ) ) <nl> + { <nl> + const char * szMaterialFileName = asset . GetFile ( 0 ) ; <nl> + if ( szMaterialFileName = = nullptr ) <nl> + { <nl> + szMaterialFileName = " " ; <nl> + } <nl> + <nl> + SetMaterial ( szMaterialFileName ) ; <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + bool CBaseObject : : CanApplyAsset ( const CAsset & asset , string * pApplyTextOut ) const <nl> + { <nl> + if ( ! strcmp ( asset . GetType ( ) - > GetTypeName ( ) , " Material " ) ) <nl> + { <nl> + if ( pApplyTextOut ! = nullptr ) <nl> + { <nl> + * pApplyTextOut = QtUtil : : ToString ( QObject : : tr ( " Assign Material " ) ) ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + return false ; <nl> + } <nl> + <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void CBaseObject : : SetLayerModified ( ) <nl> { <nl> mmm a / Code / Sandbox / Plugins / EditorCommon / Objects / BaseObject . h <nl> ppp b / Code / Sandbox / Plugins / EditorCommon / Objects / BaseObject . h <nl> class SubObjectSelectionReferenceFrameCalculator ; <nl> class CPopupMenuItem ; <nl> class CInspectorWidgetCreator ; <nl> class CObjectLayer ; <nl> + struct HitContext ; <nl> + class CAsset ; <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> typedef _smart_ptr < CBaseObject > CBaseObjectPtr ; <nl> class EDITOR_COMMON_API CBaseObject : public CObject , public _i_reference_target <nl> / / Get the material name . Even though the material pointer is null , the material name can exist separately . <nl> virtual string GetMaterialName ( ) const ; <nl> <nl> + / / ! Assigns the specified asset to the object , for example to apply material <nl> + / / ! \ param pHitContext Specifies raycast context , if we are applying the asset via a drag action <nl> + virtual bool ApplyAsset ( const CAsset & asset , HitContext * pHitContext = nullptr ) ; <nl> + virtual bool CanApplyAsset ( const CAsset & asset , string * pApplyTextOut = nullptr ) const ; <nl> + <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / ! Analyze errors for this object . <nl> virtual void Validate ( ) ; <nl>
! F ( CE - 16318 ) ( Sandbox ) Add support for dragging material from asset browser onto objects in the scene to assign
CRYTEK/CRYENGINE
354f4728ef999b76a8bb3e066559333eba9fd6fe
2018-05-15T16:52:28Z
mmm a / src / app / ui / timeline . cpp <nl> ppp b / src / app / ui / timeline . cpp <nl> void Timeline : : updateUsingEditor ( Editor * editor ) <nl> <nl> detachDocument ( ) ; <nl> <nl> + if ( m_range . enabled ( ) ) { <nl> + m_range . disableRange ( ) ; <nl> + invalidate ( ) ; <nl> + } <nl> + <nl> / / We always update the editor . In this way the timeline keeps in <nl> / / sync with the active editor . <nl> m_editor = editor ; <nl>
Disable timeline range when we select other document
aseprite/aseprite
09bfa3e61b13f134d784b32734153d2ae490c075
2015-06-15T14:16:57Z
mmm a / js / server / modules / org / arangodb / foxx / manager . js <nl> ppp b / js / server / modules / org / arangodb / foxx / manager . js <nl> <nl> <nl> var db = require ( " internal " ) . db ; <nl> var fs = require ( " fs " ) ; <nl> + var joi = require ( " joi " ) ; <nl> var utils = require ( " org / arangodb / foxx / manager - utils " ) ; <nl> var store = require ( " org / arangodb / foxx / store " ) ; <nl> var console = require ( " console " ) ; <nl> <nl> var throwFileNotFound = arangodb . throwFileNotFound ; <nl> <nl> var manifestSchema = { <nl> - " assets " : [ false , " object " ] , <nl> - " author " : [ false , " string " ] , <nl> - " configuration " : [ false , " object " ] , <nl> - " contributors " : [ false , " array " ] , <nl> - " controllers " : [ false , " object " ] , <nl> - " defaultDocument " : [ false , " string " ] , <nl> - " description " : [ true , " string " ] , <nl> - " engines " : [ false , " object " ] , <nl> - " files " : [ false , " object " ] , <nl> - " isSystem " : [ false , " boolean " ] , <nl> - " keywords " : [ false , " array " ] , <nl> - " lib " : [ false , " string " ] , <nl> - " license " : [ false , " string " ] , <nl> - " name " : [ true , " string " ] , <nl> - " repository " : [ false , " object " ] , <nl> - " setup " : [ false , " string " ] , <nl> - " teardown " : [ false , " string " ] , <nl> - " thumbnail " : [ false , " string " ] , <nl> - " version " : [ true , " string " ] , <nl> - " rootElement " : [ false , " boolean " ] , <nl> - " exports " : [ false , [ " object " , " string " ] ] <nl> + assets : joi . object ( ) . optional ( ) , <nl> + author : joi . string ( ) . allow ( " " ) . default ( " " ) , <nl> + configuration : joi . object ( ) . optional ( ) , <nl> + contributors : joi . array ( ) . optional ( ) , <nl> + controllers : joi . object ( ) . optional ( ) , <nl> + defaultDocument : joi . string ( ) . allow ( " " ) . optional ( ) , <nl> + description : joi . string ( ) . allow ( " " ) . default ( " " ) , <nl> + engines : joi . object ( ) . optional ( ) , <nl> + exports : joi . alternatives ( ) . try ( <nl> + joi . string ( ) . optional ( ) , <nl> + joi . object ( ) . optional ( ) <nl> + ) , <nl> + files : joi . object ( ) . optional ( ) , <nl> + isSystem : joi . boolean ( ) . default ( false ) , <nl> + keywords : joi . array ( ) . optional ( ) , <nl> + lib : joi . string ( ) . optional ( ) , <nl> + license : joi . string ( ) . optional ( ) , <nl> + name : joi . string ( ) . required ( ) , <nl> + repository : joi . object ( ) . optional ( ) , <nl> + setup : joi . string ( ) . optional ( ) , <nl> + teardown : joi . string ( ) . optional ( ) , <nl> + thumbnail : joi . string ( ) . optional ( ) , <nl> + version : joi . string ( ) . required ( ) , <nl> + rootElement : joi . boolean ( ) . default ( false ) <nl> } ; <nl> <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> var checkManifest = function ( filename , manifest ) { <nl> - / / add some default attributes <nl> - if ( ! manifest . hasOwnProperty ( " author " ) ) { <nl> - / / add a default ( empty ) author <nl> - manifest . author = " " ; <nl> - } <nl> - <nl> - if ( ! manifest . hasOwnProperty ( " description " ) ) { <nl> - / / add a default ( empty ) description <nl> - manifest . description = " " ; <nl> - } <nl> - <nl> - / / Validate all attributes specified in the manifest <nl> - / / the following attributes are allowed with these types . . . <nl> - <nl> - var failed = ! Object . keys ( manifestSchema ) . every ( function ( key ) { <nl> - var valid = true ; <nl> - <nl> - if ( manifest . hasOwnProperty ( key ) ) { <nl> - / / attribute is present in manifest , now check data type <nl> - var expectedType = manifestSchema [ key ] [ 1 ] ; <nl> - var actualType = Array . isArray ( manifest [ key ] ) ? " array " : typeof ( manifest [ key ] ) ; <nl> - <nl> - if ( ! Array . isArray ( expectedType ) ) { <nl> - valid = ( actualType = = = expectedType ) ; <nl> - } else { <nl> - valid = expectedType . some ( function ( type ) { <nl> - return actualType = = = type ; <nl> - } ) ; <nl> - } <nl> - <nl> - if ( ! valid ) { <nl> - console . error ( " Manifest ' % s ' uses an invalid data type ( % s ) for % s attribute ' % s ' " , <nl> + var valid = true ; <nl> + <nl> + Object . keys ( manifestSchema ) . forEach ( function ( key ) { <nl> + var schema = manifestSchema [ key ] ; <nl> + var value = manifest [ key ] ; <nl> + var result = joi . validate ( value , schema ) ; <nl> + if ( result . value ! = = undefined ) { <nl> + manifest [ key ] = result . value ; <nl> + } <nl> + if ( result . error ) { <nl> + valid = false ; <nl> + if ( value = = = undefined ) { <nl> + console . error ( <nl> + " Manifest ' % s ' % s for attribute ' % s ' " , <nl> filename , <nl> - actualType , <nl> - String ( expectedType ) , <nl> - key ) ; <nl> - } <nl> - } else { <nl> - / / attribute not present in manifest <nl> - valid = manifestSchema [ key ] [ 0 ] ; <nl> - <nl> - if ( ! valid ) { <nl> - / / required attribute <nl> - console . error ( " Manifest ' % s ' does not provide required attribute ' % s ' " , <nl> + result . error . message , <nl> + key <nl> + ) ; <nl> + } else { <nl> + console . error ( <nl> + " Manifest ' % s ' % s ( % s ) for attribute ' % s ' " , <nl> filename , <nl> - key ) ; <nl> + result . error . message , <nl> + manifest [ key ] , <nl> + key <nl> + ) ; <nl> } <nl> } <nl> + } ) ; <nl> <nl> - return valid ; <nl> + Object . keys ( manifest ) . forEach ( function ( key ) { <nl> + if ( ! manifestSchema [ key ] ) { <nl> + console . warn ( <nl> + " Manifest ' % s ' contains an unknown attribute ' % s ' " , <nl> + filename , <nl> + key <nl> + ) ; <nl> + } <nl> } ) ; <nl> <nl> - if ( failed ) { <nl> + if ( ! valid ) { <nl> throw new ArangoError ( { <nl> errorNum : errors . ERROR_MANIFEST_FILE_ATTRIBUTE_MISSING . code , <nl> errorMessage : errors . ERROR_MANIFEST_FILE_ATTRIBUTE_MISSING . message <nl> } ) ; <nl> } <nl> - <nl> - / / additionally check if there are superfluous attributes in the manifest <nl> - Object . keys ( manifest ) . forEach ( function ( key ) { <nl> - if ( ! manifestSchema . hasOwnProperty ( key ) ) { <nl> - console . warn ( " Manifest ' % s ' contains an unknown attribute ' % s ' " , <nl> - filename , <nl> - key ) ; <nl> - } <nl> - } ) ; <nl> } ; <nl> <nl> <nl>
Validate manifest using joi .
arangodb/arangodb
079b8c554b734c392e145b724ecdc4dba8e7a3cb
2015-03-24T12:15:53Z
mmm a / cocos / scripting / auto - generated <nl> ppp b / cocos / scripting / auto - generated <nl> @ @ - 1 + 1 @ @ <nl> - Subproject commit 96129ccc8c55a5ad145581182e487da551e2103d <nl> + Subproject commit d44b30c76a4a65795709802063b9530ea36fb0b0 <nl>
Merge pull request from CocosRobot / updategeneratedsubmodule_1388645344
cocos2d/cocos2d-x
91e25bc0b4cbd90e0b7cf1cf76a2d952adcb5b79
2014-01-02T06:51:49Z
mmm a / ChangeLog <nl> ppp b / ChangeLog <nl> <nl> + 2013 - 09 - 05 : Version 3 . 21 . 11 <nl> + <nl> + Performance and stability improvements on all platforms . <nl> + <nl> + <nl> 2013 - 09 - 04 : Version 3 . 21 . 10 <nl> <nl> Fixed Eternal : : IsEmpty logic ( issue 2870 ) . <nl> mmm a / src / version . cc <nl> ppp b / src / version . cc <nl> <nl> / / system so their names cannot be changed without changing the scripts . <nl> # define MAJOR_VERSION 3 <nl> # define MINOR_VERSION 21 <nl> - # define BUILD_NUMBER 11 <nl> + # define BUILD_NUMBER 12 <nl> # define PATCH_LEVEL 0 <nl> / / Use 1 for candidates and 0 otherwise . <nl> / / ( Boolean macro values are not supported by all preprocessors . ) <nl>
Prepare push to trunk . Now working on version 3 . 21 . 12 .
v8/v8
44e59822436200648ab4cc4401c4ff8421a67c5e
2013-09-05T16:29:07Z
mmm a / src / heap . cc <nl> ppp b / src / heap . cc <nl> Heap : : Heap ( ) <nl> max_semispace_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE ; <nl> # endif <nl> <nl> + intptr_t max_virtual = OS : : MaxVirtualMemory ( ) ; <nl> + <nl> + if ( max_virtual > 0 ) { <nl> + intptr_t half = max_virtual > > 1 ; <nl> + intptr_t quarter = max_virtual > > 2 ; <nl> + / / If we have limits on the amount of virtual memory we can use then we may <nl> + / / be forced to lower the allocation limits . We reserve one quarter of the <nl> + / / memory for young space and off - heap data . The rest is distributed as <nl> + / / described below . <nl> + if ( code_range_size_ > 0 ) { <nl> + / / Reserve a quarter of the memory for the code range . The old space <nl> + / / heap gets the remaining half . There is some unavoidable double <nl> + / / counting going on here since the heap size is measured in committed <nl> + / / virtual memory and the code range is only reserved virtual memory . <nl> + code_range_size_ = Min ( code_range_size_ , quarter ) ; <nl> + max_old_generation_size_ = Min ( max_old_generation_size_ , half ) ; <nl> + } else { <nl> + / / Reserve three quarters of the memory for the old space heap including <nl> + / / the executable code . <nl> + max_old_generation_size_ = Min ( max_old_generation_size_ , half + quarter ) ; <nl> + } <nl> + } <nl> + <nl> memset ( roots_ , 0 , sizeof ( roots_ [ 0 ] ) * kRootListLength ) ; <nl> global_contexts_list_ = NULL ; <nl> mark_compact_collector_ . heap_ = this ; <nl> mmm a / src / platform - posix . cc <nl> ppp b / src / platform - posix . cc <nl> <nl> namespace v8 { <nl> namespace internal { <nl> <nl> + <nl> + / / Maximum size of the virtual memory . 0 means there is no artificial <nl> + / / limit . <nl> + <nl> + intptr_t OS : : MaxVirtualMemory ( ) { <nl> + struct rlimit limit ; <nl> + int result = getrlimit ( RLIMIT_DATA , & limit ) ; <nl> + if ( result ! = 0 ) return 0 ; <nl> + return limit . rlim_cur ; <nl> + } <nl> + <nl> + <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> / / Math functions <nl> <nl> mmm a / src / platform - win32 . cc <nl> ppp b / src / platform - win32 . cc <nl> <nl> namespace v8 { <nl> namespace internal { <nl> <nl> + intptr_t OS : : MaxVirtualMemory ( ) { <nl> + return 0 ; <nl> + } <nl> + <nl> + <nl> / / Test for finite value - usually defined in math . h <nl> int isfinite ( double x ) { <nl> return _finite ( x ) ; <nl> mmm a / src / platform . h <nl> ppp b / src / platform . h <nl> class OS { <nl> / / positions indicated by the members of the CpuFeature enum from globals . h <nl> static uint64_t CpuFeaturesImpliedByPlatform ( ) ; <nl> <nl> + / / Maximum size of the virtual memory . 0 means there is no artificial <nl> + / / limit . <nl> + static intptr_t MaxVirtualMemory ( ) ; <nl> + <nl> / / Returns the double constant NAN <nl> static double nan_value ( ) ; <nl> <nl>
Lower heap size limits on systems that are short of virtual memory .
v8/v8
955e6a2496b81cbf4f5d8818d048db13eceb273c
2011-06-01T08:49:18Z
mmm a / fdbserver / workloads / Unreadable . actor . cpp <nl> ppp b / fdbserver / workloads / Unreadable . actor . cpp <nl> struct UnreadableWorkload : TestWorkload { <nl> key . setKey ( it - > first ) ; <nl> } <nl> <nl> - static void checkUnreadablity ( Arena arena , std : : map < KeyRef , ValueRef > const & setMap , KeyRangeMap < bool > & unreadableMap , <nl> - KeySelectorRef const & _begin , KeySelectorRef const & _end , bool isUnreadable , int limit , bool reverse ) { <nl> - <nl> + static void checkUnreadability ( std : : map < KeyRef , ValueRef > const & setMap , KeyRangeMap < bool > & unreadableMap , <nl> + KeySelectorRef const & _begin , KeySelectorRef const & _end , bool isUnreadable , <nl> + int limit , bool reverse ) { <nl> + <nl> / * <nl> for ( auto it : setMap ) { <nl> TraceEvent ( " RYWT_SetMapContents " ) . detail ( " Key " , printable ( it . first ) ) ; <nl> struct UnreadableWorkload : TestWorkload { <nl> ASSERT ( ! isUnreadable ) ; <nl> } <nl> else { <nl> - checkUnreadablity ( arena , setMap , unreadableMap , begin , end , isUnreadable , limit , reverse ) ; <nl> + checkUnreadability ( setMap , unreadableMap , begin , end , isUnreadable , limit , reverse ) ; <nl> } <nl> } <nl> else { <nl>
Remove unnecessary parameter from checkUnreadability
apple/foundationdb
09b3b7a325250177c463794d4f0007da4edd61e2
2020-09-14T04:32:47Z
mmm a / lib / Sema / TypeCheckSwitchStmt . cpp <nl> ppp b / lib / Sema / TypeCheckSwitchStmt . cpp <nl> <nl> # include " swift / Basic / APIntMap . h " <nl> # include < llvm / ADT / APFloat . h > <nl> <nl> - # include < numeric > <nl> # include < forward_list > <nl> + # include < iterator > <nl> + # include < numeric > <nl> + # include < utility > <nl> <nl> using namespace swift ; <nl> <nl> namespace { <nl> <nl> / / In type space , we reuse HEAD to help us print meaningful name , e . g . , <nl> / / tuple element name in fixits . <nl> - Identifier Head ; <nl> + DeclName Head ; <nl> std : : forward_list < Space > Spaces ; <nl> <nl> size_t computeSize ( TypeChecker & TC , const DeclContext * DC , <nl> namespace { <nl> llvm_unreachable ( " unhandled kind " ) ; <nl> } <nl> <nl> - explicit Space ( Type T , Identifier NameForPrinting ) <nl> - : Kind ( SpaceKind : : Type ) , TypeAndVal ( T ) , <nl> - Head ( NameForPrinting ) , Spaces ( { } ) { } <nl> + explicit Space ( Type T , DeclName NameForPrinting ) <nl> + : Kind ( SpaceKind : : Type ) , TypeAndVal ( T ) , Head ( NameForPrinting ) , <nl> + Spaces ( { } ) { } <nl> explicit Space ( UnknownCase_t , bool allowedButNotRequired ) <nl> : Kind ( SpaceKind : : UnknownCase ) , <nl> TypeAndVal ( Type ( ) , allowedButNotRequired ) , Head ( Identifier ( ) ) , <nl> Spaces ( { } ) { } <nl> - explicit Space ( Type T , Identifier H , ArrayRef < Space > SP ) <nl> - : Kind ( SpaceKind : : Constructor ) , TypeAndVal ( T ) , Head ( H ) , <nl> - Spaces ( SP . begin ( ) , SP . end ( ) ) { } <nl> - explicit Space ( Type T , Identifier H , std : : forward_list < Space > SP ) <nl> - : Kind ( SpaceKind : : Constructor ) , TypeAndVal ( T ) , Head ( H ) , <nl> - Spaces ( SP ) { } <nl> + explicit Space ( Type T , DeclName H , ArrayRef < Space > SP ) <nl> + : Kind ( SpaceKind : : Constructor ) , TypeAndVal ( T ) , Head ( H ) , <nl> + Spaces ( SP . begin ( ) , SP . end ( ) ) { } <nl> + explicit Space ( Type T , DeclName H , std : : forward_list < Space > SP ) <nl> + : Kind ( SpaceKind : : Constructor ) , TypeAndVal ( T ) , Head ( H ) , Spaces ( SP ) { } <nl> explicit Space ( ArrayRef < Space > SP ) <nl> : Kind ( SpaceKind : : Disjunct ) , TypeAndVal ( Type ( ) ) , <nl> Head ( Identifier ( ) ) , Spaces ( SP . begin ( ) , SP . end ( ) ) { } <nl> namespace { <nl> : Kind ( SpaceKind : : Empty ) , TypeAndVal ( Type ( ) ) , Head ( Identifier ( ) ) , <nl> Spaces ( { } ) { } <nl> <nl> - static Space forType ( Type T , Identifier NameForPrinting ) { <nl> + static Space forType ( Type T , DeclName NameForPrinting ) { <nl> if ( T - > isStructurallyUninhabited ( ) ) <nl> return Space ( ) ; <nl> return Space ( T , NameForPrinting ) ; <nl> namespace { <nl> static Space forUnknown ( bool allowedButNotRequired ) { <nl> return Space ( UnknownCase , allowedButNotRequired ) ; <nl> } <nl> - static Space forConstructor ( Type T , Identifier H , ArrayRef < Space > SP ) { <nl> + static Space forConstructor ( Type T , DeclName H , ArrayRef < Space > SP ) { <nl> if ( llvm : : any_of ( SP , std : : mem_fn ( & Space : : isEmpty ) ) ) { <nl> / / A constructor with an unconstructible parameter can never actually <nl> / / be used . <nl> namespace { <nl> } <nl> return Space ( T , H , SP ) ; <nl> } <nl> - static Space forConstructor ( Type T , Identifier H , <nl> + static Space forConstructor ( Type T , DeclName H , <nl> std : : forward_list < Space > SP ) { <nl> / / No need to filter SP here ; this is only used to copy other <nl> / / Constructor spaces . <nl> namespace { <nl> return TypeAndVal . getPointer ( ) ; <nl> } <nl> <nl> - Identifier getHead ( ) const { <nl> + DeclName getHead ( ) const { <nl> assert ( getKind ( ) = = SpaceKind : : Constructor <nl> & & " Wrong kind of space tried to access head " ) ; <nl> return Head ; <nl> namespace { <nl> Identifier getPrintingName ( ) const { <nl> assert ( getKind ( ) = = SpaceKind : : Type <nl> & & " Wrong kind of space tried to access printing name " ) ; <nl> - return Head ; <nl> + return Head . getBaseIdentifier ( ) ; <nl> } <nl> <nl> const std : : forward_list < Space > & getSpaces ( ) const { <nl> namespace { <nl> return this - > isSubspace ( or2Space , TC , DC ) ; <nl> } <nl> <nl> - return true ; <nl> + return false ; <nl> } <nl> PAIRCASE ( SpaceKind : : Type , SpaceKind : : Disjunct ) : { <nl> / / ( _ : Ty1 ) < = ( S1 | . . . | Sn ) iff ( S1 < = S ) | | . . . | | ( Sn < = S ) <nl> namespace { <nl> PAIRCASE ( SpaceKind : : Constructor , SpaceKind : : Constructor ) : { <nl> / / Optimization : If the constructor heads don ' t match , subspace is <nl> / / impossible . <nl> + <nl> if ( this - > Head ! = other . Head ) { <nl> return false ; <nl> } <nl> - <nl> + <nl> / / Special Case : Short - circuit comparisons with payload - less <nl> / / constructors . <nl> if ( other . getSpaces ( ) . empty ( ) ) { <nl> namespace { <nl> PAIRCASE ( SpaceKind : : Constructor , SpaceKind : : Constructor ) : { <nl> / / Optimization : If the heads of the constructors don ' t match then <nl> / / the two are disjoint and their difference is the first space . <nl> - if ( this - > Head ! = other . Head ) { <nl> + if ( this - > Head . getBaseIdentifier ( ) ! = <nl> + other . Head . getBaseIdentifier ( ) ) { <nl> return * this ; <nl> } <nl> <nl> namespace { <nl> buffer < < ( getBoolValue ( ) ? " true " : " false " ) ; <nl> break ; <nl> case SpaceKind : : Constructor : { <nl> - if ( ! Head . empty ( ) ) { <nl> + if ( ! Head . getBaseIdentifier ( ) . empty ( ) ) { <nl> buffer < < " . " ; <nl> - buffer < < Head . str ( ) ; <nl> + buffer < < Head . getBaseIdentifier ( ) . str ( ) ; <nl> } <nl> <nl> if ( Spaces . empty ( ) ) { <nl> return ; <nl> } <nl> <nl> + auto args = Head . getArgumentNames ( ) . begin ( ) ; <nl> + auto argEnd = Head . getArgumentNames ( ) . end ( ) ; <nl> + <nl> + / / FIXME : Clean up code for performance <nl> buffer < < " ( " ; <nl> - interleave ( Spaces , [ & ] ( const Space & param ) { <nl> - param . show ( buffer , forDisplay ) ; <nl> - } , [ & buffer ] ( ) { buffer < < " , " ; } ) ; <nl> + llvm : : SmallVector < std : : pair < Identifier , Space > , 4 > labelSpaces ; <nl> + for ( auto param : Spaces ) { <nl> + if ( args ! = argEnd ) { <nl> + labelSpaces . push_back ( <nl> + std : : pair < Identifier , Space > ( * args , param ) ) ; <nl> + args + + ; <nl> + } else <nl> + labelSpaces . push_back ( <nl> + std : : pair < Identifier , Space > ( Identifier ( ) , param ) ) ; <nl> + } <nl> + interleave ( <nl> + labelSpaces , <nl> + [ & ] ( const std : : pair < Identifier , Space > & param ) { <nl> + if ( ! param . first . empty ( ) ) { <nl> + buffer < < param . first ; <nl> + buffer < < " : " ; <nl> + } <nl> + param . second . show ( buffer , forDisplay ) ; <nl> + } , <nl> + [ & buffer ] ( ) { buffer < < " , " ; } ) ; <nl> buffer < < " ) " ; <nl> } <nl> break ; <nl> namespace { <nl> Space : : forType ( TTy - > getUnderlyingType ( ) , Identifier ( ) ) ) ; <nl> } <nl> } <nl> - return Space : : forConstructor ( tp , eed - > getName ( ) , <nl> + return Space : : forConstructor ( tp , eed - > getFullName ( ) , <nl> constElemSpaces ) ; <nl> } ) ; <nl> <nl> namespace { <nl> return ; <nl> <nl> Space projection = projectPattern ( TC , caseItem . getPattern ( ) ) ; <nl> - <nl> bool isRedundant = ! projection . isEmpty ( ) & & <nl> llvm : : any_of ( spaces , [ & ] ( const Space & handled ) { <nl> return projection . isSubspace ( handled , TC , DC ) ; <nl> namespace { <nl> auto subSpace = projectPattern ( TC , OSP - > getSubPattern ( ) ) ; <nl> / / To match patterns like ( _ , _ , . . . ) ? , we must rewrite the underlying <nl> / / tuple pattern to . some ( _ , _ , . . . ) first . <nl> - if ( subSpace . getKind ( ) = = SpaceKind : : Constructor <nl> - & & subSpace . getHead ( ) . empty ( ) ) { <nl> + if ( subSpace . getKind ( ) = = SpaceKind : : Constructor & & <nl> + subSpace . getHead ( ) . getBaseIdentifier ( ) . empty ( ) ) { <nl> return Space : : forConstructor ( item - > getType ( ) , name , <nl> std : : move ( subSpace . getSpaces ( ) ) ) ; <nl> } <nl> mmm a / test / FixCode / fixits - switch . swift . result <nl> ppp b / test / FixCode / fixits - switch . swift . result <nl> func foo4 ( _ e : E2 ) - > Int { <nl> switch e { <nl> case . e2 : <nl> return 1 <nl> - case . e1 ( let a , let s ) : <nl> + case . e1 ( a : let a , s : let s ) : <nl> < # code # > <nl> - case . e3 ( let a ) : <nl> + case . e3 ( a : let a ) : <nl> < # code # > <nl> case . e4 ( _ ) : <nl> < # code # > <nl> case . e5 ( _ , _ ) : <nl> < # code # > <nl> - case . e6 ( let a , _ ) : <nl> + case . e6 ( a : let a , _ ) : <nl> < # code # > <nl> case . e7 : <nl> < # code # > <nl> - case . e8 ( let a , _ , _ ) : <nl> + case . e8 ( a : let a , _ , _ ) : <nl> < # code # > <nl> case . e9 ( _ , _ , _ ) : <nl> < # code # > <nl> func foo6 ( _ e : E2 ) - > Int { <nl> switch e { <nl> case let . e1 ( x , y ) : <nl> return x + y <nl> - case . e2 ( let a ) : <nl> + case . e2 ( a : let a ) : <nl> < # code # > <nl> - case . e3 ( let a ) : <nl> + case . e3 ( a : let a ) : <nl> < # code # > <nl> case . e4 ( _ ) : <nl> < # code # > <nl> case . e5 ( _ , _ ) : <nl> < # code # > <nl> - case . e6 ( let a , _ ) : <nl> + case . e6 ( a : let a , _ ) : <nl> < # code # > <nl> case . e7 : <nl> < # code # > <nl> - case . e8 ( let a , _ , _ ) : <nl> + case . e8 ( a : let a , _ , _ ) : <nl> < # code # > <nl> case . e9 ( _ , _ , _ ) : <nl> < # code # > <nl> func foo7 ( _ e : E2 ) - > Int { <nl> case . e2 ( 1 ) : return 0 <nl> case . e1 : return 0 <nl> case . e3 : return 0 <nl> - case . e2 ( let a ) : <nl> + case . e2 ( a : let a ) : <nl> < # code # > <nl> case . e4 ( _ ) : <nl> < # code # > <nl> case . e5 ( _ , _ ) : <nl> < # code # > <nl> - case . e6 ( let a , _ ) : <nl> + case . e6 ( a : let a , _ ) : <nl> < # code # > <nl> case . e7 : <nl> < # code # > <nl> - case . e8 ( let a , _ , _ ) : <nl> + case . e8 ( a : let a , _ , _ ) : <nl> < # code # > <nl> case . e9 ( _ , _ , _ ) : <nl> < # code # > <nl> mmm a / test / Sema / exhaustive_switch . swift <nl> ppp b / test / Sema / exhaustive_switch . swift <nl> enum Z { <nl> <nl> func sr11160_extra ( ) { <nl> switch Z . z1 ( a : 1 ) { / / expected - error { { switch must be exhaustive } } <nl> - / / expected - note @ - 1 { { add missing case : ' . z1 ( let a ) ' } } <nl> + / / expected - note @ - 1 { { add missing case : ' . z1 ( a : let a ) ' } } <nl> case . z2 ( _ , _ ) : ( ) <nl> case . z3 ( _ ) : ( ) <nl> } <nl> <nl> switch Z . z1 ( a : 1 ) { / / expected - error { { switch must be exhaustive } } <nl> - / / expected - note @ - 1 { { add missing case : ' . z2 ( let a , let b ) ' } } <nl> + / / expected - note @ - 1 { { add missing case : ' . z2 ( a : let a , b : let b ) ' } } <nl> case . z1 ( _ ) : ( ) <nl> case . z3 ( _ ) : ( ) <nl> } <nl>
Merge pull request from AndrewLitteken / SR - 11159 - SpaceEngine
apple/swift
cb3f9e6e845a672c95c139e5604f0273b20eedf4
2019-10-04T15:39:34Z
mmm a / Telegram / gyp / telegram_linux . gypi <nl> ppp b / Telegram / gyp / telegram_linux . gypi <nl> <nl> { <nl> ' conditions ' : [ [ ' build_linux ' , { <nl> ' variables ' : { <nl> + ' variables ' : { <nl> + ' build_defines % ' : ' ' , <nl> + } , <nl> ' not_need_gtk % ' : ' < ! ( python - c " print ( \ ' TDESKTOP_DISABLE_GTK_INTEGRATION \ ' in \ ' < ( build_defines ) \ ' ) " ) ' , <nl> ' pkgconfig_libs ' : [ <nl> # In order to work libxkbcommon must be linked statically , <nl>
Fix default build .
telegramdesktop/tdesktop
e466dc9fc7f3981ed407f01b6d4486ed7941c051
2018-07-10T09:14:53Z
mmm a / imgui . cpp <nl> ppp b / imgui . cpp <nl> bool ImGui : : IsItemHovered ( ImGuiHoveredFlags flags ) <nl> { <nl> ImGuiContext & g = * GImGui ; <nl> ImGuiWindow * window = g . CurrentWindow ; <nl> - if ( g . NavDisableMouseHover ) <nl> + if ( g . NavDisableMouseHover & & ! g . NavDisableHighlight ) <nl> return IsItemFocused ( ) ; <nl> <nl> / / Test for bounding box overlap , as updated as ItemAdd ( ) <nl> bool ImGui : : ButtonBehavior ( const ImRect & bb , ImGuiID id , bool * out_hovered , bool <nl> <nl> / / Gamepad / Keyboard navigation <nl> / / We report navigated item as hovered but we don ' t set g . HoveredId to not interfere with mouse . <nl> - if ( g . NavId = = id & & ! g . NavDisableHighlight & & ( g . ActiveId = = 0 | | g . ActiveId = = id | | g . ActiveId = = window - > MoveId ) ) <nl> + if ( g . NavId = = id & & ! g . NavDisableHighlight & & g . NavDisableMouseHover & & ( g . ActiveId = = 0 | | g . ActiveId = = id | | g . ActiveId = = window - > MoveId ) ) <nl> hovered = true ; <nl> <nl> if ( g . NavActivateDownId = = id ) <nl>
Nav : Update hovered logic , so IsItemHovered and ButtonBehavior are more consistent with each other . The known case this fixes is nav focusing on a color button , tooltip appears , mouse move : previously tooltip would stay up . ( )
ocornut/imgui
cea78cc576eae0380f9cf43333e3b7e89730b663
2018-01-24T09:24:41Z
mmm a / Telegram / SourceFiles / core / shortcuts . cpp <nl> ppp b / Telegram / SourceFiles / core / shortcuts . cpp <nl> void Manager : : fillDefaults ( ) { <nl> set ( qsl ( " f5 " ) , Command : : SupportReloadTemplates ) ; <nl> set ( qsl ( " ctrl + delete " ) , Command : : SupportToggleMuted ) ; <nl> set ( qsl ( " ctrl + insert " ) , Command : : SupportScrollToCurrent ) ; <nl> + <nl> + set ( qsl ( " ctrl + 1 " ) , Command : : ChatPinned1 ) ; <nl> + set ( qsl ( " ctrl + 2 " ) , Command : : ChatPinned2 ) ; <nl> + set ( qsl ( " ctrl + 3 " ) , Command : : ChatPinned3 ) ; <nl> + set ( qsl ( " ctrl + 4 " ) , Command : : ChatPinned4 ) ; <nl> + set ( qsl ( " ctrl + 5 " ) , Command : : ChatPinned5 ) ; <nl> } <nl> <nl> void Manager : : writeDefaultFile ( ) { <nl> mmm a / Telegram / SourceFiles / core / shortcuts . h <nl> ppp b / Telegram / SourceFiles / core / shortcuts . h <nl> enum class Command { <nl> ChatNext , <nl> ChatFirst , <nl> ChatLast , <nl> + ChatPinned1 , <nl> + ChatPinned2 , <nl> + ChatPinned3 , <nl> + ChatPinned4 , <nl> + ChatPinned5 , <nl> <nl> SupportReloadTemplates , <nl> SupportToggleMuted , <nl> mmm a / Telegram / SourceFiles / dialogs / dialogs_inner_widget . cpp <nl> ppp b / Telegram / SourceFiles / dialogs / dialogs_inner_widget . cpp <nl> void DialogsInner : : setupShortcuts ( ) { <nl> request - > check ( Command : : ChatLast ) & & request - > handle ( [ = ] { <nl> return jumpToDialogRow ( last ) ; <nl> } ) ; <nl> + <nl> + static const auto kPinned = { <nl> + Command : : ChatPinned1 , <nl> + Command : : ChatPinned2 , <nl> + Command : : ChatPinned3 , <nl> + Command : : ChatPinned4 , <nl> + Command : : ChatPinned5 , <nl> + } ; <nl> + auto & & pinned = ranges : : view : : zip ( kPinned , ranges : : view : : ints ( 0 ) ) ; <nl> + for ( const auto [ command , index ] : pinned ) { <nl> + request - > check ( command ) & & request - > handle ( [ = , index = index ] { <nl> + const auto count = shownPinnedCount ( ) ; <nl> + if ( index > = count ) { <nl> + return false ; <nl> + } <nl> + const auto row = * ( shownDialogs ( ) - > cbegin ( ) + index ) ; <nl> + return jumpToDialogRow ( { row - > key ( ) , FullMsgId ( ) } ) ; <nl> + } ) ; <nl> + } <nl> if ( Auth ( ) . supportMode ( ) & & row . key . history ( ) ) { <nl> request - > check ( <nl> Command : : SupportScrollToCurrent <nl>
Ctrl + [ 1 - 5 ] jump to the relevant pinned chat .
telegramdesktop/tdesktop
ea7796dccc030fad104fc96c1c25c678c58cdd73
2019-01-11T13:30:00Z
mmm a / src / app / commands / cmd_sprite_size . cpp <nl> ppp b / src / app / commands / cmd_sprite_size . cpp <nl> void SpriteSizeCommand : : onExecute ( Context * context ) <nl> job . waitJob ( ) ; <nl> } <nl> <nl> - ContextWriter writer ( reader ) ; <nl> - update_screen_for_document ( writer . document ( ) ) ; <nl> + update_screen_for_document ( reader . document ( ) ) ; <nl> } <nl> <nl> void SpriteSizeCommand : : onLockRatioClick ( ) <nl>
Remove unnecessary ContextWriter at the end of SpriteSizeCommand
aseprite/aseprite
0f4705e67b4448de3bc1a685cb21bf0c2d132117
2015-04-21T15:14:02Z
mmm a / dbms / src / Storages / MergeTree / MergeTreeDataMerger . cpp <nl> ppp b / dbms / src / Storages / MergeTree / MergeTreeDataMerger . cpp <nl> static void extractMergingAndGatheringColumns ( const NamesAndTypesList & all_colu <nl> NamesAndTypesList & merging_columns , Names & merging_column_names <nl> ) <nl> { <nl> - Names primary_key_columns_dup = primary_key_expressions - > getRequiredColumns ( ) ; <nl> - std : : set < String > key_columns ( primary_key_columns_dup . cbegin ( ) , primary_key_columns_dup . cend ( ) ) ; <nl> + Names primary_key_columns_vec = primary_key_expressions - > getRequiredColumns ( ) ; <nl> + std : : set < String > key_columns ( primary_key_columns_vec . cbegin ( ) , primary_key_columns_vec . cend ( ) ) ; <nl> if ( secondary_key_expressions ) <nl> { <nl> - Names secondary_key_columns_dup = secondary_key_expressions - > getRequiredColumns ( ) ; <nl> - key_columns . insert ( secondary_key_columns_dup . begin ( ) , secondary_key_columns_dup . end ( ) ) ; <nl> + Names secondary_key_columns_vec = secondary_key_expressions - > getRequiredColumns ( ) ; <nl> + key_columns . insert ( secondary_key_columns_vec . begin ( ) , secondary_key_columns_vec . end ( ) ) ; <nl> } <nl> <nl> / / / Force sign column for Collapsing mode <nl> static void extractMergingAndGatheringColumns ( const NamesAndTypesList & all_colu <nl> if ( merging_params . mode = = MergeTreeData : : MergingParams : : VersionedCollapsing ) <nl> key_columns . emplace ( merging_params . sign_column ) ; <nl> <nl> + / / / Force to merge at least one column in case of empty key <nl> + if ( key_columns . empty ( ) ) <nl> + key_columns . emplace ( all_columns . front ( ) . name ) ; <nl> + <nl> / / / TODO : also force " summing " and " aggregating " columns to make Horizontal merge only for such columns <nl> <nl> for ( auto & column : all_columns ) <nl> mmm a / dbms / tests / queries / 0_stateless / 00578_merge_trees_without_primary_key . sql <nl> ppp b / dbms / tests / queries / 0_stateless / 00578_merge_trees_without_primary_key . sql <nl> <nl> SELECT ' * * * MergeTree * * * ' ; <nl> <nl> DROP TABLE IF EXISTS test . unsorted ; <nl> - CREATE TABLE test . unsorted ( x UInt32 , y String ) ENGINE MergeTree ORDER BY tuple ( ) ; <nl> + CREATE TABLE test . unsorted ( x UInt32 , y String ) ENGINE MergeTree ORDER BY tuple ( ) SETTINGS vertical_merge_algorithm_min_rows_to_activate = 0 , vertical_merge_algorithm_min_columns_to_activate = 0 ; <nl> <nl> INSERT INTO test . unsorted VALUES ( 1 , ' a ' ) , ( 5 , ' b ' ) ; <nl> INSERT INTO test . unsorted VALUES ( 2 , ' c ' ) , ( 4 , ' d ' ) ; <nl>
Fixed ordinary MergeTree merges in case of empty ORDER BY key . [ # CLICKHOUSE - 2 ]
ClickHouse/ClickHouse
f1b32e8982f1f5b5d2d19f8884183fa5eab085e6
2018-03-14T20:49:18Z
mmm a / xbmc / utils / EGLUtils . cpp <nl> ppp b / xbmc / utils / EGLUtils . cpp <nl> <nl> # include " EGLUtils . h " <nl> # include " log . h " <nl> <nl> + # include " guilib / IDirtyRegionSolver . h " <nl> + # include " settings / AdvancedSettings . h " <nl> + <nl> + # include < EGL / eglext . h > <nl> + # include < string . h > <nl> + <nl> std : : set < std : : string > CEGLUtils : : GetClientExtensions ( ) <nl> { <nl> const char * extensions = eglQueryString ( EGL_NO_DISPLAY , EGL_EXTENSIONS ) ; <nl> void CEGLUtils : : LogError ( const std : : string & what ) <nl> { <nl> CLog : : Log ( LOGERROR , " % s ( EGL error % d ) " , what . c_str ( ) , eglGetError ( ) ) ; <nl> } <nl> + <nl> + CEGLContextUtils : : CEGLContextUtils ( ) : <nl> + m_eglDisplay ( EGL_NO_DISPLAY ) , <nl> + m_eglSurface ( EGL_NO_SURFACE ) , <nl> + m_eglContext ( EGL_NO_CONTEXT ) , <nl> + m_eglConfig ( 0 ) <nl> + { <nl> + } <nl> + <nl> + CEGLContextUtils : : ~ CEGLContextUtils ( ) <nl> + { <nl> + Destroy ( ) ; <nl> + } <nl> + <nl> + bool CEGLContextUtils : : CreateDisplay ( EGLDisplay display , <nl> + EGLint renderable_type , <nl> + EGLint rendering_api ) <nl> + { <nl> + EGLint neglconfigs = 0 ; <nl> + int major , minor ; <nl> + <nl> + EGLint surface_type = EGL_WINDOW_BIT ; <nl> + / / for the non - trivial dirty region modes , we need the EGL buffer to be preserved across updates <nl> + if ( g_advancedSettings . m_guiAlgorithmDirtyRegions = = DIRTYREGION_SOLVER_COST_REDUCTION | | <nl> + g_advancedSettings . m_guiAlgorithmDirtyRegions = = DIRTYREGION_SOLVER_UNION ) <nl> + surface_type | = EGL_SWAP_BEHAVIOR_PRESERVED_BIT ; <nl> + <nl> + EGLint attribs [ ] = <nl> + { <nl> + EGL_RED_SIZE , 8 , <nl> + EGL_GREEN_SIZE , 8 , <nl> + EGL_BLUE_SIZE , 8 , <nl> + EGL_ALPHA_SIZE , 8 , <nl> + EGL_DEPTH_SIZE , 16 , <nl> + EGL_STENCIL_SIZE , 0 , <nl> + EGL_SAMPLE_BUFFERS , 0 , <nl> + EGL_SAMPLES , 0 , <nl> + EGL_SURFACE_TYPE , surface_type , <nl> + EGL_RENDERABLE_TYPE , renderable_type , <nl> + EGL_NONE <nl> + } ; <nl> + <nl> + # if defined ( EGL_EXT_platform_base ) & & defined ( EGL_KHR_platform_gbm ) & & defined ( HAVE_GBM ) <nl> + if ( m_eglDisplay = = EGL_NO_DISPLAY & & <nl> + CEGLUtils : : HasExtension ( EGL_NO_DISPLAY , " EGL_EXT_platform_base " ) & & <nl> + CEGLUtils : : HasExtension ( EGL_NO_DISPLAY , " EGL_KHR_platform_gbm " ) ) <nl> + { <nl> + PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplayEXT = ( PFNEGLGETPLATFORMDISPLAYEXTPROC ) eglGetProcAddress ( " eglGetPlatformDisplayEXT " ) ; <nl> + if ( getPlatformDisplayEXT ) <nl> + { <nl> + m_eglDisplay = getPlatformDisplayEXT ( EGL_PLATFORM_GBM_KHR , ( EGLNativeDisplayType ) display , NULL ) ; <nl> + } <nl> + } <nl> + # endif <nl> + <nl> + if ( m_eglDisplay = = EGL_NO_DISPLAY ) <nl> + { <nl> + m_eglDisplay = eglGetDisplay ( ( EGLNativeDisplayType ) display ) ; <nl> + } <nl> + <nl> + if ( m_eglDisplay = = EGL_NO_DISPLAY ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " failed to get EGL display " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + if ( ! eglInitialize ( m_eglDisplay , & major , & minor ) ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " failed to initialize EGL display " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + eglBindAPI ( rendering_api ) ; <nl> + <nl> + if ( ! eglChooseConfig ( m_eglDisplay , attribs , <nl> + & m_eglConfig , 1 , & neglconfigs ) ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " Failed to query number of EGL configs " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + if ( neglconfigs < = 0 ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " No suitable EGL configs found " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + bool CEGLContextUtils : : CreateContext ( ) <nl> + { <nl> + int client_version = 2 ; <nl> + <nl> + const EGLint context_attribs [ ] = <nl> + { <nl> + EGL_CONTEXT_CLIENT_VERSION , client_version , EGL_NONE <nl> + } ; <nl> + <nl> + if ( m_eglContext = = EGL_NO_CONTEXT ) <nl> + { <nl> + m_eglContext = eglCreateContext ( m_eglDisplay , m_eglConfig , <nl> + EGL_NO_CONTEXT , context_attribs ) ; <nl> + } <nl> + <nl> + if ( m_eglContext = = EGL_NO_CONTEXT ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " failed to create EGL context " ) ; <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + bool CEGLContextUtils : : BindContext ( ) <nl> + { <nl> + if ( ! eglMakeCurrent ( m_eglDisplay , m_eglSurface , <nl> + m_eglSurface , m_eglContext ) ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " Failed to make context current % p % p % p " , <nl> + m_eglDisplay , m_eglSurface , m_eglContext ) ; <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + bool CEGLContextUtils : : SurfaceAttrib ( ) <nl> + { <nl> + / / for the non - trivial dirty region modes , we need the EGL buffer to be preserved across updates <nl> + if ( g_advancedSettings . m_guiAlgorithmDirtyRegions = = DIRTYREGION_SOLVER_COST_REDUCTION | | <nl> + g_advancedSettings . m_guiAlgorithmDirtyRegions = = DIRTYREGION_SOLVER_UNION ) <nl> + { <nl> + if ( ( m_eglDisplay = = EGL_NO_DISPLAY ) | | ( m_eglSurface = = EGL_NO_SURFACE ) ) <nl> + { <nl> + return false ; <nl> + } <nl> + <nl> + if ( ! eglSurfaceAttrib ( m_eglDisplay , m_eglSurface , EGL_SWAP_BEHAVIOR , EGL_BUFFER_PRESERVED ) ) <nl> + { <nl> + CLog : : Log ( LOGDEBUG , " % s : Could not set EGL_SWAP_BEHAVIOR " , __FUNCTION__ ) ; <nl> + } <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + bool CEGLContextUtils : : CreateSurface ( EGLNativeWindowType surface ) <nl> + { <nl> + m_eglSurface = eglCreateWindowSurface ( m_eglDisplay , <nl> + m_eglConfig , <nl> + surface , <nl> + nullptr ) ; <nl> + <nl> + if ( m_eglSurface = = EGL_NO_SURFACE ) <nl> + { <nl> + CLog : : Log ( LOGERROR , " failed to create EGL window surface % d " , eglGetError ( ) ) ; <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + void CEGLContextUtils : : Destroy ( ) <nl> + { <nl> + if ( m_eglContext ! = EGL_NO_CONTEXT ) <nl> + { <nl> + eglDestroyContext ( m_eglDisplay , m_eglContext ) ; <nl> + eglMakeCurrent ( m_eglDisplay , EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT ) ; <nl> + m_eglContext = EGL_NO_CONTEXT ; <nl> + } <nl> + <nl> + if ( m_eglSurface ! = EGL_NO_SURFACE ) <nl> + { <nl> + eglDestroySurface ( m_eglDisplay , m_eglSurface ) ; <nl> + m_eglSurface = EGL_NO_SURFACE ; <nl> + } <nl> + <nl> + if ( m_eglDisplay ! = EGL_NO_DISPLAY ) <nl> + { <nl> + eglTerminate ( m_eglDisplay ) ; <nl> + m_eglDisplay = EGL_NO_DISPLAY ; <nl> + } <nl> + } <nl> + <nl> + void CEGLContextUtils : : Detach ( ) <nl> + { <nl> + if ( m_eglContext ! = EGL_NO_CONTEXT ) <nl> + { <nl> + eglMakeCurrent ( m_eglDisplay , EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT ) ; <nl> + } <nl> + <nl> + if ( m_eglSurface ! = EGL_NO_SURFACE ) <nl> + { <nl> + eglDestroySurface ( m_eglDisplay , m_eglSurface ) ; <nl> + m_eglSurface = EGL_NO_SURFACE ; <nl> + } <nl> + } <nl> + <nl> + bool CEGLContextUtils : : SetVSync ( bool enable ) <nl> + { <nl> + if ( ! eglSwapInterval ( m_eglDisplay , enable ) ) <nl> + { <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + void CEGLContextUtils : : SwapBuffers ( ) <nl> + { <nl> + if ( m_eglDisplay = = EGL_NO_DISPLAY | | m_eglSurface = = EGL_NO_SURFACE ) <nl> + { <nl> + return ; <nl> + } <nl> + <nl> + eglSwapBuffers ( m_eglDisplay , m_eglSurface ) ; <nl> + } <nl> mmm a / xbmc / utils / EGLUtils . h <nl> ppp b / xbmc / utils / EGLUtils . h <nl> class CEGLAttributes <nl> private : <nl> std : : array < EGLint , AttributeCount * 2 + 1 > m_attributes ; <nl> int m_writePosition { } ; <nl> - } ; <nl> \ No newline at end of file <nl> + } ; <nl> + <nl> + class CEGLContextUtils <nl> + { <nl> + public : <nl> + CEGLContextUtils ( ) ; <nl> + virtual ~ CEGLContextUtils ( ) ; <nl> + <nl> + bool CreateDisplay ( EGLDisplay display , <nl> + EGLint renderable_type , <nl> + EGLint rendering_api ) ; <nl> + <nl> + bool CreateSurface ( EGLNativeWindowType surface ) ; <nl> + bool CreateContext ( ) ; <nl> + bool BindContext ( ) ; <nl> + bool SurfaceAttrib ( ) ; <nl> + void Destroy ( ) ; <nl> + void Detach ( ) ; <nl> + bool SetVSync ( bool enable ) ; <nl> + void SwapBuffers ( ) ; <nl> + <nl> + EGLDisplay m_eglDisplay ; <nl> + EGLSurface m_eglSurface ; <nl> + EGLContext m_eglContext ; <nl> + EGLConfig m_eglConfig ; <nl> + } ; <nl>
utils / EGLUtils : add CEGLContextUtils class
xbmc/xbmc
7e3a9b6c5d82102a83cd6a11f3601424cfd721b0
2018-03-22T20:58:56Z
mmm a / ci / jobs / quick - build / run . sh <nl> ppp b / ci / jobs / quick - build / run . sh <nl> BUILD_TARGETS = clickhouse <nl> BUILD_TYPE = Debug <nl> ENABLE_EMBEDDED_COMPILER = 0 <nl> <nl> - CMAKE_FLAGS = " - D CMAKE_C_FLAGS_ADD = - g0 - D CMAKE_CXX_FLAGS_ADD = - g0 - D ENABLE_JEMALLOC = 0 - D ENABLE_CAPNP = 0 - D ENABLE_RDKAFKA = 0 - D ENABLE_UNWIND = 0 - D ENABLE_ICU = 0 - D ENABLE_POCO_MONGODB = 0 - D ENABLE_POCO_NETSSL = 0 - D ENABLE_POCO_ODBC = 0 - D ENABLE_ODBC = 0 - D ENABLE_MYSQL = 0 " <nl> + CMAKE_FLAGS = " - D CMAKE_C_FLAGS_ADD = - g0 - D CMAKE_CXX_FLAGS_ADD = - g0 - D ENABLE_JEMALLOC = 0 - D ENABLE_CAPNP = 0 - D ENABLE_RDKAFKA = 0 - D ENABLE_UNWIND = 0 - D ENABLE_ICU = 0 - D ENABLE_POCO_MONGODB = 0 - D ENABLE_POCO_REDIS = 0 - D ENABLE_POCO_NETSSL = 0 - D ENABLE_POCO_ODBC = 0 - D ENABLE_ODBC = 0 - D ENABLE_MYSQL = 0 " <nl> <nl> [ [ $ ( uname ) = = " FreeBSD " ] ] & & COMPILER_PACKAGE_VERSION = devel & & export COMPILER_PATH = / usr / local / bin <nl> <nl> mmm a / cmake / find_poco . cmake <nl> ppp b / cmake / find_poco . cmake <nl> endif ( ) <nl> if ( NOT DEFINED ENABLE_POCO_MONGODB OR ENABLE_POCO_MONGODB ) <nl> list ( APPEND POCO_COMPONENTS MongoDB ) <nl> endif ( ) <nl> + if ( NOT DEFINED ENABLE_POCO_REDIS OR ENABLE_POCO_REDIS ) <nl> + list ( APPEND POCO_COMPONENTS Redis ) <nl> + endif ( ) <nl> # TODO : after new poco release with SQL library rename ENABLE_POCO_ODBC - > ENABLE_POCO_SQLODBC <nl> if ( NOT DEFINED ENABLE_POCO_ODBC OR ENABLE_POCO_ODBC ) <nl> list ( APPEND POCO_COMPONENTS DataODBC ) <nl> elseif ( NOT MISSING_INTERNAL_POCO_LIBRARY ) <nl> set ( ENABLE_ZIP 0 CACHE BOOL " " ) <nl> set ( ENABLE_PAGECOMPILER 0 CACHE BOOL " " ) <nl> set ( ENABLE_PAGECOMPILER_FILE2PAGE 0 CACHE BOOL " " ) <nl> - set ( ENABLE_REDIS 0 CACHE BOOL " " ) <nl> set ( ENABLE_DATA_SQLITE 0 CACHE BOOL " " ) <nl> set ( ENABLE_DATA_MYSQL 0 CACHE BOOL " " ) <nl> set ( ENABLE_DATA_POSTGRESQL 0 CACHE BOOL " " ) <nl> elseif ( NOT MISSING_INTERNAL_POCO_LIBRARY ) <nl> set ( POCO_ENABLE_ZIP 0 CACHE BOOL " " ) <nl> set ( POCO_ENABLE_PAGECOMPILER 0 CACHE BOOL " " ) <nl> set ( POCO_ENABLE_PAGECOMPILER_FILE2PAGE 0 CACHE BOOL " " ) <nl> - set ( POCO_ENABLE_REDIS 0 CACHE BOOL " " ) <nl> set ( POCO_ENABLE_SQL_SQLITE 0 CACHE BOOL " " ) <nl> set ( POCO_ENABLE_SQL_MYSQL 0 CACHE BOOL " " ) <nl> set ( POCO_ENABLE_SQL_POSTGRESQL 0 CACHE BOOL " " ) <nl> elseif ( NOT MISSING_INTERNAL_POCO_LIBRARY ) <nl> set ( Poco_MongoDB_INCLUDE_DIR " $ { ClickHouse_SOURCE_DIR } / contrib / poco / MongoDB / include / " ) <nl> endif ( ) <nl> <nl> + if ( NOT DEFINED ENABLE_POCO_REDIS OR ENABLE_POCO_REDIS ) <nl> + set ( Poco_Redis_LIBRARY PocoRedis ) <nl> + set ( Poco_Redis_INCLUDE_DIR " $ { ClickHouse_SOURCE_DIR } / contrib / poco / Redis / include / " ) <nl> + endif ( ) <nl> + <nl> if ( EXISTS " $ { ClickHouse_SOURCE_DIR } / contrib / poco / SQL / ODBC / include / " ) <nl> set ( Poco_SQL_FOUND 1 ) <nl> set ( Poco_SQL_LIBRARY PocoSQL ) <nl> endif ( ) <nl> if ( Poco_MongoDB_LIBRARY ) <nl> set ( USE_POCO_MONGODB 1 ) <nl> endif ( ) <nl> + if ( Poco_Redis_LIBRARY ) <nl> + set ( USE_POCO_REDIS 1 ) <nl> + endif ( ) <nl> if ( Poco_DataODBC_LIBRARY AND ODBC_FOUND ) <nl> set ( USE_POCO_DATAODBC 1 ) <nl> endif ( ) <nl> if ( Poco_SQLODBC_LIBRARY AND ODBC_FOUND ) <nl> set ( USE_POCO_SQLODBC 1 ) <nl> endif ( ) <nl> <nl> - message ( STATUS " Using Poco : $ { Poco_INCLUDE_DIRS } : $ { Poco_Foundation_LIBRARY } , $ { Poco_Util_LIBRARY } , $ { Poco_Net_LIBRARY } , $ { Poco_NetSSL_LIBRARY } , $ { Poco_Crypto_LIBRARY } , $ { Poco_XML_LIBRARY } , $ { Poco_Data_LIBRARY } , $ { Poco_DataODBC_LIBRARY } , $ { Poco_SQL_LIBRARY } , $ { Poco_SQLODBC_LIBRARY } , $ { Poco_MongoDB_LIBRARY } ; MongoDB = $ { USE_POCO_MONGODB } , DataODBC = $ { USE_POCO_DATAODBC } , NetSSL = $ { USE_POCO_NETSSL } " ) <nl> + message ( STATUS " Using Poco : $ { Poco_INCLUDE_DIRS } : $ { Poco_Foundation_LIBRARY } , $ { Poco_Util_LIBRARY } , $ { Poco_Net_LIBRARY } , $ { Poco_NetSSL_LIBRARY } , $ { Poco_Crypto_LIBRARY } , $ { Poco_XML_LIBRARY } , $ { Poco_Data_LIBRARY } , $ { Poco_DataODBC_LIBRARY } , $ { Poco_SQL_LIBRARY } , $ { Poco_SQLODBC_LIBRARY } , $ { Poco_MongoDB_LIBRARY } ; MongoDB = $ { USE_POCO_MONGODB } , Redis = $ { USE_POCO_REDIS } , DataODBC = $ { USE_POCO_DATAODBC } , NetSSL = $ { USE_POCO_NETSSL } " ) <nl> <nl> # How to make sutable poco : <nl> # use branch : <nl> mmm a / dbms / src / Common / config . h . in <nl> ppp b / dbms / src / Common / config . h . in <nl> <nl> # cmakedefine01 USE_POCO_SQLODBC <nl> # cmakedefine01 USE_POCO_DATAODBC <nl> # cmakedefine01 USE_POCO_MONGODB <nl> + # cmakedefine01 USE_POCO_REDIS <nl> # cmakedefine01 USE_POCO_NETSSL <nl> # cmakedefine01 USE_BASE64 <nl> # cmakedefine01 USE_HDFS <nl> mmm a / dbms / src / Dictionaries / CMakeLists . txt <nl> ppp b / dbms / src / Dictionaries / CMakeLists . txt <nl> if ( USE_POCO_MONGODB ) <nl> target_link_libraries ( clickhouse_dictionaries PRIVATE $ { Poco_MongoDB_LIBRARY } ) <nl> endif ( ) <nl> <nl> + if ( USE_POCO_REDIS ) <nl> + target_link_libraries ( clickhouse_dictionaries PRIVATE $ { Poco_Redis_LIBRARY } ) <nl> + endif ( ) <nl> + <nl> add_subdirectory ( Embedded ) <nl> new file mode 100644 <nl> index 00000000000 . . dfbb03a0034 <nl> mmm / dev / null <nl> ppp b / dbms / src / Dictionaries / RedisBlockInputStream . cpp <nl> <nl> + # include < Common / config . h > <nl> + # if USE_POCO_REDIS <nl> + <nl> + # include < sstream > <nl> + # include < string > <nl> + # include < vector > <nl> + <nl> + # include < Poco / Redis / Array . h > <nl> + # include < Poco / Redis / AsyncReader . h > <nl> + # include < Poco / Redis / Client . h > <nl> + # include < Poco / Redis / Command . h > <nl> + # include < Poco / Redis / Error . h > <nl> + # include < Poco / Redis / Exception . h > <nl> + # include < Poco / Redis / RedisEventArgs . h > <nl> + # include < Poco / Redis / RedisStream . h > <nl> + # include < Poco / Redis / Type . h > <nl> + <nl> + # include < Columns / ColumnNullable . h > <nl> + # include < Columns / ColumnString . h > <nl> + # include < Columns / ColumnsNumber . h > <nl> + # include < IO / ReadHelpers . h > <nl> + # include < IO / WriteHelpers . h > <nl> + # include < Common / FieldVisitors . h > <nl> + # include < ext / range . h > <nl> + # include " DictionaryStructure . h " <nl> + # include " RedisBlockInputStream . h " <nl> + <nl> + <nl> + namespace DB <nl> + { <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int TYPE_MISMATCH ; <nl> + } <nl> + <nl> + <nl> + RedisBlockInputStream : : RedisBlockInputStream ( <nl> + std : : shared_ptr < Poco : : Redis : : Client > client_ , <nl> + const DB : : Block & sample_block , <nl> + const size_t max_block_size ) <nl> + : client ( client_ ) , max_block_size { max_block_size } <nl> + { <nl> + description . init ( sample_block ) ; <nl> + } <nl> + <nl> + RedisBlockInputStream : : ~ RedisBlockInputStream ( ) = default ; <nl> + <nl> + <nl> + namespace <nl> + { <nl> + using ValueType = ExternalResultDescription : : ValueType ; <nl> + using RedisArray = Poco : : Redis : : Array ; <nl> + <nl> + template < typename T > <nl> + void insertNumber ( IColumn & column , const Poco : : Redis : : RedisType : : Ptr & value , const std : : string & name ) <nl> + { <nl> + switch ( value - > type ( ) ) <nl> + { <nl> + case Poco : : Redis : : RedisTypeTraits < Poco : : Int64 > : : TypeId : <nl> + static_cast < ColumnVector < T > & > ( column ) . getData ( ) . push_back ( <nl> + static_cast < const Poco : : Redis : : Type < Poco : : Int64 > * > ( value . get ( ) ) - > value ( ) ) ; <nl> + break ; <nl> + case Poco : : Redis : : RedisTypeTraits < String > : : TypeId : <nl> + static_cast < ColumnVector < T > & > ( column ) . getData ( ) . push_back ( <nl> + parse < T > ( static_cast < const Poco : : Redis : : Type < String > * > ( value . get ( ) ) - > value ( ) ) ) ; <nl> + break ; <nl> + case Poco : : Redis : : RedisTypeTraits < Poco : : Redis : : BulkString > : : TypeId : <nl> + { <nl> + const auto & bs = <nl> + static_cast < const Poco : : Redis : : Type < Poco : : Redis : : BulkString > * > ( value . get ( ) ) - > value ( ) ; <nl> + if ( bs . isNull ( ) ) <nl> + static_cast < ColumnVector < T > & > ( column ) . getData ( ) . emplace_back ( ) ; <nl> + else <nl> + static_cast < ColumnVector < T > & > ( column ) . getData ( ) . push_back ( parse < T > ( bs . value ( ) ) ) ; <nl> + break ; <nl> + } <nl> + default : <nl> + throw Exception ( <nl> + " Type mismatch , expected a number , got type id = " + toString ( value - > type ( ) ) + " for column " + name , <nl> + ErrorCodes : : TYPE_MISMATCH ) ; <nl> + } <nl> + } <nl> + <nl> + void insertValue ( IColumn & column , const ValueType type , const Poco : : Redis : : RedisType : : Ptr & value , const std : : string & name ) <nl> + { <nl> + auto getStringIfCould = [ & value , & name ] ( ) <nl> + { <nl> + switch ( value - > type ( ) ) <nl> + { <nl> + case Poco : : Redis : : RedisTypeTraits < Poco : : Redis : : BulkString > : : TypeId : <nl> + { <nl> + const auto & bs = static_cast < const Poco : : Redis : : Type < Poco : : Redis : : BulkString > * > ( value . get ( ) ) - > value ( ) ; <nl> + if ( bs . isNull ( ) ) <nl> + throw Exception { " Type mismatch , expected not null String for column " + name , <nl> + ErrorCodes : : TYPE_MISMATCH } ; <nl> + return bs . value ( ) ; <nl> + } <nl> + case Poco : : Redis : : RedisTypeTraits < String > : : TypeId : <nl> + return static_cast < const Poco : : Redis : : Type < String > * > ( value . get ( ) ) - > value ( ) ; <nl> + default : <nl> + throw Exception { " Type mismatch , expected String , got type id = " + toString ( value - > type ( ) ) + " for column " + name , <nl> + ErrorCodes : : TYPE_MISMATCH } ; <nl> + } <nl> + } ; <nl> + switch ( type ) <nl> + { <nl> + case ValueType : : UInt8 : <nl> + insertNumber < UInt8 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : UInt16 : <nl> + insertNumber < UInt16 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : UInt32 : <nl> + insertNumber < UInt32 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : UInt64 : <nl> + insertNumber < UInt64 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Int8 : <nl> + insertNumber < Int8 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Int16 : <nl> + insertNumber < Int16 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Int32 : <nl> + insertNumber < Int32 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Int64 : <nl> + insertNumber < Int64 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Float32 : <nl> + insertNumber < Float32 > ( column , value , name ) ; <nl> + break ; <nl> + case ValueType : : Float64 : <nl> + insertNumber < Float64 > ( column , value , name ) ; <nl> + break ; <nl> + <nl> + case ValueType : : String : <nl> + { <nl> + String string = getStringIfCould ( ) ; <nl> + static_cast < ColumnString & > ( column ) . insertDataWithTerminatingZero ( string . data ( ) , string . size ( ) + 1 ) ; <nl> + break ; <nl> + } <nl> + <nl> + case ValueType : : Date : <nl> + { <nl> + if ( value - > type ( ) ! = Poco : : Redis : : RedisTypeTraits < Int64 > : : TypeId ) <nl> + throw Exception { " Type mismatch , expected Int64 ( Timestamp ) , got type id = " + toString ( value - > type ( ) ) + " for column " + name , <nl> + ErrorCodes : : TYPE_MISMATCH } ; <nl> + <nl> + static_cast < ColumnUInt16 & > ( column ) . getData ( ) . push_back ( UInt16 { DateLUT : : instance ( ) . toDayNum ( <nl> + static_cast < const Poco : : Timestamp & > ( <nl> + static_cast < const Poco : : Redis : : Type < Poco : : Int64 > * > ( value . get ( ) ) - > value ( ) ) . epochTime ( ) ) } ) ; <nl> + break ; <nl> + } <nl> + <nl> + case ValueType : : DateTime : <nl> + { <nl> + if ( value - > type ( ) ! = Poco : : Redis : : RedisTypeTraits < Poco : : Int64 > : : TypeId ) <nl> + throw Exception { " Type mismatch , expected Int64 ( Timestamp ) , got type id = " + toString ( value - > type ( ) ) + " for column " + name , <nl> + ErrorCodes : : TYPE_MISMATCH } ; <nl> + <nl> + static_cast < ColumnUInt32 & > ( column ) . getData ( ) . push_back ( <nl> + static_cast < const Poco : : Timestamp & > ( <nl> + static_cast < const Poco : : Redis : : Type < Poco : : Int64 > * > ( value . get ( ) ) - > value ( ) ) . epochTime ( ) ) ; <nl> + break ; <nl> + } <nl> + case ValueType : : UUID : <nl> + { <nl> + String string = getStringIfCould ( ) ; <nl> + static_cast < ColumnUInt128 & > ( column ) . getData ( ) . push_back ( parse < UUID > ( string ) ) ; <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + void insertDefaultValue ( IColumn & column , const IColumn & sample_column ) { column . insertFrom ( sample_column , 0 ) ; } <nl> + } <nl> + <nl> + <nl> + Block RedisBlockInputStream : : readImpl ( ) <nl> + { <nl> + if ( all_read ) <nl> + return { } ; <nl> + <nl> + const size_t size = 2 ; <nl> + assert ( size = = description . sample_block . columns ( ) ) ; <nl> + MutableColumns columns ( description . sample_block . columns ( ) ) ; <nl> + <nl> + for ( const auto i : ext : : range ( 0 , size ) ) <nl> + columns [ i ] = description . sample_block . getByPosition ( i ) . column - > cloneEmpty ( ) ; <nl> + <nl> + size_t num_rows = 0 ; <nl> + while ( num_rows < max_block_size ) <nl> + { <nl> + RedisArray commandForKeys ; <nl> + commandForKeys < < " SCAN " < < cursor ; <nl> + <nl> + auto replyForKeys = client - > execute < RedisArray > ( commandForKeys ) ; <nl> + if ( cursor = replyForKeys . get < int64_t > ( 0 ) ; cursor = = 0 ) <nl> + { <nl> + all_read = true ; <nl> + break ; <nl> + } <nl> + <nl> + auto response = replyForKeys . get < RedisArray > ( 1 ) ; <nl> + if ( response . isNull ( ) ) <nl> + continue ; <nl> + <nl> + Poco : : Redis : : Array commandForValues ; <nl> + commandForValues < < " MGET " ; <nl> + <nl> + const auto insertValueByIdx = [ this , & columns ] ( size_t idx , const auto & value ) <nl> + { <nl> + const auto & name = description . sample_block . getByPosition ( idx ) . name ; <nl> + if ( description . types [ idx ] . second ) <nl> + { <nl> + ColumnNullable & column_nullable = static_cast < ColumnNullable & > ( * columns [ idx ] ) ; <nl> + insertValue ( column_nullable . getNestedColumn ( ) , description . types [ idx ] . first , value , name ) ; <nl> + column_nullable . getNullMapData ( ) . emplace_back ( 0 ) ; <nl> + } <nl> + else <nl> + insertValue ( * columns [ idx ] , description . types [ idx ] . first , value , name ) ; <nl> + } ; <nl> + <nl> + for ( const auto & key : response ) <nl> + { <nl> + + + num_rows ; <nl> + String keyS = static_cast < const Poco : : Redis : : Type < String > * > ( key . get ( ) ) - > value ( ) ; <nl> + commandForValues < < keyS ; <nl> + insertValueByIdx ( 0 , key ) ; <nl> + } <nl> + <nl> + auto replyForValues = client - > execute < RedisArray > ( commandForValues ) ; <nl> + for ( const auto & value : replyForValues ) <nl> + { <nl> + if ( value . isNull ( ) ) <nl> + insertDefaultValue ( * columns [ 1 ] , * description . sample_block . getByPosition ( 1 ) . column ) ; <nl> + else <nl> + insertValueByIdx ( 1 , value ) ; <nl> + } <nl> + } <nl> + <nl> + if ( num_rows = = 0 ) <nl> + return { } ; <nl> + <nl> + return description . sample_block . cloneWithColumns ( std : : move ( columns ) ) ; <nl> + } <nl> + <nl> + } <nl> + <nl> + # endif <nl> new file mode 100644 <nl> index 00000000000 . . 7e32b3ff8ff <nl> mmm / dev / null <nl> ppp b / dbms / src / Dictionaries / RedisBlockInputStream . h <nl> <nl> + # pragma once <nl> + <nl> + # include < Core / Block . h > <nl> + # include < DataStreams / IProfilingBlockInputStream . h > <nl> + # include " ExternalResultDescription . h " <nl> + <nl> + <nl> + namespace Poco <nl> + { <nl> + namespace Redis <nl> + { <nl> + class Client ; <nl> + } <nl> + } <nl> + <nl> + <nl> + namespace DB <nl> + { <nl> + / / / Converts Redis Cursor to a stream of Blocks <nl> + class RedisBlockInputStream final : public IProfilingBlockInputStream <nl> + { <nl> + public : <nl> + RedisBlockInputStream ( <nl> + std : : shared_ptr < Poco : : Redis : : Client > client_ , <nl> + const Block & sample_block , <nl> + const size_t max_block_size ) ; <nl> + <nl> + ~ RedisBlockInputStream ( ) override ; <nl> + <nl> + String getName ( ) const override { return " Redis " ; } <nl> + <nl> + Block getHeader ( ) const override { return description . sample_block . cloneEmpty ( ) ; } <nl> + <nl> + private : <nl> + Block readImpl ( ) override ; <nl> + <nl> + std : : shared_ptr < Poco : : Redis : : Client > client ; <nl> + const size_t max_block_size ; <nl> + ExternalResultDescription description ; <nl> + int64_t cursor = 0 ; <nl> + bool all_read = false ; <nl> + } ; <nl> + <nl> + } <nl> new file mode 100644 <nl> index 00000000000 . . 1fb5472b48b <nl> mmm / dev / null <nl> ppp b / dbms / src / Dictionaries / RedisDictionarySource . cpp <nl> <nl> + # include " RedisDictionarySource . h " <nl> + # include " DictionarySourceFactory . h " <nl> + # include " DictionaryStructure . h " <nl> + <nl> + namespace DB <nl> + { <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int SUPPORT_IS_DISABLED ; <nl> + } <nl> + <nl> + void registerDictionarySourceRedis ( DictionarySourceFactory & factory ) <nl> + { <nl> + auto createTableSource = [ = ] ( const DictionaryStructure & dict_struct , <nl> + const Poco : : Util : : AbstractConfiguration & config , <nl> + const std : : string & config_prefix , <nl> + Block & sample_block , <nl> + const Context & / * context * / ) - > DictionarySourcePtr { <nl> + # if USE_POCO_REDIS <nl> + return std : : make_unique < RedisDictionarySource > ( dict_struct , config , config_prefix + " . redis " , sample_block ) ; <nl> + # else <nl> + ( void ) dict_struct ; <nl> + ( void ) config ; <nl> + ( void ) config_prefix ; <nl> + ( void ) sample_block ; <nl> + throw Exception { " Dictionary source of type ` redis ` is disabled because poco library was built without redis support . " , <nl> + ErrorCodes : : SUPPORT_IS_DISABLED } ; <nl> + # endif <nl> + } ; <nl> + factory . registerSource ( " redis " , createTableSource ) ; <nl> + } <nl> + <nl> + } <nl> + <nl> + <nl> + # if USE_POCO_REDIS <nl> + <nl> + # include < Poco / Redis / Array . h > <nl> + # include < Poco / Redis / AsyncReader . h > <nl> + # include < Poco / Redis / Client . h > <nl> + # include < Poco / Redis / Command . h > <nl> + # include < Poco / Redis / Error . h > <nl> + # include < Poco / Redis / Exception . h > <nl> + # include < Poco / Redis / RedisEventArgs . h > <nl> + # include < Poco / Redis / RedisStream . h > <nl> + # include < Poco / Redis / Type . h > <nl> + # include < Poco / Util / AbstractConfiguration . h > <nl> + # include < Poco / Version . h > <nl> + <nl> + # include < IO / WriteHelpers . h > <nl> + # include < Common / FieldVisitors . h > <nl> + # include < ext / enumerate . h > <nl> + # include " RedisBlockInputStream . h " <nl> + <nl> + <nl> + namespace DB <nl> + { <nl> + namespace ErrorCodes <nl> + { <nl> + extern const int UNSUPPORTED_METHOD ; <nl> + } <nl> + <nl> + <nl> + static const size_t max_block_size = 8192 ; <nl> + <nl> + <nl> + RedisDictionarySource : : RedisDictionarySource ( <nl> + const DictionaryStructure & dict_struct , <nl> + const std : : string & host , <nl> + UInt16 port , <nl> + const Block & sample_block ) <nl> + : dict_struct { dict_struct } <nl> + , host { host } <nl> + , port { port } <nl> + , sample_block { sample_block } <nl> + , client { std : : make_shared < Poco : : Redis : : Client > ( host , port ) } <nl> + { <nl> + } <nl> + <nl> + <nl> + RedisDictionarySource : : RedisDictionarySource ( <nl> + const DictionaryStructure & dict_struct , <nl> + const Poco : : Util : : AbstractConfiguration & config , <nl> + const std : : string & config_prefix , <nl> + Block & sample_block ) <nl> + : RedisDictionarySource ( <nl> + dict_struct , <nl> + config . getString ( config_prefix + " . host " ) , <nl> + config . getUInt ( config_prefix + " . port " ) , <nl> + sample_block ) <nl> + { <nl> + } <nl> + <nl> + <nl> + RedisDictionarySource : : RedisDictionarySource ( const RedisDictionarySource & other ) <nl> + : RedisDictionarySource { other . dict_struct , <nl> + other . host , <nl> + other . port , <nl> + other . sample_block } <nl> + { <nl> + } <nl> + <nl> + <nl> + RedisDictionarySource : : ~ RedisDictionarySource ( ) = default ; <nl> + <nl> + <nl> + BlockInputStreamPtr RedisDictionarySource : : loadAll ( ) <nl> + { <nl> + return std : : make_shared < RedisBlockInputStream > ( client , sample_block , max_block_size ) ; <nl> + } <nl> + <nl> + / * <nl> + BlockInputStreamPtr RedisDictionarySource : : loadIds ( const std : : vector < UInt64 > & ids ) <nl> + { <nl> + if ( ! dict_struct . id ) <nl> + throw Exception { " ' id ' is required for selective loading " , ErrorCodes : : UNSUPPORTED_METHOD } ; <nl> + <nl> + Poco : : Redis : : Array ids_array ( new Poco : : Redis : : Array ) ; <nl> + for ( const UInt64 id : ids ) <nl> + ids_array - > add ( DB : : toString ( id ) , Int32 ( id ) ) ; <nl> + <nl> + cursor - > query ( ) . selector ( ) . addNewDocument ( dict_struct . id - > name ) . add ( " $ in " , ids_array ) ; <nl> + <nl> + return std : : make_shared < RedisBlockInputStream > ( connection , sample_block , max_block_size ) ; <nl> + } <nl> + <nl> + <nl> + BlockInputStreamPtr RedisDictionarySource : : loadKeys ( const Columns & key_columns , const std : : vector < size_t > & requested_rows ) <nl> + { <nl> + if ( ! dict_struct . key ) <nl> + throw Exception { " ' key ' is required for selective loading " , ErrorCodes : : UNSUPPORTED_METHOD } ; <nl> + <nl> + Poco : : Redis : : Array : : Ptr keys_array ( new Poco : : Redis : : Array ) ; <nl> + <nl> + for ( const auto row_idx : requested_rows ) <nl> + { <nl> + auto & key = keys_array - > addNewDocument ( DB : : toString ( row_idx ) ) ; <nl> + <nl> + for ( const auto attr : ext : : enumerate ( * dict_struct . key ) ) <nl> + { <nl> + switch ( attr . second . underlying_type ) <nl> + { <nl> + case AttributeUnderlyingType : : UInt8 : <nl> + case AttributeUnderlyingType : : UInt16 : <nl> + case AttributeUnderlyingType : : UInt32 : <nl> + case AttributeUnderlyingType : : UInt64 : <nl> + case AttributeUnderlyingType : : UInt128 : <nl> + case AttributeUnderlyingType : : Int8 : <nl> + case AttributeUnderlyingType : : Int16 : <nl> + case AttributeUnderlyingType : : Int32 : <nl> + case AttributeUnderlyingType : : Int64 : <nl> + case AttributeUnderlyingType : : Decimal32 : <nl> + case AttributeUnderlyingType : : Decimal64 : <nl> + case AttributeUnderlyingType : : Decimal128 : <nl> + key . add ( attr . second . name , Int32 ( key_columns [ attr . first ] - > get64 ( row_idx ) ) ) ; <nl> + break ; <nl> + <nl> + case AttributeUnderlyingType : : Float32 : <nl> + case AttributeUnderlyingType : : Float64 : <nl> + key . add ( attr . second . name , applyVisitor ( FieldVisitorConvertToNumber < Float64 > ( ) , ( * key_columns [ attr . first ] ) [ row_idx ] ) ) ; <nl> + break ; <nl> + <nl> + case AttributeUnderlyingType : : String : <nl> + String _str ( get < String > ( ( * key_columns [ attr . first ] ) [ row_idx ] ) ) ; <nl> + / / / Convert string to ObjectID <nl> + if ( attr . second . is_object_id ) <nl> + { <nl> + Poco : : Redis : : ObjectId : : Ptr _id ( new Poco : : Redis : : ObjectId ( _str ) ) ; <nl> + key . add ( attr . second . name , _id ) ; <nl> + } <nl> + else <nl> + { <nl> + key . add ( attr . second . name , _str ) ; <nl> + } <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + / / / If more than one key we should use $ or <nl> + cursor - > query ( ) . selector ( ) . add ( " $ or " , keys_array ) ; <nl> + <nl> + return std : : make_shared < RedisBlockInputStream > ( connection , sample_block , max_block_size ) ; <nl> + } <nl> + * / <nl> + <nl> + std : : string RedisDictionarySource : : toString ( ) const <nl> + { <nl> + return " Redis : " + host + ' : ' + DB : : toString ( port ) ; <nl> + } <nl> + <nl> + } <nl> + <nl> + # endif <nl> new file mode 100644 <nl> index 00000000000 . . 61417fac393 <nl> mmm / dev / null <nl> ppp b / dbms / src / Dictionaries / RedisDictionarySource . h <nl> <nl> + # pragma once <nl> + <nl> + # include < Common / config . h > <nl> + # if USE_POCO_REDIS <nl> + <nl> + # include " DictionaryStructure . h " <nl> + # include " IDictionarySource . h " <nl> + <nl> + namespace Poco <nl> + { <nl> + namespace Util <nl> + { <nl> + class AbstractConfiguration ; <nl> + } <nl> + <nl> + namespace Redis <nl> + { <nl> + class Client ; <nl> + } <nl> + } <nl> + <nl> + <nl> + namespace DB <nl> + { <nl> + / / / Allows loading dictionaries from a Redis collection <nl> + class RedisDictionarySource final : public IDictionarySource <nl> + { <nl> + RedisDictionarySource ( <nl> + const DictionaryStructure & dict_struct , <nl> + const std : : string & host , <nl> + UInt16 port , <nl> + const Block & sample_block ) ; <nl> + <nl> + public : <nl> + RedisDictionarySource ( <nl> + const DictionaryStructure & dict_struct , <nl> + const Poco : : Util : : AbstractConfiguration & config , <nl> + const std : : string & config_prefix , <nl> + Block & sample_block ) ; <nl> + <nl> + RedisDictionarySource ( const RedisDictionarySource & other ) ; <nl> + <nl> + ~ RedisDictionarySource ( ) override ; <nl> + <nl> + BlockInputStreamPtr loadAll ( ) override ; <nl> + <nl> + BlockInputStreamPtr loadUpdatedAll ( ) override <nl> + { <nl> + throw Exception { " Method loadUpdatedAll is unsupported for RedisDictionarySource " , ErrorCodes : : NOT_IMPLEMENTED } ; <nl> + } <nl> + <nl> + bool supportsSelectiveLoad ( ) const override { return true ; } <nl> + <nl> + BlockInputStreamPtr loadIds ( const std : : vector < UInt64 > & / * ids * / ) override { throw 1 ; } ; <nl> + <nl> + BlockInputStreamPtr loadKeys ( const Columns & / * key_columns * / , const std : : vector < size_t > & / * requested_rows * / ) override { throw 1 ; } ; <nl> + <nl> + / / / @ todo : for Redis , modification date can somehow be determined from the ` _id ` object field <nl> + bool isModified ( ) const override { return true ; } <nl> + <nl> + / / / Not yet supported <nl> + bool hasUpdateField ( ) const override { return false ; } <nl> + <nl> + DictionarySourcePtr clone ( ) const override { return std : : make_unique < RedisDictionarySource > ( * this ) ; } <nl> + <nl> + std : : string toString ( ) const override ; <nl> + <nl> + private : <nl> + const DictionaryStructure dict_struct ; <nl> + const std : : string host ; <nl> + const UInt16 port ; <nl> + Block sample_block ; <nl> + <nl> + std : : shared_ptr < Poco : : Redis : : Client > client ; <nl> + } ; <nl> + <nl> + } <nl> + # endif <nl> + <nl> + / * namespace DB <nl> + { <nl> + class DictionarySourceFactory ; <nl> + void registerDictionarySourceRedis ( DictionarySourceFactory & factory ) ; <nl> + } * / <nl>
Add basic functionality for dict
ClickHouse/ClickHouse
51384fd6917dda0f624b14b3deb09b20400436b6
2019-01-15T22:08:56Z
mmm a / docker / build / dev . x86_64 . dockerfile <nl> ppp b / docker / build / dev . x86_64 . dockerfile <nl> RUN apt - get install - y \ <nl> nfs - common \ <nl> zip <nl> <nl> + WORKDIR / apollo <nl> USER apollo <nl> mmm a / docker / canary / start_container . py <nl> ppp b / docker / canary / start_container . py <nl> def __init__ ( self , args ) : <nl> self . other_options = [ <nl> ' - - privileged ' , <nl> ' - - net host ' , <nl> - ' - w / apollo ' , <nl> ' - - add - host in_dev_docker : 127 . 0 . 0 . 1 ' , <nl> ' - - hostname in_dev_docker ' , <nl> ' - - shm - size 2G ' , <nl>
Docker : Add WORKDIR in dockerfile .
ApolloAuto/apollo
5a6e88ebd3866aad682bcd5ea899f7ac7528a904
2018-05-03T05:35:46Z
mmm a / src / x87 / code - stubs - x87 . cc <nl> ppp b / src / x87 / code - stubs - x87 . cc <nl> void StoreGlobalViaContextStub : : Generate ( MacroAssembler * masm ) { <nl> / / Load the PropertyCell at the specified slot . <nl> __ mov ( cell_reg , ContextOperand ( context_reg , slot_reg ) ) ; <nl> <nl> - / / Check that cell value is not the_hole . <nl> - { <nl> - / / TODO ( bmeurer ) : use ecx ( name_reg ) when name parameter is removed . <nl> - Register cell_value_reg = cell_details_reg ; <nl> - __ mov ( cell_value_reg , FieldOperand ( cell_reg , PropertyCell : : kValueOffset ) ) ; <nl> - __ CompareRoot ( cell_value_reg , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ j ( equal , & slow_case , FLAG_debug_code ? Label : : kFar : Label : : kNear ) ; <nl> - } <nl> - <nl> / / Load PropertyDetails for the cell ( actually only the cell_type and kind ) . <nl> __ mov ( cell_details_reg , <nl> FieldOperand ( cell_reg , PropertyCell : : kDetailsOffset ) ) ; <nl> __ SmiUntag ( cell_details_reg ) ; <nl> __ and_ ( cell_details_reg , <nl> Immediate ( PropertyDetails : : PropertyCellTypeField : : kMask | <nl> - PropertyDetails : : KindField : : kMask ) ) ; <nl> - <nl> + PropertyDetails : : KindField : : kMask | <nl> + PropertyDetails : : kAttributesReadOnlyMask ) ) ; <nl> <nl> / / Check if PropertyCell holds mutable data . <nl> Label not_mutable_data ; <nl> void StoreGlobalViaContextStub : : Generate ( MacroAssembler * masm ) { <nl> __ cmp ( value_reg , FieldOperand ( cell_reg , PropertyCell : : kValueOffset ) ) ; <nl> __ j ( not_equal , & not_same_value , <nl> FLAG_debug_code ? Label : : kFar : Label : : kNear ) ; <nl> + / / Make sure the PropertyCell is not marked READ_ONLY . <nl> + __ test ( cell_details_reg , <nl> + Immediate ( PropertyDetails : : kAttributesReadOnlyMask ) ) ; <nl> + __ j ( not_zero , & slow_case ) ; <nl> if ( FLAG_debug_code ) { <nl> Label done ; <nl> / / This can only be true for Constant , ConstantType and Undefined cells , <nl> void StoreGlobalViaContextStub : : Generate ( MacroAssembler * masm ) { <nl> __ Ret ( ) ; <nl> __ bind ( & not_same_value ) ; <nl> <nl> - / / Check if PropertyCell contains data with constant type . <nl> + / / Check if PropertyCell contains data with constant type ( and is not <nl> + / / READ_ONLY ) . <nl> __ cmp ( cell_details_reg , <nl> Immediate ( PropertyDetails : : PropertyCellTypeField : : encode ( <nl> PropertyCellType : : kConstantType ) | <nl>
X87 : [ stubs ] Properly handle read - only properties in StoreGlobalViaContextStub .
v8/v8
02f097487cb69c1b51712e8b3c6e767b0f892fdf
2015-07-28T08:34:43Z
mmm a / xbmc / video / dialogs / GUIDialogVideoInfo . cpp <nl> ppp b / xbmc / video / dialogs / GUIDialogVideoInfo . cpp <nl> void CGUIDialogVideoInfo : : OnGetArt ( ) <nl> / / which is probably the IMDb thumb . These could be wrong , so allow the user <nl> / / to delete the incorrect thumb <nl> CFileItemPtr item ( new CFileItem ( " thumb : / / None " , false ) ) ; <nl> - item - > SetIconImage ( " DefaultVideo . png " ) ; <nl> + item - > SetIconImage ( " DefaultPicture . png " ) ; <nl> item - > SetLabel ( g_localizeStrings . Get ( 13515 ) ) ; <nl> items . Add ( item ) ; <nl> } <nl> void CGUIDialogVideoInfo : : OnGetFanart ( ) <nl> else <nl> { <nl> CFileItemPtr itemNone ( new CFileItem ( " fanart : / / None " , false ) ) ; <nl> - itemNone - > SetIconImage ( " DefaultVideo . png " ) ; <nl> + itemNone - > SetIconImage ( " DefaultPicture . png " ) ; <nl> itemNone - > SetLabel ( g_localizeStrings . Get ( 20439 ) ) ; <nl> items . Add ( itemNone ) ; <nl> } <nl> void CGUIDialogVideoInfo : : ShowFor ( const CFileItem & item ) <nl> ADDON : : ScraperPtr info ; <nl> window - > OnItemInfo ( item , info ) ; <nl> } <nl> - } <nl> \ No newline at end of file <nl> + } <nl>
[ gui ] use correct fallback icon for " no art " entry in art selection
xbmc/xbmc
4d3b243811e4273676ac11039682a2cdcebe3761
2016-09-28T15:31:56Z
mmm a / tensorflow / python / ops / image_ops_impl . py <nl> ppp b / tensorflow / python / ops / image_ops_impl . py <nl> def extract_glimpse ( <nl> <nl> extract_glimpse . __doc__ = gen_image_ops . extract_glimpse . __doc__ <nl> <nl> - extract_glimpse_v2 = gen_image_ops . extract_glimpse <nl> + extract_glimpse_v2 = gen_image_ops . extract_glimpse <nl> tf_export ( v2 = [ ' image . extract_glimpse ' ] ) ( extract_glimpse_v2 ) <nl>
Pylint fix
tensorflow/tensorflow
196b5aefbb2ff6d0fff434e02699db621a8faf41
2019-01-28T21:58:03Z
mmm a / modules / imgproc / include / opencv2 / imgproc / imgproc . hpp <nl> ppp b / modules / imgproc / include / opencv2 / imgproc / imgproc . hpp <nl> enum <nl> COLOR_RGBA2mRGBA = 125 , <nl> COLOR_mRGBA2RGBA = 126 , <nl> <nl> - COLOR_COLORCVT_MAX = 127 <nl> + / / Edge - Aware Demosaicing <nl> + COLOR_BayerBG2BGR_EA = 127 , <nl> + COLOR_BayerGB2BGR_EA = 128 , <nl> + COLOR_BayerRG2BGR_EA = 129 , <nl> + COLOR_BayerGR2BGR_EA = 130 , <nl> + <nl> + COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA , <nl> + COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA , <nl> + COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA , <nl> + COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA , <nl> + <nl> + COLOR_COLORCVT_MAX = 131 <nl> } ; <nl> <nl> <nl> class CV_EXPORTS_W Subdiv2D <nl> Point2f bottomRight ; <nl> } ; <nl> <nl> + / / main function for all demosaicing procceses <nl> + CV_EXPORTS_W void demosaicing ( InputArray _src , OutputArray _dst , int code , int dcn = 0 ) ; <nl> + <nl> } <nl> <nl> # endif / * __cplusplus * / <nl> mmm a / modules / imgproc / include / opencv2 / imgproc / types_c . h <nl> ppp b / modules / imgproc / include / opencv2 / imgproc / types_c . h <nl> enum <nl> CV_RGBA2mRGBA = 125 , <nl> CV_mRGBA2RGBA = 126 , <nl> <nl> - CV_COLORCVT_MAX = 127 <nl> + / / Edge - Aware Demosaicing <nl> + CV_BayerBG2BGR_EA = 127 , <nl> + CV_BayerGB2BGR_EA = 128 , <nl> + CV_BayerRG2BGR_EA = 129 , <nl> + CV_BayerGR2BGR_EA = 130 , <nl> + <nl> + CV_BayerBG2RGB_EA = CV_BayerRG2BGR_EA , <nl> + CV_BayerGB2RGB_EA = CV_BayerGR2BGR_EA , <nl> + CV_BayerRG2RGB_EA = CV_BayerBG2BGR_EA , <nl> + CV_BayerGR2RGB_EA = CV_BayerGB2BGR_EA , <nl> + <nl> + CV_COLORCVT_MAX = 131 <nl> } ; <nl> <nl> <nl> mmm a / modules / imgproc / perf / perf_cvt_color . cpp <nl> ppp b / modules / imgproc / perf / perf_cvt_color . cpp <nl> PERF_TEST_P ( Size_CvtMode2 , cvtColorYUV420 , <nl> <nl> SANITY_CHECK ( dst , 1 ) ; <nl> } <nl> + <nl> + CV_ENUM ( EdgeAwareBayerMode , COLOR_BayerBG2BGR_EA , COLOR_BayerGB2BGR_EA , COLOR_BayerRG2BGR_EA , COLOR_BayerGR2BGR_EA ) <nl> + <nl> + typedef std : : tr1 : : tuple < Size , EdgeAwareBayerMode > EdgeAwareParams ; <nl> + typedef perf : : TestBaseWithParam < EdgeAwareParams > EdgeAwareDemosaicingTest ; <nl> + <nl> + PERF_TEST_P ( EdgeAwareDemosaicingTest , demosaicingEA , <nl> + testing : : Combine ( <nl> + testing : : Values ( szVGA , sz720p , sz1080p , Size ( 130 , 60 ) ) , <nl> + testing : : ValuesIn ( EdgeAwareBayerMode : : all ( ) ) <nl> + ) <nl> + ) <nl> + { <nl> + Size sz = get < 0 > ( GetParam ( ) ) ; <nl> + int mode = get < 1 > ( GetParam ( ) ) ; <nl> + <nl> + Mat src ( sz , CV_8UC1 ) ; <nl> + Mat dst ( sz , CV_8UC3 ) ; <nl> + <nl> + declare . in ( src , WARMUP_RNG ) . out ( dst ) ; <nl> + <nl> + TEST_CYCLE ( ) cvtColor ( src , dst , mode , 3 ) ; <nl> + <nl> + SANITY_CHECK ( dst , 1 ) ; <nl> + } <nl> mmm a / modules / imgproc / src / color . cpp <nl> ppp b / modules / imgproc / src / color . cpp <nl> <nl> <nl> # include " precomp . hpp " <nl> # include < limits > <nl> - # include < iostream > <nl> <nl> namespace cv <nl> { <nl> struct Luv2RGB_b <nl> } ; <nl> <nl> <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / Bayer Pattern - > RGB conversion / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - template < typename T > <nl> - class SIMDBayerStubInterpolator_ <nl> - { <nl> - public : <nl> - int bayer2Gray ( const T * , int , T * , int , int , int , int ) const <nl> - { <nl> - return 0 ; <nl> - } <nl> - <nl> - int bayer2RGB ( const T * , int , T * , int , int ) const <nl> - { <nl> - return 0 ; <nl> - } <nl> - } ; <nl> - <nl> - # if CV_SSE2 <nl> - class SIMDBayerInterpolator_8u <nl> - { <nl> - public : <nl> - SIMDBayerInterpolator_8u ( ) <nl> - { <nl> - use_simd = checkHardwareSupport ( CV_CPU_SSE2 ) ; <nl> - } <nl> - <nl> - int bayer2Gray ( const uchar * bayer , int bayer_step , uchar * dst , <nl> - int width , int bcoeff , int gcoeff , int rcoeff ) const <nl> - { <nl> - if ( ! use_simd ) <nl> - return 0 ; <nl> - <nl> - __m128i _b2y = _mm_set1_epi16 ( ( short ) ( rcoeff * 2 ) ) ; <nl> - __m128i _g2y = _mm_set1_epi16 ( ( short ) ( gcoeff * 2 ) ) ; <nl> - __m128i _r2y = _mm_set1_epi16 ( ( short ) ( bcoeff * 2 ) ) ; <nl> - const uchar * bayer_end = bayer + width ; <nl> - <nl> - for ( ; bayer < = bayer_end - 18 ; bayer + = 14 , dst + = 14 ) <nl> - { <nl> - __m128i r0 = _mm_loadu_si128 ( ( const __m128i * ) bayer ) ; <nl> - __m128i r1 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step ) ) ; <nl> - __m128i r2 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step * 2 ) ) ; <nl> - <nl> - __m128i b1 = _mm_add_epi16 ( _mm_srli_epi16 ( _mm_slli_epi16 ( r0 , 8 ) , 7 ) , <nl> - _mm_srli_epi16 ( _mm_slli_epi16 ( r2 , 8 ) , 7 ) ) ; <nl> - __m128i b0 = _mm_add_epi16 ( b1 , _mm_srli_si128 ( b1 , 2 ) ) ; <nl> - b1 = _mm_slli_epi16 ( _mm_srli_si128 ( b1 , 2 ) , 1 ) ; <nl> - <nl> - __m128i g0 = _mm_add_epi16 ( _mm_srli_epi16 ( r0 , 7 ) , _mm_srli_epi16 ( r2 , 7 ) ) ; <nl> - __m128i g1 = _mm_srli_epi16 ( _mm_slli_epi16 ( r1 , 8 ) , 7 ) ; <nl> - g0 = _mm_add_epi16 ( g0 , _mm_add_epi16 ( g1 , _mm_srli_si128 ( g1 , 2 ) ) ) ; <nl> - g1 = _mm_slli_epi16 ( _mm_srli_si128 ( g1 , 2 ) , 2 ) ; <nl> - <nl> - r0 = _mm_srli_epi16 ( r1 , 8 ) ; <nl> - r1 = _mm_slli_epi16 ( _mm_add_epi16 ( r0 , _mm_srli_si128 ( r0 , 2 ) ) , 2 ) ; <nl> - r0 = _mm_slli_epi16 ( r0 , 3 ) ; <nl> - <nl> - g0 = _mm_add_epi16 ( _mm_mulhi_epi16 ( b0 , _b2y ) , _mm_mulhi_epi16 ( g0 , _g2y ) ) ; <nl> - g1 = _mm_add_epi16 ( _mm_mulhi_epi16 ( b1 , _b2y ) , _mm_mulhi_epi16 ( g1 , _g2y ) ) ; <nl> - g0 = _mm_add_epi16 ( g0 , _mm_mulhi_epi16 ( r0 , _r2y ) ) ; <nl> - g1 = _mm_add_epi16 ( g1 , _mm_mulhi_epi16 ( r1 , _r2y ) ) ; <nl> - g0 = _mm_srli_epi16 ( g0 , 2 ) ; <nl> - g1 = _mm_srli_epi16 ( g1 , 2 ) ; <nl> - g0 = _mm_packus_epi16 ( g0 , g0 ) ; <nl> - g1 = _mm_packus_epi16 ( g1 , g1 ) ; <nl> - g0 = _mm_unpacklo_epi8 ( g0 , g1 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) dst , g0 ) ; <nl> - } <nl> - <nl> - return ( int ) ( bayer - ( bayer_end - width ) ) ; <nl> - } <nl> - <nl> - int bayer2RGB ( const uchar * bayer , int bayer_step , uchar * dst , int width , int blue ) const <nl> - { <nl> - if ( ! use_simd ) <nl> - return 0 ; <nl> - / * <nl> - B G B G | B G B G | B G B G | B G B G <nl> - G R G R | G R G R | G R G R | G R G R <nl> - B G B G | B G B G | B G B G | B G B G <nl> - * / <nl> - __m128i delta1 = _mm_set1_epi16 ( 1 ) , delta2 = _mm_set1_epi16 ( 2 ) ; <nl> - __m128i mask = _mm_set1_epi16 ( blue < 0 ? - 1 : 0 ) , z = _mm_setzero_si128 ( ) ; <nl> - __m128i masklo = _mm_set1_epi16 ( 0x00ff ) ; <nl> - const uchar * bayer_end = bayer + width ; <nl> - <nl> - for ( ; bayer < = bayer_end - 18 ; bayer + = 14 , dst + = 42 ) <nl> - { <nl> - __m128i r0 = _mm_loadu_si128 ( ( const __m128i * ) bayer ) ; <nl> - __m128i r1 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step ) ) ; <nl> - __m128i r2 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step * 2 ) ) ; <nl> - <nl> - __m128i b1 = _mm_add_epi16 ( _mm_and_si128 ( r0 , masklo ) , _mm_and_si128 ( r2 , masklo ) ) ; <nl> - __m128i b0 = _mm_add_epi16 ( b1 , _mm_srli_si128 ( b1 , 2 ) ) ; <nl> - b1 = _mm_srli_si128 ( b1 , 2 ) ; <nl> - b1 = _mm_srli_epi16 ( _mm_add_epi16 ( b1 , delta1 ) , 1 ) ; <nl> - b0 = _mm_srli_epi16 ( _mm_add_epi16 ( b0 , delta2 ) , 2 ) ; <nl> - b0 = _mm_packus_epi16 ( b0 , b1 ) ; <nl> - <nl> - __m128i g0 = _mm_add_epi16 ( _mm_srli_epi16 ( r0 , 8 ) , _mm_srli_epi16 ( r2 , 8 ) ) ; <nl> - __m128i g1 = _mm_and_si128 ( r1 , masklo ) ; <nl> - g0 = _mm_add_epi16 ( g0 , _mm_add_epi16 ( g1 , _mm_srli_si128 ( g1 , 2 ) ) ) ; <nl> - g1 = _mm_srli_si128 ( g1 , 2 ) ; <nl> - g0 = _mm_srli_epi16 ( _mm_add_epi16 ( g0 , delta2 ) , 2 ) ; <nl> - g0 = _mm_packus_epi16 ( g0 , g1 ) ; <nl> - <nl> - r0 = _mm_srli_epi16 ( r1 , 8 ) ; <nl> - r1 = _mm_add_epi16 ( r0 , _mm_srli_si128 ( r0 , 2 ) ) ; <nl> - r1 = _mm_srli_epi16 ( _mm_add_epi16 ( r1 , delta1 ) , 1 ) ; <nl> - r0 = _mm_packus_epi16 ( r0 , r1 ) ; <nl> - <nl> - b1 = _mm_and_si128 ( _mm_xor_si128 ( b0 , r0 ) , mask ) ; <nl> - b0 = _mm_xor_si128 ( b0 , b1 ) ; <nl> - r0 = _mm_xor_si128 ( r0 , b1 ) ; <nl> - <nl> - / / b1 g1 b1 g1 . . . <nl> - b1 = _mm_unpackhi_epi8 ( b0 , g0 ) ; <nl> - / / b0 g0 b2 g2 b4 g4 . . . . <nl> - b0 = _mm_unpacklo_epi8 ( b0 , g0 ) ; <nl> - <nl> - / / r1 0 r3 0 . . . <nl> - r1 = _mm_unpackhi_epi8 ( r0 , z ) ; <nl> - / / r0 0 r2 0 r4 0 . . . <nl> - r0 = _mm_unpacklo_epi8 ( r0 , z ) ; <nl> - <nl> - / / 0 b0 g0 r0 0 b2 g2 r2 0 . . . <nl> - g0 = _mm_slli_si128 ( _mm_unpacklo_epi16 ( b0 , r0 ) , 1 ) ; <nl> - / / 0 b8 g8 r8 0 b10 g10 r10 0 . . . <nl> - g1 = _mm_slli_si128 ( _mm_unpackhi_epi16 ( b0 , r0 ) , 1 ) ; <nl> - <nl> - / / b1 g1 r1 0 b3 g3 r3 . . . . <nl> - r0 = _mm_unpacklo_epi16 ( b1 , r1 ) ; <nl> - / / b9 g9 r9 0 . . . <nl> - r1 = _mm_unpackhi_epi16 ( b1 , r1 ) ; <nl> - <nl> - b0 = _mm_srli_si128 ( _mm_unpacklo_epi32 ( g0 , r0 ) , 1 ) ; <nl> - b1 = _mm_srli_si128 ( _mm_unpackhi_epi32 ( g0 , r0 ) , 1 ) ; <nl> - <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 0 ) , b0 ) ; <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 1 ) , _mm_srli_si128 ( b0 , 8 ) ) ; <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 2 ) , b1 ) ; <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 3 ) , _mm_srli_si128 ( b1 , 8 ) ) ; <nl> - <nl> - g0 = _mm_srli_si128 ( _mm_unpacklo_epi32 ( g1 , r1 ) , 1 ) ; <nl> - g1 = _mm_srli_si128 ( _mm_unpackhi_epi32 ( g1 , r1 ) , 1 ) ; <nl> - <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 4 ) , g0 ) ; <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 5 ) , _mm_srli_si128 ( g0 , 8 ) ) ; <nl> - <nl> - _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 6 ) , g1 ) ; <nl> - } <nl> - <nl> - return ( int ) ( bayer - ( bayer_end - width ) ) ; <nl> - } <nl> - <nl> - bool use_simd ; <nl> - } ; <nl> - # else <nl> - typedef SIMDBayerStubInterpolator_ < uchar > SIMDBayerInterpolator_8u ; <nl> - # endif <nl> - <nl> - template < typename T , class SIMDInterpolator > <nl> - static void Bayer2Gray_ ( const Mat & srcmat , Mat & dstmat , int code ) <nl> - { <nl> - SIMDInterpolator vecOp ; <nl> - const int R2Y = 4899 ; <nl> - const int G2Y = 9617 ; <nl> - const int B2Y = 1868 ; <nl> - const int SHIFT = 14 ; <nl> - <nl> - const T * bayer0 = ( const T * ) srcmat . data ; <nl> - int bayer_step = ( int ) ( srcmat . step / sizeof ( T ) ) ; <nl> - T * dst0 = ( T * ) dstmat . data ; <nl> - int dst_step = ( int ) ( dstmat . step / sizeof ( T ) ) ; <nl> - Size size = srcmat . size ( ) ; <nl> - int bcoeff = B2Y , rcoeff = R2Y ; <nl> - int start_with_green = code = = CV_BayerGB2GRAY | | code = = CV_BayerGR2GRAY ; <nl> - bool brow = true ; <nl> - <nl> - if ( code ! = CV_BayerBG2GRAY & & code ! = CV_BayerGB2GRAY ) <nl> - { <nl> - brow = false ; <nl> - std : : swap ( bcoeff , rcoeff ) ; <nl> - } <nl> - <nl> - dst0 + = dst_step + 1 ; <nl> - size . height - = 2 ; <nl> - size . width - = 2 ; <nl> - <nl> - for ( ; size . height - - > 0 ; bayer0 + = bayer_step , dst0 + = dst_step ) <nl> - { <nl> - unsigned t0 , t1 , t2 ; <nl> - const T * bayer = bayer0 ; <nl> - T * dst = dst0 ; <nl> - const T * bayer_end = bayer + size . width ; <nl> - <nl> - if ( size . width < = 0 ) <nl> - { <nl> - dst [ - 1 ] = dst [ size . width ] = 0 ; <nl> - continue ; <nl> - } <nl> - <nl> - if ( start_with_green ) <nl> - { <nl> - t0 = ( bayer [ 1 ] + bayer [ bayer_step * 2 + 1 ] ) * rcoeff ; <nl> - t1 = ( bayer [ bayer_step ] + bayer [ bayer_step + 2 ] ) * bcoeff ; <nl> - t2 = bayer [ bayer_step + 1 ] * ( 2 * G2Y ) ; <nl> - <nl> - dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 1 ) ; <nl> - bayer + + ; <nl> - dst + + ; <nl> - } <nl> - <nl> - int delta = vecOp . bayer2Gray ( bayer , bayer_step , dst , size . width , bcoeff , G2Y , rcoeff ) ; <nl> - bayer + = delta ; <nl> - dst + = delta ; <nl> - <nl> - for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = 2 ) <nl> - { <nl> - t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> - t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] ) * G2Y ; <nl> - t2 = bayer [ bayer_step + 1 ] * ( 4 * bcoeff ) ; <nl> - dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 2 ) ; <nl> - <nl> - t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> - t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] ) * bcoeff ; <nl> - t2 = bayer [ bayer_step + 2 ] * ( 2 * G2Y ) ; <nl> - dst [ 1 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 1 ) ; <nl> - } <nl> - <nl> - if ( bayer < bayer_end ) <nl> - { <nl> - t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> - t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] ) * G2Y ; <nl> - t2 = bayer [ bayer_step + 1 ] * ( 4 * bcoeff ) ; <nl> - dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 2 ) ; <nl> - bayer + + ; <nl> - dst + + ; <nl> - } <nl> - <nl> - dst0 [ - 1 ] = dst0 [ 0 ] ; <nl> - dst0 [ size . width ] = dst0 [ size . width - 1 ] ; <nl> - <nl> - brow = ! brow ; <nl> - std : : swap ( bcoeff , rcoeff ) ; <nl> - start_with_green = ! start_with_green ; <nl> - } <nl> - <nl> - size = dstmat . size ( ) ; <nl> - dst0 = ( T * ) dstmat . data ; <nl> - if ( size . height > 2 ) <nl> - for ( int i = 0 ; i < size . width ; i + + ) <nl> - { <nl> - dst0 [ i ] = dst0 [ i + dst_step ] ; <nl> - dst0 [ i + ( size . height - 1 ) * dst_step ] = dst0 [ i + ( size . height - 2 ) * dst_step ] ; <nl> - } <nl> - else <nl> - for ( int i = 0 ; i < size . width ; i + + ) <nl> - { <nl> - dst0 [ i ] = dst0 [ i + ( size . height - 1 ) * dst_step ] = 0 ; <nl> - } <nl> - } <nl> - <nl> - template < typename T , class SIMDInterpolator > <nl> - static void Bayer2RGB_ ( const Mat & srcmat , Mat & dstmat , int code ) <nl> - { <nl> - SIMDInterpolator vecOp ; <nl> - const T * bayer0 = ( const T * ) srcmat . data ; <nl> - int bayer_step = ( int ) ( srcmat . step / sizeof ( T ) ) ; <nl> - T * dst0 = ( T * ) dstmat . data ; <nl> - int dst_step = ( int ) ( dstmat . step / sizeof ( T ) ) ; <nl> - Size size = srcmat . size ( ) ; <nl> - int blue = code = = CV_BayerBG2BGR | | code = = CV_BayerGB2BGR ? - 1 : 1 ; <nl> - int start_with_green = code = = CV_BayerGB2BGR | | code = = CV_BayerGR2BGR ; <nl> - <nl> - dst0 + = dst_step + 3 + 1 ; <nl> - size . height - = 2 ; <nl> - size . width - = 2 ; <nl> - <nl> - for ( ; size . height - - > 0 ; bayer0 + = bayer_step , dst0 + = dst_step ) <nl> - { <nl> - int t0 , t1 ; <nl> - const T * bayer = bayer0 ; <nl> - T * dst = dst0 ; <nl> - const T * bayer_end = bayer + size . width ; <nl> - <nl> - if ( size . width < = 0 ) <nl> - { <nl> - dst [ - 4 ] = dst [ - 3 ] = dst [ - 2 ] = dst [ size . width * 3 - 1 ] = <nl> - dst [ size . width * 3 ] = dst [ size . width * 3 + 1 ] = 0 ; <nl> - continue ; <nl> - } <nl> - <nl> - if ( start_with_green ) <nl> - { <nl> - t0 = ( bayer [ 1 ] + bayer [ bayer_step * 2 + 1 ] + 1 ) > > 1 ; <nl> - t1 = ( bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + 1 ) > > 1 ; <nl> - dst [ - blue ] = ( T ) t0 ; <nl> - dst [ 0 ] = bayer [ bayer_step + 1 ] ; <nl> - dst [ blue ] = ( T ) t1 ; <nl> - bayer + + ; <nl> - dst + = 3 ; <nl> - } <nl> - <nl> - int delta = vecOp . bayer2RGB ( bayer , bayer_step , dst , size . width , blue ) ; <nl> - bayer + = delta ; <nl> - dst + = delta * 3 ; <nl> - <nl> - if ( blue > 0 ) <nl> - { <nl> - for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = 6 ) <nl> - { <nl> - t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> - bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> - t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> - bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> - dst [ - 1 ] = ( T ) t0 ; <nl> - dst [ 0 ] = ( T ) t1 ; <nl> - dst [ 1 ] = bayer [ bayer_step + 1 ] ; <nl> - <nl> - t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> - t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> - dst [ 2 ] = ( T ) t0 ; <nl> - dst [ 3 ] = bayer [ bayer_step + 2 ] ; <nl> - dst [ 4 ] = ( T ) t1 ; <nl> - } <nl> - } <nl> - else <nl> - { <nl> - for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = 6 ) <nl> - { <nl> - t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> - bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> - t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> - bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> - dst [ 1 ] = ( T ) t0 ; <nl> - dst [ 0 ] = ( T ) t1 ; <nl> - dst [ - 1 ] = bayer [ bayer_step + 1 ] ; <nl> - <nl> - t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> - t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> - dst [ 4 ] = ( T ) t0 ; <nl> - dst [ 3 ] = bayer [ bayer_step + 2 ] ; <nl> - dst [ 2 ] = ( T ) t1 ; <nl> - } <nl> - } <nl> - <nl> - if ( bayer < bayer_end ) <nl> - { <nl> - t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> - bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> - t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> - bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> - dst [ - blue ] = ( T ) t0 ; <nl> - dst [ 0 ] = ( T ) t1 ; <nl> - dst [ blue ] = bayer [ bayer_step + 1 ] ; <nl> - bayer + + ; <nl> - dst + = 3 ; <nl> - } <nl> - <nl> - dst0 [ - 4 ] = dst0 [ - 1 ] ; <nl> - dst0 [ - 3 ] = dst0 [ 0 ] ; <nl> - dst0 [ - 2 ] = dst0 [ 1 ] ; <nl> - dst0 [ size . width * 3 - 1 ] = dst0 [ size . width * 3 - 4 ] ; <nl> - dst0 [ size . width * 3 ] = dst0 [ size . width * 3 - 3 ] ; <nl> - dst0 [ size . width * 3 + 1 ] = dst0 [ size . width * 3 - 2 ] ; <nl> - <nl> - blue = - blue ; <nl> - start_with_green = ! start_with_green ; <nl> - } <nl> - <nl> - size = dstmat . size ( ) ; <nl> - dst0 = ( T * ) dstmat . data ; <nl> - if ( size . height > 2 ) <nl> - for ( int i = 0 ; i < size . width * 3 ; i + + ) <nl> - { <nl> - dst0 [ i ] = dst0 [ i + dst_step ] ; <nl> - dst0 [ i + ( size . height - 1 ) * dst_step ] = dst0 [ i + ( size . height - 2 ) * dst_step ] ; <nl> - } <nl> - else <nl> - for ( int i = 0 ; i < size . width * 3 ; i + + ) <nl> - { <nl> - dst0 [ i ] = dst0 [ i + ( size . height - 1 ) * dst_step ] = 0 ; <nl> - } <nl> - } <nl> - <nl> - <nl> - / / / / / / / / / / / / / / / / / / / Demosaicing using Variable Number of Gradients / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - static void Bayer2RGB_VNG_8u ( const Mat & srcmat , Mat & dstmat , int code ) <nl> - { <nl> - const uchar * bayer = srcmat . data ; <nl> - int bstep = ( int ) srcmat . step ; <nl> - uchar * dst = dstmat . data ; <nl> - int dststep = ( int ) dstmat . step ; <nl> - Size size = srcmat . size ( ) ; <nl> - <nl> - int blueIdx = code = = CV_BayerBG2BGR_VNG | | code = = CV_BayerGB2BGR_VNG ? 0 : 2 ; <nl> - bool greenCell0 = code ! = CV_BayerBG2BGR_VNG & & code ! = CV_BayerRG2BGR_VNG ; <nl> - <nl> - / / for too small images use the simple interpolation algorithm <nl> - if ( MIN ( size . width , size . height ) < 8 ) <nl> - { <nl> - Bayer2RGB_ < uchar , SIMDBayerInterpolator_8u > ( srcmat , dstmat , code ) ; <nl> - return ; <nl> - } <nl> - <nl> - const int brows = 3 , bcn = 7 ; <nl> - int N = size . width , N2 = N * 2 , N3 = N * 3 , N4 = N * 4 , N5 = N * 5 , N6 = N * 6 , N7 = N * 7 ; <nl> - int i , bufstep = N7 * bcn ; <nl> - cv : : AutoBuffer < ushort > _buf ( bufstep * brows ) ; <nl> - ushort * buf = ( ushort * ) _buf ; <nl> - <nl> - bayer + = bstep * 2 ; <nl> - <nl> - # if CV_SSE2 <nl> - bool haveSSE = cv : : checkHardwareSupport ( CV_CPU_SSE2 ) ; <nl> - # define _mm_absdiff_epu16 ( a , b ) _mm_adds_epu16 ( _mm_subs_epu16 ( a , b ) , _mm_subs_epu16 ( b , a ) ) <nl> - # endif <nl> - <nl> - for ( int y = 2 ; y < size . height - 4 ; y + + ) <nl> - { <nl> - uchar * dstrow = dst + dststep * y + 6 ; <nl> - const uchar * srow ; <nl> - <nl> - for ( int dy = ( y = = 2 ? - 1 : 1 ) ; dy < = 1 ; dy + + ) <nl> - { <nl> - ushort * brow = buf + ( ( y + dy - 1 ) % brows ) * bufstep + 1 ; <nl> - srow = bayer + ( y + dy ) * bstep + 1 ; <nl> - <nl> - for ( i = 0 ; i < bcn ; i + + ) <nl> - brow [ N * i - 1 ] = brow [ ( N - 2 ) + N * i ] = 0 ; <nl> - <nl> - i = 1 ; <nl> - <nl> - # if CV_SSE2 <nl> - if ( haveSSE ) <nl> - { <nl> - __m128i z = _mm_setzero_si128 ( ) ; <nl> - for ( ; i < = N - 9 ; i + = 8 , srow + = 8 , brow + = 8 ) <nl> - { <nl> - __m128i s1 , s2 , s3 , s4 , s6 , s7 , s8 , s9 ; <nl> - <nl> - s1 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 - bstep ) ) , z ) ; <nl> - s2 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - bstep ) ) , z ) ; <nl> - s3 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 - bstep ) ) , z ) ; <nl> - <nl> - s4 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 ) ) , z ) ; <nl> - s6 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 ) ) , z ) ; <nl> - <nl> - s7 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 + bstep ) ) , z ) ; <nl> - s8 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + bstep ) ) , z ) ; <nl> - s9 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 + bstep ) ) , z ) ; <nl> - <nl> - __m128i b0 , b1 , b2 , b3 , b4 , b5 , b6 ; <nl> - <nl> - b0 = _mm_adds_epu16 ( _mm_slli_epi16 ( _mm_absdiff_epu16 ( s2 , s8 ) , 1 ) , <nl> - _mm_adds_epu16 ( _mm_absdiff_epu16 ( s1 , s7 ) , <nl> - _mm_absdiff_epu16 ( s3 , s9 ) ) ) ; <nl> - b1 = _mm_adds_epu16 ( _mm_slli_epi16 ( _mm_absdiff_epu16 ( s4 , s6 ) , 1 ) , <nl> - _mm_adds_epu16 ( _mm_absdiff_epu16 ( s1 , s3 ) , <nl> - _mm_absdiff_epu16 ( s7 , s9 ) ) ) ; <nl> - b2 = _mm_slli_epi16 ( _mm_absdiff_epu16 ( s3 , s7 ) , 1 ) ; <nl> - b3 = _mm_slli_epi16 ( _mm_absdiff_epu16 ( s1 , s9 ) , 1 ) ; <nl> - <nl> - _mm_storeu_si128 ( ( __m128i * ) brow , b0 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N ) , b1 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N2 ) , b2 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N3 ) , b3 ) ; <nl> - <nl> - b4 = _mm_adds_epu16 ( b2 , _mm_adds_epu16 ( _mm_absdiff_epu16 ( s2 , s4 ) , <nl> - _mm_absdiff_epu16 ( s6 , s8 ) ) ) ; <nl> - b5 = _mm_adds_epu16 ( b3 , _mm_adds_epu16 ( _mm_absdiff_epu16 ( s2 , s6 ) , <nl> - _mm_absdiff_epu16 ( s4 , s8 ) ) ) ; <nl> - b6 = _mm_adds_epu16 ( _mm_adds_epu16 ( s2 , s4 ) , _mm_adds_epu16 ( s6 , s8 ) ) ; <nl> - b6 = _mm_srli_epi16 ( b6 , 1 ) ; <nl> - <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N4 ) , b4 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N5 ) , b5 ) ; <nl> - _mm_storeu_si128 ( ( __m128i * ) ( brow + N6 ) , b6 ) ; <nl> - } <nl> - } <nl> - # endif <nl> - <nl> - for ( ; i < N - 1 ; i + + , srow + + , brow + + ) <nl> - { <nl> - brow [ 0 ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ - 1 + bstep ] ) + <nl> - std : : abs ( srow [ - bstep ] - srow [ + bstep ] ) * 2 + <nl> - std : : abs ( srow [ 1 - bstep ] - srow [ 1 + bstep ] ) ) ; <nl> - brow [ N ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ 1 - bstep ] ) + <nl> - std : : abs ( srow [ - 1 ] - srow [ 1 ] ) * 2 + <nl> - std : : abs ( srow [ - 1 + bstep ] - srow [ 1 + bstep ] ) ) ; <nl> - brow [ N2 ] = ( ushort ) ( std : : abs ( srow [ + 1 - bstep ] - srow [ - 1 + bstep ] ) * 2 ) ; <nl> - brow [ N3 ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ 1 + bstep ] ) * 2 ) ; <nl> - brow [ N4 ] = ( ushort ) ( brow [ N2 ] + std : : abs ( srow [ - bstep ] - srow [ - 1 ] ) + <nl> - std : : abs ( srow [ + bstep ] - srow [ 1 ] ) ) ; <nl> - brow [ N5 ] = ( ushort ) ( brow [ N3 ] + std : : abs ( srow [ - bstep ] - srow [ 1 ] ) + <nl> - std : : abs ( srow [ + bstep ] - srow [ - 1 ] ) ) ; <nl> - brow [ N6 ] = ( ushort ) ( ( srow [ - bstep ] + srow [ - 1 ] + srow [ 1 ] + srow [ + bstep ] ) > > 1 ) ; <nl> - } <nl> - } <nl> - <nl> - const ushort * brow0 = buf + ( ( y - 2 ) % brows ) * bufstep + 2 ; <nl> - const ushort * brow1 = buf + ( ( y - 1 ) % brows ) * bufstep + 2 ; <nl> - const ushort * brow2 = buf + ( y % brows ) * bufstep + 2 ; <nl> - static const float scale [ ] = { 0 . f , 0 . 5f , 0 . 25f , 0 . 1666666666667f , 0 . 125f , 0 . 1f , 0 . 08333333333f , 0 . 0714286f , 0 . 0625f } ; <nl> - srow = bayer + y * bstep + 2 ; <nl> - bool greenCell = greenCell0 ; <nl> - <nl> - i = 2 ; <nl> - # if CV_SSE2 <nl> - int limit = ! haveSSE ? N - 2 : greenCell ? std : : min ( 3 , N - 2 ) : 2 ; <nl> - # else <nl> - int limit = N - 2 ; <nl> - # endif <nl> - <nl> - do <nl> - { <nl> - for ( ; i < limit ; i + + , srow + + , brow0 + + , brow1 + + , brow2 + + , dstrow + = 3 ) <nl> - { <nl> - int gradN = brow0 [ 0 ] + brow1 [ 0 ] ; <nl> - int gradS = brow1 [ 0 ] + brow2 [ 0 ] ; <nl> - int gradW = brow1 [ N - 1 ] + brow1 [ N ] ; <nl> - int gradE = brow1 [ N ] + brow1 [ N + 1 ] ; <nl> - int minGrad = std : : min ( std : : min ( std : : min ( gradN , gradS ) , gradW ) , gradE ) ; <nl> - int maxGrad = std : : max ( std : : max ( std : : max ( gradN , gradS ) , gradW ) , gradE ) ; <nl> - int R , G , B ; <nl> - <nl> - if ( ! greenCell ) <nl> - { <nl> - int gradNE = brow0 [ N4 + 1 ] + brow1 [ N4 ] ; <nl> - int gradSW = brow1 [ N4 ] + brow2 [ N4 - 1 ] ; <nl> - int gradNW = brow0 [ N5 - 1 ] + brow1 [ N5 ] ; <nl> - int gradSE = brow1 [ N5 ] + brow2 [ N5 + 1 ] ; <nl> - <nl> - minGrad = std : : min ( std : : min ( std : : min ( std : : min ( minGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> - maxGrad = std : : max ( std : : max ( std : : max ( std : : max ( maxGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> - int T = minGrad + MAX ( maxGrad / 2 , 1 ) ; <nl> - <nl> - int Rs = 0 , Gs = 0 , Bs = 0 , ng = 0 ; <nl> - if ( gradN < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 ] + srow [ 0 ] ; <nl> - Gs + = srow [ - bstep ] * 2 ; <nl> - Bs + = srow [ - bstep - 1 ] + srow [ - bstep + 1 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradS < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 ] + srow [ 0 ] ; <nl> - Gs + = srow [ bstep ] * 2 ; <nl> - Bs + = srow [ bstep - 1 ] + srow [ bstep + 1 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradW < T ) <nl> - { <nl> - Rs + = srow [ - 2 ] + srow [ 0 ] ; <nl> - Gs + = srow [ - 1 ] * 2 ; <nl> - Bs + = srow [ - bstep - 1 ] + srow [ bstep - 1 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradE < T ) <nl> - { <nl> - Rs + = srow [ 2 ] + srow [ 0 ] ; <nl> - Gs + = srow [ 1 ] * 2 ; <nl> - Bs + = srow [ - bstep + 1 ] + srow [ bstep + 1 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradNE < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 + 2 ] + srow [ 0 ] ; <nl> - Gs + = brow0 [ N6 + 1 ] ; <nl> - Bs + = srow [ - bstep + 1 ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - if ( gradSW < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 - 2 ] + srow [ 0 ] ; <nl> - Gs + = brow2 [ N6 - 1 ] ; <nl> - Bs + = srow [ bstep - 1 ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - if ( gradNW < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 - 2 ] + srow [ 0 ] ; <nl> - Gs + = brow0 [ N6 - 1 ] ; <nl> - Bs + = srow [ - bstep + 1 ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - if ( gradSE < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 + 2 ] + srow [ 0 ] ; <nl> - Gs + = brow2 [ N6 + 1 ] ; <nl> - Bs + = srow [ - bstep + 1 ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - R = srow [ 0 ] ; <nl> - G = R + cvRound ( ( Gs - Rs ) * scale [ ng ] ) ; <nl> - B = R + cvRound ( ( Bs - Rs ) * scale [ ng ] ) ; <nl> - } <nl> - else <nl> - { <nl> - int gradNE = brow0 [ N2 ] + brow0 [ N2 + 1 ] + brow1 [ N2 ] + brow1 [ N2 + 1 ] ; <nl> - int gradSW = brow1 [ N2 ] + brow1 [ N2 - 1 ] + brow2 [ N2 ] + brow2 [ N2 - 1 ] ; <nl> - int gradNW = brow0 [ N3 ] + brow0 [ N3 - 1 ] + brow1 [ N3 ] + brow1 [ N3 - 1 ] ; <nl> - int gradSE = brow1 [ N3 ] + brow1 [ N3 + 1 ] + brow2 [ N3 ] + brow2 [ N3 + 1 ] ; <nl> - <nl> - minGrad = std : : min ( std : : min ( std : : min ( std : : min ( minGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> - maxGrad = std : : max ( std : : max ( std : : max ( std : : max ( maxGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> - int T = minGrad + MAX ( maxGrad / 2 , 1 ) ; <nl> - <nl> - int Rs = 0 , Gs = 0 , Bs = 0 , ng = 0 ; <nl> - if ( gradN < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 - 1 ] + srow [ - bstep * 2 + 1 ] ; <nl> - Gs + = srow [ - bstep * 2 ] + srow [ 0 ] ; <nl> - Bs + = srow [ - bstep ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - if ( gradS < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 - 1 ] + srow [ bstep * 2 + 1 ] ; <nl> - Gs + = srow [ bstep * 2 ] + srow [ 0 ] ; <nl> - Bs + = srow [ bstep ] * 2 ; <nl> - ng + + ; <nl> - } <nl> - if ( gradW < T ) <nl> - { <nl> - Rs + = srow [ - 1 ] * 2 ; <nl> - Gs + = srow [ - 2 ] + srow [ 0 ] ; <nl> - Bs + = srow [ - bstep - 2 ] + srow [ bstep - 2 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradE < T ) <nl> - { <nl> - Rs + = srow [ 1 ] * 2 ; <nl> - Gs + = srow [ 2 ] + srow [ 0 ] ; <nl> - Bs + = srow [ - bstep + 2 ] + srow [ bstep + 2 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradNE < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 + 1 ] + srow [ 1 ] ; <nl> - Gs + = srow [ - bstep + 1 ] * 2 ; <nl> - Bs + = srow [ - bstep ] + srow [ - bstep + 2 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradSW < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 - 1 ] + srow [ - 1 ] ; <nl> - Gs + = srow [ bstep - 1 ] * 2 ; <nl> - Bs + = srow [ bstep ] + srow [ bstep - 2 ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradNW < T ) <nl> - { <nl> - Rs + = srow [ - bstep * 2 - 1 ] + srow [ - 1 ] ; <nl> - Gs + = srow [ - bstep - 1 ] * 2 ; <nl> - Bs + = srow [ - bstep - 2 ] + srow [ - bstep ] ; <nl> - ng + + ; <nl> - } <nl> - if ( gradSE < T ) <nl> - { <nl> - Rs + = srow [ bstep * 2 + 1 ] + srow [ 1 ] ; <nl> - Gs + = srow [ bstep + 1 ] * 2 ; <nl> - Bs + = srow [ bstep + 2 ] + srow [ bstep ] ; <nl> - ng + + ; <nl> - } <nl> - G = srow [ 0 ] ; <nl> - R = G + cvRound ( ( Rs - Gs ) * scale [ ng ] ) ; <nl> - B = G + cvRound ( ( Bs - Gs ) * scale [ ng ] ) ; <nl> - } <nl> - dstrow [ blueIdx ] = CV_CAST_8U ( B ) ; <nl> - dstrow [ 1 ] = CV_CAST_8U ( G ) ; <nl> - dstrow [ blueIdx ^ 2 ] = CV_CAST_8U ( R ) ; <nl> - greenCell = ! greenCell ; <nl> - } <nl> - <nl> - # if CV_SSE2 <nl> - if ( ! haveSSE ) <nl> - break ; <nl> - <nl> - __m128i emask = _mm_set1_epi32 ( 0x0000ffff ) , <nl> - omask = _mm_set1_epi32 ( 0xffff0000 ) , <nl> - z = _mm_setzero_si128 ( ) , <nl> - one = _mm_set1_epi16 ( 1 ) ; <nl> - __m128 _0_5 = _mm_set1_ps ( 0 . 5f ) ; <nl> - <nl> - # define _mm_merge_epi16 ( a , b ) _mm_or_si128 ( _mm_and_si128 ( a , emask ) , _mm_and_si128 ( b , omask ) ) / / ( aA_aA_aA_aA ) * ( bB_bB_bB_bB ) = > ( bA_bA_bA_bA ) <nl> - # define _mm_cvtloepi16_ps ( a ) _mm_cvtepi32_ps ( _mm_srai_epi32 ( _mm_unpacklo_epi16 ( a , a ) , 16 ) ) / / ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) = > ( 1f , 2f , 3f , 4f ) <nl> - # define _mm_cvthiepi16_ps ( a ) _mm_cvtepi32_ps ( _mm_srai_epi32 ( _mm_unpackhi_epi16 ( a , a ) , 16 ) ) / / ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) = > ( 5f , 6f , 7f , 8f ) <nl> - # define _mm_loadl_u8_s16 ( ptr , offset ) _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( ( ptr ) + ( offset ) ) ) , z ) / / load 8 uchars to 8 shorts <nl> - <nl> - / / process 8 pixels at once <nl> - for ( ; i < = N - 10 ; i + = 8 , srow + = 8 , brow0 + = 8 , brow1 + = 8 , brow2 + = 8 ) <nl> - { <nl> - / / int gradN = brow0 [ 0 ] + brow1 [ 0 ] ; <nl> - __m128i gradN = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) brow0 ) , _mm_loadu_si128 ( ( __m128i * ) brow1 ) ) ; <nl> - <nl> - / / int gradS = brow1 [ 0 ] + brow2 [ 0 ] ; <nl> - __m128i gradS = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) brow1 ) , _mm_loadu_si128 ( ( __m128i * ) brow2 ) ) ; <nl> - <nl> - / / int gradW = brow1 [ N - 1 ] + brow1 [ N ] ; <nl> - __m128i gradW = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N ) ) ) ; <nl> - <nl> - / / int gradE = brow1 [ N + 1 ] + brow1 [ N ] ; <nl> - __m128i gradE = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N ) ) ) ; <nl> - <nl> - / / int minGrad = std : : min ( std : : min ( std : : min ( gradN , gradS ) , gradW ) , gradE ) ; <nl> - / / int maxGrad = std : : max ( std : : max ( std : : max ( gradN , gradS ) , gradW ) , gradE ) ; <nl> - __m128i minGrad = _mm_min_epi16 ( _mm_min_epi16 ( gradN , gradS ) , _mm_min_epi16 ( gradW , gradE ) ) ; <nl> - __m128i maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( gradN , gradS ) , _mm_max_epi16 ( gradW , gradE ) ) ; <nl> - <nl> - __m128i grad0 , grad1 ; <nl> - <nl> - / / int gradNE = brow0 [ N4 + 1 ] + brow1 [ N4 ] ; <nl> - / / int gradNE = brow0 [ N2 ] + brow0 [ N2 + 1 ] + brow1 [ N2 ] + brow1 [ N2 + 1 ] ; <nl> - grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N4 + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N4 ) ) ) ; <nl> - grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N2 + 1 ) ) ) , <nl> - _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 + 1 ) ) ) ) ; <nl> - __m128i gradNE = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> - <nl> - / / int gradSW = brow1 [ N4 ] + brow2 [ N4 - 1 ] ; <nl> - / / int gradSW = brow1 [ N2 ] + brow1 [ N2 - 1 ] + brow2 [ N2 ] + brow2 [ N2 - 1 ] ; <nl> - grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N4 - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N4 ) ) ) ; <nl> - grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N2 - 1 ) ) ) , <nl> - _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 - 1 ) ) ) ) ; <nl> - __m128i gradSW = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> - <nl> - minGrad = _mm_min_epi16 ( _mm_min_epi16 ( minGrad , gradNE ) , gradSW ) ; <nl> - maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( maxGrad , gradNE ) , gradSW ) ; <nl> - <nl> - / / int gradNW = brow0 [ N5 - 1 ] + brow1 [ N5 ] ; <nl> - / / int gradNW = brow0 [ N3 ] + brow0 [ N3 - 1 ] + brow1 [ N3 ] + brow1 [ N3 - 1 ] ; <nl> - grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N5 - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N5 ) ) ) ; <nl> - grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N3 - 1 ) ) ) , <nl> - _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 - 1 ) ) ) ) ; <nl> - __m128i gradNW = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> - <nl> - / / int gradSE = brow1 [ N5 ] + brow2 [ N5 + 1 ] ; <nl> - / / int gradSE = brow1 [ N3 ] + brow1 [ N3 + 1 ] + brow2 [ N3 ] + brow2 [ N3 + 1 ] ; <nl> - grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N5 + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N5 ) ) ) ; <nl> - grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N3 + 1 ) ) ) , <nl> - _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 + 1 ) ) ) ) ; <nl> - __m128i gradSE = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> - <nl> - minGrad = _mm_min_epi16 ( _mm_min_epi16 ( minGrad , gradNW ) , gradSE ) ; <nl> - maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( maxGrad , gradNW ) , gradSE ) ; <nl> - <nl> - / / int T = minGrad + maxGrad / 2 ; <nl> - __m128i T = _mm_adds_epi16 ( _mm_max_epi16 ( _mm_srli_epi16 ( maxGrad , 1 ) , one ) , minGrad ) ; <nl> - <nl> - __m128i RGs = z , GRs = z , Bs = z , ng = z ; <nl> - <nl> - __m128i x0 = _mm_loadl_u8_s16 ( srow , + 0 ) ; <nl> - __m128i x1 = _mm_loadl_u8_s16 ( srow , - 1 - bstep ) ; <nl> - __m128i x2 = _mm_loadl_u8_s16 ( srow , - 1 - bstep * 2 ) ; <nl> - __m128i x3 = _mm_loadl_u8_s16 ( srow , - bstep ) ; <nl> - __m128i x4 = _mm_loadl_u8_s16 ( srow , + 1 - bstep * 2 ) ; <nl> - __m128i x5 = _mm_loadl_u8_s16 ( srow , + 1 - bstep ) ; <nl> - __m128i x6 = _mm_loadl_u8_s16 ( srow , + 2 - bstep ) ; <nl> - __m128i x7 = _mm_loadl_u8_s16 ( srow , + 1 ) ; <nl> - __m128i x8 = _mm_loadl_u8_s16 ( srow , + 2 + bstep ) ; <nl> - __m128i x9 = _mm_loadl_u8_s16 ( srow , + 1 + bstep ) ; <nl> - __m128i x10 = _mm_loadl_u8_s16 ( srow , + 1 + bstep * 2 ) ; <nl> - __m128i x11 = _mm_loadl_u8_s16 ( srow , + bstep ) ; <nl> - __m128i x12 = _mm_loadl_u8_s16 ( srow , - 1 + bstep * 2 ) ; <nl> - __m128i x13 = _mm_loadl_u8_s16 ( srow , - 1 + bstep ) ; <nl> - __m128i x14 = _mm_loadl_u8_s16 ( srow , - 2 + bstep ) ; <nl> - __m128i x15 = _mm_loadl_u8_s16 ( srow , - 1 ) ; <nl> - __m128i x16 = _mm_loadl_u8_s16 ( srow , - 2 - bstep ) ; <nl> - <nl> - __m128i t0 , t1 , mask ; <nl> - <nl> - / / gradN * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradN ) ; / / mask = T > gradN <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradN ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x3 , 1 ) ; / / srow [ - bstep ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 ) , x0 ) ; / / srow [ - bstep * 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = ( srow [ - bstep * 2 ] + srow [ 0 ] ) * ( T > gradN ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> - / / GRs + = { srow [ - bstep ] * 2 ; ( srow [ - bstep * 2 - 1 ] + srow [ - bstep * 2 + 1 ] ) } * ( T > gradN ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x2 , x4 ) ) , mask ) ) ; <nl> - / / Bs + = { ( srow [ - bstep - 1 ] + srow [ - bstep + 1 ] ) ; srow [ - bstep ] * 2 } * ( T > gradN ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x1 , x5 ) , t0 ) , mask ) ) ; <nl> - <nl> - / / gradNE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradNE ) ; / / mask = T > gradNE <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradNE ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x5 , 1 ) ; / / srow [ - bstep + 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 + 2 ) , x0 ) ; / / srow [ - bstep * 2 + 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = { ( srow [ - bstep * 2 + 2 ] + srow [ 0 ] ) ; srow [ - bstep + 1 ] * 2 } * ( T > gradNE ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> - / / GRs + = { brow0 [ N6 + 1 ] ; ( srow [ - bstep * 2 + 1 ] + srow [ 1 ] ) } * ( T > gradNE ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N6 + 1 ) ) , _mm_adds_epi16 ( x4 , x7 ) ) , mask ) ) ; <nl> - / / Bs + = { srow [ - bstep + 1 ] * 2 ; ( srow [ - bstep ] + srow [ - bstep + 2 ] ) } * ( T > gradNE ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x3 , x6 ) ) , mask ) ) ; <nl> - <nl> - / / gradE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradE ) ; / / mask = T > gradE <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradE ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x7 , 1 ) ; / / srow [ 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , 2 ) , x0 ) ; / / srow [ 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = ( srow [ 2 ] + srow [ 0 ] ) * ( T > gradE ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> - / / GRs + = ( srow [ 1 ] * 2 ) * ( T > gradE ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( t0 , mask ) ) ; <nl> - / / Bs + = { ( srow [ - bstep + 1 ] + srow [ bstep + 1 ] ) ; ( srow [ - bstep + 2 ] + srow [ bstep + 2 ] ) } * ( T > gradE ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x5 , x9 ) , _mm_adds_epi16 ( x6 , x8 ) ) , mask ) ) ; <nl> - <nl> - / / gradSE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradSE ) ; / / mask = T > gradSE <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradSE ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x9 , 1 ) ; / / srow [ bstep + 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 + 2 ) , x0 ) ; / / srow [ bstep * 2 + 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = { ( srow [ bstep * 2 + 2 ] + srow [ 0 ] ) ; srow [ bstep + 1 ] * 2 } * ( T > gradSE ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> - / / GRs + = { brow2 [ N6 + 1 ] ; ( srow [ 1 ] + srow [ bstep * 2 + 1 ] ) } * ( T > gradSE ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N6 + 1 ) ) , _mm_adds_epi16 ( x7 , x10 ) ) , mask ) ) ; <nl> - / / Bs + = { srow [ - bstep + 1 ] * 2 ; ( srow [ bstep + 2 ] + srow [ bstep ] ) } * ( T > gradSE ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_slli_epi16 ( x5 , 1 ) , _mm_adds_epi16 ( x8 , x11 ) ) , mask ) ) ; <nl> - <nl> - / / gradS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradS ) ; / / mask = T > gradS <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradS ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x11 , 1 ) ; / / srow [ bstep ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 ) , x0 ) ; / / srow [ bstep * 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = ( srow [ bstep * 2 ] + srow [ 0 ] ) * ( T > gradS ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> - / / GRs + = { srow [ bstep ] * 2 ; ( srow [ bstep * 2 + 1 ] + srow [ bstep * 2 - 1 ] ) } * ( T > gradS ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x10 , x12 ) ) , mask ) ) ; <nl> - / / Bs + = { ( srow [ bstep + 1 ] + srow [ bstep - 1 ] ) ; srow [ bstep ] * 2 } * ( T > gradS ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x9 , x13 ) , t0 ) , mask ) ) ; <nl> - <nl> - / / gradSW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradSW ) ; / / mask = T > gradSW <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradSW ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x13 , 1 ) ; / / srow [ bstep - 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 - 2 ) , x0 ) ; / / srow [ bstep * 2 - 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = { ( srow [ bstep * 2 - 2 ] + srow [ 0 ] ) ; srow [ bstep - 1 ] * 2 } * ( T > gradSW ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> - / / GRs + = { brow2 [ N6 - 1 ] ; ( srow [ bstep * 2 - 1 ] + srow [ - 1 ] ) } * ( T > gradSW ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N6 - 1 ) ) , _mm_adds_epi16 ( x12 , x15 ) ) , mask ) ) ; <nl> - / / Bs + = { srow [ bstep - 1 ] * 2 ; ( srow [ bstep ] + srow [ bstep - 2 ] ) } * ( T > gradSW ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x11 , x14 ) ) , mask ) ) ; <nl> - <nl> - / / gradW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradW ) ; / / mask = T > gradW <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradW ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x15 , 1 ) ; / / srow [ - 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - 2 ) , x0 ) ; / / srow [ - 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = ( srow [ - 2 ] + srow [ 0 ] ) * ( T > gradW ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> - / / GRs + = ( srow [ - 1 ] * 2 ) * ( T > gradW ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( t0 , mask ) ) ; <nl> - / / Bs + = { ( srow [ - bstep - 1 ] + srow [ bstep - 1 ] ) ; ( srow [ bstep - 2 ] + srow [ - bstep - 2 ] ) } * ( T > gradW ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x1 , x13 ) , _mm_adds_epi16 ( x14 , x16 ) ) , mask ) ) ; <nl> - <nl> - / / gradNW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> - mask = _mm_cmpgt_epi16 ( T , gradNW ) ; / / mask = T > gradNW <nl> - ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradNW ) <nl> - <nl> - t0 = _mm_slli_epi16 ( x1 , 1 ) ; / / srow [ - bstep - 1 ] * 2 <nl> - t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 - 2 ) , x0 ) ; / / srow [ - bstep * 2 - 2 ] + srow [ 0 ] <nl> - <nl> - / / RGs + = { ( srow [ - bstep * 2 - 2 ] + srow [ 0 ] ) ; srow [ - bstep - 1 ] * 2 } * ( T > gradNW ) <nl> - RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> - / / GRs + = { brow0 [ N6 - 1 ] ; ( srow [ - bstep * 2 - 1 ] + srow [ - 1 ] ) } * ( T > gradNW ) <nl> - GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N6 - 1 ) ) , _mm_adds_epi16 ( x2 , x15 ) ) , mask ) ) ; <nl> - / / Bs + = { srow [ - bstep - 1 ] * 2 ; ( srow [ - bstep ] + srow [ - bstep - 2 ] ) } * ( T > gradNW ) <nl> - Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_slli_epi16 ( x5 , 1 ) , _mm_adds_epi16 ( x3 , x16 ) ) , mask ) ) ; <nl> - <nl> - __m128 ngf0 = _mm_div_ps ( _0_5 , _mm_cvtloepi16_ps ( ng ) ) ; <nl> - __m128 ngf1 = _mm_div_ps ( _0_5 , _mm_cvthiepi16_ps ( ng ) ) ; <nl> - <nl> - / / now interpolate r , g & b <nl> - t0 = _mm_subs_epi16 ( GRs , RGs ) ; <nl> - t1 = _mm_subs_epi16 ( Bs , RGs ) ; <nl> - <nl> - t0 = _mm_add_epi16 ( x0 , _mm_packs_epi32 ( <nl> - _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvtloepi16_ps ( t0 ) , ngf0 ) ) , <nl> - _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvthiepi16_ps ( t0 ) , ngf1 ) ) ) ) ; <nl> - <nl> - t1 = _mm_add_epi16 ( x0 , _mm_packs_epi32 ( <nl> - _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvtloepi16_ps ( t1 ) , ngf0 ) ) , <nl> - _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvthiepi16_ps ( t1 ) , ngf1 ) ) ) ) ; <nl> - <nl> - x1 = _mm_merge_epi16 ( x0 , t0 ) ; <nl> - x2 = _mm_merge_epi16 ( t0 , x0 ) ; <nl> - <nl> - uchar R [ 8 ] , G [ 8 ] , B [ 8 ] ; <nl> - <nl> - _mm_storel_epi64 ( blueIdx ? ( __m128i * ) B : ( __m128i * ) R , _mm_packus_epi16 ( x1 , z ) ) ; <nl> - _mm_storel_epi64 ( ( __m128i * ) G , _mm_packus_epi16 ( x2 , z ) ) ; <nl> - _mm_storel_epi64 ( blueIdx ? ( __m128i * ) R : ( __m128i * ) B , _mm_packus_epi16 ( t1 , z ) ) ; <nl> - <nl> - for ( int j = 0 ; j < 8 ; j + + , dstrow + = 3 ) <nl> - { <nl> - dstrow [ 0 ] = B [ j ] ; dstrow [ 1 ] = G [ j ] ; dstrow [ 2 ] = R [ j ] ; <nl> - } <nl> - } <nl> - # endif <nl> - <nl> - limit = N - 2 ; <nl> - } <nl> - while ( i < N - 2 ) ; <nl> - <nl> - for ( i = 0 ; i < 6 ; i + + ) <nl> - { <nl> - dst [ dststep * y + 5 - i ] = dst [ dststep * y + 8 - i ] ; <nl> - dst [ dststep * y + ( N - 2 ) * 3 + i ] = dst [ dststep * y + ( N - 3 ) * 3 + i ] ; <nl> - } <nl> - <nl> - greenCell0 = ! greenCell0 ; <nl> - blueIdx ^ = 2 ; <nl> - } <nl> - <nl> - for ( i = 0 ; i < size . width * 3 ; i + + ) <nl> - { <nl> - dst [ i ] = dst [ i + dststep ] = dst [ i + dststep * 2 ] ; <nl> - dst [ i + dststep * ( size . height - 4 ) ] = <nl> - dst [ i + dststep * ( size . height - 3 ) ] = <nl> - dst [ i + dststep * ( size . height - 2 ) ] = <nl> - dst [ i + dststep * ( size . height - 1 ) ] = dst [ i + dststep * ( size . height - 5 ) ] ; <nl> - } <nl> - } <nl> - <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / YUV420 - > RGB / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> const int ITUR_BT_601_CY = 1220542 ; <nl> void cv : : cvtColor ( InputArray _src , OutputArray _dst , int code , int dcn ) <nl> break ; <nl> <nl> case CV_BayerBG2GRAY : case CV_BayerGB2GRAY : case CV_BayerRG2GRAY : case CV_BayerGR2GRAY : <nl> - if ( dcn < = 0 ) dcn = 1 ; <nl> - CV_Assert ( scn = = 1 & & dcn = = 1 ) ; <nl> - <nl> - _dst . create ( sz , CV_MAKETYPE ( depth , dcn ) ) ; <nl> - dst = _dst . getMat ( ) ; <nl> - <nl> - if ( depth = = CV_8U ) <nl> - Bayer2Gray_ < uchar , SIMDBayerInterpolator_8u > ( src , dst , code ) ; <nl> - else if ( depth = = CV_16U ) <nl> - Bayer2Gray_ < ushort , SIMDBayerStubInterpolator_ < ushort > > ( src , dst , code ) ; <nl> - else <nl> - CV_Error ( CV_StsUnsupportedFormat , " Bayer - > Gray demosaicing only supports 8u and 16u types " ) ; <nl> - break ; <nl> - <nl> case CV_BayerBG2BGR : case CV_BayerGB2BGR : case CV_BayerRG2BGR : case CV_BayerGR2BGR : <nl> case CV_BayerBG2BGR_VNG : case CV_BayerGB2BGR_VNG : case CV_BayerRG2BGR_VNG : case CV_BayerGR2BGR_VNG : <nl> - { <nl> - if ( dcn < = 0 ) <nl> - dcn = 3 ; <nl> - CV_Assert ( scn = = 1 & & dcn = = 3 ) ; <nl> - <nl> - _dst . create ( sz , CV_MAKE_TYPE ( depth , dcn ) ) ; <nl> - Mat dst_ = _dst . getMat ( ) ; <nl> - <nl> - if ( code = = CV_BayerBG2BGR | | code = = CV_BayerGB2BGR | | <nl> - code = = CV_BayerRG2BGR | | code = = CV_BayerGR2BGR ) <nl> - { <nl> - if ( depth = = CV_8U ) <nl> - Bayer2RGB_ < uchar , SIMDBayerInterpolator_8u > ( src , dst_ , code ) ; <nl> - else if ( depth = = CV_16U ) <nl> - Bayer2RGB_ < ushort , SIMDBayerStubInterpolator_ < ushort > > ( src , dst_ , code ) ; <nl> - else <nl> - CV_Error ( CV_StsUnsupportedFormat , " Bayer - > RGB demosaicing only supports 8u and 16u types " ) ; <nl> - } <nl> - else <nl> - { <nl> - CV_Assert ( depth = = CV_8U ) ; <nl> - Bayer2RGB_VNG_8u ( src , dst_ , code ) ; <nl> - } <nl> - } <nl> + case CV_BayerBG2BGR_EA : case CV_BayerGB2BGR_EA : case CV_BayerRG2BGR_EA : case CV_BayerGR2BGR_EA : <nl> + demosaicing ( src , _dst , code , dcn ) ; <nl> break ; <nl> + <nl> case CV_YUV2BGR_NV21 : case CV_YUV2RGB_NV21 : case CV_YUV2BGR_NV12 : case CV_YUV2RGB_NV12 : <nl> case CV_YUV2BGRA_NV21 : case CV_YUV2RGBA_NV21 : case CV_YUV2BGRA_NV12 : case CV_YUV2RGBA_NV12 : <nl> { <nl> new file mode 100644 <nl> index 00000000000 . . d78f4fb0451 <nl> mmm / dev / null <nl> ppp b / modules / imgproc / src / demosaicing . cpp <nl> <nl> + / * M / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / <nl> + / / IMPORTANT : READ BEFORE DOWNLOADING , COPYING , INSTALLING OR USING . <nl> + / / <nl> + / / By downloading , copying , installing or using the software you agree to this license . <nl> + / / If you do not agree to this license , do not download , install , <nl> + / / copy or use the software . <nl> + / / <nl> + / / <nl> + / / License Agreement <nl> + / / For Open Source Computer Vision Library <nl> + / / <nl> + / / Copyright ( C ) 2000 - 2008 , Intel Corporation , all rights reserved . <nl> + / / Copyright ( C ) 2009 - 2010 , Willow Garage Inc . , all rights reserved . <nl> + / / Third party copyrights are property of their respective owners . <nl> + / / <nl> + / / Redistribution and use in source and binary forms , with or without modification , <nl> + / / are permitted provided that the following conditions are met : <nl> + / / <nl> + / / * Redistribution ' s of source code must retain the above copyright notice , <nl> + / / this list of conditions and the following disclaimer . <nl> + / / <nl> + / / * Redistribution ' s in binary form must reproduce the above copyright notice , <nl> + / / this list of conditions and the following disclaimer in the documentation <nl> + / / and / or other materials provided with the distribution . <nl> + / / <nl> + / / * The name of the copyright holders may not be used to endorse or promote products <nl> + / / derived from this software without specific prior written permission . <nl> + / / <nl> + / / This software is provided by the copyright holders and contributors " as is " and <nl> + / / any express or implied warranties , including , but not limited to , the implied <nl> + / / warranties of merchantability and fitness for a particular purpose are disclaimed . <nl> + / / In no event shall the Intel Corporation or contributors be liable for any direct , <nl> + / / indirect , incidental , special , exemplary , or consequential damages <nl> + / / ( including , but not limited to , procurement of substitute goods or services ; <nl> + / / loss of use , data , or profits ; or business interruption ) however caused <nl> + / / and on any theory of liability , whether in contract , strict liability , <nl> + / / or tort ( including negligence or otherwise ) arising in any way out of <nl> + / / the use of this software , even if advised of the possibility of such damage . <nl> + / / <nl> + / / M * / <nl> + <nl> + # include " precomp . hpp " <nl> + <nl> + # include < limits > <nl> + <nl> + namespace cv <nl> + { <nl> + <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / Bayer Pattern - > RGB conversion / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + template < typename T > <nl> + class SIMDBayerStubInterpolator_ <nl> + { <nl> + public : <nl> + int bayer2Gray ( const T * , int , T * , int , int , int , int ) const <nl> + { <nl> + return 0 ; <nl> + } <nl> + <nl> + int bayer2RGB ( const T * , int , T * , int , int ) const <nl> + { <nl> + return 0 ; <nl> + } <nl> + } ; <nl> + <nl> + # if CV_SSE2 <nl> + class SIMDBayerInterpolator_8u <nl> + { <nl> + public : <nl> + SIMDBayerInterpolator_8u ( ) <nl> + { <nl> + use_simd = checkHardwareSupport ( CV_CPU_SSE2 ) ; <nl> + } <nl> + <nl> + int bayer2Gray ( const uchar * bayer , int bayer_step , uchar * dst , <nl> + int width , int bcoeff , int gcoeff , int rcoeff ) const <nl> + { <nl> + if ( ! use_simd ) <nl> + return 0 ; <nl> + <nl> + __m128i _b2y = _mm_set1_epi16 ( ( short ) ( rcoeff * 2 ) ) ; <nl> + __m128i _g2y = _mm_set1_epi16 ( ( short ) ( gcoeff * 2 ) ) ; <nl> + __m128i _r2y = _mm_set1_epi16 ( ( short ) ( bcoeff * 2 ) ) ; <nl> + const uchar * bayer_end = bayer + width ; <nl> + <nl> + for ( ; bayer < = bayer_end - 18 ; bayer + = 14 , dst + = 14 ) <nl> + { <nl> + __m128i r0 = _mm_loadu_si128 ( ( const __m128i * ) bayer ) ; <nl> + __m128i r1 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step ) ) ; <nl> + __m128i r2 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step * 2 ) ) ; <nl> + <nl> + __m128i b1 = _mm_add_epi16 ( _mm_srli_epi16 ( _mm_slli_epi16 ( r0 , 8 ) , 7 ) , <nl> + _mm_srli_epi16 ( _mm_slli_epi16 ( r2 , 8 ) , 7 ) ) ; <nl> + __m128i b0 = _mm_add_epi16 ( b1 , _mm_srli_si128 ( b1 , 2 ) ) ; <nl> + b1 = _mm_slli_epi16 ( _mm_srli_si128 ( b1 , 2 ) , 1 ) ; <nl> + <nl> + __m128i g0 = _mm_add_epi16 ( _mm_srli_epi16 ( r0 , 7 ) , _mm_srli_epi16 ( r2 , 7 ) ) ; <nl> + __m128i g1 = _mm_srli_epi16 ( _mm_slli_epi16 ( r1 , 8 ) , 7 ) ; <nl> + g0 = _mm_add_epi16 ( g0 , _mm_add_epi16 ( g1 , _mm_srli_si128 ( g1 , 2 ) ) ) ; <nl> + g1 = _mm_slli_epi16 ( _mm_srli_si128 ( g1 , 2 ) , 2 ) ; <nl> + <nl> + r0 = _mm_srli_epi16 ( r1 , 8 ) ; <nl> + r1 = _mm_slli_epi16 ( _mm_add_epi16 ( r0 , _mm_srli_si128 ( r0 , 2 ) ) , 2 ) ; <nl> + r0 = _mm_slli_epi16 ( r0 , 3 ) ; <nl> + <nl> + g0 = _mm_add_epi16 ( _mm_mulhi_epi16 ( b0 , _b2y ) , _mm_mulhi_epi16 ( g0 , _g2y ) ) ; <nl> + g1 = _mm_add_epi16 ( _mm_mulhi_epi16 ( b1 , _b2y ) , _mm_mulhi_epi16 ( g1 , _g2y ) ) ; <nl> + g0 = _mm_add_epi16 ( g0 , _mm_mulhi_epi16 ( r0 , _r2y ) ) ; <nl> + g1 = _mm_add_epi16 ( g1 , _mm_mulhi_epi16 ( r1 , _r2y ) ) ; <nl> + g0 = _mm_srli_epi16 ( g0 , 2 ) ; <nl> + g1 = _mm_srli_epi16 ( g1 , 2 ) ; <nl> + g0 = _mm_packus_epi16 ( g0 , g0 ) ; <nl> + g1 = _mm_packus_epi16 ( g1 , g1 ) ; <nl> + g0 = _mm_unpacklo_epi8 ( g0 , g1 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) dst , g0 ) ; <nl> + } <nl> + <nl> + return ( int ) ( bayer - ( bayer_end - width ) ) ; <nl> + } <nl> + <nl> + int bayer2RGB ( const uchar * bayer , int bayer_step , uchar * dst , int width , int blue ) const <nl> + { <nl> + if ( ! use_simd ) <nl> + return 0 ; <nl> + / * <nl> + B G B G | B G B G | B G B G | B G B G <nl> + G R G R | G R G R | G R G R | G R G R <nl> + B G B G | B G B G | B G B G | B G B G <nl> + * / <nl> + __m128i delta1 = _mm_set1_epi16 ( 1 ) , delta2 = _mm_set1_epi16 ( 2 ) ; <nl> + __m128i mask = _mm_set1_epi16 ( blue < 0 ? - 1 : 0 ) , z = _mm_setzero_si128 ( ) ; <nl> + __m128i masklo = _mm_set1_epi16 ( 0x00ff ) ; <nl> + const uchar * bayer_end = bayer + width ; <nl> + <nl> + for ( ; bayer < = bayer_end - 18 ; bayer + = 14 , dst + = 42 ) <nl> + { <nl> + __m128i r0 = _mm_loadu_si128 ( ( const __m128i * ) bayer ) ; <nl> + __m128i r1 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step ) ) ; <nl> + __m128i r2 = _mm_loadu_si128 ( ( const __m128i * ) ( bayer + bayer_step * 2 ) ) ; <nl> + <nl> + __m128i b1 = _mm_add_epi16 ( _mm_and_si128 ( r0 , masklo ) , _mm_and_si128 ( r2 , masklo ) ) ; <nl> + __m128i b0 = _mm_add_epi16 ( b1 , _mm_srli_si128 ( b1 , 2 ) ) ; <nl> + b1 = _mm_srli_si128 ( b1 , 2 ) ; <nl> + b1 = _mm_srli_epi16 ( _mm_add_epi16 ( b1 , delta1 ) , 1 ) ; <nl> + b0 = _mm_srli_epi16 ( _mm_add_epi16 ( b0 , delta2 ) , 2 ) ; <nl> + b0 = _mm_packus_epi16 ( b0 , b1 ) ; <nl> + <nl> + __m128i g0 = _mm_add_epi16 ( _mm_srli_epi16 ( r0 , 8 ) , _mm_srli_epi16 ( r2 , 8 ) ) ; <nl> + __m128i g1 = _mm_and_si128 ( r1 , masklo ) ; <nl> + g0 = _mm_add_epi16 ( g0 , _mm_add_epi16 ( g1 , _mm_srli_si128 ( g1 , 2 ) ) ) ; <nl> + g1 = _mm_srli_si128 ( g1 , 2 ) ; <nl> + g0 = _mm_srli_epi16 ( _mm_add_epi16 ( g0 , delta2 ) , 2 ) ; <nl> + g0 = _mm_packus_epi16 ( g0 , g1 ) ; <nl> + <nl> + r0 = _mm_srli_epi16 ( r1 , 8 ) ; <nl> + r1 = _mm_add_epi16 ( r0 , _mm_srli_si128 ( r0 , 2 ) ) ; <nl> + r1 = _mm_srli_epi16 ( _mm_add_epi16 ( r1 , delta1 ) , 1 ) ; <nl> + r0 = _mm_packus_epi16 ( r0 , r1 ) ; <nl> + <nl> + b1 = _mm_and_si128 ( _mm_xor_si128 ( b0 , r0 ) , mask ) ; <nl> + b0 = _mm_xor_si128 ( b0 , b1 ) ; <nl> + r0 = _mm_xor_si128 ( r0 , b1 ) ; <nl> + <nl> + / / b1 g1 b1 g1 . . . <nl> + b1 = _mm_unpackhi_epi8 ( b0 , g0 ) ; <nl> + / / b0 g0 b2 g2 b4 g4 . . . . <nl> + b0 = _mm_unpacklo_epi8 ( b0 , g0 ) ; <nl> + <nl> + / / r1 0 r3 0 . . . <nl> + r1 = _mm_unpackhi_epi8 ( r0 , z ) ; <nl> + / / r0 0 r2 0 r4 0 . . . <nl> + r0 = _mm_unpacklo_epi8 ( r0 , z ) ; <nl> + <nl> + / / 0 b0 g0 r0 0 b2 g2 r2 0 . . . <nl> + g0 = _mm_slli_si128 ( _mm_unpacklo_epi16 ( b0 , r0 ) , 1 ) ; <nl> + / / 0 b8 g8 r8 0 b10 g10 r10 0 . . . <nl> + g1 = _mm_slli_si128 ( _mm_unpackhi_epi16 ( b0 , r0 ) , 1 ) ; <nl> + <nl> + / / b1 g1 r1 0 b3 g3 r3 . . . . <nl> + r0 = _mm_unpacklo_epi16 ( b1 , r1 ) ; <nl> + / / b9 g9 r9 0 . . . <nl> + r1 = _mm_unpackhi_epi16 ( b1 , r1 ) ; <nl> + <nl> + b0 = _mm_srli_si128 ( _mm_unpacklo_epi32 ( g0 , r0 ) , 1 ) ; <nl> + b1 = _mm_srli_si128 ( _mm_unpackhi_epi32 ( g0 , r0 ) , 1 ) ; <nl> + <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 0 ) , b0 ) ; <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 1 ) , _mm_srli_si128 ( b0 , 8 ) ) ; <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 2 ) , b1 ) ; <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 3 ) , _mm_srli_si128 ( b1 , 8 ) ) ; <nl> + <nl> + g0 = _mm_srli_si128 ( _mm_unpacklo_epi32 ( g1 , r1 ) , 1 ) ; <nl> + g1 = _mm_srli_si128 ( _mm_unpackhi_epi32 ( g1 , r1 ) , 1 ) ; <nl> + <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 4 ) , g0 ) ; <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 5 ) , _mm_srli_si128 ( g0 , 8 ) ) ; <nl> + <nl> + _mm_storel_epi64 ( ( __m128i * ) ( dst - 1 + 6 * 6 ) , g1 ) ; <nl> + } <nl> + <nl> + return ( int ) ( bayer - ( bayer_end - width ) ) ; <nl> + } <nl> + <nl> + bool use_simd ; <nl> + } ; <nl> + # else <nl> + typedef SIMDBayerStubInterpolator_ < uchar > SIMDBayerInterpolator_8u ; <nl> + # endif <nl> + <nl> + template < typename T , class SIMDInterpolator > <nl> + static void Bayer2Gray_ ( const Mat & srcmat , Mat & dstmat , int code ) <nl> + { <nl> + SIMDInterpolator vecOp ; <nl> + const int R2Y = 4899 ; <nl> + const int G2Y = 9617 ; <nl> + const int B2Y = 1868 ; <nl> + const int SHIFT = 14 ; <nl> + <nl> + const T * bayer0 = ( const T * ) srcmat . data ; <nl> + int bayer_step = ( int ) ( srcmat . step / sizeof ( T ) ) ; <nl> + T * dst0 = ( T * ) dstmat . data ; <nl> + int dst_step = ( int ) ( dstmat . step / sizeof ( T ) ) ; <nl> + Size size = srcmat . size ( ) ; <nl> + int bcoeff = B2Y , rcoeff = R2Y ; <nl> + int start_with_green = code = = CV_BayerGB2GRAY | | code = = CV_BayerGR2GRAY ; <nl> + bool brow = true ; <nl> + <nl> + if ( code ! = CV_BayerBG2GRAY & & code ! = CV_BayerGB2GRAY ) <nl> + { <nl> + brow = false ; <nl> + std : : swap ( bcoeff , rcoeff ) ; <nl> + } <nl> + <nl> + dst0 + = dst_step + 1 ; <nl> + size . height - = 2 ; <nl> + size . width - = 2 ; <nl> + <nl> + for ( ; size . height - - > 0 ; bayer0 + = bayer_step , dst0 + = dst_step ) <nl> + { <nl> + unsigned t0 , t1 , t2 ; <nl> + const T * bayer = bayer0 ; <nl> + T * dst = dst0 ; <nl> + const T * bayer_end = bayer + size . width ; <nl> + <nl> + if ( size . width < = 0 ) <nl> + { <nl> + dst [ - 1 ] = dst [ size . width ] = 0 ; <nl> + continue ; <nl> + } <nl> + <nl> + if ( start_with_green ) <nl> + { <nl> + t0 = ( bayer [ 1 ] + bayer [ bayer_step * 2 + 1 ] ) * rcoeff ; <nl> + t1 = ( bayer [ bayer_step ] + bayer [ bayer_step + 2 ] ) * bcoeff ; <nl> + t2 = bayer [ bayer_step + 1 ] * ( 2 * G2Y ) ; <nl> + <nl> + dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 1 ) ; <nl> + bayer + + ; <nl> + dst + + ; <nl> + } <nl> + <nl> + int delta = vecOp . bayer2Gray ( bayer , bayer_step , dst , size . width , bcoeff , G2Y , rcoeff ) ; <nl> + bayer + = delta ; <nl> + dst + = delta ; <nl> + <nl> + for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = 2 ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] ) * G2Y ; <nl> + t2 = bayer [ bayer_step + 1 ] * ( 4 * bcoeff ) ; <nl> + dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 2 ) ; <nl> + <nl> + t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> + t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] ) * bcoeff ; <nl> + t2 = bayer [ bayer_step + 2 ] * ( 2 * G2Y ) ; <nl> + dst [ 1 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 1 ) ; <nl> + } <nl> + <nl> + if ( bayer < bayer_end ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + bayer [ bayer_step * 2 + 2 ] ) * rcoeff ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] ) * G2Y ; <nl> + t2 = bayer [ bayer_step + 1 ] * ( 4 * bcoeff ) ; <nl> + dst [ 0 ] = ( T ) CV_DESCALE ( t0 + t1 + t2 , SHIFT + 2 ) ; <nl> + bayer + + ; <nl> + dst + + ; <nl> + } <nl> + <nl> + dst0 [ - 1 ] = dst0 [ 0 ] ; <nl> + dst0 [ size . width ] = dst0 [ size . width - 1 ] ; <nl> + <nl> + brow = ! brow ; <nl> + std : : swap ( bcoeff , rcoeff ) ; <nl> + start_with_green = ! start_with_green ; <nl> + } <nl> + <nl> + size = dstmat . size ( ) ; <nl> + dst0 = ( T * ) dstmat . data ; <nl> + if ( size . height > 2 ) <nl> + for ( int i = 0 ; i < size . width ; i + + ) <nl> + { <nl> + dst0 [ i ] = dst0 [ i + dst_step ] ; <nl> + dst0 [ i + ( size . height - 1 ) * dst_step ] = dst0 [ i + ( size . height - 2 ) * dst_step ] ; <nl> + } <nl> + else <nl> + for ( int i = 0 ; i < size . width ; i + + ) <nl> + { <nl> + dst0 [ i ] = dst0 [ i + ( size . height - 1 ) * dst_step ] = 0 ; <nl> + } <nl> + } <nl> + <nl> + template < typename T , typename SIMDInterpolator > <nl> + class Bayer2RGB_Invoker : <nl> + public ParallelLoopBody <nl> + { <nl> + public : <nl> + Bayer2RGB_Invoker ( const Mat & _srcmat , Mat & _dstmat , int _start_with_green , int _blue , const Size & _size ) : <nl> + srcmat ( _srcmat ) , dstmat ( _dstmat ) , Start_with_green ( _start_with_green ) , Blue ( _blue ) , size ( _size ) <nl> + { <nl> + } <nl> + <nl> + virtual void operator ( ) ( const Range & range ) const <nl> + { <nl> + SIMDInterpolator vecOp ; <nl> + const T * bayer0 = ( const T * ) srcmat . data ; <nl> + int bayer_step = ( int ) ( srcmat . step / sizeof ( T ) ) ; <nl> + <nl> + T * dst0 = ( T * ) dstmat . data ; <nl> + int dst_step = ( int ) ( dstmat . step / sizeof ( T ) ) ; <nl> + <nl> + int blue = Blue , start_with_green = Start_with_green ; <nl> + int alpha = std : : numeric_limits < T > : : max ( ) ; <nl> + if ( range . start % 2 ) <nl> + { <nl> + blue = - blue ; <nl> + start_with_green = ! start_with_green ; <nl> + } <nl> + <nl> + int dcn = dstmat . channels ( ) ; <nl> + dst0 + = dst_step + dcn + 1 ; <nl> + int dcn2 = dcn < < 1 ; <nl> + <nl> + dst0 + = dst_step * range . start ; <nl> + bayer0 + = bayer_step * range . start ; <nl> + <nl> + for ( int i = range . start ; i < range . end ; bayer0 + = bayer_step , dst0 + = dst_step , + + i ) <nl> + { <nl> + int t0 , t1 ; <nl> + const T * bayer = bayer0 ; <nl> + T * dst = dst0 ; <nl> + const T * bayer_end = bayer + size . width ; <nl> + <nl> + / / in case of when size . width < = 2 <nl> + if ( size . width < = 0 ) <nl> + { <nl> + / / ? <nl> + dst [ - 4 ] = dst [ - 3 ] = dst [ - 2 ] = dst [ size . width * 3 - 1 ] = <nl> + dst [ size . width * 3 ] = dst [ size . width * 3 + 1 ] = 0 ; <nl> + continue ; <nl> + } <nl> + <nl> + if ( start_with_green ) <nl> + { <nl> + t0 = ( bayer [ 1 ] + bayer [ bayer_step * 2 + 1 ] + 1 ) > > 1 ; <nl> + t1 = ( bayer [ bayer_step ] + bayer [ bayer_step + 2 ] + 1 ) > > 1 ; <nl> + <nl> + dst [ - blue ] = ( T ) t0 ; <nl> + dst [ 0 ] = bayer [ bayer_step + 1 ] ; <nl> + dst [ blue ] = ( T ) t1 ; <nl> + if ( dcn = = 4 ) <nl> + dst [ 2 ] = alpha ; / / alpha channel <nl> + <nl> + bayer + + ; <nl> + dst + = dcn ; <nl> + } <nl> + <nl> + / / simd optimization only for dcn = = 3 <nl> + int delta = dcn = = 4 ? 0 : vecOp . bayer2RGB ( bayer , bayer_step , dst , size . width , blue ) ; <nl> + bayer + = delta ; <nl> + dst + = delta * dcn ; <nl> + <nl> + if ( dcn = = 3 ) / / Bayer to BGR <nl> + { <nl> + if ( blue > 0 ) <nl> + { <nl> + for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = dcn2 ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> + bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> + dst [ - 1 ] = ( T ) t0 ; <nl> + dst [ 0 ] = ( T ) t1 ; <nl> + dst [ 1 ] = bayer [ bayer_step + 1 ] ; <nl> + <nl> + t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> + t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> + dst [ 2 ] = ( T ) t0 ; <nl> + dst [ 3 ] = bayer [ bayer_step + 2 ] ; <nl> + dst [ 4 ] = ( T ) t1 ; <nl> + } <nl> + } <nl> + else <nl> + { <nl> + for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = dcn2 ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> + bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> + dst [ 1 ] = ( T ) t0 ; <nl> + dst [ 0 ] = ( T ) t1 ; <nl> + dst [ - 1 ] = bayer [ bayer_step + 1 ] ; <nl> + <nl> + t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> + t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> + dst [ 4 ] = ( T ) t0 ; <nl> + dst [ 3 ] = bayer [ bayer_step + 2 ] ; <nl> + dst [ 2 ] = ( T ) t1 ; <nl> + } <nl> + } <nl> + } <nl> + else / / Bayer to BGRA <nl> + { <nl> + / / if current row does not contain Blue pixels <nl> + if ( blue > 0 ) <nl> + { <nl> + for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = dcn2 ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> + bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> + dst [ - 1 ] = ( T ) t0 ; <nl> + dst [ 0 ] = ( T ) t1 ; <nl> + dst [ 1 ] = bayer [ bayer_step + 1 ] ; <nl> + dst [ 2 ] = alpha ; / / alpha channel <nl> + <nl> + t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> + t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> + dst [ 3 ] = ( T ) t0 ; <nl> + dst [ 4 ] = bayer [ bayer_step + 2 ] ; <nl> + dst [ 5 ] = ( T ) t1 ; <nl> + dst [ 6 ] = alpha ; / / alpha channel <nl> + } <nl> + } <nl> + else / / if current row contains Blue pixels <nl> + { <nl> + for ( ; bayer < = bayer_end - 2 ; bayer + = 2 , dst + = dcn2 ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> + bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> + dst [ - 1 ] = bayer [ bayer_step + 1 ] ; <nl> + dst [ 0 ] = ( T ) t1 ; <nl> + dst [ 1 ] = ( T ) t0 ; <nl> + dst [ 2 ] = alpha ; / / alpha channel <nl> + <nl> + t0 = ( bayer [ 2 ] + bayer [ bayer_step * 2 + 2 ] + 1 ) > > 1 ; <nl> + t1 = ( bayer [ bayer_step + 1 ] + bayer [ bayer_step + 3 ] + 1 ) > > 1 ; <nl> + dst [ 3 ] = ( T ) t1 ; <nl> + dst [ 4 ] = bayer [ bayer_step + 2 ] ; <nl> + dst [ 5 ] = ( T ) t0 ; <nl> + dst [ 6 ] = alpha ; / / alpha channel <nl> + } <nl> + } <nl> + } <nl> + <nl> + / / if skip one pixel at the end of row <nl> + if ( bayer < bayer_end ) <nl> + { <nl> + t0 = ( bayer [ 0 ] + bayer [ 2 ] + bayer [ bayer_step * 2 ] + <nl> + bayer [ bayer_step * 2 + 2 ] + 2 ) > > 2 ; <nl> + t1 = ( bayer [ 1 ] + bayer [ bayer_step ] + <nl> + bayer [ bayer_step + 2 ] + bayer [ bayer_step * 2 + 1 ] + 2 ) > > 2 ; <nl> + dst [ - blue ] = ( T ) t0 ; <nl> + dst [ 0 ] = ( T ) t1 ; <nl> + dst [ blue ] = bayer [ bayer_step + 1 ] ; <nl> + if ( dcn = = 4 ) <nl> + dst [ 2 ] = alpha ; / / alpha channel <nl> + bayer + + ; <nl> + dst + = dcn ; <nl> + } <nl> + <nl> + / / fill the last and the first pixels of row accordingly <nl> + if ( dcn = = 3 ) <nl> + { <nl> + dst0 [ - 4 ] = dst0 [ - 1 ] ; <nl> + dst0 [ - 3 ] = dst0 [ 0 ] ; <nl> + dst0 [ - 2 ] = dst0 [ 1 ] ; <nl> + dst0 [ size . width * dcn - 1 ] = dst0 [ size . width * dcn - 4 ] ; <nl> + dst0 [ size . width * dcn ] = dst0 [ size . width * dcn - 3 ] ; <nl> + dst0 [ size . width * dcn + 1 ] = dst0 [ size . width * dcn - 2 ] ; <nl> + } <nl> + else <nl> + { <nl> + dst0 [ - 5 ] = dst0 [ - 1 ] ; <nl> + dst0 [ - 4 ] = dst0 [ 0 ] ; <nl> + dst0 [ - 3 ] = dst0 [ 1 ] ; <nl> + dst0 [ - 2 ] = dst0 [ 2 ] ; / / alpha channel <nl> + dst0 [ size . width * dcn - 1 ] = dst0 [ size . width * dcn - 5 ] ; <nl> + dst0 [ size . width * dcn ] = dst0 [ size . width * dcn - 4 ] ; <nl> + dst0 [ size . width * dcn + 1 ] = dst0 [ size . width * dcn - 3 ] ; <nl> + dst0 [ size . width * dcn + 2 ] = dst0 [ size . width * dcn - 2 ] ; / / alpha channel <nl> + } <nl> + <nl> + blue = - blue ; <nl> + start_with_green = ! start_with_green ; <nl> + } <nl> + } <nl> + <nl> + public : <nl> + const Mat srcmat ; <nl> + Mat dstmat ; <nl> + int Start_with_green , Blue ; <nl> + const Size size ; <nl> + } ; <nl> + <nl> + template < typename T , class SIMDInterpolator > <nl> + static void Bayer2RGB_ ( const Mat & srcmat , Mat & dstmat , int code ) <nl> + { <nl> + int dst_step = ( int ) ( dstmat . step / sizeof ( T ) ) ; <nl> + Size size = srcmat . size ( ) ; <nl> + int blue = code = = CV_BayerBG2BGR | | code = = CV_BayerGB2BGR ? - 1 : 1 ; <nl> + int start_with_green = code = = CV_BayerGB2BGR | | code = = CV_BayerGR2BGR ; <nl> + <nl> + int dcn = dstmat . channels ( ) ; <nl> + size . height - = 2 ; <nl> + size . width - = 2 ; <nl> + <nl> + Range range ( 0 , size . height ) ; <nl> + Bayer2RGB_Invoker < T , SIMDInterpolator > invoker ( srcmat , dstmat , start_with_green , blue , size ) ; <nl> + <nl> + parallel_for_ ( range , invoker ) ; <nl> + <nl> + / / filling the first and the last rows <nl> + size = dstmat . size ( ) ; <nl> + T * dst0 = ( T * ) dstmat . data ; <nl> + if ( size . height > 2 ) <nl> + for ( int i = 0 ; i < size . width * dcn ; i + + ) <nl> + { <nl> + dst0 [ i ] = dst0 [ i + dst_step ] ; <nl> + dst0 [ i + ( size . height - 1 ) * dst_step ] = dst0 [ i + ( size . height - 2 ) * dst_step ] ; <nl> + } <nl> + else <nl> + for ( int i = 0 ; i < size . width * dcn ; i + + ) <nl> + dst0 [ i ] = dst0 [ i + ( size . height - 1 ) * dst_step ] = 0 ; <nl> + } <nl> + <nl> + <nl> + / / / / / / / / / / / / / / / / / / / Demosaicing using Variable Number of Gradients / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + static void Bayer2RGB_VNG_8u ( const Mat & srcmat , Mat & dstmat , int code ) <nl> + { <nl> + const uchar * bayer = srcmat . data ; <nl> + int bstep = ( int ) srcmat . step ; <nl> + uchar * dst = dstmat . data ; <nl> + int dststep = ( int ) dstmat . step ; <nl> + Size size = srcmat . size ( ) ; <nl> + <nl> + int blueIdx = code = = CV_BayerBG2BGR_VNG | | code = = CV_BayerGB2BGR_VNG ? 0 : 2 ; <nl> + bool greenCell0 = code ! = CV_BayerBG2BGR_VNG & & code ! = CV_BayerRG2BGR_VNG ; <nl> + <nl> + / / for too small images use the simple interpolation algorithm <nl> + if ( MIN ( size . width , size . height ) < 8 ) <nl> + { <nl> + Bayer2RGB_ < uchar , SIMDBayerInterpolator_8u > ( srcmat , dstmat , code ) ; <nl> + return ; <nl> + } <nl> + <nl> + const int brows = 3 , bcn = 7 ; <nl> + int N = size . width , N2 = N * 2 , N3 = N * 3 , N4 = N * 4 , N5 = N * 5 , N6 = N * 6 , N7 = N * 7 ; <nl> + int i , bufstep = N7 * bcn ; <nl> + cv : : AutoBuffer < ushort > _buf ( bufstep * brows ) ; <nl> + ushort * buf = ( ushort * ) _buf ; <nl> + <nl> + bayer + = bstep * 2 ; <nl> + <nl> + # if CV_SSE2 <nl> + bool haveSSE = cv : : checkHardwareSupport ( CV_CPU_SSE2 ) ; <nl> + # define _mm_absdiff_epu16 ( a , b ) _mm_adds_epu16 ( _mm_subs_epu16 ( a , b ) , _mm_subs_epu16 ( b , a ) ) <nl> + # endif <nl> + <nl> + for ( int y = 2 ; y < size . height - 4 ; y + + ) <nl> + { <nl> + uchar * dstrow = dst + dststep * y + 6 ; <nl> + const uchar * srow ; <nl> + <nl> + for ( int dy = ( y = = 2 ? - 1 : 1 ) ; dy < = 1 ; dy + + ) <nl> + { <nl> + ushort * brow = buf + ( ( y + dy - 1 ) % brows ) * bufstep + 1 ; <nl> + srow = bayer + ( y + dy ) * bstep + 1 ; <nl> + <nl> + for ( i = 0 ; i < bcn ; i + + ) <nl> + brow [ N * i - 1 ] = brow [ ( N - 2 ) + N * i ] = 0 ; <nl> + <nl> + i = 1 ; <nl> + <nl> + # if CV_SSE2 <nl> + if ( haveSSE ) <nl> + { <nl> + __m128i z = _mm_setzero_si128 ( ) ; <nl> + for ( ; i < = N - 9 ; i + = 8 , srow + = 8 , brow + = 8 ) <nl> + { <nl> + __m128i s1 , s2 , s3 , s4 , s6 , s7 , s8 , s9 ; <nl> + <nl> + s1 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 - bstep ) ) , z ) ; <nl> + s2 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - bstep ) ) , z ) ; <nl> + s3 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 - bstep ) ) , z ) ; <nl> + <nl> + s4 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 ) ) , z ) ; <nl> + s6 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 ) ) , z ) ; <nl> + <nl> + s7 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow - 1 + bstep ) ) , z ) ; <nl> + s8 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + bstep ) ) , z ) ; <nl> + s9 = _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( srow + 1 + bstep ) ) , z ) ; <nl> + <nl> + __m128i b0 , b1 , b2 , b3 , b4 , b5 , b6 ; <nl> + <nl> + b0 = _mm_adds_epu16 ( _mm_slli_epi16 ( _mm_absdiff_epu16 ( s2 , s8 ) , 1 ) , <nl> + _mm_adds_epu16 ( _mm_absdiff_epu16 ( s1 , s7 ) , <nl> + _mm_absdiff_epu16 ( s3 , s9 ) ) ) ; <nl> + b1 = _mm_adds_epu16 ( _mm_slli_epi16 ( _mm_absdiff_epu16 ( s4 , s6 ) , 1 ) , <nl> + _mm_adds_epu16 ( _mm_absdiff_epu16 ( s1 , s3 ) , <nl> + _mm_absdiff_epu16 ( s7 , s9 ) ) ) ; <nl> + b2 = _mm_slli_epi16 ( _mm_absdiff_epu16 ( s3 , s7 ) , 1 ) ; <nl> + b3 = _mm_slli_epi16 ( _mm_absdiff_epu16 ( s1 , s9 ) , 1 ) ; <nl> + <nl> + _mm_storeu_si128 ( ( __m128i * ) brow , b0 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N ) , b1 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N2 ) , b2 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N3 ) , b3 ) ; <nl> + <nl> + b4 = _mm_adds_epu16 ( b2 , _mm_adds_epu16 ( _mm_absdiff_epu16 ( s2 , s4 ) , <nl> + _mm_absdiff_epu16 ( s6 , s8 ) ) ) ; <nl> + b5 = _mm_adds_epu16 ( b3 , _mm_adds_epu16 ( _mm_absdiff_epu16 ( s2 , s6 ) , <nl> + _mm_absdiff_epu16 ( s4 , s8 ) ) ) ; <nl> + b6 = _mm_adds_epu16 ( _mm_adds_epu16 ( s2 , s4 ) , _mm_adds_epu16 ( s6 , s8 ) ) ; <nl> + b6 = _mm_srli_epi16 ( b6 , 1 ) ; <nl> + <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N4 ) , b4 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N5 ) , b5 ) ; <nl> + _mm_storeu_si128 ( ( __m128i * ) ( brow + N6 ) , b6 ) ; <nl> + } <nl> + } <nl> + # endif <nl> + <nl> + for ( ; i < N - 1 ; i + + , srow + + , brow + + ) <nl> + { <nl> + brow [ 0 ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ - 1 + bstep ] ) + <nl> + std : : abs ( srow [ - bstep ] - srow [ + bstep ] ) * 2 + <nl> + std : : abs ( srow [ 1 - bstep ] - srow [ 1 + bstep ] ) ) ; <nl> + brow [ N ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ 1 - bstep ] ) + <nl> + std : : abs ( srow [ - 1 ] - srow [ 1 ] ) * 2 + <nl> + std : : abs ( srow [ - 1 + bstep ] - srow [ 1 + bstep ] ) ) ; <nl> + brow [ N2 ] = ( ushort ) ( std : : abs ( srow [ + 1 - bstep ] - srow [ - 1 + bstep ] ) * 2 ) ; <nl> + brow [ N3 ] = ( ushort ) ( std : : abs ( srow [ - 1 - bstep ] - srow [ 1 + bstep ] ) * 2 ) ; <nl> + brow [ N4 ] = ( ushort ) ( brow [ N2 ] + std : : abs ( srow [ - bstep ] - srow [ - 1 ] ) + <nl> + std : : abs ( srow [ + bstep ] - srow [ 1 ] ) ) ; <nl> + brow [ N5 ] = ( ushort ) ( brow [ N3 ] + std : : abs ( srow [ - bstep ] - srow [ 1 ] ) + <nl> + std : : abs ( srow [ + bstep ] - srow [ - 1 ] ) ) ; <nl> + brow [ N6 ] = ( ushort ) ( ( srow [ - bstep ] + srow [ - 1 ] + srow [ 1 ] + srow [ + bstep ] ) > > 1 ) ; <nl> + } <nl> + } <nl> + <nl> + const ushort * brow0 = buf + ( ( y - 2 ) % brows ) * bufstep + 2 ; <nl> + const ushort * brow1 = buf + ( ( y - 1 ) % brows ) * bufstep + 2 ; <nl> + const ushort * brow2 = buf + ( y % brows ) * bufstep + 2 ; <nl> + static const float scale [ ] = { 0 . f , 0 . 5f , 0 . 25f , 0 . 1666666666667f , 0 . 125f , 0 . 1f , 0 . 08333333333f , 0 . 0714286f , 0 . 0625f } ; <nl> + srow = bayer + y * bstep + 2 ; <nl> + bool greenCell = greenCell0 ; <nl> + <nl> + i = 2 ; <nl> + # if CV_SSE2 <nl> + int limit = ! haveSSE ? N - 2 : greenCell ? std : : min ( 3 , N - 2 ) : 2 ; <nl> + # else <nl> + int limit = N - 2 ; <nl> + # endif <nl> + <nl> + do <nl> + { <nl> + for ( ; i < limit ; i + + , srow + + , brow0 + + , brow1 + + , brow2 + + , dstrow + = 3 ) <nl> + { <nl> + int gradN = brow0 [ 0 ] + brow1 [ 0 ] ; <nl> + int gradS = brow1 [ 0 ] + brow2 [ 0 ] ; <nl> + int gradW = brow1 [ N - 1 ] + brow1 [ N ] ; <nl> + int gradE = brow1 [ N ] + brow1 [ N + 1 ] ; <nl> + int minGrad = std : : min ( std : : min ( std : : min ( gradN , gradS ) , gradW ) , gradE ) ; <nl> + int maxGrad = std : : max ( std : : max ( std : : max ( gradN , gradS ) , gradW ) , gradE ) ; <nl> + int R , G , B ; <nl> + <nl> + if ( ! greenCell ) <nl> + { <nl> + int gradNE = brow0 [ N4 + 1 ] + brow1 [ N4 ] ; <nl> + int gradSW = brow1 [ N4 ] + brow2 [ N4 - 1 ] ; <nl> + int gradNW = brow0 [ N5 - 1 ] + brow1 [ N5 ] ; <nl> + int gradSE = brow1 [ N5 ] + brow2 [ N5 + 1 ] ; <nl> + <nl> + minGrad = std : : min ( std : : min ( std : : min ( std : : min ( minGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> + maxGrad = std : : max ( std : : max ( std : : max ( std : : max ( maxGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> + int T = minGrad + MAX ( maxGrad / 2 , 1 ) ; <nl> + <nl> + int Rs = 0 , Gs = 0 , Bs = 0 , ng = 0 ; <nl> + if ( gradN < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 ] + srow [ 0 ] ; <nl> + Gs + = srow [ - bstep ] * 2 ; <nl> + Bs + = srow [ - bstep - 1 ] + srow [ - bstep + 1 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradS < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 ] + srow [ 0 ] ; <nl> + Gs + = srow [ bstep ] * 2 ; <nl> + Bs + = srow [ bstep - 1 ] + srow [ bstep + 1 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradW < T ) <nl> + { <nl> + Rs + = srow [ - 2 ] + srow [ 0 ] ; <nl> + Gs + = srow [ - 1 ] * 2 ; <nl> + Bs + = srow [ - bstep - 1 ] + srow [ bstep - 1 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradE < T ) <nl> + { <nl> + Rs + = srow [ 2 ] + srow [ 0 ] ; <nl> + Gs + = srow [ 1 ] * 2 ; <nl> + Bs + = srow [ - bstep + 1 ] + srow [ bstep + 1 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradNE < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 + 2 ] + srow [ 0 ] ; <nl> + Gs + = brow0 [ N6 + 1 ] ; <nl> + Bs + = srow [ - bstep + 1 ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + if ( gradSW < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 - 2 ] + srow [ 0 ] ; <nl> + Gs + = brow2 [ N6 - 1 ] ; <nl> + Bs + = srow [ bstep - 1 ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + if ( gradNW < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 - 2 ] + srow [ 0 ] ; <nl> + Gs + = brow0 [ N6 - 1 ] ; <nl> + Bs + = srow [ - bstep + 1 ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + if ( gradSE < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 + 2 ] + srow [ 0 ] ; <nl> + Gs + = brow2 [ N6 + 1 ] ; <nl> + Bs + = srow [ - bstep + 1 ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + R = srow [ 0 ] ; <nl> + G = R + cvRound ( ( Gs - Rs ) * scale [ ng ] ) ; <nl> + B = R + cvRound ( ( Bs - Rs ) * scale [ ng ] ) ; <nl> + } <nl> + else <nl> + { <nl> + int gradNE = brow0 [ N2 ] + brow0 [ N2 + 1 ] + brow1 [ N2 ] + brow1 [ N2 + 1 ] ; <nl> + int gradSW = brow1 [ N2 ] + brow1 [ N2 - 1 ] + brow2 [ N2 ] + brow2 [ N2 - 1 ] ; <nl> + int gradNW = brow0 [ N3 ] + brow0 [ N3 - 1 ] + brow1 [ N3 ] + brow1 [ N3 - 1 ] ; <nl> + int gradSE = brow1 [ N3 ] + brow1 [ N3 + 1 ] + brow2 [ N3 ] + brow2 [ N3 + 1 ] ; <nl> + <nl> + minGrad = std : : min ( std : : min ( std : : min ( std : : min ( minGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> + maxGrad = std : : max ( std : : max ( std : : max ( std : : max ( maxGrad , gradNE ) , gradSW ) , gradNW ) , gradSE ) ; <nl> + int T = minGrad + MAX ( maxGrad / 2 , 1 ) ; <nl> + <nl> + int Rs = 0 , Gs = 0 , Bs = 0 , ng = 0 ; <nl> + if ( gradN < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 - 1 ] + srow [ - bstep * 2 + 1 ] ; <nl> + Gs + = srow [ - bstep * 2 ] + srow [ 0 ] ; <nl> + Bs + = srow [ - bstep ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + if ( gradS < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 - 1 ] + srow [ bstep * 2 + 1 ] ; <nl> + Gs + = srow [ bstep * 2 ] + srow [ 0 ] ; <nl> + Bs + = srow [ bstep ] * 2 ; <nl> + ng + + ; <nl> + } <nl> + if ( gradW < T ) <nl> + { <nl> + Rs + = srow [ - 1 ] * 2 ; <nl> + Gs + = srow [ - 2 ] + srow [ 0 ] ; <nl> + Bs + = srow [ - bstep - 2 ] + srow [ bstep - 2 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradE < T ) <nl> + { <nl> + Rs + = srow [ 1 ] * 2 ; <nl> + Gs + = srow [ 2 ] + srow [ 0 ] ; <nl> + Bs + = srow [ - bstep + 2 ] + srow [ bstep + 2 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradNE < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 + 1 ] + srow [ 1 ] ; <nl> + Gs + = srow [ - bstep + 1 ] * 2 ; <nl> + Bs + = srow [ - bstep ] + srow [ - bstep + 2 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradSW < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 - 1 ] + srow [ - 1 ] ; <nl> + Gs + = srow [ bstep - 1 ] * 2 ; <nl> + Bs + = srow [ bstep ] + srow [ bstep - 2 ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradNW < T ) <nl> + { <nl> + Rs + = srow [ - bstep * 2 - 1 ] + srow [ - 1 ] ; <nl> + Gs + = srow [ - bstep - 1 ] * 2 ; <nl> + Bs + = srow [ - bstep - 2 ] + srow [ - bstep ] ; <nl> + ng + + ; <nl> + } <nl> + if ( gradSE < T ) <nl> + { <nl> + Rs + = srow [ bstep * 2 + 1 ] + srow [ 1 ] ; <nl> + Gs + = srow [ bstep + 1 ] * 2 ; <nl> + Bs + = srow [ bstep + 2 ] + srow [ bstep ] ; <nl> + ng + + ; <nl> + } <nl> + G = srow [ 0 ] ; <nl> + R = G + cvRound ( ( Rs - Gs ) * scale [ ng ] ) ; <nl> + B = G + cvRound ( ( Bs - Gs ) * scale [ ng ] ) ; <nl> + } <nl> + dstrow [ blueIdx ] = CV_CAST_8U ( B ) ; <nl> + dstrow [ 1 ] = CV_CAST_8U ( G ) ; <nl> + dstrow [ blueIdx ^ 2 ] = CV_CAST_8U ( R ) ; <nl> + greenCell = ! greenCell ; <nl> + } <nl> + <nl> + # if CV_SSE2 <nl> + if ( ! haveSSE ) <nl> + break ; <nl> + <nl> + __m128i emask = _mm_set1_epi32 ( 0x0000ffff ) , <nl> + omask = _mm_set1_epi32 ( 0xffff0000 ) , <nl> + z = _mm_setzero_si128 ( ) , <nl> + one = _mm_set1_epi16 ( 1 ) ; <nl> + __m128 _0_5 = _mm_set1_ps ( 0 . 5f ) ; <nl> + <nl> + # define _mm_merge_epi16 ( a , b ) _mm_or_si128 ( _mm_and_si128 ( a , emask ) , _mm_and_si128 ( b , omask ) ) / / ( aA_aA_aA_aA ) * ( bB_bB_bB_bB ) = > ( bA_bA_bA_bA ) <nl> + # define _mm_cvtloepi16_ps ( a ) _mm_cvtepi32_ps ( _mm_srai_epi32 ( _mm_unpacklo_epi16 ( a , a ) , 16 ) ) / / ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) = > ( 1f , 2f , 3f , 4f ) <nl> + # define _mm_cvthiepi16_ps ( a ) _mm_cvtepi32_ps ( _mm_srai_epi32 ( _mm_unpackhi_epi16 ( a , a ) , 16 ) ) / / ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) = > ( 5f , 6f , 7f , 8f ) <nl> + # define _mm_loadl_u8_s16 ( ptr , offset ) _mm_unpacklo_epi8 ( _mm_loadl_epi64 ( ( __m128i * ) ( ( ptr ) + ( offset ) ) ) , z ) / / load 8 uchars to 8 shorts <nl> + <nl> + / / process 8 pixels at once <nl> + for ( ; i < = N - 10 ; i + = 8 , srow + = 8 , brow0 + = 8 , brow1 + = 8 , brow2 + = 8 ) <nl> + { <nl> + / / int gradN = brow0 [ 0 ] + brow1 [ 0 ] ; <nl> + __m128i gradN = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) brow0 ) , _mm_loadu_si128 ( ( __m128i * ) brow1 ) ) ; <nl> + <nl> + / / int gradS = brow1 [ 0 ] + brow2 [ 0 ] ; <nl> + __m128i gradS = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) brow1 ) , _mm_loadu_si128 ( ( __m128i * ) brow2 ) ) ; <nl> + <nl> + / / int gradW = brow1 [ N - 1 ] + brow1 [ N ] ; <nl> + __m128i gradW = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N ) ) ) ; <nl> + <nl> + / / int gradE = brow1 [ N + 1 ] + brow1 [ N ] ; <nl> + __m128i gradE = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N ) ) ) ; <nl> + <nl> + / / int minGrad = std : : min ( std : : min ( std : : min ( gradN , gradS ) , gradW ) , gradE ) ; <nl> + / / int maxGrad = std : : max ( std : : max ( std : : max ( gradN , gradS ) , gradW ) , gradE ) ; <nl> + __m128i minGrad = _mm_min_epi16 ( _mm_min_epi16 ( gradN , gradS ) , _mm_min_epi16 ( gradW , gradE ) ) ; <nl> + __m128i maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( gradN , gradS ) , _mm_max_epi16 ( gradW , gradE ) ) ; <nl> + <nl> + __m128i grad0 , grad1 ; <nl> + <nl> + / / int gradNE = brow0 [ N4 + 1 ] + brow1 [ N4 ] ; <nl> + / / int gradNE = brow0 [ N2 ] + brow0 [ N2 + 1 ] + brow1 [ N2 ] + brow1 [ N2 + 1 ] ; <nl> + grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N4 + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N4 ) ) ) ; <nl> + grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N2 + 1 ) ) ) , <nl> + _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 + 1 ) ) ) ) ; <nl> + __m128i gradNE = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> + <nl> + / / int gradSW = brow1 [ N4 ] + brow2 [ N4 - 1 ] ; <nl> + / / int gradSW = brow1 [ N2 ] + brow1 [ N2 - 1 ] + brow2 [ N2 ] + brow2 [ N2 - 1 ] ; <nl> + grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N4 - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N4 ) ) ) ; <nl> + grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N2 - 1 ) ) ) , <nl> + _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N2 - 1 ) ) ) ) ; <nl> + __m128i gradSW = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> + <nl> + minGrad = _mm_min_epi16 ( _mm_min_epi16 ( minGrad , gradNE ) , gradSW ) ; <nl> + maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( maxGrad , gradNE ) , gradSW ) ; <nl> + <nl> + / / int gradNW = brow0 [ N5 - 1 ] + brow1 [ N5 ] ; <nl> + / / int gradNW = brow0 [ N3 ] + brow0 [ N3 - 1 ] + brow1 [ N3 ] + brow1 [ N3 - 1 ] ; <nl> + grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N5 - 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N5 ) ) ) ; <nl> + grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N3 - 1 ) ) ) , <nl> + _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 - 1 ) ) ) ) ; <nl> + __m128i gradNW = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> + <nl> + / / int gradSE = brow1 [ N5 ] + brow2 [ N5 + 1 ] ; <nl> + / / int gradSE = brow1 [ N3 ] + brow1 [ N3 + 1 ] + brow2 [ N3 ] + brow2 [ N3 + 1 ] ; <nl> + grad0 = _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N5 + 1 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N5 ) ) ) ; <nl> + grad1 = _mm_adds_epi16 ( _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N3 + 1 ) ) ) , <nl> + _mm_adds_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 ) ) , _mm_loadu_si128 ( ( __m128i * ) ( brow1 + N3 + 1 ) ) ) ) ; <nl> + __m128i gradSE = _mm_merge_epi16 ( grad0 , grad1 ) ; <nl> + <nl> + minGrad = _mm_min_epi16 ( _mm_min_epi16 ( minGrad , gradNW ) , gradSE ) ; <nl> + maxGrad = _mm_max_epi16 ( _mm_max_epi16 ( maxGrad , gradNW ) , gradSE ) ; <nl> + <nl> + / / int T = minGrad + maxGrad / 2 ; <nl> + __m128i T = _mm_adds_epi16 ( _mm_max_epi16 ( _mm_srli_epi16 ( maxGrad , 1 ) , one ) , minGrad ) ; <nl> + <nl> + __m128i RGs = z , GRs = z , Bs = z , ng = z ; <nl> + <nl> + __m128i x0 = _mm_loadl_u8_s16 ( srow , + 0 ) ; <nl> + __m128i x1 = _mm_loadl_u8_s16 ( srow , - 1 - bstep ) ; <nl> + __m128i x2 = _mm_loadl_u8_s16 ( srow , - 1 - bstep * 2 ) ; <nl> + __m128i x3 = _mm_loadl_u8_s16 ( srow , - bstep ) ; <nl> + __m128i x4 = _mm_loadl_u8_s16 ( srow , + 1 - bstep * 2 ) ; <nl> + __m128i x5 = _mm_loadl_u8_s16 ( srow , + 1 - bstep ) ; <nl> + __m128i x6 = _mm_loadl_u8_s16 ( srow , + 2 - bstep ) ; <nl> + __m128i x7 = _mm_loadl_u8_s16 ( srow , + 1 ) ; <nl> + __m128i x8 = _mm_loadl_u8_s16 ( srow , + 2 + bstep ) ; <nl> + __m128i x9 = _mm_loadl_u8_s16 ( srow , + 1 + bstep ) ; <nl> + __m128i x10 = _mm_loadl_u8_s16 ( srow , + 1 + bstep * 2 ) ; <nl> + __m128i x11 = _mm_loadl_u8_s16 ( srow , + bstep ) ; <nl> + __m128i x12 = _mm_loadl_u8_s16 ( srow , - 1 + bstep * 2 ) ; <nl> + __m128i x13 = _mm_loadl_u8_s16 ( srow , - 1 + bstep ) ; <nl> + __m128i x14 = _mm_loadl_u8_s16 ( srow , - 2 + bstep ) ; <nl> + __m128i x15 = _mm_loadl_u8_s16 ( srow , - 1 ) ; <nl> + __m128i x16 = _mm_loadl_u8_s16 ( srow , - 2 - bstep ) ; <nl> + <nl> + __m128i t0 , t1 , mask ; <nl> + <nl> + / / gradN * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradN ) ; / / mask = T > gradN <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradN ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x3 , 1 ) ; / / srow [ - bstep ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 ) , x0 ) ; / / srow [ - bstep * 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = ( srow [ - bstep * 2 ] + srow [ 0 ] ) * ( T > gradN ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> + / / GRs + = { srow [ - bstep ] * 2 ; ( srow [ - bstep * 2 - 1 ] + srow [ - bstep * 2 + 1 ] ) } * ( T > gradN ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x2 , x4 ) ) , mask ) ) ; <nl> + / / Bs + = { ( srow [ - bstep - 1 ] + srow [ - bstep + 1 ] ) ; srow [ - bstep ] * 2 } * ( T > gradN ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x1 , x5 ) , t0 ) , mask ) ) ; <nl> + <nl> + / / gradNE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradNE ) ; / / mask = T > gradNE <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradNE ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x5 , 1 ) ; / / srow [ - bstep + 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 + 2 ) , x0 ) ; / / srow [ - bstep * 2 + 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = { ( srow [ - bstep * 2 + 2 ] + srow [ 0 ] ) ; srow [ - bstep + 1 ] * 2 } * ( T > gradNE ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> + / / GRs + = { brow0 [ N6 + 1 ] ; ( srow [ - bstep * 2 + 1 ] + srow [ 1 ] ) } * ( T > gradNE ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N6 + 1 ) ) , _mm_adds_epi16 ( x4 , x7 ) ) , mask ) ) ; <nl> + / / Bs + = { srow [ - bstep + 1 ] * 2 ; ( srow [ - bstep ] + srow [ - bstep + 2 ] ) } * ( T > gradNE ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x3 , x6 ) ) , mask ) ) ; <nl> + <nl> + / / gradE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradE ) ; / / mask = T > gradE <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradE ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x7 , 1 ) ; / / srow [ 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , 2 ) , x0 ) ; / / srow [ 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = ( srow [ 2 ] + srow [ 0 ] ) * ( T > gradE ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> + / / GRs + = ( srow [ 1 ] * 2 ) * ( T > gradE ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( t0 , mask ) ) ; <nl> + / / Bs + = { ( srow [ - bstep + 1 ] + srow [ bstep + 1 ] ) ; ( srow [ - bstep + 2 ] + srow [ bstep + 2 ] ) } * ( T > gradE ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x5 , x9 ) , _mm_adds_epi16 ( x6 , x8 ) ) , mask ) ) ; <nl> + <nl> + / / gradSE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradSE ) ; / / mask = T > gradSE <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradSE ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x9 , 1 ) ; / / srow [ bstep + 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 + 2 ) , x0 ) ; / / srow [ bstep * 2 + 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = { ( srow [ bstep * 2 + 2 ] + srow [ 0 ] ) ; srow [ bstep + 1 ] * 2 } * ( T > gradSE ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> + / / GRs + = { brow2 [ N6 + 1 ] ; ( srow [ 1 ] + srow [ bstep * 2 + 1 ] ) } * ( T > gradSE ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N6 + 1 ) ) , _mm_adds_epi16 ( x7 , x10 ) ) , mask ) ) ; <nl> + / / Bs + = { srow [ - bstep + 1 ] * 2 ; ( srow [ bstep + 2 ] + srow [ bstep ] ) } * ( T > gradSE ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_slli_epi16 ( x5 , 1 ) , _mm_adds_epi16 ( x8 , x11 ) ) , mask ) ) ; <nl> + <nl> + / / gradS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradS ) ; / / mask = T > gradS <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradS ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x11 , 1 ) ; / / srow [ bstep ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 ) , x0 ) ; / / srow [ bstep * 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = ( srow [ bstep * 2 ] + srow [ 0 ] ) * ( T > gradS ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> + / / GRs + = { srow [ bstep ] * 2 ; ( srow [ bstep * 2 + 1 ] + srow [ bstep * 2 - 1 ] ) } * ( T > gradS ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x10 , x12 ) ) , mask ) ) ; <nl> + / / Bs + = { ( srow [ bstep + 1 ] + srow [ bstep - 1 ] ) ; srow [ bstep ] * 2 } * ( T > gradS ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x9 , x13 ) , t0 ) , mask ) ) ; <nl> + <nl> + / / gradSW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradSW ) ; / / mask = T > gradSW <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradSW ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x13 , 1 ) ; / / srow [ bstep - 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , bstep * 2 - 2 ) , x0 ) ; / / srow [ bstep * 2 - 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = { ( srow [ bstep * 2 - 2 ] + srow [ 0 ] ) ; srow [ bstep - 1 ] * 2 } * ( T > gradSW ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> + / / GRs + = { brow2 [ N6 - 1 ] ; ( srow [ bstep * 2 - 1 ] + srow [ - 1 ] ) } * ( T > gradSW ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow2 + N6 - 1 ) ) , _mm_adds_epi16 ( x12 , x15 ) ) , mask ) ) ; <nl> + / / Bs + = { srow [ bstep - 1 ] * 2 ; ( srow [ bstep ] + srow [ bstep - 2 ] ) } * ( T > gradSW ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( t0 , _mm_adds_epi16 ( x11 , x14 ) ) , mask ) ) ; <nl> + <nl> + / / gradW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradW ) ; / / mask = T > gradW <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradW ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x15 , 1 ) ; / / srow [ - 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - 2 ) , x0 ) ; / / srow [ - 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = ( srow [ - 2 ] + srow [ 0 ] ) * ( T > gradW ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( t1 , mask ) ) ; <nl> + / / GRs + = ( srow [ - 1 ] * 2 ) * ( T > gradW ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( t0 , mask ) ) ; <nl> + / / Bs + = { ( srow [ - bstep - 1 ] + srow [ bstep - 1 ] ) ; ( srow [ bstep - 2 ] + srow [ - bstep - 2 ] ) } * ( T > gradW ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_adds_epi16 ( x1 , x13 ) , _mm_adds_epi16 ( x14 , x16 ) ) , mask ) ) ; <nl> + <nl> + / / gradNW * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * <nl> + mask = _mm_cmpgt_epi16 ( T , gradNW ) ; / / mask = T > gradNW <nl> + ng = _mm_sub_epi16 ( ng , mask ) ; / / ng + = ( T > gradNW ) <nl> + <nl> + t0 = _mm_slli_epi16 ( x1 , 1 ) ; / / srow [ - bstep - 1 ] * 2 <nl> + t1 = _mm_adds_epi16 ( _mm_loadl_u8_s16 ( srow , - bstep * 2 - 2 ) , x0 ) ; / / srow [ - bstep * 2 - 2 ] + srow [ 0 ] <nl> + <nl> + / / RGs + = { ( srow [ - bstep * 2 - 2 ] + srow [ 0 ] ) ; srow [ - bstep - 1 ] * 2 } * ( T > gradNW ) <nl> + RGs = _mm_adds_epi16 ( RGs , _mm_and_si128 ( _mm_merge_epi16 ( t1 , t0 ) , mask ) ) ; <nl> + / / GRs + = { brow0 [ N6 - 1 ] ; ( srow [ - bstep * 2 - 1 ] + srow [ - 1 ] ) } * ( T > gradNW ) <nl> + GRs = _mm_adds_epi16 ( GRs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_loadu_si128 ( ( __m128i * ) ( brow0 + N6 - 1 ) ) , _mm_adds_epi16 ( x2 , x15 ) ) , mask ) ) ; <nl> + / / Bs + = { srow [ - bstep - 1 ] * 2 ; ( srow [ - bstep ] + srow [ - bstep - 2 ] ) } * ( T > gradNW ) <nl> + Bs = _mm_adds_epi16 ( Bs , _mm_and_si128 ( _mm_merge_epi16 ( _mm_slli_epi16 ( x5 , 1 ) , _mm_adds_epi16 ( x3 , x16 ) ) , mask ) ) ; <nl> + <nl> + __m128 ngf0 = _mm_div_ps ( _0_5 , _mm_cvtloepi16_ps ( ng ) ) ; <nl> + __m128 ngf1 = _mm_div_ps ( _0_5 , _mm_cvthiepi16_ps ( ng ) ) ; <nl> + <nl> + / / now interpolate r , g & b <nl> + t0 = _mm_subs_epi16 ( GRs , RGs ) ; <nl> + t1 = _mm_subs_epi16 ( Bs , RGs ) ; <nl> + <nl> + t0 = _mm_add_epi16 ( x0 , _mm_packs_epi32 ( <nl> + _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvtloepi16_ps ( t0 ) , ngf0 ) ) , <nl> + _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvthiepi16_ps ( t0 ) , ngf1 ) ) ) ) ; <nl> + <nl> + t1 = _mm_add_epi16 ( x0 , _mm_packs_epi32 ( <nl> + _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvtloepi16_ps ( t1 ) , ngf0 ) ) , <nl> + _mm_cvtps_epi32 ( _mm_mul_ps ( _mm_cvthiepi16_ps ( t1 ) , ngf1 ) ) ) ) ; <nl> + <nl> + x1 = _mm_merge_epi16 ( x0 , t0 ) ; <nl> + x2 = _mm_merge_epi16 ( t0 , x0 ) ; <nl> + <nl> + uchar R [ 8 ] , G [ 8 ] , B [ 8 ] ; <nl> + <nl> + _mm_storel_epi64 ( blueIdx ? ( __m128i * ) B : ( __m128i * ) R , _mm_packus_epi16 ( x1 , z ) ) ; <nl> + _mm_storel_epi64 ( ( __m128i * ) G , _mm_packus_epi16 ( x2 , z ) ) ; <nl> + _mm_storel_epi64 ( blueIdx ? ( __m128i * ) R : ( __m128i * ) B , _mm_packus_epi16 ( t1 , z ) ) ; <nl> + <nl> + for ( int j = 0 ; j < 8 ; j + + , dstrow + = 3 ) <nl> + { <nl> + dstrow [ 0 ] = B [ j ] ; dstrow [ 1 ] = G [ j ] ; dstrow [ 2 ] = R [ j ] ; <nl> + } <nl> + } <nl> + # endif <nl> + <nl> + limit = N - 2 ; <nl> + } <nl> + while ( i < N - 2 ) ; <nl> + <nl> + for ( i = 0 ; i < 6 ; i + + ) <nl> + { <nl> + dst [ dststep * y + 5 - i ] = dst [ dststep * y + 8 - i ] ; <nl> + dst [ dststep * y + ( N - 2 ) * 3 + i ] = dst [ dststep * y + ( N - 3 ) * 3 + i ] ; <nl> + } <nl> + <nl> + greenCell0 = ! greenCell0 ; <nl> + blueIdx ^ = 2 ; <nl> + } <nl> + <nl> + for ( i = 0 ; i < size . width * 3 ; i + + ) <nl> + { <nl> + dst [ i ] = dst [ i + dststep ] = dst [ i + dststep * 2 ] ; <nl> + dst [ i + dststep * ( size . height - 4 ) ] = <nl> + dst [ i + dststep * ( size . height - 3 ) ] = <nl> + dst [ i + dststep * ( size . height - 2 ) ] = <nl> + dst [ i + dststep * ( size . height - 1 ) ] = dst [ i + dststep * ( size . height - 5 ) ] ; <nl> + } <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / Edge - Aware Demosaicing / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + template < typename T > <nl> + class Bayer2RGB_EdgeAware_T_Invoker : <nl> + public cv : : ParallelLoopBody <nl> + { <nl> + public : <nl> + Bayer2RGB_EdgeAware_T_Invoker ( const Mat & _src , Mat & _dst , const Size & _size , <nl> + int _blue , int _start_with_green ) : <nl> + ParallelLoopBody ( ) , <nl> + src ( _src ) , dst ( _dst ) , size ( _size ) , Blue ( _blue ) , Start_with_green ( _start_with_green ) <nl> + { <nl> + } <nl> + <nl> + virtual void operator ( ) ( const Range & range ) const <nl> + { <nl> + int dcn = dst . channels ( ) ; <nl> + int start_with_green = Start_with_green , blue = Blue ; <nl> + int sstep = src . step / src . elemSize1 ( ) , dstep = dst . step / dst . elemSize1 ( ) ; <nl> + <nl> + start_with_green = range . start % 2 = = 0 ? ( Start_with_green ^ 1 ) : Start_with_green ; <nl> + blue = range . start % 2 = = 0 ? ( Blue ^ 1 ) : Blue ; <nl> + const T * S = reinterpret_cast < const T * > ( src . data + range . start * src . step ) + 1 ; <nl> + T * D = reinterpret_cast < T * > ( dst . data + range . start * dst . step ) + dcn ; <nl> + <nl> + / / to BGR <nl> + for ( int y = range . start ; y < range . end ; + + y ) <nl> + { <nl> + int x = 1 ; <nl> + if ( start_with_green ) <nl> + { <nl> + D [ blue < < 1 ] = ( S [ - sstep ] + S [ sstep ] ) > > 1 ; <nl> + D [ 1 ] = S [ 0 ] ; <nl> + D [ 2 - ( blue < < 1 ) ] = ( S [ - 1 ] + S [ 1 ] ) > > 1 ; <nl> + D + = dcn ; <nl> + + + S ; <nl> + + + x ; <nl> + } <nl> + <nl> + if ( blue ) <nl> + for ( ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + D [ 0 ] = S [ 0 ] ; <nl> + D [ 1 ] = ( std : : abs ( S [ - 1 ] - S [ 1 ] ) > std : : abs ( S [ sstep ] - S [ - sstep ] ) ? ( S [ sstep ] + S [ - sstep ] + 1 ) : ( S [ - 1 ] + S [ 1 ] + 1 ) ) > > 1 ; <nl> + D [ 2 ] = ( S [ - sstep - 1 ] + S [ - sstep + 1 ] + S [ sstep - 1 ] + S [ sstep + 1 ] ) > > 2 ; <nl> + <nl> + D [ 3 ] = ( S [ 0 ] + S [ 2 ] + 1 ) > > 1 ; <nl> + D [ 4 ] = S [ 1 ] ; <nl> + D [ 5 ] = ( S [ - sstep + 1 ] + S [ sstep + 1 ] + 1 ) > > 1 ; <nl> + } <nl> + else <nl> + for ( ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + D [ 0 ] = ( S [ - sstep - 1 ] + S [ - sstep + 1 ] + S [ sstep - 1 ] + S [ sstep + 1 ] + 2 ) > > 2 ; <nl> + D [ 1 ] = ( std : : abs ( S [ - 1 ] - S [ 1 ] ) > std : : abs ( S [ sstep ] - S [ - sstep ] ) ? ( S [ sstep ] + S [ - sstep ] + 1 ) : ( S [ - 1 ] + S [ 1 ] + 1 ) ) > > 1 ; <nl> + D [ 2 ] = S [ 0 ] ; <nl> + <nl> + D [ 3 ] = ( S [ - sstep + 1 ] + S [ sstep + 1 ] + 1 ) > > 1 ; <nl> + D [ 4 ] = S [ 1 ] ; <nl> + D [ 5 ] = ( S [ 0 ] + S [ 2 ] + 1 ) > > 1 ; <nl> + } <nl> + <nl> + if ( x < = size . width ) <nl> + { <nl> + D [ blue < < 1 ] = ( S [ - sstep - 1 ] + S [ - sstep + 1 ] + S [ sstep - 1 ] + S [ sstep + 1 ] + 2 ) > > 2 ; <nl> + D [ 1 ] = ( std : : abs ( S [ - 1 ] - S [ 1 ] ) > std : : abs ( S [ sstep ] - S [ - sstep ] ) ? ( S [ sstep ] + S [ - sstep ] + 1 ) : ( S [ - 1 ] + S [ 1 ] + 1 ) ) > > 1 ; <nl> + D [ 2 - ( blue < < 1 ) ] = S [ 0 ] ; <nl> + D + = dcn ; <nl> + + + S ; <nl> + } <nl> + <nl> + for ( int i = 0 ; i < dcn ; + + i ) <nl> + { <nl> + D [ i ] = D [ - dcn + i ] ; <nl> + D [ - dstep + dcn + i ] = D [ - dstep + ( dcn < < 1 ) + i ] ; <nl> + } <nl> + <nl> + start_with_green ^ = 1 ; <nl> + blue ^ = 1 ; <nl> + S + = 2 ; <nl> + D + = 2 * dcn ; <nl> + } <nl> + } <nl> + <nl> + private : <nl> + const Mat src ; <nl> + Mat dst ; <nl> + const Size size ; <nl> + const int Blue , Start_with_green ; <nl> + <nl> + const Bayer2RGB_EdgeAware_T_Invoker & operator = ( const Bayer2RGB_EdgeAware_T_Invoker & ) ; <nl> + Bayer2RGB_EdgeAware_T_Invoker ( const Bayer2RGB_EdgeAware_T_Invoker & ) ; <nl> + } ; <nl> + <nl> + template < typename T > <nl> + static void Bayer2RGB_EdgeAware_T ( const Mat & src , Mat & dst , int code ) <nl> + { <nl> + Size size = src . size ( ) ; <nl> + <nl> + / / for small sizes <nl> + if ( size . width < = 2 | | size . height < = 2 ) <nl> + { <nl> + dst = Scalar : : all ( 0 ) ; <nl> + return ; <nl> + } <nl> + <nl> + size . width - = 2 ; <nl> + size . height - = 1 ; <nl> + <nl> + int start_with_green = code = = CV_BayerGB2BGR_EA | | code = = CV_BayerGR2BGR_EA ? 1 : 0 ; <nl> + int blue = code = = CV_BayerGB2BGR_EA | | code = = CV_BayerBG2BGR_EA ? 1 : 0 ; <nl> + <nl> + Bayer2RGB_EdgeAware_T_Invoker < T > invoker ( src , dst , size , blue , start_with_green ) ; <nl> + Range range ( 1 , size . height ) ; <nl> + parallel_for_ ( range , invoker ) ; <nl> + <nl> + size . width + = 2 ; <nl> + T * firstRow = reinterpret_cast < T * > ( dst . data ) , * lastRow = reinterpret_cast < T * > ( dst . data + size . height * dst . step ) ; <nl> + size . width * = dst . channels ( ) ; <nl> + int dstep = dst . step / dst . elemSize1 ( ) ; <nl> + for ( int x = 0 ; x < size . width ; + + x ) <nl> + { <nl> + firstRow [ x ] = firstRow [ dstep + x ] ; <nl> + lastRow [ x ] = lastRow [ - dstep + x ] ; <nl> + } <nl> + } <nl> + <nl> + } / / end namespace cv <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / The main Demosaicing function / / <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + void cv : : demosaicing ( InputArray _src , OutputArray _dst , int code , int dcn ) <nl> + { <nl> + Mat src = _src . getMat ( ) , dst ; <nl> + Size sz = src . size ( ) ; <nl> + int scn = src . channels ( ) , depth = src . depth ( ) ; <nl> + <nl> + CV_Assert ( depth = = CV_8U | | depth = = CV_16U ) ; <nl> + CV_Assert ( ! src . empty ( ) ) ; <nl> + <nl> + switch ( code ) <nl> + { <nl> + case CV_BayerBG2GRAY : case CV_BayerGB2GRAY : case CV_BayerRG2GRAY : case CV_BayerGR2GRAY : <nl> + if ( dcn < = 0 ) <nl> + dcn = 1 ; <nl> + CV_Assert ( scn = = 1 & & dcn = = 1 ) ; <nl> + <nl> + _dst . create ( sz , CV_MAKETYPE ( depth , dcn ) ) ; <nl> + dst = _dst . getMat ( ) ; <nl> + <nl> + if ( depth = = CV_8U ) <nl> + Bayer2Gray_ < uchar , SIMDBayerInterpolator_8u > ( src , dst , code ) ; <nl> + else if ( depth = = CV_16U ) <nl> + Bayer2Gray_ < ushort , SIMDBayerStubInterpolator_ < ushort > > ( src , dst , code ) ; <nl> + else <nl> + CV_Error ( CV_StsUnsupportedFormat , " Bayer - > Gray demosaicing only supports 8u and 16u types " ) ; <nl> + break ; <nl> + <nl> + case CV_BayerBG2BGR : case CV_BayerGB2BGR : case CV_BayerRG2BGR : case CV_BayerGR2BGR : <nl> + case CV_BayerBG2BGR_VNG : case CV_BayerGB2BGR_VNG : case CV_BayerRG2BGR_VNG : case CV_BayerGR2BGR_VNG : <nl> + { <nl> + if ( dcn < = 0 ) <nl> + dcn = 3 ; <nl> + CV_Assert ( scn = = 1 & & ( dcn = = 3 | | dcn = = 4 ) ) ; <nl> + <nl> + _dst . create ( sz , CV_MAKE_TYPE ( depth , dcn ) ) ; <nl> + Mat dst_ = _dst . getMat ( ) ; <nl> + <nl> + if ( code = = CV_BayerBG2BGR | | code = = CV_BayerGB2BGR | | <nl> + code = = CV_BayerRG2BGR | | code = = CV_BayerGR2BGR ) <nl> + { <nl> + if ( depth = = CV_8U ) <nl> + Bayer2RGB_ < uchar , SIMDBayerInterpolator_8u > ( src , dst_ , code ) ; <nl> + else if ( depth = = CV_16U ) <nl> + Bayer2RGB_ < ushort , SIMDBayerStubInterpolator_ < ushort > > ( src , dst_ , code ) ; <nl> + else <nl> + CV_Error ( CV_StsUnsupportedFormat , " Bayer - > RGB demosaicing only supports 8u and 16u types " ) ; <nl> + } <nl> + else <nl> + { <nl> + CV_Assert ( depth = = CV_8U ) ; <nl> + Bayer2RGB_VNG_8u ( src , dst_ , code ) ; <nl> + } <nl> + } <nl> + break ; <nl> + <nl> + case CV_BayerBG2BGR_EA : case CV_BayerGB2BGR_EA : case CV_BayerRG2BGR_EA : case CV_BayerGR2BGR_EA : <nl> + if ( dcn < = 0 ) <nl> + dcn = 3 ; <nl> + <nl> + CV_Assert ( scn = = 1 & & dcn = = 3 ) ; <nl> + _dst . create ( sz , CV_MAKETYPE ( depth , dcn ) ) ; <nl> + dst = _dst . getMat ( ) ; <nl> + <nl> + if ( depth = = CV_8U ) <nl> + Bayer2RGB_EdgeAware_T < uchar > ( src , dst , code ) ; <nl> + else if ( depth = = CV_16U ) <nl> + Bayer2RGB_EdgeAware_T < ushort > ( src , dst , code ) ; <nl> + else <nl> + CV_Error ( CV_StsUnsupportedFormat , " Bayer - > RGB Edge - Aware demosaicing only currently supports 8u and 16u types " ) ; <nl> + <nl> + break ; <nl> + <nl> + default : <nl> + CV_Error ( CV_StsBadFlag , " Unknown / unsupported color conversion code " ) ; <nl> + } <nl> + } <nl> mmm a / modules / imgproc / test / test_color . cpp <nl> ppp b / modules / imgproc / test / test_color . cpp <nl> TEST ( Imgproc_ColorBayer , accuracy ) { CV_ColorBayerTest test ; test . safe_run ( ) ; } <nl> <nl> TEST ( Imgproc_ColorBayer , regression ) <nl> { <nl> - cvtest : : TS & ts = * cvtest : : TS : : ptr ( ) ; <nl> + cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> <nl> - Mat given = imread ( string ( ts . get_data_path ( ) ) + " / cvtcolor / bayer_input . png " , CV_LOAD_IMAGE_GRAYSCALE ) ; <nl> - Mat gold = imread ( string ( ts . get_data_path ( ) ) + " / cvtcolor / bayer_gold . png " , CV_LOAD_IMAGE_UNCHANGED ) ; <nl> + Mat given = imread ( string ( ts - > get_data_path ( ) ) + " / cvtcolor / bayer_input . png " , CV_LOAD_IMAGE_GRAYSCALE ) ; <nl> + Mat gold = imread ( string ( ts - > get_data_path ( ) ) + " / cvtcolor / bayer_gold . png " , CV_LOAD_IMAGE_UNCHANGED ) ; <nl> Mat result ; <nl> + <nl> + CV_Assert ( given . data ! = NULL & & gold . data ! = NULL ) ; <nl> <nl> cvtColor ( given , result , CV_BayerBG2GRAY ) ; <nl> <nl> TEST ( Imgproc_ColorBayer , regression ) <nl> <nl> TEST ( Imgproc_ColorBayerVNG , regression ) <nl> { <nl> - cvtest : : TS & ts = * cvtest : : TS : : ptr ( ) ; <nl> + cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> <nl> - Mat given = imread ( string ( ts . get_data_path ( ) ) + " / cvtcolor / bayer_input . png " , CV_LOAD_IMAGE_GRAYSCALE ) ; <nl> - string goldfname = string ( ts . get_data_path ( ) ) + " / cvtcolor / bayerVNG_gold . png " ; <nl> + Mat given = imread ( string ( ts - > get_data_path ( ) ) + " / cvtcolor / bayer_input . png " , CV_LOAD_IMAGE_GRAYSCALE ) ; <nl> + string goldfname = string ( ts - > get_data_path ( ) ) + " / cvtcolor / bayerVNG_gold . png " ; <nl> Mat gold = imread ( goldfname , CV_LOAD_IMAGE_UNCHANGED ) ; <nl> Mat result ; <nl> <nl> TEST ( Imgproc_ColorBayerVNG , regression ) <nl> } <nl> } <nl> <nl> + / / creating Bayer pattern <nl> + template < typename T , int depth > <nl> + static void calculateBayerPattern ( const Mat & src , Mat & bayer , const char * pattern ) <nl> + { <nl> + Size ssize = src . size ( ) ; <nl> + const int scn = 1 ; <nl> + bayer . create ( ssize , CV_MAKETYPE ( depth , scn ) ) ; <nl> + <nl> + if ( ! strcmp ( pattern , " bg " ) ) <nl> + { <nl> + for ( int y = 0 ; y < ssize . height ; + + y ) <nl> + for ( int x = 0 ; x < ssize . width ; + + x ) <nl> + { <nl> + if ( ( x + y ) % 2 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 1 ] ) ; <nl> + else if ( x % 2 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 0 ] ) ; <nl> + else <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 2 ] ) ; <nl> + } <nl> + } <nl> + else if ( ! strcmp ( pattern , " gb " ) ) <nl> + { <nl> + for ( int y = 0 ; y < ssize . height ; + + y ) <nl> + for ( int x = 0 ; x < ssize . width ; + + x ) <nl> + { <nl> + if ( ( x + y ) % 2 = = 0 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 1 ] ) ; <nl> + else if ( x % 2 = = 0 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 0 ] ) ; <nl> + else <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 2 ] ) ; <nl> + } <nl> + } <nl> + else if ( ! strcmp ( pattern , " rg " ) ) <nl> + { <nl> + for ( int y = 0 ; y < ssize . height ; + + y ) <nl> + for ( int x = 0 ; x < ssize . width ; + + x ) <nl> + { <nl> + if ( ( x + y ) % 2 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 1 ] ) ; <nl> + else if ( x % 2 = = 0 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 0 ] ) ; <nl> + else <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 2 ] ) ; <nl> + } <nl> + } <nl> + else <nl> + { <nl> + for ( int y = 0 ; y < ssize . height ; + + y ) <nl> + for ( int x = 0 ; x < ssize . width ; + + x ) <nl> + { <nl> + if ( ( x + y ) % 2 = = 0 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 1 ] ) ; <nl> + else if ( x % 2 ) <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 0 ] ) ; <nl> + else <nl> + bayer . at < T > ( y , x ) = static_cast < T > ( src . at < Vec3b > ( y , x ) [ 2 ] ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> TEST ( Imgproc_ColorBayerVNG_Strict , regression ) <nl> { <nl> - cvtest : : TS & ts = * cvtest : : TS : : ptr ( ) ; <nl> + cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> const char pattern [ ] [ 3 ] = { " bg " , " gb " , " rg " , " gr " } ; <nl> const std : : string image_name = " lena . png " ; <nl> - const std : : string parent_path = string ( ts . get_data_path ( ) ) + " / cvtcolor_strict / " ; <nl> + const std : : string parent_path = string ( ts - > get_data_path ( ) ) + " / cvtcolor_strict / " ; <nl> <nl> Mat src , dst , bayer , reference ; <nl> std : : string full_path = parent_path + image_name ; <nl> src = imread ( full_path , CV_LOAD_IMAGE_UNCHANGED ) ; <nl> - Size ssize = src . size ( ) ; <nl> <nl> if ( src . data = = NULL ) <nl> { <nl> - ts . set_failed_test_info ( cvtest : : TS : : FAIL_MISSING_TEST_DATA ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " No input image \ n " ) ; <nl> - ts . set_gtest_status ( ) ; <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_MISSING_TEST_DATA ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " No input image \ n " ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> return ; <nl> } <nl> <nl> - int type = - 1 ; <nl> for ( int i = 0 ; i < 4 ; + + i ) <nl> { <nl> - / / creating Bayer pattern <nl> - bayer . create ( ssize , CV_MAKETYPE ( src . depth ( ) , 1 ) ) ; <nl> - <nl> - if ( ! strcmp ( pattern [ i ] , " bg " ) ) <nl> - { <nl> - for ( int y = 0 ; y < ssize . height ; + + y ) <nl> - for ( int x = 0 ; x < ssize . width ; + + x ) <nl> - { <nl> - if ( ( x + y ) % 2 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 1 ] ; <nl> - else if ( x % 2 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 0 ] ; <nl> - else <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 2 ] ; <nl> - } <nl> - type = CV_BayerBG2BGR_VNG ; <nl> - } <nl> - else if ( ! strcmp ( pattern [ i ] , " gb " ) ) <nl> - { <nl> - for ( int y = 0 ; y < ssize . height ; + + y ) <nl> - for ( int x = 0 ; x < ssize . width ; + + x ) <nl> - { <nl> - if ( ( x + y ) % 2 = = 0 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 1 ] ; <nl> - else if ( x % 2 = = 0 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 0 ] ; <nl> - else <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 2 ] ; <nl> - } <nl> - type = CV_BayerGB2BGR_VNG ; <nl> - } <nl> - else if ( ! strcmp ( pattern [ i ] , " rg " ) ) <nl> - { <nl> - for ( int y = 0 ; y < ssize . height ; + + y ) <nl> - for ( int x = 0 ; x < ssize . width ; + + x ) <nl> - { <nl> - if ( ( x + y ) % 2 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 1 ] ; <nl> - else if ( x % 2 = = 0 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 0 ] ; <nl> - else <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 2 ] ; <nl> - } <nl> - type = CV_BayerRG2BGR_VNG ; <nl> - } <nl> - else <nl> - { <nl> - for ( int y = 0 ; y < ssize . height ; + + y ) <nl> - for ( int x = 0 ; x < ssize . width ; + + x ) <nl> - { <nl> - if ( ( x + y ) % 2 = = 0 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 1 ] ; <nl> - else if ( x % 2 ) <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 0 ] ; <nl> - else <nl> - bayer . at < uchar > ( y , x ) = src . at < Vec3b > ( y , x ) [ 2 ] ; <nl> - } <nl> - type = CV_BayerGR2BGR_VNG ; <nl> - } <nl> + calculateBayerPattern < uchar , CV_8U > ( src , bayer , pattern [ i ] ) ; <nl> + CV_Assert ( ! bayer . empty ( ) & & bayer . type ( ) = = CV_8UC1 ) ; <nl> <nl> / / calculating a dst image <nl> - cvtColor ( bayer , dst , type ) ; <nl> + cvtColor ( bayer , dst , CV_BayerBG2BGR_VNG + i ) ; <nl> <nl> / / reading a reference image <nl> full_path = parent_path + pattern [ i ] + image_name ; <nl> TEST ( Imgproc_ColorBayerVNG_Strict , regression ) <nl> if ( reference . depth ( ) ! = dst . depth ( ) | | reference . channels ( ) ! = dst . channels ( ) | | <nl> reference . size ( ) ! = dst . size ( ) ) <nl> { <nl> - ts . set_failed_test_info ( cvtest : : TS : : FAIL_MISMATCH ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " \ nReference channels : % d \ n " <nl> + std : : cout < < reference ( Rect ( 0 , 0 , 5 , 5 ) ) < < std : : endl < < std : : endl < < std : : endl ; <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_MISMATCH ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " \ nReference channels : % d \ n " <nl> " Actual channels : % d \ n " , reference . channels ( ) , dst . channels ( ) ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " \ nReference depth : % d \ n " <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " \ nReference depth : % d \ n " <nl> " Actual depth : % d \ n " , reference . depth ( ) , dst . depth ( ) ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " \ nReference rows : % d \ n " <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " \ nReference rows : % d \ n " <nl> " Actual rows : % d \ n " , reference . rows , dst . rows ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " \ nReference cols : % d \ n " <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " \ nReference cols : % d \ n " <nl> " Actual cols : % d \ n " , reference . cols , dst . cols ) ; <nl> - ts . set_gtest_status ( ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> <nl> return ; <nl> } <nl> TEST ( Imgproc_ColorBayerVNG_Strict , regression ) <nl> int nonZero = countNonZero ( diff . reshape ( 1 ) > 1 ) ; <nl> if ( nonZero ! = 0 ) <nl> { <nl> - ts . set_failed_test_info ( cvtest : : TS : : FAIL_BAD_ACCURACY ) ; <nl> - ts . printf ( cvtest : : TS : : SUMMARY , " \ nCount non zero in absdiff : % d \ n " , nonZero ) ; <nl> - ts . set_gtest_status ( ) ; <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_BAD_ACCURACY ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " \ nCount non zero in absdiff : % d \ n " , nonZero ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> return ; <nl> } <nl> } <nl> } <nl> <nl> - <nl> - void GetTestMatrix ( Mat & src ) <nl> + static void getTestMatrix ( Mat & src ) <nl> { <nl> Size ssize ( 1000 , 1000 ) ; <nl> src . create ( ssize , CV_32FC3 ) ; <nl> void GetTestMatrix ( Mat & src ) <nl> } <nl> } <nl> <nl> - void validate_result ( const Mat & reference , const Mat & actual , const Mat & src = Mat ( ) , int mode = - 1 ) <nl> + static void validateResult ( const Mat & reference , const Mat & actual , const Mat & src = Mat ( ) , int mode = - 1 ) <nl> { <nl> cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> Size ssize = reference . size ( ) ; <nl> void validate_result ( const Mat & reference , const Mat & actual , const Mat & src = M <nl> TEST ( Imgproc_ColorLab_Full , accuracy ) <nl> { <nl> Mat src ; <nl> - GetTestMatrix ( src ) ; <nl> - Mat reference ( src . size ( ) , CV_32FC3 ) ; <nl> + getTestMatrix ( src ) ; <nl> Size ssize = src . size ( ) ; <nl> CV_Assert ( ssize . width = = ssize . height ) ; <nl> <nl> TEST ( Imgproc_ColorLab_Full , accuracy ) <nl> cv : : Mat recons ; <nl> cv : : cvtColor ( lab , recons , inverse_code ) ; <nl> <nl> - validate_result ( src , recons , src , forward_code ) ; <nl> + validateResult ( src , recons , src , forward_code ) ; <nl> + } <nl> + <nl> + static void test_Bayer2RGB_EdgeAware_8u ( const Mat & src , Mat & dst , int code ) <nl> + { <nl> + if ( dst . empty ( ) ) <nl> + dst . create ( src . size ( ) , CV_MAKETYPE ( src . depth ( ) , 3 ) ) ; <nl> + Size size = src . size ( ) ; <nl> + size . width - = 1 ; <nl> + size . height - = 1 ; <nl> + <nl> + int dcn = dst . channels ( ) ; <nl> + CV_Assert ( dcn = = 3 ) ; <nl> + <nl> + int step = src . step ; <nl> + const uchar * S = src . ptr < uchar > ( 1 ) + 1 ; <nl> + uchar * D = dst . ptr < uchar > ( 1 ) + dcn ; <nl> + <nl> + int start_with_green = code = = CV_BayerGB2BGR_EA | | code = = CV_BayerGR2BGR_EA ? 1 : 0 ; <nl> + int blue = code = = CV_BayerGB2BGR_EA | | code = = CV_BayerBG2BGR_EA ? 1 : 0 ; <nl> + <nl> + for ( int y = 1 ; y < size . height ; + + y ) <nl> + { <nl> + S = src . ptr < uchar > ( y ) + 1 ; <nl> + D = dst . ptr < uchar > ( y ) + dcn ; <nl> + <nl> + if ( start_with_green ) <nl> + { <nl> + for ( int x = 1 ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + / / red <nl> + D [ 0 ] = ( S [ - 1 ] + S [ 1 ] ) / 2 ; <nl> + D [ 1 ] = S [ 0 ] ; <nl> + D [ 2 ] = ( S [ - step ] + S [ step ] ) / 2 ; <nl> + if ( ! blue ) <nl> + std : : swap ( D [ 0 ] , D [ 2 ] ) ; <nl> + } <nl> <nl> - / / src * = 255 . 0f ; <nl> - / / recons * = 255 . 0f ; <nl> + S = src . ptr < uchar > ( y ) + 2 ; <nl> + D = dst . ptr < uchar > ( y ) + 2 * dcn ; <nl> + <nl> + for ( int x = 2 ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + / / red <nl> + D [ 0 ] = S [ 0 ] ; <nl> + D [ 1 ] = ( std : : abs ( S [ - 1 ] - S [ 1 ] ) > std : : abs ( S [ step ] - S [ - step ] ) ? ( S [ step ] + S [ - step ] ) : ( S [ - 1 ] + S [ 1 ] ) ) / 2 ; <nl> + D [ 2 ] = ( ( S [ - step - 1 ] + S [ - step + 1 ] + S [ step - 1 ] + S [ step + 1 ] ) / 4 ) ; <nl> + if ( ! blue ) <nl> + std : : swap ( D [ 0 ] , D [ 2 ] ) ; <nl> + } <nl> + } <nl> + else <nl> + { <nl> + for ( int x = 1 ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + D [ 0 ] = S [ 0 ] ; <nl> + D [ 1 ] = ( std : : abs ( S [ - 1 ] - S [ 1 ] ) > std : : abs ( S [ step ] - S [ - step ] ) ? ( S [ step ] + S [ - step ] ) : ( S [ - 1 ] + S [ 1 ] ) ) / 2 ; <nl> + D [ 2 ] = ( ( S [ - step - 1 ] + S [ - step + 1 ] + S [ step - 1 ] + S [ step + 1 ] ) / 4 ) ; <nl> + if ( ! blue ) <nl> + std : : swap ( D [ 0 ] , D [ 2 ] ) ; <nl> + } <nl> <nl> - / / imshow ( " Test " , src ) ; <nl> - / / imshow ( " OpenCV " , recons ) ; <nl> - / / waitKey ( ) ; <nl> + S = src . ptr < uchar > ( y ) + 2 ; <nl> + D = dst . ptr < uchar > ( y ) + 2 * dcn ; <nl> + <nl> + for ( int x = 2 ; x < size . width ; x + = 2 , S + = 2 , D + = 2 * dcn ) <nl> + { <nl> + D [ 0 ] = ( S [ - 1 ] + S [ 1 ] ) / 2 ; <nl> + D [ 1 ] = S [ 0 ] ; <nl> + D [ 2 ] = ( S [ - step ] + S [ step ] ) / 2 ; <nl> + if ( ! blue ) <nl> + std : : swap ( D [ 0 ] , D [ 2 ] ) ; <nl> + } <nl> + } <nl> + <nl> + D = dst . ptr < uchar > ( y + 1 ) - dcn ; <nl> + for ( int i = 0 ; i < dcn ; + + i ) <nl> + { <nl> + D [ i ] = D [ - dcn + i ] ; <nl> + D [ - static_cast < int > ( dst . step ) + dcn + i ] = D [ - static_cast < int > ( dst . step ) + ( dcn < < 1 ) + i ] ; <nl> + } <nl> + <nl> + start_with_green ^ = 1 ; <nl> + blue ^ = 1 ; <nl> + } <nl> + <nl> + + + size . width ; <nl> + uchar * firstRow = dst . data , * lastRow = dst . data + size . height * dst . step ; <nl> + size . width * = dcn ; <nl> + for ( int x = 0 ; x < size . width ; + + x ) <nl> + { <nl> + firstRow [ x ] = firstRow [ dst . step + x ] ; <nl> + lastRow [ x ] = lastRow [ - static_cast < int > ( dst . step ) + x ] ; <nl> + } <nl> + } <nl> + <nl> + template < typename T > <nl> + static void checkData ( const Mat & actual , const Mat & reference , cvtest : : TS * ts , const char * type , <nl> + bool & next , const char * bayer_type ) <nl> + { <nl> + EXPECT_EQ ( actual . size ( ) , reference . size ( ) ) ; <nl> + EXPECT_EQ ( actual . channels ( ) , reference . channels ( ) ) ; <nl> + EXPECT_EQ ( actual . depth ( ) , reference . depth ( ) ) ; <nl> + <nl> + Size size = reference . size ( ) ; <nl> + size . width * = reference . channels ( ) ; <nl> + for ( int y = 0 ; y < size . height & & next ; + + y ) <nl> + { <nl> + const T * A = reinterpret_cast < const T * > ( actual . data + actual . step * y ) ; <nl> + const T * R = reinterpret_cast < const T * > ( reference . data + reference . step * y ) ; <nl> + <nl> + for ( int x = 0 ; x < size . width & & next ; + + x ) <nl> + if ( std : : abs ( A [ x ] - R [ x ] ) > 1 ) <nl> + { <nl> + # define SUM cvtest : : TS : : SUMMARY <nl> + ts - > printf ( SUM , " \ nReference value : % d \ n " , static_cast < int > ( R [ x ] ) ) ; <nl> + ts - > printf ( SUM , " Actual value : % d \ n " , static_cast < int > ( A [ x ] ) ) ; <nl> + ts - > printf ( SUM , " ( y , x ) : ( % d , % d ) \ n " , y , x / reference . channels ( ) ) ; <nl> + ts - > printf ( SUM , " Pattern : % s \ n " , type ) ; <nl> + ts - > printf ( SUM , " Bayer image type : % s " , bayer_type ) ; <nl> + # undef SUM <nl> + <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_BAD_ACCURACY ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> + <nl> + next = false ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + TEST ( ImgProc_BayerEdgeAwareDemosaicing , accuracy ) <nl> + { <nl> + cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> + const std : : string image_name = " lena . png " ; <nl> + const std : : string parent_path = string ( ts - > get_data_path ( ) ) + " / cvtcolor_strict / " ; <nl> + <nl> + Mat src , bayer ; <nl> + std : : string full_path = parent_path + image_name ; <nl> + src = imread ( full_path , CV_LOAD_IMAGE_UNCHANGED ) ; <nl> + <nl> + if ( src . data = = NULL ) <nl> + { <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_MISSING_TEST_DATA ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " No input image \ n " ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> + return ; <nl> + } <nl> + <nl> + / * <nl> + COLOR_BayerBG2BGR_EA = 127 , <nl> + COLOR_BayerGB2BGR_EA = 128 , <nl> + COLOR_BayerRG2BGR_EA = 129 , <nl> + COLOR_BayerGR2BGR_EA = 130 , <nl> + * / <nl> + <nl> + bool next = true ; <nl> + const char * types [ ] = { " bg " , " gb " , " rg " , " gr " } ; <nl> + for ( int i = 0 ; i < 4 & & next ; + + i ) <nl> + { <nl> + calculateBayerPattern < uchar , CV_8U > ( src , bayer , types [ i ] ) ; <nl> + Mat reference ; <nl> + test_Bayer2RGB_EdgeAware_8u ( bayer , reference , CV_BayerBG2BGR_EA + i ) ; <nl> + <nl> + for ( int t = 0 ; t < = 1 ; + + t ) <nl> + { <nl> + if ( t = = 1 ) <nl> + calculateBayerPattern < unsigned short int , CV_16U > ( src , bayer , types [ i ] ) ; <nl> + <nl> + CV_Assert ( ! bayer . empty ( ) & & ( bayer . type ( ) = = CV_8UC1 | | bayer . type ( ) = = CV_16UC1 ) ) ; <nl> + <nl> + Mat actual ; <nl> + cv : : demosaicing ( bayer , actual , CV_BayerBG2BGR_EA + i ) ; <nl> + <nl> + if ( t = = 0 ) <nl> + checkData < unsigned char > ( actual , reference , ts , types [ i ] , next , " CV_8U " ) ; <nl> + else <nl> + { <nl> + Mat tmp ; <nl> + reference . convertTo ( tmp , CV_16U ) ; <nl> + checkData < unsigned short int > ( actual , tmp , ts , types [ i ] , next , " CV_16U " ) ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + <nl> + TEST ( ImgProc_Bayer2RGBA , accuracy ) <nl> + { <nl> + cvtest : : TS * ts = cvtest : : TS : : ptr ( ) ; <nl> + Mat raw = imread ( string ( ts - > get_data_path ( ) ) + " / cvtcolor / bayer_input . png " , CV_LOAD_IMAGE_GRAYSCALE ) ; <nl> + Mat rgb , reference ; <nl> + <nl> + CV_Assert ( raw . channels ( ) = = 1 ) ; <nl> + CV_Assert ( raw . depth ( ) = = CV_8U ) ; <nl> + CV_Assert ( ! raw . empty ( ) ) ; <nl> + <nl> + for ( int code = CV_BayerBG2BGR ; code < = CV_BayerGR2BGR ; + + code ) <nl> + { <nl> + cvtColor ( raw , rgb , code ) ; <nl> + cvtColor ( rgb , reference , CV_BGR2BGRA ) ; <nl> + <nl> + Mat actual ; <nl> + cvtColor ( raw , actual , code , 4 ) ; <nl> + <nl> + EXPECT_EQ ( reference . size ( ) , actual . size ( ) ) ; <nl> + EXPECT_EQ ( reference . depth ( ) , actual . depth ( ) ) ; <nl> + EXPECT_EQ ( reference . channels ( ) , actual . channels ( ) ) ; <nl> + <nl> + Size ssize = raw . size ( ) ; <nl> + int cn = reference . channels ( ) ; <nl> + ssize . width * = cn ; <nl> + bool next = true ; <nl> + for ( int y = 0 ; y < ssize . height & & next ; + + y ) <nl> + { <nl> + const uchar * rD = reference . ptr < uchar > ( y ) ; <nl> + const uchar * D = actual . ptr < uchar > ( y ) ; <nl> + for ( int x = 0 ; x < ssize . width & & next ; + + x ) <nl> + if ( abs ( rD [ x ] - D [ x ] ) > = 1 ) <nl> + { <nl> + next = false ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " Error in : ( % d , % d ) \ n " , x / cn , y ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " Reference value : % d \ n " , rD [ x ] ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " Actual value : % d \ n " , D [ x ] ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " Src value : % d \ n " , raw . ptr < uchar > ( y ) [ x ] ) ; <nl> + ts - > printf ( cvtest : : TS : : SUMMARY , " Size : ( % d , % d ) \ n " , reference . rows , reference . cols ) ; <nl> + <nl> + Mat diff ; <nl> + absdiff ( actual , reference , diff ) ; <nl> + <nl> + cv : : Rect r ( 0 , ssize . height - 5 , 7 , 5 ) ; <nl> + std : : cout < < " Actual : " < < std : : endl < < actual ( r ) < < std : : endl < < std : : endl ; <nl> + std : : cout < < " Reference : " < < std : : endl < < reference ( r ) < < std : : endl < < std : : endl ; <nl> + std : : cout < < " Difference : " < < std : : endl < < diff ( r ) < < std : : endl < < std : : endl ; <nl> + <nl> + imshow ( " Diff " , diff ) ; <nl> + waitKey ( ) ; <nl> + <nl> + EXPECT_EQ ( countNonZero ( diff . reshape ( 1 ) > 1 ) , 0 ) ; <nl> + <nl> + ts - > set_failed_test_info ( cvtest : : TS : : FAIL_BAD_ACCURACY ) ; <nl> + ts - > set_gtest_status ( ) ; <nl> + } <nl> + } <nl> + } <nl> } <nl>
added edge - aware demosaicing and bayer to bgra conversion
opencv/opencv
5225672dc0b55aae3a023c5efc365bd13f1a7ef5
2012-11-26T12:17:43Z
mmm a / tensorflow / go / op / wrappers . go <nl> ppp b / tensorflow / go / op / wrappers . go <nl> func Cholesky ( scope * Scope , input tf . Output ) ( output tf . Output ) { <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / FusedBatchNormGradAttr is an optional argument to FusedBatchNormGrad . <nl> - type FusedBatchNormGradAttr func ( optionalAttr ) <nl> - <nl> - / / FusedBatchNormGradEpsilon sets the optional epsilon attribute to value . <nl> - / / <nl> - / / value : A small float number added to the variance of x . <nl> - / / If not specified , defaults to 0 . 0001 <nl> - func FusedBatchNormGradEpsilon ( value float32 ) FusedBatchNormGradAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " epsilon " ] = value <nl> - } <nl> - } <nl> - <nl> - / / FusedBatchNormGradDataFormat sets the optional data_format attribute to value . <nl> - / / <nl> - / / value : The data format for y_backprop , x , x_backprop . <nl> - / / Either " NHWC " ( default ) or " NCHW " . <nl> - / / If not specified , defaults to " NHWC " <nl> - func FusedBatchNormGradDataFormat ( value string ) FusedBatchNormGradAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " data_format " ] = value <nl> - } <nl> - } <nl> - <nl> - / / FusedBatchNormGradIsTraining sets the optional is_training attribute to value . <nl> - / / <nl> - / / value : A bool value to indicate the operation is for training ( default ) <nl> - / / or inference . <nl> - / / If not specified , defaults to true <nl> - func FusedBatchNormGradIsTraining ( value bool ) FusedBatchNormGradAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " is_training " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Gradient for batch normalization . <nl> - / / <nl> - / / Note that the size of 4D Tensors are defined by either " NHWC " or " NCHW " . <nl> - / / The size of 1D Tensors matches the dimension C of the 4D Tensors . <nl> - / / <nl> - / / Arguments : <nl> - / / y_backprop : A 4D Tensor for the gradient with respect to y . <nl> - / / x : A 4D Tensor for input data . <nl> - / / scale : A 1D Tensor for scaling factor , to scale the normalized x . <nl> - / / reserve_space_1 : When is_training is True , a 1D Tensor for the computed batch <nl> - / / mean to be reused in gradient computation . When is_training is <nl> - / / False , a 1D Tensor for the population mean to be reused in both <nl> - / / 1st and 2nd order gradient computation . <nl> - / / reserve_space_2 : When is_training is True , a 1D Tensor for the computed batch <nl> - / / variance ( inverted variance in the cuDNN case ) to be reused in <nl> - / / gradient computation . When is_training is False , a 1D Tensor <nl> - / / for the population variance to be reused in both 1st and 2nd <nl> - / / order gradient computation . <nl> - / / <nl> - / / Returns A 4D Tensor for the gradient with respect to x . A 1D Tensor for the gradient with respect to scale . A 1D Tensor for the gradient with respect to offset . Unused placeholder to match the mean input in FusedBatchNorm . Unused placeholder to match the variance input <nl> - / / in FusedBatchNorm . <nl> - func FusedBatchNormGrad ( scope * Scope , y_backprop tf . Output , x tf . Output , scale tf . Output , reserve_space_1 tf . Output , reserve_space_2 tf . Output , optional . . . FusedBatchNormGradAttr ) ( x_backprop tf . Output , scale_backprop tf . Output , offset_backprop tf . Output , reserve_space_3 tf . Output , reserve_space_4 tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " FusedBatchNormGrad " , <nl> - Input : [ ] tf . Input { <nl> - y_backprop , x , scale , reserve_space_1 , reserve_space_2 , <nl> - } , <nl> - Attrs : attrs , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) , op . Output ( 1 ) , op . Output ( 2 ) , op . Output ( 3 ) , op . Output ( 4 ) <nl> - } <nl> - <nl> - / / ShapeAttr is an optional argument to Shape . <nl> - type ShapeAttr func ( optionalAttr ) <nl> - <nl> - / / ShapeOutType sets the optional out_type attribute to value . <nl> - / / If not specified , defaults to DT_INT32 <nl> - func ShapeOutType ( value tf . DataType ) ShapeAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " out_type " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Returns the shape of a tensor . <nl> - / / <nl> - / / This operation returns a 1 - D integer tensor representing the shape of ` input ` . <nl> - / / <nl> - / / For example : <nl> - / / <nl> - / / ` ` ` <nl> - / / # ' t ' is [ [ [ 1 , 1 , 1 ] , [ 2 , 2 , 2 ] ] , [ [ 3 , 3 , 3 ] , [ 4 , 4 , 4 ] ] ] <nl> - / / shape ( t ) = = > [ 2 , 2 , 3 ] <nl> - / / ` ` ` <nl> - func Shape ( scope * Scope , input tf . Output , optional . . . ShapeAttr ) ( output tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " Shape " , <nl> - Input : [ ] tf . Input { <nl> - input , <nl> - } , <nl> - Attrs : attrs , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / Computes softmax cross entropy cost and gradients to backpropagate . <nl> - / / <nl> - / / Inputs are the logits , not probabilities . <nl> - / / <nl> - / / Arguments : <nl> - / / features : batch_size x num_classes matrix <nl> - / / labels : batch_size x num_classes matrix <nl> - / / The caller must ensure that each batch of labels represents a valid <nl> - / / probability distribution . <nl> - / / <nl> - / / Returns Per example loss ( batch_size vector ) . backpropagated gradients ( batch_size x num_classes matrix ) . <nl> - func SoftmaxCrossEntropyWithLogits ( scope * Scope , features tf . Output , labels tf . Output ) ( loss tf . Output , backprop tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " SoftmaxCrossEntropyWithLogits " , <nl> - Input : [ ] tf . Input { <nl> - features , labels , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) , op . Output ( 1 ) <nl> - } <nl> - <nl> / / MaxPool3DGradGradAttr is an optional argument to MaxPool3DGradGrad . <nl> type MaxPool3DGradGradAttr func ( optionalAttr ) <nl> <nl> func DecodeJSONExample ( scope * Scope , json_examples tf . Output ) ( binary_examples t <nl> / / Requires ` updates . shape = indices . shape + ref . shape [ 1 : ] ` . <nl> / / <nl> / / < div style = " width : 70 % ; margin : auto ; margin - bottom : 10px ; margin - top : 20px ; " > <nl> - / / < img style = " width : 100 % " src = " https : / / www . tensorflow . org / images / ScatterAdd . png " alt > <nl> + / / < img style = " width : 100 % " src = ' https : / / www . tensorflow . org / images / ScatterAdd . png ' alt > <nl> / / < / div > <nl> / / <nl> / / Arguments : <nl> func Conv3D ( scope * Scope , input tf . Output , filter tf . Output , strides [ ] int64 , pa <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / L2 Loss . <nl> - / / <nl> - / / Computes half the L2 norm of a tensor without the ` sqrt ` : <nl> - / / <nl> - / / output = sum ( t * * 2 ) / 2 <nl> - / / <nl> - / / Arguments : <nl> - / / t : Typically 2 - D , but may have any dimensions . <nl> - / / <nl> - / / Returns 0 - D . <nl> - func L2Loss ( scope * Scope , t tf . Output ) ( output tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " L2Loss " , <nl> - Input : [ ] tf . Input { <nl> - t , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / Computes rectified linear : ` max ( features , 0 ) ` . <nl> - func Relu ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " Relu " , <nl> - Input : [ ] tf . Input { <nl> - features , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> / / Returns the truth value of ( x > = y ) element - wise . <nl> / / <nl> / / * NOTE * : ` GreaterEqual ` supports broadcasting . More about broadcasting <nl> func SerializeTensor ( scope * Scope , tensor tf . Output ) ( serialized tf . Output ) { <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / Get the value of the tensor specified by its handle . <nl> - / / <nl> - / / Arguments : <nl> - / / handle : The handle for a tensor stored in the session state . <nl> - / / dtype : The type of the output value . <nl> + / / FusedBatchNormGradAttr is an optional argument to FusedBatchNormGrad . <nl> + type FusedBatchNormGradAttr func ( optionalAttr ) <nl> + <nl> + / / FusedBatchNormGradEpsilon sets the optional epsilon attribute to value . <nl> / / <nl> - / / Returns The tensor for the given handle . <nl> - func GetSessionTensor ( scope * Scope , handle tf . Output , dtype tf . DataType ) ( value tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - attrs : = map [ string ] interface { } { " dtype " : dtype } <nl> - opspec : = tf . OpSpec { <nl> - Type : " GetSessionTensor " , <nl> - Input : [ ] tf . Input { <nl> - handle , <nl> - } , <nl> - Attrs : attrs , <nl> + / / value : A small float number added to the variance of x . <nl> + / / If not specified , defaults to 0 . 0001 <nl> + func FusedBatchNormGradEpsilon ( value float32 ) FusedBatchNormGradAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " epsilon " ] = value <nl> } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> } <nl> <nl> - / / ResourceApplyProximalGradientDescentAttr is an optional argument to ResourceApplyProximalGradientDescent . <nl> - type ResourceApplyProximalGradientDescentAttr func ( optionalAttr ) <nl> + / / FusedBatchNormGradDataFormat sets the optional data_format attribute to value . <nl> + / / <nl> + / / value : The data format for y_backprop , x , x_backprop . <nl> + / / Either " NHWC " ( default ) or " NCHW " . <nl> + / / If not specified , defaults to " NHWC " <nl> + func FusedBatchNormGradDataFormat ( value string ) FusedBatchNormGradAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " data_format " ] = value <nl> + } <nl> + } <nl> <nl> - / / ResourceApplyProximalGradientDescentUseLocking sets the optional use_locking attribute to value . <nl> + / / FusedBatchNormGradIsTraining sets the optional is_training attribute to value . <nl> / / <nl> - / / value : If True , the subtraction will be protected by a lock ; <nl> - / / otherwise the behavior is undefined , but may exhibit less contention . <nl> - / / If not specified , defaults to false <nl> - func ResourceApplyProximalGradientDescentUseLocking ( value bool ) ResourceApplyProximalGradientDescentAttr { <nl> + / / value : A bool value to indicate the operation is for training ( default ) <nl> + / / or inference . <nl> + / / If not specified , defaults to true <nl> + func FusedBatchNormGradIsTraining ( value bool ) FusedBatchNormGradAttr { <nl> return func ( m optionalAttr ) { <nl> - m [ " use_locking " ] = value <nl> + m [ " is_training " ] = value <nl> } <nl> } <nl> <nl> - / / Update ' * var ' as FOBOS algorithm with fixed learning rate . <nl> + / / Gradient for batch normalization . <nl> / / <nl> - / / prox_v = var - alpha * delta <nl> - / / var = sign ( prox_v ) / ( 1 + alpha * l2 ) * max { | prox_v | - alpha * l1 , 0 } <nl> + / / Note that the size of 4D Tensors are defined by either " NHWC " or " NCHW " . <nl> + / / The size of 1D Tensors matches the dimension C of the 4D Tensors . <nl> / / <nl> / / Arguments : <nl> - / / var_ : Should be from a Variable ( ) . <nl> - / / alpha : Scaling factor . Must be a scalar . <nl> - / / l1 : L1 regularization . Must be a scalar . <nl> - / / l2 : L2 regularization . Must be a scalar . <nl> - / / delta : The change . <nl> + / / y_backprop : A 4D Tensor for the gradient with respect to y . <nl> + / / x : A 4D Tensor for input data . <nl> + / / scale : A 1D Tensor for scaling factor , to scale the normalized x . <nl> + / / reserve_space_1 : When is_training is True , a 1D Tensor for the computed batch <nl> + / / mean to be reused in gradient computation . When is_training is <nl> + / / False , a 1D Tensor for the population mean to be reused in both <nl> + / / 1st and 2nd order gradient computation . <nl> + / / reserve_space_2 : When is_training is True , a 1D Tensor for the computed batch <nl> + / / variance ( inverted variance in the cuDNN case ) to be reused in <nl> + / / gradient computation . When is_training is False , a 1D Tensor <nl> + / / for the population variance to be reused in both 1st and 2nd <nl> + / / order gradient computation . <nl> / / <nl> - / / Returns the created operation . <nl> - func ResourceApplyProximalGradientDescent ( scope * Scope , var_ tf . Output , alpha tf . Output , l1 tf . Output , l2 tf . Output , delta tf . Output , optional . . . ResourceApplyProximalGradientDescentAttr ) ( o * tf . Operation ) { <nl> + / / Returns A 4D Tensor for the gradient with respect to x . A 1D Tensor for the gradient with respect to scale . A 1D Tensor for the gradient with respect to offset . Unused placeholder to match the mean input in FusedBatchNorm . Unused placeholder to match the variance input <nl> + / / in FusedBatchNorm . <nl> + func FusedBatchNormGrad ( scope * Scope , y_backprop tf . Output , x tf . Output , scale tf . Output , reserve_space_1 tf . Output , reserve_space_2 tf . Output , optional . . . FusedBatchNormGradAttr ) ( x_backprop tf . Output , scale_backprop tf . Output , offset_backprop tf . Output , reserve_space_3 tf . Output , reserve_space_4 tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " FusedBatchNormGrad " , <nl> + Input : [ ] tf . Input { <nl> + y_backprop , x , scale , reserve_space_1 , reserve_space_2 , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) , op . Output ( 1 ) , op . Output ( 2 ) , op . Output ( 3 ) , op . Output ( 4 ) <nl> + } <nl> + <nl> + / / Computes rectified linear : ` max ( features , 0 ) ` . <nl> + func Relu ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " Relu " , <nl> + Input : [ ] tf . Input { <nl> + features , <nl> + } , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / L2 Loss . <nl> + / / <nl> + / / Computes half the L2 norm of a tensor without the ` sqrt ` : <nl> + / / <nl> + / / output = sum ( t * * 2 ) / 2 <nl> + / / <nl> + / / Arguments : <nl> + / / t : Typically 2 - D , but may have any dimensions . <nl> + / / <nl> + / / Returns 0 - D . <nl> + func L2Loss ( scope * Scope , t tf . Output ) ( output tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " L2Loss " , <nl> + Input : [ ] tf . Input { <nl> + t , <nl> + } , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / ShapeAttr is an optional argument to Shape . <nl> + type ShapeAttr func ( optionalAttr ) <nl> + <nl> + / / ShapeOutType sets the optional out_type attribute to value . <nl> + / / If not specified , defaults to DT_INT32 <nl> + func ShapeOutType ( value tf . DataType ) ShapeAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " out_type " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Returns the shape of a tensor . <nl> + / / <nl> + / / This operation returns a 1 - D integer tensor representing the shape of ` input ` . <nl> + / / <nl> + / / For example : <nl> + / / <nl> + / / ` ` ` <nl> + / / # ' t ' is [ [ [ 1 , 1 , 1 ] , [ 2 , 2 , 2 ] ] , [ [ 3 , 3 , 3 ] , [ 4 , 4 , 4 ] ] ] <nl> + / / shape ( t ) = = > [ 2 , 2 , 3 ] <nl> + / / ` ` ` <nl> + func Shape ( scope * Scope , input tf . Output , optional . . . ShapeAttr ) ( output tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " Shape " , <nl> + Input : [ ] tf . Input { <nl> + input , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / Computes softmax cross entropy cost and gradients to backpropagate . <nl> + / / <nl> + / / Inputs are the logits , not probabilities . <nl> + / / <nl> + / / Arguments : <nl> + / / features : batch_size x num_classes matrix <nl> + / / labels : batch_size x num_classes matrix <nl> + / / The caller must ensure that each batch of labels represents a valid <nl> + / / probability distribution . <nl> + / / <nl> + / / Returns Per example loss ( batch_size vector ) . backpropagated gradients ( batch_size x num_classes matrix ) . <nl> + func SoftmaxCrossEntropyWithLogits ( scope * Scope , features tf . Output , labels tf . Output ) ( loss tf . Output , backprop tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " SoftmaxCrossEntropyWithLogits " , <nl> + Input : [ ] tf . Input { <nl> + features , labels , <nl> + } , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) , op . Output ( 1 ) <nl> + } <nl> + <nl> + / / Get the value of the tensor specified by its handle . <nl> + / / <nl> + / / Arguments : <nl> + / / handle : The handle for a tensor stored in the session state . <nl> + / / dtype : The type of the output value . <nl> + / / <nl> + / / Returns The tensor for the given handle . <nl> + func GetSessionTensor ( scope * Scope , handle tf . Output , dtype tf . DataType ) ( value tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { " dtype " : dtype } <nl> + opspec : = tf . OpSpec { <nl> + Type : " GetSessionTensor " , <nl> + Input : [ ] tf . Input { <nl> + handle , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / ResourceApplyProximalGradientDescentAttr is an optional argument to ResourceApplyProximalGradientDescent . <nl> + type ResourceApplyProximalGradientDescentAttr func ( optionalAttr ) <nl> + <nl> + / / ResourceApplyProximalGradientDescentUseLocking sets the optional use_locking attribute to value . <nl> + / / <nl> + / / value : If True , the subtraction will be protected by a lock ; <nl> + / / otherwise the behavior is undefined , but may exhibit less contention . <nl> + / / If not specified , defaults to false <nl> + func ResourceApplyProximalGradientDescentUseLocking ( value bool ) ResourceApplyProximalGradientDescentAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " use_locking " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Update ' * var ' as FOBOS algorithm with fixed learning rate . <nl> + / / <nl> + / / prox_v = var - alpha * delta <nl> + / / var = sign ( prox_v ) / ( 1 + alpha * l2 ) * max { | prox_v | - alpha * l1 , 0 } <nl> + / / <nl> + / / Arguments : <nl> + / / var_ : Should be from a Variable ( ) . <nl> + / / alpha : Scaling factor . Must be a scalar . <nl> + / / l1 : L1 regularization . Must be a scalar . <nl> + / / l2 : L2 regularization . Must be a scalar . <nl> + / / delta : The change . <nl> + / / <nl> + / / Returns the created operation . <nl> + func ResourceApplyProximalGradientDescent ( scope * Scope , var_ tf . Output , alpha tf . Output , l1 tf . Output , l2 tf . Output , delta tf . Output , optional . . . ResourceApplyProximalGradientDescentAttr ) ( o * tf . Operation ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> func AsString ( scope * Scope , input tf . Output , optional . . . AsStringAttr ) ( output t <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / StringSplitAttr is an optional argument to StringSplit . <nl> - type StringSplitAttr func ( optionalAttr ) <nl> - <nl> - / / StringSplitSkipEmpty sets the optional skip_empty attribute to value . <nl> - / / <nl> - / / value : A ` bool ` . If ` True ` , skip the empty strings from the result . <nl> - / / If not specified , defaults to true <nl> - func StringSplitSkipEmpty ( value bool ) StringSplitAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " skip_empty " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Split elements of ` input ` based on ` delimiter ` into a ` SparseTensor ` . <nl> + / / Assigns sparse updates to the variable referenced by ` resource ` . <nl> / / <nl> - / / Let N be the size of source ( typically N will be the batch size ) . Split each <nl> - / / element of ` input ` based on ` delimiter ` and return a ` SparseTensor ` <nl> - / / containing the splitted tokens . Empty tokens are ignored . <nl> + / / This operation computes <nl> / / <nl> - / / ` delimiter ` can be empty , or a string of split characters . If ` delimiter ` is an <nl> - / / empty string , each element of ` input ` is split into individual single - byte <nl> - / / character strings , including splitting of UTF - 8 multibyte sequences . Otherwise <nl> - / / every character of ` delimiter ` is a potential split point . <nl> + / / # Scalar indices <nl> + / / ref [ indices , . . . ] = updates [ . . . ] <nl> / / <nl> - / / For example : <nl> - / / N = 2 , input [ 0 ] is ' hello world ' and input [ 1 ] is ' a b c ' , then the output <nl> - / / will be <nl> + / / # Vector indices ( for each i ) <nl> + / / ref [ indices [ i ] , . . . ] = updates [ i , . . . ] <nl> / / <nl> - / / indices = [ 0 , 0 ; <nl> - / / 0 , 1 ; <nl> - / / 1 , 0 ; <nl> - / / 1 , 1 ; <nl> - / / 1 , 2 ] <nl> - / / shape = [ 2 , 3 ] <nl> - / / values = [ ' hello ' , ' world ' , ' a ' , ' b ' , ' c ' ] <nl> + / / # High rank indices ( for each i , . . . , j ) <nl> + / / ref [ indices [ i , . . . , j ] , . . . ] = updates [ i , . . . , j , . . . ] <nl> / / <nl> / / Arguments : <nl> - / / input : 1 - D . Strings to split . <nl> - / / delimiter : 0 - D . Delimiter characters ( bytes ) , or empty string . <nl> + / / resource : Should be from a ` Variable ` node . <nl> + / / indices : A tensor of indices into the first dimension of ` ref ` . <nl> + / / updates : A tensor of updated values to add to ` ref ` . <nl> / / <nl> - / / Returns A dense matrix of int64 representing the indices of the sparse tensor . A vector of strings corresponding to the splited values . a length - 2 vector of int64 representing the shape of the sparse <nl> - / / tensor , where the first value is N and the second value is the maximum number <nl> - / / of tokens in a single input entry . <nl> - func StringSplit ( scope * Scope , input tf . Output , delimiter tf . Output , optional . . . StringSplitAttr ) ( indices tf . Output , values tf . Output , shape tf . Output ) { <nl> + / / Returns the created operation . <nl> + func ResourceScatterUpdate ( scope * Scope , resource tf . Output , indices tf . Output , updates tf . Output ) ( o * tf . Operation ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> opspec : = tf . OpSpec { <nl> - Type : " StringSplit " , <nl> + Type : " ResourceScatterUpdate " , <nl> Input : [ ] tf . Input { <nl> - input , delimiter , <nl> + resource , indices , updates , <nl> } , <nl> - Attrs : attrs , <nl> } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) , op . Output ( 1 ) , op . Output ( 2 ) <nl> + return scope . AddOperation ( opspec ) <nl> } <nl> <nl> - / / Inverse 3D real - valued fast Fourier transform . <nl> + / / Given a path to new and old vocabulary files , returns a remapping Tensor of <nl> / / <nl> - / / Computes the inverse 3 - dimensional discrete Fourier transform of a real - valued <nl> - / / signal over the inner - most 3 dimensions of ` input ` . <nl> + / / length ` num_new_vocab ` , where ` remapping [ i ] ` contains the row number in the old <nl> + / / vocabulary that corresponds to row ` i ` in the new vocabulary ( starting at line <nl> + / / ` new_vocab_offset ` and up to ` num_new_vocab ` entities ) , or ` - 1 ` if entry ` i ` <nl> + / / in the new vocabulary is not in the old vocabulary . ` num_vocab_offset ` enables <nl> + / / use in the partitioned variable case , and should generally be set through <nl> + / / examining partitioning info . The format of the files should be a text file , <nl> + / / with each line containing a single entity within the vocabulary . <nl> / / <nl> - / / The inner - most 3 dimensions of ` input ` are assumed to be the result of ` RFFT3D ` : <nl> - / / The inner - most dimension contains the ` fft_length / 2 + 1 ` unique components of <nl> - / / the DFT of a real - valued signal . If ` fft_length ` is not provided , it is computed <nl> - / / from the size of the inner - most 3 dimensions of ` input ` . If the FFT length used <nl> - / / to compute ` input ` is odd , it should be provided since it cannot be inferred <nl> - / / properly . <nl> + / / For example , with ` new_vocab_file ` a text file containing each of the following <nl> + / / elements on a single line : ` [ f0 , f1 , f2 , f3 ] ` , old_vocab_file = [ f1 , f0 , f3 ] , <nl> + / / ` num_new_vocab = 3 , new_vocab_offset = 1 ` , the returned remapping would be <nl> + / / ` [ 0 , - 1 , 2 ] ` . <nl> / / <nl> - / / Along each axis ` IRFFT3D ` is computed on , if ` fft_length ` ( or <nl> - / / ` fft_length / 2 + 1 ` for the inner - most dimension ) is smaller than the <nl> - / / corresponding dimension of ` input ` , the dimension is cropped . If it is larger , <nl> + / / The op also returns a count of how many entries in the new vocabulary <nl> + / / were present in the old vocabulary , which is used to calculate the number of <nl> + / / values to initialize in a weight matrix remapping <nl> + / / <nl> + / / This functionality can be used to remap both row vocabularies ( typically , <nl> + / / features ) and column vocabularies ( typically , classes ) from TensorFlow <nl> + / / checkpoints . Note that the partitioning logic relies on contiguous vocabularies <nl> + / / corresponding to div - partitioned variables . Moreover , the underlying remapping <nl> + / / uses an IndexTable ( as opposed to an inexact CuckooTable ) , so client code should <nl> + / / use the corresponding index_table_from_file ( ) as the FeatureColumn framework <nl> + / / does ( as opposed to tf . feature_to_id ( ) , which uses a CuckooTable ) . <nl> + / / <nl> + / / Arguments : <nl> + / / new_vocab_file : Path to the new vocab file . <nl> + / / old_vocab_file : Path to the old vocab file . <nl> + / / new_vocab_offset : How many entries into the new vocab file to start reading . <nl> + / / num_new_vocab : Number of entries in the new vocab file to remap . <nl> + / / <nl> + / / Returns A Tensor of length num_new_vocab where the element at index i <nl> + / / is equal to the old ID that maps to the new ID i . This element is - 1 for any <nl> + / / new ID that is not found in the old vocabulary . Number of new vocab entries found in old vocab . <nl> + func GenerateVocabRemapping ( scope * Scope , new_vocab_file tf . Output , old_vocab_file tf . Output , new_vocab_offset int64 , num_new_vocab int64 ) ( remapping tf . Output , num_present tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { " new_vocab_offset " : new_vocab_offset , " num_new_vocab " : num_new_vocab } <nl> + opspec : = tf . OpSpec { <nl> + Type : " GenerateVocabRemapping " , <nl> + Input : [ ] tf . Input { <nl> + new_vocab_file , old_vocab_file , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) , op . Output ( 1 ) <nl> + } <nl> + <nl> + / / Computes softsign : ` features / ( abs ( features ) + 1 ) ` . <nl> + func Softsign ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " Softsign " , <nl> + Input : [ ] tf . Input { <nl> + features , <nl> + } , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / ResizeBilinearAttr is an optional argument to ResizeBilinear . <nl> + type ResizeBilinearAttr func ( optionalAttr ) <nl> + <nl> + / / ResizeBilinearAlignCorners sets the optional align_corners attribute to value . <nl> + / / <nl> + / / value : If true , rescale input by ( new_height - 1 ) / ( height - 1 ) , which <nl> + / / exactly aligns the 4 corners of images and resized images . If false , rescale <nl> + / / by new_height / height . Treat similarly the width dimension . <nl> + / / If not specified , defaults to false <nl> + func ResizeBilinearAlignCorners ( value bool ) ResizeBilinearAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " align_corners " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Resize ` images ` to ` size ` using bilinear interpolation . <nl> + / / <nl> + / / Input images can be of different types but output images are always float . <nl> + / / <nl> + / / Arguments : <nl> + / / images : 4 - D with shape ` [ batch , height , width , channels ] ` . <nl> + / / size : = A 1 - D int32 Tensor of 2 elements : ` new_height , new_width ` . The <nl> + / / new size for the images . <nl> + / / <nl> + / / Returns 4 - D with shape <nl> + / / ` [ batch , new_height , new_width , channels ] ` . <nl> + func ResizeBilinear ( scope * Scope , images tf . Output , size tf . Output , optional . . . ResizeBilinearAttr ) ( resized_images tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " ResizeBilinear " , <nl> + Input : [ ] tf . Input { <nl> + images , size , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / ProdAttr is an optional argument to Prod . <nl> + type ProdAttr func ( optionalAttr ) <nl> + <nl> + / / ProdKeepDims sets the optional keep_dims attribute to value . <nl> + / / <nl> + / / value : If true , retain reduced dimensions with length 1 . <nl> + / / If not specified , defaults to false <nl> + func ProdKeepDims ( value bool ) ProdAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " keep_dims " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Computes the product of elements across dimensions of a tensor . <nl> + / / <nl> + / / Reduces ` input ` along the dimensions given in ` reduction_indices ` . Unless <nl> + / / ` keep_dims ` is true , the rank of the tensor is reduced by 1 for each entry in <nl> + / / ` reduction_indices ` . If ` keep_dims ` is true , the reduced dimensions are <nl> + / / retained with length 1 . <nl> + / / <nl> + / / Arguments : <nl> + / / input : The tensor to reduce . <nl> + / / reduction_indices : The dimensions to reduce . Must be in the range <nl> + / / ` [ - rank ( input ) , rank ( input ) ) ` . <nl> + / / <nl> + / / Returns The reduced tensor . <nl> + func Prod ( scope * Scope , input tf . Output , reduction_indices tf . Output , optional . . . ProdAttr ) ( output tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " Prod " , <nl> + Input : [ ] tf . Input { <nl> + input , reduction_indices , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / StringSplitAttr is an optional argument to StringSplit . <nl> + type StringSplitAttr func ( optionalAttr ) <nl> + <nl> + / / StringSplitSkipEmpty sets the optional skip_empty attribute to value . <nl> + / / <nl> + / / value : A ` bool ` . If ` True ` , skip the empty strings from the result . <nl> + / / If not specified , defaults to true <nl> + func StringSplitSkipEmpty ( value bool ) StringSplitAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " skip_empty " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Split elements of ` input ` based on ` delimiter ` into a ` SparseTensor ` . <nl> + / / <nl> + / / Let N be the size of source ( typically N will be the batch size ) . Split each <nl> + / / element of ` input ` based on ` delimiter ` and return a ` SparseTensor ` <nl> + / / containing the splitted tokens . Empty tokens are ignored . <nl> + / / <nl> + / / ` delimiter ` can be empty , or a string of split characters . If ` delimiter ` is an <nl> + / / empty string , each element of ` input ` is split into individual single - byte <nl> + / / character strings , including splitting of UTF - 8 multibyte sequences . Otherwise <nl> + / / every character of ` delimiter ` is a potential split point . <nl> + / / <nl> + / / For example : <nl> + / / N = 2 , input [ 0 ] is ' hello world ' and input [ 1 ] is ' a b c ' , then the output <nl> + / / will be <nl> + / / <nl> + / / indices = [ 0 , 0 ; <nl> + / / 0 , 1 ; <nl> + / / 1 , 0 ; <nl> + / / 1 , 1 ; <nl> + / / 1 , 2 ] <nl> + / / shape = [ 2 , 3 ] <nl> + / / values = [ ' hello ' , ' world ' , ' a ' , ' b ' , ' c ' ] <nl> + / / <nl> + / / Arguments : <nl> + / / input : 1 - D . Strings to split . <nl> + / / delimiter : 0 - D . Delimiter characters ( bytes ) , or empty string . <nl> + / / <nl> + / / Returns A dense matrix of int64 representing the indices of the sparse tensor . A vector of strings corresponding to the splited values . a length - 2 vector of int64 representing the shape of the sparse <nl> + / / tensor , where the first value is N and the second value is the maximum number <nl> + / / of tokens in a single input entry . <nl> + func StringSplit ( scope * Scope , input tf . Output , delimiter tf . Output , optional . . . StringSplitAttr ) ( indices tf . Output , values tf . Output , shape tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " StringSplit " , <nl> + Input : [ ] tf . Input { <nl> + input , delimiter , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) , op . Output ( 1 ) , op . Output ( 2 ) <nl> + } <nl> + <nl> + / / Inverse 3D real - valued fast Fourier transform . <nl> + / / <nl> + / / Computes the inverse 3 - dimensional discrete Fourier transform of a real - valued <nl> + / / signal over the inner - most 3 dimensions of ` input ` . <nl> + / / <nl> + / / The inner - most 3 dimensions of ` input ` are assumed to be the result of ` RFFT3D ` : <nl> + / / The inner - most dimension contains the ` fft_length / 2 + 1 ` unique components of <nl> + / / the DFT of a real - valued signal . If ` fft_length ` is not provided , it is computed <nl> + / / from the size of the inner - most 3 dimensions of ` input ` . If the FFT length used <nl> + / / to compute ` input ` is odd , it should be provided since it cannot be inferred <nl> + / / properly . <nl> + / / <nl> + / / Along each axis ` IRFFT3D ` is computed on , if ` fft_length ` ( or <nl> + / / ` fft_length / 2 + 1 ` for the inner - most dimension ) is smaller than the <nl> + / / corresponding dimension of ` input ` , the dimension is cropped . If it is larger , <nl> / / the dimension is padded with zeros . <nl> / / <nl> / / Arguments : <nl> func PadV2 ( scope * Scope , input tf . Output , paddings tf . Output , constant_values tf <nl> / / <nl> / / Arguments : <nl> / / gradients : The backpropagated gradients to the corresponding Selu operation . <nl> - / / outputs : The outputs of the corresponding Selu operation . <nl> - / / <nl> - / / Returns The gradients : ` gradients * ( outputs + scale * alpha ) ` <nl> - / / if outputs < 0 , ` scale * gradients ` otherwise . <nl> - func SeluGrad ( scope * Scope , gradients tf . Output , outputs tf . Output ) ( backprops tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " SeluGrad " , <nl> - Input : [ ] tf . Input { <nl> - gradients , outputs , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / Computes softplus : ` log ( exp ( features ) + 1 ) ` . <nl> - func Softplus ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " Softplus " , <nl> - Input : [ ] tf . Input { <nl> - features , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / BatchMatMulAttr is an optional argument to BatchMatMul . <nl> - type BatchMatMulAttr func ( optionalAttr ) <nl> - <nl> - / / BatchMatMulAdjX sets the optional adj_x attribute to value . <nl> - / / <nl> - / / value : If ` True ` , adjoint the slices of ` x ` . Defaults to ` False ` . <nl> - / / If not specified , defaults to false <nl> - func BatchMatMulAdjX ( value bool ) BatchMatMulAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " adj_x " ] = value <nl> - } <nl> - } <nl> - <nl> - / / BatchMatMulAdjY sets the optional adj_y attribute to value . <nl> - / / <nl> - / / value : If ` True ` , adjoint the slices of ` y ` . Defaults to ` False ` . <nl> - / / If not specified , defaults to false <nl> - func BatchMatMulAdjY ( value bool ) BatchMatMulAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " adj_y " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Multiplies slices of two tensors in batches . <nl> - / / <nl> - / / Multiplies all slices of ` Tensor ` ` x ` and ` y ` ( each slice can be <nl> - / / viewed as an element of a batch ) , and arranges the individual results <nl> - / / in a single output tensor of the same batch size . Each of the <nl> - / / individual slices can optionally be adjointed ( to adjoint a matrix <nl> - / / means to transpose and conjugate it ) before multiplication by setting <nl> - / / the ` adj_x ` or ` adj_y ` flag to ` True ` , which are by default ` False ` . <nl> - / / <nl> - / / The input tensors ` x ` and ` y ` are 2 - D or higher with shape ` [ . . . , r_x , c_x ] ` <nl> - / / and ` [ . . . , r_y , c_y ] ` . <nl> - / / <nl> - / / The output tensor is 2 - D or higher with shape ` [ . . . , r_o , c_o ] ` , where : <nl> - / / <nl> - / / r_o = c_x if adj_x else r_x <nl> - / / c_o = r_y if adj_y else c_y <nl> - / / <nl> - / / It is computed as : <nl> - / / <nl> - / / output [ . . . , : , : ] = matrix ( x [ . . . , : , : ] ) * matrix ( y [ . . . , : , : ] ) <nl> - / / <nl> - / / Arguments : <nl> - / / x : 2 - D or higher with shape ` [ . . . , r_x , c_x ] ` . <nl> - / / y : 2 - D or higher with shape ` [ . . . , r_y , c_y ] ` . <nl> - / / <nl> - / / Returns 3 - D or higher with shape ` [ . . . , r_o , c_o ] ` <nl> - func BatchMatMul ( scope * Scope , x tf . Output , y tf . Output , optional . . . BatchMatMulAttr ) ( output tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " BatchMatMul " , <nl> - Input : [ ] tf . Input { <nl> - x , y , <nl> - } , <nl> - Attrs : attrs , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / Computes softplus gradients for a softplus operation . <nl> - / / <nl> - / / Arguments : <nl> - / / gradients : The backpropagated gradients to the corresponding softplus operation . <nl> - / / features : The features passed as input to the corresponding softplus operation . <nl> - / / <nl> - / / Returns The gradients : ` gradients / ( 1 + exp ( - features ) ) ` . <nl> - func SoftplusGrad ( scope * Scope , gradients tf . Output , features tf . Output ) ( backprops tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " SoftplusGrad " , <nl> - Input : [ ] tf . Input { <nl> - gradients , features , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / Given a path to new and old vocabulary files , returns a remapping Tensor of <nl> - / / <nl> - / / length ` num_new_vocab ` , where ` remapping [ i ] ` contains the row number in the old <nl> - / / vocabulary that corresponds to row ` i ` in the new vocabulary ( starting at line <nl> - / / ` new_vocab_offset ` and up to ` num_new_vocab ` entities ) , or ` - 1 ` if entry ` i ` <nl> - / / in the new vocabulary is not in the old vocabulary . ` num_vocab_offset ` enables <nl> - / / use in the partitioned variable case , and should generally be set through <nl> - / / examining partitioning info . The format of the files should be a text file , <nl> - / / with each line containing a single entity within the vocabulary . <nl> - / / <nl> - / / For example , with ` new_vocab_file ` a text file containing each of the following <nl> - / / elements on a single line : ` [ f0 , f1 , f2 , f3 ] ` , old_vocab_file = [ f1 , f0 , f3 ] , <nl> - / / ` num_new_vocab = 3 , new_vocab_offset = 1 ` , the returned remapping would be <nl> - / / ` [ 0 , - 1 , 2 ] ` . <nl> - / / <nl> - / / The op also returns a count of how many entries in the new vocabulary <nl> - / / were present in the old vocabulary , which is used to calculate the number of <nl> - / / values to initialize in a weight matrix remapping <nl> - / / <nl> - / / This functionality can be used to remap both row vocabularies ( typically , <nl> - / / features ) and column vocabularies ( typically , classes ) from TensorFlow <nl> - / / checkpoints . Note that the partitioning logic relies on contiguous vocabularies <nl> - / / corresponding to div - partitioned variables . Moreover , the underlying remapping <nl> - / / uses an IndexTable ( as opposed to an inexact CuckooTable ) , so client code should <nl> - / / use the corresponding index_table_from_file ( ) as the FeatureColumn framework <nl> - / / does ( as opposed to tf . feature_to_id ( ) , which uses a CuckooTable ) . <nl> - / / <nl> - / / Arguments : <nl> - / / new_vocab_file : Path to the new vocab file . <nl> - / / old_vocab_file : Path to the old vocab file . <nl> - / / new_vocab_offset : How many entries into the new vocab file to start reading . <nl> - / / num_new_vocab : Number of entries in the new vocab file to remap . <nl> - / / <nl> - / / Returns A Tensor of length num_new_vocab where the element at index i <nl> - / / is equal to the old ID that maps to the new ID i . This element is - 1 for any <nl> - / / new ID that is not found in the old vocabulary . Number of new vocab entries found in old vocab . <nl> - func GenerateVocabRemapping ( scope * Scope , new_vocab_file tf . Output , old_vocab_file tf . Output , new_vocab_offset int64 , num_new_vocab int64 ) ( remapping tf . Output , num_present tf . Output ) { <nl> + / / outputs : The outputs of the corresponding Selu operation . <nl> + / / <nl> + / / Returns The gradients : ` gradients * ( outputs + scale * alpha ) ` <nl> + / / if outputs < 0 , ` scale * gradients ` otherwise . <nl> + func SeluGrad ( scope * Scope , gradients tf . Output , outputs tf . Output ) ( backprops tf . Output ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> - attrs : = map [ string ] interface { } { " new_vocab_offset " : new_vocab_offset , " num_new_vocab " : num_new_vocab } <nl> opspec : = tf . OpSpec { <nl> - Type : " GenerateVocabRemapping " , <nl> + Type : " SeluGrad " , <nl> Input : [ ] tf . Input { <nl> - new_vocab_file , old_vocab_file , <nl> + gradients , outputs , <nl> } , <nl> - Attrs : attrs , <nl> } <nl> op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) , op . Output ( 1 ) <nl> + return op . Output ( 0 ) <nl> } <nl> <nl> - / / Computes softsign : ` features / ( abs ( features ) + 1 ) ` . <nl> - func Softsign ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> + / / Computes softplus : ` log ( exp ( features ) + 1 ) ` . <nl> + func Softplus ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> opspec : = tf . OpSpec { <nl> - Type : " Softsign " , <nl> + Type : " Softplus " , <nl> Input : [ ] tf . Input { <nl> features , <nl> } , <nl> func Softsign ( scope * Scope , features tf . Output ) ( activations tf . Output ) { <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / ResizeBilinearAttr is an optional argument to ResizeBilinear . <nl> - type ResizeBilinearAttr func ( optionalAttr ) <nl> + / / BatchMatMulAttr is an optional argument to BatchMatMul . <nl> + type BatchMatMulAttr func ( optionalAttr ) <nl> <nl> - / / ResizeBilinearAlignCorners sets the optional align_corners attribute to value . <nl> + / / BatchMatMulAdjX sets the optional adj_x attribute to value . <nl> / / <nl> - / / value : If true , rescale input by ( new_height - 1 ) / ( height - 1 ) , which <nl> - / / exactly aligns the 4 corners of images and resized images . If false , rescale <nl> - / / by new_height / height . Treat similarly the width dimension . <nl> + / / value : If ` True ` , adjoint the slices of ` x ` . Defaults to ` False ` . <nl> / / If not specified , defaults to false <nl> - func ResizeBilinearAlignCorners ( value bool ) ResizeBilinearAttr { <nl> + func BatchMatMulAdjX ( value bool ) BatchMatMulAttr { <nl> return func ( m optionalAttr ) { <nl> - m [ " align_corners " ] = value <nl> + m [ " adj_x " ] = value <nl> } <nl> } <nl> <nl> - / / Resize ` images ` to ` size ` using bilinear interpolation . <nl> + / / BatchMatMulAdjY sets the optional adj_y attribute to value . <nl> / / <nl> - / / Input images can be of different types but output images are always float . <nl> + / / value : If ` True ` , adjoint the slices of ` y ` . Defaults to ` False ` . <nl> + / / If not specified , defaults to false <nl> + func BatchMatMulAdjY ( value bool ) BatchMatMulAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " adj_y " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Multiplies slices of two tensors in batches . <nl> + / / <nl> + / / Multiplies all slices of ` Tensor ` ` x ` and ` y ` ( each slice can be <nl> + / / viewed as an element of a batch ) , and arranges the individual results <nl> + / / in a single output tensor of the same batch size . Each of the <nl> + / / individual slices can optionally be adjointed ( to adjoint a matrix <nl> + / / means to transpose and conjugate it ) before multiplication by setting <nl> + / / the ` adj_x ` or ` adj_y ` flag to ` True ` , which are by default ` False ` . <nl> + / / <nl> + / / The input tensors ` x ` and ` y ` are 2 - D or higher with shape ` [ . . . , r_x , c_x ] ` <nl> + / / and ` [ . . . , r_y , c_y ] ` . <nl> + / / <nl> + / / The output tensor is 2 - D or higher with shape ` [ . . . , r_o , c_o ] ` , where : <nl> + / / <nl> + / / r_o = c_x if adj_x else r_x <nl> + / / c_o = r_y if adj_y else c_y <nl> + / / <nl> + / / It is computed as : <nl> + / / <nl> + / / output [ . . . , : , : ] = matrix ( x [ . . . , : , : ] ) * matrix ( y [ . . . , : , : ] ) <nl> / / <nl> / / Arguments : <nl> - / / images : 4 - D with shape ` [ batch , height , width , channels ] ` . <nl> - / / size : = A 1 - D int32 Tensor of 2 elements : ` new_height , new_width ` . The <nl> - / / new size for the images . <nl> + / / x : 2 - D or higher with shape ` [ . . . , r_x , c_x ] ` . <nl> + / / y : 2 - D or higher with shape ` [ . . . , r_y , c_y ] ` . <nl> / / <nl> - / / Returns 4 - D with shape <nl> - / / ` [ batch , new_height , new_width , channels ] ` . <nl> - func ResizeBilinear ( scope * Scope , images tf . Output , size tf . Output , optional . . . ResizeBilinearAttr ) ( resized_images tf . Output ) { <nl> + / / Returns 3 - D or higher with shape ` [ . . . , r_o , c_o ] ` <nl> + func BatchMatMul ( scope * Scope , x tf . Output , y tf . Output , optional . . . BatchMatMulAttr ) ( output tf . Output ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> func ResizeBilinear ( scope * Scope , images tf . Output , size tf . Output , optional . . . <nl> a ( attrs ) <nl> } <nl> opspec : = tf . OpSpec { <nl> - Type : " ResizeBilinear " , <nl> + Type : " BatchMatMul " , <nl> Input : [ ] tf . Input { <nl> - images , size , <nl> + x , y , <nl> } , <nl> Attrs : attrs , <nl> } <nl> func ResizeBilinear ( scope * Scope , images tf . Output , size tf . Output , optional . . . <nl> return op . Output ( 0 ) <nl> } <nl> <nl> - / / ProdAttr is an optional argument to Prod . <nl> - type ProdAttr func ( optionalAttr ) <nl> - <nl> - / / ProdKeepDims sets the optional keep_dims attribute to value . <nl> - / / <nl> - / / value : If true , retain reduced dimensions with length 1 . <nl> - / / If not specified , defaults to false <nl> - func ProdKeepDims ( value bool ) ProdAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " keep_dims " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Computes the product of elements across dimensions of a tensor . <nl> - / / <nl> - / / Reduces ` input ` along the dimensions given in ` reduction_indices ` . Unless <nl> - / / ` keep_dims ` is true , the rank of the tensor is reduced by 1 for each entry in <nl> - / / ` reduction_indices ` . If ` keep_dims ` is true , the reduced dimensions are <nl> - / / retained with length 1 . <nl> + / / Computes softplus gradients for a softplus operation . <nl> / / <nl> / / Arguments : <nl> - / / input : The tensor to reduce . <nl> - / / reduction_indices : The dimensions to reduce . Must be in the range <nl> - / / ` [ - rank ( input ) , rank ( input ) ) ` . <nl> + / / gradients : The backpropagated gradients to the corresponding softplus operation . <nl> + / / features : The features passed as input to the corresponding softplus operation . <nl> / / <nl> - / / Returns The reduced tensor . <nl> - func Prod ( scope * Scope , input tf . Output , reduction_indices tf . Output , optional . . . ProdAttr ) ( output tf . Output ) { <nl> + / / Returns The gradients : ` gradients / ( 1 + exp ( - features ) ) ` . <nl> + func SoftplusGrad ( scope * Scope , gradients tf . Output , features tf . Output ) ( backprops tf . Output ) { <nl> if scope . Err ( ) ! = nil { <nl> return <nl> } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> opspec : = tf . OpSpec { <nl> - Type : " Prod " , <nl> + Type : " SoftplusGrad " , <nl> Input : [ ] tf . Input { <nl> - input , reduction_indices , <nl> + gradients , features , <nl> } , <nl> - Attrs : attrs , <nl> } <nl> op : = scope . AddOperation ( opspec ) <nl> return op . Output ( 0 ) <nl> func Sqrt ( scope * Scope , x tf . Output ) ( y tf . Output ) { <nl> return op . Output ( 0 ) <nl> } <nl> <nl> + / / MatrixInverseAttr is an optional argument to MatrixInverse . <nl> + type MatrixInverseAttr func ( optionalAttr ) <nl> + <nl> + / / MatrixInverseAdjoint sets the optional adjoint attribute to value . <nl> + / / If not specified , defaults to false <nl> + func MatrixInverseAdjoint ( value bool ) MatrixInverseAttr { <nl> + return func ( m optionalAttr ) { <nl> + m [ " adjoint " ] = value <nl> + } <nl> + } <nl> + <nl> + / / Computes the inverse of one or more square invertible matrices or their <nl> + / / <nl> + / / adjoints ( conjugate transposes ) . <nl> + / / <nl> + / / The input is a tensor of shape ` [ . . . , M , M ] ` whose inner - most 2 dimensions <nl> + / / form square matrices . The output is a tensor of the same shape as the input <nl> + / / containing the inverse for all input submatrices ` [ . . . , : , : ] ` . <nl> + / / <nl> + / / The op uses LU decomposition with partial pivoting to compute the inverses . <nl> + / / <nl> + / / If a matrix is not invertible there is no guarantee what the op does . It <nl> + / / may detect the condition and raise an exception or it may simply return a <nl> + / / garbage result . <nl> + / / <nl> + / / Arguments : <nl> + / / input : Shape is ` [ . . . , M , M ] ` . <nl> + / / <nl> + / / Returns Shape is ` [ . . . , M , M ] ` . <nl> + / / <nl> + / / @ compatibility ( numpy ) <nl> + / / Equivalent to np . linalg . inv <nl> + / / @ end_compatibility <nl> + func MatrixInverse ( scope * Scope , input tf . Output , optional . . . MatrixInverseAttr ) ( output tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + attrs : = map [ string ] interface { } { } <nl> + for _ , a : = range optional { <nl> + a ( attrs ) <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " MatrixInverse " , <nl> + Input : [ ] tf . Input { <nl> + input , <nl> + } , <nl> + Attrs : attrs , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> + / / Computes the gradient for the sqrt of ` x ` wrt its input . <nl> + / / <nl> + / / Specifically , ` grad = dy * 0 . 5 / y ` , where ` y = sqrt ( x ) ` , and ` dy ` <nl> + / / is the corresponding input gradient . <nl> + func SqrtGrad ( scope * Scope , y tf . Output , dy tf . Output ) ( z tf . Output ) { <nl> + if scope . Err ( ) ! = nil { <nl> + return <nl> + } <nl> + opspec : = tf . OpSpec { <nl> + Type : " SqrtGrad " , <nl> + Input : [ ] tf . Input { <nl> + y , dy , <nl> + } , <nl> + } <nl> + op : = scope . AddOperation ( opspec ) <nl> + return op . Output ( 0 ) <nl> + } <nl> + <nl> / / Inserts a dimension of 1 into a tensor ' s shape . <nl> / / <nl> / / Given a tensor ` input ` , this operation inserts a dimension of 1 at the <nl> func AudioSummaryV2 ( scope * Scope , tag tf . Output , tensor tf . Output , sample_rate t <nl> op : = scope . AddOperation ( opspec ) <nl> return op . Output ( 0 ) <nl> } <nl> - <nl> - / / Computes the gradient for the sqrt of ` x ` wrt its input . <nl> - / / <nl> - / / Specifically , ` grad = dy * 0 . 5 / y ` , where ` y = sqrt ( x ) ` , and ` dy ` <nl> - / / is the corresponding input gradient . <nl> - func SqrtGrad ( scope * Scope , y tf . Output , dy tf . Output ) ( z tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " SqrtGrad " , <nl> - Input : [ ] tf . Input { <nl> - y , dy , <nl> - } , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl> - <nl> - / / MatrixInverseAttr is an optional argument to MatrixInverse . <nl> - type MatrixInverseAttr func ( optionalAttr ) <nl> - <nl> - / / MatrixInverseAdjoint sets the optional adjoint attribute to value . <nl> - / / If not specified , defaults to false <nl> - func MatrixInverseAdjoint ( value bool ) MatrixInverseAttr { <nl> - return func ( m optionalAttr ) { <nl> - m [ " adjoint " ] = value <nl> - } <nl> - } <nl> - <nl> - / / Computes the inverse of one or more square invertible matrices or their <nl> - / / <nl> - / / adjoints ( conjugate transposes ) . <nl> - / / <nl> - / / The input is a tensor of shape ` [ . . . , M , M ] ` whose inner - most 2 dimensions <nl> - / / form square matrices . The output is a tensor of the same shape as the input <nl> - / / containing the inverse for all input submatrices ` [ . . . , : , : ] ` . <nl> - / / <nl> - / / The op uses LU decomposition with partial pivoting to compute the inverses . <nl> - / / <nl> - / / If a matrix is not invertible there is no guarantee what the op does . It <nl> - / / may detect the condition and raise an exception or it may simply return a <nl> - / / garbage result . <nl> - / / <nl> - / / Arguments : <nl> - / / input : Shape is ` [ . . . , M , M ] ` . <nl> - / / <nl> - / / Returns Shape is ` [ . . . , M , M ] ` . <nl> - / / <nl> - / / @ compatibility ( numpy ) <nl> - / / Equivalent to np . linalg . inv <nl> - / / @ end_compatibility <nl> - func MatrixInverse ( scope * Scope , input tf . Output , optional . . . MatrixInverseAttr ) ( output tf . Output ) { <nl> - if scope . Err ( ) ! = nil { <nl> - return <nl> - } <nl> - attrs : = map [ string ] interface { } { } <nl> - for _ , a : = range optional { <nl> - a ( attrs ) <nl> - } <nl> - opspec : = tf . OpSpec { <nl> - Type : " MatrixInverse " , <nl> - Input : [ ] tf . Input { <nl> - input , <nl> - } , <nl> - Attrs : attrs , <nl> - } <nl> - op : = scope . AddOperation ( opspec ) <nl> - return op . Output ( 0 ) <nl> - } <nl>
Go : Update generated wrapper functions for TensorFlow ops .
tensorflow/tensorflow
558f146e1d84a6dbca5282dfeefdbd6312eb97ba
2017-10-30T23:20:11Z
mmm a / test / common / test_common . py <nl> ppp b / test / common / test_common . py <nl> def __init__ ( self , opts , test_dir ) : <nl> get_executable_path ( opts , " rethinkdb " ) , " create " , " - - force " , <nl> " - s " , str ( self . opts [ " slices " ] ) , <nl> " - c " , str ( self . opts [ " cores " ] ) , <nl> - ] + self . rethinkdb_flags ( ) , <nl> + ] + ( [ " - - extent - size " , " 1048576 " ] if self . opts [ " valgrind " ] else [ ] ) + self . rethinkdb_flags ( ) , <nl> " creator_output " , <nl> timeout = 30 , <nl> valgrind_tool = self . opts [ " valgrind - tool " ] if self . opts [ " valgrind " ] else None , <nl> test_dir = self . test_dir <nl> ) <nl> - <nl> + <nl> def rethinkdb_flags ( self ) : <nl> flags = [ ] <nl> for file in self . files : <nl>
Sets extent size to 1MB for when valgrind is on , in tests .
rethinkdb/rethinkdb
9453c400876ad884e6576d67791a35b320431245
2011-01-06T23:34:01Z
mmm a / build / cocos2d_libs . xcodeproj / project . pbxproj <nl> ppp b / build / cocos2d_libs . xcodeproj / project . pbxproj <nl> <nl> / * End PBXAggregateTarget section * / <nl> <nl> / * Begin PBXBuildFile section * / <nl> - 06C0F2EF186AD822003594D5 / * ObjectFactory . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 06CAAABA186AD63B0012A414 / * ObjectFactory . cpp * / ; } ; <nl> - 06C0F2F0186AD824003594D5 / * ObjectFactory . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 06CAAABA186AD63B0012A414 / * ObjectFactory . cpp * / ; } ; <nl> 06CAAAC5186AD7E50012A414 / * TriggerObj . h in Headers * / = { isa = PBXBuildFile ; fileRef = 06CAAAC1186AD63B0012A414 / * TriggerObj . h * / ; } ; <nl> 06CAAAC6186AD7E60012A414 / * TriggerObj . h in Headers * / = { isa = PBXBuildFile ; fileRef = 06CAAAC1186AD63B0012A414 / * TriggerObj . h * / ; } ; <nl> 06CAAAC7186AD7E90012A414 / * TriggerObj . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 06CAAAC0186AD63B0012A414 / * TriggerObj . cpp * / ; } ; <nl> <nl> 06CAAACE186AD7FA0012A414 / * TriggerBase . h in Headers * / = { isa = PBXBuildFile ; fileRef = 06CAAABD186AD63B0012A414 / * TriggerBase . h * / ; } ; <nl> 06CAAACF186AD7FC0012A414 / * TriggerBase . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 06CAAABC186AD63B0012A414 / * TriggerBase . cpp * / ; } ; <nl> 06CAAAD0186AD7FE0012A414 / * TriggerBase . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 06CAAABC186AD63B0012A414 / * TriggerBase . cpp * / ; } ; <nl> - 06CAAAD1186AD8010012A414 / * ObjectFactory . h in Headers * / = { isa = PBXBuildFile ; fileRef = 06CAAABB186AD63B0012A414 / * ObjectFactory . h * / ; } ; <nl> - 06CAAAD2186AD8030012A414 / * ObjectFactory . h in Headers * / = { isa = PBXBuildFile ; fileRef = 06CAAABB186AD63B0012A414 / * ObjectFactory . h * / ; } ; <nl> 1A01C68418F57BE800EFE3A6 / * CCArray . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 1A01C67618F57BE800EFE3A6 / * CCArray . cpp * / ; } ; <nl> 1A01C68518F57BE800EFE3A6 / * CCArray . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 1A01C67618F57BE800EFE3A6 / * CCArray . cpp * / ; } ; <nl> 1A01C68618F57BE800EFE3A6 / * CCArray . h in Headers * / = { isa = PBXBuildFile ; fileRef = 1A01C67718F57BE800EFE3A6 / * CCArray . h * / ; } ; <nl> <nl> 2905FA8E18CF08D100240AA3 / * UIWidget . h in Headers * / = { isa = PBXBuildFile ; fileRef = 2905FA1418CF08D100240AA3 / * UIWidget . h * / ; } ; <nl> 2905FA8F18CF08D100240AA3 / * UIWidget . h in Headers * / = { isa = PBXBuildFile ; fileRef = 2905FA1418CF08D100240AA3 / * UIWidget . h * / ; } ; <nl> 2986667F18B1B246000E39CA / * CCTweenFunction . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 2986667818B1B079000E39CA / * CCTweenFunction . cpp * / ; } ; <nl> + 299754F4193EC95400A54AC3 / * ObjectFactory . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 299754F2193EC95400A54AC3 / * ObjectFactory . cpp * / ; } ; <nl> + 299754F5193EC95400A54AC3 / * ObjectFactory . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 299754F2193EC95400A54AC3 / * ObjectFactory . cpp * / ; } ; <nl> + 299754F6193EC95400A54AC3 / * ObjectFactory . h in Headers * / = { isa = PBXBuildFile ; fileRef = 299754F3193EC95400A54AC3 / * ObjectFactory . h * / ; } ; <nl> + 299754F7193EC95400A54AC3 / * ObjectFactory . h in Headers * / = { isa = PBXBuildFile ; fileRef = 299754F3193EC95400A54AC3 / * ObjectFactory . h * / ; } ; <nl> 29CB8F4C1929D1BB00C841D6 / * UILayoutManager . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 29CB8F4A1929D1BB00C841D6 / * UILayoutManager . cpp * / ; } ; <nl> 29CB8F4D1929D1BB00C841D6 / * UILayoutManager . cpp in Sources * / = { isa = PBXBuildFile ; fileRef = 29CB8F4A1929D1BB00C841D6 / * UILayoutManager . cpp * / ; } ; <nl> 29CB8F4E1929D1BB00C841D6 / * UILayoutManager . h in Headers * / = { isa = PBXBuildFile ; fileRef = 29CB8F4B1929D1BB00C841D6 / * UILayoutManager . h * / ; } ; <nl> <nl> / * End PBXContainerItemProxy section * / <nl> <nl> / * Begin PBXFileReference section * / <nl> - 06CAAABA186AD63B0012A414 / * ObjectFactory . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = ObjectFactory . cpp ; sourceTree = " < group > " ; } ; <nl> - 06CAAABB186AD63B0012A414 / * ObjectFactory . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = ObjectFactory . h ; sourceTree = " < group > " ; } ; <nl> 06CAAABC186AD63B0012A414 / * TriggerBase . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = TriggerBase . cpp ; sourceTree = " < group > " ; } ; <nl> 06CAAABD186AD63B0012A414 / * TriggerBase . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = TriggerBase . h ; sourceTree = " < group > " ; } ; <nl> 06CAAABE186AD63B0012A414 / * TriggerMng . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = TriggerMng . cpp ; sourceTree = " < group > " ; } ; <nl> <nl> 29080DEB191B82CE0066F8DF / * UIDeprecated . h * / = { isa = PBXFileReference ; lastKnownFileType = sourcecode . c . h ; path = UIDeprecated . h ; sourceTree = " < group > " ; } ; <nl> 2986667818B1B079000E39CA / * CCTweenFunction . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = CCTweenFunction . cpp ; sourceTree = " < group > " ; } ; <nl> 2986667918B1B079000E39CA / * CCTweenFunction . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = CCTweenFunction . h ; sourceTree = " < group > " ; } ; <nl> + 299754F2193EC95400A54AC3 / * ObjectFactory . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; name = ObjectFactory . cpp ; path = . . / base / ObjectFactory . cpp ; sourceTree = " < group > " ; } ; <nl> + 299754F3193EC95400A54AC3 / * ObjectFactory . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; name = ObjectFactory . h ; path = . . / base / ObjectFactory . h ; sourceTree = " < group > " ; } ; <nl> 29CB8F4A1929D1BB00C841D6 / * UILayoutManager . cpp * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . cpp . cpp ; path = UILayoutManager . cpp ; sourceTree = " < group > " ; } ; <nl> 29CB8F4B1929D1BB00C841D6 / * UILayoutManager . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = UILayoutManager . h ; sourceTree = " < group > " ; } ; <nl> 29CB8F541929D7A900C841D6 / * UIScrollInterface . h * / = { isa = PBXFileReference ; fileEncoding = 4 ; lastKnownFileType = sourcecode . c . h ; path = UIScrollInterface . h ; sourceTree = " < group > " ; } ; <nl> <nl> 1A5700A2180BC5E60088DEC7 / * base * / = { <nl> isa = PBXGroup ; <nl> children = ( <nl> + 299754F2193EC95400A54AC3 / * ObjectFactory . cpp * / , <nl> + 299754F3193EC95400A54AC3 / * ObjectFactory . h * / , <nl> 50ABBDC11925AB6E00A911A9 / * atitc . cpp * / , <nl> 50ABBDC21925AB6E00A911A9 / * atitc . h * / , <nl> 50ABBDC31925AB6E00A911A9 / * base64 . cpp * / , <nl> <nl> children = ( <nl> 50FCEB6818C72017004AD434 / * WidgetReader * / , <nl> 06CAAAC1186AD63B0012A414 / * TriggerObj . h * / , <nl> - 06CAAABA186AD63B0012A414 / * ObjectFactory . cpp * / , <nl> - 06CAAABB186AD63B0012A414 / * ObjectFactory . h * / , <nl> 06CAAABC186AD63B0012A414 / * TriggerBase . cpp * / , <nl> 06CAAABD186AD63B0012A414 / * TriggerBase . h * / , <nl> 06CAAABE186AD63B0012A414 / * TriggerMng . cpp * / , <nl> <nl> 1A570073180BC5A10088DEC7 / * CCActionGrid . h in Headers * / , <nl> 50FCEBB518C72017004AD434 / * SliderReader . h in Headers * / , <nl> 5034CA3B191D591100CE6051 / * ccShader_PositionColor . vert in Headers * / , <nl> - 06CAAAD1186AD8010012A414 / * ObjectFactory . h in Headers * / , <nl> 1A570077180BC5A10088DEC7 / * CCActionGrid3D . h in Headers * / , <nl> 1A57007B180BC5A10088DEC7 / * CCActionInstant . h in Headers * / , <nl> 1A57007F180BC5A10088DEC7 / * CCActionInterval . h in Headers * / , <nl> <nl> 1A01C68C18F57BE800EFE3A6 / * CCDeprecated . h in Headers * / , <nl> 50ABBD561925AB0000A911A9 / * TransformUtils . h in Headers * / , <nl> 2905FA6418CF08D100240AA3 / * UIListView . h in Headers * / , <nl> + 299754F6193EC95400A54AC3 / * ObjectFactory . h in Headers * / , <nl> 50FCEBB918C72017004AD434 / * TextAtlasReader . h in Headers * / , <nl> 50ABBD991925AB4100A911A9 / * CCGLProgramStateCache . h in Headers * / , <nl> 5034CA3D191D591100CE6051 / * ccShader_PositionColor . frag in Headers * / , <nl> <nl> 2905FA7118CF08D100240AA3 / * UIRichText . h in Headers * / , <nl> 503DD8E41926736A00CD74DD / * CCDirectorCaller . h in Headers * / , <nl> 50ABBD8A1925AB4100A911A9 / * CCCustomCommand . h in Headers * / , <nl> + 299754F7193EC95400A54AC3 / * ObjectFactory . h in Headers * / , <nl> 2905FA6D18CF08D100240AA3 / * UIPageView . h in Headers * / , <nl> 50ABBE881925AB6F00A911A9 / * ccMacros . h in Headers * / , <nl> 50ABC0101926664800A911A9 / * CCFileUtils . h in Headers * / , <nl> <nl> 50ABBDB81925AB4100A911A9 / * CCTexture2D . h in Headers * / , <nl> 50ABBE341925AB6F00A911A9 / * CCConfiguration . h in Headers * / , <nl> 1A570299180BCCAB0088DEC7 / * CCAnimationCache . h in Headers * / , <nl> - 06CAAAD2186AD8030012A414 / * ObjectFactory . h in Headers * / , <nl> 50ABBEAA1925AB6F00A911A9 / * CCTouch . h in Headers * / , <nl> 2905FA6918CF08D100240AA3 / * UILoadingBar . h in Headers * / , <nl> 50ABBE741925AB6F00A911A9 / * CCEventListenerMouse . h in Headers * / , <nl> <nl> 1A57011B180BC90D0088DEC7 / * CCGrabber . cpp in Sources * / , <nl> 1A57011F180BC90D0088DEC7 / * CCGrid . cpp in Sources * / , <nl> 50FCEBA718C72017004AD434 / * LoadingBarReader . cpp in Sources * / , <nl> - 06C0F2EF186AD822003594D5 / * ObjectFactory . cpp in Sources * / , <nl> 1A57019D180BCB590088DEC7 / * CCFont . cpp in Sources * / , <nl> 1A5701A1180BCB590088DEC7 / * CCFontAtlas . cpp in Sources * / , <nl> 1A5701A5180BCB590088DEC7 / * CCFontAtlasCache . cpp in Sources * / , <nl> <nl> 2905FA5218CF08D100240AA3 / * UIImageView . cpp in Sources * / , <nl> 50ABBDBD1925AB4100A911A9 / * CCTextureCache . cpp in Sources * / , <nl> B29594CE1926D61F003EEF37 / * CCSprite3DDataCache . cpp in Sources * / , <nl> + 299754F4193EC95400A54AC3 / * ObjectFactory . cpp in Sources * / , <nl> 2905FA7C18CF08D100240AA3 / * UIText . cpp in Sources * / , <nl> 50FCEB9F18C72017004AD434 / * LayoutReader . cpp in Sources * / , <nl> 50ABC0211926664800A911A9 / * CCGLView . cpp in Sources * / , <nl> <nl> 1A570113180BC8EE0088DEC7 / * CCDrawNode . cpp in Sources * / , <nl> 1A57011C180BC90D0088DEC7 / * CCGrabber . cpp in Sources * / , <nl> 1A570120180BC90D0088DEC7 / * CCGrid . cpp in Sources * / , <nl> - 06C0F2F0186AD824003594D5 / * ObjectFactory . cpp in Sources * / , <nl> 1A57019E180BCB590088DEC7 / * CCFont . cpp in Sources * / , <nl> 503DD8E21926736A00CD74DD / * CCCommon . mm in Sources * / , <nl> 1A5701A2180BCB590088DEC7 / * CCFontAtlas . cpp in Sources * / , <nl> <nl> B375107E1823ACA100B3BA6A / * CCPhysicsContactInfo_chipmunk . cpp in Sources * / , <nl> 1A5701C8180BCB5A0088DEC7 / * CCLabelTextFormatter . cpp in Sources * / , <nl> 1A5701CC180BCB5A0088DEC7 / * CCLabelTTF . cpp in Sources * / , <nl> + 299754F5193EC95400A54AC3 / * ObjectFactory . cpp in Sources * / , <nl> 1A5701DF180BCB8C0088DEC7 / * CCLayer . cpp in Sources * / , <nl> 50ABBDBE1925AB4100A911A9 / * CCTextureCache . cpp in Sources * / , <nl> 1A5701E3180BCB8C0088DEC7 / * CCScene . cpp in Sources * / , <nl> mmm a / cocos / editor - support / cocostudio / CCComAttribute . cpp <nl> ppp b / cocos / editor - support / cocostudio / CCComAttribute . cpp <nl> THE SOFTWARE . <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> # include " cocostudio / CCComAttribute . h " <nl> + # include " platform / CCFileUtils . h " <nl> <nl> using namespace cocos2d ; <nl> <nl> bool ComAttribute : : serialize ( void * r ) <nl> std : : string filePath ; <nl> if ( file ! = nullptr ) <nl> { <nl> - filePath . assign ( cocos2d : : CCFileUtils : : getInstance ( ) - > fullPathForFilename ( file ) ) ; <nl> + filePath . assign ( cocos2d : : FileUtils : : getInstance ( ) - > fullPathForFilename ( file ) ) ; <nl> } <nl> int resType = DICTOOL - > getIntValue_json ( fileData , " resourceType " , - 1 ) ; <nl> CC_BREAK_IF ( resType ! = 0 ) ; <nl> mmm a / cocos / editor - support / cocostudio / CCComAttribute . h <nl> ppp b / cocos / editor - support / cocostudio / CCComAttribute . h <nl> THE SOFTWARE . <nl> # define __CC_EXTENTIONS_CCCOMATTRIBUTE_H__ <nl> <nl> # include " CCComBase . h " <nl> + # include " 2d / CCComponent . h " <nl> + # include " base / CCValue . h " <nl> <nl> namespace cocostudio { <nl> <nl> mmm a / cocos / editor - support / cocostudio / CCComAudio . cpp <nl> ppp b / cocos / editor - support / cocostudio / CCComAudio . cpp <nl> THE SOFTWARE . <nl> <nl> # include " cocostudio / CCComAudio . h " <nl> # include " audio / include / SimpleAudioEngine . h " <nl> + # include " platform / CCFileUtils . h " <nl> <nl> namespace cocostudio { <nl> <nl> bool ComAudio : : serialize ( void * r ) <nl> std : : string filePath ; <nl> if ( file ! = nullptr ) <nl> { <nl> - filePath . assign ( cocos2d : : CCFileUtils : : getInstance ( ) - > fullPathForFilename ( file ) ) ; <nl> + filePath . assign ( cocos2d : : FileUtils : : getInstance ( ) - > fullPathForFilename ( file ) ) ; <nl> } <nl> int resType = DICTOOL - > getIntValue_json ( fileData , " resourceType " , - 1 ) ; <nl> CC_BREAK_IF ( resType ! = 0 ) ; <nl> mmm a / cocos / editor - support / cocostudio / CCComAudio . h <nl> ppp b / cocos / editor - support / cocostudio / CCComAudio . h <nl> THE SOFTWARE . <nl> # define __CC_EXTENTIONS_CCCOMAUDIO_H__ <nl> <nl> # include " CCComBase . h " <nl> + # include " 2d / CCComponent . h " <nl> <nl> namespace cocostudio { <nl> <nl> mmm a / cocos / editor - support / cocostudio / CCComBase . h <nl> ppp b / cocos / editor - support / cocostudio / CCComBase . h <nl> THE SOFTWARE . <nl> # ifndef __CC_EXTENTIONS_CCCOMBASE_H__ <nl> # define __CC_EXTENTIONS_CCCOMBASE_H__ <nl> <nl> - # include " ObjectFactory . h " <nl> - # include " DictionaryHelper . h " <nl> # include < string > <nl> + # include " DictionaryHelper . h " <nl> + # include " base / ObjectFactory . h " <nl> <nl> <nl> # define DECLARE_CLASS_COMPONENT_INFO \ <nl> public : \ <nl> - static cocostudio : : ObjectFactory : : TInfo Type ; \ <nl> + static cocos2d : : ObjectFactory : : TInfo Type ; \ <nl> static cocos2d : : Ref * createInstance ( void ) ; \ <nl> <nl> # define IMPLEMENT_CLASS_COMPONENT_INFO ( className ) \ <nl> THE SOFTWARE . <nl> { \ <nl> return className : : create ( ) ; \ <nl> } \ <nl> - cocostudio : : ObjectFactory : : TInfo className : : Type ( # className , & className : : createInstance ) ; \ <nl> + cocos2d : : ObjectFactory : : TInfo className : : Type ( # className , & className : : createInstance ) ; \ <nl> <nl> # define CREATE_CLASS_COMPONENT_INFO ( className ) \ <nl> - cocostudio : : ObjectFactory : : TInfo ( # className , & className : : createInstance ) <nl> + cocos2d : : ObjectFactory : : TInfo ( # className , & className : : createInstance ) <nl> <nl> <nl> # endif <nl> mmm a / cocos / editor - support / cocostudio / CCComController . cpp <nl> ppp b / cocos / editor - support / cocostudio / CCComController . cpp <nl> THE SOFTWARE . <nl> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> <nl> # include " cocostudio / CCComController . h " <nl> + # include " 2d / CCNode . h " <nl> <nl> namespace cocostudio { <nl> <nl> mmm a / cocos / editor - support / cocostudio / CCComController . h <nl> ppp b / cocos / editor - support / cocostudio / CCComController . h <nl> THE SOFTWARE . <nl> <nl> # include " CCComBase . h " <nl> # include " cocostudio / CCInputDelegate . h " <nl> + # include " 2d / CCComponent . h " <nl> <nl> namespace cocostudio { <nl> <nl> mmm a / cocos / editor - support / cocostudio / CCComRender . h <nl> ppp b / cocos / editor - support / cocostudio / CCComRender . h <nl> THE SOFTWARE . <nl> # define __CC_EXTENTIONS_CCCOMRENDER_H__ <nl> <nl> # include " CCComBase . h " <nl> + # include " 2d / CCComponent . h " <nl> <nl> namespace cocostudio { <nl> <nl> mmm a / cocos / editor - support / cocostudio / CCSGUIReader . cpp <nl> ppp b / cocos / editor - support / cocostudio / CCSGUIReader . cpp <nl> Widget * GUIReader : : widgetFromJsonFile ( const char * fileName ) <nl> CC_SAFE_DELETE ( pReader ) ; <nl> return widget ; <nl> } <nl> + <nl> + <nl> + <nl> + std : : string WidgetPropertiesReader : : getGUIClassName ( const std : : string & name ) <nl> + { <nl> + std : : string convertedClassName = name ; <nl> + if ( name = = " Panel " ) <nl> + { <nl> + convertedClassName = " Layout " ; <nl> + } <nl> + else if ( name = = " TextArea " ) <nl> + { <nl> + convertedClassName = " Text " ; <nl> + } <nl> + else if ( name = = " TextButton " ) <nl> + { <nl> + convertedClassName = " Button " ; <nl> + } <nl> + else if ( name = = " Label " ) <nl> + { <nl> + convertedClassName = " Text " ; <nl> + } <nl> + else if ( name = = " LabelAtlas " ) <nl> + { <nl> + convertedClassName = " TextAtlas " ; <nl> + } <nl> + else if ( name = = " LabelBMFont " ) <nl> + { <nl> + convertedClassName = " TextBMFont " ; <nl> + } <nl> + <nl> + <nl> + return convertedClassName ; <nl> + } <nl> + <nl> + cocos2d : : ui : : Widget * WidgetPropertiesReader : : createGUI ( const std : : string & classname ) <nl> + { <nl> + std : : string name = this - > getGUIClassName ( classname ) ; <nl> + <nl> + Ref * object = ObjectFactory : : getInstance ( ) - > createObject ( name ) ; <nl> + <nl> + return dynamic_cast < ui : : Widget * > ( object ) ; <nl> + } <nl> + <nl> + WidgetReaderProtocol * WidgetPropertiesReader : : createWidgetReaderProtocol ( const std : : string & classname ) <nl> + { <nl> + Ref * object = ObjectFactory : : getInstance ( ) - > createObject ( classname ) ; <nl> + <nl> + return dynamic_cast < WidgetReaderProtocol * > ( object ) ; <nl> + } <nl> + <nl> + <nl> <nl> <nl> void WidgetPropertiesReader : : setAnchorPointForWidget ( cocos2d : : ui : : Widget * widget , const rapidjson : : Value & options ) <nl> Widget * WidgetPropertiesReader0300 : : widgetFromJsonDictionary ( const rapidjson : : Va <nl> { <nl> const char * classname = DICTOOL - > getStringValue_json ( data , " classname " ) ; <nl> const rapidjson : : Value & uiOptions = DICTOOL - > getSubDictionary_json ( data , " options " ) ; <nl> - Widget * widget = ObjectFactory : : getInstance ( ) - > createGUI ( classname ) ; <nl> + Widget * widget = this - > createGUI ( classname ) ; <nl> <nl> / / create widget reader to parse properties of widget <nl> std : : string readerName = classname ; <nl> Widget * WidgetPropertiesReader0300 : : widgetFromJsonDictionary ( const rapidjson : : Va <nl> readerName = " TextBMFont " ; <nl> } <nl> readerName . append ( " Reader " ) ; <nl> - WidgetReaderProtocol * reader = ObjectFactory : : getInstance ( ) - > createWidgetReaderProtocol ( readerName ) ; <nl> + <nl> + WidgetReaderProtocol * reader = this - > createWidgetReaderProtocol ( readerName ) ; <nl> <nl> if ( reader ) <nl> { <nl> Widget * WidgetPropertiesReader0300 : : widgetFromJsonDictionary ( const rapidjson : : Va <nl> { <nl> readerName = " WidgetReader " ; <nl> } <nl> - reader = ObjectFactory : : getInstance ( ) - > createWidgetReaderProtocol ( readerName ) ; <nl> + <nl> + reader = dynamic_cast < WidgetReaderProtocol * > ( ObjectFactory : : getInstance ( ) - > createObject ( readerName ) ) ; <nl> + <nl> setPropsForAllWidgetFromJsonDictionary ( reader , widget , uiOptions ) ; <nl> <nl> / / 2nd . , custom widget parse with custom reader <nl> mmm a / cocos / editor - support / cocostudio / CCSGUIReader . h <nl> ppp b / cocos / editor - support / cocostudio / CCSGUIReader . h <nl> THE SOFTWARE . <nl> # include " ui / UIWidget . h " <nl> # include " cocostudio / DictionaryHelper . h " <nl> # include " WidgetReader / WidgetReaderProtocol . h " <nl> - # include " ObjectFactory . h " <nl> + # include " base / ObjectFactory . h " <nl> + <nl> <nl> namespace cocostudio { <nl> <nl> + <nl> # define kCCSVersion 1 . 0 <nl> <nl> typedef void ( cocos2d : : Ref : : * SEL_ParseEvent ) ( const std : : string & , cocos2d : : Ref * , const rapidjson : : Value & ) ; <nl> class GUIReader : public cocos2d : : Ref <nl> <nl> const std : : string & getFilePath ( ) const { return m_strFilePath ; } ; <nl> void registerTypeAndCallBack ( const std : : string & classType , <nl> - ObjectFactory : : Instance ins , <nl> + cocos2d : : ObjectFactory : : Instance ins , <nl> Ref * object , <nl> SEL_ParseEvent callBack ) ; <nl> <nl> class WidgetPropertiesReader : public cocos2d : : Ref <nl> protected : <nl> void setAnchorPointForWidget ( cocos2d : : ui : : Widget * widget , const rapidjson : : Value & options ) ; <nl> <nl> + std : : string getGUIClassName ( const std : : string & name ) ; <nl> + cocos2d : : ui : : Widget * createGUI ( const std : : string & classname ) ; <nl> + WidgetReaderProtocol * createWidgetReaderProtocol ( const std : : string & classname ) ; <nl> + <nl> protected : <nl> std : : string m_strFilePath ; <nl> } ; <nl> mmm a / cocos / editor - support / cocostudio / CCSSceneReader . cpp <nl> ppp b / cocos / editor - support / cocostudio / CCSSceneReader . cpp <nl> Node * SceneReader : : nodeByTag ( Node * parent , int tag ) <nl> } <nl> return _retNode ; <nl> } <nl> - <nl> + <nl> + cocos2d : : Component * SceneReader : : createComponent ( const std : : string classname ) <nl> + { <nl> + std : : string name = this - > getComponentClassName ( classname ) ; <nl> + Ref * object = ObjectFactory : : getInstance ( ) - > createObject ( name ) ; <nl> + <nl> + return dynamic_cast < Component * > ( object ) ; <nl> + } <nl> + std : : string SceneReader : : getComponentClassName ( const std : : string & name ) <nl> + { <nl> + std : : string comName ; <nl> + if ( name = = " CCSprite " | | name = = " CCTMXTiledMap " | | name = = " CCParticleSystemQuad " | | name = = " CCArmature " | | name = = " GUIComponent " ) <nl> + { <nl> + comName = " ComRender " ; <nl> + } <nl> + else if ( name = = " CCComAudio " | | name = = " CCBackgroundAudio " ) <nl> + { <nl> + comName = " ComAudio " ; <nl> + } <nl> + else if ( name = = " CCComController " ) <nl> + { <nl> + comName = " ComController " ; <nl> + } <nl> + else if ( name = = " CCComAttribute " ) <nl> + { <nl> + comName = " ComAttribute " ; <nl> + } <nl> + else if ( name = = " CCScene " ) <nl> + { <nl> + comName = " Scene " ; <nl> + } <nl> + else <nl> + { <nl> + CCASSERT ( false , " Unregistered Component ! " ) ; <nl> + } <nl> + <nl> + return comName ; <nl> + } <nl> <nl> Node * SceneReader : : createObject ( const rapidjson : : Value & dict , cocos2d : : Node * parent , AttachComponentType attachComponent ) <nl> { <nl> Node * SceneReader : : createObject ( const rapidjson : : Value & dict , cocos2d : : Node * par <nl> break ; <nl> } <nl> const char * comName = DICTOOL - > getStringValue_json ( subDict , " classname " ) ; <nl> - Component * com = ObjectFactory : : getInstance ( ) - > createComponent ( comName ) ; <nl> + Component * com = this - > createComponent ( comName ) ; <nl> if ( com ! = nullptr ) <nl> { <nl> if ( com - > serialize ( ( void * ) ( & subDict ) ) ) <nl> mmm a / cocos / editor - support / cocostudio / CCSSceneReader . h <nl> ppp b / cocos / editor - support / cocostudio / CCSSceneReader . h <nl> class SceneReader <nl> private : <nl> SceneReader ( void ) ; <nl> virtual ~ SceneReader ( void ) ; <nl> + std : : string getComponentClassName ( const std : : string & name ) ; <nl> + <nl> + cocos2d : : Component * createComponent ( const std : : string classname ) ; <nl> + <nl> <nl> cocos2d : : Node * createObject ( const rapidjson : : Value & dict , cocos2d : : Node * parent , AttachComponentType attachComponent ) ; <nl> void setPropertyFromJsonDict ( const rapidjson : : Value & dict , cocos2d : : Node * node ) ; <nl>
fix ObjectFactory refactor issue
cocos2d/cocos2d-x
54e93f6c41d033de49cf8580db927499c6e52e30
2014-06-04T06:56:34Z
mmm a / tools / EventClients / lib / python / xbmcclient . py <nl> ppp b / tools / EventClients / lib / python / xbmcclient . py <nl> def _get_icon_type ( self , icon_file ) : <nl> elif icon_file . lower ( ) [ - 3 : ] = = " gif " : <nl> return ICON_GIF <nl> elif icon_file . lower ( ) [ - 3 : ] = = " jpg " : <nl> - return ICON_JPG <nl> + return ICON_JPEG <nl> return ICON_NONE <nl>
Applied - Thanks David Byers
xbmc/xbmc
a0baa0d6dec741c188d473738661e33039259726
2010-07-20T16:40:59Z
mmm a / Code / Sandbox / Plugins / DependencyGraph / Model . h <nl> ppp b / Code / Sandbox / Plugins / DependencyGraph / Model . h <nl> class CModel <nl> f ( asset , asset - > GetMetadataFile ( ) , rootDepth ) ; <nl> <nl> CAssetManager * pAssetManager = GetIEditor ( ) - > GetAssetManager ( ) ; <nl> - std : : stack < std : : vector < string > > stack ; <nl> - stack . push ( std : : move ( asset - > GetDependencies ( ) ) ) ; <nl> + std : : stack < std : : vector < SAssetDependencyInfo > > stack ; <nl> + stack . push ( asset - > GetDependencies ( ) ) ; <nl> while ( ! stack . empty ( ) ) <nl> { <nl> auto & dependencies = stack . top ( ) ; <nl> class CModel <nl> stack . pop ( ) ; <nl> continue ; <nl> } <nl> - <nl> - CAsset * pAsset = pAssetManager - > FindAssetForFile ( dependencies . back ( ) ) ; <nl> - f ( pAsset , dependencies . back ( ) , stack . size ( ) ) ; <nl> + const string & path = dependencies . back ( ) . path ; <nl> + CAsset * pAsset = pAssetManager - > FindAssetForFile ( path ) ; <nl> + f ( pAsset , path , stack . size ( ) ) ; <nl> dependencies . pop_back ( ) ; <nl> <nl> if ( ! pAsset ) <nl> class CModel <nl> / / Unresolved dependency . <nl> continue ; <nl> } <nl> - stack . push ( std : : move ( pAsset - > GetDependencies ( ) ) ) ; <nl> + stack . push ( pAsset - > GetDependencies ( ) ) ; <nl> } <nl> } <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorSubstance / AssetImporters / SubstanceArchiveImporter . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorSubstance / AssetImporters / SubstanceArchiveImporter . cpp <nl> namespace EditorSubstance <nl> / / after imported , lest try regenerate everything dependant <nl> if ( checkDepenencies ) <nl> { <nl> - for ( CAsset * depAsset : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( * currentAsset ) ) <nl> + for ( auto & item : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( * currentAsset ) ) <nl> { <nl> - string dependantAssetTypeName ( depAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> + CAsset * pDepAsset = item . first ; <nl> + string dependantAssetTypeName ( pDepAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> if ( dependantAssetTypeName = = " SubstanceInstance " ) <nl> { <nl> - EditorSubstance : : CManager : : Instance ( ) - > ForcePresetRegeneration ( depAsset ) ; <nl> + EditorSubstance : : CManager : : Instance ( ) - > ForcePresetRegeneration ( pDepAsset ) ; <nl> } <nl> } <nl> } <nl> mmm a / Code / Sandbox / Plugins / EditorSubstance / AssetTypes / SubstanceInstance . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorSubstance / AssetTypes / SubstanceInstance . cpp <nl> namespace EditorSubstance <nl> { <nl> const string relativeFileName = PathUtil : : AbsolutePathToGamePath ( editAsset . GetAsset ( ) . GetName ( ) ) ; <nl> editAsset . SetFiles ( " " , { relativeFileName + " . crysub " } ) ; <nl> - string * archiveName = ( string * ) ( pTypeSpecificParameter ) ; <nl> - editAsset . SetDependencies ( { * archiveName } ) ; <nl> - <nl> <nl> + CRY_ASSERT ( pTypeSpecificParameter ) ; <nl> + if ( pTypeSpecificParameter ) <nl> + { <nl> + string & archiveName = * ( string * ) ( pTypeSpecificParameter ) ; <nl> + editAsset . SetDependencies ( { { archiveName , 1 } } ) ; <nl> + } <nl> return true ; <nl> } <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorSubstance / EditorSubstanceManager . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorSubstance / EditorSubstanceManager . cpp <nl> namespace EditorSubstance { <nl> QObject : : connect ( newAct , & QAction : : triggered , this , & CManager : : OnCreateInstance ) ; <nl> } <nl> QAction * rebuild = menu - > CreateAction ( " Rebuild All Instances " ) ; <nl> - QObject : : connect ( rebuild , & QAction : : triggered , this , [ = ] ( ) { <nl> - for ( CAsset * depAsset : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( * asset ) ) <nl> + QObject : : connect ( rebuild , & QAction : : triggered , this , [ = ] ( ) <nl> + { <nl> + for ( auto & item : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( * asset ) ) <nl> { <nl> - string dependantAssetTypeName ( depAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> + CAsset * pDepAsset = item . first ; <nl> + string dependantAssetTypeName ( pDepAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> if ( dependantAssetTypeName = = " SubstanceInstance " ) <nl> { <nl> - ForcePresetRegeneration ( depAsset ) ; <nl> + ForcePresetRegeneration ( pDepAsset ) ; <nl> } <nl> } <nl> } ) ; <nl> namespace EditorSubstance { <nl> string typeName ( asset . GetType ( ) - > GetTypeName ( ) ) ; <nl> if ( typeName = = " Texture " / * | | typeName = = " SubstanceDefinition " * / ) <nl> { <nl> - for ( CAsset * depAsset : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( asset ) ) <nl> + for ( auto & item : CAssetManager : : GetInstance ( ) - > GetReverseDependencies ( asset ) ) <nl> { <nl> - string dependantAssetTypeName ( depAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> + CAsset * pDepAsset = item . first ; <nl> + string dependantAssetTypeName ( pDepAsset - > GetType ( ) - > GetTypeName ( ) ) ; <nl> if ( dependantAssetTypeName = = " SubstanceInstance " ) <nl> { <nl> - ForcePresetRegeneration ( depAsset ) ; <nl> + ForcePresetRegeneration ( pDepAsset ) ; <nl> } <nl> } <nl> <nl> mmm a / Code / Sandbox / Plugins / EditorSubstance / PresetEditor . cpp <nl> ppp b / Code / Sandbox / Plugins / EditorSubstance / PresetEditor . cpp <nl> bool CSubstancePresetEditor : : OnOpenAsset ( CAsset * pAsset ) <nl> bool CSubstancePresetEditor : : OnSaveAsset ( CEditableAsset & editAsset ) <nl> { <nl> m_pPreset - > Save ( ) ; <nl> - std : : vector < string > dependencies ; <nl> - dependencies . push_back ( m_pPreset - > GetSubstanceArchive ( ) ) ; <nl> + std : : vector < SAssetDependencyInfo > dependencies ; <nl> + dependencies . emplace_back ( m_pPreset - > GetSubstanceArchive ( ) , 1 ) ; <nl> const std : : vector < string > images = m_pPreset - > GetInputImages ( ) ; <nl> - dependencies . insert ( dependencies . end ( ) , images . begin ( ) , images . end ( ) ) ; <nl> + for ( const string & image : images ) <nl> + { <nl> + dependencies . emplace_back ( image , 1 ) ; <nl> + } <nl> editAsset . SetDependencies ( dependencies ) ; <nl> <nl> GetAssetBeingEdited ( ) - > SetModified ( false ) ; <nl> mmm a / Code / Sandbox / Plugins / MaterialEditorPlugin / MaterialEditor . cpp <nl> ppp b / Code / Sandbox / Plugins / MaterialEditorPlugin / MaterialEditor . cpp <nl> bool CMaterialEditor : : OnSaveAsset ( CEditableAsset & editAsset ) <nl> { <nl> editAsset . SetFiles ( " " , { m_pMaterial - > GetFilename ( ) } ) ; <nl> <nl> - std : : vector < string > filenames ; <nl> + std : : vector < SAssetDependencyInfo > filenames ; <nl> <nl> / / TODO : not all dependencies are found , some paths are relative to same folder which is not good . . . <nl> int textureCount = m_pMaterial - > GetTextureDependencies ( filenames ) ; <nl> mmm a / Code / Tools / CryCommonTools / Metadata / Metadata . cpp <nl> ppp b / Code / Tools / CryCommonTools / Metadata / Metadata . cpp <nl> void AddDetails ( XmlNodeRef & xml , const std : : vector < std : : pair < string , string > > & d <nl> } <nl> } <nl> <nl> - void AddDependencies ( XmlNodeRef & xml , const std : : vector < string > & dependencies ) <nl> + void AddDependencies ( XmlNodeRef & xml , const std : : vector < std : : pair < string , int32 > > & dependencies ) <nl> { <nl> if ( dependencies . empty ( ) ) <nl> { <nl> void AddDependencies ( XmlNodeRef & xml , const std : : vector < string > & dependencies ) <nl> pDependencies = xml - > newChild ( " Dependencies " ) ; <nl> } <nl> <nl> - for ( const auto & detail : dependencies ) <nl> + for ( const auto & item : dependencies ) <nl> { <nl> XmlNodeRef pPath = pDependencies - > newChild ( " Path " ) ; <nl> <nl> + if ( item . second ) <nl> + { <nl> + pPath - > setAttr ( " usageCount " , item . second ) ; <nl> + } <nl> + <nl> / / There is an agreement in the sandbox dependency tracking system that local paths have to start with " . / " <nl> - if ( detail . FindOneOf ( " / \ \ " ) ! = string : : npos ) <nl> + if ( item . first . FindOneOf ( " / \ \ " ) ! = string : : npos ) <nl> { <nl> - pPath - > setContent ( detail ) ; <nl> + pPath - > setContent ( item . first ) ; <nl> } <nl> else / / Folow the engine rules : if no slashes in the name assume it is in same folder as the cryasset . <nl> { <nl> - pPath - > setContent ( string ( ) . Format ( " . / % s " , detail . c_str ( ) ) ) ; <nl> + pPath - > setContent ( string ( ) . Format ( " . / % s " , item . first . c_str ( ) ) ) ; <nl> } <nl> } <nl> } <nl> mmm a / Code / Tools / CryCommonTools / Metadata / Metadata . h <nl> ppp b / Code / Tools / CryCommonTools / Metadata / Metadata . h <nl> bool ReadMetadata ( const XmlNodeRef & asset , SAssetMetadata & metadata ) ; <nl> <nl> const XmlNodeRef GetMetadataNode ( const XmlNodeRef & asset ) ; <nl> void AddDetails ( XmlNodeRef & xml , const std : : vector < std : : pair < string , string > > & details ) ; <nl> - void AddDependencies ( XmlNodeRef & xml , const std : : vector < string > & dependencies ) ; <nl> + void AddDependencies ( XmlNodeRef & xml , const std : : vector < std : : pair < string , int32 > > & dependencies ) ; <nl> <nl> } <nl> mmm a / Code / Tools / RC / ResourceCompilerPC / Metadata / MetadataCompiler . cpp <nl> ppp b / Code / Tools / RC / ResourceCompilerPC / Metadata / MetadataCompiler . cpp <nl> void CollectCgfDetails ( XmlNodeRef & xmlnode , const CContentCGF & cgf ) <nl> details . emplace_back ( " bonesCount " , string ( ) . Format ( " % i " , pSkin - > m_arrBoneEntities . size ( ) ) ) ; <nl> } <nl> <nl> - std : : vector < string > dependencies ; <nl> + std : : vector < std : : pair < string , int32 > > dependencies ; <nl> if ( materialCount ) <nl> { <nl> - dependencies . emplace_back ( PathUtil : : ReplaceExtension ( cgf . GetMaterial ( 0 ) - > name , " mtl " ) ) ; <nl> + dependencies . emplace_back ( PathUtil : : ReplaceExtension ( cgf . GetMaterial ( 0 ) - > name , " mtl " ) , 1 ) ; <nl> } <nl> <nl> AssetManager : : AddDetails ( xmlnode , details ) ; <nl> bool CollectMtlDetails ( XmlNodeRef & xmlnode , const char * szFilename , IResourceCom <nl> <nl> int subMaterialCount = 0 ; <nl> int textureCount = 0 ; <nl> - std : : vector < string > dependencies ; <nl> + std : : vector < std : : pair < string , int32 > > dependencies ; <nl> std : : stack < XmlNodeRef > mtls ; <nl> mtls . push ( mtl ) ; <nl> while ( ! mtls . empty ( ) ) <nl> bool CollectMtlDetails ( XmlNodeRef & xmlnode , const char * szFilename , IResourceCom <nl> continue ; <nl> } <nl> const string path = PathUtil : : ReplaceExtension ( filename , " dds " ) ; <nl> - if ( std : : any_of ( dependencies . begin ( ) , dependencies . end ( ) , [ & path ] ( const string & x ) { return path . CompareNoCase ( x ) = = 0 ; } ) ) <nl> + auto it = std : : find_if ( dependencies . begin ( ) , dependencies . end ( ) , [ & path ] ( const auto & x ) <nl> + { <nl> + return path . CompareNoCase ( x . first ) = = 0 ; <nl> + } ) ; <nl> + <nl> + if ( it ! = dependencies . end ( ) ) <nl> { <nl> + + + ( it - > second ) ; <nl> continue ; <nl> } <nl> - dependencies . emplace_back ( path ) ; <nl> + dependencies . emplace_back ( path , 1 ) ; <nl> + + textureCount ; <nl> } <nl> } <nl> bool CollectCdfDetails ( XmlNodeRef & xmlnode , const char * szFilename , IResourceCom <nl> return false ; <nl> } <nl> <nl> - std : : vector < string > dependencies ; <nl> + std : : vector < std : : pair < string , int32 > > dependencies ; <nl> <nl> const char * filename ; <nl> const XmlNodeRef model = cdf - > findChild ( " Model " ) ; <nl> if ( model & & model - > getAttr ( " File " , & filename ) ) <nl> { <nl> - dependencies . emplace_back ( filename ) ; <nl> + dependencies . emplace_back ( filename , 0 ) ; <nl> if ( model - > getAttr ( " Material " , & filename ) ) <nl> { <nl> - dependencies . emplace_back ( filename ) ; <nl> + dependencies . emplace_back ( filename , 0 ) ; <nl> } <nl> } <nl> <nl> bool CollectCdfDetails ( XmlNodeRef & xmlnode , const char * szFilename , IResourceCom <nl> { <nl> if ( item - > getAttr ( szAttr , & filename ) ) <nl> { <nl> - dependencies . emplace_back ( filename ) ; <nl> + dependencies . emplace_back ( filename , 0 ) ; <nl> } <nl> } <nl> } <nl>
! FRO ( Sandbox ) ( DEV - 4934 ) A pilot implementation of tracking of dependency instance count in asset system .
CRYTEK/CRYENGINE
ed436a719dbb18fa1ceb09513d8c749ad23fe86a
2017-11-29T11:23:23Z
mmm a / emscripten . py <nl> ppp b / emscripten . py <nl> def load_from_cache ( chunk ) : <nl> <nl> indexing = forwarded_json [ ' Functions ' ] [ ' indexedFunctions ' ] <nl> def indexize ( js ) : <nl> - return re . sub ( r ' " { { FI_ ( [ \ w \ d_ $ ] + ) } } " ' , lambda m : str ( indexing . get ( m . groups ( 0 ) [ 0 ] ) or 0 ) , js ) <nl> + return re . sub ( r " ' { { FI_ ( [ \ w \ d_ $ ] + ) } } ' " , lambda m : str ( indexing . get ( m . groups ( 0 ) [ 0 ] ) or 0 ) , js ) <nl> <nl> blockaddrs = forwarded_json [ ' Functions ' ] [ ' blockAddresses ' ] <nl> def blockaddrsize ( js ) : <nl> mmm a / src / modules . js <nl> ppp b / src / modules . js <nl> var Functions = { <nl> } <nl> if ( phase ! = ' post ' & & singlePhase ) { <nl> if ( ! doNotCreate ) this . indexedFunctions [ ident ] = 0 ; / / tell python we need this indexized <nl> - return ' " { { FI_ ' + ident + ' } } " ' ; / / something python will replace later <nl> + return " ' { { FI_ " + ident + " } } ' " ; / / something python will replace later <nl> } else { <nl> var ret = this . indexedFunctions [ ident ] ; <nl> if ( ! ret ) { <nl>
make function indexing replacements JSON - friendly
emscripten-core/emscripten
6f3e1629f8a97cbe2aa2ad430df32cc13c616889
2013-01-22T19:37:18Z
mmm a / src / python / grpcio / grpc / experimental / aio / _call . py <nl> ppp b / src / python / grpcio / grpc / experimental / aio / _call . py <nl> def _set_status ( self , status : cygrpc . AioRpcStatus ) - > None : <nl> self . _status . set_result ( status ) <nl> self . _code = _common . CYGRPC_STATUS_CODE_TO_STATUS_CODE [ status . code ( ) ] <nl> <nl> - async def _raise_if_not_ok ( self ) - > None : <nl> + async def _raise_for_status ( self ) - > None : <nl> if self . _locally_cancelled : <nl> raise asyncio . CancelledError ( ) <nl> await self . _status <nl> async def _invoke ( self ) - > ResponseType : <nl> self . cancel ( ) <nl> <nl> # Raises here if RPC failed or cancelled <nl> - await self . _raise_if_not_ok ( ) <nl> + await self . _raise_for_status ( ) <nl> <nl> return _common . deserialize ( serialized_response , <nl> self . _response_deserializer ) <nl> async def _read ( self ) - > ResponseType : <nl> <nl> async def read ( self ) - > ResponseType : <nl> if self . _status . done ( ) : <nl> - await self . _raise_if_not_ok ( ) <nl> + await self . _raise_for_status ( ) <nl> raise asyncio . InvalidStateError ( _RPC_ALREADY_FINISHED_DETAILS ) <nl> <nl> response_message = await self . _read ( ) <nl> <nl> if response_message is None : <nl> # If the read operation failed , Core should explain why . <nl> - await self . _raise_if_not_ok ( ) <nl> + await self . _raise_for_status ( ) <nl> # If no exception raised , there is something wrong internally . <nl> assert False , ' Read operation failed with StatusCode . OK ' <nl> else : <nl>
Use " raise_for_status "
grpc/grpc
5c4e28583068dcceeb56917e4d86a2cf43c13b03
2020-01-06T19:54:57Z
mmm a / include / envoy / server / BUILD <nl> ppp b / include / envoy / server / BUILD <nl> envoy_cc_library ( <nl> " / / include / envoy / init : init_interface " , <nl> " / / include / envoy / local_info : local_info_interface " , <nl> " / / include / envoy / ratelimit : ratelimit_interface " , <nl> - " / / include / envoy / router : route_config_provider_manager_interface " , <nl> " / / include / envoy / runtime : runtime_interface " , <nl> " / / include / envoy / ssl : context_manager_interface " , <nl> " / / include / envoy / thread_local : thread_local_interface " , <nl> envoy_cc_library ( <nl> " / / include / envoy / local_info : local_info_interface " , <nl> " / / include / envoy / network : drain_decision_interface " , <nl> " / / include / envoy / ratelimit : ratelimit_interface " , <nl> - " / / include / envoy / router : route_config_provider_manager_interface " , <nl> " / / include / envoy / runtime : runtime_interface " , <nl> " / / include / envoy / singleton : manager_interface " , <nl> " / / include / envoy / thread_local : thread_local_interface " , <nl> mmm a / include / envoy / server / filter_config . h <nl> ppp b / include / envoy / server / filter_config . h <nl> <nl> # include " envoy / network / drain_decision . h " <nl> # include " envoy / network / filter . h " <nl> # include " envoy / ratelimit / ratelimit . h " <nl> - # include " envoy / router / route_config_provider_manager . h " <nl> # include " envoy / runtime / runtime . h " <nl> # include " envoy / singleton / manager . h " <nl> # include " envoy / thread_local / thread_local . h " <nl> class FactoryContext { <nl> * used to allow runtime lockless updates to configuration , etc . across multiple threads . <nl> * / <nl> virtual ThreadLocal : : SlotAllocator & threadLocal ( ) PURE ; <nl> - <nl> - / * * <nl> - * @ return RouteConfigProviderManager & singleton for use by the entire server . <nl> - * / <nl> - virtual Router : : RouteConfigProviderManager & routeConfigProviderManager ( ) PURE ; <nl> } ; <nl> <nl> enum class NetworkFilterType { Read , Write , Both } ; <nl> mmm a / include / envoy / server / instance . h <nl> ppp b / include / envoy / server / instance . h <nl> <nl> # include " envoy / local_info / local_info . h " <nl> # include " envoy / network / listen_socket . h " <nl> # include " envoy / ratelimit / ratelimit . h " <nl> - # include " envoy / router / route_config_provider_manager . h " <nl> # include " envoy / runtime / runtime . h " <nl> # include " envoy / server / admin . h " <nl> # include " envoy / server / drain_manager . h " <nl> class Instance { <nl> * @ return information about the local environment the server is running in . <nl> * / <nl> virtual const LocalInfo : : LocalInfo & localInfo ( ) PURE ; <nl> - <nl> - / * * <nl> - * @ return the server ' s http route manager . <nl> - * / <nl> - virtual Router : : ServerRouteConfigProviderManager & routeConfigProviderManager ( ) PURE ; <nl> } ; <nl> <nl> } / / namespace Server <nl> mmm a / include / envoy / singleton / instance . h <nl> ppp b / include / envoy / singleton / instance . h <nl> class Instance { <nl> virtual ~ Instance ( ) { } <nl> } ; <nl> <nl> - typedef std : : shared_ptr < Instance > InstancePtr ; <nl> + typedef std : : shared_ptr < Instance > InstanceSharedPtr ; <nl> <nl> } / / namespace Singleton <nl> } / / namespace Envoy <nl> mmm a / include / envoy / singleton / manager . h <nl> ppp b / include / envoy / singleton / manager . h <nl> template < const char * name_param > class RegistrationImpl : public Registration { <nl> std : : string name ( ) override { return name_param ; } <nl> } ; <nl> <nl> + / * * <nl> + * Macro used to statically register singletons managed by the singleton manager <nl> + * defined in envoy / singleton / manager . h . After the NAME has been registered use the <nl> + * SINGLETON_MANAGER_REGISTERED_NAME macro to access the name registered with the <nl> + * singleton manager . <nl> + * / <nl> + # define SINGLETON_MANAGER_REGISTRATION ( NAME ) \ <nl> + static constexpr char NAME # # _singleton_name [ ] = # NAME " _singleton " ; \ <nl> + static Registry : : RegisterFactory < Singleton : : RegistrationImpl < NAME # # _singleton_name > , \ <nl> + Singleton : : Registration > \ <nl> + NAME # # _singleton_registered_ ; <nl> + <nl> + # define SINGLETON_MANAGER_REGISTERED_NAME ( NAME ) NAME # # _singleton_name <nl> + <nl> / * * <nl> * Callback function used to create a singleton . <nl> * / <nl> - typedef std : : function < InstancePtr ( ) > SingletonFactoryCb ; <nl> + typedef std : : function < InstanceSharedPtr ( ) > SingletonFactoryCb ; <nl> <nl> / * * <nl> * A manager for all server - side singletons . <nl> class Manager { <nl> * singletons must store the shared_ptr for as long as the singleton is needed . <nl> * @ return InstancePtr the singleton . <nl> * / <nl> - virtual InstancePtr get ( const std : : string & name , SingletonFactoryCb ) PURE ; <nl> + virtual InstanceSharedPtr get ( const std : : string & name , SingletonFactoryCb ) PURE ; <nl> } ; <nl> <nl> typedef std : : unique_ptr < Manager > ManagerPtr ; <nl> mmm a / source / common / router / BUILD <nl> ppp b / source / common / router / BUILD <nl> envoy_cc_library ( <nl> " / / include / envoy / local_info : local_info_interface " , <nl> " / / include / envoy / router : rds_interface " , <nl> " / / include / envoy / router : route_config_provider_manager_interface " , <nl> + " / / include / envoy / singleton : instance_interface " , <nl> " / / include / envoy / thread_local : thread_local_interface " , <nl> " / / source / common / common : assert_lib " , <nl> " / / source / common / common : logger_lib " , <nl> mmm a / source / common / router / rds_impl . h <nl> ppp b / source / common / router / rds_impl . h <nl> <nl> # include " envoy / local_info / local_info . h " <nl> # include " envoy / router / rds . h " <nl> # include " envoy / router / route_config_provider_manager . h " <nl> + # include " envoy / singleton / instance . h " <nl> # include " envoy / thread_local / thread_local . h " <nl> <nl> # include " common / common / logger . h " <nl> class RdsRouteConfigProviderImpl <nl> friend class RouteConfigProviderManagerImpl ; <nl> } ; <nl> <nl> - / / TODO ( junr03 ) : use then singleton manager in # 1410 . <nl> - class RouteConfigProviderManagerImpl : public ServerRouteConfigProviderManager { <nl> + class RouteConfigProviderManagerImpl : public ServerRouteConfigProviderManager , <nl> + public Singleton : : Instance { <nl> public : <nl> RouteConfigProviderManagerImpl ( Runtime : : Loader & runtime , Event : : Dispatcher & dispatcher , <nl> Runtime : : RandomGenerator & random , <nl> mmm a / source / common / singleton / manager_impl . cc <nl> ppp b / source / common / singleton / manager_impl . cc <nl> <nl> namespace Envoy { <nl> namespace Singleton { <nl> <nl> - InstancePtr ManagerImpl : : get ( const std : : string & name , SingletonFactoryCb cb ) { <nl> + InstanceSharedPtr ManagerImpl : : get ( const std : : string & name , SingletonFactoryCb cb ) { <nl> ASSERT ( run_tid_ = = Thread : : Thread : : currentThreadId ( ) ) ; <nl> if ( nullptr = = Registry : : FactoryRegistry < Registration > : : getFactory ( name ) ) { <nl> PANIC ( fmt : : format ( " invalid singleton name ' { } ' . Make sure it is registered . " , name ) ) ; <nl> } <nl> <nl> if ( nullptr = = singletons_ [ name ] . lock ( ) ) { <nl> - InstancePtr singleton = cb ( ) ; <nl> + InstanceSharedPtr singleton = cb ( ) ; <nl> singletons_ [ name ] = singleton ; <nl> return singleton ; <nl> } else { <nl> mmm a / source / common / singleton / manager_impl . h <nl> ppp b / source / common / singleton / manager_impl . h <nl> class ManagerImpl : public Manager { <nl> ManagerImpl ( ) : run_tid_ ( Thread : : Thread : : currentThreadId ( ) ) { } <nl> <nl> / / Singleton : : Manager <nl> - InstancePtr get ( const std : : string & name , SingletonFactoryCb cb ) override ; <nl> + InstanceSharedPtr get ( const std : : string & name , SingletonFactoryCb cb ) override ; <nl> <nl> private : <nl> std : : unordered_map < std : : string , std : : weak_ptr < Instance > > singletons_ ; <nl> mmm a / source / server / config / network / BUILD <nl> ppp b / source / server / config / network / BUILD <nl> envoy_cc_library ( <nl> " / / include / envoy / filesystem : filesystem_interface " , <nl> " / / include / envoy / http : filter_interface " , <nl> " / / include / envoy / registry " , <nl> + " / / include / envoy / router : route_config_provider_manager_interface " , <nl> " / / include / envoy / server : filter_config_interface " , <nl> " / / include / envoy / server : options_interface " , <nl> " / / include / envoy / stats : stats_interface " , <nl> mmm a / source / server / config / network / http_connection_manager . cc <nl> ppp b / source / server / config / network / http_connection_manager . cc <nl> namespace Configuration { <nl> <nl> const std : : string HttpConnectionManagerConfig : : DEFAULT_SERVER_STRING = " envoy " ; <nl> <nl> - static constexpr char date_provider_singleton_name [ ] = " date_provider_singleton " ; <nl> - static Registry : : RegisterFactory < Singleton : : RegistrationImpl < date_provider_singleton_name > , <nl> - Singleton : : Registration > <nl> - date_provider_singleton_registered_ ; <nl> + / / Singleton registration via macro defined in envoy / singleton / manager . h <nl> + SINGLETON_MANAGER_REGISTRATION ( date_provider ) ; <nl> + SINGLETON_MANAGER_REGISTRATION ( route_config_provider_manager ) ; <nl> <nl> NetworkFilterFactoryCb HttpConnectionManagerFilterConfigFactory : : createFilterFactory ( <nl> const Json : : Object & json_http_connection_manager , FactoryContext & context ) { <nl> std : : shared_ptr < Http : : TlsCachingDateProviderImpl > date_provider = <nl> context . singletonManager ( ) . getTyped < Http : : TlsCachingDateProviderImpl > ( <nl> - date_provider_singleton_name , [ & context ] { <nl> + SINGLETON_MANAGER_REGISTERED_NAME ( date_provider ) , [ & context ] { <nl> return std : : make_shared < Http : : TlsCachingDateProviderImpl > ( context . dispatcher ( ) , <nl> context . threadLocal ( ) ) ; <nl> } ) ; <nl> <nl> + std : : shared_ptr < Router : : RouteConfigProviderManager > route_config_provider_manager = <nl> + context . singletonManager ( ) . getTyped < Router : : RouteConfigProviderManager > ( <nl> + SINGLETON_MANAGER_REGISTERED_NAME ( route_config_provider_manager ) , [ & context ] { <nl> + return std : : make_shared < Router : : RouteConfigProviderManagerImpl > ( <nl> + context . runtime ( ) , context . dispatcher ( ) , context . random ( ) , context . localInfo ( ) , <nl> + context . threadLocal ( ) ) ; <nl> + } ) ; <nl> + <nl> envoy : : api : : v2 : : filter : : HttpConnectionManager http_connection_manager ; <nl> Config : : FilterJson : : translateHttpConnectionManager ( json_http_connection_manager , <nl> http_connection_manager ) ; <nl> - std : : shared_ptr < HttpConnectionManagerConfig > http_config ( <nl> - new HttpConnectionManagerConfig ( http_connection_manager , context , * date_provider ) ) ; <nl> - return [ http_config , & context , date_provider ] ( Network : : FilterManager & filter_manager ) - > void { <nl> + std : : shared_ptr < HttpConnectionManagerConfig > http_config ( new HttpConnectionManagerConfig ( <nl> + http_connection_manager , context , * date_provider , * route_config_provider_manager ) ) ; <nl> + <nl> + / / This lambda captures the shared_ptrs created above , thus preserving the <nl> + / / reference count . Moreover , keep in mind the capture list determines <nl> + / / destruction order . <nl> + return [ route_config_provider_manager , http_config , & context , <nl> + date_provider ] ( Network : : FilterManager & filter_manager ) - > void { <nl> filter_manager . addReadFilter ( Network : : ReadFilterSharedPtr { new Http : : ConnectionManagerImpl ( <nl> * http_config , context . drainDecision ( ) , context . random ( ) , context . httpTracer ( ) , <nl> context . runtime ( ) , context . localInfo ( ) , context . clusterManager ( ) ) } ) ; <nl> HttpConnectionManagerConfigUtility : : determineNextProtocol ( Network : : Connection & c <nl> <nl> HttpConnectionManagerConfig : : HttpConnectionManagerConfig ( <nl> const envoy : : api : : v2 : : filter : : HttpConnectionManager & config , FactoryContext & context , <nl> - Http : : DateProvider & date_provider ) <nl> + Http : : DateProvider & date_provider , <nl> + Router : : RouteConfigProviderManager & route_config_provider_manager ) <nl> : context_ ( context ) , stats_prefix_ ( fmt : : format ( " http . { } . " , config . stat_prefix ( ) ) ) , <nl> stats_ ( Http : : ConnectionManagerImpl : : generateStats ( stats_prefix_ , context_ . scope ( ) ) ) , <nl> tracing_stats_ ( <nl> Http : : ConnectionManagerImpl : : generateTracingStats ( stats_prefix_ , context_ . scope ( ) ) ) , <nl> use_remote_address_ ( PROTOBUF_GET_WRAPPED_OR_DEFAULT ( config , use_remote_address , false ) ) , <nl> + route_config_provider_manager_ ( route_config_provider_manager ) , <nl> http2_settings_ ( Http : : Utility : : parseHttp2Settings ( config . http2_protocol_options ( ) ) ) , <nl> http1_settings_ ( Http : : Utility : : parseHttp1Settings ( config . http_protocol_options ( ) ) ) , <nl> drain_timeout_ ( PROTOBUF_GET_MS_OR_DEFAULT ( config , drain_timeout , 5000 ) ) , <nl> generate_request_id_ ( PROTOBUF_GET_WRAPPED_OR_DEFAULT ( config , generate_request_id , true ) ) , <nl> + <nl> date_provider_ ( date_provider ) { <nl> <nl> route_config_provider_ = Router : : RouteConfigProviderUtil : : create ( <nl> config , context_ . runtime ( ) , context_ . clusterManager ( ) , context_ . scope ( ) , stats_prefix_ , <nl> - context_ . initManager ( ) , context_ . routeConfigProviderManager ( ) ) ; <nl> + context_ . initManager ( ) , route_config_provider_manager_ ) ; <nl> <nl> switch ( config . forward_client_cert_details ( ) ) { <nl> case envoy : : api : : v2 : : filter : : HttpConnectionManager : : SANITIZE : <nl> mmm a / source / server / config / network / http_connection_manager . h <nl> ppp b / source / server / config / network / http_connection_manager . h <nl> <nl> # include < string > <nl> <nl> # include " envoy / http / filter . h " <nl> + # include " envoy / router / route_config_provider_manager . h " <nl> # include " envoy / server / filter_config . h " <nl> <nl> # include " common / common / logger . h " <nl> class HttpConnectionManagerConfig : Logger : : Loggable < Logger : : Id : : config > , <nl> public Http : : ConnectionManagerConfig { <nl> public : <nl> HttpConnectionManagerConfig ( const envoy : : api : : v2 : : filter : : HttpConnectionManager & config , <nl> - FactoryContext & context , Http : : DateProvider & date_provider ) ; <nl> + FactoryContext & context , Http : : DateProvider & date_provider , <nl> + Router : : RouteConfigProviderManager & route_config_provider_manager ) ; <nl> <nl> / / Http : : FilterChainFactory <nl> void createFilterChain ( Http : : FilterChainFactoryCallbacks & callbacks ) override ; <nl> class HttpConnectionManagerConfig : Logger : : Loggable < Logger : : Id : : config > , <nl> const bool use_remote_address_ { } ; <nl> Http : : ForwardClientCertType forward_client_cert_ ; <nl> std : : vector < Http : : ClientCertDetailsType > set_current_client_cert_details_ ; <nl> + Router : : RouteConfigProviderManager & route_config_provider_manager_ ; <nl> CodecType codec_type_ ; <nl> const Http : : Http2Settings http2_settings_ ; <nl> const Http : : Http1Settings http1_settings_ ; <nl> mmm a / source / server / config_validation / server . cc <nl> ppp b / source / server / config_validation / server . cc <nl> void ValidationInstance : : initialize ( Options & options , <nl> thread_local_ . registerThread ( * dispatcher_ , true ) ; <nl> runtime_loader_ = component_factory . createRuntime ( * this , initial_config ) ; <nl> ssl_context_manager_ . reset ( new Ssl : : ContextManagerImpl ( * runtime_loader_ ) ) ; <nl> - route_config_provider_manager_ . reset ( new Router : : RouteConfigProviderManagerImpl ( <nl> - runtime ( ) , dispatcher ( ) , random ( ) , localInfo ( ) , threadLocal ( ) ) ) ; <nl> cluster_manager_factory_ . reset ( new Upstream : : ValidationClusterManagerFactory ( <nl> runtime ( ) , stats ( ) , threadLocal ( ) , random ( ) , dnsResolver ( ) , sslContextManager ( ) , dispatcher ( ) , <nl> localInfo ( ) ) ) ; <nl> mmm a / source / server / config_validation / server . h <nl> ppp b / source / server / config_validation / server . h <nl> class ValidationInstance : Logger : : Loggable < Logger : : Id : : main > , <nl> Tracing : : HttpTracer & httpTracer ( ) override { return config_ - > httpTracer ( ) ; } <nl> ThreadLocal : : Instance & threadLocal ( ) override { return thread_local_ ; } <nl> const LocalInfo : : LocalInfo & localInfo ( ) override { return * local_info_ ; } <nl> - Router : : ServerRouteConfigProviderManager & routeConfigProviderManager ( ) override { <nl> - return * route_config_provider_manager_ ; <nl> - } <nl> <nl> / / Server : : ListenerComponentFactory <nl> std : : vector < Configuration : : NetworkFilterFactoryCb > <nl> class ValidationInstance : Logger : : Loggable < Logger : : Id : : main > , <nl> AccessLog : : AccessLogManagerImpl access_log_manager_ ; <nl> std : : unique_ptr < Upstream : : ValidationClusterManagerFactory > cluster_manager_factory_ ; <nl> InitManagerImpl init_manager_ ; <nl> - std : : unique_ptr < Router : : RouteConfigProviderManagerImpl > route_config_provider_manager_ ; <nl> ListenerManagerImpl listener_manager_ ; <nl> } ; <nl> <nl> mmm a / source / server / listener_manager_impl . h <nl> ppp b / source / server / listener_manager_impl . h <nl> class ListenerImpl : public Listener , <nl> Stats : : Scope & scope ( ) override { return * global_scope_ ; } <nl> Singleton : : Manager & singletonManager ( ) override { return parent_ . server_ . singletonManager ( ) ; } <nl> ThreadLocal : : Instance & threadLocal ( ) override { return parent_ . server_ . threadLocal ( ) ; } <nl> - Router : : RouteConfigProviderManager & routeConfigProviderManager ( ) override { <nl> - return parent_ . server_ . routeConfigProviderManager ( ) ; <nl> - } <nl> <nl> / / Network : : DrainDecision <nl> bool drainClose ( ) const override ; <nl> mmm a / source / server / server . cc <nl> ppp b / source / server / server . cc <nl> void InstanceImpl : : initialize ( Options & options , <nl> runtime ( ) , stats ( ) , threadLocal ( ) , random ( ) , dnsResolver ( ) , sslContextManager ( ) , dispatcher ( ) , <nl> localInfo ( ) ) ) ; <nl> <nl> - route_config_provider_manager_ . reset ( new Router : : RouteConfigProviderManagerImpl ( <nl> - runtime ( ) , dispatcher ( ) , random ( ) , localInfo ( ) , threadLocal ( ) ) ) ; <nl> - <nl> / / Now the configuration gets parsed . The configuration may start setting thread local data <nl> / / per above . See MainImpl : : initialize ( ) for why we do this pointer dance . <nl> Configuration : : MainImpl * main_config = new Configuration : : MainImpl ( ) ; <nl> mmm a / source / server / server . h <nl> ppp b / source / server / server . h <nl> class InstanceImpl : Logger : : Loggable < Logger : : Id : : main > , public Instance { <nl> Tracing : : HttpTracer & httpTracer ( ) override ; <nl> ThreadLocal : : Instance & threadLocal ( ) override { return thread_local_ ; } <nl> const LocalInfo : : LocalInfo & localInfo ( ) override { return * local_info_ ; } <nl> - Router : : ServerRouteConfigProviderManager & routeConfigProviderManager ( ) override { <nl> - return * route_config_provider_manager_ ; <nl> - } <nl> <nl> private : <nl> void flushStats ( ) ; <nl> mmm a / test / mocks / server / mocks . cc <nl> ppp b / test / mocks / server / mocks . cc <nl> MockInstance : : MockInstance ( ) <nl> ON_CALL ( * this , drainManager ( ) ) . WillByDefault ( ReturnRef ( drain_manager_ ) ) ; <nl> ON_CALL ( * this , initManager ( ) ) . WillByDefault ( ReturnRef ( init_manager_ ) ) ; <nl> ON_CALL ( * this , listenerManager ( ) ) . WillByDefault ( ReturnRef ( listener_manager_ ) ) ; <nl> - ON_CALL ( * this , routeConfigProviderManager ( ) ) <nl> - . WillByDefault ( ReturnRef ( route_config_provider_manager_ ) ) ; <nl> ON_CALL ( * this , singletonManager ( ) ) . WillByDefault ( ReturnRef ( * singleton_manager_ ) ) ; <nl> } <nl> <nl> MockFactoryContext : : MockFactoryContext ( ) : singleton_manager_ ( new Singleton : : Man <nl> ON_CALL ( * this , server ( ) ) . WillByDefault ( ReturnRef ( server_ ) ) ; <nl> ON_CALL ( * this , singletonManager ( ) ) . WillByDefault ( ReturnRef ( * singleton_manager_ ) ) ; <nl> ON_CALL ( * this , threadLocal ( ) ) . WillByDefault ( ReturnRef ( thread_local_ ) ) ; <nl> - ON_CALL ( * this , routeConfigProviderManager ( ) ) <nl> - . WillByDefault ( ReturnRef ( route_config_provider_manager_ ) ) ; <nl> } <nl> <nl> MockFactoryContext : : ~ MockFactoryContext ( ) { } <nl> mmm a / test / mocks / server / mocks . h <nl> ppp b / test / mocks / server / mocks . h <nl> class MockInstance : public Instance { <nl> MOCK_METHOD0 ( httpTracer , Tracing : : HttpTracer & ( ) ) ; <nl> MOCK_METHOD0 ( threadLocal , ThreadLocal : : Instance & ( ) ) ; <nl> MOCK_METHOD0 ( localInfo , const LocalInfo : : LocalInfo & ( ) ) ; <nl> - MOCK_METHOD0 ( routeConfigProviderManager , Router : : ServerRouteConfigProviderManager & ( ) ) ; <nl> <nl> testing : : NiceMock < ThreadLocal : : MockInstance > thread_local_ ; <nl> Stats : : IsolatedStoreImpl stats_store_ ; <nl> class MockInstance : public Instance { <nl> testing : : NiceMock < Runtime : : MockRandomGenerator > random_ ; <nl> testing : : NiceMock < LocalInfo : : MockLocalInfo > local_info_ ; <nl> testing : : NiceMock < Init : : MockManager > init_manager_ ; <nl> - testing : : NiceMock < Router : : MockRouteConfigProviderManager > route_config_provider_manager_ ; <nl> testing : : NiceMock < MockListenerManager > listener_manager_ ; <nl> Singleton : : ManagerPtr singleton_manager_ ; <nl> } ; <nl> class MockFactoryContext : public FactoryContext { <nl> MOCK_METHOD0 ( server , Instance & ( ) ) ; <nl> MOCK_METHOD0 ( singletonManager , Singleton : : Manager & ( ) ) ; <nl> MOCK_METHOD0 ( threadLocal , ThreadLocal : : Instance & ( ) ) ; <nl> - MOCK_METHOD0 ( routeConfigProviderManager , Router : : RouteConfigProviderManager & ( ) ) ; <nl> <nl> testing : : NiceMock < AccessLog : : MockAccessLogManager > access_log_manager_ ; <nl> testing : : NiceMock < Upstream : : MockClusterManager > cluster_manager_ ; <nl> - testing : : NiceMock < Router : : MockRouteConfigProviderManager > route_config_provider_manager_ ; <nl> testing : : NiceMock < Event : : MockDispatcher > dispatcher_ ; <nl> testing : : NiceMock < MockDrainManager > drain_manager_ ; <nl> testing : : NiceMock < Tracing : : MockHttpTracer > http_tracer_ ; <nl> mmm a / test / server / config / network / BUILD <nl> ppp b / test / server / config / network / BUILD <nl> envoy_cc_test ( <nl> " / / source / common / buffer : buffer_lib " , <nl> " / / source / common / config : filter_json_lib " , <nl> " / / source / common / event : dispatcher_lib " , <nl> + " / / source / common / router : rds_lib " , <nl> " / / source / server / config / http : dynamo_lib " , <nl> " / / source / server / config / network : http_connection_manager_lib " , <nl> " / / test / mocks / network : network_mocks " , <nl> mmm a / test / server / config / network / http_connection_manager_test . cc <nl> ppp b / test / server / config / network / http_connection_manager_test . cc <nl> <nl> # include " common / buffer / buffer_impl . h " <nl> # include " common / config / filter_json . h " <nl> # include " common / http / date_provider_impl . h " <nl> + # include " common / router / rds_impl . h " <nl> <nl> # include " server / config / network / http_connection_manager . h " <nl> <nl> class HttpConnectionManagerConfigTest : public testing : : Test { <nl> public : <nl> NiceMock < MockFactoryContext > context_ ; <nl> Http : : SlowDateProviderImpl date_provider_ ; <nl> + Router : : RouteConfigProviderManagerImpl route_config_provider_manager_ { <nl> + context_ . runtime ( ) , context_ . dispatcher ( ) , context_ . random ( ) , context_ . localInfo ( ) , <nl> + context_ . threadLocal ( ) } ; <nl> } ; <nl> <nl> TEST_F ( HttpConnectionManagerConfigTest , InvalidFilterName ) { <nl> TEST_F ( HttpConnectionManagerConfigTest , InvalidFilterName ) { <nl> <nl> EXPECT_THROW_WITH_MESSAGE ( <nl> HttpConnectionManagerConfig ( parseHttpConnectionManagerFromJson ( json_string ) , context_ , <nl> - date_provider_ ) , <nl> + date_provider_ , route_config_provider_manager_ ) , <nl> EnvoyException , " unable to create http filter factory for ' foo ' " ) ; <nl> } <nl> <nl> TEST_F ( HttpConnectionManagerConfigTest , MiscConfig ) { <nl> ) EOF " ; <nl> <nl> HttpConnectionManagerConfig config ( parseHttpConnectionManagerFromJson ( json_string ) , context_ , <nl> - date_provider_ ) ; <nl> + date_provider_ , route_config_provider_manager_ ) ; <nl> + <nl> EXPECT_THAT ( std : : vector < Http : : LowerCaseString > ( { Http : : LowerCaseString ( " foo " ) } ) , <nl> ContainerEq ( config . tracingConfig ( ) - > request_headers_for_tags_ ) ) ; <nl> EXPECT_EQ ( * context_ . local_info_ . address_ , config . localAddress ( ) ) ; <nl>
move route config provider manager to singleton manager registry ( )
envoyproxy/envoy
fc1097e0400d97b9071b62f452a0222ff8934bb7
2017-08-17T01:25:17Z
new file mode 100644 <nl> index 000000000000 . . 7d0ea57e3298 <nl> mmm / dev / null <nl> ppp b / jstests / geo_multikey0 . js <nl> <nl> + / / Multikey geo values tests - SERVER - 3793 . <nl> + <nl> + t = db . jstests_geo_multikey0 ; <nl> + t . drop ( ) ; <nl> + <nl> + / / Check that conflicting constraints are satisfied by parallel array elements . <nl> + t . save ( { loc : [ { x : 20 , y : 30 } , { x : 30 , y : 40 } ] } ) ; <nl> + assert . eq ( 1 , t . count ( { loc : { x : 20 , y : 30 } , $ and : [ { loc : { $ gt : { x : 20 , y : 35 } , $ lt : { x : 20 , y : 34 } } } ] } ) ) ; <nl> + <nl> + / / Check that conflicting constraints are satisfied by parallel array elements with a 2d index on loc . <nl> + if ( 0 ) { / / SERVER - 3793 <nl> + t . ensureIndex ( { loc : ' 2d ' } ) ; <nl> + assert . eq ( 1 , t . count ( { loc : { x : 20 , y : 30 } , $ and : [ { loc : { $ gt : { x : 20 , y : 35 } , $ lt : { x : 20 , y : 34 } } } ] } ) ) ; <nl> + } <nl> + <nl> + t . drop ( ) ; <nl> + <nl> + / / Check that conflicting constraints are satisfied by parallel array elements of x . <nl> + t . save ( { loc : [ 20 , 30 ] , x : [ 1 , 2 ] } ) ; <nl> + assert . eq ( 1 , t . count ( { loc : [ 20 , 30 ] , x : { $ gt : 1 . 7 , $ lt : 1 . 2 } } ) ) ; <nl> + <nl> + / / Check that conflicting constraints are satisfied by parallel array elements of x with a 2d index on loc , x . <nl> + if ( 0 ) { / / SERVER - 3793 <nl> + t . ensureIndex ( { loc : ' 2d ' , x : 1 } ) ; <nl> + assert . eq ( 1 , t . count ( { loc : [ 20 , 30 ] , x : { $ gt : 1 . 7 , $ lt : 1 . 2 } } ) ) ; <nl> + } <nl>
SERVER - 3793 test
mongodb/mongo
812b3dbb385c3267f918765fecd6742adda53ce9
2011-09-12T18:46:18Z
mmm a / xbmc / cores / dvdplayer / DVDCodecs / DVDFactoryCodec . cpp <nl> ppp b / xbmc / cores / dvdplayer / DVDCodecs / DVDFactoryCodec . cpp <nl> CDVDVideoCodec * CDVDFactoryCodec : : CreateVideoCodec ( CDVDStreamInfo & hint , const C <nl> } <nl> # endif <nl> <nl> - std : : string value = StringUtils : : Format ( " % d " , info . optimal_buffer_size ) ; <nl> + std : : string value = StringUtils : : Format ( " % d " , info . max_buffer_size ) ; <nl> options . m_keys . push_back ( CDVDCodecOption ( " surfaces " , value ) ) ; <nl> if ( ( pCodec = OpenCodec ( new CDVDVideoCodecFFmpeg ( ) , hint , options ) ) ) return pCodec ; <nl> <nl>
Merge pull request from popcornmix / render_fix
xbmc/xbmc
6cb9c13606b87c90a45bd423f30426565928bedf
2015-05-11T19:26:51Z
mmm a / util / options_helper . cc <nl> ppp b / util / options_helper . cc <nl> bool ParseOptionHelper ( char * opt_address , const OptionType & opt_type , <nl> return ParseEnum < EncodingType > ( <nl> encoding_type_string_map , value , <nl> reinterpret_cast < EncodingType * > ( opt_address ) ) ; <nl> + case OptionType : : kWALRecoveryMode : <nl> + return ParseEnum < WALRecoveryMode > ( <nl> + wal_recovery_mode_string_map , value , <nl> + reinterpret_cast < WALRecoveryMode * > ( opt_address ) ) ; <nl> + case OptionType : : kAccessHint : <nl> + return ParseEnum < DBOptions : : AccessHint > ( <nl> + access_hint_string_map , value , <nl> + reinterpret_cast < DBOptions : : AccessHint * > ( opt_address ) ) ; <nl> + case OptionType : : kInfoLogLevel : <nl> + return ParseEnum < InfoLogLevel > ( <nl> + info_log_level_string_map , value , <nl> + reinterpret_cast < InfoLogLevel * > ( opt_address ) ) ; <nl> default : <nl> return false ; <nl> } <nl> bool SerializeSingleOptionHelper ( const char * opt_address , <nl> return SerializeEnum < EncodingType > ( <nl> encoding_type_string_map , <nl> * reinterpret_cast < const EncodingType * > ( opt_address ) , value ) ; <nl> + case OptionType : : kWALRecoveryMode : <nl> + return SerializeEnum < WALRecoveryMode > ( <nl> + wal_recovery_mode_string_map , <nl> + * reinterpret_cast < const WALRecoveryMode * > ( opt_address ) , value ) ; <nl> + case OptionType : : kAccessHint : <nl> + return SerializeEnum < DBOptions : : AccessHint > ( <nl> + access_hint_string_map , <nl> + * reinterpret_cast < const DBOptions : : AccessHint * > ( opt_address ) , value ) ; <nl> + case OptionType : : kInfoLogLevel : <nl> + return SerializeEnum < InfoLogLevel > ( <nl> + info_log_level_string_map , <nl> + * reinterpret_cast < const InfoLogLevel * > ( opt_address ) , value ) ; <nl> default : <nl> return false ; <nl> } <nl> mmm a / util / options_helper . h <nl> ppp b / util / options_helper . h <nl> enum class OptionType { <nl> kFlushBlockPolicyFactory , <nl> kChecksumType , <nl> kEncodingType , <nl> + kWALRecoveryMode , <nl> + kAccessHint , <nl> + kInfoLogLevel , <nl> kUnknown <nl> } ; <nl> <nl> Status GetColumnFamilyOptionsFromMapInternal ( <nl> static std : : unordered_map < std : : string , OptionTypeInfo > db_options_type_info = { <nl> / * <nl> / / not yet supported <nl> - AccessHint access_hint_on_compaction_start ; <nl> Env * env ; <nl> - InfoLogLevel info_log_level ; <nl> - WALRecoveryMode wal_recovery_mode ; <nl> std : : shared_ptr < Cache > row_cache ; <nl> std : : shared_ptr < DeleteScheduler > delete_scheduler ; <nl> std : : shared_ptr < Logger > info_log ; <nl> static std : : unordered_map < std : : string , OptionTypeInfo > db_options_type_info = { <nl> OptionVerificationType : : kNormal } } , <nl> { " stats_dump_period_sec " , <nl> { offsetof ( struct DBOptions , stats_dump_period_sec ) , OptionType : : kUInt , <nl> + OptionVerificationType : : kNormal } } , <nl> + { " fail_if_options_file_error " , <nl> + { offsetof ( struct DBOptions , fail_if_options_file_error ) , <nl> + OptionType : : kBoolean , OptionVerificationType : : kNormal } } , <nl> + { " allow_concurrent_memtable_write " , <nl> + { offsetof ( struct DBOptions , allow_concurrent_memtable_write ) , <nl> + OptionType : : kBoolean , OptionVerificationType : : kNormal } } , <nl> + { " wal_recovery_mode " , <nl> + { offsetof ( struct DBOptions , wal_recovery_mode ) , <nl> + OptionType : : kWALRecoveryMode , OptionVerificationType : : kNormal } } , <nl> + { " enable_write_thread_adaptive_yield " , <nl> + { offsetof ( struct DBOptions , enable_write_thread_adaptive_yield ) , <nl> + OptionType : : kBoolean , OptionVerificationType : : kNormal } } , <nl> + { " write_thread_slow_yield_usec " , <nl> + { offsetof ( struct DBOptions , write_thread_slow_yield_usec ) , <nl> + OptionType : : kUInt64T , OptionVerificationType : : kNormal } } , <nl> + { " write_thread_max_yield_usec " , <nl> + { offsetof ( struct DBOptions , write_thread_max_yield_usec ) , <nl> + OptionType : : kUInt64T , OptionVerificationType : : kNormal } } , <nl> + { " access_hint_on_compaction_start " , <nl> + { offsetof ( struct DBOptions , access_hint_on_compaction_start ) , <nl> + OptionType : : kAccessHint , OptionVerificationType : : kNormal } } , <nl> + { " info_log_level " , <nl> + { offsetof ( struct DBOptions , info_log_level ) , OptionType : : kInfoLogLevel , <nl> OptionVerificationType : : kNormal } } } ; <nl> <nl> static std : : unordered_map < std : : string , OptionTypeInfo > cf_options_type_info = { <nl> static std : : unordered_map < std : : string , CompactionStyle > <nl> { " kCompactionStyleFIFO " , kCompactionStyleFIFO } , <nl> { " kCompactionStyleNone " , kCompactionStyleNone } } ; <nl> <nl> + static std : : unordered_map < std : : string , <nl> + WALRecoveryMode > wal_recovery_mode_string_map = { <nl> + { " kTolerateCorruptedTailRecords " , <nl> + WALRecoveryMode : : kTolerateCorruptedTailRecords } , <nl> + { " kAbsoluteConsistency " , WALRecoveryMode : : kAbsoluteConsistency } , <nl> + { " kPointInTimeRecovery " , WALRecoveryMode : : kPointInTimeRecovery } , <nl> + { " kSkipAnyCorruptedRecords " , WALRecoveryMode : : kSkipAnyCorruptedRecords } } ; <nl> + <nl> + static std : : unordered_map < std : : string , DBOptions : : AccessHint > <nl> + access_hint_string_map = { { " NONE " , DBOptions : : AccessHint : : NONE } , <nl> + { " NORMAL " , DBOptions : : AccessHint : : NORMAL } , <nl> + { " SEQUENTIAL " , DBOptions : : AccessHint : : SEQUENTIAL } , <nl> + { " WILLNEED " , DBOptions : : AccessHint : : WILLNEED } } ; <nl> + <nl> + static std : : unordered_map < std : : string , InfoLogLevel > info_log_level_string_map = <nl> + { { " DEBUG_LEVEL " , InfoLogLevel : : DEBUG_LEVEL } , <nl> + { " INFO_LEVEL " , InfoLogLevel : : INFO_LEVEL } , <nl> + { " WARN_LEVEL " , InfoLogLevel : : WARN_LEVEL } , <nl> + { " ERROR_LEVEL " , InfoLogLevel : : ERROR_LEVEL } , <nl> + { " FATAL_LEVEL " , InfoLogLevel : : FATAL_LEVEL } , <nl> + { " HEADER_LEVEL " , InfoLogLevel : : HEADER_LEVEL } } ; <nl> + <nl> } / / namespace rocksdb <nl> <nl> # endif / / ! ROCKSDB_LITE <nl> mmm a / util / options_parser . cc <nl> ppp b / util / options_parser . cc <nl> bool AreEqualOptions ( <nl> * reinterpret_cast < const BlockBasedTableOptions : : IndexType * > ( <nl> offset1 ) = = <nl> * reinterpret_cast < const BlockBasedTableOptions : : IndexType * > ( offset2 ) ) ; <nl> + case OptionType : : kWALRecoveryMode : <nl> + return ( * reinterpret_cast < const WALRecoveryMode * > ( offset1 ) = = <nl> + * reinterpret_cast < const WALRecoveryMode * > ( offset2 ) ) ; <nl> + case OptionType : : kAccessHint : <nl> + return ( * reinterpret_cast < const DBOptions : : AccessHint * > ( offset1 ) = = <nl> + * reinterpret_cast < const DBOptions : : AccessHint * > ( offset2 ) ) ; <nl> + case OptionType : : kInfoLogLevel : <nl> + return ( * reinterpret_cast < const InfoLogLevel * > ( offset1 ) = = <nl> + * reinterpret_cast < const InfoLogLevel * > ( offset2 ) ) ; <nl> default : <nl> if ( type_info . verification = = OptionVerificationType : : kByName | | <nl> type_info . verification = = OptionVerificationType : : kByNameAllowNull ) { <nl> mmm a / util / options_test . cc <nl> ppp b / util / options_test . cc <nl> TEST_F ( OptionsParserTest , DBOptionsAllFieldsSettable ) { <nl> options = new ( options_ptr ) DBOptions ( ) ; <nl> FillWithSpecialChar ( options_ptr , sizeof ( DBOptions ) , kDBOptionsBlacklist ) ; <nl> <nl> - / / Following options are not settable through GetDBOptionsFromString ( ) : <nl> - options - > fail_if_options_file_error = false ; <nl> - options - > allow_concurrent_memtable_write = false ; <nl> - options - > wal_recovery_mode = WALRecoveryMode : : kPointInTimeRecovery ; <nl> - options - > enable_write_thread_adaptive_yield = true ; <nl> - options - > write_thread_slow_yield_usec = true ; <nl> - options - > write_thread_max_yield_usec = 1000u ; <nl> - options - > access_hint_on_compaction_start = DBOptions : : AccessHint : : NONE ; <nl> - options - > info_log_level = InfoLogLevel : : DEBUG_LEVEL ; <nl> - <nl> char * new_options_ptr = new char [ sizeof ( DBOptions ) ] ; <nl> DBOptions * new_options = new ( new_options_ptr ) DBOptions ( ) ; <nl> FillWithSpecialChar ( new_options_ptr , sizeof ( DBOptions ) , kDBOptionsBlacklist ) ; <nl> TEST_F ( OptionsParserTest , DBOptionsAllFieldsSettable ) { <nl> " allow_mmap_reads = false ; " <nl> " max_log_file_size = 4607 ; " <nl> " random_access_max_buffer_size = 1048576 ; " <nl> - " advise_random_on_open = true ; " , <nl> + " advise_random_on_open = true ; " <nl> + " fail_if_options_file_error = false ; " <nl> + " allow_concurrent_memtable_write = true ; " <nl> + " wal_recovery_mode = kPointInTimeRecovery ; " <nl> + " enable_write_thread_adaptive_yield = true ; " <nl> + " write_thread_slow_yield_usec = 5 ; " <nl> + " write_thread_max_yield_usec = 1000 ; " <nl> + " access_hint_on_compaction_start = NONE ; " <nl> + " info_log_level = DEBUG_LEVEL ; " , <nl> new_options ) ) ; <nl> <nl> ASSERT_EQ ( unset_bytes_base , NumUnsetBytes ( new_options_ptr , sizeof ( DBOptions ) , <nl>
Add parsing of missing DB options
facebook/rocksdb
deb08b8226a6e54038c48d62394c585a94a7f181
2016-03-02T18:34:14Z
mmm a / CHANGELOG . md <nl> ppp b / CHANGELOG . md <nl> using the ` . dynamicType ` member to retrieve the type of an expression should mig <nl> ` ` ` swift <nl> let a : Foo & Bar <nl> let b = value as ? A & B & C <nl> - func foo < T : Foo & Bar > ( x : T ) { … } <nl> - func bar ( x : Foo & Bar ) { … } <nl> + func foo < T : Foo & Bar > ( x : T ) { . . . } <nl> + func bar ( x : Foo & Bar ) { . . . } <nl> typealias G = GenericStruct < Foo & Bar > <nl> ` ` ` <nl> <nl> Swift 2 . 0 <nl> * Public extensions of generic types are now permitted . <nl> <nl> ` ` ` swift <nl> - public extension Array { … } <nl> + public extension Array { . . . } <nl> ` ` ` <nl> <nl> * * ( 16974298 ) * * <nl> Swift 2 . 0 <nl> For example : <nl> <nl> ` ` ` swift <nl> - func produceGizmoUsingTechnology ( ) throws - > Gizmo { … } <nl> - func produceGizmoUsingMagic ( ) throws - > Gizmo { … } <nl> + func produceGizmoUsingTechnology ( ) throws - > Gizmo { . . . } <nl> + func produceGizmoUsingMagic ( ) throws - > Gizmo { . . . } <nl> <nl> if let result = try ? produceGizmoUsingTechnology ( ) { return result } <nl> if let result = try ? produceGizmoUsingMagic ( ) { return result } <nl> Swift 2 . 0 <nl> function or initializer . For example : <nl> <nl> ` ` ` swift <nl> - func doSomethingToValues ( values : Int . . . , options : MyOptions = [ ] , fn : ( Int ) - & gt ; Void ) { … } <nl> + func doSomethingToValues ( values : Int . . . , options : MyOptions = [ ] , fn : ( Int ) - & gt ; Void ) { . . . } <nl> ` ` ` <nl> <nl> * * ( 20127197 ) * * <nl> Swift 2 . 0 <nl> * * ( 17227475 ) * * <nl> <nl> * When delegating or chaining to a failable initializer ( for example , with <nl> - ` self . init ( … ) ` or ` super . init ( … ) ` ) , one can now force - unwrap the result with <nl> + ` self . init ( . . . ) ` or ` super . init ( . . . ) ` ) , one can now force - unwrap the result with <nl> ` ! ` . For example : <nl> <nl> ` ` ` swift <nl> Swift 1 . 2 <nl> } <nl> <nl> class MySomethingDelegate : SomethingDelegate { <nl> - @ objc func didSomething ( ) { … } <nl> + @ objc func didSomething ( ) { . . . } <nl> } <nl> ` ` ` <nl> <nl> mmm a / benchmark / README . md <nl> ppp b / benchmark / README . md <nl> To add a new multiple file test : <nl> 1 . Add a new directory and files under the ` multi - source ` directory as <nl> specified below : <nl> <nl> - ├ ─ ─ multi - source <nl> - │ ├ ─ ─ YourTestName <nl> - │ │ ├ ─ ─ TestFile1 . swift <nl> - │ │ ├ ─ ─ TestFile2 . swift <nl> - │ │ ├ ─ ─ TestFile3 . swift <nl> + + - - multi - source <nl> + | + - - YourTestName <nl> + | | + - - TestFile1 . swift <nl> + | | + - - TestFile2 . swift <nl> + | | + - - TestFile3 . swift <nl> <nl> At least one run function ( specified in the template below ) must <nl> exist in the files . <nl> mmm a / docs / AccessControl . rst <nl> ppp b / docs / AccessControl . rst <nl> future , ` ` public ` ` may be used for both API and SPI , at which point we may <nl> design additional annotations to distinguish the two . <nl> <nl> By default , most entities in a source file have ` ` internal ` ` access . <nl> - This optimizes for the most common case — a single - target application <nl> - project — while not accidentally revealing entities to clients of a framework <nl> + This optimizes for the most common case - - a single - target application <nl> + project - - while not accidentally revealing entities to clients of a framework <nl> module . <nl> <nl> . . warning : : This document has not yet been updated for SE - 0117 , which adds the <nl> mmm a / docs / AccessControlInStdlib . rst <nl> ppp b / docs / AccessControlInStdlib . rst <nl> To document the reason for marking symbols public , we use comments : <nl> ` internal ` <nl> = = = = = = = = = = <nl> <nl> - In Swift , ` internal ` is an implied default everywhere — except within <nl> + In Swift , ` internal ` is an implied default everywhere - - except within <nl> ` public ` extensions and protocols . Therefore , ` internal ` should be used <nl> explicitly everywhere in the stdlib to avoid confusion . <nl> <nl> mmm a / docs / Arrays . rst <nl> ppp b / docs / Arrays . rst <nl> Swift provides three generic array types , all of which have amortized <nl> O ( 1 ) growth . In this document , statements about * * ArrayType * * apply <nl> to all three of the components . <nl> <nl> - * ` ` ContiguousArray < Element > ` ` is the fastest and simplest of the three — use <nl> + * ` ` ContiguousArray < Element > ` ` is the fastest and simplest of the three - - use <nl> this when you need " C array " performance . The elements of a <nl> ` ` ContiguousArray ` ` are always stored contiguously in memory . <nl> <nl> . . image : : ContiguousArray . png <nl> <nl> * ` ` Array < Element > ` ` is like ` ` ContiguousArray < Element > ` ` , but optimized for <nl> - efficient conversions from Cocoa and back — when ` ` Element ` ` can be a class <nl> + efficient conversions from Cocoa and back - - when ` ` Element ` ` can be a class <nl> type , ` ` Array < Element > ` ` can be backed by the ( potentially non - contiguous ) <nl> storage of an arbitrary ` ` NSArray ` ` rather than by a Swift <nl> ` ` ContiguousArray ` ` . ` ` Array < Element > ` ` also supports up - and downcasts <nl> TODO : this section is outdated . <nl> <nl> When up - casting an ` ` [ Derived ] ` ` to ` ` [ Base ] ` ` , a buffer of <nl> ` ` Derived ` ` object can simply be ` ` unsafeBitCast ` ` \ ' ed to a buffer <nl> - of elements of type ` ` Base ` ` — as long as the resulting buffer is never <nl> + of elements of type ` ` Base ` ` - - as long as the resulting buffer is never <nl> mutated . For example , we cannot allow a ` ` Base ` ` element to be <nl> inserted in the buffer , because the buffer ' s destructor will destroy <nl> the elements with the ( incorrect ) static presumption that they have <nl> mmm a / docs / GenericsManifesto . md <nl> ppp b / docs / GenericsManifesto . md <nl> func apply < . . . Args , Result > ( fn : ( Args . . . ) - > Result , / / function taking some <nl> <nl> # # # Extensions of structural types <nl> <nl> - Currently , only nominal types ( classes , structs , enums , protocols ) can be extended . One could imagine extending structural types — particularly tuple types — to allow them to , e . g . , conform to protocols . For example , pulling together variadic generics , parameterized extensions , and conditional conformances , one could express " a tuple type is ` Equatable ` if all of its element types are ` Equatable ` " : <nl> + Currently , only nominal types ( classes , structs , enums , protocols ) can be extended . One could imagine extending structural types - - particularly tuple types - - to allow them to , e . g . , conform to protocols . For example , pulling together variadic generics , parameterized extensions , and conditional conformances , one could express " a tuple type is ` Equatable ` if all of its element types are ` Equatable ` " : <nl> <nl> ` ` ` Swift <nl> extension < . . . Elements : Equatable > ( Elements . . . ) : Equatable { / / extending the tuple type " ( Elements . . . ) " to be Equatable <nl> The ` where ` clause of generic functions comes very early in the declaration , alt <nl> func containsAll < S : Sequence where Sequence . Iterator . Element = = Element > ( elements : S ) - > Bool <nl> ` ` ` <nl> <nl> - One could move the ` where ` clause to the end of the signature , so that the most important parts — name , generic parameter , parameters , result type — precede it : <nl> + One could move the ` where ` clause to the end of the signature , so that the most important parts - - name , generic parameter , parameters , result type - - precede it : <nl> <nl> ` ` ` Swift <nl> func containsAll < S : Sequence > ( elements : S ) - > Bool <nl> func foo ( value : Any ) { <nl> foo ( X ( ) ) <nl> ` ` ` <nl> <nl> - Under what circumstances should it print " P " ? If ` foo ( ) ` is defined within the same module as the conformance of ` X ` to ` P ` ? If the call is defined within the same module as the conformance of ` X ` to ` P ` ? Never ? Either of the first two answers requires significant complications in the dynamic casting infrastructure to take into account the module in which a particular dynamic cast occurred ( the first option ) or where an existential was formed ( the second option ) , while the third answer breaks the link between the static and dynamic type systems — none of which is an acceptable result . <nl> + Under what circumstances should it print " P " ? If ` foo ( ) ` is defined within the same module as the conformance of ` X ` to ` P ` ? If the call is defined within the same module as the conformance of ` X ` to ` P ` ? Never ? Either of the first two answers requires significant complications in the dynamic casting infrastructure to take into account the module in which a particular dynamic cast occurred ( the first option ) or where an existential was formed ( the second option ) , while the third answer breaks the link between the static and dynamic type systems - - none of which is an acceptable result . <nl> <nl> # # # Conditional conformances via protocol extensions <nl> <nl> mmm a / docs / GitWorkflows . rst <nl> ppp b / docs / GitWorkflows . rst <nl> Purpose <nl> Swift development has been based on SVN since its inception . As part of the <nl> transition to Git this document helps to address questions about how common SVN <nl> workflows we use today translate to their Git counterparts as well as to discuss <nl> - Git workflow practices we plan on having — at least initially — after the Git <nl> - transition . Notably we will follow a model where commits to trunk — which is <nl> - the ' master ' branch in Git — has commits land ( in the common case ) via rebasing <nl> + Git workflow practices we plan on having - - at least initially - - after the Git <nl> + transition . Notably we will follow a model where commits to trunk - - which is <nl> + the ' master ' branch in Git - - has commits land ( in the common case ) via rebasing <nl> instead of merging . This model is open to evolution later , but this mimics the <nl> workflow we have today with SVN . <nl> <nl> mmm a / docs / InitializerProblems . rst <nl> ppp b / docs / InitializerProblems . rst <nl> Problem 3 : Factory Initializers <nl> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = <nl> <nl> Finally , we try to standardize on initializers for object creation in Swift , <nl> - even going as far as to import Objective - C factory methods as initializers … but <nl> + even going as far as to import Objective - C factory methods as initializers . . . but <nl> there are some patterns that cannot be written in Swift , such as this one : : <nl> <nl> class AnyGenerator < Element > : GeneratorType { <nl> mmm a / docs / LibraryEvolution . rst <nl> ppp b / docs / LibraryEvolution . rst <nl> specifying the name of the client library along with the required version : : <nl> <nl> / / Client code <nl> @ available ( Magician 1 . 5 ) <nl> - class CrystalBallView : MagicView { / * … * / } <nl> + class CrystalBallView : MagicView { / * . . . * / } <nl> <nl> Library versions can also be checked dynamically using ` ` # available ` ` , allowing <nl> for fallback behavior when the requested library version is not present : : <nl> example using methods : : <nl> <nl> public struct Point2D { <nl> var x , y : Double <nl> - public init ( x : Double , y : Double ) { / * … * / } <nl> + public init ( x : Double , y : Double ) { / * . . . * / } <nl> } <nl> <nl> extension Point2D { <nl> polar representation : : <nl> <nl> public struct Point2D { <nl> var r , theta : Double <nl> - public init ( x : Double , y : Double ) { / * … * / } <nl> + public init ( x : Double , y : Double ) { / * . . . * / } <nl> } <nl> <nl> and the ` ` x ` ` and ` ` y ` ` properties have now disappeared . To avoid this , the <nl> can enforce its safe use . <nl> We ' ve considered two possible syntaxes for this : : <nl> <nl> @ available ( 1 . 1 ) <nl> - extension Wand : MagicType { / * … * / } <nl> + extension Wand : MagicType { / * . . . * / } <nl> <nl> and <nl> <nl> : : <nl> <nl> - extension Wand : @ available ( 1 . 1 ) MagicType { / * … * / } <nl> + extension Wand : @ available ( 1 . 1 ) MagicType { / * . . . * / } <nl> <nl> The former requires fewer changes to the language grammar , but the latter could <nl> also be used on the declaration of the type itself ( i . e . the ` ` struct ` ` <nl> mmm a / docs / MutationModel . rst <nl> ppp b / docs / MutationModel . rst <nl> The implicit ` ` self ` ` parameter of a struct or enum method is semantically an <nl> objects . <nl> <nl> A program that applies the ` ` mutating ` ` to a method of a <nl> - class — or of a protocol attributed with ` ` @ class_protocol ` ` — is <nl> + class - - or of a protocol attributed with ` ` @ class_protocol ` ` - - is <nl> ill - formed . [ Note : it is logically consistent to think of all methods <nl> of classes as read - only , even though they may in fact modify instance <nl> variables , because they never " write back " onto the source reference . ] <nl> mmm a / docs / PatternMatching . rst <nl> ppp b / docs / PatternMatching . rst <nl> Scoping <nl> <nl> Despite the lack of grouping braces , the semantics are that the statements in <nl> each case - group form their own scope , and falling off the end causes control to <nl> - resume at the end of the switch statement — i . e . " implicit break " , not " implicit <nl> + resume at the end of the switch statement - - i . e . " implicit break " , not " implicit <nl> fallthrough " . <nl> <nl> Chris seems motivated to eventually add an explicit ' fallthrough ' <nl> grouped by braces . It ' s natural to group the cases with braces as well . Doing <nl> both lets us avoid a ' case ' keyword , but otherwise it leads to ugly style , <nl> because either the last case ends in two braces on the same line or cases have <nl> to further indented . Okay , it ' s easy enough to not require braces on the match , <nl> - with the grammar saying that cases are just greedily consumed — there ' s no <nl> + with the grammar saying that cases are just greedily consumed - - there ' s no <nl> ambiguity here because the switch statement is necessarily within braces . But <nl> that leaves the code without a definitive end to the cases , and the closing <nl> braces end up causing a lot of unnecessary vertical whitespace , like so : : <nl> <nl> switch ( x ) <nl> case . foo { <nl> - / / … <nl> + / / . . . <nl> } <nl> case . bar { <nl> - / / … <nl> + / / . . . <nl> } <nl> <nl> So instead , let ' s require the switch statement to have braces , and <nl> we ' ll allow the cases to be written without them : : <nl> <nl> switch ( x ) { <nl> case . foo : <nl> - / / … <nl> + / / . . . <nl> case . bar : <nl> - / / … <nl> + / / . . . <nl> } <nl> <nl> That ' s really a lot prettier , except it breaks the rule about always grouping <nl> Non - exhaustive switches <nl> . . . . . . . . . . . . . . . . . . . . . . . <nl> <nl> Since falling out of a statement is reasonable behavior in an <nl> - imperative language — in contrast to , say , a functional language where <nl> - you ' re in an expression and you need to produce a value — there ' s a <nl> + imperative language - - in contrast to , say , a functional language where <nl> + you ' re in an expression and you need to produce a value - - there ' s a <nl> colorable argument that non - exhaustive matches should be okay . I <nl> dislike this , however , and propose that it should be an error to <nl> make a non - exhaustive switch ; people who want non - exhaustive matches <nl> major clients : <nl> You might think that having a " pattern " as basic as : code : ` foo ` mean <nl> something different in two different contexts would be confusing , but <nl> actually I don ' t think people will generally think of these as the <nl> - same production — you might if you were in a functional language where <nl> + same production - - you might if you were in a functional language where <nl> you really can decompose in a function signature , but we don ' t allow <nl> that , and I think that will serve to divide them in programmers ' minds . <nl> So we can get away with some things . : ) <nl> It would be interesting to allow overloading / customization of <nl> pattern - matching . We may find ourselves needing to do something like this to <nl> support non - fragile pattern matching anyway ( if there ' s some set of restrictions <nl> that make it reasonable to permit that ) . The obvious idea of compiling into the <nl> - visitor pattern is a bit compelling , although control flow would be tricky — <nl> + visitor pattern is a bit compelling , although control flow would be tricky - - <nl> we ' d probably need the generated code to throw an exception . Alternatively , we <nl> could let the non - fragile type convert itself into a fragile type for purposes <nl> of pattern matching . <nl> mmm a / docs / SequencesAndCollections . rst <nl> ppp b / docs / SequencesAndCollections . rst <nl> taxonomy exists and how it is structured . <nl> Sequences <nl> = = = = = = = = = <nl> <nl> - It all begins with Swift ' s ` for ` \ … \ ` in ` loop : : <nl> + It all begins with Swift ' s ` for ` \ . . . \ ` in ` loop : : <nl> <nl> for x in s { <nl> doSomethingWith ( x ) <nl> represented by the ` SequenceType ` protocol : : <nl> <nl> . . sidebar : : Hiding Iterator Type Details <nl> <nl> - A sequence ' s iterator is an associated type — rather than something <nl> - like | AnyIterator | __ that depends only on the element type — for <nl> + A sequence ' s iterator is an associated type - - rather than something <nl> + like | AnyIterator | __ that depends only on the element type - - for <nl> performance reasons . Although the alternative design has <nl> significant usability benefits , it requires one dynamic <nl> allocation / deallocation pair and * N * dynamic dispatches to traverse <nl> the two kinds of sequences . <nl> are traversed . <nl> <nl> * * * Stable * * sequences , like arrays , should * not * be mutated by ` for ` \ <nl> - … \ ` in ` , and thus require * separate traversal state * . <nl> + . . . \ ` in ` , and thus require * separate traversal state * . <nl> <nl> To get an initial traversal state for an arbitrary sequence ` x ` , Swift <nl> calls ` x . makeIterator ( ) ` . The sequence delivers that state , along with <nl> traversal logic , in the form of an * * iterator * * . <nl> Iterators <nl> = = = = = = = = = = <nl> <nl> - ` for ` \ … \ ` in ` needs three operations from the iterator : <nl> + ` for ` \ . . . \ ` in ` needs three operations from the iterator : <nl> <nl> * get the current element <nl> * advance to the next element <nl> returning ` nil ` when the iterator is exhausted : : <nl> } <nl> <nl> Combined with ` SequenceType ` , we now have everything we need to <nl> - implement a generic ` for ` \ … \ ` in ` loop . <nl> + implement a generic ` for ` \ . . . \ ` in ` loop . <nl> <nl> . . sidebar : : Adding a Buffer <nl> <nl> implement a generic ` for ` \ … \ ` in ` loop . <nl> Operating on Sequences Generically <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - <nl> <nl> - Given an arbitrary ` SequenceType ` , aside from a simple ` for ` \ … \ ` in ` loop , <nl> + Given an arbitrary ` SequenceType ` , aside from a simple ` for ` \ . . . \ ` in ` loop , <nl> you can do anything that requires reading elements from beginning to <nl> end . For example : : <nl> <nl> end . For example : : <nl> let s = String ( array ( " Swift " , withSeparator : " | " ) ) <nl> print ( s ) / / " S | w | i | f | t " <nl> <nl> - Because sequences may be volatile , though , you can — in general — only <nl> + Because sequences may be volatile , though , you can - - in general - - only <nl> make a single traversal . This capability is quite enough for many <nl> languages : the iteration abstractions of Java , C # , Python , and Ruby <nl> all go about as far as ` SequenceType ` , and no further . In Swift , <nl> how we interact with arrays : we subscript the collection using its <nl> <nl> let ith = c [ i ] <nl> <nl> - An * * index * * \ — which must model ` ForwardIndexType ` \ — is a type with a <nl> + An * * index * * \ - - which must model ` ForwardIndexType ` \ - - is a type with a <nl> linear series of discrete values that can be compared for equality : <nl> <nl> . . sidebar : : Dictionary Keys <nl> All direct operations on indices are intended to be lightweight , with <nl> amortized O ( 1 ) complexity . In fact , indices into ` Dictionary ` and <nl> ` Set ` * could * be bidirectional , but are limited to modeling <nl> ` ForwardIndexType ` because the APIs of ` NSDictionary ` and <nl> - ` NSSet ` — which can act as backing stores of ` Dictionary ` and ` Set ` — do <nl> + ` NSSet ` - - which can act as backing stores of ` Dictionary ` and ` Set ` - - do <nl> not efficiently support reverse traversal . <nl> <nl> Conclusion <nl> mmm a / docs / StringDesign . rst <nl> ppp b / docs / StringDesign . rst <nl> Strings are * * Mutable * * <nl> <nl> The ability to change a string ' s value might not be worth noting <nl> except that * some languages make all strings immutable * , as a way <nl> - of working around problems that Swift has defined away — by making <nl> + of working around problems that Swift has defined away - - by making <nl> strings pure values ( see below ) . <nl> <nl> . . parsed - literal : : <nl> passes you a string * you own it * . Nobody can change a string value <nl> | swift | var c = Cave ( ) <nl> ` / / c : Cave = < Cave instance > ` <nl> | swift | s = " Hey " <nl> - | swift | var t = : look1 : ` c . say ( s ) ` \ : aside : ` this call can ' t change s … ` <nl> + | swift | var t = : look1 : ` c . say ( s ) ` \ : aside : ` this call can ' t change s . . . ` <nl> ` / / t : String = " HeyHey " ` <nl> | swift | s <nl> - ` / / s : String = ` : look : ` " Hey " ` \ : aside : ` … and it doesn ' t . ` <nl> - | swift | : look1 : ` t . addEcho ( ) ` \ : aside : ` this call can ' t change c . lastSound … ` <nl> + ` / / s : String = ` : look : ` " Hey " ` \ : aside : ` . . . and it doesn ' t . ` <nl> + | swift | : look1 : ` t . addEcho ( ) ` \ : aside : ` this call can ' t change c . lastSound . . . ` <nl> | swift | [ s , c . lastSound , t ] <nl> - ` / / r0 : [ String ] = [ " Hey " , ` : look : ` " HeyHey " ` \ : aside : ` … and it doesn ' t . ` \ ` , " HeyHeyHeyHey " ] ` <nl> + ` / / r0 : [ String ] = [ " Hey " , ` : look : ` " HeyHey " ` \ : aside : ` . . . and it doesn ' t . ` \ ` , " HeyHeyHeyHey " ] ` <nl> <nl> Strings are * * Unicode - Aware * * <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> Strings are * * Containers * * <nl> | swift | var s = " Strings are awesome " <nl> ` / / s : String = " Strings are awesome " ` <nl> | swift | var r = s . find ( " awe " ) <nl> - ` / / r : Range < StringIndex > = < " … are a ̲ w ̲ e ̲ some " > ` <nl> + ` / / r : Range < StringIndex > = < " . . . are a ̲ w ̲ e ̲ some " > ` <nl> | swift | s [ r . start ] <nl> ` / / r0 : Character = ` : look : ` Character ( " a " ) ` \ : aside : ` String elements have type Character ( see below ) ` <nl> <nl> Why a Built - In String Type ? <nl> " value semantics " in place of " C + + semantics " . I know that is what <nl> you meant , but we need to tread carefully in the final document . <nl> <nl> - ` ` NSString ` ` and ` ` NSMutableString ` ` \ — the string types provided by <nl> - Cocoa — are full - featured classes with high - level functionality for <nl> + ` ` NSString ` ` and ` ` NSMutableString ` ` \ - - the string types provided by <nl> + Cocoa - - are full - featured classes with high - level functionality for <nl> writing fully - localized applications . They have served Apple <nl> programmers well ; so , why does Swift have its own string type ? <nl> <nl> all contexts . <nl> <nl> : ` ` NSAnchoredSearch ` ` : Not applicable to whole - string comparisons <nl> : ` ` NSNumericSearch ` ` : While it ' s legitimate to defer this <nl> - functionality to Cocoa , it ' s ( probably — see <nl> + functionality to Cocoa , it ' s ( probably - - see <nl> < rdar : / / problem / 14724804 > ) locale - independent and <nl> easy enough to implement in Swift . TBD_ <nl> : ` ` NSDiacriticInsensitiveSearch ` ` : Ditto ; TBD_ <nl> Searching <nl> <nl> . . Sidebar : : Rationale <nl> <nl> - Modern languages ( Java , C # , Python , Ruby … ) have standardized on <nl> + Modern languages ( Java , C # , Python , Ruby . . . ) have standardized on <nl> variants of ` ` startsWith ` ` / \ ` ` endsWith ` ` . There ' s no reason Swift <nl> should deviate from de - facto industry standards here . <nl> <nl> Dynamic Formatting <nl> . . parsed - literal : : <nl> \ - ( NSString \ * ) \ * * stringByAppendingFormat : * * \ ( NSString \ * ) format , . . . NS_FORMAT_FUNCTION ( 1 , 2 ) ; <nl> <nl> - : Swift : * Not directly provided * \ — see the * Swift formatting proposal * <nl> + : Swift : * Not directly provided * \ - - see the * Swift formatting proposal * <nl> <nl> Extracting Numeric Values <nl> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> Extracting Numeric Values <nl> \ - ( long long ) longLongValue ; <nl> \ - ( BOOL ) boolValue ; <nl> <nl> - : Swift : Not in ` ` String ` ` \ — It is up to other types to provide their <nl> + : Swift : Not in ` ` String ` ` \ - - It is up to other types to provide their <nl> conversions to and from String . See also this ` rationale ` __ <nl> <nl> __ extending_ <nl> mmm a / docs / TextFormatting . rst <nl> ppp b / docs / TextFormatting . rst <nl> Formatting Variants <nl> mmmmmmmmmmmmmmmmmm - <nl> <nl> ` ` CustomStringConvertible ` ` types with parameterized textual representations <nl> - ( e . g . number types ) * additionally * support a ` ` format ( … ) ` ` method <nl> + ( e . g . number types ) * additionally * support a ` ` format ( . . . ) ` ` method <nl> parameterized according to that type ' s axes of variability : : <nl> <nl> print ( offset ) <nl> print ( offset . format ( ) ) / / equivalent to previous line <nl> print ( offset . format ( radix : 16 , width : 5 , precision : 3 ) ) <nl> <nl> - Although ` ` format ( … ) ` ` is intended to provide the most general <nl> + Although ` ` format ( . . . ) ` ` is intended to provide the most general <nl> interface , specialized formatting interfaces are also possible : : <nl> <nl> print ( offset . hex ( ) ) <nl> Extended Formatting Example <nl> <nl> The following code is a scaled - down version of the formatting code <nl> used for ` ` Int ` ` . It represents an example of how a relatively <nl> - complicated ` ` format ( … ) ` ` might be written : : <nl> + complicated ` ` format ( . . . ) ` ` might be written : : <nl> <nl> protocol CustomStringConvertibleInteger <nl> : ExpressibleByIntegerLiteral , Comparable , SignedNumber , CustomStringConvertible { <nl> an underlying stream : : <nl> var base : UnderlyingStream <nl> } <nl> <nl> - However , upcasing is a trivial example : many such transformations — such <nl> - as ` ` trim ( ) ` ` or regex replacement — are stateful , which implies some <nl> + However , upcasing is a trivial example : many such transformations - - such <nl> + as ` ` trim ( ) ` ` or regex replacement - - are stateful , which implies some <nl> way of indicating " end of input " so that buffered state can be <nl> processed and written to the underlying stream : <nl> <nl> and , finally , we ' d be able to write : <nl> <nl> The complexity of this back - and - forth adapter dance is daunting , and <nl> might well be better handled in the language once we have some formal <nl> - model — such as coroutines — of inversion - of - control . We think it makes <nl> + model - - such as coroutines - - of inversion - of - control . We think it makes <nl> more sense to build the important transformations directly into <nl> ` ` format ( ) ` ` methods , allowing , e . g . : <nl> <nl> to tip the balance in favor of the current design . <nl> <nl> mmmmmm - - <nl> <nl> - . . [ # format ] Whether ` ` format ( … ) ` ` is to be a real protocol or merely <nl> + . . [ # format ] Whether ` ` format ( . . . ) ` ` is to be a real protocol or merely <nl> an ad - hoc convention is TBD . So far , there ' s no obvious use for a <nl> generic ` ` format ` ` with arguments that depend on the type being <nl> formatted , so an ad - hoc convention would be just fine . <nl> mmm a / docs / archive / Resilience . rst <nl> ppp b / docs / archive / Resilience . rst <nl> behavior of our implementations would work against these goals . <nl> Almost all languages provide some amount of abstraction of implementation . For <nl> example , functions are usually opaque data types which fully abstract away the <nl> exact sequence of operations performed . Similarly , adding a new field to a C <nl> - struct does not break programs which refer to a different field — those programs <nl> + struct does not break programs which refer to a different field - - those programs <nl> may need to be recompiled , but once recompiled , they should continue to <nl> work . ( This would not necessarily be true if , say , fields were accessed by index <nl> rather than by name . ) <nl> of this : [ born_unchanging ] for things that are universally non - resilient , <nl> <nl> Global functions always export a maximally - resilient entrypoint . If there exist <nl> any [ fragile ] arguments , and there do not exist any resilient arguments , they <nl> - also export a [ fragile ] copy . Callers do … something ? Have to know what they ' re <nl> + also export a [ fragile ] copy . Callers do . . . something ? Have to know what they ' re <nl> deploying against , I guess . <nl> <nl> Want some concrete representation for [ ref ] arguments . <nl> Break it down by types of declarations . <nl> <nl> * typealias has no resilience <nl> <nl> - * struct — the set / order of fields can change — means size / alignment , layout , <nl> + * struct - - the set / order of fields can change - - means size / alignment , layout , <nl> copy / destruction semantics , etc . can all change <nl> <nl> * fields - direct access vs . getter / setter <nl> Break it down by types of declarations . <nl> <nl> * types - as if top level <nl> <nl> - * class — same as a structs , plus <nl> + * class - - same as a structs , plus <nl> <nl> - * base classes — can ' t completely remove a base class ( breaks interface ) , but <nl> + * base classes - - can ' t completely remove a base class ( breaks interface ) , but <nl> can introduce a new intermediate base <nl> <nl> - * virtual dispatch — table vs . dictionary , devirtualization ( to which <nl> + * virtual dispatch - - table vs . dictionary , devirtualization ( to which <nl> decl ? ) . Some amount of table lookup can be done as static vs . dynamic offsets <nl> <nl> - * funcs — inlineability <nl> + * funcs - - inlineability <nl> <nl> - * vars — direct access vs . getter / setter . Direct accesses for types that aren ' t <nl> + * vars - - direct access vs . getter / setter . Direct accesses for types that aren ' t <nl> inherently fragile need to be indirected because they may need to be <nl> dynamically allocated . In general , might be actor - local , this is for when the <nl> model does say " global variable " . <nl> <nl> - * extensions of classes — like class . Fields are always side - allocated if we ' re <nl> + * extensions of classes - - like class . Fields are always side - allocated if we ' re <nl> extending a class not defined in this component ( w / i domain ? ) . Making a class <nl> fragile is also a promise not to add more fields in extensions in this <nl> component ; probably need a way to force a side - table . <nl> <nl> - * protocols — can ' t remove / change existing methods , but can add defaulted <nl> + * protocols - - can ' t remove / change existing methods , but can add defaulted <nl> methods . Doing this resiliently requires load - time checking . vtable for <nl> non - defaulted methods , ? for rest ? <nl> <nl> mmm a / docs / proposals / CPointerInteropLanguageModel . rst <nl> ppp b / docs / proposals / CPointerInteropLanguageModel . rst <nl> <nl> We have a pretty good user model for C pointer interop now , but the language <nl> model still needs improvement . Building the user model on top of implicit <nl> conversions has a number of undesirable side effects . We end up with a mess of <nl> - pointer types — the intended user - facing , one - word pointer types <nl> + pointer types - - the intended user - facing , one - word pointer types <nl> ` ` UnsafeMutablePointer ` ` and ` ` OpaquePointer ` ` , which expose a full pointer - ish API <nl> and are naturally ABI - compatible with C pointers ; and the bridging pointer <nl> types , ` ` ObjCMutablePointer ` ` , ` ` CMutablePointer ` ` , ` ` CConstPointer ` ` , <nl> mmm a / docs / proposals / InitializerInheritance . rst <nl> ppp b / docs / proposals / InitializerInheritance . rst <nl> class and its superclasses . <nl> There are three kinds of delegation : <nl> <nl> * * * super * * : runs an initializer belonging to a superclass ( in ObjC , <nl> - ` ` [ super init … ] ` ` ; in Swift , ` ` super . init ( . . . ) ` ` ) . <nl> + ` ` [ super init . . . ] ` ` ; in Swift , ` ` super . init ( . . . ) ` ` ) . <nl> <nl> * * * peer * * : runs an initializer belonging to the current class ( ObjC <nl> does not have syntax for this , although it is supported by the <nl> There are three kinds of delegation : <nl> <nl> * * * dispatched * * : given a signature , runs the initializer with that <nl> signature that is either defined or inherited by the most - derived <nl> - class ( in ObjC , ` ` [ self init … ] ` ` ; not currently supported by Swift ) <nl> + class ( in ObjC , ` ` [ self init . . . ] ` ` ; not currently supported by Swift ) <nl> <nl> We can also distinguish two ways to originally invoke an initializer : <nl> <nl> mmm a / docs / proposals / Inplace . rst <nl> ppp b / docs / proposals / Inplace . rst <nl> We propose to allow method pairs of the form : <nl> . . parsed - literal : : <nl> <nl> extension * * X * * { <nl> - func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * X * * <nl> + func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * X * * <nl> <nl> - func * * = * * \ * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * Void * * <nl> + func * * = * * \ * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * Void * * <nl> } <nl> <nl> The second ` ` = f ` ` method is known as an * * assignment method * * [ # getset ] _ . <nl> Given an ordinary method of a type ` ` X ` ` : <nl> . . parsed - literal : : <nl> <nl> extension * * X * * { <nl> - func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * X * * <nl> + func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * X * * <nl> } <nl> <nl> if there is no corresponding * assignment method * in ` ` X ` ` with the signature <nl> if there is no corresponding * assignment method * in ` ` X ` ` with the signature <nl> . . parsed - literal : : <nl> <nl> extension * * X * * { <nl> - func * = f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * Void * * <nl> + func * = f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * Void * * <nl> } <nl> <nl> we can compile the statement <nl> <nl> . . parsed - literal : : <nl> <nl> - x \ * * . = * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , … p \ * n * : a \ * n * ) <nl> + x \ * * . = * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , . . . p \ * n * : a \ * n * ) <nl> <nl> as though it were written : <nl> <nl> . . parsed - literal : : <nl> <nl> - x * * = x . * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , … p \ * n * : a \ * n * ) <nl> + x * * = x . * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , . . . p \ * n * : a \ * n * ) <nl> <nl> Generating the Non - Mutating Form <nl> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> Given an * assignment method * of a value type ` ` X ` ` : <nl> . . parsed - literal : : <nl> <nl> extension * * X * * { <nl> - func * = f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * Void * * <nl> + func * = f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * Void * * <nl> } <nl> <nl> if there is no method in ` ` X ` ` with the signature <nl> if there is no method in ` ` X ` ` with the signature <nl> . . parsed - literal : : <nl> <nl> extension * * X * * { <nl> - func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , … p \ * n * : T \ * n * ) - > * * X * * <nl> + func * f * \ ( p₀ : T₀ , p₁ : T₁ , p₂ : T₂ , . . . p \ * n * : T \ * n * ) - > * * X * * <nl> } <nl> <nl> we can compile the expression <nl> <nl> . . parsed - literal : : <nl> <nl> - * * x . * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , … p \ * n * : a \ * n * ) <nl> + * * x . * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , . . . p \ * n * : a \ * n * ) <nl> <nl> as though it were written : <nl> <nl> as though it were written : <nl> <nl> { <nl> ( var y : X ) - > X in <nl> - y \ * * . = * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , … p \ * n * : a \ * n * ) <nl> + y \ * * . = * * \ * f * \ ( a₀ , p₁ : a₁ , p₂ : a₂ , . . . p \ * n * : a \ * n * ) <nl> return y <nl> } ( x ) <nl> <nl> mmm a / docs / proposals / RemoteMirrors . rst <nl> ppp b / docs / proposals / RemoteMirrors . rst <nl> While this should have zero runtime overhead when not in use , it is OK if <nl> introspection requires some additional computation , especially if it can be <nl> front - loaded or memoized . <nl> <nl> - It is OK if in rare cases the metadata is not precise — for some allocations , <nl> + It is OK if in rare cases the metadata is not precise - - for some allocations , <nl> we might not be able to figure out the runtime type of the contained value . <nl> Also we will not attempt to verify the " roots " of the object graph by walking <nl> the stack for pointers . <nl> Opaque value buffers <nl> <nl> These come up when a value is too large to fit inside of an existential ' s <nl> inline storage , for example . They do not have a header , so we will not attempt <nl> - to introspect them at first — eventually , we could identify pointers to buffers <nl> + to introspect them at first - - eventually , we could identify pointers to buffers <nl> where the existential is itself inside of a heap - allocated object . <nl> <nl> Existing metadata <nl> several strategies depending on the type being referenced . For concrete <nl> non - generic types , a direct call to a lazy accessor can be generated . For bound <nl> generic types T < P1 , . . . , Pn > , we recursively emit metadata references for the <nl> generic parameters Pn , then call the getter for the bound type T . For <nl> - archetypes — that is , generic type parameters which are free variables in the <nl> - function body being compiled — the metadata is passed in as a value , so the <nl> + archetypes - - that is , generic type parameters which are free variables in the <nl> + function body being compiled - - the metadata is passed in as a value , so the <nl> compiler simply emits a copy of that . <nl> <nl> Generic type metadata tells us the size of each heap allocation , but does not <nl> Similarly , we can think of the field type access function as an operation F ( T , <nl> S ) which returns the types of the fields of T , with T again fixed at compile <nl> time . <nl> <nl> - What we really want here is to build an " interpreter " — or really , a parser for <nl> - a simple serialized graph — which understands how to parse uninstantiated <nl> + What we really want here is to build an " interpreter " - - or really , a parser for <nl> + a simple serialized graph - - which understands how to parse uninstantiated <nl> generic metadata , keep track of substitutions , and calculate field offsets , <nl> sizes , and locations of references . <nl> <nl> to identify heap references therein , and the full type for reflection . The <nl> former could be retained while the latter could be stripped out in certain <nl> builds . <nl> <nl> - We already have a very similar encoding — parameter type mangling in SIL . It <nl> + We already have a very similar encoding - - parameter type mangling in SIL . It <nl> would be good to re - use this encoding , but for completeness , the full format of <nl> a type reference is described below : <nl> <nl> a type reference is described below : <nl> # . * * A metatype . * * This consists of : <nl> <nl> - ( optional ) a type reference to the instance type <nl> - - there ' s no required information — a metatype is always a single pointer to <nl> + - there ' s no required information - - a metatype is always a single pointer to <nl> a heap object which itself does not reference any other heap objects . <nl> <nl> # . * * An existential metatype . * * This consists of : <nl> a type reference is described below : <nl> identifiable by an index here ( and once we add nested generic types , a depth ) . <nl> <nl> You can visualize type references as if they are written in an S - expression <nl> - format — but in reality , it would be serialized in a compact binary form : <nl> + format - - but in reality , it would be serialized in a compact binary form : <nl> <nl> : : <nl> <nl> tools . <nl> case Strong , Weak , Unowned <nl> / / the field is an opaque binary blob , contents unknown . <nl> case Opaque <nl> - / / the field is a value type — look inside recursively . <nl> + / / the field is a value type - - look inside recursively . <nl> case ValueType ( indirect field : FieldDescriptor ) <nl> } <nl> <nl> tools . <nl> <nl> func instantiateSymbolicType ( _ ref : SymbolicTypeReference ) - > [ FieldTypeDescriptor ] <nl> <nl> - Field type metadata can have circular references — for example , consider two <nl> + Field type metadata can have circular references - - for example , consider two <nl> classes which contain optionals of each other . In order to calculate field <nl> offsets correctly , we need to break cycles when we know something is a class <nl> type , and use a work - list algorithm instead of unbounded recursion to ensure <nl> mmm a / docs / proposals / ValueSemantics . rst <nl> ppp b / docs / proposals / ValueSemantics . rst <nl> The Role of Moves <nl> = = = = = = = = = = = = = = = = = <nl> <nl> Further complicating matters is the fact that the big three operations <nl> - can be — and often are — combined in ways that mask the value / reference <nl> + can be - - and often are - - combined in ways that mask the value / reference <nl> distinction . In fact both of the following must be present in order <nl> to observe a difference in behavior : <nl> <nl> mmm a / docs / proposals / archive / MemoryAndConcurrencyModel . rst <nl> ppp b / docs / proposals / archive / MemoryAndConcurrencyModel . rst <nl> With the basic approach above , you can only perform actions on actors that are <nl> built into the actor . For example , if you had an actor with two methods : : <nl> <nl> actor MyActor { <nl> - func foo ( ) { … } <nl> - func bar ( ) { … } <nl> - func getvalue ( ) - > double { … } <nl> + func foo ( ) { . . . } <nl> + func bar ( ) { . . . } <nl> + func getvalue ( ) - > double { . . . } <nl> } <nl> <nl> Then there is no way to perform a composite operation that needs to " atomically " <nl> perform foo ( ) and bar ( ) without any other operations getting in between . If you <nl> had code like this : : <nl> <nl> - var a : MyActor = … <nl> + var a : MyActor = . . . <nl> a . foo ( ) <nl> a . bar ( ) <nl> <nl> wouldn ' t be run in between them . To handle this , the async block structure can <nl> be used to submit a sequence of code that is atomically run in the actor ' s <nl> context , e . g . : : <nl> <nl> - var a : MyActor = … <nl> + var a : MyActor = . . . <nl> async a { <nl> a . foo ( ) <nl> a . bar ( ) <nl> This conceptually submits a closure to run in the context of the actor . If you <nl> look at it this way , an async message send is conceptually equivalent to an <nl> async block . As such , the original example was equivalent to : : <nl> <nl> - var a : MyActor = … <nl> + var a : MyActor = . . . <nl> async a { a . foo ( ) } <nl> async a { a . bar ( ) } <nl> <nl> mmm a / docs / proposals / archive / ProgramStructureAndCompilationModel . rst <nl> ppp b / docs / proposals / archive / ProgramStructureAndCompilationModel . rst <nl> Components are explicitly declared , and these declarations can include : <nl> " I depend on swift standard libs 1 . 4 or later " <nl> <nl> * a list of subcomponents that contribute to the component : " mac os consists of <nl> - appkit , coredata , … " <nl> + appkit , coredata , . . . " <nl> <nl> * a list of resource files and other stuff that makes up the framework <nl> <nl> mmm a / docs / proposals / rejected / ClassConstruction . rst <nl> ppp b / docs / proposals / rejected / ClassConstruction . rst <nl> Here are the proposed rules : <nl> default , part of the public interface of a subclass defined in <nl> Objective - C . <nl> <nl> - * ` ` self . init ( … ) ` ` calls in Swift never dispatch virtually . We have a <nl> + * ` ` self . init ( . . . ) ` ` calls in Swift never dispatch virtually . We have a <nl> safe model for " virtual initialization : " ` ` init ` ` methods can call <nl> overridable methods after all instance variables and superclasses <nl> are initialized . Allowing * virtual * constructor delegation would <nl> mmm a / docs / proposals / rejected / Clonable . rst <nl> ppp b / docs / proposals / rejected / Clonable . rst <nl> Generics <nl> There is actually a straightforward programming model for generics . <nl> If you want to design a generic component where a type parameter ` ` T ` ` <nl> binds to both ` ` class ` ` \ es and non - ` ` class ` ` types , you can view <nl> - ` ` T ` ` as a value type where — as with C pointers — the value is the <nl> + ` ` T ` ` as a value type where - - as with C pointers - - the value is the <nl> reference rather than the object being referred to . <nl> <nl> Of course , if ` ` T ` ` is only supposed to bind to ` ` class ` ` \ es , a <nl> mmm a / docs / proposals / valref . rst <nl> ppp b / docs / proposals / valref . rst <nl> <nl> : Date : 2013 - 03 - 15 <nl> <nl> * * Abstract : * * We propose a system that offers first - class support for <nl> - both value and reference semantics . By allowing — but not <nl> - requiring — ( instance ) variables , function parameters , and generic <nl> + both value and reference semantics . By allowing - - but not <nl> + requiring - - ( instance ) variables , function parameters , and generic <nl> constraints to be declared as ` ` val ` ` or ` ` ref ` ` , we offer users the <nl> ability to nail down semantics to the desired degree without <nl> compromising ease of use . <nl> and has value semantics : : <nl> case Cons ( car : T , cdr : List < T > ) <nl> } <nl> <nl> - / / A list node with reference semantics — copying the node creates a node <nl> + / / A list node with reference semantics - - copying the node creates a node <nl> / / that shares structure with the tail of the list <nl> union Node < T > { <nl> case Nil ( ) <nl> mmm a / lib / SILGen / SILGenConvert . cpp <nl> ppp b / lib / SILGen / SILGenConvert . cpp <nl> ManagedValue SILGenFunction : : emitUncheckedGetOptionalValueFrom ( SILLocation loc , <nl> ManagedValue payload ; <nl> <nl> / / Take the payload from the optional . Cheat a bit in the + 0 <nl> - / / case — UncheckedTakeEnumData will never actually invalidate an Optional enum <nl> + / / case - - UncheckedTakeEnumData will never actually invalidate an Optional enum <nl> / / value . <nl> SILValue payloadVal ; <nl> if ( ! addrOrValue . getType ( ) . isAddress ( ) ) { <nl> mmm a / stdlib / public / SDK / Foundation / NSDictionary . swift <nl> ppp b / stdlib / public / SDK / Foundation / NSDictionary . swift <nl> extension NSDictionary { <nl> / / / Initializes a newly allocated dictionary and adds to it objects from <nl> / / / another given dictionary . <nl> / / / <nl> - / / / - Returns : An initialized dictionary — which might be different <nl> - / / / than the original receiver — containing the keys and values <nl> + / / / - Returns : An initialized dictionary - - which might be different <nl> + / / / than the original receiver - - containing the keys and values <nl> / / / found in ` otherDictionary ` . <nl> @ objc ( _swiftInitWithDictionary_NSDictionary : ) <nl> public convenience init ( dictionary otherDictionary : NSDictionary ) { <nl> mmm a / stdlib / public / SDK / Foundation / TimeZone . swift <nl> ppp b / stdlib / public / SDK / Foundation / TimeZone . swift <nl> public struct TimeZone : Hashable , Equatable , ReferenceConvertible { <nl> <nl> / / / Returns a time zone identified by a given abbreviation . <nl> / / / <nl> - / / / In general , you are discouraged from using abbreviations except for unique instances such as " GMT " . Time Zone abbreviations are not standardized and so a given abbreviation may have multiple meanings — for example , " EST " refers to Eastern Time in both the United States and Australia <nl> + / / / In general , you are discouraged from using abbreviations except for unique instances such as " GMT " . Time Zone abbreviations are not standardized and so a given abbreviation may have multiple meanings - - for example , " EST " refers to Eastern Time in both the United States and Australia <nl> / / / <nl> / / / - parameter abbreviation : The abbreviation for the time zone . <nl> / / / - returns : A time zone identified by abbreviation determined by resolving the abbreviation to an identifier using the abbreviation dictionary and then returning the time zone for that identifier . Returns ` nil ` if there is no match for abbreviation . <nl> mmm a / stdlib / public / core / Integers . swift . gyb <nl> ppp b / stdlib / public / core / Integers . swift . gyb <nl> extension ExpressibleByIntegerLiteral <nl> / / = = = mmm Arithmetic mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> - / / / Declares methods backing binary arithmetic operators — such as ` + ` , ` - ` and <nl> - / / / ` * ` — and their mutating counterparts . <nl> + / / / Declares methods backing binary arithmetic operators - - such as ` + ` , ` - ` and <nl> + / / / ` * ` - - and their mutating counterparts . <nl> / / / <nl> / / / It provides a suitable basis for arithmetic on scalars such as integers and <nl> / / / floating point numbers . <nl> mmm a / stdlib / public / core / Unicode . swift <nl> ppp b / stdlib / public / core / Unicode . swift <nl> public struct UTF8 : UnicodeCodec { <nl> static func _decodeOne ( _ buffer : UInt32 ) - > ( result : UInt32 ? , length : UInt8 ) { <nl> / / Note the buffer is read least significant byte first : [ # 3 # 2 # 1 # 0 ] . <nl> <nl> - if buffer & 0x80 = = 0 { / / 1 - byte sequence ( ASCII ) , buffer : [ … … … CU0 ] . <nl> + if buffer & 0x80 = = 0 { / / 1 - byte sequence ( ASCII ) , buffer : [ . . . . . . . . . CU0 ] . <nl> let value = buffer & 0xff <nl> return ( value , 1 ) <nl> } <nl> public struct UTF8 : UnicodeCodec { <nl> let bit1 = ( lut1 > > index ) & 1 <nl> <nl> switch ( bit1 , bit0 ) { <nl> - case ( 0 , 0 ) : / / 2 - byte sequence , buffer : [ … … CU1 CU0 ] . <nl> + case ( 0 , 0 ) : / / 2 - byte sequence , buffer : [ . . . . . . CU1 CU0 ] . <nl> / / Require 10xx xxxx 110x xxxx . <nl> if _slowPath ( buffer & 0xc0e0 ! = 0x80c0 ) { return ( nil , 1 ) } <nl> / / Disallow xxxx xxxx xxx0 000x ( < = 7 bits case ) . <nl> public struct UTF8 : UnicodeCodec { <nl> | ( buffer & 0x001f ) < < 6 <nl> return ( value , 2 ) <nl> <nl> - case ( 0 , 1 ) : / / 3 - byte sequence , buffer : [ … CU2 CU1 CU0 ] . <nl> + case ( 0 , 1 ) : / / 3 - byte sequence , buffer : [ . . . CU2 CU1 CU0 ] . <nl> / / Disallow xxxx xxxx xx0x xxxx xxxx 0000 ( < = 11 bits case ) . <nl> if _slowPath ( buffer & 0x00200f = = 0x000000 ) { return ( nil , 1 ) } <nl> / / Disallow xxxx xxxx xx1x xxxx xxxx 1101 ( surrogate code points ) . <nl> mmm a / stdlib / public / core / UnsafeRawBufferPointer . swift . gyb <nl> ppp b / stdlib / public / core / UnsafeRawBufferPointer . swift . gyb <nl> public struct Unsafe $ { Mutable } RawBufferPointer <nl> to : base + count - elementStride + 1 , <nl> by : elementStride <nl> ) { <nl> - / / underflow is permitted – e . g . a sequence into <nl> + / / underflow is permitted - - e . g . a sequence into <nl> / / the spare capacity of an Array buffer <nl> guard let x = it . next ( ) else { break } <nl> p . initializeMemory ( as : S . Iterator . Element . self , to : x ) <nl>
[ gardening ] Replace likely word processor artefacts with ASCII equivalents ( — → - - , … → . . . )
apple/swift
3918d9d25115527af0d82de9e658c9f29bf9c5b1
2017-01-08T14:23:06Z
new file mode 100644 <nl> index 000000000000 . . 82c50b662c6d <nl> mmm / dev / null <nl> ppp b / include / swift / AST / Decl . h <nl> <nl> + / / = = = mmm Decl . h - Swift Language Declaration ASTs mmmmmmmmmmmmmmm * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2015 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This file defines the Decl class and subclasses . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_DECL_H <nl> + # define SWIFT_DECL_H <nl> + <nl> + # include " llvm / Support / SMLoc . h " <nl> + # include " llvm / ADT / StringRef . h " <nl> + <nl> + namespace llvm { <nl> + class StringRef ; <nl> + } <nl> + <nl> + namespace swift { <nl> + class ASTContext ; <nl> + class Type ; <nl> + class Expr ; <nl> + <nl> + enum DeclKind { <nl> + VarDeclKind <nl> + / / FuncDeclKind <nl> + } ; <nl> + <nl> + / / / Decl - Base class for all declarations in Swift . <nl> + class Decl { <nl> + Decl ( const Decl & ) ; / / DO NOT IMPLEMENT <nl> + void operator = ( const Decl & ) ; / / DO NOT IMPLEMENT <nl> + DeclKind Kind ; <nl> + protected : <nl> + Decl ( DeclKind kind ) : Kind ( kind ) { } <nl> + public : <nl> + DeclKind getKind ( ) const { return Kind ; } <nl> + <nl> + private : <nl> + / / Make placement new and vanilla new / delete illegal for Decls . <nl> + void * operator new ( size_t Bytes ) throw ( ) ; / / DO NOT IMPLEMENT . <nl> + void operator delete ( void * Data ) throw ( ) ; / / DO NOT IMPLEMENT . <nl> + void * operator new ( size_t Bytes , void * Mem ) throw ( ) ; / / DO NOT IMPLEMENT . <nl> + public : <nl> + / / Only allow allocation of Types using the allocator in ASTContext <nl> + / / or by doing a placement new . <nl> + void * operator new ( size_t Bytes , ASTContext & C , <nl> + unsigned Alignment = 8 ) throw ( ) ; <nl> + } ; <nl> + <nl> + / / / VarDecl - ' var ' declaration . <nl> + class VarDecl : public Decl { <nl> + friend class ASTContext ; <nl> + public : <nl> + llvm : : SMLoc VarLoc ; / / Location of the ' var ' token . <nl> + llvm : : StringRef Name ; <nl> + Type * Ty ; <nl> + Expr * Init ; <nl> + <nl> + VarDecl ( llvm : : SMLoc varloc , llvm : : StringRef name , Type * ty , Expr * init ) <nl> + : Decl ( VarDeclKind ) , VarLoc ( varloc ) , Name ( name ) , Ty ( ty ) , Init ( init ) { } <nl> + <nl> + } ; <nl> + <nl> + } / / end namespace swift <nl> + <nl> + # endif <nl> new file mode 100644 <nl> index 000000000000 . . cdaad9febd68 <nl> mmm / dev / null <nl> ppp b / lib / AST / Decl . cpp <nl> <nl> + / / = = = mmm Decl . cpp - Swift Language Decl ASTs mmmmmmmmmmmmmmmmmmmmmmmmmmmmmm = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2015 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This file implements the Decl class and subclasses . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / AST / Decl . h " <nl> + # include " swift / AST / ASTContext . h " <nl> + using namespace swift ; <nl> + <nl> + / / Only allow allocation of Decls using the allocator in ASTContext . <nl> + void * Decl : : operator new ( size_t Bytes , ASTContext & C , <nl> + unsigned Alignment ) throw ( ) { <nl> + return C . Allocate ( Bytes , Alignment ) ; <nl> + } <nl>
stub out Decl AST ' s .
apple/swift
340a7faa01c21adf25dc5b8113648bb5366c8c59
2010-07-19T04:59:13Z
mmm a / buildscripts / smoke . py <nl> ppp b / buildscripts / smoke . py <nl> def missing ( lst , src , dst ) : <nl> if " error - docs " in stats : <nl> print " Error getting docs to diff : " <nl> pprint . pprint ( stats [ " error - docs " ] ) <nl> - return False <nl> + return True <nl> <nl> if ( small_oplog or small_oplog_rs ) and not ( lost_in_master or lost_in_slave or screwy_in_slave ) : <nl> print " replication ok for % d collections " % ( len ( replicated_collections ) ) <nl> <nl> - return True <nl> + return False <nl> <nl> <nl> def report ( ) : <nl>
SERVER - 12804 : only ' report ' dbhash failure on failure
mongodb/mongo
9110ba43e61d8d579ee8eec1bbfc3d16d5ece86f
2014-02-23T23:36:34Z
mmm a / single_include / catch . hpp <nl> ppp b / single_include / catch . hpp <nl> namespace Catch <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> explicit Approx <nl> ( <nl> - double d <nl> + double value <nl> ) <nl> - : m_epsilon ( std : : numeric_limits < double > : : epsilon ( ) ) , <nl> + : m_epsilon ( std : : numeric_limits < float > : : epsilon ( ) * 100 ) , <nl> m_scale ( 1 . 0 ) , <nl> - m_d ( d ) <nl> + m_value ( value ) <nl> { <nl> } <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + Approx <nl> + ( <nl> + const Approx & other <nl> + ) <nl> + : m_epsilon ( other . m_epsilon ) , <nl> + m_scale ( other . m_scale ) , <nl> + m_value ( other . m_value ) <nl> + { <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + static Approx custom <nl> + ( ) <nl> + { <nl> + return Approx ( 0 ) ; <nl> + } <nl> + <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + Approx operator ( ) <nl> + ( <nl> + double value <nl> + ) <nl> + { <nl> + Approx approx ( value ) ; <nl> + approx . epsilon ( m_epsilon ) ; <nl> + approx . scale ( m_scale ) ; <nl> + return approx ; <nl> + } <nl> + <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> friend bool operator = = <nl> ( <nl> namespace Catch <nl> ) <nl> { <nl> / / Thanks to Richard Harris for his help refining this formula <nl> - return fabs ( lhs - rhs . m_d ) < rhs . m_epsilon * ( rhs . m_scale + ( std : : max ) ( fabs ( lhs ) , fabs ( rhs . m_d ) ) ) ; <nl> + return fabs ( lhs - rhs . m_value ) < rhs . m_epsilon * ( rhs . m_scale + ( std : : max ) ( fabs ( lhs ) , fabs ( rhs . m_value ) ) ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> namespace Catch <nl> std : : string toString ( ) const <nl> { <nl> std : : ostringstream oss ; <nl> - oss < < " Approx ( " < < m_d < < " ) " ; <nl> + oss < < " Approx ( " < < m_value < < " ) " ; <nl> return oss . str ( ) ; <nl> } <nl> <nl> private : <nl> double m_epsilon ; <nl> double m_scale ; <nl> - double m_d ; <nl> + double m_value ; <nl> } ; <nl> } <nl> <nl> namespace Catch <nl> * / <nl> # define TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED <nl> <nl> - / / # included from : internal / catch_reporter_registrars . hpp <nl> + / / # included from : . . / internal / catch_reporter_registrars . hpp <nl> <nl> / * <nl> * catch_reporter_registrars . hpp <nl> namespace Catch <nl> * / <nl> # define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED <nl> <nl> - / / # included from : internal / catch_xmlwriter . hpp <nl> + / / # included from : . . / internal / catch_xmlwriter . hpp <nl> <nl> / * <nl> * catch_xmlwriter . hpp <nl>
regenerated to include Approx changes
catchorg/Catch2
f721a96d245a255cde64cc70956cf2ca2831b757
2011-06-07T13:13:57Z
mmm a / tools / editor / io_plugins / editor_import_collada . cpp <nl> ppp b / tools / editor / io_plugins / editor_import_collada . cpp <nl> Node * EditorSceneImporterCollada : : import_scene ( const String & p_path , uint32_t p_ <nl> <nl> state . create_animations ( p_flags & IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS ) ; <nl> AnimationPlayer * ap = memnew ( AnimationPlayer ) ; <nl> - ap - > set_name ( " animations " ) ; <nl> for ( int i = 0 ; i < state . animations . size ( ) ; i + + ) { <nl> String name ; <nl> if ( state . animations [ i ] - > get_name ( ) = = " " ) <nl>
Merge pull request from SaracenOne / animation_import_fix
godotengine/godot
1403fa18a9cf1077d9b7ec974ee9f77249ae49b6
2016-07-13T15:49:09Z
new file mode 100644 <nl> index 000000000000 . . d6b8904b3aed <nl> mmm / dev / null <nl> ppp b / include / swift / AST / ASTMangler . h <nl> <nl> + / / = = = mmm ASTMangler . h - Swift AST symbol mangling mmmmmmmmmmmmmmm * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef __SWIFT_AST_ASTMANGLER_H__ <nl> + # define __SWIFT_AST_ASTMANGLER_H__ <nl> + <nl> + # include " swift / Basic / Mangler . h " <nl> + # include " swift / AST / Types . h " <nl> + # include " swift / AST / Decl . h " <nl> + # include " swift / AST / GenericSignature . h " <nl> + <nl> + namespace swift { <nl> + <nl> + class AbstractClosureExpr ; <nl> + <nl> + namespace NewMangling { <nl> + <nl> + / / / Utility function which selects either the old or new mangling for a type . <nl> + std : : string mangleTypeForDebugger ( Type Ty , const DeclContext * DC ) ; <nl> + <nl> + / / / Utility function which selects either the old or new mangling for a type and <nl> + / / / mangles the type as USR . <nl> + std : : string mangleTypeAsUSR ( Type Ty ) ; <nl> + <nl> + / / / The mangler for AST declarations . <nl> + class ASTMangler : public Mangler { <nl> + protected : <nl> + CanGenericSignature CurGenericSignature ; <nl> + ModuleDecl * Mod = nullptr ; <nl> + const DeclContext * DeclCtx = nullptr ; <nl> + <nl> + / / / Optimize out protocol names if a type only conforms to one protocol . <nl> + bool OptimizeProtocolNames ; <nl> + <nl> + / / / If enabled , Arche - and Alias types are mangled with context . <nl> + bool DWARFMangling ; <nl> + <nl> + public : <nl> + enum class SymbolKind { <nl> + Default , <nl> + VTableMethod , <nl> + DynamicThunk , <nl> + SwiftAsObjCThunk , <nl> + ObjCAsSwiftThunk , <nl> + DirectMethodReferenceThunk , <nl> + } ; <nl> + <nl> + ASTMangler ( bool DWARFMangling = false , <nl> + bool usePunycode = true , <nl> + bool OptimizeProtocolNames = true ) <nl> + : Mangler ( usePunycode ) , <nl> + OptimizeProtocolNames ( OptimizeProtocolNames ) , <nl> + DWARFMangling ( DWARFMangling ) { } <nl> + <nl> + std : : string mangleClosureEntity ( const AbstractClosureExpr * closure , <nl> + SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleEntity ( const ValueDecl * decl , bool isCurried , <nl> + SymbolKind SKind = SymbolKind : : Default ) ; <nl> + <nl> + std : : string mangleDestructorEntity ( const DestructorDecl * decl , <nl> + bool isDeallocating , SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleConstructorEntity ( const ConstructorDecl * ctor , <nl> + bool isAllocating , bool isCurried , <nl> + SymbolKind SKind = SymbolKind : : Default ) ; <nl> + <nl> + std : : string mangleIVarInitDestroyEntity ( const ClassDecl * decl , <nl> + bool isDestroyer , SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleAccessorEntity ( AccessorKind kind , <nl> + AddressorKind addressorKind , <nl> + const ValueDecl * decl , <nl> + bool isStatic , <nl> + SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleGlobalGetterEntity ( ValueDecl * decl , <nl> + SymbolKind SKind = SymbolKind : : Default ) ; <nl> + <nl> + std : : string mangleDefaultArgumentEntity ( const DeclContext * func , <nl> + unsigned index , <nl> + SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleInitializerEntity ( const VarDecl * var , SymbolKind SKind ) ; <nl> + <nl> + std : : string mangleNominalType ( const NominalTypeDecl * decl ) ; <nl> + <nl> + std : : string mangleWitnessTable ( NormalProtocolConformance * C ) ; <nl> + <nl> + std : : string mangleWitnessThunk ( ProtocolConformance * Conformance , <nl> + ValueDecl * Requirement ) ; <nl> + <nl> + std : : string mangleClosureWitnessThunk ( ProtocolConformance * Conformance , <nl> + AbstractClosureExpr * Closure ) ; <nl> + <nl> + std : : string mangleBehaviorInitThunk ( const VarDecl * decl ) ; <nl> + <nl> + std : : string mangleGlobalVariableFull ( const VarDecl * decl ) ; <nl> + <nl> + std : : string mangleGlobalInit ( const VarDecl * decl , int counter , <nl> + bool isInitFunc ) ; <nl> + <nl> + std : : string mangleReabstructionThunkHelper ( CanSILFunctionType ThunkType , <nl> + Type FromType , Type ToType , <nl> + ModuleDecl * Module ) ; <nl> + <nl> + std : : string mangleType ( Type decl , const DeclContext * DC ) ; <nl> + <nl> + std : : string mangleTypeAsUSR ( Type type ) ; <nl> + <nl> + std : : string mangleTypeAsContextUSR ( const NominalTypeDecl * type ) ; <nl> + <nl> + std : : string mangleDeclAsUSR ( ValueDecl * Decl , StringRef USRPrefix ) ; <nl> + <nl> + protected : <nl> + <nl> + void appendSymbolKind ( SymbolKind SKind ) ; <nl> + <nl> + void appendType ( Type type ) ; <nl> + <nl> + void appendDeclName ( const ValueDecl * decl ) ; <nl> + <nl> + void appendProtocolList ( ArrayRef < Type > Protocols , bool & First ) ; <nl> + <nl> + GenericTypeParamType * appendAssocType ( DependentMemberType * DepTy , <nl> + bool & isAssocTypeAtDepth ) ; <nl> + <nl> + void appendOpWithGenericParamIndex ( StringRef , <nl> + GenericTypeParamType * paramTy ) ; <nl> + <nl> + void bindGenericParameters ( const DeclContext * DC ) ; <nl> + <nl> + void bindGenericParameters ( CanGenericSignature sig ) ; <nl> + <nl> + / / / \ brief Mangles a sugared type iff we are mangling for the debugger . <nl> + template < class T > void appendSugaredType ( Type type ) { <nl> + assert ( DWARFMangling & & <nl> + " sugared types are only legal when mangling for the debugger " ) ; <nl> + auto * BlandTy = cast < T > ( type . getPointer ( ) ) - > getSinglyDesugaredType ( ) ; <nl> + appendType ( BlandTy ) ; <nl> + } <nl> + <nl> + void appendBoundGenericArgs ( Type type ) ; <nl> + <nl> + void appendImplFunctionType ( SILFunctionType * fn ) ; <nl> + <nl> + void appendContextOf ( const ValueDecl * decl ) ; <nl> + <nl> + void appendContext ( const DeclContext * ctx ) ; <nl> + <nl> + void appendModule ( const ModuleDecl * module ) ; <nl> + <nl> + void appendProtocolName ( const ProtocolDecl * protocol ) ; <nl> + <nl> + void appendNominalType ( const NominalTypeDecl * decl ) ; <nl> + <nl> + void appendFunctionType ( AnyFunctionType * fn ) ; <nl> + <nl> + void appendFunctionSignature ( AnyFunctionType * fn ) ; <nl> + <nl> + void appendParams ( Type ParamsTy ) ; <nl> + <nl> + void appendTypeList ( Type listTy ) ; <nl> + <nl> + void appendGenericSignature ( const GenericSignature * sig ) ; <nl> + <nl> + void appendRequirement ( const Requirement & reqt ) ; <nl> + <nl> + void appendGenericSignatureParts ( ArrayRef < GenericTypeParamType * > params , <nl> + unsigned initialParamDepth , <nl> + ArrayRef < Requirement > requirements ) ; <nl> + <nl> + void appendAssociatedTypeName ( DependentMemberType * dmt ) ; <nl> + <nl> + void appendClosureEntity ( const SerializedAbstractClosureExpr * closure ) ; <nl> + <nl> + void appendClosureEntity ( const AbstractClosureExpr * closure ) ; <nl> + <nl> + void appendClosureComponents ( Type Ty , unsigned discriminator , bool isImplicit , <nl> + const DeclContext * parentContext , <nl> + const DeclContext * localContext ) ; <nl> + <nl> + void appendDefaultArgumentEntity ( const DeclContext * ctx , unsigned index ) ; <nl> + <nl> + void appendInitializerEntity ( const VarDecl * var ) ; <nl> + <nl> + Type getDeclTypeForMangling ( const ValueDecl * decl , <nl> + ArrayRef < GenericTypeParamType * > & genericParams , <nl> + unsigned & initialParamIndex , <nl> + ArrayRef < Requirement > & requirements , <nl> + SmallVectorImpl < Requirement > & requirementsBuf ) ; <nl> + <nl> + void appendDeclType ( const ValueDecl * decl ) ; <nl> + <nl> + bool tryAppendStandardSubstitution ( const NominalTypeDecl * type ) ; <nl> + <nl> + void appendConstructorEntity ( const ConstructorDecl * ctor , bool isAllocating ) ; <nl> + <nl> + void appendDestructorEntity ( const DestructorDecl * decl , bool isDeallocating ) ; <nl> + <nl> + void appendAccessorEntity ( AccessorKind kind , <nl> + AddressorKind addressorKind , <nl> + const ValueDecl * decl , <nl> + bool isStatic ) ; <nl> + <nl> + void appendEntity ( const ValueDecl * decl , StringRef EntityOp , bool isStatic ) ; <nl> + <nl> + void appendEntity ( const ValueDecl * decl ) ; <nl> + <nl> + void appendProtocolConformance ( const ProtocolConformance * conformance ) ; <nl> + } ; <nl> + <nl> + } / / end namespace NewMangling <nl> + } / / end namespace swift <nl> + <nl> + # endif / / __SWIFT_AST_ASTMANGLER_H__ <nl> mmm a / include / swift / Basic / Demangle . h <nl> ppp b / include / swift / Basic / Demangle . h <nl> void mangleIdentifier ( const char * data , size_t length , <nl> / / / This should always round - trip perfectly with demangleSymbolAsNode . <nl> std : : string mangleNode ( const NodePointer & root ) ; <nl> <nl> + std : : string mangleNodeNew ( const NodePointer & root ) ; <nl> + <nl> / / / \ brief Transform the node structure to a string . <nl> / / / <nl> / / / Typical usage : <nl> class DemanglerPrinter { <nl> } <nl> <nl> std : : string & & str ( ) & & { return std : : move ( Stream ) ; } <nl> - <nl> + <nl> + llvm : : StringRef getStringRef ( ) const { return Stream ; } <nl> + <nl> + / / / Returns a mutable reference to the last character added to the printer . <nl> + char & lastChar ( ) { return Stream . back ( ) ; } <nl> + <nl> private : <nl> std : : string Stream ; <nl> } ; <nl> <nl> + bool mangleStandardSubstitution ( Node * node , DemanglerPrinter & Out ) ; <nl> + bool isSpecialized ( Node * node ) ; <nl> + NodePointer getUnspecialized ( Node * node ) ; <nl> + <nl> / / / Is a character considered a digit by the demangling grammar ? <nl> / / / <nl> / / / Yes , this is equivalent to the standard C isdigit ( 3 ) , but some platforms <nl> mmm a / include / swift / Basic / DemangleNodes . def <nl> ppp b / include / swift / Basic / DemangleNodes . def <nl> NODE ( VTableAttribute ) <nl> NODE ( Weak ) <nl> CONTEXT_NODE ( WillSet ) <nl> NODE ( WitnessTableOffset ) <nl> + NODE ( ReflectionMetadataBuiltinDescriptor ) <nl> + NODE ( ReflectionMetadataFieldDescriptor ) <nl> + NODE ( ReflectionMetadataAssocTypeDescriptor ) <nl> + NODE ( ReflectionMetadataSuperclassDescriptor ) <nl> + CONTEXT_NODE ( CurryThunk ) <nl> NODE ( ThrowsAnnotation ) <nl> - <nl> + NODE ( EmptyList ) <nl> + NODE ( FirstElementMarker ) <nl> + NODE ( VariadicMarker ) <nl> # undef CONTEXT_NODE <nl> # undef NODE <nl> new file mode 100644 <nl> index 000000000000 . . f2faaf58289f <nl> mmm / dev / null <nl> ppp b / include / swift / Basic / Demangler . h <nl> <nl> + / / = = = mmm Demangler . h - String to Node - Tree Demangling mmmmmmmmm - - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_BASIC_DEMANGLER_H <nl> + # define SWIFT_BASIC_DEMANGLER_H <nl> + <nl> + # include " swift / Basic / Demangle . h " <nl> + # include < vector > <nl> + <nl> + using namespace swift : : Demangle ; <nl> + using llvm : : StringRef ; <nl> + <nl> + namespace swift { <nl> + namespace NewMangling { <nl> + <nl> + class Demangler { <nl> + StringRef Text ; <nl> + size_t Pos ; <nl> + <nl> + struct NodeWithPos { <nl> + NodePointer Node ; <nl> + size_t Pos ; <nl> + } ; <nl> + <nl> + std : : vector < NodeWithPos > NodeStack ; <nl> + std : : vector < NodePointer > Substitutions ; <nl> + std : : vector < unsigned > PendingSubstitutions ; <nl> + std : : vector < StringRef > Words ; <nl> + <nl> + static NodePointer pop_back_val ( std : : vector < NodePointer > & NodeVector ) { <nl> + if ( NodeVector . empty ( ) ) <nl> + return nullptr ; <nl> + NodePointer Val = NodeVector . back ( ) ; <nl> + NodeVector . pop_back ( ) ; <nl> + return Val ; <nl> + } <nl> + <nl> + bool nextIf ( StringRef str ) { <nl> + if ( ! Text . substr ( Pos ) . startswith ( str ) ) return false ; <nl> + Pos + = str . size ( ) ; <nl> + return true ; <nl> + } <nl> + <nl> + char peekChar ( ) { <nl> + if ( Pos > = Text . size ( ) ) <nl> + return 0 ; <nl> + return Text [ Pos ] ; <nl> + } <nl> + <nl> + char nextChar ( ) { <nl> + if ( Pos > = Text . size ( ) ) <nl> + return 0 ; <nl> + return Text [ Pos + + ] ; <nl> + } <nl> + <nl> + bool nextIf ( char c ) { <nl> + if ( peekChar ( ) ! = c ) <nl> + return false ; <nl> + Pos + + ; <nl> + return true ; <nl> + } <nl> + <nl> + void pushBack ( ) { <nl> + assert ( Pos > 0 ) ; <nl> + Pos - - ; <nl> + } <nl> + <nl> + void pushNode ( NodePointer Nd ) { <nl> + NodeStack . push_back ( { Nd , Pos } ) ; <nl> + } <nl> + <nl> + NodePointer popNode ( ) { <nl> + if ( ! NodeStack . empty ( ) ) { <nl> + NodePointer Val = NodeStack . back ( ) . Node ; <nl> + NodeStack . pop_back ( ) ; <nl> + return Val ; <nl> + } <nl> + return nullptr ; <nl> + } <nl> + <nl> + NodePointer popNode ( Node : : Kind kind ) { <nl> + if ( NodeStack . empty ( ) ) <nl> + return nullptr ; <nl> + <nl> + Node : : Kind NdKind = NodeStack . back ( ) . Node - > getKind ( ) ; <nl> + if ( NdKind ! = kind ) <nl> + return nullptr ; <nl> + <nl> + return popNode ( ) ; <nl> + } <nl> + <nl> + template < typename Pred > NodePointer popNode ( Pred pred ) { <nl> + if ( NodeStack . empty ( ) ) <nl> + return nullptr ; <nl> + <nl> + Node : : Kind NdKind = NodeStack . back ( ) . Node - > getKind ( ) ; <nl> + if ( ! pred ( NdKind ) ) <nl> + return nullptr ; <nl> + <nl> + return popNode ( ) ; <nl> + } <nl> + <nl> + public : <nl> + Demangler ( llvm : : StringRef mangled ) : Text ( mangled ) , Pos ( 0 ) { } <nl> + <nl> + NodePointer demangleTopLevel ( ) ; <nl> + <nl> + private : <nl> + <nl> + void addSubstitution ( NodePointer Nd ) { <nl> + if ( Nd ) <nl> + Substitutions . push_back ( Nd ) ; <nl> + } <nl> + <nl> + static NodePointer addChild ( NodePointer Parent , NodePointer Child ) { <nl> + if ( ! Parent | | ! Child ) <nl> + return nullptr ; <nl> + Parent - > addChild ( Child ) ; <nl> + return Parent ; <nl> + } <nl> + <nl> + static NodePointer createWithChild ( Node : : Kind kind , NodePointer Child ) { <nl> + if ( ! Child ) <nl> + return nullptr ; <nl> + NodePointer Nd = NodeFactory : : create ( kind ) ; <nl> + Nd - > addChild ( Child ) ; <nl> + return Nd ; <nl> + } <nl> + <nl> + static NodePointer createType ( NodePointer Child ) { <nl> + return createWithChild ( Node : : Kind : : Type , Child ) ; <nl> + } <nl> + <nl> + static NodePointer createWithChildren ( Node : : Kind kind , NodePointer Child1 , <nl> + NodePointer Child2 ) { <nl> + if ( ! Child1 | | ! Child2 ) <nl> + return nullptr ; <nl> + NodePointer Nd = NodeFactory : : create ( kind ) ; <nl> + Nd - > addChild ( Child1 ) ; <nl> + Nd - > addChild ( Child2 ) ; <nl> + return Nd ; <nl> + } <nl> + <nl> + static NodePointer createWithChildren ( Node : : Kind kind , NodePointer Child1 , <nl> + NodePointer Child2 , <nl> + NodePointer Child3 ) { <nl> + if ( ! Child1 | | ! Child2 | | ! Child3 ) <nl> + return nullptr ; <nl> + NodePointer Nd = NodeFactory : : create ( kind ) ; <nl> + Nd - > addChild ( Child1 ) ; <nl> + Nd - > addChild ( Child2 ) ; <nl> + Nd - > addChild ( Child3 ) ; <nl> + return Nd ; <nl> + } <nl> + <nl> + NodePointer createWithPoppedType ( Node : : Kind kind ) { <nl> + return createWithChild ( kind , popNode ( Node : : Kind : : Type ) ) ; <nl> + } <nl> + <nl> + NodePointer swapWith ( Node : : Kind kind ) { <nl> + NodePointer Nd = popNode ( ) ; <nl> + pushNode ( NodeFactory : : create ( kind ) ) ; <nl> + return Nd ; <nl> + } <nl> + <nl> + NodePointer changeKind ( NodePointer Node , Node : : Kind NewKind ) ; <nl> + <nl> + NodePointer demangleOperator ( ) ; <nl> + <nl> + int demangleNatural ( ) ; <nl> + int demangleIndex ( ) ; <nl> + NodePointer demangleIndexAsNode ( ) ; <nl> + NodePointer demangleIdentifier ( ) ; <nl> + NodePointer demangleOperatorIdentifier ( ) ; <nl> + <nl> + NodePointer demangleMultiSubstitutions ( ) ; <nl> + static NodePointer createSwiftType ( Node : : Kind typeKind , StringRef name ) ; <nl> + NodePointer demangleKnownType ( ) ; <nl> + NodePointer demangleLocalIdentifier ( ) ; <nl> + <nl> + NodePointer popModule ( ) ; <nl> + NodePointer popContext ( ) ; <nl> + NodePointer popTypeAndGetChild ( ) ; <nl> + NodePointer popTypeAndGetNominal ( ) ; <nl> + NodePointer demangleBuiltinType ( ) ; <nl> + NodePointer demangleNominalType ( Node : : Kind kind ) ; <nl> + NodePointer demangleTypeAlias ( ) ; <nl> + NodePointer demangleExtensionContext ( ) ; <nl> + NodePointer demanglePlainFunction ( ) ; <nl> + NodePointer popFunctionType ( Node : : Kind kind ) ; <nl> + NodePointer popFunctionParams ( Node : : Kind kind ) ; <nl> + NodePointer popTuple ( ) ; <nl> + NodePointer popTypeList ( ) ; <nl> + NodePointer popProtocol ( ) ; <nl> + NodePointer demangleBoundGenericType ( ) ; <nl> + NodePointer demangleBoundGenericArgs ( NodePointer nominalType ) ; <nl> + NodePointer demangleInitializer ( ) ; <nl> + NodePointer demangleImplParamConvention ( ) ; <nl> + NodePointer demangleImplResultConvention ( Node : : Kind ConvKind ) ; <nl> + NodePointer demangleImplFunctionType ( ) ; <nl> + NodePointer demangleMetatype ( ) ; <nl> + static NodePointer createArchetypeRef ( int depth , int i ) ; <nl> + NodePointer demangleArchetype ( ) ; <nl> + NodePointer demangleAssociatedTypeSimple ( NodePointer GenericParamIdx ) ; <nl> + NodePointer demangleAssociatedTypeCompound ( NodePointer GenericParamIdx ) ; <nl> + <nl> + NodePointer popAssocTypeName ( ) ; <nl> + static NodePointer getDependentGenericParamType ( int depth , int index ) ; <nl> + NodePointer demangleGenericParamIndex ( ) ; <nl> + NodePointer popProtocolConformance ( ) ; <nl> + NodePointer demangleThunkOrSpecialization ( ) ; <nl> + NodePointer demangleGenericSpecialization ( Node : : Kind SpecKind ) ; <nl> + NodePointer demangleFunctionSpecialization ( ) ; <nl> + NodePointer demangleFuncSpecParam ( Node : : IndexType ParamIdx ) ; <nl> + NodePointer addFuncSpecParamIdentifier ( NodePointer Param , <nl> + FunctionSigSpecializationParamKind Kind , <nl> + StringRef FirstParam = StringRef ( ) ) ; <nl> + NodePointer addFuncSpecParamNumber ( NodePointer Param , <nl> + FunctionSigSpecializationParamKind Kind ) ; <nl> + <nl> + NodePointer demangleSpecAttributes ( Node : : Kind SpecKind ) ; <nl> + <nl> + NodePointer demangleWitness ( ) ; <nl> + NodePointer demangleSpecialType ( ) ; <nl> + NodePointer demangleMetatypeRepresentation ( ) ; <nl> + NodePointer demangleFunctionEntity ( ) ; <nl> + NodePointer demangleEntity ( Node : : Kind Kind ) ; <nl> + NodePointer demangleProtocolListType ( ) ; <nl> + NodePointer demangleGenericSignature ( bool hasParamCounts ) ; <nl> + NodePointer demangleGenericRequirement ( ) ; <nl> + NodePointer demangleGenericType ( ) ; <nl> + NodePointer demangleValueWitness ( ) ; <nl> + } ; <nl> + <nl> + } / / end namespace NewMangling <nl> + } / / end namespace swift <nl> + <nl> + # endif / / SWIFT_BASIC_DEMANGLER_H <nl> new file mode 100644 <nl> index 000000000000 . . f519978d16aa <nl> mmm / dev / null <nl> ppp b / include / swift / Basic / Mangler . h <nl> <nl> + / / = = = mmm Mangler . h - Base class for Swift name mangling mmmmmmmmm * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_BASIC_MANGLER_H <nl> + # define SWIFT_BASIC_MANGLER_H <nl> + <nl> + # include " swift / Basic / ManglingUtils . h " <nl> + # include " llvm / ADT / DenseMap . h " <nl> + # include " llvm / ADT / StringRef . h " <nl> + # include " llvm / ADT / StringMap . h " <nl> + # include " llvm / Support / raw_ostream . h " <nl> + <nl> + using llvm : : StringRef ; <nl> + using llvm : : ArrayRef ; <nl> + <nl> + namespace swift { <nl> + namespace NewMangling { <nl> + <nl> + / / / Returns true if the new mangling scheme should be used . <nl> + / / / <nl> + / / / TODO : remove this function when the old mangling is removed . <nl> + bool useNewMangling ( ) ; <nl> + <nl> + / / / Select an old or new mangled string , based on useNewMangling ( ) . <nl> + / / / <nl> + / / / Also performs test to check if the demangling of both string yield the same <nl> + / / / demangling tree . <nl> + / / / TODO : remove this function when the old mangling is removed . <nl> + std : : string selectMangling ( const std : : string & Old , const std : : string & New ) ; <nl> + <nl> + void printManglingStats ( ) ; <nl> + <nl> + / / / The basic Swift symbol mangler . <nl> + / / / <nl> + / / / This class serves as a abstract base class for specific manglers . It <nl> + / / / provides some basic utilities , like handling of substitutions , mangling of <nl> + / / / identifiers , etc . <nl> + class Mangler { <nl> + protected : <nl> + template < typename Mangler > <nl> + friend void mangleIdentifier ( Mangler & M , StringRef ident ) ; <nl> + <nl> + / / / The storage for the mangled symbol . <nl> + llvm : : SmallVector < char , 128 > Storage ; <nl> + <nl> + / / / The output stream for the mangled symbol . <nl> + llvm : : raw_svector_ostream Buffer ; <nl> + <nl> + / / / A temporary storage needed by the : : mangleIdentifier ( ) template function . <nl> + llvm : : SmallVector < WordReplacement , 8 > SubstWordsInIdent ; <nl> + <nl> + / / / Substitutions , except identifier substitutions . <nl> + llvm : : DenseMap < const void * , unsigned > Substitutions ; <nl> + <nl> + / / / Identifier substitutions . <nl> + llvm : : StringMap < unsigned > StringSubstitutions ; <nl> + <nl> + / / / The position in the Buffer where the last substitution was written . <nl> + int lastSubstIdx = - 2 ; <nl> + <nl> + / / / Word substitutions in mangled identifiers . <nl> + llvm : : SmallVector < SubstitutionWord , 26 > Words ; <nl> + <nl> + / / / If enabled , non - ASCII names are encoded in modified Punycode . <nl> + bool UsePunycode ; <nl> + <nl> + / / / A helpful little wrapper for an integer value that should be mangled <nl> + / / / in a particular , compressed value . <nl> + class Index { <nl> + unsigned N ; <nl> + public : <nl> + explicit Index ( unsigned n ) : N ( n ) { } <nl> + friend llvm : : raw_ostream & operator < < ( llvm : : raw_ostream & out , Index n ) { <nl> + if ( n . N ! = 0 ) out < < ( n . N - 1 ) ; <nl> + return ( out < < ' _ ' ) ; <nl> + } <nl> + } ; <nl> + <nl> + / / / Returns the buffer as a StringRef , needed by mangleIdentifier ( ) . <nl> + StringRef getBufferStr ( ) const { <nl> + return StringRef ( Storage . data ( ) , Storage . size ( ) ) ; <nl> + } <nl> + <nl> + protected : <nl> + <nl> + Mangler ( bool usePunycode ) : Buffer ( Storage ) , UsePunycode ( usePunycode ) { } <nl> + <nl> + / / / Adds the mangling prefix . <nl> + void beginMangling ( ) ; <nl> + <nl> + / / / Finish the mangling of the symbol and return the mangled name . <nl> + std : : string finalize ( ) ; <nl> + <nl> + / / / Finish the mangling of the symbol and write the mangled name into <nl> + / / / \ p stream . <nl> + void finalize ( llvm : : raw_ostream & stream ) ; <nl> + <nl> + / / / Appends a mangled identifier string . <nl> + void appendIdentifier ( StringRef ident ) ; <nl> + <nl> + void addSubstitution ( const void * ptr ) { <nl> + Substitutions [ ptr ] = Substitutions . size ( ) + StringSubstitutions . size ( ) ; <nl> + } <nl> + void addSubstitution ( StringRef Str ) { <nl> + StringSubstitutions [ Str ] = Substitutions . size ( ) + StringSubstitutions . size ( ) ; <nl> + } <nl> + <nl> + bool tryMangleSubstitution ( const void * ptr ) ; <nl> + <nl> + void mangleSubstitution ( unsigned Index ) ; <nl> + <nl> + # ifndef NDEBUG <nl> + void recordOpStatImpl ( StringRef op , size_t OldPos ) ; <nl> + # endif <nl> + <nl> + void recordOpStat ( StringRef op , size_t OldPos ) { <nl> + # ifndef NDEBUG <nl> + recordOpStatImpl ( op , OldPos ) ; <nl> + # endif <nl> + } <nl> + <nl> + void appendOperator ( StringRef op ) { <nl> + size_t OldPos = Storage . size ( ) ; <nl> + Buffer < < op ; <nl> + recordOpStat ( op , OldPos ) ; <nl> + } <nl> + void appendOperator ( StringRef op , int natural ) { <nl> + size_t OldPos = Storage . size ( ) ; <nl> + Buffer < < op < < natural < < ' _ ' ; <nl> + recordOpStat ( op , OldPos ) ; <nl> + } <nl> + void appendOperator ( StringRef op , Index index ) { <nl> + size_t OldPos = Storage . size ( ) ; <nl> + Buffer < < op < < index ; <nl> + recordOpStat ( op , OldPos ) ; <nl> + } <nl> + void appendOperator ( StringRef op , Index index1 , Index index2 ) { <nl> + size_t OldPos = Storage . size ( ) ; <nl> + Buffer < < op < < index1 < < index2 ; <nl> + recordOpStat ( op , OldPos ) ; <nl> + } <nl> + void appendOperator ( StringRef op , StringRef arg ) { <nl> + size_t OldPos = Storage . size ( ) ; <nl> + Buffer < < op < < arg ; <nl> + recordOpStat ( op , OldPos ) ; <nl> + } <nl> + void appendListSeparator ( ) { <nl> + appendOperator ( " _ " ) ; <nl> + } <nl> + void appendListSeparator ( bool & isFirstListItem ) { <nl> + if ( isFirstListItem ) { <nl> + appendListSeparator ( ) ; <nl> + isFirstListItem = false ; <nl> + } <nl> + } <nl> + } ; <nl> + <nl> + } / / end namespace Mangle <nl> + } / / end namespace swift <nl> + <nl> + # endif / / SWIFT_BASIC_MANGLER_H <nl> new file mode 100644 <nl> index 000000000000 . . 7bab46fb6610 <nl> mmm / dev / null <nl> ppp b / include / swift / Basic / ManglingMacros . h <nl> <nl> + / / = = = mmm ManglingMacros . h - Macros for Swift symbol mangling mmm - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_BASIC_MANGLING_MACROS_H <nl> + # define SWIFT_BASIC_MANGLING_MACROS_H <nl> + <nl> + / / The following macro enables the " new " mangling , which has an _S prefix rather <nl> + / / then the original _T prefix . <nl> + / / TODO : When we get rid of the old mangling , the term " new mangling " should <nl> + / / just be renamed to " mangling " . <nl> + <nl> + / / # define USE_NEW_MANGLING <nl> + <nl> + # define STRINGIFY_MANGLING ( M ) # M <nl> + # define MANGLE_AS_STRING ( M ) STRINGIFY_MANGLING ( M ) <nl> + <nl> + / / / The mangling prefix for the new mangling . <nl> + # define MANGLING_PREFIX _S <nl> + <nl> + # define MANGLING_PREFIX_STR MANGLE_AS_STRING ( MANGLING_PREFIX ) <nl> + <nl> + / / The following macros help to create symbol manglings . They can be used <nl> + / / if a mangled name is needed at compile - time , e . g . for variable names in the <nl> + / / swift runtime libraries . <nl> + <nl> + # define MANGLING_CONCAT2_IMPL ( a , b ) a # # b <nl> + # define MANGLING_CONCAT3_IMPL ( a , b , c ) a # # b # # c <nl> + <nl> + # ifdef USE_NEW_MANGLING <nl> + <nl> + # define MANGLE_SYM ( Ops ) MANGLING_CONCAT2_IMPL ( MANGLING_PREFIX , Ops ) <nl> + # define MANGLING_CONCAT2 ( a , b ) MANGLING_CONCAT2_IMPL ( a , b ) <nl> + # define MANGLING_CONCAT3 ( a , b , c ) MANGLING_CONCAT3_IMPL ( a , b , c ) <nl> + # define SELECT_MANGLING ( Old , New ) New <nl> + # define METADATA_MANGLING N <nl> + # define METATYPE_MANGLING m <nl> + # define EMPTY_TUPLE_MANGLING yt <nl> + # define NO_ARGS_MANGLING yy <nl> + # define FUNC_TYPE_MANGLING c <nl> + <nl> + # else <nl> + <nl> + # define MANGLE_SYM ( Ops ) MANGLING_CONCAT2_IMPL ( _T , Ops ) <nl> + # define MANGLING_CONCAT2 ( a , b ) MANGLING_CONCAT2_IMPL ( b , a ) <nl> + # define MANGLING_CONCAT3 ( a , b , c ) MANGLING_CONCAT3_IMPL ( c , b , a ) <nl> + # define SELECT_MANGLING ( Old , New ) Old <nl> + # define METADATA_MANGLING M <nl> + # define METATYPE_MANGLING M <nl> + # define EMPTY_TUPLE_MANGLING T_ <nl> + # define NO_ARGS_MANGLING T_T_ <nl> + # define FUNC_TYPE_MANGLING F <nl> + <nl> + # endif <nl> + <nl> + # define FUNCTION_MANGLING \ <nl> + MANGLING_CONCAT2 ( NO_ARGS_MANGLING , FUNC_TYPE_MANGLING ) <nl> + <nl> + # define THIN_FUNCTION_MANGLING \ <nl> + MANGLING_CONCAT2 ( NO_ARGS_MANGLING , Xf ) <nl> + <nl> + # define OPTIONAL_MANGLING ( Ty ) \ <nl> + MANGLING_CONCAT3 ( MANGLING_CONCAT2_IMPL ( Ty , _ ) , Sq , G ) <nl> + <nl> + # define METADATA_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT2 ( Ty , METADATA_MANGLING ) ) <nl> + <nl> + # define STRUCT_METADATA_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , V , METADATA_MANGLING ) ) <nl> + <nl> + # define CLASS_METADATA_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , C , METADATA_MANGLING ) ) <nl> + <nl> + # define STRUCT_MD_ACCESSOR_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , V , Ma ) ) <nl> + <nl> + # define VALUE_WITNESS_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT2 ( Ty , WV ) ) <nl> + <nl> + # define UNOWNED_VALUE_WITNESS_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , Xo , WV ) ) <nl> + <nl> + # define WEAK_VALUE_WITNESS_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( OPTIONAL_MANGLING ( Ty ) , Xw , WV ) ) <nl> + <nl> + # define METATYPE_VALUE_WITNESS_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , METATYPE_MANGLING , WV ) ) <nl> + <nl> + # define NOMINAL_TYPE_DESCR_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT2 ( Ty , Mn ) ) <nl> + <nl> + # define STRUCT_TYPE_DESCR_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT3 ( Ty , V , Mn ) ) <nl> + <nl> + # define PROTOCOL_DESCR_SYM ( Ty ) \ <nl> + MANGLE_SYM ( MANGLING_CONCAT2 ( Ty , Mp ) ) <nl> + <nl> + # endif / / SWIFT_BASIC_MANGLING_MACROS_H <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . 71bf0a61b6fb <nl> mmm / dev / null <nl> ppp b / include / swift / Basic / ManglingUtils . h <nl> <nl> + / / = = = mmm ManglingUtils . h - Utilities for Swift name mangling mmm - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_BASIC_MANGLINGUTILS_H <nl> + # define SWIFT_BASIC_MANGLINGUTILS_H <nl> + <nl> + # include " llvm / ADT / StringRef . h " <nl> + # include " llvm / ADT / ArrayRef . h " <nl> + # include " swift / Basic / Punycode . h " <nl> + <nl> + namespace swift { <nl> + namespace NewMangling { <nl> + <nl> + inline bool isLowerLetter ( char ch ) { <nl> + return ch > = ' a ' & & ch < = ' z ' ; <nl> + } <nl> + <nl> + inline bool isUpperLetter ( char ch ) { <nl> + return ch > = ' A ' & & ch < = ' Z ' ; <nl> + } <nl> + <nl> + inline bool isDigit ( char ch ) { <nl> + return ch > = ' 0 ' & & ch < = ' 9 ' ; <nl> + } <nl> + <nl> + inline bool isLetter ( char ch ) { <nl> + return isLowerLetter ( ch ) | | isUpperLetter ( ch ) ; <nl> + } <nl> + <nl> + / / / Returns true if \ p ch is a character which defines the begin of a <nl> + / / / substitution word . <nl> + inline bool isWordStart ( char ch ) { <nl> + return ! isDigit ( ch ) & & ch ! = ' _ ' & & ch ! = 0 ; <nl> + } <nl> + <nl> + / / / Returns true if \ p ch is a character ( following \ p prevCh ) which defines <nl> + / / / the end of a substitution word . <nl> + inline bool isWordEnd ( char ch , char prevCh ) { <nl> + if ( ch = = ' _ ' | | ch = = 0 ) <nl> + return true ; <nl> + <nl> + if ( ! isUpperLetter ( prevCh ) & & isUpperLetter ( ch ) ) <nl> + return true ; <nl> + <nl> + return false ; <nl> + } <nl> + <nl> + / / / Returns true if \ p ch is a valid character which may appear in a symbol <nl> + / / / mangling . <nl> + inline bool isValidSymbolChar ( char ch ) { <nl> + return isLetter ( ch ) | | isDigit ( ch ) | | ch = = ' _ ' | | ch = = ' $ ' ; <nl> + } <nl> + <nl> + / / / Returns true if \ p str contains any character which may not appear in a <nl> + / / / mangled symbol string and therefore must be punycode encoded . <nl> + bool needsPunycodeEncoding ( StringRef str ) ; <nl> + <nl> + / / / Returns true if \ p str contains any non - ASCII character . <nl> + bool isNonAscii ( StringRef str ) ; <nl> + <nl> + / / / Describes a Word in a mangled identifier . <nl> + struct SubstitutionWord { <nl> + <nl> + / / / The position of the first word character in the mangled string . <nl> + size_t start ; <nl> + <nl> + / / / The length of the word . <nl> + size_t length ; <nl> + } ; <nl> + <nl> + / / / Helper struct which represents a word substitution . <nl> + struct WordReplacement { <nl> + / / / The position in the identifier where the word is substituted . <nl> + size_t StringPos ; <nl> + <nl> + / / / The index into the mangler ' s Words array ( - 1 if invalid ) . <nl> + int WordIdx ; <nl> + } ; <nl> + <nl> + / / / Translate the given operator character into its mangled form . <nl> + / / / <nl> + / / / Current operator characters : @ / = - + * % < > ! & | ^ ~ and the special operator ' . . ' <nl> + char translateOperatorChar ( char op ) ; <nl> + <nl> + / / / Returns a string where all characters of the operator \ Op are translated to <nl> + / / / their mangled form . <nl> + std : : string translateOperator ( StringRef Op ) ; <nl> + <nl> + / / / Mangles an identifier using a generic Mangler class . <nl> + / / / <nl> + / / / The Mangler class must provide the following : <nl> + / / / * ) Words : An array of SubstitutionWord which holds the current list of <nl> + / / / found words which can be used for substitutions . <nl> + / / / * ) SubstWordsInIdent : An array of WordReplacement , which is just used <nl> + / / / as a temporary storage during mangling . Must be empty . <nl> + / / / * ) Buffer : A stream where the mangled identifier is written to . <nl> + / / / * ) getBufferStr ( ) : Returns a StringRef of the current content of Buffer . <nl> + / / / * ) UsePunycode : A flag indicating if punycode encoding should be done . <nl> + template < typename Mangler > <nl> + void mangleIdentifier ( Mangler & M , StringRef ident ) { <nl> + <nl> + size_t WordsInBuffer = M . Words . size ( ) ; <nl> + assert ( M . SubstWordsInIdent . empty ( ) ) ; <nl> + std : : string punycodeBuf ; <nl> + if ( M . UsePunycode & & needsPunycodeEncoding ( ident ) ) { <nl> + / / If the identifier contains non - ASCII character , we mangle <nl> + / / with an initial ' 00 ' and Punycode the identifier string . <nl> + Punycode : : encodePunycodeUTF8 ( ident , punycodeBuf , <nl> + / * mapNonSymbolChars * / true ) ; <nl> + ident = punycodeBuf ; <nl> + M . Buffer < < " 00 " ; <nl> + } else { <nl> + / / Search for word substitutions and for new words . <nl> + const size_t NotInsideWord = ~ 0 ; <nl> + size_t wordStartPos = NotInsideWord ; <nl> + for ( size_t Pos = 0 , Len = ident . size ( ) ; Pos < = Len ; + + Pos ) { <nl> + char ch = ( Pos < Len ? ident [ Pos ] : 0 ) ; <nl> + if ( wordStartPos ! = NotInsideWord & & isWordEnd ( ch , ident [ Pos - 1 ] ) ) { <nl> + / / This position is the end of a word , i . e . the next character after a <nl> + / / word . <nl> + assert ( Pos > wordStartPos ) ; <nl> + size_t wordLen = Pos - wordStartPos ; <nl> + StringRef Word = ident . substr ( wordStartPos , wordLen ) ; <nl> + <nl> + / / Helper function to lookup the Word in a string . <nl> + auto lookupWord = [ & ] ( StringRef Str , <nl> + size_t FromWordIdx , size_t ToWordIdx ) - > int { <nl> + for ( size_t Idx = FromWordIdx ; Idx < ToWordIdx ; + + Idx ) { <nl> + const SubstitutionWord & w = M . Words [ Idx ] ; <nl> + StringRef existingWord = Str . substr ( w . start , w . length ) ; <nl> + if ( Word = = existingWord ) <nl> + return ( int ) Idx ; <nl> + } <nl> + return - 1 ; <nl> + } ; <nl> + <nl> + / / Is the word already present in the so far mangled string ? <nl> + int WordIdx = lookupWord ( M . getBufferStr ( ) , 0 , WordsInBuffer ) ; <nl> + / / Otherwise , is the word already present in this identifier ? <nl> + if ( WordIdx < 0 ) <nl> + WordIdx = lookupWord ( ident , WordsInBuffer , M . Words . size ( ) ) ; <nl> + <nl> + if ( WordIdx > = 0 ) { <nl> + / / We found a word substitution ! <nl> + assert ( WordIdx < 26 ) ; <nl> + M . SubstWordsInIdent . push_back ( { wordStartPos , WordIdx } ) ; <nl> + } else if ( wordLen > = 2 & & M . Words . size ( ) < 26 ) { <nl> + / / It ' s a new word : remember it . <nl> + / / Note : at this time the word ' s start position is relative to the <nl> + / / begin of the identifier . We must update it afterwards so that it is <nl> + / / relative to the begin of the whole mangled Buffer . <nl> + M . Words . push_back ( { wordStartPos , wordLen } ) ; <nl> + } <nl> + wordStartPos = NotInsideWord ; <nl> + } <nl> + if ( wordStartPos = = NotInsideWord & & isWordStart ( ch ) ) { <nl> + / / This position is the begin of a word . <nl> + wordStartPos = Pos ; <nl> + } <nl> + } <nl> + / / If we have word substitutions mangle an initial ' 0 ' . <nl> + if ( ! M . SubstWordsInIdent . empty ( ) ) <nl> + M . Buffer < < ' 0 ' ; <nl> + } <nl> + size_t Pos = 0 ; <nl> + / / Add a dummy - word at the end of the list . <nl> + M . SubstWordsInIdent . push_back ( { ident . size ( ) , - 1 } ) ; <nl> + <nl> + / / Mangle a sequence of word substitutions and sub - strings . <nl> + for ( size_t Idx = 0 , End = M . SubstWordsInIdent . size ( ) ; Idx < End ; + + Idx ) { <nl> + const WordReplacement & Repl = M . SubstWordsInIdent [ Idx ] ; <nl> + if ( Pos < Repl . StringPos ) { <nl> + / / Mangle the sub - string up to the next word substitution ( or to the end <nl> + / / of the identifier - that ' s why we added the dummy - word ) . <nl> + / / The first thing : we add the encoded sub - string length . <nl> + M . Buffer < < ( Repl . StringPos - Pos ) ; <nl> + assert ( ! isDigit ( ident [ Pos ] ) & & <nl> + " first char of sub - string may not be a digit " ) ; <nl> + do { <nl> + / / Update the start position of new added words , so that they refer to <nl> + / / the begin of the whole mangled Buffer . <nl> + if ( WordsInBuffer < M . Words . size ( ) & & <nl> + M . Words [ WordsInBuffer ] . start = = Pos ) { <nl> + M . Words [ WordsInBuffer ] . start = M . getBufferStr ( ) . size ( ) ; <nl> + WordsInBuffer + + ; <nl> + } <nl> + / / Add a literal character of the sub - string . <nl> + M . Buffer < < ident [ Pos ] ; <nl> + Pos + + ; <nl> + } while ( Pos < Repl . StringPos ) ; <nl> + } <nl> + / / Is it a " real " word substitution ( and not the dummy - word ) ? <nl> + if ( Repl . WordIdx > = 0 ) { <nl> + assert ( Repl . WordIdx < = ( int ) WordsInBuffer ) ; <nl> + Pos + = M . Words [ Repl . WordIdx ] . length ; <nl> + if ( Idx < End - 2 ) { <nl> + M . Buffer < < ( char ) ( Repl . WordIdx + ' a ' ) ; <nl> + } else { <nl> + / / The last word substitution is a captial letter . <nl> + M . Buffer < < ( char ) ( Repl . WordIdx + ' A ' ) ; <nl> + if ( Pos = = ident . size ( ) ) <nl> + M . Buffer < < ' 0 ' ; <nl> + } <nl> + } <nl> + } <nl> + M . SubstWordsInIdent . clear ( ) ; <nl> + } <nl> + <nl> + } / / end namespace Mangle <nl> + } / / end namespace swift <nl> + <nl> + # endif / / SWIFT_BASIC_MANGLINGUTILS_H <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . 6e3a27e0fba3 <nl> mmm / dev / null <nl> ppp b / include / swift / SILOptimizer / Utils / SpecializationMangler . h <nl> <nl> + / / = = = mmm SpecializationMangler . h - mangling of specializations - - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_SILOPTIMIZER_UTILS_SPECIALIZATIONMANGLER_H <nl> + # define SWIFT_SILOPTIMIZER_UTILS_SPECIALIZATIONMANGLER_H <nl> + <nl> + # include " swift / Basic / Demangler . h " <nl> + # include " swift / Basic / NullablePtr . h " <nl> + # include " swift / AST / ASTMangler . h " <nl> + # include " swift / SIL / SILLinkage . h " <nl> + # include " swift / SIL / SILFunction . h " <nl> + <nl> + namespace swift { <nl> + namespace NewMangling { <nl> + <nl> + enum class SpecializationKind : uint8_t { <nl> + Generic , <nl> + NotReAbstractedGeneric , <nl> + FunctionSignature , <nl> + } ; <nl> + <nl> + / / / Inject SpecializationPass into the Mangle namespace . <nl> + using SpecializationPass = Demangle : : SpecializationPass ; <nl> + <nl> + / / / The base class for specialization mangles . <nl> + class SpecializationMangler : public NewMangling : : ASTMangler { <nl> + protected : <nl> + / / / The specialization pass . <nl> + SpecializationPass Pass ; <nl> + <nl> + IsFragile_t Fragile ; <nl> + <nl> + / / / The original function which is specialized . <nl> + SILFunction * Function ; <nl> + <nl> + llvm : : SmallVector < char , 32 > ArgOpStorage ; <nl> + llvm : : raw_svector_ostream ArgOpBuffer ; <nl> + <nl> + protected : <nl> + SpecializationMangler ( SpecializationPass P , IsFragile_t Fragile , <nl> + SILFunction * F ) <nl> + : Pass ( P ) , Fragile ( Fragile ) , Function ( F ) , ArgOpBuffer ( ArgOpStorage ) { } <nl> + <nl> + SILFunction * getFunction ( ) const { return Function ; } <nl> + <nl> + void beginMangling ( ) ; <nl> + <nl> + / / / Finish the mangling of the symbol and return the mangled name . <nl> + std : : string finalize ( ) ; <nl> + <nl> + void appendSpecializationOperator ( StringRef Op ) { <nl> + appendOperator ( Op , StringRef ( ArgOpStorage . data ( ) , ArgOpStorage . size ( ) ) ) ; <nl> + } <nl> + } ; <nl> + <nl> + / / The mangler for specialized generic functions . <nl> + class GenericSpecializationMangler : public SpecializationMangler { <nl> + <nl> + ArrayRef < Substitution > Subs ; <nl> + <nl> + public : <nl> + <nl> + bool isReAbstracted ; <nl> + <nl> + GenericSpecializationMangler ( SILFunction * F , <nl> + ArrayRef < Substitution > Subs , <nl> + IsFragile_t Fragile , <nl> + bool isReAbstracted ) <nl> + : SpecializationMangler ( SpecializationPass : : GenericSpecializer , Fragile , F ) , <nl> + Subs ( Subs ) , isReAbstracted ( isReAbstracted ) { } <nl> + <nl> + std : : string mangle ( ) ; <nl> + } ; <nl> + <nl> + / / The mangler for functions where arguments are specialized . <nl> + class FunctionSignatureSpecializationMangler : public SpecializationMangler { <nl> + <nl> + using ReturnValueModifierIntBase = uint16_t ; <nl> + enum class ReturnValueModifier : ReturnValueModifierIntBase { <nl> + / / Option Space 4 bits ( i . e . 16 options ) . <nl> + Unmodified = 0 , <nl> + First_Option = 0 , Last_Option = 31 , <nl> + <nl> + / / Option Set Space . 12 bits ( i . e . 12 option ) . <nl> + Dead = 32 , <nl> + OwnedToUnowned = 64 , <nl> + First_OptionSetEntry = 32 , LastOptionSetEntry = 32768 , <nl> + } ; <nl> + <nl> + / / We use this private typealias to make it easy to expand ArgumentModifier ' s <nl> + / / size if we need to . <nl> + using ArgumentModifierIntBase = uint16_t ; <nl> + enum class ArgumentModifier : ArgumentModifierIntBase { <nl> + / / Option Space 4 bits ( i . e . 16 options ) . <nl> + Unmodified = 0 , <nl> + ConstantProp = 1 , <nl> + ClosureProp = 2 , <nl> + BoxToValue = 3 , <nl> + BoxToStack = 4 , <nl> + First_Option = 0 , Last_Option = 31 , <nl> + <nl> + / / Option Set Space . 12 bits ( i . e . 12 option ) . <nl> + Dead = 32 , <nl> + OwnedToGuaranteed = 64 , <nl> + SROA = 128 , <nl> + First_OptionSetEntry = 32 , LastOptionSetEntry = 32768 , <nl> + } ; <nl> + <nl> + using ArgInfo = std : : pair < ArgumentModifierIntBase , <nl> + NullablePtr < SILInstruction > > ; <nl> + llvm : : SmallVector < ArgInfo , 8 > Args ; <nl> + <nl> + ReturnValueModifierIntBase ReturnValue ; <nl> + <nl> + public : <nl> + FunctionSignatureSpecializationMangler ( SpecializationPass Pass , <nl> + IsFragile_t Fragile , <nl> + SILFunction * F ) ; <nl> + void setArgumentConstantProp ( unsigned ArgNo , LiteralInst * LI ) ; <nl> + void setArgumentClosureProp ( unsigned ArgNo , PartialApplyInst * PAI ) ; <nl> + void setArgumentClosureProp ( unsigned ArgNo , ThinToThickFunctionInst * TTTFI ) ; <nl> + void setArgumentDead ( unsigned ArgNo ) ; <nl> + void setArgumentOwnedToGuaranteed ( unsigned ArgNo ) ; <nl> + void setArgumentSROA ( unsigned ArgNo ) ; <nl> + void setArgumentBoxToValue ( unsigned ArgNo ) ; <nl> + void setArgumentBoxToStack ( unsigned ArgNo ) ; <nl> + void setReturnValueOwnedToUnowned ( ) ; <nl> + <nl> + std : : string mangle ( ) ; <nl> + <nl> + private : <nl> + void mangleConstantProp ( LiteralInst * LI ) ; <nl> + void mangleClosureProp ( SILInstruction * Inst ) ; <nl> + void mangleArgument ( ArgumentModifierIntBase ArgMod , <nl> + NullablePtr < SILInstruction > Inst ) ; <nl> + void mangleReturnValue ( ReturnValueModifierIntBase RetMod ) ; <nl> + } ; <nl> + <nl> + } / / end namespace NewMangling <nl> + } / / end namespace swift <nl> + <nl> + # endif <nl> new file mode 100644 <nl> index 000000000000 . . d96b8063e5a2 <nl> mmm / dev / null <nl> ppp b / lib / AST / ASTMangler . cpp <nl> <nl> + / / = = = mmm ASTMangler . cpp - Swift AST symbol mangling mmmmmmmmmmmmmmmmmmmmm - - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This file implements declaration name mangling in Swift . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / AST / ASTMangler . h " <nl> + # include " swift / AST / ASTContext . h " <nl> + # include " swift / AST / ASTVisitor . h " <nl> + # include " swift / AST / Initializer . h " <nl> + # include " swift / AST / Module . h " <nl> + # include " swift / AST / ProtocolConformance . h " <nl> + # include " swift / AST / Mangle . h " <nl> + # include " swift / Basic / ManglingUtils . h " <nl> + # include " swift / Strings . h " <nl> + # include " clang / Basic / CharInfo . h " <nl> + # include " clang / AST / Attr . h " <nl> + # include " clang / AST / Decl . h " <nl> + # include " clang / AST / DeclObjC . h " <nl> + # include " llvm / ADT / DenseMap . h " <nl> + # include " llvm / ADT / SmallString . h " <nl> + # include " llvm / ADT / StringRef . h " <nl> + # include " llvm / Support / ErrorHandling . h " <nl> + # include " llvm / Support / SaveAndRestore . h " <nl> + # include " llvm / Support / raw_ostream . h " <nl> + # include " llvm / Support / CommandLine . h " <nl> + <nl> + using namespace swift ; <nl> + using namespace NewMangling ; <nl> + <nl> + std : : string NewMangling : : mangleTypeForDebugger ( Type Ty , const DeclContext * DC ) { <nl> + if ( useNewMangling ( ) ) { <nl> + ASTMangler : : ASTMangler NewMangler ( / * DWARF * / true ) ; <nl> + return NewMangler . mangleType ( Ty , DC ) ; <nl> + } <nl> + Mangle : : Mangler OldMangler ( / * DWARF * / true ) ; <nl> + OldMangler . mangleTypeForDebugger ( Ty , DC ) ; <nl> + return OldMangler . finalize ( ) ; <nl> + } <nl> + <nl> + std : : string NewMangling : : mangleTypeAsUSR ( Type Ty ) { <nl> + if ( useNewMangling ( ) ) { <nl> + ASTMangler : : ASTMangler NewMangler ; <nl> + return NewMangler . mangleTypeAsUSR ( Ty ) ; <nl> + } <nl> + Mangle : : Mangler OldMangler ; <nl> + OldMangler . mangleType ( Ty , / * uncurry * / 0 ) ; <nl> + return OldMangler . finalize ( ) ; <nl> + } <nl> + <nl> + <nl> + std : : string ASTMangler : : mangleClosureEntity ( const AbstractClosureExpr * closure , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendClosureEntity ( closure ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleEntity ( const ValueDecl * decl , bool isCurried , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendEntity ( decl ) ; <nl> + if ( isCurried ) <nl> + appendOperator ( " Tc " ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleDestructorEntity ( const DestructorDecl * decl , <nl> + bool isDeallocating , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendDestructorEntity ( decl , isDeallocating ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleConstructorEntity ( const ConstructorDecl * ctor , <nl> + bool isAllocating , <nl> + bool isCurried , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendConstructorEntity ( ctor , isAllocating ) ; <nl> + if ( isCurried ) <nl> + appendOperator ( " Tc " ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleIVarInitDestroyEntity ( const ClassDecl * decl , <nl> + bool isDestroyer , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendContext ( decl ) ; <nl> + appendOperator ( isDestroyer ? " fE " : " fe " ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleAccessorEntity ( AccessorKind kind , <nl> + AddressorKind addressorKind , <nl> + const ValueDecl * decl , <nl> + bool isStatic , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendAccessorEntity ( kind , addressorKind , decl , isStatic ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleGlobalGetterEntity ( ValueDecl * decl , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendEntity ( decl , " fG " , false ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleDefaultArgumentEntity ( const DeclContext * func , <nl> + unsigned index , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendDefaultArgumentEntity ( func , index ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleInitializerEntity ( const VarDecl * var , <nl> + SymbolKind SKind ) { <nl> + beginMangling ( ) ; <nl> + appendInitializerEntity ( var ) ; <nl> + appendSymbolKind ( SKind ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleNominalType ( const NominalTypeDecl * decl ) { <nl> + beginMangling ( ) ; <nl> + appendNominalType ( decl ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleWitnessTable ( NormalProtocolConformance * C ) { <nl> + beginMangling ( ) ; <nl> + appendProtocolConformance ( C ) ; <nl> + appendOperator ( " WP " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleWitnessThunk ( ProtocolConformance * Conformance , <nl> + ValueDecl * Requirement ) { <nl> + beginMangling ( ) ; <nl> + / / Concrete witness thunks get a special mangling . <nl> + if ( Conformance ) <nl> + appendProtocolConformance ( Conformance ) ; <nl> + <nl> + if ( auto ctor = dyn_cast < ConstructorDecl > ( Requirement ) ) { <nl> + appendConstructorEntity ( ctor , / * isAllocating = * / true ) ; <nl> + } else { <nl> + assert ( isa < FuncDecl > ( Requirement ) & & " expected function " ) ; <nl> + appendEntity ( cast < FuncDecl > ( Requirement ) ) ; <nl> + } <nl> + <nl> + if ( Conformance ) <nl> + appendOperator ( " TW " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleClosureWitnessThunk ( <nl> + ProtocolConformance * Conformance , <nl> + AbstractClosureExpr * Closure ) { <nl> + beginMangling ( ) ; <nl> + appendProtocolConformance ( Conformance ) ; <nl> + appendClosureEntity ( Closure ) ; <nl> + appendOperator ( " TW " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleBehaviorInitThunk ( const VarDecl * decl ) { <nl> + auto topLevelContext = decl - > getDeclContext ( ) - > getModuleScopeContext ( ) ; <nl> + auto fileUnit = cast < FileUnit > ( topLevelContext ) ; <nl> + Identifier discriminator = fileUnit - > getDiscriminatorForPrivateValue ( decl ) ; <nl> + assert ( ! discriminator . empty ( ) ) ; <nl> + assert ( ! isNonAscii ( discriminator . str ( ) ) & & <nl> + " discriminator contains non - ASCII characters " ) ; <nl> + assert ( ! clang : : isDigit ( discriminator . str ( ) . front ( ) ) & & <nl> + " not a valid identifier " ) ; <nl> + <nl> + appendContextOf ( decl ) ; <nl> + appendIdentifier ( decl - > getName ( ) . str ( ) ) ; <nl> + appendIdentifier ( discriminator . str ( ) ) ; <nl> + appendOperator ( " TB " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleGlobalVariableFull ( const VarDecl * decl ) { <nl> + / / As a special case , Clang functions and globals don ' t get mangled at all . <nl> + / / FIXME : When we can import C + + , use Clang ' s mangler . <nl> + if ( auto clangDecl = <nl> + dyn_cast_or_null < clang : : DeclaratorDecl > ( decl - > getClangDecl ( ) ) ) { <nl> + if ( auto asmLabel = clangDecl - > getAttr < clang : : AsmLabelAttr > ( ) ) { <nl> + Buffer < < ' \ 01 ' < < asmLabel - > getLabel ( ) ; <nl> + } else { <nl> + Buffer < < clangDecl - > getName ( ) ; <nl> + } <nl> + return finalize ( ) ; <nl> + } <nl> + beginMangling ( ) ; <nl> + appendEntity ( decl ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleGlobalInit ( const VarDecl * decl , int counter , <nl> + bool isInitFunc ) { <nl> + auto topLevelContext = decl - > getDeclContext ( ) - > getModuleScopeContext ( ) ; <nl> + auto fileUnit = cast < FileUnit > ( topLevelContext ) ; <nl> + Identifier discriminator = fileUnit - > getDiscriminatorForPrivateValue ( decl ) ; <nl> + assert ( ! discriminator . empty ( ) ) ; <nl> + assert ( ! isNonAscii ( discriminator . str ( ) ) & & <nl> + " discriminator contains non - ASCII characters " ) ; <nl> + assert ( ! clang : : isDigit ( discriminator . str ( ) . front ( ) ) & & <nl> + " not a valid identifier " ) ; <nl> + <nl> + Buffer < < " globalinit_ " ; <nl> + appendIdentifier ( discriminator . str ( ) ) ; <nl> + Buffer < < ( isInitFunc ? " _func " : " _token " ) ; <nl> + Buffer < < counter ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleReabstructionThunkHelper ( <nl> + CanSILFunctionType ThunkType , <nl> + Type FromType , <nl> + Type ToType , <nl> + ModuleDecl * Module ) { <nl> + Mod = Module ; <nl> + GenericSignature * GenSig = ThunkType - > getGenericSignature ( ) ; <nl> + if ( GenSig ) <nl> + CurGenericSignature = GenSig - > getCanonicalSignature ( ) ; <nl> + <nl> + beginMangling ( ) ; <nl> + appendType ( FromType ) ; <nl> + appendType ( ToType ) ; <nl> + if ( GenSig ) <nl> + appendGenericSignature ( GenSig ) ; <nl> + / / TODO : mangle ThunkType - > isPseudogeneric ( ) <nl> + appendOperator ( " TR " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleType ( Type Ty , const DeclContext * DC ) { <nl> + assert ( DWARFMangling & & " DWARFMangling expected when mangling for debugger " ) ; <nl> + <nl> + beginMangling ( ) ; <nl> + if ( DC ) <nl> + bindGenericParameters ( DC ) ; <nl> + DeclCtx = DC ; <nl> + <nl> + appendType ( Ty ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleTypeAsUSR ( Type type ) { <nl> + appendType ( type ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleTypeAsContextUSR ( const NominalTypeDecl * type ) { <nl> + appendContext ( type ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string ASTMangler : : mangleDeclAsUSR ( ValueDecl * Decl , StringRef USRPrefix ) { <nl> + Buffer < < USRPrefix ; <nl> + bindGenericParameters ( Decl - > getDeclContext ( ) ) ; <nl> + <nl> + if ( auto Ctor = dyn_cast < ConstructorDecl > ( Decl ) ) { <nl> + appendConstructorEntity ( Ctor , / * isAllocating = * / false ) ; <nl> + } else if ( auto Dtor = dyn_cast < DestructorDecl > ( Decl ) ) { <nl> + appendDestructorEntity ( Dtor , / * isDeallocating = * / false ) ; <nl> + } else if ( auto NTD = dyn_cast < NominalTypeDecl > ( Decl ) ) { <nl> + appendNominalType ( NTD ) ; <nl> + } else if ( isa < TypeAliasDecl > ( Decl ) | | isa < AssociatedTypeDecl > ( Decl ) ) { <nl> + appendContextOf ( Decl ) ; <nl> + appendDeclName ( Decl ) ; <nl> + } else { <nl> + appendEntity ( Decl ) ; <nl> + } <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendSymbolKind ( SymbolKind SKind ) { <nl> + switch ( SKind ) { <nl> + case SymbolKind : : Default : return ; <nl> + case SymbolKind : : VTableMethod : return appendOperator ( " TV " ) ; <nl> + case SymbolKind : : DynamicThunk : return appendOperator ( " TD " ) ; <nl> + case SymbolKind : : SwiftAsObjCThunk : return appendOperator ( " To " ) ; <nl> + case SymbolKind : : ObjCAsSwiftThunk : return appendOperator ( " TO " ) ; <nl> + case SymbolKind : : DirectMethodReferenceThunk : return appendOperator ( " Td " ) ; <nl> + } <nl> + } <nl> + <nl> + / / / Returns true if one of the ancestor DeclContexts of \ p D is either marked <nl> + / / / private or is a local context . <nl> + static bool isInPrivateOrLocalContext ( const ValueDecl * D ) { <nl> + const DeclContext * DC = D - > getDeclContext ( ) ; <nl> + if ( ! DC - > isTypeContext ( ) ) { <nl> + assert ( ( DC - > isModuleScopeContext ( ) | | DC - > isLocalContext ( ) ) & & <nl> + " unexpected context kind " ) ; <nl> + return DC - > isLocalContext ( ) ; <nl> + } <nl> + <nl> + auto declaredType = DC - > getDeclaredTypeOfContext ( ) ; <nl> + if ( ! declaredType | | declaredType - > hasError ( ) ) <nl> + return false ; <nl> + <nl> + auto * nominal = declaredType - > getAnyNominal ( ) ; <nl> + if ( nominal - > getFormalAccess ( ) < = Accessibility : : FilePrivate ) <nl> + return true ; <nl> + return isInPrivateOrLocalContext ( nominal ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendDeclName ( const ValueDecl * decl ) { <nl> + if ( decl - > getName ( ) . isOperator ( ) ) { <nl> + appendIdentifier ( translateOperator ( decl - > getName ( ) . str ( ) ) ) ; <nl> + switch ( decl - > getAttrs ( ) . getUnaryOperatorKind ( ) ) { <nl> + case UnaryOperatorKind : : Prefix : <nl> + return appendOperator ( " op " ) ; <nl> + case UnaryOperatorKind : : Postfix : <nl> + return appendOperator ( " oP " ) ; <nl> + case UnaryOperatorKind : : None : <nl> + return appendOperator ( " oi " ) ; <nl> + } <nl> + llvm_unreachable ( " bad UnaryOperatorKind " ) ; <nl> + } else { <nl> + appendIdentifier ( decl - > getName ( ) . str ( ) ) ; <nl> + } <nl> + <nl> + if ( decl - > getDeclContext ( ) - > isLocalContext ( ) ) { <nl> + / / Mangle local declarations with a numeric discriminator . <nl> + return appendOperator ( " L " , Index ( decl - > getLocalDiscriminator ( ) ) ) ; <nl> + } <nl> + if ( decl - > hasAccessibility ( ) & & <nl> + decl - > getFormalAccess ( ) < = Accessibility : : FilePrivate & & <nl> + ! isInPrivateOrLocalContext ( decl ) ) { <nl> + / / Mangle non - local private declarations with a textual discriminator <nl> + / / based on their enclosing file . <nl> + <nl> + / / The first < identifier > is a discriminator string unique to the decl ' s <nl> + / / original source file . <nl> + auto topLevelContext = decl - > getDeclContext ( ) - > getModuleScopeContext ( ) ; <nl> + auto fileUnit = cast < FileUnit > ( topLevelContext ) ; <nl> + <nl> + Identifier discriminator = <nl> + fileUnit - > getDiscriminatorForPrivateValue ( decl ) ; <nl> + assert ( ! discriminator . empty ( ) ) ; <nl> + assert ( ! isNonAscii ( discriminator . str ( ) ) & & <nl> + " discriminator contains non - ASCII characters " ) ; <nl> + ( void ) isNonAscii ; <nl> + assert ( ! clang : : isDigit ( discriminator . str ( ) . front ( ) ) & & <nl> + " not a valid identifier " ) ; <nl> + <nl> + appendIdentifier ( discriminator . str ( ) ) ; <nl> + return appendOperator ( " LL " ) ; <nl> + } <nl> + } <nl> + <nl> + static const char * getMetatypeRepresentationOp ( MetatypeRepresentation Rep ) { <nl> + switch ( Rep ) { <nl> + case MetatypeRepresentation : : Thin : <nl> + return " t " ; <nl> + case MetatypeRepresentation : : Thick : <nl> + return " T " ; <nl> + case MetatypeRepresentation : : ObjC : <nl> + return " o " ; <nl> + } <nl> + } <nl> + <nl> + / / / Mangle a type into the buffer . <nl> + / / / <nl> + void ASTMangler : : appendType ( Type type ) { <nl> + assert ( ( DWARFMangling | | type - > isCanonical ( ) ) & & <nl> + " expecting canonical types when not mangling for the debugger " ) ; <nl> + TypeBase * tybase = type . getPointer ( ) ; <nl> + switch ( type - > getKind ( ) ) { <nl> + case TypeKind : : TypeVariable : <nl> + llvm_unreachable ( " mangling type variable " ) ; <nl> + <nl> + case TypeKind : : Module : <nl> + llvm_unreachable ( " Cannot mangle module type yet " ) ; <nl> + <nl> + case TypeKind : : Error : <nl> + case TypeKind : : Unresolved : <nl> + Buffer < < " . ERR . " ; <nl> + return ; <nl> + <nl> + / / We don ' t care about these types being a bit verbose because we <nl> + / / don ' t expect them to come up that often in API names . <nl> + case TypeKind : : BuiltinFloat : <nl> + switch ( cast < BuiltinFloatType > ( tybase ) - > getFPKind ( ) ) { <nl> + case BuiltinFloatType : : IEEE16 : appendOperator ( " Bf16_ " ) ; return ; <nl> + case BuiltinFloatType : : IEEE32 : appendOperator ( " Bf32_ " ) ; return ; <nl> + case BuiltinFloatType : : IEEE64 : appendOperator ( " Bf64_ " ) ; return ; <nl> + case BuiltinFloatType : : IEEE80 : appendOperator ( " Bf80_ " ) ; return ; <nl> + case BuiltinFloatType : : IEEE128 : appendOperator ( " Bf128_ " ) ; return ; <nl> + case BuiltinFloatType : : PPC128 : llvm_unreachable ( " ppc128 not supported " ) ; <nl> + } <nl> + llvm_unreachable ( " bad floating - point kind " ) ; <nl> + case TypeKind : : BuiltinInteger : { <nl> + auto width = cast < BuiltinIntegerType > ( tybase ) - > getWidth ( ) ; <nl> + if ( width . isFixedWidth ( ) ) <nl> + appendOperator ( " Bi " , Index ( width . getFixedWidth ( ) + 1 ) ) ; <nl> + else if ( width . isPointerWidth ( ) ) <nl> + appendOperator ( " Bw " ) ; <nl> + else <nl> + llvm_unreachable ( " impossible width value " ) ; <nl> + return ; <nl> + } <nl> + case TypeKind : : BuiltinRawPointer : <nl> + return appendOperator ( " Bp " ) ; <nl> + case TypeKind : : BuiltinNativeObject : <nl> + return appendOperator ( " Bo " ) ; <nl> + case TypeKind : : BuiltinBridgeObject : <nl> + return appendOperator ( " Bb " ) ; <nl> + case TypeKind : : BuiltinUnknownObject : <nl> + return appendOperator ( " BO " ) ; <nl> + case TypeKind : : BuiltinUnsafeValueBuffer : <nl> + return appendOperator ( " BB " ) ; <nl> + case TypeKind : : BuiltinVector : <nl> + appendType ( cast < BuiltinVectorType > ( tybase ) - > getElementType ( ) ) ; <nl> + return appendOperator ( " Bv " , <nl> + cast < BuiltinVectorType > ( tybase ) - > getNumElements ( ) ) ; <nl> + case TypeKind : : NameAlias : { <nl> + assert ( DWARFMangling & & " sugared types are only legal for the debugger " ) ; <nl> + auto NameAliasTy = cast < NameAliasType > ( tybase ) ; <nl> + TypeAliasDecl * decl = NameAliasTy - > getDecl ( ) ; <nl> + if ( decl - > getModuleContext ( ) = = decl - > getASTContext ( ) . TheBuiltinModule ) { <nl> + / / It ' s not possible to mangle the context of the builtin module . <nl> + return appendType ( decl - > getUnderlyingType ( ) ) ; <nl> + } <nl> + <nl> + / / For the DWARF output we want to mangle the type alias + context , <nl> + / / unless the type alias references a builtin type . <nl> + appendContextOf ( decl ) ; <nl> + appendDeclName ( decl ) ; <nl> + return appendOperator ( " a " ) ; <nl> + } <nl> + <nl> + case TypeKind : : Paren : <nl> + return appendSugaredType < ParenType > ( type ) ; <nl> + case TypeKind : : Substituted : <nl> + return appendSugaredType < SubstitutedType > ( type ) ; <nl> + case TypeKind : : ArraySlice : / * fallthrough * / <nl> + case TypeKind : : Optional : <nl> + return appendSugaredType < SyntaxSugarType > ( type ) ; <nl> + case TypeKind : : Dictionary : <nl> + return appendSugaredType < DictionaryType > ( type ) ; <nl> + <nl> + case TypeKind : : ImplicitlyUnwrappedOptional : { <nl> + assert ( DWARFMangling & & " sugared types are only legal for the debugger " ) ; <nl> + auto * IUO = cast < ImplicitlyUnwrappedOptionalType > ( tybase ) ; <nl> + auto implDecl = tybase - > getASTContext ( ) . getImplicitlyUnwrappedOptionalDecl ( ) ; <nl> + auto GenTy = BoundGenericType : : get ( implDecl , Type ( ) , IUO - > getBaseType ( ) ) ; <nl> + return appendType ( GenTy ) ; <nl> + } <nl> + <nl> + case TypeKind : : ExistentialMetatype : { <nl> + ExistentialMetatypeType * EMT = cast < ExistentialMetatypeType > ( tybase ) ; <nl> + appendType ( EMT - > getInstanceType ( ) ) ; <nl> + if ( EMT - > hasRepresentation ( ) ) { <nl> + appendOperator ( " Xm " , <nl> + getMetatypeRepresentationOp ( EMT - > getRepresentation ( ) ) ) ; <nl> + } else { <nl> + appendOperator ( " Xp " ) ; <nl> + } <nl> + return ; <nl> + } <nl> + case TypeKind : : Metatype : { <nl> + MetatypeType * MT = cast < MetatypeType > ( tybase ) ; <nl> + appendType ( MT - > getInstanceType ( ) ) ; <nl> + if ( MT - > hasRepresentation ( ) ) { <nl> + appendOperator ( " XM " , <nl> + getMetatypeRepresentationOp ( MT - > getRepresentation ( ) ) ) ; <nl> + } else { <nl> + appendOperator ( " m " ) ; <nl> + } <nl> + return ; <nl> + } <nl> + case TypeKind : : LValue : <nl> + llvm_unreachable ( " @ lvalue types should not occur in function interfaces " ) ; <nl> + <nl> + case TypeKind : : InOut : <nl> + appendType ( cast < InOutType > ( tybase ) - > getObjectType ( ) ) ; <nl> + return appendOperator ( " z " ) ; <nl> + <nl> + case TypeKind : : UnmanagedStorage : <nl> + appendType ( cast < UnmanagedStorageType > ( tybase ) - > getReferentType ( ) ) ; <nl> + return appendOperator ( " Xu " ) ; <nl> + <nl> + case TypeKind : : UnownedStorage : <nl> + appendType ( cast < UnownedStorageType > ( tybase ) - > getReferentType ( ) ) ; <nl> + return appendOperator ( " Xo " ) ; <nl> + <nl> + case TypeKind : : WeakStorage : <nl> + appendType ( cast < WeakStorageType > ( tybase ) - > getReferentType ( ) ) ; <nl> + return appendOperator ( " Xw " ) ; <nl> + <nl> + case TypeKind : : Tuple : <nl> + appendTypeList ( type ) ; <nl> + return appendOperator ( " t " ) ; <nl> + <nl> + case TypeKind : : Protocol : <nl> + case TypeKind : : ProtocolComposition : { <nl> + / / We mangle ProtocolType and ProtocolCompositionType using the <nl> + / / same production : <nl> + bool First = true ; <nl> + appendProtocolList ( type , First ) ; <nl> + if ( First ) <nl> + appendOperator ( " y " ) ; <nl> + return appendOperator ( " p " ) ; <nl> + } <nl> + case TypeKind : : UnboundGeneric : <nl> + case TypeKind : : Class : <nl> + case TypeKind : : Enum : <nl> + case TypeKind : : Struct : <nl> + case TypeKind : : BoundGenericClass : <nl> + case TypeKind : : BoundGenericEnum : <nl> + case TypeKind : : BoundGenericStruct : <nl> + if ( type - > isSpecialized ( ) ) { <nl> + appendBoundGenericArgs ( type ) ; <nl> + appendNominalType ( type - > getAnyNominal ( ) ) ; <nl> + return appendOperator ( " G " ) ; <nl> + } <nl> + appendNominalType ( tybase - > getAnyNominal ( ) ) ; <nl> + return ; <nl> + <nl> + case TypeKind : : SILFunction : <nl> + return appendImplFunctionType ( cast < SILFunctionType > ( tybase ) ) ; <nl> + <nl> + / / type : : = archetype <nl> + case TypeKind : : Archetype : { <nl> + auto * archetype = cast < ArchetypeType > ( tybase ) ; <nl> + <nl> + / / Mangle the associated type of a parent archetype . <nl> + if ( auto parent = archetype - > getParent ( ) ) { <nl> + assert ( archetype - > getAssocType ( ) <nl> + & & " child archetype has no associated type ? ! " ) ; <nl> + <nl> + if ( tryMangleSubstitution ( archetype ) ) <nl> + return ; <nl> + appendType ( parent ) ; <nl> + appendIdentifier ( archetype - > getName ( ) . str ( ) ) ; <nl> + appendOperator ( " Qa " ) ; <nl> + addSubstitution ( archetype ) ; <nl> + return ; <nl> + } <nl> + <nl> + / / archetype : : = ' Q ' < index > # archetype with depth = 0 , index = N <nl> + / / archetype : : = ' Qd ' < index > < index > # archetype with depth = M + 1 , index = N <nl> + / / Mangle generic parameter archetypes . <nl> + <nl> + / / Find the archetype information . <nl> + const DeclContext * DC = DeclCtx ; <nl> + auto GTPT = ArchetypeBuilder : : mapTypeOutOfContext ( DC , archetype ) <nl> + - > castTo < GenericTypeParamType > ( ) ; <nl> + <nl> + if ( DWARFMangling ) { <nl> + Buffer < < ' q ' < < Index ( GTPT - > getIndex ( ) ) ; <nl> + <nl> + / / The DWARF output created by Swift is intentionally flat , <nl> + / / therefore archetypes are emitted with their DeclContext if <nl> + / / they appear at the top level of a type . <nl> + DWARFMangling = false ; <nl> + while ( DC & & DC - > isGenericContext ( ) ) { <nl> + if ( DC - > isInnermostContextGeneric ( ) & & <nl> + DC - > getGenericParamsOfContext ( ) - > getDepth ( ) = = GTPT - > getDepth ( ) ) <nl> + break ; <nl> + DC = DC - > getParent ( ) ; <nl> + } <nl> + assert ( DC & & " no decl context for archetype found " ) ; <nl> + if ( ! DC ) return ; <nl> + appendContext ( DC ) ; <nl> + DWARFMangling = true ; <nl> + return appendOperator ( " Qq " , Index ( GTPT - > getIndex ( ) ) ) ; <nl> + } <nl> + if ( GTPT - > getDepth ( ) ! = 0 ) { <nl> + return appendOperator ( " Qd " , Index ( GTPT - > getDepth ( ) - 1 ) , <nl> + Index ( GTPT - > getIndex ( ) ) ) ; <nl> + } <nl> + return appendOperator ( " Q " , Index ( GTPT - > getIndex ( ) ) ) ; <nl> + } <nl> + <nl> + case TypeKind : : DynamicSelf : { <nl> + auto dynamicSelf = cast < DynamicSelfType > ( tybase ) ; <nl> + if ( dynamicSelf - > getSelfType ( ) - > getAnyNominal ( ) ) { <nl> + appendType ( dynamicSelf - > getSelfType ( ) ) ; <nl> + return appendOperator ( " XD " ) ; <nl> + } <nl> + return appendType ( dynamicSelf - > getSelfType ( ) ) ; <nl> + } <nl> + <nl> + case TypeKind : : GenericFunction : { <nl> + auto genFunc = cast < GenericFunctionType > ( tybase ) ; <nl> + appendFunctionType ( genFunc ) ; <nl> + appendGenericSignature ( genFunc - > getGenericSignature ( ) ) ; <nl> + appendOperator ( " u " ) ; <nl> + return ; <nl> + } <nl> + <nl> + case TypeKind : : GenericTypeParam : { <nl> + auto paramTy = cast < GenericTypeParamType > ( tybase ) ; <nl> + / / A special mangling for the very first generic parameter . This shows up <nl> + / / frequently because it corresponds to ' Self ' in protocol requirement <nl> + / / generic signatures . <nl> + if ( paramTy - > getDepth ( ) = = 0 & & paramTy - > getIndex ( ) = = 0 ) <nl> + return appendOperator ( " x " ) ; <nl> + <nl> + return appendOpWithGenericParamIndex ( " q " , paramTy ) ; <nl> + } <nl> + <nl> + case TypeKind : : DependentMember : { <nl> + auto * DepTy = cast < DependentMemberType > ( tybase ) ; <nl> + if ( tryMangleSubstitution ( DepTy ) ) <nl> + return ; <nl> + <nl> + bool isAssocTypeAtDepth = false ; <nl> + if ( GenericTypeParamType * gpBase = appendAssocType ( DepTy , <nl> + isAssocTypeAtDepth ) ) { <nl> + if ( gpBase - > getDepth ( ) = = 0 & & gpBase - > getIndex ( ) = = 0 ) { <nl> + appendOperator ( isAssocTypeAtDepth ? " QZ " : " Qz " ) ; <nl> + } else { <nl> + appendOpWithGenericParamIndex ( isAssocTypeAtDepth ? " QY " : " Qy " , <nl> + gpBase ) ; <nl> + } <nl> + } else { <nl> + / / Dependent members of non - generic - param types are not canonical , but <nl> + / / we may still want to mangle them for debugging or indexing purposes . <nl> + appendType ( DepTy - > getBase ( ) ) ; <nl> + appendAssociatedTypeName ( DepTy ) ; <nl> + appendOperator ( " qa " ) ; <nl> + } <nl> + addSubstitution ( DepTy ) ; <nl> + return ; <nl> + } <nl> + <nl> + case TypeKind : : Function : <nl> + appendFunctionType ( cast < FunctionType > ( tybase ) ) ; <nl> + return ; <nl> + <nl> + case TypeKind : : SILBox : <nl> + appendType ( cast < SILBoxType > ( tybase ) - > getBoxedType ( ) ) ; <nl> + return appendOperator ( " Xb " ) ; <nl> + <nl> + case TypeKind : : SILBlockStorage : <nl> + llvm_unreachable ( " should never be mangled " ) ; <nl> + } <nl> + llvm_unreachable ( " bad type kind " ) ; <nl> + } <nl> + <nl> + / / / Mangle a list of protocols . Each protocol is a substitution <nl> + / / / candidate . <nl> + void ASTMangler : : appendProtocolList ( ArrayRef < Type > Protocols , bool & First ) { <nl> + for ( Type protoTy : Protocols ) { <nl> + if ( auto * Composition = protoTy - > getAs < ProtocolCompositionType > ( ) ) { <nl> + appendProtocolList ( Composition - > getProtocols ( ) , First ) ; <nl> + } else { <nl> + appendProtocolName ( protoTy - > castTo < ProtocolType > ( ) - > getDecl ( ) ) ; <nl> + appendListSeparator ( First ) ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + GenericTypeParamType * ASTMangler : : appendAssocType ( DependentMemberType * DepTy , <nl> + bool & isAssocTypeAtDepth ) { <nl> + auto base = DepTy - > getBase ( ) - > getCanonicalType ( ) ; <nl> + / / ' t_0_0 . Member ' <nl> + if ( auto gpBase = dyn_cast < GenericTypeParamType > ( base ) ) { <nl> + appendAssociatedTypeName ( DepTy ) ; <nl> + isAssocTypeAtDepth = false ; <nl> + return gpBase ; <nl> + } <nl> + <nl> + / / ' t_0_0 . Member . Member . . . ' <nl> + SmallVector < DependentMemberType * , 2 > path ; <nl> + path . push_back ( DepTy ) ; <nl> + while ( auto dmBase = dyn_cast < DependentMemberType > ( base ) ) { <nl> + path . push_back ( dmBase ) ; <nl> + base = dmBase . getBase ( ) ; <nl> + } <nl> + if ( auto gpRoot = dyn_cast < GenericTypeParamType > ( base ) ) { <nl> + bool first = true ; <nl> + for ( auto * member : reversed ( path ) ) { <nl> + appendAssociatedTypeName ( member ) ; <nl> + appendListSeparator ( first ) ; <nl> + } <nl> + isAssocTypeAtDepth = true ; <nl> + return gpRoot ; <nl> + } <nl> + return nullptr ; <nl> + } <nl> + <nl> + void ASTMangler : : appendOpWithGenericParamIndex ( StringRef Op , <nl> + GenericTypeParamType * paramTy ) { <nl> + llvm : : SmallVector < char , 8 > OpBuf ( Op . begin ( ) , Op . end ( ) ) ; <nl> + if ( paramTy - > getDepth ( ) > 0 ) { <nl> + OpBuf . push_back ( ' d ' ) ; <nl> + return appendOperator ( StringRef ( OpBuf . data ( ) , OpBuf . size ( ) ) , <nl> + Index ( paramTy - > getDepth ( ) - 1 ) , <nl> + Index ( paramTy - > getIndex ( ) ) ) ; <nl> + } <nl> + if ( paramTy - > getIndex ( ) = = 0 ) { <nl> + OpBuf . push_back ( ' z ' ) ; <nl> + return appendOperator ( StringRef ( OpBuf . data ( ) , OpBuf . size ( ) ) ) ; <nl> + } <nl> + appendOperator ( Op , Index ( paramTy - > getIndex ( ) - 1 ) ) ; <nl> + } <nl> + <nl> + <nl> + / / / Bind the generic parameters from the given signature . <nl> + void ASTMangler : : bindGenericParameters ( CanGenericSignature sig ) { <nl> + if ( sig ) <nl> + CurGenericSignature = sig ; <nl> + } <nl> + <nl> + / / / Bind the generic parameters from the given context and its parents . <nl> + void ASTMangler : : bindGenericParameters ( const DeclContext * DC ) { <nl> + if ( auto sig = DC - > getGenericSignatureOfContext ( ) ) <nl> + bindGenericParameters ( sig - > getCanonicalSignature ( ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendBoundGenericArgs ( Type type ) { <nl> + if ( auto * unboundType = type - > getAs < UnboundGenericType > ( ) ) { <nl> + if ( auto parent = unboundType - > getParent ( ) ) <nl> + appendBoundGenericArgs ( parent ) ; <nl> + return appendOperator ( " y " ) ; <nl> + } <nl> + if ( auto * nominalType = type - > getAs < NominalType > ( ) ) { <nl> + if ( auto parent = nominalType - > getParent ( ) ) <nl> + appendBoundGenericArgs ( parent ) ; <nl> + return appendOperator ( " y " ) ; <nl> + } <nl> + auto * boundType = type - > castTo < BoundGenericType > ( ) ; <nl> + if ( auto parent = boundType - > getParent ( ) ) <nl> + appendBoundGenericArgs ( parent ) ; <nl> + <nl> + bool firstArg = true ; <nl> + for ( Type arg : boundType - > getGenericArgs ( ) ) { <nl> + appendType ( arg ) ; <nl> + appendListSeparator ( firstArg ) ; <nl> + } <nl> + } <nl> + <nl> + static char getParamConvention ( ParameterConvention conv ) { <nl> + / / @ in and @ out are mangled the same because they ' re put in <nl> + / / different places . <nl> + switch ( conv ) { <nl> + case ParameterConvention : : Indirect_In : return ' i ' ; <nl> + case ParameterConvention : : Indirect_Inout : return ' l ' ; <nl> + case ParameterConvention : : Indirect_InoutAliasable : return ' b ' ; <nl> + case ParameterConvention : : Indirect_In_Guaranteed : return ' n ' ; <nl> + case ParameterConvention : : Direct_Owned : return ' x ' ; <nl> + case ParameterConvention : : Direct_Unowned : return ' y ' ; <nl> + case ParameterConvention : : Direct_Guaranteed : return ' g ' ; <nl> + case ParameterConvention : : Direct_Deallocating : return ' e ' ; <nl> + } <nl> + llvm_unreachable ( " bad parameter convention " ) ; <nl> + } ; <nl> + <nl> + static char getResultConvention ( ResultConvention conv ) { <nl> + switch ( conv ) { <nl> + case ResultConvention : : Indirect : return ' r ' ; <nl> + case ResultConvention : : Owned : return ' o ' ; <nl> + case ResultConvention : : Unowned : return ' d ' ; <nl> + case ResultConvention : : UnownedInnerPointer : return ' u ' ; <nl> + case ResultConvention : : Autoreleased : return ' a ' ; <nl> + } <nl> + llvm_unreachable ( " bad result convention " ) ; <nl> + } ; <nl> + <nl> + void ASTMangler : : appendImplFunctionType ( SILFunctionType * fn ) { <nl> + <nl> + llvm : : SmallVector < char , 32 > OpArgs ; <nl> + <nl> + if ( fn - > isPolymorphic ( ) & & fn - > isPseudogeneric ( ) ) <nl> + OpArgs . push_back ( ' P ' ) ; <nl> + <nl> + / / < impl - callee - convention > <nl> + if ( fn - > getExtInfo ( ) . hasContext ( ) ) { <nl> + OpArgs . push_back ( getParamConvention ( fn - > getCalleeConvention ( ) ) ) ; <nl> + } else { <nl> + OpArgs . push_back ( ' t ' ) ; <nl> + } <nl> + <nl> + switch ( fn - > getRepresentation ( ) ) { <nl> + case SILFunctionTypeRepresentation : : Thick : <nl> + case SILFunctionTypeRepresentation : : Thin : <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : Block : <nl> + OpArgs . push_back ( ' B ' ) ; <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : CFunctionPointer : <nl> + OpArgs . push_back ( ' C ' ) ; <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : ObjCMethod : <nl> + OpArgs . push_back ( ' O ' ) ; <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : Method : <nl> + OpArgs . push_back ( ' M ' ) ; <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : Closure : <nl> + OpArgs . push_back ( ' K ' ) ; <nl> + break ; <nl> + case SILFunctionTypeRepresentation : : WitnessMethod : <nl> + OpArgs . push_back ( ' W ' ) ; <nl> + break ; <nl> + } <nl> + <nl> + / / Mangle the parameters . <nl> + for ( auto param : fn - > getParameters ( ) ) { <nl> + OpArgs . push_back ( getParamConvention ( param . getConvention ( ) ) ) ; <nl> + appendType ( param . getType ( ) ) ; <nl> + } <nl> + <nl> + / / Mangle the results . <nl> + for ( auto result : fn - > getAllResults ( ) ) { <nl> + OpArgs . push_back ( getResultConvention ( result . getConvention ( ) ) ) ; <nl> + appendType ( result . getType ( ) ) ; <nl> + } <nl> + <nl> + / / Mangle the error result if present . <nl> + if ( fn - > hasErrorResult ( ) ) { <nl> + auto error = fn - > getErrorResult ( ) ; <nl> + OpArgs . push_back ( ' z ' ) ; <nl> + OpArgs . push_back ( getResultConvention ( error . getConvention ( ) ) ) ; <nl> + appendType ( error . getType ( ) ) ; <nl> + } <nl> + if ( fn - > isPolymorphic ( ) ) <nl> + appendGenericSignature ( fn - > getGenericSignature ( ) ) ; <nl> + <nl> + OpArgs . push_back ( ' _ ' ) ; <nl> + <nl> + appendOperator ( " I " , StringRef ( OpArgs . data ( ) , OpArgs . size ( ) ) ) ; <nl> + } <nl> + <nl> + / / / Mangle the context of the given declaration as a < context . <nl> + / / / This is the top - level entrypoint for mangling < context > . <nl> + void ASTMangler : : appendContextOf ( const ValueDecl * decl ) { <nl> + auto clangDecl = decl - > getClangDecl ( ) ; <nl> + <nl> + / / Classes and protocols implemented in Objective - C have a special context <nl> + / / mangling . <nl> + / / known - context : : = ' So ' <nl> + if ( isa < ClassDecl > ( decl ) & & clangDecl ) { <nl> + assert ( isa < clang : : ObjCInterfaceDecl > ( clangDecl ) | | <nl> + isa < clang : : TypedefDecl > ( clangDecl ) ) ; <nl> + return appendOperator ( " So " ) ; <nl> + } <nl> + <nl> + if ( isa < ProtocolDecl > ( decl ) & & clangDecl ) { <nl> + assert ( isa < clang : : ObjCProtocolDecl > ( clangDecl ) ) ; <nl> + return appendOperator ( " So " ) ; <nl> + } <nl> + <nl> + / / Declarations provided by a C module have a special context mangling . <nl> + / / known - context : : = ' SC ' <nl> + / / Do a dance to avoid a layering dependency . <nl> + if ( auto file = dyn_cast < FileUnit > ( decl - > getDeclContext ( ) ) ) { <nl> + if ( file - > getKind ( ) = = FileUnitKind : : ClangModule ) <nl> + return appendOperator ( " SC " ) ; <nl> + } <nl> + <nl> + / / Just mangle the decl ' s DC . <nl> + appendContext ( decl - > getDeclContext ( ) ) ; <nl> + } <nl> + <nl> + namespace { <nl> + class FindFirstVariable : <nl> + public PatternVisitor < FindFirstVariable , VarDecl * > { <nl> + public : <nl> + VarDecl * visitNamedPattern ( NamedPattern * P ) { <nl> + return P - > getDecl ( ) ; <nl> + } <nl> + <nl> + VarDecl * visitTuplePattern ( TuplePattern * P ) { <nl> + for ( auto & elt : P - > getElements ( ) ) { <nl> + VarDecl * var = visit ( elt . getPattern ( ) ) ; <nl> + if ( var ) return var ; <nl> + } <nl> + return nullptr ; <nl> + } <nl> + <nl> + VarDecl * visitParenPattern ( ParenPattern * P ) { <nl> + return visit ( P - > getSubPattern ( ) ) ; <nl> + } <nl> + VarDecl * visitVarPattern ( VarPattern * P ) { <nl> + return visit ( P - > getSubPattern ( ) ) ; <nl> + } <nl> + VarDecl * visitTypedPattern ( TypedPattern * P ) { <nl> + return visit ( P - > getSubPattern ( ) ) ; <nl> + } <nl> + VarDecl * visitAnyPattern ( AnyPattern * P ) { <nl> + return nullptr ; <nl> + } <nl> + <nl> + / / Refutable patterns shouldn ' t ever come up . <nl> + # define REFUTABLE_PATTERN ( ID , BASE ) \ <nl> + VarDecl * visit # # ID # # Pattern ( ID # # Pattern * P ) { \ <nl> + llvm_unreachable ( " shouldn ' t be visiting a refutable pattern here ! " ) ; \ <nl> + } <nl> + # define PATTERN ( ID , BASE ) <nl> + # include " swift / AST / PatternNodes . def " <nl> + } ; <nl> + } <nl> + <nl> + / / / Find the first identifier bound by the given binding . This <nl> + / / / assumes that field and global - variable bindings always bind at <nl> + / / / least one name , which is probably a reasonable assumption but may <nl> + / / / not be adequately enforced . <nl> + static VarDecl * findFirstVariable ( PatternBindingDecl * binding ) { <nl> + for ( auto entry : binding - > getPatternList ( ) ) { <nl> + auto var = FindFirstVariable ( ) . visit ( entry . getPattern ( ) ) ; <nl> + if ( var ) return var ; <nl> + } <nl> + llvm_unreachable ( " pattern - binding bound no variables ? " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendContext ( const DeclContext * ctx ) { <nl> + switch ( ctx - > getContextKind ( ) ) { <nl> + case DeclContextKind : : Module : <nl> + return appendModule ( cast < Module > ( ctx ) ) ; <nl> + <nl> + case DeclContextKind : : FileUnit : <nl> + assert ( ! isa < BuiltinUnit > ( ctx ) & & " mangling member of builtin module ! " ) ; <nl> + appendContext ( ctx - > getParent ( ) ) ; <nl> + return ; <nl> + <nl> + case DeclContextKind : : SerializedLocal : { <nl> + auto local = cast < SerializedLocalDeclContext > ( ctx ) ; <nl> + switch ( local - > getLocalDeclContextKind ( ) ) { <nl> + case LocalDeclContextKind : : AbstractClosure : <nl> + appendClosureEntity ( cast < SerializedAbstractClosureExpr > ( local ) ) ; <nl> + return ; <nl> + case LocalDeclContextKind : : DefaultArgumentInitializer : { <nl> + auto argInit = cast < SerializedDefaultArgumentInitializer > ( local ) ; <nl> + appendDefaultArgumentEntity ( ctx - > getParent ( ) , argInit - > getIndex ( ) ) ; <nl> + return ; <nl> + } <nl> + case LocalDeclContextKind : : PatternBindingInitializer : { <nl> + auto patternInit = cast < SerializedPatternBindingInitializer > ( local ) ; <nl> + auto var = findFirstVariable ( patternInit - > getBinding ( ) ) ; <nl> + appendInitializerEntity ( var ) ; <nl> + return ; <nl> + } <nl> + case LocalDeclContextKind : : TopLevelCodeDecl : <nl> + return appendContext ( local - > getParent ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + case DeclContextKind : : GenericTypeDecl : <nl> + if ( auto nomctx = dyn_cast < NominalTypeDecl > ( ctx ) ) <nl> + appendNominalType ( nomctx ) ; <nl> + else <nl> + appendContext ( ctx - > getParent ( ) ) ; <nl> + return ; <nl> + <nl> + case DeclContextKind : : ExtensionDecl : { <nl> + auto ExtD = cast < ExtensionDecl > ( ctx ) ; <nl> + auto ExtTy = ExtD - > getExtendedType ( ) ; <nl> + / / Recover from erroneous extension . <nl> + if ( ExtTy . isNull ( ) | | ExtTy - > hasError ( ) ) <nl> + return appendContext ( ExtD - > getDeclContext ( ) ) ; <nl> + <nl> + auto decl = ExtTy - > getAnyNominal ( ) ; <nl> + assert ( decl & & " extension of non - nominal type ? " ) ; <nl> + / / Mangle the module name if : <nl> + / / - the extension is defined in a different module from the actual nominal <nl> + / / type decl , <nl> + / / - the extension is constrained , or <nl> + / / - the extension is to a protocol . <nl> + / / FIXME : In a world where protocol extensions are dynamically dispatched , <nl> + / / " extension is to a protocol " would no longer be a reason to use the <nl> + / / extension mangling , because an extension method implementation could be <nl> + / / resiliently moved into the original protocol itself . <nl> + if ( ExtD - > getParentModule ( ) ! = decl - > getParentModule ( ) <nl> + | | ExtD - > isConstrainedExtension ( ) <nl> + | | ExtD - > getDeclaredInterfaceType ( ) - > isExistentialType ( ) ) { <nl> + auto sig = ExtD - > getGenericSignature ( ) ; <nl> + / / If the extension is constrained , mangle the generic signature that <nl> + / / constrains it . <nl> + appendNominalType ( decl ) ; <nl> + appendModule ( ExtD - > getParentModule ( ) ) ; <nl> + if ( sig & & ExtD - > isConstrainedExtension ( ) ) { <nl> + Mod = ExtD - > getModuleContext ( ) ; <nl> + appendGenericSignature ( sig ) ; <nl> + } <nl> + return appendOperator ( " E " ) ; <nl> + } <nl> + return appendNominalType ( decl ) ; <nl> + } <nl> + <nl> + case DeclContextKind : : AbstractClosureExpr : <nl> + return appendClosureEntity ( cast < AbstractClosureExpr > ( ctx ) ) ; <nl> + <nl> + case DeclContextKind : : AbstractFunctionDecl : { <nl> + auto fn = cast < AbstractFunctionDecl > ( ctx ) ; <nl> + <nl> + / / Constructors and destructors as contexts are always mangled <nl> + / / using the non - ( de ) allocating variants . <nl> + if ( auto ctor = dyn_cast < ConstructorDecl > ( fn ) ) { <nl> + return appendConstructorEntity ( ctor , / * allocating * / false ) ; <nl> + } <nl> + <nl> + if ( auto dtor = dyn_cast < DestructorDecl > ( fn ) ) <nl> + return appendDestructorEntity ( dtor , / * deallocating * / false ) ; <nl> + <nl> + return appendEntity ( fn ) ; <nl> + } <nl> + <nl> + case DeclContextKind : : SubscriptDecl : <nl> + / / FIXME : We may need to do something here if subscripts contain any symbols <nl> + / / exposed with linkage names . <nl> + return appendContext ( ctx - > getParent ( ) ) ; <nl> + <nl> + case DeclContextKind : : Initializer : <nl> + switch ( cast < Initializer > ( ctx ) - > getInitializerKind ( ) ) { <nl> + case InitializerKind : : DefaultArgument : { <nl> + auto argInit = cast < DefaultArgumentInitializer > ( ctx ) ; <nl> + return appendDefaultArgumentEntity ( ctx - > getParent ( ) , argInit - > getIndex ( ) ) ; <nl> + } <nl> + <nl> + case InitializerKind : : PatternBinding : { <nl> + auto patternInit = cast < PatternBindingInitializer > ( ctx ) ; <nl> + auto var = findFirstVariable ( patternInit - > getBinding ( ) ) ; <nl> + return appendInitializerEntity ( var ) ; <nl> + } <nl> + } <nl> + llvm_unreachable ( " bad initializer kind " ) ; <nl> + <nl> + case DeclContextKind : : TopLevelCodeDecl : <nl> + / / Mangle the containing module context . <nl> + return appendContext ( ctx - > getParent ( ) ) ; <nl> + } <nl> + <nl> + llvm_unreachable ( " bad decl context " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendModule ( const Module * module ) { <nl> + assert ( ! module - > getParent ( ) & & " cannot mangle nested modules ! " ) ; <nl> + <nl> + / / Try the special ' swift ' substitution . <nl> + if ( module - > isStdlibModule ( ) ) <nl> + return appendOperator ( " s " ) ; <nl> + <nl> + StringRef ModName = module - > getName ( ) . str ( ) ; <nl> + if ( ModName = = MANGLING_MODULE_OBJC ) <nl> + return appendOperator ( " So " ) ; <nl> + if ( ModName = = MANGLING_MODULE_C ) <nl> + return appendOperator ( " SC " ) ; <nl> + <nl> + appendIdentifier ( ModName ) ; <nl> + } <nl> + <nl> + / / / Mangle the name of a protocol as a substitution candidate . <nl> + void ASTMangler : : appendProtocolName ( const ProtocolDecl * protocol ) { <nl> + appendContextOf ( protocol ) ; <nl> + appendDeclName ( protocol ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendNominalType ( const NominalTypeDecl * decl ) { <nl> + / / Check for certain standard types . <nl> + if ( tryAppendStandardSubstitution ( decl ) ) <nl> + return ; <nl> + <nl> + / / For generic types , this uses the unbound type . <nl> + TypeBase * key = decl - > getDeclaredType ( ) . getPointer ( ) ; <nl> + <nl> + / / Try to mangle the entire name as a substitution . <nl> + if ( tryMangleSubstitution ( key ) ) <nl> + return ; <nl> + <nl> + appendContextOf ( decl ) ; <nl> + appendDeclName ( decl ) ; <nl> + <nl> + switch ( decl - > getKind ( ) ) { <nl> + # define NOMINAL_TYPE_DECL ( id , parent ) <nl> + # define DECL ( id , parent ) \ <nl> + case DeclKind : : id : <nl> + # include " swift / AST / DeclNodes . def " <nl> + llvm_unreachable ( " not a nominal type " ) ; <nl> + <nl> + case DeclKind : : Protocol : <nl> + appendOperator ( " P " ) ; <nl> + break ; <nl> + case DeclKind : : Class : <nl> + appendOperator ( " C " ) ; <nl> + break ; <nl> + case DeclKind : : Enum : <nl> + appendOperator ( " O " ) ; <nl> + break ; <nl> + case DeclKind : : Struct : <nl> + appendOperator ( " V " ) ; <nl> + break ; <nl> + } <nl> + addSubstitution ( key ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendFunctionType ( AnyFunctionType * fn ) { <nl> + assert ( ( DWARFMangling | | fn - > isCanonical ( ) ) & & <nl> + " expecting canonical types when not mangling for the debugger " ) ; <nl> + <nl> + appendFunctionSignature ( fn ) ; <nl> + <nl> + / / Note that we do not currently use thin representations in the AST <nl> + / / for the types of function decls . This may need to change at some <nl> + / / point , in which case the uncurry logic can probably migrate to that <nl> + / / case . <nl> + / / <nl> + / / It would have been cleverer if we ' d used ' f ' for thin functions <nl> + / / and something else for uncurried functions , but oh well . <nl> + / / <nl> + / / Or maybe we can change the mangling at the same time we make <nl> + / / changes to better support thin functions . <nl> + switch ( fn - > getRepresentation ( ) ) { <nl> + case AnyFunctionType : : Representation : : Block : <nl> + return appendOperator ( " XB " ) ; <nl> + case AnyFunctionType : : Representation : : Thin : <nl> + return appendOperator ( " Xf " ) ; <nl> + case AnyFunctionType : : Representation : : Swift : <nl> + if ( fn - > isAutoClosure ( ) ) <nl> + return appendOperator ( " XK " ) ; <nl> + return appendOperator ( " c " ) ; <nl> + <nl> + case AnyFunctionType : : Representation : : CFunctionPointer : <nl> + return appendOperator ( " XC " ) ; <nl> + } <nl> + } <nl> + <nl> + void ASTMangler : : appendFunctionSignature ( AnyFunctionType * fn ) { <nl> + appendParams ( fn - > getResult ( ) ) ; <nl> + appendParams ( fn - > getInput ( ) ) ; <nl> + if ( fn - > throws ( ) ) <nl> + appendOperator ( " K " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendParams ( Type ParamsTy ) { <nl> + TupleType * Tuple = ParamsTy - > getAs < TupleType > ( ) ; <nl> + if ( Tuple & & Tuple - > getNumElements ( ) = = 0 ) { <nl> + appendOperator ( " y " ) ; <nl> + } else { <nl> + appendType ( ParamsTy ) ; <nl> + } <nl> + } <nl> + <nl> + void ASTMangler : : appendTypeList ( Type listTy ) { <nl> + if ( TupleType * tuple = listTy - > getAs < TupleType > ( ) ) { <nl> + if ( tuple - > getNumElements ( ) = = 0 ) <nl> + return appendOperator ( " y " ) ; <nl> + bool firstField = true ; <nl> + for ( auto & field : tuple - > getElements ( ) ) { <nl> + appendType ( field . getType ( ) ) ; <nl> + if ( field . hasName ( ) ) <nl> + appendIdentifier ( field . getName ( ) . str ( ) ) ; <nl> + appendListSeparator ( firstField ) ; <nl> + } <nl> + if ( tuple - > getElements ( ) . back ( ) . isVararg ( ) ) <nl> + return appendOperator ( " d " ) ; <nl> + } else { <nl> + appendType ( listTy ) ; <nl> + appendListSeparator ( ) ; <nl> + } <nl> + } <nl> + <nl> + void ASTMangler : : appendGenericSignature ( const GenericSignature * sig ) { <nl> + auto canSig = sig - > getCanonicalSignature ( ) ; <nl> + CurGenericSignature = canSig ; <nl> + appendGenericSignatureParts ( canSig - > getGenericParams ( ) , 0 , <nl> + canSig - > getRequirements ( ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendRequirement ( const Requirement & reqt ) { <nl> + <nl> + Type FirstTy = reqt . getFirstType ( ) - > getCanonicalType ( ) ; <nl> + Type SecondTy = reqt . getSecondType ( ) ; <nl> + <nl> + switch ( reqt . getKind ( ) ) { <nl> + case RequirementKind : : Conformance : <nl> + appendProtocolName ( SecondTy - > castTo < ProtocolType > ( ) - > getDecl ( ) ) ; <nl> + break ; <nl> + case RequirementKind : : Superclass : <nl> + case RequirementKind : : SameType : <nl> + appendType ( SecondTy - > getCanonicalType ( ) ) ; <nl> + break ; <nl> + } <nl> + <nl> + if ( auto * DT = FirstTy - > getAs < DependentMemberType > ( ) ) { <nl> + bool isAssocTypeAtDepth = false ; <nl> + if ( tryMangleSubstitution ( DT ) ) { <nl> + switch ( reqt . getKind ( ) ) { <nl> + case RequirementKind : : Conformance : <nl> + return appendOperator ( " RQ " ) ; <nl> + case RequirementKind : : Superclass : <nl> + return appendOperator ( " RB " ) ; <nl> + case RequirementKind : : SameType : <nl> + return appendOperator ( " RS " ) ; <nl> + } <nl> + llvm_unreachable ( " bad requirement type " ) ; <nl> + } <nl> + GenericTypeParamType * gpBase = appendAssocType ( DT , isAssocTypeAtDepth ) ; <nl> + addSubstitution ( DT ) ; <nl> + assert ( gpBase ) ; <nl> + switch ( reqt . getKind ( ) ) { <nl> + case RequirementKind : : Conformance : <nl> + return appendOpWithGenericParamIndex ( isAssocTypeAtDepth ? " RP " : " Rp " , <nl> + gpBase ) ; <nl> + case RequirementKind : : Superclass : <nl> + return appendOpWithGenericParamIndex ( isAssocTypeAtDepth ? " RC " : " Rc " , <nl> + gpBase ) ; <nl> + case RequirementKind : : SameType : <nl> + return appendOpWithGenericParamIndex ( isAssocTypeAtDepth ? " RT " : " Rt " , <nl> + gpBase ) ; <nl> + } <nl> + llvm_unreachable ( " bad requirement type " ) ; <nl> + } <nl> + GenericTypeParamType * gpBase = FirstTy - > castTo < GenericTypeParamType > ( ) ; <nl> + switch ( reqt . getKind ( ) ) { <nl> + case RequirementKind : : Conformance : <nl> + return appendOpWithGenericParamIndex ( " R " , gpBase ) ; <nl> + case RequirementKind : : Superclass : <nl> + return appendOpWithGenericParamIndex ( " Rb " , gpBase ) ; <nl> + case RequirementKind : : SameType : <nl> + return appendOpWithGenericParamIndex ( " Rs " , gpBase ) ; <nl> + } <nl> + llvm_unreachable ( " bad requirement type " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendGenericSignatureParts ( <nl> + ArrayRef < GenericTypeParamType * > params , <nl> + unsigned initialParamDepth , <nl> + ArrayRef < Requirement > requirements ) { <nl> + / / Mangle the requirements . <nl> + for ( const Requirement & reqt : requirements ) { <nl> + appendRequirement ( reqt ) ; <nl> + } <nl> + <nl> + if ( params . size ( ) = = 1 & & params [ 0 ] - > getDepth ( ) = = initialParamDepth ) <nl> + return appendOperator ( " l " ) ; <nl> + <nl> + llvm : : SmallVector < char , 16 > OpStorage ; <nl> + llvm : : raw_svector_ostream OpBuffer ( OpStorage ) ; <nl> + <nl> + / / Mangle the number of parameters . <nl> + unsigned depth = 0 ; <nl> + unsigned count = 0 ; <nl> + <nl> + / / Since it ' s unlikely ( but not impossible ) to have zero generic parameters <nl> + / / at a depth , encode indexes starting from 1 , and use a special mangling <nl> + / / for zero . <nl> + auto mangleGenericParamCount = [ & ] ( unsigned depth , unsigned count ) { <nl> + if ( depth < initialParamDepth ) <nl> + return ; <nl> + if ( count = = 0 ) <nl> + OpBuffer < < ' z ' ; <nl> + else <nl> + OpBuffer < < Index ( count - 1 ) ; <nl> + } ; <nl> + <nl> + / / As a special case , mangle nothing if there ' s a single generic parameter <nl> + / / at the initial depth . <nl> + for ( auto param : params ) { <nl> + if ( param - > getDepth ( ) ! = depth ) { <nl> + assert ( param - > getDepth ( ) > depth & & " generic params not ordered " ) ; <nl> + while ( depth < param - > getDepth ( ) ) { <nl> + mangleGenericParamCount ( depth , count ) ; <nl> + + + depth ; <nl> + count = 0 ; <nl> + } <nl> + } <nl> + assert ( param - > getIndex ( ) = = count & & " generic params not ordered " ) ; <nl> + + + count ; <nl> + } <nl> + mangleGenericParamCount ( depth , count ) ; <nl> + OpBuffer < < ' l ' ; <nl> + <nl> + appendOperator ( " r " , StringRef ( OpStorage . data ( ) , OpStorage . size ( ) ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendAssociatedTypeName ( DependentMemberType * dmt ) { <nl> + auto assocTy = dmt - > getAssocType ( ) ; <nl> + <nl> + / / If the base type is known to have a single protocol conformance <nl> + / / in the current generic context , then we don ' t need to disambiguate the <nl> + / / associated type name by protocol . <nl> + / / FIXME : We ought to be able to get to the generic signature from a <nl> + / / dependent type , but can ' t yet . Shouldn ' t need this side channel . <nl> + <nl> + appendIdentifier ( assocTy - > getName ( ) . str ( ) ) ; <nl> + if ( ! OptimizeProtocolNames | | ! CurGenericSignature | | ! Mod <nl> + | | CurGenericSignature - > getConformsTo ( dmt - > getBase ( ) , * Mod ) . size ( ) > 1 ) { <nl> + appendNominalType ( assocTy - > getProtocol ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + void ASTMangler : : appendClosureEntity ( <nl> + const SerializedAbstractClosureExpr * closure ) { <nl> + appendClosureComponents ( closure - > getType ( ) , closure - > getDiscriminator ( ) , <nl> + closure - > isImplicit ( ) , closure - > getParent ( ) , <nl> + closure - > getLocalContext ( ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendClosureEntity ( const AbstractClosureExpr * closure ) { <nl> + appendClosureComponents ( closure - > getType ( ) , closure - > getDiscriminator ( ) , <nl> + isa < AutoClosureExpr > ( closure ) , closure - > getParent ( ) , <nl> + closure - > getLocalContext ( ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendClosureComponents ( Type Ty , unsigned discriminator , <nl> + bool isImplicit , <nl> + const DeclContext * parentContext , <nl> + const DeclContext * localContext ) { <nl> + if ( ! DeclCtx ) DeclCtx = localContext ; <nl> + <nl> + assert ( discriminator ! = AbstractClosureExpr : : InvalidDiscriminator <nl> + & & " closure must be marked correctly with discriminator " ) ; <nl> + <nl> + appendContext ( parentContext ) ; <nl> + <nl> + if ( ! Ty ) <nl> + Ty = ErrorType : : get ( localContext - > getASTContext ( ) ) ; <nl> + <nl> + Ty = ArchetypeBuilder : : mapTypeOutOfContext ( parentContext , Ty ) ; <nl> + appendType ( Ty - > getCanonicalType ( ) ) ; <nl> + appendOperator ( isImplicit ? " fu " : " fU " , Index ( discriminator ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendDefaultArgumentEntity ( const DeclContext * func , <nl> + unsigned index ) { <nl> + appendContext ( func ) ; <nl> + appendOperator ( " fA " , Index ( index ) ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendInitializerEntity ( const VarDecl * var ) { <nl> + appendEntity ( var , " v " , var - > isStatic ( ) ) ; <nl> + appendOperator ( " fi " ) ; <nl> + } <nl> + <nl> + / / / Is this declaration a method for mangling purposes ? If so , we ' ll leave the <nl> + / / / Self type out of its mangling . <nl> + static bool isMethodDecl ( const Decl * decl ) { <nl> + return isa < AbstractFunctionDecl > ( decl ) <nl> + & & ( isa < NominalTypeDecl > ( decl - > getDeclContext ( ) ) <nl> + | | isa < ExtensionDecl > ( decl - > getDeclContext ( ) ) ) ; <nl> + } <nl> + <nl> + static bool genericParamIsBelowDepth ( Type type , unsigned methodDepth ) { <nl> + if ( auto gp = type - > getAs < GenericTypeParamType > ( ) ) { <nl> + return gp - > getDepth ( ) > = methodDepth ; <nl> + } <nl> + if ( auto dm = type - > getAs < DependentMemberType > ( ) ) { <nl> + return genericParamIsBelowDepth ( dm - > getBase ( ) , methodDepth ) ; <nl> + } <nl> + / / Non - dependent types in a same - type requirement don ' t affect whether we <nl> + / / mangle the requirement . <nl> + return false ; <nl> + } <nl> + <nl> + Type ASTMangler : : getDeclTypeForMangling ( const ValueDecl * decl , <nl> + ArrayRef < GenericTypeParamType * > & genericParams , <nl> + unsigned & initialParamDepth , <nl> + ArrayRef < Requirement > & requirements , <nl> + SmallVectorImpl < Requirement > & requirementsBuf ) { <nl> + auto & C = decl - > getASTContext ( ) ; <nl> + if ( ! decl - > hasInterfaceType ( ) ) <nl> + return ErrorType : : get ( C ) - > getCanonicalType ( ) ; <nl> + <nl> + / / FIXME : Interface types for ParamDecls <nl> + Type type = decl - > getInterfaceType ( ) ; <nl> + if ( type - > hasArchetype ( ) ) { <nl> + assert ( isa < ParamDecl > ( decl ) ) ; <nl> + type = ArchetypeBuilder : : mapTypeOutOfContext ( <nl> + decl - > getDeclContext ( ) , type ) ; <nl> + } <nl> + <nl> + initialParamDepth = 0 ; <nl> + CanGenericSignature sig ; <nl> + if ( auto gft = type - > getAs < GenericFunctionType > ( ) ) { <nl> + sig = gft - > getGenericSignature ( ) - > getCanonicalSignature ( ) ; <nl> + CurGenericSignature = sig ; <nl> + genericParams = sig - > getGenericParams ( ) ; <nl> + requirements = sig - > getRequirements ( ) ; <nl> + <nl> + type = FunctionType : : get ( gft - > getInput ( ) , gft - > getResult ( ) , <nl> + gft - > getExtInfo ( ) ) ; <nl> + } else { <nl> + genericParams = { } ; <nl> + requirements = { } ; <nl> + } <nl> + <nl> + / / Shed the ' self ' type and generic requirements from method manglings . <nl> + if ( isMethodDecl ( decl ) & & type & & ! type - > hasError ( ) ) { <nl> + / / Drop the Self argument clause from the type . <nl> + type = type - > castTo < AnyFunctionType > ( ) - > getResult ( ) ; <nl> + <nl> + / / Drop generic parameters and requirements from the method ' s context . <nl> + if ( auto parentGenericSig = <nl> + decl - > getDeclContext ( ) - > getGenericSignatureOfContext ( ) ) { <nl> + / / The method ' s depth starts below the depth of the context . <nl> + if ( ! parentGenericSig - > getGenericParams ( ) . empty ( ) ) <nl> + initialParamDepth = <nl> + parentGenericSig - > getGenericParams ( ) . back ( ) - > getDepth ( ) + 1 ; <nl> + <nl> + while ( ! genericParams . empty ( ) ) { <nl> + if ( genericParams . front ( ) - > getDepth ( ) > = initialParamDepth ) <nl> + break ; <nl> + genericParams = genericParams . slice ( 1 ) ; <nl> + } <nl> + <nl> + requirementsBuf . clear ( ) ; <nl> + for ( auto & reqt : sig - > getRequirements ( ) ) { <nl> + switch ( reqt . getKind ( ) ) { <nl> + case RequirementKind : : Conformance : <nl> + case RequirementKind : : Superclass : <nl> + / / We don ' t need the requirement if the constrained type is above the <nl> + / / method depth . <nl> + if ( ! genericParamIsBelowDepth ( reqt . getFirstType ( ) , initialParamDepth ) ) <nl> + continue ; <nl> + break ; <nl> + case RequirementKind : : SameType : <nl> + / / We don ' t need the requirement if both types are above the method <nl> + / / depth , or non - dependent . <nl> + if ( ! genericParamIsBelowDepth ( reqt . getFirstType ( ) , initialParamDepth ) & & <nl> + ! genericParamIsBelowDepth ( reqt . getSecondType ( ) , initialParamDepth ) ) <nl> + continue ; <nl> + break ; <nl> + } <nl> + <nl> + / / If we fell through the switch , mangle the requirement . <nl> + requirementsBuf . push_back ( reqt ) ; <nl> + } <nl> + requirements = requirementsBuf ; <nl> + } <nl> + } <nl> + return type - > getCanonicalType ( ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendDeclType ( const ValueDecl * decl ) { <nl> + ArrayRef < GenericTypeParamType * > genericParams ; <nl> + unsigned initialParamDepth ; <nl> + ArrayRef < Requirement > requirements ; <nl> + SmallVector < Requirement , 4 > requirementsBuf ; <nl> + Mod = decl - > getModuleContext ( ) ; <nl> + Type type = getDeclTypeForMangling ( decl , <nl> + genericParams , initialParamDepth , <nl> + requirements , requirementsBuf ) ; <nl> + appendType ( type ) ; <nl> + <nl> + / / Mangle the generic signature , if any . <nl> + if ( ! genericParams . empty ( ) | | ! requirements . empty ( ) ) { <nl> + appendGenericSignatureParts ( genericParams , initialParamDepth , <nl> + requirements ) ; <nl> + appendOperator ( " u " ) ; <nl> + } <nl> + } <nl> + <nl> + bool ASTMangler : : tryAppendStandardSubstitution ( const NominalTypeDecl * decl ) { <nl> + / / Bail out if our parent isn ' t the swift standard library . <nl> + DeclContext * dc = decl - > getDeclContext ( ) ; <nl> + if ( ! dc - > isModuleScopeContext ( ) | | ! dc - > getParentModule ( ) - > isStdlibModule ( ) ) <nl> + return false ; <nl> + <nl> + StringRef name = decl - > getName ( ) . str ( ) ; <nl> + if ( name = = " Int " ) { <nl> + appendOperator ( " Si " ) ; <nl> + return true ; <nl> + } else if ( name = = " UInt " ) { <nl> + appendOperator ( " Su " ) ; <nl> + return true ; <nl> + } else if ( name = = " Bool " ) { <nl> + appendOperator ( " Sb " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnicodeScalar " ) { <nl> + appendOperator ( " Sc " ) ; <nl> + return true ; <nl> + } else if ( name = = " Double " ) { <nl> + appendOperator ( " Sd " ) ; <nl> + return true ; <nl> + } else if ( name = = " Float " ) { <nl> + appendOperator ( " Sf " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafeRawPointer " ) { <nl> + appendOperator ( " SV " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafeMutableRawPointer " ) { <nl> + appendOperator ( " Sv " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafePointer " ) { <nl> + appendOperator ( " SP " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafeMutablePointer " ) { <nl> + appendOperator ( " Sp " ) ; <nl> + return true ; <nl> + } else if ( name = = " Optional " ) { <nl> + appendOperator ( " Sq " ) ; <nl> + return true ; <nl> + } else if ( name = = " ImplicitlyUnwrappedOptional " ) { <nl> + appendOperator ( " SQ " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafeBufferPointer " ) { <nl> + appendOperator ( " SR " ) ; <nl> + return true ; <nl> + } else if ( name = = " UnsafeMutableBufferPointer " ) { <nl> + appendOperator ( " Sr " ) ; <nl> + return true ; <nl> + } else if ( name = = " Array " ) { <nl> + appendOperator ( " Sa " ) ; <nl> + return true ; <nl> + } else if ( name = = " String " ) { <nl> + appendOperator ( " SS " ) ; <nl> + return true ; <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> + void ASTMangler : : appendConstructorEntity ( const ConstructorDecl * ctor , <nl> + bool isAllocating ) { <nl> + appendContextOf ( ctor ) ; <nl> + appendDeclType ( ctor ) ; <nl> + appendOperator ( isAllocating ? " fC " : " fc " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendDestructorEntity ( const DestructorDecl * dtor , <nl> + bool isDeallocating ) { <nl> + appendContextOf ( dtor ) ; <nl> + appendOperator ( isDeallocating ? " fD " : " fd " ) ; <nl> + } <nl> + <nl> + static StringRef getCodeForAccessorKind ( AccessorKind kind , <nl> + AddressorKind addressorKind ) { <nl> + switch ( kind ) { <nl> + case AccessorKind : : NotAccessor : llvm_unreachable ( " bad accessor kind ! " ) ; <nl> + case AccessorKind : : IsGetter : return " g " ; <nl> + case AccessorKind : : IsSetter : return " s " ; <nl> + case AccessorKind : : IsWillSet : return " w " ; <nl> + case AccessorKind : : IsDidSet : return " W " ; <nl> + case AccessorKind : : IsAddressor : <nl> + / / ' l ' is for location . ' A ' was taken . <nl> + switch ( addressorKind ) { <nl> + case AddressorKind : : NotAddressor : llvm_unreachable ( " bad combo " ) ; <nl> + case AddressorKind : : Unsafe : return " lu " ; <nl> + case AddressorKind : : Owning : return " lO " ; <nl> + case AddressorKind : : NativeOwning : return " lo " ; <nl> + case AddressorKind : : NativePinning : return " lp " ; <nl> + } <nl> + llvm_unreachable ( " bad addressor kind " ) ; <nl> + case AccessorKind : : IsMutableAddressor : <nl> + switch ( addressorKind ) { <nl> + case AddressorKind : : NotAddressor : llvm_unreachable ( " bad combo " ) ; <nl> + case AddressorKind : : Unsafe : return " au " ; <nl> + case AddressorKind : : Owning : return " aO " ; <nl> + case AddressorKind : : NativeOwning : return " ao " ; <nl> + case AddressorKind : : NativePinning : return " aP " ; <nl> + } <nl> + llvm_unreachable ( " bad addressor kind " ) ; <nl> + case AccessorKind : : IsMaterializeForSet : return " m " ; <nl> + } <nl> + llvm_unreachable ( " bad accessor kind " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendAccessorEntity ( AccessorKind kind , <nl> + AddressorKind addressorKind , <nl> + const ValueDecl * decl , <nl> + bool isStatic ) { <nl> + assert ( kind ! = AccessorKind : : NotAccessor ) ; <nl> + appendContextOf ( decl ) ; <nl> + bindGenericParameters ( decl - > getDeclContext ( ) ) ; <nl> + appendDeclName ( decl ) ; <nl> + appendDeclType ( decl ) ; <nl> + appendOperator ( " f " , getCodeForAccessorKind ( kind , addressorKind ) ) ; <nl> + if ( isStatic ) <nl> + appendOperator ( " Z " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendEntity ( const ValueDecl * decl , StringRef EntityOp , <nl> + bool isStatic ) { <nl> + if ( ! DeclCtx ) DeclCtx = decl - > getInnermostDeclContext ( ) ; <nl> + appendContextOf ( decl ) ; <nl> + appendDeclName ( decl ) ; <nl> + appendDeclType ( decl ) ; <nl> + appendOperator ( EntityOp ) ; <nl> + if ( isStatic ) <nl> + appendOperator ( " Z " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendEntity ( const ValueDecl * decl ) { <nl> + if ( ! DeclCtx ) DeclCtx = decl - > getInnermostDeclContext ( ) ; <nl> + assert ( ! isa < ConstructorDecl > ( decl ) ) ; <nl> + assert ( ! isa < DestructorDecl > ( decl ) ) ; <nl> + <nl> + / / Handle accessors specially , they are mangled as modifiers on the accessed <nl> + / / declaration . <nl> + if ( auto func = dyn_cast < FuncDecl > ( decl ) ) { <nl> + auto accessorKind = func - > getAccessorKind ( ) ; <nl> + if ( accessorKind ! = AccessorKind : : NotAccessor ) <nl> + return appendAccessorEntity ( accessorKind , func - > getAddressorKind ( ) , <nl> + func - > getAccessorStorageDecl ( ) , <nl> + decl - > isStatic ( ) ) ; <nl> + } <nl> + <nl> + if ( isa < VarDecl > ( decl ) ) <nl> + return appendEntity ( decl , " v " , decl - > isStatic ( ) ) ; <nl> + if ( isa < SubscriptDecl > ( decl ) ) <nl> + return appendEntity ( decl , " i " , decl - > isStatic ( ) ) ; <nl> + if ( isa < GenericTypeParamDecl > ( decl ) ) <nl> + return appendEntity ( decl , " fp " , decl - > isStatic ( ) ) ; <nl> + <nl> + assert ( isa < AbstractFunctionDecl > ( decl ) | | isa < EnumElementDecl > ( decl ) ) ; <nl> + <nl> + appendContextOf ( decl ) ; <nl> + appendDeclName ( decl ) ; <nl> + <nl> + ArrayRef < GenericTypeParamType * > genericParams ; <nl> + unsigned initialParamDepth ; <nl> + ArrayRef < Requirement > requirements ; <nl> + SmallVector < Requirement , 4 > requirementsBuf ; <nl> + Mod = decl - > getModuleContext ( ) ; <nl> + Type type = getDeclTypeForMangling ( decl , <nl> + genericParams , initialParamDepth , <nl> + requirements , requirementsBuf ) ; <nl> + <nl> + if ( AnyFunctionType * FuncTy = type - > getAs < AnyFunctionType > ( ) ) { <nl> + appendFunctionSignature ( FuncTy ) ; <nl> + } else { <nl> + / / In case SourceKit comes up with an invalid ( Error ) function type . <nl> + appendType ( type ) ; <nl> + } <nl> + <nl> + / / Mangle the generic signature , if any . <nl> + if ( ! genericParams . empty ( ) | | ! requirements . empty ( ) ) { <nl> + appendGenericSignatureParts ( genericParams , initialParamDepth , <nl> + requirements ) ; <nl> + } <nl> + appendOperator ( " F " ) ; <nl> + if ( decl - > isStatic ( ) ) <nl> + appendOperator ( " Z " ) ; <nl> + } <nl> + <nl> + void ASTMangler : : appendProtocolConformance ( const ProtocolConformance * conformance ) { <nl> + Mod = conformance - > getDeclContext ( ) - > getParentModule ( ) ; <nl> + if ( auto behaviorStorage = conformance - > getBehaviorDecl ( ) ) { <nl> + auto topLevelContext = <nl> + conformance - > getDeclContext ( ) - > getModuleScopeContext ( ) ; <nl> + appendContextOf ( behaviorStorage ) ; <nl> + FileUnit * fileUnit = cast < FileUnit > ( topLevelContext ) ; <nl> + appendIdentifier ( <nl> + fileUnit - > getDiscriminatorForPrivateValue ( behaviorStorage ) . str ( ) ) ; <nl> + appendProtocolName ( conformance - > getProtocol ( ) ) ; <nl> + appendIdentifier ( behaviorStorage - > getName ( ) . str ( ) ) ; <nl> + } else { <nl> + appendType ( conformance - > getInterfaceType ( ) - > getCanonicalType ( ) ) ; <nl> + appendProtocolName ( conformance - > getProtocol ( ) ) ; <nl> + appendModule ( conformance - > getDeclContext ( ) - > getParentModule ( ) ) ; <nl> + } <nl> + if ( GenericSignature * Sig = conformance - > getGenericSignature ( ) ) { <nl> + appendGenericSignature ( Sig ) ; <nl> + } <nl> + } <nl> mmm a / lib / AST / CMakeLists . txt <nl> ppp b / lib / AST / CMakeLists . txt <nl> add_swift_library ( swiftAST STATIC <nl> ArchetypeBuilder . cpp <nl> ASTContext . cpp <nl> ASTDumper . cpp <nl> + ASTMangler . cpp <nl> ASTNode . cpp <nl> ASTPrinter . cpp <nl> ASTScope . cpp <nl> mmm a / lib / Basic / CMakeLists . txt <nl> ppp b / lib / Basic / CMakeLists . txt <nl> add_swift_library ( swiftBasic STATIC <nl> Cache . cpp <nl> ClusteredBitVector . cpp <nl> Demangle . cpp <nl> + Demangler . cpp <nl> DemangleWrappers . cpp <nl> DiagnosticConsumer . cpp <nl> DiverseStack . cpp <nl> add_swift_library ( swiftBasic STATIC <nl> JSONSerialization . cpp <nl> LangOptions . cpp <nl> LLVMContext . cpp <nl> + Mangler . cpp <nl> + ManglingUtils . cpp <nl> Platform . cpp <nl> PrefixMap . cpp <nl> PrettyStackTrace . cpp <nl> add_swift_library ( swiftBasic STATIC <nl> PunycodeUTF8 . cpp <nl> QuotedString . cpp <nl> Remangle . cpp <nl> + Remangler . cpp <nl> SourceLoc . cpp <nl> StringExtras . cpp <nl> TaskQueue . cpp <nl> mmm a / lib / Basic / Demangle . cpp <nl> ppp b / lib / Basic / Demangle . cpp <nl> class NodePrinter { <nl> case Node : : Kind : : AutoClosureType : <nl> case Node : : Kind : : CFunctionPointer : <nl> case Node : : Kind : : Constructor : <nl> + case Node : : Kind : : CurryThunk : <nl> case Node : : Kind : : Deallocator : <nl> case Node : : Kind : : DeclContext : <nl> case Node : : Kind : : DefaultArgumentInitializer : <nl> class NodePrinter { <nl> case Node : : Kind : : Weak : <nl> case Node : : Kind : : WillSet : <nl> case Node : : Kind : : WitnessTableOffset : <nl> + case Node : : Kind : : ReflectionMetadataBuiltinDescriptor : <nl> + case Node : : Kind : : ReflectionMetadataFieldDescriptor : <nl> + case Node : : Kind : : ReflectionMetadataAssocTypeDescriptor : <nl> + case Node : : Kind : : ReflectionMetadataSuperclassDescriptor : <nl> case Node : : Kind : : ThrowsAnnotation : <nl> + case Node : : Kind : : EmptyList : <nl> + case Node : : Kind : : FirstElementMarker : <nl> + case Node : : Kind : : VariadicMarker : <nl> return false ; <nl> } <nl> unreachable ( " bad node kind " ) ; <nl> void NodePrinter : : print ( NodePointer pointer , bool asContext , bool suppressType ) <nl> Printer < < " static " ; <nl> print ( pointer - > getChild ( 0 ) , asContext , suppressType ) ; <nl> return ; <nl> + case Node : : Kind : : CurryThunk : <nl> + Printer < < " curry thunk of " ; <nl> + print ( pointer - > getChild ( 0 ) , asContext , suppressType ) ; <nl> + return ; <nl> case Node : : Kind : : Directness : <nl> Printer < < toString ( Directness ( pointer - > getIndex ( ) ) ) < < " " ; <nl> return ; <nl> void NodePrinter : : print ( NodePointer pointer , bool asContext , bool suppressType ) <nl> Printer < < pointer - > getText ( ) ; <nl> return ; <nl> } <nl> - case Node : : Kind : : ThrowsAnnotation : { <nl> + case Node : : Kind : : ReflectionMetadataBuiltinDescriptor : <nl> + Printer < < " reflection metadata builtin descriptor " ; <nl> + print ( pointer - > getChild ( 0 ) ) ; <nl> + return ; <nl> + case Node : : Kind : : ReflectionMetadataFieldDescriptor : <nl> + Printer < < " reflection metadata field descriptor " ; <nl> + print ( pointer - > getChild ( 0 ) ) ; <nl> + return ; <nl> + case Node : : Kind : : ReflectionMetadataAssocTypeDescriptor : <nl> + Printer < < " reflection metadata associated type descriptor " ; <nl> + print ( pointer - > getChild ( 0 ) ) ; <nl> + return ; <nl> + case Node : : Kind : : ReflectionMetadataSuperclassDescriptor : <nl> + Printer < < " reflection metadata superclass descriptor " ; <nl> + print ( pointer - > getChild ( 0 ) ) ; <nl> + return ; <nl> + <nl> + case Node : : Kind : : ThrowsAnnotation : <nl> Printer < < " throws " ; <nl> return ; <nl> - } <nl> + case Node : : Kind : : EmptyList : <nl> + Printer < < " empty - list " ; <nl> + return ; <nl> + case Node : : Kind : : FirstElementMarker : <nl> + Printer < < " first - element - marker " ; <nl> + return ; <nl> + case Node : : Kind : : VariadicMarker : <nl> + Printer < < " variadic - marker " ; <nl> + return ; <nl> } <nl> unreachable ( " bad node kind ! " ) ; <nl> } <nl> new file mode 100644 <nl> index 000000000000 . . ac17dce76e4f <nl> mmm / dev / null <nl> ppp b / lib / Basic / Demangler . cpp <nl> <nl> + / / = = = mmm Demangler . cpp - String to Node - Tree Demangling mmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This file implements new Swift de - mangler . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / Basic / Demangler . h " <nl> + # include " swift / Basic / ManglingUtils . h " <nl> + # include " swift / Basic / ManglingMacros . h " <nl> + # include " swift / Basic / Punycode . h " <nl> + # include " swift / Basic / Fallthrough . h " <nl> + # include " swift / Basic / Range . h " <nl> + # include " swift / Strings . h " <nl> + # include " llvm / Support / ErrorHandling . h " <nl> + <nl> + <nl> + using namespace swift ; <nl> + using swift : : Demangle : : FunctionSigSpecializationParamKind ; <nl> + <nl> + namespace { <nl> + <nl> + static bool isDeclName ( Node : : Kind kind ) { <nl> + switch ( kind ) { <nl> + case Node : : Kind : : Identifier : <nl> + case Node : : Kind : : LocalDeclName : <nl> + case Node : : Kind : : PrivateDeclName : <nl> + case Node : : Kind : : PrefixOperator : <nl> + case Node : : Kind : : PostfixOperator : <nl> + case Node : : Kind : : InfixOperator : <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + static bool isContext ( Node : : Kind kind ) { <nl> + switch ( kind ) { <nl> + # define NODE ( ID ) <nl> + # define CONTEXT_NODE ( ID ) \ <nl> + case Node : : Kind : : ID : <nl> + # include " swift / Basic / DemangleNodes . def " <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + static bool isNominal ( Node : : Kind kind ) { <nl> + switch ( kind ) { <nl> + case Node : : Kind : : Structure : <nl> + case Node : : Kind : : Class : <nl> + case Node : : Kind : : Enum : <nl> + case Node : : Kind : : Protocol : <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + static bool isEntity ( Node : : Kind kind ) { <nl> + / / Also accepts some kind which are not entities . <nl> + if ( kind = = Node : : Kind : : Type ) <nl> + return true ; <nl> + return isContext ( kind ) ; <nl> + } <nl> + <nl> + static bool isRequirement ( Node : : Kind kind ) { <nl> + switch ( kind ) { <nl> + case Node : : Kind : : DependentGenericSameTypeRequirement : <nl> + case Node : : Kind : : DependentGenericConformanceRequirement : <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + } / / anonymous namespace <nl> + <nl> + namespace swift { <nl> + namespace NewMangling { <nl> + <nl> + NodePointer Demangler : : demangleTopLevel ( ) { <nl> + if ( ! nextIf ( MANGLING_PREFIX_STR ) ) <nl> + return nullptr ; <nl> + <nl> + NodePointer topLevel = NodeFactory : : create ( Node : : Kind : : Global ) ; <nl> + <nl> + int Idx = 0 ; <nl> + while ( ! Text . empty ( ) ) { <nl> + NodePointer Node = demangleOperator ( ) ; <nl> + if ( ! Node ) <nl> + break ; <nl> + pushNode ( Node ) ; <nl> + Idx + + ; <nl> + } <nl> + <nl> + bool beforeSpecializtions = false ; <nl> + for ( const NodeWithPos & NWP : reversed ( NodeStack ) ) { <nl> + switch ( NWP . Node - > getKind ( ) ) { <nl> + case Node : : Kind : : FunctionSignatureSpecialization : <nl> + case Node : : Kind : : GenericSpecialization : <nl> + case Node : : Kind : : GenericSpecializationNotReAbstracted : <nl> + topLevel - > addChild ( NWP . Node ) ; <nl> + beforeSpecializtions = true ; <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + for ( const NodeWithPos & NWP : NodeStack ) { <nl> + NodePointer Nd = NWP . Node ; <nl> + switch ( Nd - > getKind ( ) ) { <nl> + case Node : : Kind : : FunctionSignatureSpecialization : <nl> + case Node : : Kind : : GenericSpecialization : <nl> + case Node : : Kind : : GenericSpecializationNotReAbstracted : <nl> + beforeSpecializtions = false ; <nl> + break ; <nl> + case Node : : Kind : : Type : <nl> + topLevel - > addChild ( Nd - > getFirstChild ( ) ) ; <nl> + break ; <nl> + case Node : : Kind : : Identifier : <nl> + if ( beforeSpecializtions & & <nl> + StringRef ( Nd - > getText ( ) ) . startswith ( " _T " ) ) { <nl> + NodePointer Global = demangleSymbolAsNode ( Nd - > getText ( ) ) ; <nl> + if ( Global & & Global - > getKind ( ) = = Node : : Kind : : Global ) { <nl> + for ( NodePointer Child : * Global ) { <nl> + topLevel - > addChild ( Child ) ; <nl> + } <nl> + break ; <nl> + } <nl> + } <nl> + SWIFT_FALLTHROUGH ; <nl> + default : <nl> + topLevel - > addChild ( Nd ) ; <nl> + break ; <nl> + } <nl> + } <nl> + size_t EndPos = ( NodeStack . empty ( ) ? 0 : NodeStack . back ( ) . Pos ) ; <nl> + if ( EndPos < Text . size ( ) ) { <nl> + topLevel - > addChild ( NodeFactory : : create ( Node : : Kind : : Suffix , <nl> + Text . substr ( EndPos ) ) ) ; <nl> + } <nl> + <nl> + return topLevel ; <nl> + } <nl> + <nl> + NodePointer Demangler : : changeKind ( NodePointer Node , Node : : Kind NewKind ) { <nl> + if ( ! Node ) <nl> + return nullptr ; <nl> + NodePointer NewNode ; <nl> + if ( Node - > hasText ( ) ) { <nl> + NewNode = NodeFactory : : create ( NewKind , Node - > getText ( ) ) ; <nl> + } else if ( Node - > hasIndex ( ) ) { <nl> + NewNode = NodeFactory : : create ( NewKind , Node - > getIndex ( ) ) ; <nl> + } else { <nl> + NewNode = NodeFactory : : create ( NewKind ) ; <nl> + } <nl> + for ( NodePointer Child : * Node ) { <nl> + NewNode - > addChild ( Child ) ; <nl> + } <nl> + return NewNode ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleOperator ( ) { <nl> + switch ( char c = nextChar ( ) ) { <nl> + case ' A ' : return demangleMultiSubstitutions ( ) ; <nl> + case ' B ' : return demangleBuiltinType ( ) ; <nl> + case ' C ' : return demangleNominalType ( Node : : Kind : : Class ) ; <nl> + case ' E ' : return demangleExtensionContext ( ) ; <nl> + case ' F ' : return demanglePlainFunction ( ) ; <nl> + case ' G ' : return demangleBoundGenericType ( ) ; <nl> + case ' I ' : return demangleImplFunctionType ( ) ; <nl> + case ' K ' : return NodeFactory : : create ( Node : : Kind : : ThrowsAnnotation ) ; <nl> + case ' L ' : return demangleLocalIdentifier ( ) ; <nl> + case ' M ' : return demangleMetatype ( ) ; <nl> + case ' N ' : return createWithChild ( Node : : Kind : : TypeMetadata , <nl> + popNode ( Node : : Kind : : Type ) ) ; <nl> + case ' O ' : return demangleNominalType ( Node : : Kind : : Enum ) ; <nl> + case ' P ' : return demangleNominalType ( Node : : Kind : : Protocol ) ; <nl> + case ' Q ' : return demangleArchetype ( ) ; <nl> + case ' R ' : return demangleGenericRequirement ( ) ; <nl> + case ' S ' : return demangleKnownType ( ) ; <nl> + case ' T ' : return demangleThunkOrSpecialization ( ) ; <nl> + case ' V ' : return demangleNominalType ( Node : : Kind : : Structure ) ; <nl> + case ' W ' : return demangleWitness ( ) ; <nl> + case ' X ' : return demangleSpecialType ( ) ; <nl> + case ' Z ' : return createWithChild ( Node : : Kind : : Static , popNode ( isEntity ) ) ; <nl> + case ' a ' : return demangleTypeAlias ( ) ; <nl> + case ' c ' : return popFunctionType ( Node : : Kind : : FunctionType ) ; <nl> + case ' d ' : return NodeFactory : : create ( Node : : Kind : : VariadicMarker ) ; <nl> + case ' f ' : return demangleFunctionEntity ( ) ; <nl> + case ' i ' : return demangleEntity ( Node : : Kind : : Subscript ) ; <nl> + case ' l ' : return demangleGenericSignature ( / * hasParamCounts * / false ) ; <nl> + case ' m ' : return createType ( createWithChild ( Node : : Kind : : Metatype , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' o ' : return demangleOperatorIdentifier ( ) ; <nl> + case ' p ' : return demangleProtocolListType ( ) ; <nl> + case ' q ' : return createType ( demangleGenericParamIndex ( ) ) ; <nl> + case ' r ' : return demangleGenericSignature ( / * hasParamCounts * / true ) ; <nl> + case ' s ' : return NodeFactory : : create ( Node : : Kind : : Module , STDLIB_NAME ) ; <nl> + case ' t ' : return popTuple ( ) ; <nl> + case ' u ' : return demangleGenericType ( ) ; <nl> + case ' v ' : return demangleEntity ( Node : : Kind : : Variable ) ; <nl> + case ' w ' : return demangleValueWitness ( ) ; <nl> + case ' x ' : return createType ( getDependentGenericParamType ( 0 , 0 ) ) ; <nl> + case ' y ' : return NodeFactory : : create ( Node : : Kind : : EmptyList ) ; <nl> + case ' z ' : return createType ( createWithChild ( Node : : Kind : : InOut , <nl> + popTypeAndGetChild ( ) ) ) ; <nl> + case ' _ ' : return NodeFactory : : create ( Node : : Kind : : FirstElementMarker ) ; <nl> + default : <nl> + pushBack ( ) ; <nl> + return demangleIdentifier ( ) ; <nl> + } <nl> + } <nl> + <nl> + int Demangler : : demangleNatural ( ) { <nl> + if ( ! isDigit ( peekChar ( ) ) ) <nl> + return - 1000 ; <nl> + int num = 0 ; <nl> + while ( true ) { <nl> + char c = peekChar ( ) ; <nl> + if ( ! isDigit ( c ) ) <nl> + return num ; <nl> + int newNum = ( 10 * num ) + ( c - ' 0 ' ) ; <nl> + if ( newNum < num ) <nl> + return - 1000 ; <nl> + num = newNum ; <nl> + nextChar ( ) ; <nl> + } <nl> + } <nl> + <nl> + int Demangler : : demangleIndex ( ) { <nl> + if ( nextIf ( ' _ ' ) ) <nl> + return 0 ; <nl> + int num = demangleNatural ( ) ; <nl> + if ( num > = 0 & & nextIf ( ' _ ' ) ) <nl> + return num + 1 ; <nl> + return - 1000 ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleIndexAsNode ( ) { <nl> + int Idx = demangleIndex ( ) ; <nl> + if ( Idx > = 0 ) <nl> + return NodeFactory : : create ( Node : : Kind : : Number , Idx ) ; <nl> + return nullptr ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleMultiSubstitutions ( ) { <nl> + while ( true ) { <nl> + char c = nextChar ( ) ; <nl> + if ( isLowerLetter ( c ) ) { <nl> + unsigned Idx = c - ' a ' ; <nl> + if ( Idx > = Substitutions . size ( ) ) <nl> + return nullptr ; <nl> + pushNode ( Substitutions [ Idx ] ) ; <nl> + continue ; <nl> + } <nl> + if ( isUpperLetter ( c ) ) { <nl> + unsigned Idx = c - ' A ' ; <nl> + if ( Idx > = Substitutions . size ( ) ) <nl> + return nullptr ; <nl> + return Substitutions [ Idx ] ; <nl> + } <nl> + pushBack ( ) ; <nl> + unsigned Idx = demangleIndex ( ) + 26 ; <nl> + if ( Idx > = Substitutions . size ( ) ) <nl> + return nullptr ; <nl> + return Substitutions [ Idx ] ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : createSwiftType ( Node : : Kind typeKind , StringRef name ) { <nl> + return createType ( createWithChildren ( typeKind , <nl> + NodeFactory : : create ( Node : : Kind : : Module , STDLIB_NAME ) , <nl> + NodeFactory : : create ( Node : : Kind : : Identifier , name ) ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleKnownType ( ) { <nl> + switch ( nextChar ( ) ) { <nl> + case ' o ' : <nl> + return NodeFactory : : create ( Node : : Kind : : Module , MANGLING_MODULE_OBJC ) ; <nl> + case ' C ' : <nl> + return NodeFactory : : create ( Node : : Kind : : Module , MANGLING_MODULE_C ) ; <nl> + case ' a ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " Array " ) ; <nl> + case ' b ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " Bool " ) ; <nl> + case ' c ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnicodeScalar " ) ; <nl> + case ' d ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " Double " ) ; <nl> + case ' f ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " Float " ) ; <nl> + case ' i ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " Int " ) ; <nl> + case ' V ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafeRawPointer " ) ; <nl> + case ' v ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafeMutableRawPointer " ) ; <nl> + case ' P ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafePointer " ) ; <nl> + case ' p ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafeMutablePointer " ) ; <nl> + case ' q ' : <nl> + return createSwiftType ( Node : : Kind : : Enum , " Optional " ) ; <nl> + case ' Q ' : <nl> + return createSwiftType ( Node : : Kind : : Enum , " ImplicitlyUnwrappedOptional " ) ; <nl> + case ' R ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafeBufferPointer " ) ; <nl> + case ' r ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UnsafeMutableBufferPointer " ) ; <nl> + case ' S ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " String " ) ; <nl> + case ' u ' : <nl> + return createSwiftType ( Node : : Kind : : Structure , " UInt " ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleIdentifier ( ) { <nl> + bool hasWordSubsts = false ; <nl> + bool isPunycoded = false ; <nl> + char c = peekChar ( ) ; <nl> + if ( ! isDigit ( c ) ) <nl> + return nullptr ; <nl> + if ( c = = ' 0 ' ) { <nl> + nextChar ( ) ; <nl> + if ( peekChar ( ) = = ' 0 ' ) { <nl> + nextChar ( ) ; <nl> + isPunycoded = true ; <nl> + } else { <nl> + hasWordSubsts = true ; <nl> + } <nl> + } <nl> + std : : string Identifier ; <nl> + do { <nl> + while ( hasWordSubsts & & isLetter ( peekChar ( ) ) ) { <nl> + char c = nextChar ( ) ; <nl> + int WordIdx = 0 ; <nl> + if ( isLowerLetter ( c ) ) { <nl> + WordIdx = c - ' a ' ; <nl> + } else { <nl> + assert ( isUpperLetter ( c ) ) ; <nl> + WordIdx = c - ' A ' ; <nl> + hasWordSubsts = false ; <nl> + } <nl> + if ( WordIdx > = ( int ) Words . size ( ) ) <nl> + return nullptr ; <nl> + StringRef Slice = Words [ WordIdx ] ; <nl> + Identifier . append ( Slice . data ( ) , Slice . size ( ) ) ; <nl> + } <nl> + if ( nextIf ( ' 0 ' ) ) <nl> + break ; <nl> + int numChars = demangleNatural ( ) ; <nl> + if ( numChars < = 0 ) <nl> + return nullptr ; <nl> + if ( Pos + numChars > = Text . size ( ) ) <nl> + return nullptr ; <nl> + StringRef Slice = StringRef ( Text . data ( ) + Pos , numChars ) ; <nl> + if ( isPunycoded ) { <nl> + nextIf ( ' _ ' ) ; <nl> + if ( ! Punycode : : decodePunycodeUTF8 ( Slice , Identifier ) ) <nl> + return nullptr ; <nl> + } else { <nl> + Identifier . append ( Slice . data ( ) , Slice . size ( ) ) ; <nl> + int wordStartPos = - 1 ; <nl> + for ( int Idx = 0 , End = ( int ) Slice . size ( ) ; Idx < = End ; + + Idx ) { <nl> + char c = ( Idx < End ? Slice [ Idx ] : 0 ) ; <nl> + if ( wordStartPos > = 0 & & isWordEnd ( c , Slice [ Idx - 1 ] ) ) { <nl> + if ( Idx - wordStartPos > = 2 ) { <nl> + StringRef word ( Slice . begin ( ) + wordStartPos , Idx - wordStartPos ) ; <nl> + Words . push_back ( word ) ; <nl> + } <nl> + wordStartPos = - 1 ; <nl> + } <nl> + if ( wordStartPos < 0 & & isWordStart ( c ) ) { <nl> + wordStartPos = Idx ; <nl> + } <nl> + } <nl> + } <nl> + Pos + = numChars ; <nl> + } while ( hasWordSubsts ) ; <nl> + <nl> + if ( Identifier . empty ( ) ) <nl> + return nullptr ; <nl> + NodePointer Ident = NodeFactory : : create ( Node : : Kind : : Identifier , Identifier ) ; <nl> + addSubstitution ( Ident ) ; <nl> + return Ident ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleOperatorIdentifier ( ) { <nl> + NodePointer Ident = popNode ( Node : : Kind : : Identifier ) ; <nl> + <nl> + static const char op_char_table [ ] = " & @ / = > < * ! | + ? % - ~ ^ . " ; <nl> + <nl> + std : : string OpStr ; <nl> + OpStr . reserve ( Ident - > getText ( ) . size ( ) ) ; <nl> + for ( signed char c : Ident - > getText ( ) ) { <nl> + if ( c < 0 ) { <nl> + / / Pass through Unicode characters . <nl> + OpStr . push_back ( c ) ; <nl> + continue ; <nl> + } <nl> + if ( ! isLowerLetter ( c ) ) <nl> + return nullptr ; <nl> + char o = op_char_table [ c - ' a ' ] ; <nl> + if ( o = = ' ' ) <nl> + return nullptr ; <nl> + OpStr . push_back ( o ) ; <nl> + } <nl> + switch ( nextChar ( ) ) { <nl> + case ' i ' : return NodeFactory : : create ( Node : : Kind : : InfixOperator , OpStr ) ; <nl> + case ' p ' : return NodeFactory : : create ( Node : : Kind : : PrefixOperator , OpStr ) ; <nl> + case ' P ' : return NodeFactory : : create ( Node : : Kind : : PostfixOperator , OpStr ) ; <nl> + default : return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleLocalIdentifier ( ) { <nl> + if ( nextIf ( ' L ' ) ) { <nl> + NodePointer discriminator = popNode ( Node : : Kind : : Identifier ) ; <nl> + NodePointer name = popNode ( Node : : Kind : : Identifier ) ; <nl> + return createWithChildren ( Node : : Kind : : PrivateDeclName , discriminator , name ) ; <nl> + } <nl> + NodePointer discriminator = demangleIndexAsNode ( ) ; <nl> + NodePointer name = popNode ( Node : : Kind : : Identifier ) ; <nl> + return createWithChildren ( Node : : Kind : : LocalDeclName , discriminator , name ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popModule ( ) { <nl> + if ( NodePointer Ident = popNode ( Node : : Kind : : Identifier ) ) <nl> + return changeKind ( Ident , Node : : Kind : : Module ) ; <nl> + return popNode ( Node : : Kind : : Module ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popContext ( ) { <nl> + if ( NodePointer Mod = popModule ( ) ) <nl> + return Mod ; <nl> + <nl> + if ( NodePointer Ty = popNode ( Node : : Kind : : Type ) ) { <nl> + if ( Ty - > getNumChildren ( ) ! = 1 ) <nl> + return nullptr ; <nl> + NodePointer Child = Ty - > getFirstChild ( ) ; <nl> + if ( ! isContext ( Child - > getKind ( ) ) ) <nl> + return nullptr ; <nl> + return Child ; <nl> + } <nl> + return popNode ( isContext ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popTypeAndGetChild ( ) { <nl> + NodePointer Ty = popNode ( Node : : Kind : : Type ) ; <nl> + if ( ! Ty | | Ty - > getNumChildren ( ) ! = 1 ) <nl> + return nullptr ; <nl> + return Ty - > getFirstChild ( ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popTypeAndGetNominal ( ) { <nl> + NodePointer Child = popTypeAndGetChild ( ) ; <nl> + if ( Child & & isNominal ( Child - > getKind ( ) ) ) <nl> + return Child ; <nl> + return nullptr ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleBuiltinType ( ) { <nl> + NodePointer Ty ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' b ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . BridgeObject " ) ; <nl> + break ; <nl> + case ' B ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . UnsafeValueBuffer " ) ; <nl> + break ; <nl> + case ' f ' : { <nl> + int size = demangleIndex ( ) - 1 ; <nl> + if ( size < = 0 ) <nl> + return nullptr ; <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + std : : move ( DemanglerPrinter ( ) < < " Builtin . Float " < < size ) . str ( ) ) ; <nl> + break ; <nl> + } <nl> + case ' i ' : { <nl> + int size = demangleIndex ( ) - 1 ; <nl> + if ( size < = 0 ) <nl> + return nullptr ; <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + ( DemanglerPrinter ( ) < < " Builtin . Int " < < size ) . str ( ) ) ; <nl> + break ; <nl> + } <nl> + case ' v ' : { <nl> + int elts = demangleIndex ( ) - 1 ; <nl> + if ( elts < = 0 ) <nl> + return nullptr ; <nl> + NodePointer EltType = popTypeAndGetChild ( ) ; <nl> + if ( ! EltType | | EltType - > getKind ( ) ! = Node : : Kind : : BuiltinTypeName | | <nl> + EltType - > getText ( ) . find ( " Builtin . " ) ! = 0 ) <nl> + return nullptr ; <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + ( DemanglerPrinter ( ) < < " Builtin . Vec " < < elts < < " x " < < <nl> + EltType - > getText ( ) . substr ( sizeof ( " Builtin . " ) - 1 ) ) . str ( ) ) ; <nl> + break ; <nl> + } <nl> + case ' O ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . UnknownObject " ) ; <nl> + break ; <nl> + case ' o ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . NativeObject " ) ; <nl> + break ; <nl> + case ' p ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . RawPointer " ) ; <nl> + break ; <nl> + case ' w ' : <nl> + Ty = NodeFactory : : create ( Node : : Kind : : BuiltinTypeName , <nl> + " Builtin . Word " ) ; <nl> + break ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + return createType ( Ty ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleNominalType ( Node : : Kind kind ) { <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Ctx = popContext ( ) ; <nl> + NodePointer NTy = createType ( createWithChildren ( kind , Ctx , Name ) ) ; <nl> + addSubstitution ( NTy ) ; <nl> + return NTy ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleTypeAlias ( ) { <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Ctx = popContext ( ) ; <nl> + return createWithChildren ( Node : : Kind : : TypeAlias , Ctx , Name ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleExtensionContext ( ) { <nl> + NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ; <nl> + NodePointer Module = popModule ( ) ; <nl> + NodePointer Type = popTypeAndGetNominal ( ) ; <nl> + NodePointer Ext = createWithChildren ( Node : : Kind : : Extension , Module , Type ) ; <nl> + if ( GenSig ) <nl> + Ext = addChild ( Ext , GenSig ) ; <nl> + return Ext ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demanglePlainFunction ( ) { <nl> + NodePointer Func = NodeFactory : : create ( Node : : Kind : : Function ) ; <nl> + NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ; <nl> + NodePointer Type = popFunctionType ( Node : : Kind : : FunctionType ) ; <nl> + if ( GenSig ) { <nl> + Type = createType ( createWithChildren ( Node : : Kind : : DependentGenericType , <nl> + GenSig , Type ) ) ; <nl> + } <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Ctx = popContext ( ) ; <nl> + return createWithChildren ( Node : : Kind : : Function , Ctx , Name , Type ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popFunctionType ( Node : : Kind kind ) { <nl> + NodePointer FuncType = NodeFactory : : create ( kind ) ; <nl> + addChild ( FuncType , popNode ( Node : : Kind : : ThrowsAnnotation ) ) ; <nl> + <nl> + FuncType = addChild ( FuncType , popFunctionParams ( Node : : Kind : : ArgumentTuple ) ) ; <nl> + FuncType = addChild ( FuncType , popFunctionParams ( Node : : Kind : : ReturnType ) ) ; <nl> + return createType ( FuncType ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popFunctionParams ( Node : : Kind kind ) { <nl> + NodePointer ParamsType ; <nl> + if ( popNode ( Node : : Kind : : EmptyList ) ) { <nl> + ParamsType = createType ( NodeFactory : : create ( Node : : Kind : : NonVariadicTuple ) ) ; <nl> + } else { <nl> + ParamsType = popNode ( Node : : Kind : : Type ) ; <nl> + } <nl> + return createWithChild ( kind , ParamsType ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popTuple ( ) { <nl> + NodePointer Root = NodeFactory : : create ( popNode ( Node : : Kind : : VariadicMarker ) ? <nl> + Node : : Kind : : VariadicTuple : <nl> + Node : : Kind : : NonVariadicTuple ) ; <nl> + <nl> + if ( ! popNode ( Node : : Kind : : EmptyList ) ) { <nl> + std : : vector < NodePointer > Nodes ; <nl> + bool firstElem = false ; <nl> + do { <nl> + firstElem = ( popNode ( Node : : Kind : : FirstElementMarker ) ! = nullptr ) ; <nl> + NodePointer TupleElmt = NodeFactory : : create ( Node : : Kind : : TupleElement ) ; <nl> + if ( NodePointer Ident = popNode ( Node : : Kind : : Identifier ) ) { <nl> + TupleElmt - > addChild ( NodeFactory : : create ( Node : : Kind : : TupleElementName , <nl> + Ident - > getText ( ) ) ) ; <nl> + } <nl> + NodePointer Ty = popNode ( Node : : Kind : : Type ) ; <nl> + if ( ! Ty ) <nl> + return nullptr ; <nl> + TupleElmt - > addChild ( Ty ) ; <nl> + Nodes . push_back ( TupleElmt ) ; <nl> + } while ( ! firstElem ) ; <nl> + <nl> + while ( NodePointer TupleElmt = pop_back_val ( Nodes ) ) { <nl> + Root - > addChild ( TupleElmt ) ; <nl> + } <nl> + } <nl> + return createType ( Root ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popTypeList ( ) { <nl> + NodePointer Root = NodeFactory : : create ( Node : : Kind : : TypeList ) ; <nl> + <nl> + if ( ! popNode ( Node : : Kind : : EmptyList ) ) { <nl> + std : : vector < NodePointer > Nodes ; <nl> + bool firstElem = false ; <nl> + do { <nl> + firstElem = ( popNode ( Node : : Kind : : FirstElementMarker ) ! = nullptr ) ; <nl> + NodePointer Ty = popNode ( Node : : Kind : : Type ) ; <nl> + if ( ! Ty ) <nl> + return nullptr ; <nl> + Nodes . push_back ( Ty ) ; <nl> + } while ( ! firstElem ) ; <nl> + while ( NodePointer Ty = pop_back_val ( Nodes ) ) { <nl> + Root - > addChild ( Ty ) ; <nl> + } <nl> + } <nl> + return Root ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popProtocol ( ) { <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Ctx = popContext ( ) ; <nl> + NodePointer Proto = createWithChildren ( Node : : Kind : : Protocol , Ctx , Name ) ; <nl> + return createType ( Proto ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleBoundGenericType ( ) { <nl> + NodePointer Nominal = popTypeAndGetNominal ( ) ; <nl> + return createType ( demangleBoundGenericArgs ( Nominal ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleBoundGenericArgs ( NodePointer Nominal ) { <nl> + if ( ! Nominal | | Nominal - > getNumChildren ( ) < 2 ) <nl> + return nullptr ; <nl> + <nl> + NodePointer args = popTypeList ( ) ; <nl> + if ( ! args ) <nl> + return nullptr ; <nl> + <nl> + / / Generic arguments for the outermost type come first . <nl> + NodePointer Context = Nominal - > getFirstChild ( ) ; <nl> + <nl> + if ( Context - > getKind ( ) ! = Node : : Kind : : Module & & <nl> + Context - > getKind ( ) ! = Node : : Kind : : Function & & <nl> + Context - > getKind ( ) ! = Node : : Kind : : Extension ) { <nl> + NodePointer BoundParent = demangleBoundGenericArgs ( Context ) ; <nl> + <nl> + / / Rebuild this type with the new parent type , which may have <nl> + / / had its generic arguments applied . <nl> + Nominal = createWithChildren ( Nominal - > getKind ( ) , BoundParent , <nl> + Nominal - > getChild ( 1 ) ) ; <nl> + if ( ! Nominal ) <nl> + return nullptr ; <nl> + } <nl> + <nl> + / / If there were no arguments at this level there is nothing left <nl> + / / to do . <nl> + if ( args - > getNumChildren ( ) = = 0 ) <nl> + return Nominal ; <nl> + <nl> + Node : : Kind kind ; <nl> + switch ( Nominal - > getKind ( ) ) { <nl> + case Node : : Kind : : Class : <nl> + kind = Node : : Kind : : BoundGenericClass ; <nl> + break ; <nl> + case Node : : Kind : : Structure : <nl> + kind = Node : : Kind : : BoundGenericStructure ; <nl> + break ; <nl> + case Node : : Kind : : Enum : <nl> + kind = Node : : Kind : : BoundGenericEnum ; <nl> + break ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + return createWithChildren ( kind , createType ( Nominal ) , args ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleImplParamConvention ( ) { <nl> + StringRef attr ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' i ' : attr = " @ in " ; break ; <nl> + case ' l ' : attr = " @ inout " ; break ; <nl> + case ' b ' : attr = " @ inout_aliasable " ; break ; <nl> + case ' n ' : attr = " @ in_guaranteed " ; break ; <nl> + case ' x ' : attr = " @ owned " ; break ; <nl> + case ' g ' : attr = " @ guaranteed " ; break ; <nl> + case ' e ' : attr = " @ deallocating " ; break ; <nl> + case ' y ' : attr = " @ unowned " ; break ; <nl> + default : <nl> + pushBack ( ) ; <nl> + return nullptr ; <nl> + } <nl> + return createWithChild ( Node : : Kind : : ImplParameter , <nl> + NodeFactory : : create ( Node : : Kind : : ImplConvention , attr ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleImplResultConvention ( Node : : Kind ConvKind ) { <nl> + StringRef attr ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' r ' : attr = " @ out " ; break ; <nl> + case ' o ' : attr = " @ owned " ; break ; <nl> + case ' d ' : attr = " @ unowned " ; break ; <nl> + case ' u ' : attr = " @ unowned_inner_pointer " ; break ; <nl> + case ' a ' : attr = " @ autoreleased " ; break ; <nl> + default : <nl> + pushBack ( ) ; <nl> + return nullptr ; <nl> + } <nl> + return createWithChild ( ConvKind , <nl> + NodeFactory : : create ( Node : : Kind : : ImplConvention , attr ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleImplFunctionType ( ) { <nl> + NodePointer type = NodeFactory : : create ( Node : : Kind : : ImplFunctionType ) ; <nl> + <nl> + NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ; <nl> + if ( GenSig & & nextIf ( ' P ' ) ) <nl> + GenSig = changeKind ( GenSig , Node : : Kind : : DependentPseudogenericSignature ) ; <nl> + <nl> + StringRef CAttr ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' y ' : CAttr = " @ callee_unowned " ; break ; <nl> + case ' g ' : CAttr = " @ callee_guaranteed " ; break ; <nl> + case ' x ' : CAttr = " @ callee_owned " ; break ; <nl> + case ' t ' : CAttr = " @ convention ( thin ) " ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + type - > addChild ( NodeFactory : : create ( Node : : Kind : : ImplConvention , CAttr ) ) ; <nl> + <nl> + StringRef FAttr ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' B ' : FAttr = " @ convention ( block ) " ; break ; <nl> + case ' C ' : FAttr = " @ convention ( c ) " ; break ; <nl> + case ' M ' : FAttr = " @ convention ( method ) " ; break ; <nl> + case ' O ' : FAttr = " @ convention ( objc_method ) " ; break ; <nl> + case ' K ' : FAttr = " @ convention ( closure ) " ; break ; <nl> + case ' W ' : FAttr = " @ convention ( witness_method ) " ; break ; <nl> + default : <nl> + pushBack ( ) ; <nl> + break ; <nl> + } <nl> + if ( ! FAttr . empty ( ) ) <nl> + type - > addChild ( NodeFactory : : create ( Node : : Kind : : ImplFunctionAttribute , FAttr ) ) ; <nl> + <nl> + addChild ( type , GenSig ) ; <nl> + <nl> + int NumTypesToAdd = 0 ; <nl> + while ( NodePointer Param = demangleImplParamConvention ( ) ) { <nl> + type = addChild ( type , Param ) ; <nl> + NumTypesToAdd + + ; <nl> + } <nl> + while ( NodePointer Result = demangleImplResultConvention ( <nl> + Node : : Kind : : ImplResult ) ) { <nl> + type = addChild ( type , Result ) ; <nl> + NumTypesToAdd + + ; <nl> + } <nl> + if ( nextIf ( ' z ' ) ) { <nl> + NodePointer ErrorResult = demangleImplResultConvention ( <nl> + Node : : Kind : : ImplErrorResult ) ; <nl> + if ( ! ErrorResult ) <nl> + return nullptr ; <nl> + type = addChild ( type , ErrorResult ) ; <nl> + NumTypesToAdd + + ; <nl> + } <nl> + if ( ! nextIf ( ' _ ' ) ) <nl> + return nullptr ; <nl> + <nl> + for ( int Idx = 0 ; Idx < NumTypesToAdd ; + + Idx ) { <nl> + NodePointer ConvTy = popNode ( Node : : Kind : : Type ) ; <nl> + if ( ! ConvTy ) <nl> + return nullptr ; <nl> + type - > getChild ( type - > getNumChildren ( ) - Idx - 1 ) - > addChild ( ConvTy ) ; <nl> + } <nl> + return createType ( type ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleMetatype ( ) { <nl> + switch ( nextChar ( ) ) { <nl> + case ' f ' : <nl> + return createWithPoppedType ( Node : : Kind : : FullTypeMetadata ) ; <nl> + case ' P ' : <nl> + return createWithPoppedType ( Node : : Kind : : GenericTypeMetadataPattern ) ; <nl> + case ' a ' : <nl> + return createWithPoppedType ( Node : : Kind : : TypeMetadataAccessFunction ) ; <nl> + case ' L ' : <nl> + return createWithPoppedType ( Node : : Kind : : TypeMetadataLazyCache ) ; <nl> + case ' m ' : <nl> + return createWithPoppedType ( Node : : Kind : : Metaclass ) ; <nl> + case ' n ' : <nl> + return createWithPoppedType ( Node : : Kind : : NominalTypeDescriptor ) ; <nl> + case ' p ' : <nl> + return createWithChild ( Node : : Kind : : ProtocolDescriptor , popProtocol ( ) ) ; <nl> + case ' B ' : <nl> + return createWithChild ( Node : : Kind : : ReflectionMetadataBuiltinDescriptor , <nl> + popNode ( Node : : Kind : : Type ) ) ; <nl> + case ' F ' : <nl> + return createWithChild ( Node : : Kind : : ReflectionMetadataFieldDescriptor , <nl> + popNode ( Node : : Kind : : Type ) ) ; <nl> + case ' A ' : <nl> + return createWithChild ( Node : : Kind : : ReflectionMetadataAssocTypeDescriptor , <nl> + popProtocolConformance ( ) ) ; <nl> + case ' C ' : <nl> + return createWithChild ( Node : : Kind : : ReflectionMetadataSuperclassDescriptor , <nl> + popNode ( isNominal ) ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + static std : : string getArchetypeName ( Node : : IndexType index , <nl> + Node : : IndexType depth ) { <nl> + DemanglerPrinter name ; <nl> + do { <nl> + name < < ( char ) ( ' A ' + ( index % 26 ) ) ; <nl> + index / = 26 ; <nl> + } while ( index ) ; <nl> + if ( depth ! = 0 ) <nl> + name < < depth ; <nl> + return std : : move ( name ) . str ( ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : createArchetypeRef ( int depth , int i ) { <nl> + if ( depth < 0 | | i < 0 ) <nl> + return nullptr ; <nl> + <nl> + / / FIXME : Name won ' t match demangled context generic signatures correctly . <nl> + auto ref = NodeFactory : : create ( Node : : Kind : : ArchetypeRef , <nl> + getArchetypeName ( i , depth ) ) ; <nl> + ref - > addChild ( NodeFactory : : create ( Node : : Kind : : Index , depth ) ) ; <nl> + ref - > addChild ( NodeFactory : : create ( Node : : Kind : : Index , i ) ) ; <nl> + return createType ( ref ) ; <nl> + } <nl> + <nl> + <nl> + NodePointer Demangler : : demangleArchetype ( ) { <nl> + int index = demangleIndex ( ) ; <nl> + if ( index > = 0 ) <nl> + return createArchetypeRef ( 0 , index ) ; <nl> + <nl> + switch ( nextChar ( ) ) { <nl> + case ' a ' : { <nl> + NodePointer Ident = popNode ( Node : : Kind : : Identifier ) ; <nl> + NodePointer ArcheTy = popTypeAndGetChild ( ) ; <nl> + NodePointer AssocTy = createType ( <nl> + createWithChildren ( Node : : Kind : : AssociatedTypeRef , ArcheTy , Ident ) ) ; <nl> + addSubstitution ( AssocTy ) ; <nl> + return AssocTy ; <nl> + } <nl> + case ' d ' : { <nl> + int depth = demangleIndex ( ) + 1 ; <nl> + int index = demangleIndex ( ) ; <nl> + return createArchetypeRef ( depth , index ) ; <nl> + } <nl> + case ' q ' : { <nl> + NodePointer Idx = demangleIndexAsNode ( ) ; <nl> + NodePointer Ctx = popContext ( ) ; <nl> + NodePointer DeclCtx = createWithChild ( Node : : Kind : : DeclContext , Ctx ) ; <nl> + return createType ( createWithChildren ( Node : : Kind : : QualifiedArchetype , <nl> + Idx , DeclCtx ) ) ; <nl> + } <nl> + case ' P ' : <nl> + / / TODO : self type of protocol <nl> + return nullptr ; <nl> + case ' y ' : { <nl> + NodePointer T = demangleAssociatedTypeSimple ( demangleGenericParamIndex ( ) ) ; <nl> + addSubstitution ( T ) ; <nl> + return T ; <nl> + } <nl> + case ' z ' : { <nl> + NodePointer T = demangleAssociatedTypeSimple ( getDependentGenericParamType ( 0 , 0 ) ) ; <nl> + addSubstitution ( T ) ; <nl> + return T ; <nl> + } <nl> + case ' Y ' : { <nl> + NodePointer T = demangleAssociatedTypeCompound ( demangleGenericParamIndex ( ) ) ; <nl> + addSubstitution ( T ) ; <nl> + return T ; <nl> + } <nl> + case ' Z ' : { <nl> + NodePointer T = demangleAssociatedTypeCompound ( getDependentGenericParamType ( 0 , 0 ) ) ; <nl> + addSubstitution ( T ) ; <nl> + return T ; <nl> + } <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleAssociatedTypeSimple ( <nl> + NodePointer GenericParamIdx ) { <nl> + NodePointer GPI = createType ( GenericParamIdx ) ; <nl> + NodePointer ATName = popAssocTypeName ( ) ; <nl> + return createType ( createWithChildren ( Node : : Kind : : DependentMemberType , <nl> + GPI , ATName ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleAssociatedTypeCompound ( <nl> + NodePointer GenericParamIdx ) { <nl> + std : : vector < NodePointer > AssocTyNames ; <nl> + bool firstElem = false ; <nl> + do { <nl> + firstElem = ( popNode ( Node : : Kind : : FirstElementMarker ) ! = nullptr ) ; <nl> + NodePointer AssocTyName = popAssocTypeName ( ) ; <nl> + if ( ! AssocTyName ) <nl> + return nullptr ; <nl> + AssocTyNames . push_back ( AssocTyName ) ; <nl> + } while ( ! firstElem ) ; <nl> + <nl> + NodePointer Base = GenericParamIdx ; <nl> + <nl> + while ( NodePointer AssocTy = pop_back_val ( AssocTyNames ) ) { <nl> + NodePointer depTy = NodeFactory : : create ( Node : : Kind : : DependentMemberType ) ; <nl> + depTy = addChild ( depTy , createType ( Base ) ) ; <nl> + Base = addChild ( depTy , AssocTy ) ; <nl> + } <nl> + return createType ( Base ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popAssocTypeName ( ) { <nl> + NodePointer Proto = popNode ( Node : : Kind : : Type ) ; <nl> + if ( Proto & & Proto - > getFirstChild ( ) - > getKind ( ) ! = Node : : Kind : : Protocol ) <nl> + return nullptr ; <nl> + <nl> + NodePointer Id = popNode ( Node : : Kind : : Identifier ) ; <nl> + NodePointer AssocTy = changeKind ( Id , Node : : Kind : : DependentAssociatedTypeRef ) ; <nl> + addChild ( AssocTy , Proto ) ; <nl> + return AssocTy ; <nl> + } <nl> + <nl> + NodePointer Demangler : : getDependentGenericParamType ( int depth , int index ) { <nl> + if ( depth < 0 | | index < 0 ) <nl> + return nullptr ; <nl> + DemanglerPrinter PrintName ; <nl> + PrintName < < getArchetypeName ( index , depth ) ; <nl> + <nl> + auto paramTy = NodeFactory : : create ( Node : : Kind : : DependentGenericParamType , <nl> + std : : move ( PrintName ) . str ( ) ) ; <nl> + paramTy - > addChild ( NodeFactory : : create ( Node : : Kind : : Index , depth ) ) ; <nl> + paramTy - > addChild ( NodeFactory : : create ( Node : : Kind : : Index , index ) ) ; <nl> + return paramTy ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleGenericParamIndex ( ) { <nl> + if ( nextIf ( ' d ' ) ) { <nl> + int depth = demangleIndex ( ) + 1 ; <nl> + int index = demangleIndex ( ) ; <nl> + return getDependentGenericParamType ( depth , index ) ; <nl> + } <nl> + if ( nextIf ( ' z ' ) ) { <nl> + return getDependentGenericParamType ( 0 , 0 ) ; <nl> + } <nl> + return getDependentGenericParamType ( 0 , demangleIndex ( ) + 1 ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : popProtocolConformance ( ) { <nl> + NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ; <nl> + NodePointer Module = popModule ( ) ; <nl> + NodePointer Proto = popProtocol ( ) ; <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + if ( GenSig ) { <nl> + Type = createType ( createWithChildren ( Node : : Kind : : DependentGenericType , <nl> + GenSig , Type ) ) ; <nl> + } <nl> + return createWithChildren ( Node : : Kind : : ProtocolConformance , <nl> + Type , Proto , Module ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleThunkOrSpecialization ( ) { <nl> + switch ( char c = nextChar ( ) ) { <nl> + case ' c ' : return createWithChild ( Node : : Kind : : CurryThunk , popNode ( isEntity ) ) ; <nl> + case ' o ' : return swapWith ( Node : : Kind : : ObjCAttribute ) ; <nl> + case ' O ' : return swapWith ( Node : : Kind : : NonObjCAttribute ) ; <nl> + case ' D ' : return swapWith ( Node : : Kind : : DynamicAttribute ) ; <nl> + case ' d ' : return swapWith ( Node : : Kind : : DirectMethodReferenceAttribute ) ; <nl> + case ' V ' : return swapWith ( Node : : Kind : : VTableAttribute ) ; <nl> + case ' W ' : { <nl> + NodePointer Entity = popNode ( isEntity ) ; <nl> + NodePointer Conf = popProtocolConformance ( ) ; <nl> + return createWithChildren ( Node : : Kind : : ProtocolWitness , Conf , Entity ) ; <nl> + } <nl> + case ' R ' : <nl> + case ' r ' : { <nl> + NodePointer Thunk = NodeFactory : : create ( c = = ' R ' ? <nl> + Node : : Kind : : ReabstractionThunkHelper : <nl> + Node : : Kind : : ReabstractionThunk ) ; <nl> + if ( NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ) <nl> + addChild ( Thunk , GenSig ) ; <nl> + NodePointer Ty2 = popNode ( Node : : Kind : : Type ) ; <nl> + Thunk = addChild ( Thunk , popNode ( Node : : Kind : : Type ) ) ; <nl> + return addChild ( Thunk , Ty2 ) ; <nl> + } <nl> + case ' A ' : <nl> + return createWithChild ( Node : : Kind : : PartialApplyForwarder , popNode ( ) ) ; <nl> + case ' a ' : <nl> + return createWithChild ( Node : : Kind : : PartialApplyObjCForwarder , popNode ( ) ) ; <nl> + case ' g ' : <nl> + return demangleGenericSpecialization ( Node : : Kind : : GenericSpecialization ) ; <nl> + case ' G ' : <nl> + return demangleGenericSpecialization ( Node : : Kind : : <nl> + GenericSpecializationNotReAbstracted ) ; <nl> + case ' f ' : <nl> + return demangleFunctionSpecialization ( ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleGenericSpecialization ( Node : : Kind SpecKind ) { <nl> + NodePointer Spec = demangleSpecAttributes ( SpecKind ) ; <nl> + NodePointer TyList = popTypeList ( ) ; <nl> + if ( ! TyList ) <nl> + return nullptr ; <nl> + for ( NodePointer Ty : * TyList ) { <nl> + Spec - > addChild ( createWithChild ( Node : : Kind : : GenericSpecializationParam , Ty ) ) ; <nl> + } <nl> + return Spec ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleFunctionSpecialization ( ) { <nl> + NodePointer Spec = demangleSpecAttributes ( <nl> + Node : : Kind : : FunctionSignatureSpecialization ) ; <nl> + unsigned ParamIdx = 0 ; <nl> + while ( Spec & & ! nextIf ( ' _ ' ) ) { <nl> + Spec = addChild ( Spec , demangleFuncSpecParam ( ParamIdx ) ) ; <nl> + ParamIdx + + ; <nl> + } <nl> + if ( ! nextIf ( ' n ' ) ) <nl> + Spec = addChild ( Spec , demangleFuncSpecParam ( Node : : IndexType ( ~ 0 ) ) ) ; <nl> + return Spec ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleFuncSpecParam ( Node : : IndexType ParamIdx ) { <nl> + NodePointer Param = NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParam , ParamIdx ) ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' n ' : <nl> + return Param ; <nl> + case ' c ' : { <nl> + std : : vector < NodePointer > Types ; <nl> + while ( NodePointer Ty = popNode ( Node : : Kind : : Type ) ) { <nl> + Types . push_back ( Ty ) ; <nl> + } <nl> + Param = addFuncSpecParamIdentifier ( Param , <nl> + swift : : Demangle : : FunctionSigSpecializationParamKind : : ClosureProp ) ; <nl> + while ( NodePointer Ty = pop_back_val ( Types ) ) { <nl> + Param = addChild ( Param , Ty ) ; <nl> + } <nl> + return Param ; <nl> + } <nl> + case ' p ' : { <nl> + switch ( nextChar ( ) ) { <nl> + case ' f ' : <nl> + return addFuncSpecParamIdentifier ( Param , <nl> + FunctionSigSpecializationParamKind : : ConstantPropFunction ) ; <nl> + case ' g ' : <nl> + return addFuncSpecParamIdentifier ( Param , <nl> + FunctionSigSpecializationParamKind : : ConstantPropGlobal ) ; <nl> + case ' i ' : <nl> + return addFuncSpecParamNumber ( Param , <nl> + FunctionSigSpecializationParamKind : : ConstantPropInteger ) ; <nl> + case ' d ' : <nl> + return addFuncSpecParamNumber ( Param , <nl> + FunctionSigSpecializationParamKind : : ConstantPropFloat ) ; <nl> + case ' s ' : { <nl> + StringRef Encoding ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' b ' : Encoding = " u8 " ; break ; <nl> + case ' w ' : Encoding = " u16 " ; break ; <nl> + case ' c ' : Encoding = " objc " ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + NodePointer Str = popNode ( Node : : Kind : : Identifier ) ; <nl> + if ( ! Str ) <nl> + return nullptr ; <nl> + StringRef Text = Str - > getText ( ) ; <nl> + if ( Text . size ( ) > 0 & & Text [ 0 ] = = ' _ ' ) <nl> + Text = Text . drop_front ( 1 ) ; <nl> + <nl> + Param - > addChild ( NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , <nl> + unsigned ( swift : : Demangle : : FunctionSigSpecializationParamKind : : <nl> + ConstantPropString ) ) ) ; <nl> + Param - > addChild ( NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamPayload , <nl> + Encoding ) ) ; <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamPayload , <nl> + Text ) ) ; <nl> + } <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + case ' d ' : { <nl> + unsigned Value = unsigned ( FunctionSigSpecializationParamKind : : Dead ) ; <nl> + if ( nextIf ( ' G ' ) ) <nl> + Value | = unsigned ( FunctionSigSpecializationParamKind : : OwnedToGuaranteed ) ; <nl> + if ( nextIf ( ' X ' ) ) <nl> + Value | = unsigned ( FunctionSigSpecializationParamKind : : SROA ) ; <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , Value ) ) ; <nl> + } <nl> + case ' g ' : { <nl> + unsigned Value = unsigned ( FunctionSigSpecializationParamKind : : <nl> + OwnedToGuaranteed ) ; <nl> + if ( nextIf ( ' X ' ) ) <nl> + Value | = unsigned ( FunctionSigSpecializationParamKind : : SROA ) ; <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , Value ) ) ; <nl> + } <nl> + case ' x ' : <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , <nl> + unsigned ( FunctionSigSpecializationParamKind : : SROA ) ) ) ; <nl> + case ' i ' : <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , <nl> + unsigned ( FunctionSigSpecializationParamKind : : BoxToValue ) ) ) ; <nl> + case ' s ' : <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , <nl> + unsigned ( FunctionSigSpecializationParamKind : : BoxToStack ) ) ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : addFuncSpecParamIdentifier ( NodePointer Param , <nl> + FunctionSigSpecializationParamKind Kind , <nl> + StringRef FirstParam ) { <nl> + NodePointer Name = popNode ( Node : : Kind : : Identifier ) ; <nl> + if ( ! Name ) <nl> + return nullptr ; <nl> + Param - > addChild ( NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , unsigned ( Kind ) ) ) ; <nl> + if ( ! FirstParam . empty ( ) ) { <nl> + Param - > addChild ( NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamPayload , FirstParam ) ) ; <nl> + } <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamPayload , Name - > getText ( ) ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : addFuncSpecParamNumber ( NodePointer Param , <nl> + FunctionSigSpecializationParamKind Kind ) { <nl> + Param - > addChild ( NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamKind , unsigned ( Kind ) ) ) ; <nl> + std : : string Str ; <nl> + while ( isDigit ( peekChar ( ) ) ) { <nl> + Str + = nextChar ( ) ; <nl> + } <nl> + if ( Str . empty ( ) ) <nl> + return nullptr ; <nl> + return addChild ( Param , NodeFactory : : create ( <nl> + Node : : Kind : : FunctionSignatureSpecializationParamPayload , Str ) ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleSpecAttributes ( Node : : Kind SpecKind ) { <nl> + NodePointer SpecNd = NodeFactory : : create ( SpecKind ) ; <nl> + if ( nextIf ( ' q ' ) ) <nl> + SpecNd - > addChild ( NodeFactory : : create ( Node : : Kind : : SpecializationIsFragile ) ) ; <nl> + <nl> + int PassID = ( int ) nextChar ( ) - ' 0 ' ; <nl> + if ( PassID < 0 | | PassID > 9 ) <nl> + return nullptr ; <nl> + <nl> + SpecNd - > addChild ( NodeFactory : : create ( Node : : Kind : : SpecializationPassID , <nl> + PassID ) ) ; <nl> + return SpecNd ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleWitness ( ) { <nl> + switch ( nextChar ( ) ) { <nl> + case ' V ' : <nl> + return createWithChild ( Node : : Kind : : ValueWitnessTable , <nl> + popNode ( Node : : Kind : : Type ) ) ; <nl> + case ' o ' : <nl> + return createWithChild ( Node : : Kind : : WitnessTableOffset , popNode ( isEntity ) ) ; <nl> + case ' v ' : { <nl> + unsigned Directness ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' d ' : Directness = unsigned ( Directness : : Direct ) ; break ; <nl> + case ' i ' : Directness = unsigned ( Directness : : Indirect ) ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + return createWithChildren ( Node : : Kind : : FieldOffset , <nl> + NodeFactory : : create ( Node : : Kind : : Directness , Directness ) , <nl> + popNode ( isEntity ) ) ; <nl> + } <nl> + case ' P ' : <nl> + return createWithChild ( Node : : Kind : : ProtocolWitnessTable , <nl> + popProtocolConformance ( ) ) ; <nl> + case ' G ' : <nl> + return createWithChild ( Node : : Kind : : GenericProtocolWitnessTable , <nl> + popProtocolConformance ( ) ) ; <nl> + case ' I ' : <nl> + return createWithChild ( <nl> + Node : : Kind : : GenericProtocolWitnessTableInstantiationFunction , <nl> + popProtocolConformance ( ) ) ; <nl> + case ' l ' : { <nl> + NodePointer Conf = popProtocolConformance ( ) ; <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + return createWithChildren ( Node : : Kind : : LazyProtocolWitnessTableAccessor , <nl> + Type , Conf ) ; <nl> + } <nl> + case ' L ' : { <nl> + NodePointer Conf = popProtocolConformance ( ) ; <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + return createWithChildren ( <nl> + Node : : Kind : : LazyProtocolWitnessTableCacheVariable , Type , Conf ) ; <nl> + } <nl> + case ' a ' : <nl> + return createWithChild ( Node : : Kind : : ProtocolWitnessTableAccessor , <nl> + popProtocolConformance ( ) ) ; <nl> + case ' t ' : { <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Conf = popProtocolConformance ( ) ; <nl> + return createWithChildren ( Node : : Kind : : AssociatedTypeMetadataAccessor , <nl> + Conf , Name ) ; <nl> + } <nl> + case ' T ' : { <nl> + NodePointer ProtoTy = createWithChild ( Node : : Kind : : Type , popProtocol ( ) ) ; <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Conf = popProtocolConformance ( ) ; <nl> + return createWithChildren ( Node : : Kind : : AssociatedTypeMetadataAccessor , <nl> + Conf , Name , ProtoTy ) ; <nl> + } <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleSpecialType ( ) { <nl> + switch ( nextChar ( ) ) { <nl> + case ' f ' : <nl> + return popFunctionType ( Node : : Kind : : ThinFunctionType ) ; <nl> + case ' K ' : <nl> + return popFunctionType ( Node : : Kind : : AutoClosureType ) ; <nl> + case ' U ' : <nl> + return popFunctionType ( Node : : Kind : : UncurriedFunctionType ) ; <nl> + case ' B ' : <nl> + return popFunctionType ( Node : : Kind : : ObjCBlock ) ; <nl> + case ' C ' : <nl> + return popFunctionType ( Node : : Kind : : CFunctionPointer ) ; <nl> + case ' o ' : <nl> + return createType ( createWithChild ( Node : : Kind : : Unowned , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' u ' : <nl> + return createType ( createWithChild ( Node : : Kind : : Unmanaged , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' w ' : <nl> + return createType ( createWithChild ( Node : : Kind : : Weak , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' b ' : <nl> + return createType ( createWithChild ( Node : : Kind : : SILBoxType , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' D ' : <nl> + return createType ( createWithChild ( Node : : Kind : : DynamicSelf , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + case ' M ' : { <nl> + NodePointer MTR = demangleMetatypeRepresentation ( ) ; <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + return createType ( createWithChildren ( Node : : Kind : : Metatype , MTR , Type ) ) ; <nl> + } <nl> + case ' m ' : { <nl> + NodePointer MTR = demangleMetatypeRepresentation ( ) ; <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + return createType ( createWithChildren ( Node : : Kind : : ExistentialMetatype , <nl> + MTR , Type ) ) ; <nl> + } <nl> + case ' p ' : <nl> + return createType ( createWithChild ( Node : : Kind : : ExistentialMetatype , <nl> + popNode ( Node : : Kind : : Type ) ) ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleMetatypeRepresentation ( ) { <nl> + switch ( nextChar ( ) ) { <nl> + case ' t ' : <nl> + return NodeFactory : : create ( Node : : Kind : : MetatypeRepresentation , " @ thin " ) ; <nl> + case ' T ' : <nl> + return NodeFactory : : create ( Node : : Kind : : MetatypeRepresentation , " @ thick " ) ; <nl> + case ' o ' : <nl> + return NodeFactory : : create ( Node : : Kind : : MetatypeRepresentation , <nl> + " @ objc_metatype " ) ; <nl> + default : <nl> + return nullptr ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleFunctionEntity ( ) { <nl> + enum { None , Type , TypeAndName , TypeAndIndex , Index } Args ; <nl> + <nl> + Node : : Kind Kind = Node : : Kind : : EmptyList ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' D ' : Args = None ; Kind = Node : : Kind : : Deallocator ; break ; <nl> + case ' d ' : Args = None ; Kind = Node : : Kind : : Destructor ; break ; <nl> + case ' E ' : Args = None ; Kind = Node : : Kind : : IVarDestroyer ; break ; <nl> + case ' e ' : Args = None ; Kind = Node : : Kind : : IVarInitializer ; break ; <nl> + case ' i ' : Args = None ; Kind = Node : : Kind : : Initializer ; break ; <nl> + case ' C ' : Args = Type ; Kind = Node : : Kind : : Allocator ; break ; <nl> + case ' c ' : Args = Type ; Kind = Node : : Kind : : Constructor ; break ; <nl> + case ' g ' : Args = TypeAndName ; Kind = Node : : Kind : : Getter ; break ; <nl> + case ' G ' : Args = TypeAndName ; Kind = Node : : Kind : : GlobalGetter ; break ; <nl> + case ' s ' : Args = TypeAndName ; Kind = Node : : Kind : : Setter ; break ; <nl> + case ' m ' : Args = TypeAndName ; Kind = Node : : Kind : : MaterializeForSet ; break ; <nl> + case ' w ' : Args = TypeAndName ; Kind = Node : : Kind : : WillSet ; break ; <nl> + case ' W ' : Args = TypeAndName ; Kind = Node : : Kind : : DidSet ; break ; <nl> + case ' a ' : <nl> + Args = TypeAndName ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' O ' : Kind = Node : : Kind : : OwningMutableAddressor ; break ; <nl> + case ' o ' : Kind = Node : : Kind : : NativeOwningMutableAddressor ; break ; <nl> + case ' P ' : Kind = Node : : Kind : : NativePinningMutableAddressor ; break ; <nl> + case ' u ' : Kind = Node : : Kind : : UnsafeMutableAddressor ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + break ; <nl> + case ' l ' : <nl> + Args = TypeAndName ; <nl> + switch ( nextChar ( ) ) { <nl> + case ' O ' : Kind = Node : : Kind : : OwningAddressor ; break ; <nl> + case ' o ' : Kind = Node : : Kind : : NativeOwningAddressor ; break ; <nl> + case ' p ' : Kind = Node : : Kind : : NativePinningAddressor ; break ; <nl> + case ' u ' : Kind = Node : : Kind : : UnsafeAddressor ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + break ; <nl> + case ' U ' : Args = TypeAndIndex ; Kind = Node : : Kind : : ExplicitClosure ; break ; <nl> + case ' u ' : Args = TypeAndIndex ; Kind = Node : : Kind : : ImplicitClosure ; break ; <nl> + case ' A ' : Args = Index ; Kind = Node : : Kind : : DefaultArgumentInitializer ; break ; <nl> + default : return nullptr ; <nl> + } <nl> + <nl> + NodePointer Child1 , Child2 ; <nl> + switch ( Args ) { <nl> + case None : <nl> + break ; <nl> + case Type : <nl> + Child1 = popNode ( Node : : Kind : : Type ) ; <nl> + break ; <nl> + case TypeAndName : <nl> + Child2 = popNode ( Node : : Kind : : Type ) ; <nl> + Child1 = popNode ( isDeclName ) ; <nl> + break ; <nl> + case TypeAndIndex : <nl> + Child1 = demangleIndexAsNode ( ) ; <nl> + Child2 = popNode ( Node : : Kind : : Type ) ; <nl> + break ; <nl> + case Index : <nl> + Child1 = demangleIndexAsNode ( ) ; <nl> + break ; <nl> + } <nl> + NodePointer Entity = createWithChild ( Kind , popContext ( ) ) ; <nl> + switch ( Args ) { <nl> + case None : <nl> + break ; <nl> + case Type : <nl> + case Index : <nl> + Entity = addChild ( Entity , Child1 ) ; <nl> + break ; <nl> + case TypeAndName : <nl> + case TypeAndIndex : <nl> + Entity = addChild ( Entity , Child1 ) ; <nl> + Entity = addChild ( Entity , Child2 ) ; <nl> + break ; <nl> + } <nl> + return Entity ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleEntity ( Node : : Kind Kind ) { <nl> + NodePointer Type = popNode ( Node : : Kind : : Type ) ; <nl> + NodePointer Name = popNode ( isDeclName ) ; <nl> + NodePointer Context = popContext ( ) ; <nl> + return createWithChildren ( Kind , Context , Name , Type ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleProtocolListType ( ) { <nl> + NodePointer TypeList = NodeFactory : : create ( Node : : Kind : : TypeList ) ; <nl> + NodePointer ProtoList = createWithChild ( Node : : Kind : : ProtocolList , TypeList ) ; <nl> + if ( ! popNode ( Node : : Kind : : EmptyList ) ) { <nl> + std : : vector < NodePointer > ProtoNames ; <nl> + bool firstElem = false ; <nl> + do { <nl> + firstElem = ( popNode ( Node : : Kind : : FirstElementMarker ) ! = nullptr ) ; <nl> + NodePointer Proto = popProtocol ( ) ; <nl> + if ( ! Proto ) <nl> + return nullptr ; <nl> + ProtoNames . push_back ( Proto ) ; <nl> + } while ( ! firstElem ) ; <nl> + <nl> + while ( NodePointer Proto = pop_back_val ( ProtoNames ) ) { <nl> + TypeList - > addChild ( Proto ) ; <nl> + } <nl> + } <nl> + return createType ( ProtoList ) ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleGenericSignature ( bool hasParamCounts ) { <nl> + std : : vector < NodePointer > Requirements ; <nl> + while ( NodePointer Req = popNode ( isRequirement ) ) { <nl> + Requirements . push_back ( Req ) ; <nl> + } <nl> + NodePointer Sig = NodeFactory : : create ( Node : : Kind : : DependentGenericSignature ) ; <nl> + if ( hasParamCounts ) { <nl> + while ( ! nextIf ( ' l ' ) ) { <nl> + int count = 0 ; <nl> + if ( ! nextIf ( ' z ' ) ) <nl> + count = demangleIndex ( ) + 1 ; <nl> + if ( count < 0 ) <nl> + return nullptr ; <nl> + Sig - > addChild ( NodeFactory : : create ( Node : : Kind : : DependentGenericParamCount , <nl> + count ) ) ; <nl> + } <nl> + } else { <nl> + Sig - > addChild ( NodeFactory : : create ( Node : : Kind : : DependentGenericParamCount , <nl> + 1 ) ) ; <nl> + } <nl> + if ( Sig - > getNumChildren ( ) = = 0 ) <nl> + return nullptr ; <nl> + while ( NodePointer Req = pop_back_val ( Requirements ) ) { <nl> + Sig - > addChild ( Req ) ; <nl> + } <nl> + return Sig ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleGenericRequirement ( ) { <nl> + <nl> + enum { Generic , Assoc , CompoundAssoc , Substitution } TypeKind ; <nl> + enum { Protocol , BaseClass , SameType } ConstraintKind ; <nl> + <nl> + switch ( nextChar ( ) ) { <nl> + case ' c ' : ConstraintKind = BaseClass ; TypeKind = Assoc ; break ; <nl> + case ' C ' : ConstraintKind = BaseClass ; TypeKind = CompoundAssoc ; break ; <nl> + case ' b ' : ConstraintKind = BaseClass ; TypeKind = Generic ; break ; <nl> + case ' B ' : ConstraintKind = BaseClass ; TypeKind = Substitution ; break ; <nl> + case ' t ' : ConstraintKind = SameType ; TypeKind = Assoc ; break ; <nl> + case ' T ' : ConstraintKind = SameType ; TypeKind = CompoundAssoc ; break ; <nl> + case ' s ' : ConstraintKind = SameType ; TypeKind = Generic ; break ; <nl> + case ' S ' : ConstraintKind = SameType ; TypeKind = Substitution ; break ; <nl> + case ' p ' : ConstraintKind = Protocol ; TypeKind = Assoc ; break ; <nl> + case ' P ' : ConstraintKind = Protocol ; TypeKind = CompoundAssoc ; break ; <nl> + case ' Q ' : ConstraintKind = Protocol ; TypeKind = Substitution ; break ; <nl> + default : ConstraintKind = Protocol ; TypeKind = Generic ; pushBack ( ) ; break ; <nl> + } <nl> + <nl> + NodePointer ConstrTy ; <nl> + switch ( TypeKind ) { <nl> + case Generic : <nl> + ConstrTy = createType ( demangleGenericParamIndex ( ) ) ; <nl> + break ; <nl> + case Assoc : <nl> + ConstrTy = demangleAssociatedTypeSimple ( demangleGenericParamIndex ( ) ) ; <nl> + addSubstitution ( ConstrTy ) ; <nl> + break ; <nl> + case CompoundAssoc : <nl> + ConstrTy = demangleAssociatedTypeCompound ( demangleGenericParamIndex ( ) ) ; <nl> + addSubstitution ( ConstrTy ) ; <nl> + break ; <nl> + case Substitution : <nl> + ConstrTy = popNode ( Node : : Kind : : Type ) ; <nl> + break ; <nl> + } <nl> + switch ( ConstraintKind ) { <nl> + case Protocol : <nl> + return createWithChildren ( <nl> + Node : : Kind : : DependentGenericConformanceRequirement , <nl> + ConstrTy , popProtocol ( ) ) ; <nl> + case BaseClass : <nl> + return createWithChildren ( <nl> + Node : : Kind : : DependentGenericConformanceRequirement , <nl> + ConstrTy , popNode ( Node : : Kind : : Type ) ) ; <nl> + case SameType : <nl> + return createWithChildren ( Node : : Kind : : DependentGenericSameTypeRequirement , <nl> + ConstrTy , popNode ( Node : : Kind : : Type ) ) ; <nl> + } <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleGenericType ( ) { <nl> + NodePointer GenSig = popNode ( Node : : Kind : : DependentGenericSignature ) ; <nl> + NodePointer Ty = popNode ( Node : : Kind : : Type ) ; <nl> + return createType ( createWithChildren ( Node : : Kind : : DependentGenericType , <nl> + GenSig , Ty ) ) ; <nl> + } <nl> + <nl> + static int decodeValueWitnessKind ( StringRef CodeStr ) { <nl> + # define VALUE_WITNESS ( MANGLING , NAME ) \ <nl> + if ( CodeStr = = # MANGLING ) return ( int ) ValueWitnessKind : : NAME ; <nl> + # include " swift / Basic / ValueWitnessMangling . def " <nl> + return - 1 ; <nl> + } <nl> + <nl> + NodePointer Demangler : : demangleValueWitness ( ) { <nl> + char Code [ 2 ] ; <nl> + Code [ 0 ] = nextChar ( ) ; <nl> + Code [ 1 ] = nextChar ( ) ; <nl> + int Kind = decodeValueWitnessKind ( StringRef ( Code , 2 ) ) ; <nl> + if ( Kind < 0 ) <nl> + return nullptr ; <nl> + NodePointer VW = NodeFactory : : create ( Node : : Kind : : ValueWitness , unsigned ( Kind ) ) ; <nl> + return addChild ( VW , popNode ( Node : : Kind : : Type ) ) ; <nl> + } <nl> + <nl> + } / / namespace NewMangler <nl> + } / / namespace swift <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . 99b37fd1d49a <nl> mmm / dev / null <nl> ppp b / lib / Basic / Mangler . cpp <nl> <nl> + / / = = = mmm Mangler . cpp - Base class for Swift name mangling mmmmmmmmmmmmmmm - - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # define CHECK_MANGLING_AGAINST_OLD <nl> + <nl> + # include " swift / Basic / Mangler . h " <nl> + # include " swift / Basic / Punycode . h " <nl> + # include " swift / Basic / ManglingMacros . h " <nl> + # include " llvm / ADT / StringMap . h " <nl> + # include " llvm / Support / CommandLine . h " <nl> + # ifdef CHECK_MANGLING_AGAINST_OLD <nl> + # include " swift / Basic / Demangle . h " <nl> + # include " swift / Basic / DemangleWrappers . h " <nl> + # endif <nl> + # include < algorithm > <nl> + <nl> + using namespace swift ; <nl> + using namespace NewMangling ; <nl> + <nl> + bool NewMangling : : useNewMangling ( ) { <nl> + # ifdef USE_NEW_MANGLING <nl> + return true ; <nl> + # else <nl> + return false ; <nl> + # endif <nl> + } <nl> + <nl> + # ifndef NDEBUG <nl> + llvm : : cl : : opt < bool > PrintSwiftManglingStats ( <nl> + " print - swift - mangling - stats " , llvm : : cl : : init ( false ) , <nl> + llvm : : cl : : desc ( " Print statistics about Swift symbol mangling " ) ) ; <nl> + <nl> + namespace { <nl> + <nl> + # ifdef CHECK_MANGLING_AGAINST_OLD <nl> + <nl> + static bool areTreesEqual ( Demangle : : NodePointer Old , Demangle : : NodePointer New ) { <nl> + if ( ( Old ! = nullptr ) ! = ( New ! = nullptr ) ) <nl> + return false ; <nl> + if ( ! Old ) <nl> + return true ; <nl> + <nl> + if ( Old - > getKind ( ) = = Demangle : : Node : : Kind : : CurryThunk ) <nl> + Old = Old - > getFirstChild ( ) ; <nl> + if ( New - > getKind ( ) = = Demangle : : Node : : Kind : : CurryThunk ) <nl> + New = New - > getFirstChild ( ) ; <nl> + <nl> + if ( Old - > getKind ( ) ! = New - > getKind ( ) ) { <nl> + if ( Old - > getKind ( ) ! = Demangle : : Node : : Kind : : UncurriedFunctionType | | <nl> + New - > getKind ( ) ! = Demangle : : Node : : Kind : : FunctionType ) <nl> + return false ; <nl> + } <nl> + if ( Old - > hasText ( ) ! = New - > hasText ( ) ) <nl> + return false ; <nl> + if ( Old - > hasIndex ( ) ! = New - > hasIndex ( ) ) <nl> + return false ; <nl> + if ( Old - > hasText ( ) & & Old - > getText ( ) ! = New - > getText ( ) ) <nl> + return false ; <nl> + if ( Old - > hasIndex ( ) & & Old - > getIndex ( ) ! = New - > getIndex ( ) ) <nl> + return false ; <nl> + <nl> + size_t OldNum = Old - > getNumChildren ( ) ; <nl> + size_t NewNum = New - > getNumChildren ( ) ; <nl> + <nl> + if ( OldNum > = 1 & & NewNum = = 1 & & <nl> + Old - > getChild ( OldNum - 1 ) - > getKind ( ) = = Demangle : : Node : : Kind : : Suffix ) { <nl> + switch ( New - > getFirstChild ( ) - > getKind ( ) ) { <nl> + case Demangle : : Node : : Kind : : ReflectionMetadataBuiltinDescriptor : <nl> + case Demangle : : Node : : Kind : : ReflectionMetadataFieldDescriptor : <nl> + case Demangle : : Node : : Kind : : ReflectionMetadataAssocTypeDescriptor : <nl> + case Demangle : : Node : : Kind : : ReflectionMetadataSuperclassDescriptor : <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + if ( Old - > getKind ( ) = = Demangle : : Node : : Kind : : DependentAssociatedTypeRef & & <nl> + OldNum + NewNum = = 1 ) { <nl> + OldNum = 0 ; <nl> + NewNum = 0 ; <nl> + } <nl> + if ( Old - > getKind ( ) = = Demangle : : Node : : Kind : : GenericSpecializationParam & & <nl> + OldNum > 1 & & NewNum = = 1 ) <nl> + OldNum = 1 ; <nl> + <nl> + if ( OldNum ! = NewNum ) { <nl> + return false ; <nl> + } <nl> + for ( unsigned Idx = 0 , End = OldNum ; Idx < End ; + + Idx ) { <nl> + if ( ! areTreesEqual ( Old - > getChild ( Idx ) , New - > getChild ( Idx ) ) ) <nl> + return false ; <nl> + } <nl> + return true ; <nl> + } <nl> + <nl> + static bool containsDependentAssociatedTypeRef ( Demangle : : NodePointer Nd ) { <nl> + if ( Nd - > getKind ( ) = = Demangle : : Node : : Kind : : DependentAssociatedTypeRef ) <nl> + return true ; <nl> + <nl> + for ( auto Child : * Nd ) { <nl> + if ( containsDependentAssociatedTypeRef ( Child ) ) <nl> + return true ; <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> + # endif / / CHECK_MANGLING_AGAINST_OLD <nl> + <nl> + struct SizeStatEntry { <nl> + int sizeDiff ; <nl> + std : : string Old ; <nl> + std : : string New ; <nl> + } ; <nl> + <nl> + static std : : vector < SizeStatEntry > SizeStats ; <nl> + <nl> + static int numSmaller = 0 ; <nl> + static int numEqual = 0 ; <nl> + static int numLarger = 0 ; <nl> + static int totalOldSize = 0 ; <nl> + static int totalNewSize = 0 ; <nl> + static int mergedSubsts = 0 ; <nl> + <nl> + struct OpStatEntry { <nl> + OpStatEntry ( ) : num ( 0 ) , size ( 0 ) { } <nl> + <nl> + int num ; <nl> + int size ; <nl> + } ; <nl> + <nl> + static llvm : : StringMap < OpStatEntry > OpStats ; <nl> + <nl> + } / / end anonymous namespace <nl> + <nl> + void Mangler : : recordOpStatImpl ( StringRef op , size_t OldPos ) { <nl> + if ( PrintSwiftManglingStats ) { <nl> + OpStatEntry & E = OpStats [ op ] ; <nl> + E . num + + ; <nl> + E . size + = Storage . size ( ) - OldPos ; <nl> + } <nl> + } <nl> + <nl> + # endif / / NDEBUG <nl> + <nl> + std : : string NewMangling : : selectMangling ( const std : : string & Old , <nl> + const std : : string & New ) { <nl> + # ifndef NDEBUG <nl> + # ifdef CHECK_MANGLING_AGAINST_OLD <nl> + <nl> + static int numCmp = 0 ; <nl> + using namespace Demangle ; <nl> + <nl> + NodePointer OldNode = demangleSymbolAsNode ( Old ) ; <nl> + NodePointer NewNode = demangleSymbolAsNode ( New ) ; <nl> + <nl> + if ( OldNode ) { <nl> + if ( ! areTreesEqual ( OldNode , NewNode ) ) { <nl> + llvm : : errs ( ) < < " Mangling differs at # " < < numCmp < < " : \ n " <nl> + " old : " < < Old < < " \ n " <nl> + " new : " < < New < < " \ n \ n " <nl> + " # # # old tree : # # # \ n " ; <nl> + demangle_wrappers : : NodeDumper ( OldNode ) . print ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < " \ n # # # new tree : # # # \ n " ; <nl> + demangle_wrappers : : NodeDumper ( NewNode ) . print ( llvm : : errs ( ) ) ; <nl> + llvm : : errs ( ) < < ' \ n ' ; <nl> + assert ( false ) ; <nl> + } <nl> + if ( StringRef ( New ) . startswith ( MANGLING_PREFIX_STR ) ) { <nl> + std : : string Remangled = mangleNodeNew ( NewNode ) ; <nl> + if ( New ! = Remangled ) { <nl> + bool isEqual = false ; <nl> + if ( containsDependentAssociatedTypeRef ( NewNode ) ) { <nl> + NodePointer RemangledNode = demangleSymbolAsNode ( Remangled ) ; <nl> + isEqual = areTreesEqual ( RemangledNode , NewNode ) ; <nl> + } <nl> + if ( ! isEqual ) { <nl> + llvm : : errs ( ) < < " Remangling failed at # " < < numCmp < < " : \ n " <nl> + " original : " < < New < < " \ n " <nl> + " remangled : " < < Remangled < < " \ n " ; <nl> + assert ( false ) ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + numCmp + + ; <nl> + # endif / / CHECK_MANGLING_AGAINST_OLD <nl> + <nl> + if ( PrintSwiftManglingStats ) { <nl> + int OldSize = ( int ) Old . size ( ) ; <nl> + int NewSize = ( int ) New . size ( ) ; <nl> + if ( NewSize > OldSize ) { <nl> + numLarger + + ; <nl> + SizeStats . push_back ( { NewSize - OldSize , Old , New } ) ; <nl> + } else if ( OldSize > NewSize ) { <nl> + numSmaller + + ; <nl> + } else { <nl> + numEqual + + ; <nl> + } <nl> + totalOldSize + = OldSize ; <nl> + totalNewSize + = NewSize ; <nl> + } <nl> + # endif / / NDEBUG <nl> + <nl> + return useNewMangling ( ) ? New : Old ; <nl> + } <nl> + <nl> + void NewMangling : : printManglingStats ( ) { <nl> + # ifndef NDEBUG <nl> + if ( ! PrintSwiftManglingStats ) <nl> + return ; <nl> + <nl> + std : : sort ( SizeStats . begin ( ) , SizeStats . end ( ) , <nl> + [ ] ( const SizeStatEntry & LHS , const SizeStatEntry & RHS ) { <nl> + return LHS . sizeDiff < RHS . sizeDiff ; <nl> + } ) ; <nl> + <nl> + llvm : : outs ( ) < < " Mangling size stats : \ n " <nl> + " num smaller : " < < numSmaller < < " \ n " <nl> + " num larger : " < < numLarger < < " \ n " <nl> + " num equal : " < < numEqual < < " \ n " <nl> + " total old size : " < < totalOldSize < < " \ n " <nl> + " total new size : " < < totalNewSize < < " \ n " <nl> + " new - old size : " < < ( totalNewSize - totalOldSize ) < < " \ n " <nl> + " List or larger : \ n " ; <nl> + for ( const SizeStatEntry & E : SizeStats ) { <nl> + llvm : : outs ( ) < < " delta " < < E . sizeDiff < < " : " < < E . Old < < " - " < < E . New <nl> + < < ' \ n ' ; <nl> + } <nl> + <nl> + llvm : : outs ( ) < < " Mangling operator stats : \ n " ; <nl> + <nl> + typedef llvm : : StringMapEntry < OpStatEntry > MapEntry ; <nl> + std : : vector < const MapEntry * > SortedOpStats ; <nl> + for ( const MapEntry & ME : OpStats ) { <nl> + SortedOpStats . push_back ( & ME ) ; <nl> + } <nl> + std : : sort ( SortedOpStats . begin ( ) , SortedOpStats . end ( ) , <nl> + [ ] ( const MapEntry * LHS , const MapEntry * RHS ) { <nl> + return LHS - > getKey ( ) < RHS - > getKey ( ) ; <nl> + } ) ; <nl> + <nl> + for ( const MapEntry * E : SortedOpStats ) { <nl> + llvm : : outs ( ) < < " " < < E - > getKey ( ) < < " : num = " < < E - > getValue ( ) . num <nl> + < < " , size = " < < E - > getValue ( ) . size < < ' \ n ' ; <nl> + } <nl> + llvm : : outs ( ) < < " merged substitutions : " < < mergedSubsts < < ' \ n ' ; <nl> + # endif <nl> + } <nl> + <nl> + void Mangler : : beginMangling ( ) { <nl> + Buffer < < MANGLING_PREFIX_STR ; <nl> + } <nl> + <nl> + / / / Finish the mangling of the symbol and return the mangled name . <nl> + std : : string Mangler : : finalize ( ) { <nl> + assert ( Storage . size ( ) & & " Mangling an empty name " ) ; <nl> + std : : string result = std : : string ( Storage . data ( ) , Storage . size ( ) ) ; <nl> + Storage . clear ( ) ; <nl> + return result ; <nl> + } <nl> + <nl> + / / / Finish the mangling of the symbol and write the mangled name into <nl> + / / / \ p stream . <nl> + void Mangler : : finalize ( llvm : : raw_ostream & stream ) { <nl> + std : : string result = finalize ( ) ; <nl> + stream . write ( result . data ( ) , result . size ( ) ) ; <nl> + } <nl> + <nl> + void Mangler : : appendIdentifier ( StringRef ident ) { <nl> + auto Iter = StringSubstitutions . find ( ident ) ; <nl> + if ( Iter ! = StringSubstitutions . end ( ) ) <nl> + return mangleSubstitution ( Iter - > second ) ; <nl> + <nl> + size_t OldPos = Storage . size ( ) ; <nl> + addSubstitution ( ident ) ; <nl> + <nl> + mangleIdentifier ( * this , ident ) ; <nl> + <nl> + recordOpStat ( " < identifier > " , OldPos ) ; <nl> + } <nl> + <nl> + bool Mangler : : tryMangleSubstitution ( const void * ptr ) { <nl> + auto ir = Substitutions . find ( ptr ) ; <nl> + if ( ir = = Substitutions . end ( ) ) <nl> + return false ; <nl> + <nl> + mangleSubstitution ( ir - > second ) ; <nl> + return true ; <nl> + } <nl> + <nl> + void Mangler : : mangleSubstitution ( unsigned Idx ) { <nl> + if ( Idx > = 26 ) <nl> + return appendOperator ( " A " , Index ( Idx - 26 ) ) ; <nl> + <nl> + char c = Idx + ' A ' ; <nl> + if ( lastSubstIdx = = ( int ) Storage . size ( ) - 1 ) { <nl> + assert ( isUpperLetter ( Storage [ lastSubstIdx ] ) ) ; <nl> + Storage [ lastSubstIdx ] = Storage [ lastSubstIdx ] - ' A ' + ' a ' ; <nl> + Buffer < < c ; <nl> + # ifndef NDEBUG <nl> + mergedSubsts + + ; <nl> + # endif <nl> + } else { <nl> + appendOperator ( " A " , StringRef ( & c , 1 ) ) ; <nl> + } <nl> + lastSubstIdx = ( int ) Storage . size ( ) - 1 ; <nl> + } <nl> + <nl> new file mode 100644 <nl> index 000000000000 . . a95460665269 <nl> mmm / dev / null <nl> ppp b / lib / Basic / ManglingUtils . cpp <nl> <nl> + / / = = = mmm ManglingUtils . cpp - Utilities for Swift name mangling mmmmmmmmmmmm = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / Basic / ManglingUtils . h " <nl> + <nl> + using namespace swift ; <nl> + using namespace NewMangling ; <nl> + <nl> + <nl> + bool NewMangling : : isNonAscii ( StringRef str ) { <nl> + for ( unsigned char c : str ) { <nl> + if ( c > = 0x80 ) <nl> + return true ; <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> + bool NewMangling : : needsPunycodeEncoding ( StringRef str ) { <nl> + for ( unsigned char c : str ) { <nl> + if ( ! isValidSymbolChar ( c ) ) <nl> + return true ; <nl> + } <nl> + return false ; <nl> + } <nl> + <nl> + / / / Translate the given operator character into its mangled form . <nl> + / / / <nl> + / / / Current operator characters : @ / = - + * % < > ! & | ^ ~ and the special operator ' . . ' <nl> + char NewMangling : : translateOperatorChar ( char op ) { <nl> + switch ( op ) { <nl> + case ' & ' : return ' a ' ; / / ' and ' <nl> + case ' @ ' : return ' c ' ; / / ' commercial at sign ' <nl> + case ' / ' : return ' d ' ; / / ' divide ' <nl> + case ' = ' : return ' e ' ; / / ' equal ' <nl> + case ' > ' : return ' g ' ; / / ' greater ' <nl> + case ' < ' : return ' l ' ; / / ' less ' <nl> + case ' * ' : return ' m ' ; / / ' multiply ' <nl> + case ' ! ' : return ' n ' ; / / ' negate ' <nl> + case ' | ' : return ' o ' ; / / ' or ' <nl> + case ' + ' : return ' p ' ; / / ' plus ' <nl> + case ' ? ' : return ' q ' ; / / ' question ' <nl> + case ' % ' : return ' r ' ; / / ' remainder ' <nl> + case ' - ' : return ' s ' ; / / ' subtract ' <nl> + case ' ~ ' : return ' t ' ; / / ' tilde ' <nl> + case ' ^ ' : return ' x ' ; / / ' xor ' <nl> + case ' . ' : return ' z ' ; / / ' zperiod ' ( the z is silent ) <nl> + default : <nl> + return op ; <nl> + } <nl> + } <nl> + <nl> + std : : string NewMangling : : translateOperator ( StringRef Op ) { <nl> + std : : string Encoded ; <nl> + for ( char ch : Op ) { <nl> + Encoded . push_back ( translateOperatorChar ( ch ) ) ; <nl> + } <nl> + return Encoded ; <nl> + } <nl> mmm a / lib / Basic / PunycodeUTF8 . cpp <nl> ppp b / lib / Basic / PunycodeUTF8 . cpp <nl> <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> # include " swift / Basic / Punycode . h " <nl> + # include " swift / Basic / ManglingUtils . h " <nl> # include < vector > <nl> <nl> using namespace swift ; <nl> static bool isContinuationByte ( uint8_t unit ) { <nl> return ( unit & 0xC0 ) = = 0x80 ; <nl> } <nl> <nl> - static bool isValidSymbolChar ( char ch ) { <nl> - return ( ch > = ' a ' & & ch < = ' z ' ) | | ( ch > = ' A ' & & ch < = ' Z ' ) | | <nl> - ( ch > = ' 0 ' & & ch < = ' 9 ' ) | | ch = = ' _ ' | | ch = = ' $ ' ; <nl> - } <nl> - <nl> / / / Reencode well - formed UTF - 8 as UTF - 32 . <nl> / / / <nl> / / / This entry point is only called from compiler - internal entry points , so does <nl> static bool convertUTF8toUTF32 ( StringRef InputUTF8 , <nl> while ( ptr < end ) { <nl> uint8_t first = * ptr + + ; <nl> if ( first < 0x80 ) { <nl> - if ( isValidSymbolChar ( first ) | | ! mapNonSymbolChars ) { <nl> + if ( NewMangling : : isValidSymbolChar ( first ) | | ! mapNonSymbolChars ) { <nl> OutUTF32 . push_back ( first ) ; <nl> } else { <nl> OutUTF32 . push_back ( ( uint32_t ) first + 0xD800 ) ; <nl> mmm a / lib / Basic / Remangle . cpp <nl> ppp b / lib / Basic / Remangle . cpp <nl> namespace { <nl> unreachable ( " bad demangling tree node " ) ; <nl> } <nl> <nl> - NodePointer getUnspecialized ( Node * node ) ; <nl> void mangleGenericArgs ( Node * node , EntityContext & ctx ) ; <nl> void mangleAnyNominalType ( Node * node , EntityContext & ctx ) ; <nl> <nl> void Remangler : : resetSubstitutions ( ) { <nl> Substitutions . clear ( ) ; <nl> } <nl> <nl> - bool Remangler : : trySubstitution ( Node * node , SubstitutionEntry & entry ) { <nl> - auto isInSwiftModule = [ ] ( Node * node ) - > bool { <nl> - auto context = node - > begin ( ) - > get ( ) ; <nl> - return ( context - > getKind ( ) = = Node : : Kind : : Module & & <nl> - context - > getText ( ) = = STDLIB_NAME ) ; <nl> - } ; <nl> + static bool isInSwiftModule ( Node * node ) { <nl> + auto context = node - > begin ( ) - > get ( ) ; <nl> + return ( context - > getKind ( ) = = Node : : Kind : : Module & & <nl> + context - > getText ( ) = = STDLIB_NAME ) ; <nl> + } ; <nl> <nl> + bool Demangle : : mangleStandardSubstitution ( Node * node , DemanglerPrinter & Out ) { <nl> / / Look for known substitutions . <nl> switch ( node - > getKind ( ) ) { <nl> # define SUCCESS_IF_IS ( VALUE , EXPECTED , SUBSTITUTION ) \ <nl> bool Remangler : : trySubstitution ( Node * node , SubstitutionEntry & entry ) { <nl> # undef SUCCESS_IF_TEXT_IS <nl> # undef SUCCESS_IF_IS <nl> } <nl> + return false ; <nl> + } <nl> + <nl> + bool Remangler : : trySubstitution ( Node * node , SubstitutionEntry & entry ) { <nl> + if ( Demangle : : mangleStandardSubstitution ( node , Out ) ) <nl> + return true ; <nl> <nl> / / Go ahead and initialize the substitution entry . <nl> entry . TheNode = node ; <nl> void Remangler : : mangleProtocolWithoutPrefix ( Node * node ) { <nl> mangleNominalType ( node , ' \ 0 ' , ctx ) ; <nl> } <nl> <nl> - static bool isSpecialized ( Node * node ) { <nl> + bool Demangle : : isSpecialized ( Node * node ) { <nl> switch ( node - > getKind ( ) ) { <nl> case Node : : Kind : : BoundGenericStructure : <nl> case Node : : Kind : : BoundGenericEnum : <nl> static bool isSpecialized ( Node * node ) { <nl> } <nl> } <nl> <nl> - NodePointer Remangler : : getUnspecialized ( Node * node ) { <nl> + NodePointer Demangle : : getUnspecialized ( Node * node ) { <nl> switch ( node - > getKind ( ) ) { <nl> case Node : : Kind : : Structure : <nl> case Node : : Kind : : Enum : <nl> void Remangler : : mangleTypeList ( Node * node ) { <nl> Out < < ' _ ' ; <nl> } <nl> <nl> + void Remangler : : mangleReflectionMetadataBuiltinDescriptor ( Node * node ) { <nl> + Out < < " MRb " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataFieldDescriptor ( Node * node ) { <nl> + Out < < " MRf " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataAssocTypeDescriptor ( Node * node ) { <nl> + Out < < " MRa " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataSuperclassDescriptor ( Node * node ) { <nl> + Out < < " MRc " ; <nl> + } <nl> + <nl> + void Remangler : : mangleCurryThunk ( Node * node , EntityContext & ctx ) { <nl> + Out < < " < curry - thunk > " ; <nl> + } <nl> + <nl> + void Remangler : : mangleEmptyList ( Node * node ) { <nl> + Out < < " < empty > " ; <nl> + } <nl> + <nl> + void Remangler : : mangleFirstElementMarker ( Node * node ) { <nl> + Out < < " < first > " ; <nl> + } <nl> + <nl> + void Remangler : : mangleVariadicMarker ( Node * node ) { <nl> + Out < < " < vararg > " ; <nl> + } <nl> + <nl> / / / The top - level interface to the remangler . <nl> std : : string Demangle : : mangleNode ( const NodePointer & node ) { <nl> if ( ! node ) return " " ; <nl> new file mode 100644 <nl> index 000000000000 . . 979d9c3f2247 <nl> mmm / dev / null <nl> ppp b / lib / Basic / Remangler . cpp <nl> <nl> + / / = = = mmm Remangler . cpp - Swift re - mangling from a demangling tree mmmmmmmmm = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See https : / / swift . org / LICENSE . txt for license information <nl> + / / See https : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This file implements the remangler , which turns a demangling parse <nl> + / / tree back into a mangled string . This is useful for tools which <nl> + / / want to extract subtrees from mangled strings . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / Basic / Demangle . h " <nl> + # include " swift / Basic / LLVM . h " <nl> + # include " swift / Basic / Punycode . h " <nl> + # include " swift / Basic / Range . h " <nl> + # include " swift / Basic / UUID . h " <nl> + # include " swift / Basic / ManglingUtils . h " <nl> + # include " swift / Basic / Fallthrough . h " <nl> + # include " swift / Basic / ManglingMacros . h " <nl> + # include " swift / Strings . h " <nl> + # include " llvm / ADT / StringRef . h " <nl> + # include " llvm / ADT / StringSwitch . h " <nl> + # include < vector > <nl> + # include < cstdio > <nl> + # include < cstdlib > <nl> + # include < unordered_map > <nl> + <nl> + using namespace swift ; <nl> + using namespace Demangle ; <nl> + using namespace NewMangling ; <nl> + <nl> + [ [ noreturn ] ] <nl> + static void unreachable ( const char * Message ) { <nl> + fprintf ( stderr , " fatal error : % s \ n " , Message ) ; <nl> + std : : abort ( ) ; <nl> + } <nl> + <nl> + namespace { <nl> + <nl> + class SubstitutionEntry { <nl> + Node * TheNode = nullptr ; <nl> + size_t StoredHash = 0 ; <nl> + bool NewMangling = false ; <nl> + <nl> + public : <nl> + void setNode ( Node * node , bool UseNewMangling ) { <nl> + NewMangling = UseNewMangling ; <nl> + TheNode = node ; <nl> + deepHash ( node ) ; <nl> + } <nl> + <nl> + struct Hasher { <nl> + size_t operator ( ) ( const SubstitutionEntry & entry ) const { <nl> + return entry . StoredHash ; <nl> + } <nl> + } ; <nl> + <nl> + private : <nl> + friend bool operator = = ( const SubstitutionEntry & lhs , <nl> + const SubstitutionEntry & rhs ) { <nl> + return ( lhs . StoredHash = = rhs . StoredHash & & <nl> + lhs . deepEquals ( lhs . TheNode , rhs . TheNode ) ) ; <nl> + } <nl> + <nl> + bool treatAsIdentifier ( Node * node ) const { <nl> + if ( ! NewMangling ) <nl> + return false ; <nl> + <nl> + switch ( node - > getKind ( ) ) { <nl> + case Node : : Kind : : Module : <nl> + case Node : : Kind : : TupleElementName : <nl> + case Node : : Kind : : InfixOperator : <nl> + case Node : : Kind : : PrefixOperator : <nl> + case Node : : Kind : : PostfixOperator : <nl> + case Node : : Kind : : DependentAssociatedTypeRef : <nl> + case Node : : Kind : : Identifier : <nl> + return true ; <nl> + default : <nl> + return false ; <nl> + } <nl> + } <nl> + <nl> + void combineHash ( size_t newValue ) { <nl> + StoredHash = 33 * StoredHash + newValue ; <nl> + } <nl> + <nl> + void combineHash ( StringRef Text ) { <nl> + for ( char c : Text ) { <nl> + combineHash ( ( unsigned char ) c ) ; <nl> + } <nl> + } <nl> + <nl> + void deepHash ( Node * node ) { <nl> + if ( treatAsIdentifier ( node ) ) { <nl> + combineHash ( ( size_t ) Node : : Kind : : Identifier ) ; <nl> + combineHash ( node - > getText ( ) ) ; <nl> + return ; <nl> + } <nl> + combineHash ( ( size_t ) node - > getKind ( ) ) ; <nl> + if ( node - > hasIndex ( ) ) { <nl> + combineHash ( node - > getIndex ( ) ) ; <nl> + } else if ( node - > hasText ( ) ) { <nl> + combineHash ( node - > getText ( ) ) ; <nl> + } <nl> + for ( const auto & child : * node ) { <nl> + deepHash ( child . get ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + bool deepEquals ( Node * lhs , Node * rhs ) const ; <nl> + } ; <nl> + <nl> + bool SubstitutionEntry : : deepEquals ( Node * lhs , Node * rhs ) const { <nl> + if ( treatAsIdentifier ( lhs ) & & treatAsIdentifier ( rhs ) ) <nl> + return lhs - > getText ( ) = = rhs - > getText ( ) ; <nl> + <nl> + if ( lhs - > getKind ( ) ! = rhs - > getKind ( ) ) <nl> + return false ; <nl> + if ( lhs - > hasIndex ( ) ) { <nl> + if ( ! rhs - > hasIndex ( ) ) <nl> + return false ; <nl> + if ( lhs - > getIndex ( ) ! = rhs - > getIndex ( ) ) <nl> + return false ; <nl> + } else if ( lhs - > hasText ( ) ) { <nl> + if ( ! rhs - > hasText ( ) ) <nl> + return false ; <nl> + if ( lhs - > getText ( ) ! = rhs - > getText ( ) ) <nl> + return false ; <nl> + } else if ( rhs - > hasIndex ( ) | | rhs - > hasText ( ) ) { <nl> + return false ; <nl> + } <nl> + <nl> + if ( lhs - > getNumChildren ( ) ! = rhs - > getNumChildren ( ) ) <nl> + return false ; <nl> + <nl> + for ( auto li = lhs - > begin ( ) , ri = lhs - > begin ( ) , le = lhs - > end ( ) ; <nl> + li ! = le ; + + li , + + ri ) { <nl> + if ( ! deepEquals ( li - > get ( ) , ri - > get ( ) ) ) <nl> + return false ; <nl> + } <nl> + <nl> + return true ; <nl> + } <nl> + <nl> + class Remangler { <nl> + template < typename Mangler > <nl> + friend void NewMangling : : mangleIdentifier ( Mangler & M , StringRef ident ) ; <nl> + <nl> + const bool UsePunycode = true ; <nl> + <nl> + DemanglerPrinter & Buffer ; <nl> + <nl> + std : : vector < SubstitutionWord > Words ; <nl> + std : : vector < WordReplacement > SubstWordsInIdent ; <nl> + <nl> + std : : unordered_map < SubstitutionEntry , unsigned , <nl> + SubstitutionEntry : : Hasher > Substitutions ; <nl> + <nl> + int lastSubstIdx = - 2 ; <nl> + <nl> + / / We have to cons up temporary nodes sometimes when remangling <nl> + / / nested generics . This vector owns them . <nl> + std : : vector < NodePointer > TemporaryNodes ; <nl> + <nl> + StringRef getBufferStr ( ) const { return Buffer . getStringRef ( ) ; } <nl> + <nl> + template < typename Mangler > <nl> + friend void mangleIdentifier ( Mangler & M , StringRef ident ) ; <nl> + <nl> + class EntityContext { <nl> + bool AsContext = false ; <nl> + public : <nl> + bool isAsContext ( ) const { <nl> + return AsContext ; <nl> + } <nl> + <nl> + class ManglingContextRAII { <nl> + EntityContext & Ctx ; <nl> + bool SavedValue ; <nl> + public : <nl> + ManglingContextRAII ( EntityContext & ctx ) <nl> + : Ctx ( ctx ) , SavedValue ( ctx . AsContext ) { <nl> + ctx . AsContext = true ; <nl> + } <nl> + <nl> + ~ ManglingContextRAII ( ) { <nl> + Ctx . AsContext = SavedValue ; <nl> + } <nl> + } ; <nl> + } ; <nl> + <nl> + Node * getSingleChild ( Node * node ) { <nl> + assert ( node - > getNumChildren ( ) = = 1 ) ; <nl> + return node - > getFirstChild ( ) . get ( ) ; <nl> + } <nl> + <nl> + Node * getSingleChild ( Node * node , Node : : Kind kind ) { <nl> + Node * Child = getSingleChild ( node ) ; <nl> + assert ( Child - > getKind ( ) = = kind ) ; <nl> + return Child ; <nl> + } <nl> + <nl> + Node * getChildOfType ( Node * node ) { <nl> + assert ( node - > getKind ( ) = = Node : : Kind : : Type ) ; <nl> + return getSingleChild ( node ) ; <nl> + } <nl> + <nl> + void mangleIndex ( Node : : IndexType value ) { <nl> + if ( value = = 0 ) { <nl> + Buffer < < ' _ ' ; <nl> + } else { <nl> + Buffer < < ( value - 1 ) < < ' _ ' ; <nl> + } <nl> + } <nl> + <nl> + void mangleChildNodes ( Node * node ) { <nl> + mangleNodes ( node - > begin ( ) , node - > end ( ) ) ; <nl> + } <nl> + void mangleChildNodesReversed ( Node * node ) { <nl> + for ( size_t Idx = 0 , Num = node - > getNumChildren ( ) ; Idx < Num ; + + Idx ) { <nl> + mangleChildNode ( node , Num - Idx - 1 ) ; <nl> + } <nl> + } <nl> + <nl> + void mangleListSeparator ( bool & isFirstListItem ) { <nl> + if ( isFirstListItem ) { <nl> + Buffer < < ' _ ' ; <nl> + isFirstListItem = false ; <nl> + } <nl> + } <nl> + <nl> + void mangleEndOfList ( bool isFirstListItem ) { <nl> + if ( isFirstListItem ) <nl> + Buffer < < ' y ' ; <nl> + } <nl> + <nl> + void mangleNodes ( Node : : iterator i , Node : : iterator e ) { <nl> + for ( ; i ! = e ; + + i ) { <nl> + mangle ( i - > get ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + void mangleSingleChildNode ( Node * node ) { <nl> + assert ( node - > getNumChildren ( ) = = 1 ) ; <nl> + mangle ( node - > begin ( ) - > get ( ) ) ; <nl> + } <nl> + <nl> + void mangleChildNode ( Node * node , unsigned index ) { <nl> + assert ( index < node - > getNumChildren ( ) ) ; <nl> + mangle ( node - > begin ( ) [ index ] . get ( ) ) ; <nl> + } <nl> + <nl> + void manglePureProtocol ( Node * Proto ) { <nl> + if ( Proto - > getKind ( ) = = Node : : Kind : : Type ) <nl> + Proto = getSingleChild ( Proto , Node : : Kind : : Protocol ) ; <nl> + mangleChildNodes ( Proto ) ; <nl> + } <nl> + <nl> + bool trySubstitution ( Node * node , SubstitutionEntry & entry ) ; <nl> + void addSubstitution ( const SubstitutionEntry & entry ) ; <nl> + <nl> + void mangleIdentifierImpl ( Node * node , bool isOperator ) ; <nl> + <nl> + void mangleDependentGenericParamIndex ( Node * node , <nl> + const char * nonZeroPrefix = " " , <nl> + char zeroOp = ' z ' ) ; <nl> + <nl> + std : : pair < int , Node * > mangleConstrainedType ( Node * node ) ; <nl> + <nl> + void mangleFunctionSignature ( Node * FuncType ) { <nl> + mangleChildNodesReversed ( FuncType ) ; <nl> + } <nl> + <nl> + void mangleAnyNominalType ( Node * node ) ; <nl> + void mangleNominalType ( Node * node , char TypeOp ) ; <nl> + void mangleGenericArgs ( Node * node ) ; <nl> + <nl> + # define NODE ( ID ) \ <nl> + void mangle # # ID ( Node * node ) ; <nl> + # define CONTEXT_NODE ( ID ) \ <nl> + void mangle # # ID ( Node * node ) ; \ <nl> + / / void mangle # # ID ( Node * node , EntityContext & ctx ) ; <nl> + # include " swift / Basic / DemangleNodes . def " <nl> + <nl> + public : <nl> + Remangler ( DemanglerPrinter & Buffer ) : Buffer ( Buffer ) { } <nl> + <nl> + void mangle ( Node * node ) { <nl> + switch ( node - > getKind ( ) ) { <nl> + # define NODE ( ID ) case Node : : Kind : : ID : return mangle # # ID ( node ) ; <nl> + # include " swift / Basic / DemangleNodes . def " <nl> + } <nl> + unreachable ( " bad demangling tree node " ) ; <nl> + } <nl> + } ; <nl> + <nl> + bool Remangler : : trySubstitution ( Node * node , SubstitutionEntry & entry ) { <nl> + if ( mangleStandardSubstitution ( node , Buffer ) ) <nl> + return true ; <nl> + <nl> + / / Go ahead and initialize the substitution entry . <nl> + entry . setNode ( node , / * UseNewMangling * / true ) ; <nl> + <nl> + auto it = Substitutions . find ( entry ) ; <nl> + if ( it = = Substitutions . end ( ) ) <nl> + return false ; <nl> + <nl> + unsigned Idx = it - > second ; <nl> + if ( Idx > = 26 ) { <nl> + Buffer < < ' A ' ; <nl> + mangleIndex ( Idx - 26 ) ; <nl> + return true ; <nl> + } <nl> + char c = Idx + ' A ' ; <nl> + if ( lastSubstIdx = = ( int ) Buffer . getStringRef ( ) . size ( ) - 1 ) { <nl> + char & lastChar = Buffer . lastChar ( ) ; <nl> + assert ( isUpperLetter ( lastChar ) ) ; <nl> + lastChar = lastChar - ' A ' + ' a ' ; <nl> + Buffer < < c ; <nl> + } else { <nl> + Buffer < < ' A ' < < c ; <nl> + } <nl> + lastSubstIdx = Buffer . getStringRef ( ) . size ( ) - 1 ; <nl> + return true ; <nl> + } <nl> + <nl> + void Remangler : : addSubstitution ( const SubstitutionEntry & entry ) { <nl> + unsigned Idx = Substitutions . size ( ) ; <nl> + # if false <nl> + llvm : : outs ( ) < < " add subst " ; <nl> + if ( Idx < 26 ) { <nl> + llvm : : outs ( ) < < char ( ' A ' + Idx ) ; <nl> + } else { <nl> + llvm : : outs ( ) < < Idx ; <nl> + } <nl> + llvm : : outs ( ) < < " at pos " < < getBufferStr ( ) . size ( ) < < ' \ n ' ; <nl> + # endif <nl> + auto result = Substitutions . insert ( { entry , Idx } ) ; <nl> + assert ( result . second ) ; <nl> + ( void ) result ; <nl> + } <nl> + <nl> + void Remangler : : mangleIdentifierImpl ( Node * node , bool isOperator ) { <nl> + SubstitutionEntry entry ; <nl> + if ( trySubstitution ( node , entry ) ) return ; <nl> + if ( isOperator ) { <nl> + NewMangling : : mangleIdentifier ( * this , <nl> + NewMangling : : translateOperator ( node - > getText ( ) ) ) ; <nl> + } else { <nl> + NewMangling : : mangleIdentifier ( * this , node - > getText ( ) ) ; <nl> + } <nl> + addSubstitution ( entry ) ; <nl> + } <nl> + <nl> + <nl> + void Remangler : : mangleDependentGenericParamIndex ( Node * node , <nl> + const char * nonZeroPrefix , <nl> + char zeroOp ) { <nl> + auto depth = node - > getChild ( 0 ) - > getIndex ( ) ; <nl> + auto index = node - > getChild ( 1 ) - > getIndex ( ) ; <nl> + <nl> + if ( depth ! = 0 ) { <nl> + Buffer < < nonZeroPrefix < < ' d ' ; <nl> + mangleIndex ( depth - 1 ) ; <nl> + mangleIndex ( index ) ; <nl> + return ; <nl> + } <nl> + if ( index ! = 0 ) { <nl> + Buffer < < nonZeroPrefix ; <nl> + mangleIndex ( index - 1 ) ; <nl> + return ; <nl> + } <nl> + / / depth = = index = = 0 <nl> + Buffer < < zeroOp ; <nl> + } <nl> + <nl> + std : : pair < int , Node * > Remangler : : mangleConstrainedType ( Node * node ) { <nl> + if ( node - > getKind ( ) = = Node : : Kind : : Type ) <nl> + node = getChildOfType ( node ) ; <nl> + <nl> + SubstitutionEntry entry ; <nl> + if ( trySubstitution ( node , entry ) ) <nl> + return { - 1 , nullptr } ; <nl> + <nl> + std : : vector < Node * > Chain ; <nl> + while ( node - > getKind ( ) = = Node : : Kind : : DependentMemberType ) { <nl> + Chain . push_back ( node - > getChild ( 1 ) . get ( ) ) ; <nl> + node = getChildOfType ( node - > getFirstChild ( ) . get ( ) ) ; <nl> + } <nl> + assert ( node - > getKind ( ) = = Node : : Kind : : DependentGenericParamType ) ; <nl> + <nl> + const char * ListSeparator = ( Chain . size ( ) > 1 ? " _ " : " " ) ; <nl> + for ( Node * DepAssocTyRef : reversed ( Chain ) ) { <nl> + mangle ( DepAssocTyRef ) ; <nl> + Buffer < < ListSeparator ; <nl> + ListSeparator = " " ; <nl> + } <nl> + if ( Chain . size ( ) > 0 ) <nl> + addSubstitution ( entry ) ; <nl> + return { ( int ) Chain . size ( ) , node } ; <nl> + } <nl> + <nl> + void Remangler : : mangleNominalType ( Node * node , char TypeOp ) { <nl> + SubstitutionEntry entry ; <nl> + if ( trySubstitution ( node , entry ) ) return ; <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < TypeOp ; <nl> + addSubstitution ( entry ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleAnyNominalType ( Node * node ) { <nl> + if ( isSpecialized ( node ) ) { <nl> + NodePointer unboundType = getUnspecialized ( node ) ; <nl> + TemporaryNodes . push_back ( unboundType ) ; <nl> + mangleGenericArgs ( node ) ; <nl> + mangleAnyNominalType ( unboundType . get ( ) ) ; <nl> + Buffer < < ' G ' ; <nl> + return ; <nl> + } <nl> + switch ( node - > getKind ( ) ) { <nl> + case Node : : Kind : : Structure : return mangleNominalType ( node , ' V ' ) ; <nl> + case Node : : Kind : : Enum : return mangleNominalType ( node , ' O ' ) ; <nl> + case Node : : Kind : : Class : return mangleNominalType ( node , ' C ' ) ; <nl> + default : <nl> + unreachable ( " bad nominal type kind " ) ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleGenericArgs ( Node * node ) { <nl> + switch ( node - > getKind ( ) ) { <nl> + case Node : : Kind : : Structure : <nl> + case Node : : Kind : : Enum : <nl> + case Node : : Kind : : Class : { <nl> + NodePointer parentOrModule = node - > getChild ( 0 ) ; <nl> + mangleGenericArgs ( parentOrModule . get ( ) ) ; <nl> + <nl> + / / No generic arguments at this level <nl> + Buffer < < ' y ' ; <nl> + break ; <nl> + } <nl> + <nl> + case Node : : Kind : : BoundGenericStructure : <nl> + case Node : : Kind : : BoundGenericEnum : <nl> + case Node : : Kind : : BoundGenericClass : { <nl> + NodePointer unboundType = node - > getChild ( 0 ) ; <nl> + assert ( unboundType - > getKind ( ) = = Node : : Kind : : Type ) ; <nl> + NodePointer nominalType = unboundType - > getChild ( 0 ) ; <nl> + NodePointer parentOrModule = nominalType - > getChild ( 0 ) ; <nl> + mangleGenericArgs ( parentOrModule . get ( ) ) ; <nl> + <nl> + mangleTypeList ( node - > getChild ( 1 ) . get ( ) ) ; <nl> + break ; <nl> + } <nl> + <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleAllocator ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fC " ; <nl> + } <nl> + <nl> + void Remangler : : mangleArchetype ( Node * node ) { <nl> + unreachable ( " unsupported node " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleArchetypeRef ( Node * node ) { <nl> + Node : : IndexType relativeDepth = node - > getChild ( 0 ) - > getIndex ( ) ; <nl> + Node : : IndexType index = node - > getChild ( 1 ) - > getIndex ( ) ; <nl> + <nl> + Buffer < < ' Q ' ; <nl> + if ( relativeDepth ! = 0 ) { <nl> + Buffer < < ' d ' ; <nl> + mangleIndex ( relativeDepth - 1 ) ; <nl> + } <nl> + mangleIndex ( index ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleArgumentTuple ( Node * node ) { <nl> + Node * Ty = getSingleChild ( node , Node : : Kind : : Type ) ; <nl> + Node * Child = getSingleChild ( Ty ) ; <nl> + if ( Child - > getKind ( ) = = Node : : Kind : : NonVariadicTuple & & <nl> + Child - > getNumChildren ( ) = = 0 ) { <nl> + Buffer < < ' y ' ; <nl> + return ; <nl> + } <nl> + mangleSingleChildNode ( Ty ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleAssociatedType ( Node * node ) { <nl> + unreachable ( " unsupported node " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleAssociatedTypeRef ( Node * node ) { <nl> + SubstitutionEntry entry ; <nl> + if ( trySubstitution ( node , entry ) ) return ; <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " Qa " ; <nl> + addSubstitution ( entry ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleAssociatedTypeMetadataAccessor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; / / protocol conformance , identifier <nl> + Buffer < < " Wt " ; <nl> + } <nl> + <nl> + void Remangler : : mangleAssociatedTypeWitnessTableAccessor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; / / protocol conformance , identifier , type <nl> + Buffer < < " WT " ; <nl> + } <nl> + <nl> + void Remangler : : mangleAutoClosureType ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; / / argument tuple , result type <nl> + Buffer < < " XK " ; <nl> + } <nl> + <nl> + void Remangler : : mangleBoundGenericClass ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleBoundGenericEnum ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleBoundGenericStructure ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + template < size_t N > <nl> + static bool stripPrefix ( StringRef & string , const char ( & data ) [ N ] ) { <nl> + constexpr size_t prefixLength = N - 1 ; <nl> + if ( ! string . startswith ( StringRef ( data , prefixLength ) ) ) <nl> + return false ; <nl> + string = string . drop_front ( prefixLength ) ; <nl> + return true ; <nl> + } <nl> + <nl> + void Remangler : : mangleBuiltinTypeName ( Node * node ) { <nl> + Buffer < < ' B ' ; <nl> + StringRef text = node - > getText ( ) ; <nl> + <nl> + if ( text = = " Builtin . BridgeObject " ) { <nl> + Buffer < < ' b ' ; <nl> + } else if ( text = = " Builtin . UnsafeValueBuffer " ) { <nl> + Buffer < < ' B ' ; <nl> + } else if ( text = = " Builtin . UnknownObject " ) { <nl> + Buffer < < ' O ' ; <nl> + } else if ( text = = " Builtin . NativeObject " ) { <nl> + Buffer < < ' o ' ; <nl> + } else if ( text = = " Builtin . RawPointer " ) { <nl> + Buffer < < ' p ' ; <nl> + } else if ( text = = " Builtin . Word " ) { <nl> + Buffer < < ' w ' ; <nl> + } else if ( stripPrefix ( text , " Builtin . Int " ) ) { <nl> + Buffer < < ' i ' < < text < < ' _ ' ; <nl> + } else if ( stripPrefix ( text , " Builtin . Float " ) ) { <nl> + Buffer < < ' f ' < < text < < ' _ ' ; <nl> + } else if ( stripPrefix ( text , " Builtin . Vec " ) ) { <nl> + auto split = text . split ( ' x ' ) ; <nl> + if ( split . second = = " RawPointer " ) { <nl> + Buffer < < ' p ' ; <nl> + } else if ( stripPrefix ( split . second , " Float " ) ) { <nl> + Buffer < < ' f ' < < split . second < < ' _ ' ; <nl> + } else if ( stripPrefix ( split . second , " Int " ) ) { <nl> + Buffer < < ' i ' < < split . second < < ' _ ' ; <nl> + } else { <nl> + unreachable ( " unexpected builtin vector type " ) ; <nl> + } <nl> + Buffer < < " Bv " < < split . first < < ' _ ' ; <nl> + } else { <nl> + unreachable ( " unexpected builtin type " ) ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleCFunctionPointer ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; / / argument tuple , result type <nl> + Buffer < < " XC " ; <nl> + } <nl> + <nl> + void Remangler : : mangleClass ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleConstructor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fc " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDeallocator ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fD " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDeclContext ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDefaultArgumentInitializer ( Node * node ) { <nl> + mangleChildNode ( node , 0 ) ; <nl> + Buffer < < " fA " ; <nl> + mangleChildNode ( node , 1 ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentAssociatedTypeRef ( Node * node ) { <nl> + mangleIdentifier ( node ) ; <nl> + if ( node - > getNumChildren ( ) ! = 0 ) <nl> + mangleSingleChildNode ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericConformanceRequirement ( Node * node ) { <nl> + Node * ProtoOrClass = node - > getChild ( 1 ) . get ( ) ; <nl> + if ( ProtoOrClass - > getFirstChild ( ) - > getKind ( ) = = Node : : Kind : : Protocol ) { <nl> + manglePureProtocol ( ProtoOrClass ) ; <nl> + auto NumMembersAndParamIdx = mangleConstrainedType ( node - > getChild ( 0 ) . get ( ) ) ; <nl> + switch ( NumMembersAndParamIdx . first ) { <nl> + case - 1 : Buffer < < " RQ " ; return ; / / substitution <nl> + case 0 : Buffer < < " R " ; break ; <nl> + case 1 : Buffer < < " Rp " ; break ; <nl> + default : Buffer < < " RP " ; break ; <nl> + } <nl> + mangleDependentGenericParamIndex ( NumMembersAndParamIdx . second ) ; <nl> + return ; <nl> + } <nl> + mangle ( ProtoOrClass ) ; <nl> + auto NumMembersAndParamIdx = mangleConstrainedType ( node - > getChild ( 0 ) . get ( ) ) ; <nl> + switch ( NumMembersAndParamIdx . first ) { <nl> + case - 1 : Buffer < < " RB " ; return ; / / substitution <nl> + case 0 : Buffer < < " Rb " ; break ; <nl> + case 1 : Buffer < < " Rc " ; break ; <nl> + default : Buffer < < " RC " ; break ; <nl> + } <nl> + mangleDependentGenericParamIndex ( NumMembersAndParamIdx . second ) ; <nl> + return ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericParamCount ( Node * node ) { <nl> + unreachable ( " handled inline in DependentGenericSignature " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericParamType ( Node * node ) { <nl> + if ( node - > getChild ( 0 ) - > getIndex ( ) = = 0 <nl> + & & node - > getChild ( 1 ) - > getIndex ( ) = = 0 ) { <nl> + Buffer < < ' x ' ; <nl> + return ; <nl> + } <nl> + Buffer < < ' q ' ; <nl> + mangleDependentGenericParamIndex ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericSameTypeRequirement ( Node * node ) { <nl> + mangleChildNode ( node , 1 ) ; <nl> + auto NumMembersAndParamIdx = mangleConstrainedType ( node - > getChild ( 0 ) . get ( ) ) ; <nl> + switch ( NumMembersAndParamIdx . first ) { <nl> + case - 1 : Buffer < < " RS " ; return ; / / substitution <nl> + case 0 : Buffer < < " Rs " ; break ; <nl> + case 1 : Buffer < < " Rt " ; break ; <nl> + default : Buffer < < " RT " ; break ; <nl> + } <nl> + mangleDependentGenericParamIndex ( NumMembersAndParamIdx . second ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericSignature ( Node * node ) { <nl> + size_t ParamCountEnd = 0 ; <nl> + for ( size_t Idx = 0 , Num = node - > getNumChildren ( ) ; Idx < Num ; Idx + + ) { <nl> + Node * Child = node - > getChild ( Idx ) . get ( ) ; <nl> + if ( Child - > getKind ( ) = = Node : : Kind : : DependentGenericParamCount ) { <nl> + ParamCountEnd = Idx + 1 ; <nl> + } else { <nl> + / / requirement <nl> + mangleChildNode ( node , Idx ) ; <nl> + } <nl> + } <nl> + / / If there ' s only one generic param , mangle nothing . <nl> + if ( ParamCountEnd = = 1 & & node - > getChild ( 0 ) - > getIndex ( ) = = 1 ) { <nl> + Buffer < < ' l ' ; <nl> + return ; <nl> + } <nl> + <nl> + / / Remangle generic params . <nl> + Buffer < < ' r ' ; <nl> + for ( size_t Idx = 0 ; Idx < ParamCountEnd ; + + Idx ) { <nl> + Node * Count = node - > getChild ( Idx ) . get ( ) ; <nl> + if ( Count - > getIndex ( ) > 0 ) { <nl> + mangleIndex ( Count - > getIndex ( ) - 1 ) ; <nl> + } else { <nl> + Buffer < < ' z ' ; <nl> + } <nl> + } <nl> + Buffer < < ' l ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentGenericType ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; / / type , generic signature <nl> + Buffer < < ' u ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleDependentMemberType ( Node * node ) { <nl> + auto NumMembersAndParamIdx = mangleConstrainedType ( node ) ; <nl> + switch ( NumMembersAndParamIdx . first ) { <nl> + case - 1 : <nl> + break ; / / substitution <nl> + case 0 : <nl> + unreachable ( " wrong dependent member type " ) ; <nl> + case 1 : <nl> + Buffer < < ' Q ' ; <nl> + mangleDependentGenericParamIndex ( NumMembersAndParamIdx . second , " y " , ' z ' ) ; <nl> + break ; <nl> + default : <nl> + Buffer < < ' Q ' ; <nl> + mangleDependentGenericParamIndex ( NumMembersAndParamIdx . second , " Y " , ' Z ' ) ; <nl> + break ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleDependentPseudogenericSignature ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleDestructor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fd " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDidSet ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fW " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDirectness ( Node * node ) { <nl> + if ( node - > getIndex ( ) = = unsigned ( Directness : : Direct ) ) { <nl> + Buffer < < ' d ' ; <nl> + } else { <nl> + assert ( node - > getIndex ( ) = = unsigned ( Directness : : Indirect ) ) ; <nl> + Buffer < < ' i ' ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleDynamicAttribute ( Node * node ) { <nl> + Buffer < < " TD " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDirectMethodReferenceAttribute ( Node * node ) { <nl> + Buffer < < " Td " ; <nl> + } <nl> + <nl> + void Remangler : : mangleDynamicSelf ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; / / type <nl> + Buffer < < " XD " ; <nl> + } <nl> + <nl> + void Remangler : : mangleEnum ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleErrorType ( Node * node ) { <nl> + Buffer < < " ERR " ; <nl> + } <nl> + <nl> + void Remangler : : mangleExistentialMetatype ( Node * node ) { <nl> + if ( node - > getFirstChild ( ) - > getKind ( ) = = Node : : Kind : : MetatypeRepresentation ) { <nl> + mangleChildNode ( node , 1 ) ; <nl> + Buffer < < " Xm " ; <nl> + mangleChildNode ( node , 0 ) ; <nl> + } else { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Xp " ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleExplicitClosure ( Node * node ) { <nl> + mangleChildNode ( node , 0 ) ; / / context <nl> + mangleChildNode ( node , 2 ) ; / / type <nl> + Buffer < < " fU " ; <nl> + mangleChildNode ( node , 1 ) ; / / index <nl> + } <nl> + <nl> + void Remangler : : mangleExtension ( Node * node ) { <nl> + mangleChildNode ( node , 1 ) ; <nl> + mangleChildNode ( node , 0 ) ; <nl> + if ( node - > getNumChildren ( ) = = 3 ) <nl> + mangleChildNode ( node , 2 ) ; / / generic signature <nl> + Buffer < < ' E ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleFieldOffset ( Node * node ) { <nl> + mangleChildNode ( node , 1 ) ; / / variable <nl> + Buffer < < " Wv " ; <nl> + mangleChildNode ( node , 0 ) ; / / directness <nl> + } <nl> + <nl> + void Remangler : : mangleFullTypeMetadata ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Mf " ; <nl> + } <nl> + <nl> + void Remangler : : mangleFunction ( Node * node ) { <nl> + mangleChildNode ( node , 0 ) ; / / context <nl> + mangleChildNode ( node , 1 ) ; / / name <nl> + Node * FuncType = getSingleChild ( node - > getChild ( 2 ) . get ( ) ) ; <nl> + if ( FuncType - > getKind ( ) = = Node : : Kind : : DependentGenericType ) { <nl> + mangleFunctionSignature ( getSingleChild ( FuncType - > getChild ( 1 ) . get ( ) ) ) ; <nl> + mangleChildNode ( FuncType , 0 ) ; / / generic signature <nl> + } else { <nl> + mangleFunctionSignature ( FuncType ) ; <nl> + } <nl> + Buffer < < " F " ; <nl> + } <nl> + <nl> + void Remangler : : mangleFunctionSignatureSpecialization ( Node * node ) { <nl> + for ( NodePointer Param : * node ) { <nl> + if ( Param - > getKind ( ) = = Node : : Kind : : FunctionSignatureSpecializationParam & & <nl> + Param - > getNumChildren ( ) > 0 ) { <nl> + Node * KindNd = Param - > getChild ( 0 ) . get ( ) ; <nl> + switch ( FunctionSigSpecializationParamKind ( KindNd - > getIndex ( ) ) ) { <nl> + case FunctionSigSpecializationParamKind : : ConstantPropFunction : <nl> + case FunctionSigSpecializationParamKind : : ConstantPropGlobal : <nl> + mangleIdentifier ( Param - > getChild ( 1 ) . get ( ) ) ; <nl> + break ; <nl> + case FunctionSigSpecializationParamKind : : ConstantPropString : <nl> + mangleIdentifier ( Param - > getChild ( 2 ) . get ( ) ) ; <nl> + break ; <nl> + case FunctionSigSpecializationParamKind : : ClosureProp : <nl> + mangleIdentifier ( Param - > getChild ( 1 ) . get ( ) ) ; <nl> + for ( unsigned i = 2 , e = Param - > getNumChildren ( ) ; i ! = e ; + + i ) { <nl> + mangleType ( Param - > getChild ( i ) . get ( ) ) ; <nl> + } <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + Buffer < < " Tf " ; <nl> + bool returnValMangled = false ; <nl> + for ( NodePointer Child : * node ) { <nl> + if ( Child - > getKind ( ) = = Node : : Kind : : FunctionSignatureSpecializationParam ) { <nl> + if ( Child - > getIndex ( ) = = Node : : IndexType ( ~ 0 ) ) { <nl> + Buffer < < ' _ ' ; <nl> + returnValMangled = true ; <nl> + } <nl> + } <nl> + mangle ( Child . get ( ) ) ; <nl> + } <nl> + if ( ! returnValMangled ) <nl> + Buffer < < " _n " ; <nl> + } <nl> + <nl> + void Remangler : : mangleFunctionSignatureSpecializationParam ( Node * node ) { <nl> + if ( ! node - > hasChildren ( ) ) { <nl> + Buffer < < ' n ' ; <nl> + return ; <nl> + } <nl> + <nl> + / / The first child is always a kind that specifies the type of param that we <nl> + / / have . <nl> + Node * KindNd = node - > getChild ( 0 ) . get ( ) ; <nl> + unsigned kindValue = KindNd - > getIndex ( ) ; <nl> + auto kind = FunctionSigSpecializationParamKind ( kindValue ) ; <nl> + <nl> + switch ( kind ) { <nl> + case FunctionSigSpecializationParamKind : : ConstantPropFunction : <nl> + Buffer < < " pf " ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : ConstantPropGlobal : <nl> + Buffer < < " pg " ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : ConstantPropInteger : <nl> + Buffer < < " pi " < < node - > getChild ( 1 ) - > getText ( ) ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : ConstantPropFloat : <nl> + Buffer < < " pd " < < node - > getChild ( 1 ) - > getText ( ) ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : ConstantPropString : { <nl> + Buffer < < " ps " ; <nl> + StringRef encodingStr = node - > getChild ( 1 ) - > getText ( ) ; <nl> + if ( encodingStr = = " u8 " ) { <nl> + Buffer < < ' b ' ; <nl> + } else if ( encodingStr = = " u16 " ) { <nl> + Buffer < < ' w ' ; <nl> + } else if ( encodingStr = = " objc " ) { <nl> + Buffer < < ' c ' ; <nl> + } else { <nl> + unreachable ( " Unknown encoding " ) ; <nl> + } <nl> + return ; <nl> + } <nl> + case FunctionSigSpecializationParamKind : : ClosureProp : <nl> + Buffer < < ' c ' ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : BoxToValue : <nl> + Buffer < < ' i ' ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : BoxToStack : <nl> + Buffer < < ' s ' ; <nl> + return ; <nl> + case FunctionSigSpecializationParamKind : : SROA : <nl> + Buffer < < ' x ' ; <nl> + return ; <nl> + default : <nl> + if ( kindValue & unsigned ( FunctionSigSpecializationParamKind : : Dead ) ) { <nl> + Buffer < < ' d ' ; <nl> + if ( kindValue & <nl> + unsigned ( FunctionSigSpecializationParamKind : : OwnedToGuaranteed ) ) <nl> + Buffer < < ' G ' ; <nl> + } else if ( kindValue & <nl> + unsigned ( FunctionSigSpecializationParamKind : : OwnedToGuaranteed ) ) { <nl> + Buffer < < ' g ' ; <nl> + } <nl> + if ( kindValue & unsigned ( FunctionSigSpecializationParamKind : : SROA ) ) <nl> + Buffer < < ' X ' ; <nl> + return ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleFunctionSignatureSpecializationParamKind ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleFunctionSignatureSpecializationParamPayload ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleFunctionType ( Node * node ) { <nl> + mangleFunctionSignature ( node ) ; <nl> + Buffer < < ' c ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleGenericProtocolWitnessTable ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " WG " ; <nl> + } <nl> + <nl> + void Remangler : : mangleGenericProtocolWitnessTableInstantiationFunction ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " WI " ; <nl> + } <nl> + <nl> + void Remangler : : mangleGenericSpecialization ( Node * node ) { <nl> + bool FirstParam = true ; <nl> + for ( NodePointer Child : * node ) { <nl> + if ( Child - > getKind ( ) = = Node : : Kind : : GenericSpecializationParam ) { <nl> + mangleChildNode ( Child . get ( ) , 0 ) ; <nl> + mangleListSeparator ( FirstParam ) ; <nl> + } <nl> + } <nl> + assert ( ! FirstParam & & " generic specialization with no substitutions " ) ; <nl> + <nl> + Buffer < < ( node - > getKind ( ) = = <nl> + Node : : Kind : : GenericSpecializationNotReAbstracted ? " TG " : " Tg " ) ; <nl> + for ( NodePointer Child : * node ) { <nl> + if ( Child - > getKind ( ) ! = Node : : Kind : : GenericSpecializationParam ) <nl> + mangle ( Child . get ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleGenericSpecializationNotReAbstracted ( Node * node ) { <nl> + mangleGenericSpecialization ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleGenericSpecializationParam ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleGenericTypeMetadataPattern ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " MP " ; <nl> + } <nl> + <nl> + void Remangler : : mangleGetter ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fg " ; <nl> + } <nl> + <nl> + void Remangler : : mangleGlobal ( Node * node ) { <nl> + Buffer < < MANGLING_PREFIX_STR ; <nl> + bool mangleInReverseOrder = false ; <nl> + for ( auto Iter = node - > begin ( ) , End = node - > end ( ) ; Iter ! = End ; + + Iter ) { <nl> + Node * Child = Iter - > get ( ) ; <nl> + switch ( Child - > getKind ( ) ) { <nl> + case Node : : Kind : : FunctionSignatureSpecialization : <nl> + case Node : : Kind : : GenericSpecialization : <nl> + case Node : : Kind : : GenericSpecializationNotReAbstracted : <nl> + case Node : : Kind : : ObjCAttribute : <nl> + case Node : : Kind : : NonObjCAttribute : <nl> + case Node : : Kind : : DynamicAttribute : <nl> + case Node : : Kind : : VTableAttribute : <nl> + case Node : : Kind : : DirectMethodReferenceAttribute : <nl> + mangleInReverseOrder = true ; <nl> + break ; <nl> + default : <nl> + mangle ( Child ) ; <nl> + if ( mangleInReverseOrder ) { <nl> + auto ReverseIter = Iter ; <nl> + while ( ReverseIter ! = node - > begin ( ) ) { <nl> + - - ReverseIter ; <nl> + mangle ( ReverseIter - > get ( ) ) ; <nl> + } <nl> + mangleInReverseOrder = false ; <nl> + } <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleGlobalGetter ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fG " ; <nl> + } <nl> + <nl> + void Remangler : : mangleIdentifier ( Node * node ) { <nl> + mangleIdentifierImpl ( node , / * isOperator * / false ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleIndex ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleIVarInitializer ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " fe " ; <nl> + } <nl> + <nl> + void Remangler : : mangleIVarDestroyer ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " fE " ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplConvention ( Node * node ) { <nl> + char ConvCh = llvm : : StringSwitch < char > ( node - > getText ( ) ) <nl> + . Case ( " @ callee_unowned " , ' y ' ) <nl> + . Case ( " @ callee_guaranteed " , ' g ' ) <nl> + . Case ( " @ callee_owned " , ' x ' ) <nl> + . Default ( 0 ) ; <nl> + assert ( ConvCh & & " invalid impl callee convention " ) ; <nl> + Buffer < < ConvCh ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplFunctionAttribute ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplFunctionType ( Node * node ) { <nl> + const char * PseudoGeneric = " " ; <nl> + for ( NodePointer Child : * node ) { <nl> + switch ( Child - > getKind ( ) ) { <nl> + case Node : : Kind : : ImplParameter : <nl> + case Node : : Kind : : ImplResult : <nl> + case Node : : Kind : : ImplErrorResult : <nl> + mangleChildNode ( Child . get ( ) , 1 ) ; <nl> + break ; <nl> + case Node : : Kind : : DependentPseudogenericSignature : <nl> + PseudoGeneric = " P " ; <nl> + SWIFT_FALLTHROUGH ; <nl> + case Node : : Kind : : DependentGenericSignature : <nl> + mangle ( Child . get ( ) ) ; <nl> + break ; <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + Buffer < < ' I ' < < PseudoGeneric ; <nl> + for ( NodePointer Child : * node ) { <nl> + switch ( Child - > getKind ( ) ) { <nl> + case Node : : Kind : : ImplConvention : { <nl> + char ConvCh = llvm : : StringSwitch < char > ( Child - > getText ( ) ) <nl> + . Case ( " @ callee_unowned " , ' y ' ) <nl> + . Case ( " @ callee_guaranteed " , ' g ' ) <nl> + . Case ( " @ callee_owned " , ' x ' ) <nl> + . Case ( " @ convention ( thin ) " , ' t ' ) <nl> + . Default ( 0 ) ; <nl> + assert ( ConvCh & & " invalid impl callee convention " ) ; <nl> + Buffer < < ConvCh ; <nl> + break ; <nl> + } <nl> + case Node : : Kind : : ImplFunctionAttribute : { <nl> + char FuncAttr = llvm : : StringSwitch < char > ( Child - > getText ( ) ) <nl> + . Case ( " @ convention ( block ) " , ' B ' ) <nl> + . Case ( " @ convention ( c ) " , ' C ' ) <nl> + . Case ( " @ convention ( method ) " , ' M ' ) <nl> + . Case ( " @ convention ( objc_method ) " , ' O ' ) <nl> + . Case ( " @ convention ( closure ) " , ' K ' ) <nl> + . Case ( " @ convention ( witness_method ) " , ' W ' ) <nl> + . Default ( 0 ) ; <nl> + assert ( FuncAttr & & " invalid impl function attribute " ) ; <nl> + Buffer < < FuncAttr ; <nl> + break ; <nl> + } <nl> + case Node : : Kind : : ImplParameter : { <nl> + char ConvCh = llvm : : StringSwitch < char > ( Child - > getFirstChild ( ) - > getText ( ) ) <nl> + . Case ( " @ in " , ' i ' ) <nl> + . Case ( " @ inout " , ' l ' ) <nl> + . Case ( " @ inout_aliasable " , ' b ' ) <nl> + . Case ( " @ in_guaranteed " , ' n ' ) <nl> + . Case ( " @ owned " , ' x ' ) <nl> + . Case ( " @ guaranteed " , ' g ' ) <nl> + . Case ( " @ deallocating " , ' e ' ) <nl> + . Case ( " @ unowned " , ' y ' ) <nl> + . Default ( 0 ) ; <nl> + assert ( ConvCh & & " invalid impl parameter convention " ) ; <nl> + Buffer < < ConvCh ; <nl> + break ; <nl> + } <nl> + case Node : : Kind : : ImplErrorResult : <nl> + Buffer < < ' z ' ; <nl> + SWIFT_FALLTHROUGH ; <nl> + case Node : : Kind : : ImplResult : { <nl> + char ConvCh = llvm : : StringSwitch < char > ( Child - > getFirstChild ( ) - > getText ( ) ) <nl> + . Case ( " @ out " , ' r ' ) <nl> + . Case ( " @ owned " , ' o ' ) <nl> + . Case ( " @ unowned " , ' d ' ) <nl> + . Case ( " @ unowned_inner_pointer " , ' u ' ) <nl> + . Case ( " @ autoreleased " , ' a ' ) <nl> + . Default ( 0 ) ; <nl> + assert ( ConvCh & & " invalid impl parameter convention " ) ; <nl> + Buffer < < ConvCh ; <nl> + break ; <nl> + } <nl> + default : <nl> + break ; <nl> + } <nl> + } <nl> + Buffer < < ' _ ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplicitClosure ( Node * node ) { <nl> + mangleChildNode ( node , 0 ) ; / / context <nl> + mangleChildNode ( node , 2 ) ; / / type <nl> + Buffer < < " fu " ; <nl> + mangleChildNode ( node , 1 ) ; / / index <nl> + } <nl> + <nl> + void Remangler : : mangleImplParameter ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplResult ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleImplErrorResult ( Node * node ) { <nl> + unreachable ( " handled inline " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleInOut ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < ' z ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleInfixOperator ( Node * node ) { <nl> + mangleIdentifierImpl ( node , / * isOperator * / true ) ; <nl> + Buffer < < " oi " ; <nl> + } <nl> + <nl> + void Remangler : : mangleInitializer ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fi " ; <nl> + } <nl> + <nl> + void Remangler : : mangleLazyProtocolWitnessTableAccessor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " Wl " ; <nl> + } <nl> + <nl> + void Remangler : : mangleLazyProtocolWitnessTableCacheVariable ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " WL " ; <nl> + } <nl> + <nl> + void Remangler : : mangleLocalDeclName ( Node * node ) { <nl> + mangleChildNode ( node , 1 ) ; / / identifier <nl> + Buffer < < ' L ' ; <nl> + mangleChildNode ( node , 0 ) ; / / index <nl> + } <nl> + <nl> + void Remangler : : mangleMaterializeForSet ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fm " ; <nl> + } <nl> + <nl> + void Remangler : : mangleMetatype ( Node * node ) { <nl> + if ( node - > getFirstChild ( ) - > getKind ( ) = = Node : : Kind : : MetatypeRepresentation ) { <nl> + mangleChildNode ( node , 1 ) ; <nl> + Buffer < < " XM " ; <nl> + mangleChildNode ( node , 0 ) ; <nl> + } else { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < ' m ' ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleMetatypeRepresentation ( Node * node ) { <nl> + if ( node - > getText ( ) = = " @ thin " ) { <nl> + Buffer < < ' t ' ; <nl> + } else if ( node - > getText ( ) = = " @ thick " ) { <nl> + Buffer < < ' T ' ; <nl> + } else if ( node - > getText ( ) = = " @ objc_metatype " ) { <nl> + Buffer < < ' o ' ; <nl> + } else { <nl> + unreachable ( " wrong metatype representation " ) ; <nl> + } <nl> + } <nl> + <nl> + void Remangler : : mangleMetaclass ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " Mm " ; <nl> + } <nl> + <nl> + void Remangler : : mangleModule ( Node * node ) { <nl> + mangleIdentifier ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleNativeOwningAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " flo " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNativeOwningMutableAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fao " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNativePinningAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " flp " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNativePinningMutableAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " faP " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNominalTypeDescriptor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Mn " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNonObjCAttribute ( Node * node ) { <nl> + Buffer < < " TO " ; <nl> + } <nl> + <nl> + void Remangler : : mangleNonVariadicTuple ( Node * node ) { <nl> + mangleTypeList ( node ) ; <nl> + Buffer < < ' t ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleNumber ( Node * node ) { <nl> + mangleIndex ( node - > getIndex ( ) ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleObjCAttribute ( Node * node ) { <nl> + Buffer < < " To " ; <nl> + } <nl> + <nl> + void Remangler : : mangleObjCBlock ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; <nl> + Buffer < < " XB " ; <nl> + } <nl> + <nl> + void Remangler : : mangleOwningAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " flO " ; <nl> + } <nl> + <nl> + void Remangler : : mangleOwningMutableAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " faO " ; <nl> + } <nl> + <nl> + void Remangler : : manglePartialApplyForwarder ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " TA " ; <nl> + } <nl> + <nl> + void Remangler : : manglePartialApplyObjCForwarder ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " Ta " ; <nl> + } <nl> + <nl> + void Remangler : : manglePostfixOperator ( Node * node ) { <nl> + mangleIdentifierImpl ( node , / * isOperator * / true ) ; <nl> + Buffer < < " oP " ; <nl> + } <nl> + <nl> + void Remangler : : manglePrefixOperator ( Node * node ) { <nl> + mangleIdentifierImpl ( node , / * isOperator * / true ) ; <nl> + Buffer < < " op " ; <nl> + } <nl> + <nl> + void Remangler : : manglePrivateDeclName ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; <nl> + Buffer < < " LL " ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocol ( Node * node ) { <nl> + mangleNominalType ( node , ' P ' ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolConformance ( Node * node ) { <nl> + Node * Ty = getChildOfType ( node - > getChild ( 0 ) . get ( ) ) ; <nl> + Node * GenSig = nullptr ; <nl> + if ( Ty - > getKind ( ) = = Node : : Kind : : DependentGenericType ) { <nl> + GenSig = Ty - > getFirstChild ( ) . get ( ) ; <nl> + Ty = Ty - > getChild ( 1 ) . get ( ) ; <nl> + } <nl> + mangle ( Ty ) ; <nl> + manglePureProtocol ( node - > getChild ( 1 ) . get ( ) ) ; <nl> + mangleChildNode ( node , 2 ) ; <nl> + if ( GenSig ) <nl> + mangle ( GenSig ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolDescriptor ( Node * node ) { <nl> + manglePureProtocol ( getSingleChild ( node , Node : : Kind : : Type ) ) ; <nl> + Buffer < < " Mp " ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolList ( Node * node ) { <nl> + node = getSingleChild ( node , Node : : Kind : : TypeList ) ; <nl> + bool FirstElem = true ; <nl> + for ( NodePointer Child : * node ) { <nl> + manglePureProtocol ( Child . get ( ) ) ; <nl> + mangleListSeparator ( FirstElem ) ; <nl> + } <nl> + mangleEndOfList ( FirstElem ) ; <nl> + Buffer < < ' p ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolWitness ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " TW " ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolWitnessTable ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " WP " ; <nl> + } <nl> + <nl> + void Remangler : : mangleProtocolWitnessTableAccessor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Wa " ; <nl> + } <nl> + <nl> + void Remangler : : mangleQualifiedArchetype ( Node * node ) { <nl> + mangleChildNode ( node , 1 ) ; <nl> + Buffer < < " Qq " ; <nl> + mangleIndex ( node - > getFirstChild ( ) . get ( ) ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleReabstractionThunk ( Node * node ) { <nl> + if ( node - > getNumChildren ( ) = = 3 ) { <nl> + mangleChildNode ( node , 1 ) ; / / type 1 <nl> + mangleChildNode ( node , 2 ) ; / / type 2 <nl> + mangleChildNode ( node , 0 ) ; / / generic signature <nl> + } else { <nl> + mangleChildNodes ( node ) ; <nl> + } <nl> + Buffer < < " Tr " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReabstractionThunkHelper ( Node * node ) { <nl> + if ( node - > getNumChildren ( ) = = 3 ) { <nl> + mangleChildNode ( node , 1 ) ; / / type 1 <nl> + mangleChildNode ( node , 2 ) ; / / type 2 <nl> + mangleChildNode ( node , 0 ) ; / / generic signature <nl> + } else { <nl> + mangleChildNodes ( node ) ; <nl> + } <nl> + Buffer < < " TR " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReturnType ( Node * node ) { <nl> + mangleArgumentTuple ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleSILBoxType ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Xb " ; <nl> + } <nl> + <nl> + void Remangler : : mangleSetter ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fs " ; <nl> + } <nl> + <nl> + void Remangler : : mangleSpecializationPassID ( Node * node ) { <nl> + Buffer < < node - > getIndex ( ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleSpecializationIsFragile ( Node * node ) { <nl> + Buffer < < ' q ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleStatic ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < ' Z ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleStructure ( Node * node ) { <nl> + mangleAnyNominalType ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleSubscript ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < ' i ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleSuffix ( Node * node ) { <nl> + / / Just add the suffix back on . <nl> + Buffer < < node - > getText ( ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleThinFunctionType ( Node * node ) { <nl> + mangleFunctionSignature ( node ) ; <nl> + Buffer < < " Xf " ; <nl> + } <nl> + <nl> + void Remangler : : mangleTupleElement ( Node * node ) { <nl> + mangleChildNodesReversed ( node ) ; / / tuple type , element name ? <nl> + } <nl> + <nl> + void Remangler : : mangleTupleElementName ( Node * node ) { <nl> + mangleIdentifier ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleType ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeAlias ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < ' a ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeList ( Node * node ) { <nl> + bool FirstElem = true ; <nl> + for ( size_t Idx = 0 , Num = node - > getNumChildren ( ) ; Idx < Num ; + + Idx ) { <nl> + mangleChildNode ( node , Idx ) ; <nl> + mangleListSeparator ( FirstElem ) ; <nl> + } <nl> + mangleEndOfList ( FirstElem ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeMangling ( Node * node ) { <nl> + unreachable ( " not used " ) ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeMetadata ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " N " ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeMetadataAccessFunction ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Ma " ; <nl> + } <nl> + <nl> + void Remangler : : mangleTypeMetadataLazyCache ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " ML " ; <nl> + } <nl> + <nl> + void Remangler : : mangleUncurriedFunctionType ( Node * node ) { <nl> + mangleFunctionSignature ( node ) ; <nl> + Buffer < < " XU " ; <nl> + } <nl> + <nl> + void Remangler : : mangleUnmanaged ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Xu " ; <nl> + } <nl> + <nl> + void Remangler : : mangleUnowned ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Xo " ; <nl> + } <nl> + <nl> + void Remangler : : mangleUnsafeAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " flu " ; <nl> + } <nl> + <nl> + void Remangler : : mangleUnsafeMutableAddressor ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fau " ; <nl> + } <nl> + <nl> + void Remangler : : mangleValueWitness ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; / / type <nl> + const char * Code = nullptr ; <nl> + switch ( ValueWitnessKind ( node - > getIndex ( ) ) ) { <nl> + # define VALUE_WITNESS ( MANGLING , NAME ) \ <nl> + case ValueWitnessKind : : NAME : Code = # MANGLING ; break ; <nl> + # include " swift / Basic / ValueWitnessMangling . def " <nl> + } <nl> + Buffer < < ' w ' < < Code ; <nl> + } <nl> + <nl> + void Remangler : : mangleValueWitnessTable ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " WV " ; <nl> + } <nl> + <nl> + void Remangler : : mangleVariable ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < ' v ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleVariadicTuple ( Node * node ) { <nl> + mangleTypeList ( node ) ; <nl> + Buffer < < " dt " ; <nl> + } <nl> + <nl> + void Remangler : : mangleVTableAttribute ( Node * node ) { <nl> + Buffer < < " TV " ; <nl> + } <nl> + <nl> + void Remangler : : mangleWeak ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Xw " ; <nl> + } <nl> + <nl> + void Remangler : : mangleWillSet ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " fw " ; <nl> + } <nl> + <nl> + void Remangler : : mangleWitnessTableOffset ( Node * node ) { <nl> + mangleChildNodes ( node ) ; <nl> + Buffer < < " Wo " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataBuiltinDescriptor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " MB " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataFieldDescriptor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " MF " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataAssocTypeDescriptor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; / / protocol - conformance <nl> + Buffer < < " MA " ; <nl> + } <nl> + <nl> + void Remangler : : mangleReflectionMetadataSuperclassDescriptor ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; / / protocol - conformance <nl> + Buffer < < " MC " ; <nl> + } <nl> + <nl> + void Remangler : : mangleCurryThunk ( Node * node ) { <nl> + mangleSingleChildNode ( node ) ; <nl> + Buffer < < " Tc " ; <nl> + } <nl> + <nl> + void Remangler : : mangleThrowsAnnotation ( Node * node ) { <nl> + Buffer < < ' K ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleEmptyList ( Node * node ) { <nl> + Buffer < < ' y ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleFirstElementMarker ( Node * node ) { <nl> + Buffer < < ' _ ' ; <nl> + } <nl> + <nl> + void Remangler : : mangleVariadicMarker ( Node * node ) { <nl> + Buffer < < ' d ' ; <nl> + } <nl> + <nl> + } / / anonymous namespace <nl> + <nl> + / / / The top - level interface to the remangler . <nl> + std : : string Demangle : : mangleNodeNew ( const NodePointer & node ) { <nl> + if ( ! node ) return " " ; <nl> + <nl> + DemanglerPrinter printer ; <nl> + Remangler ( printer ) . mangle ( node . get ( ) ) ; <nl> + <nl> + return std : : move ( printer ) . str ( ) ; <nl> + } <nl> mmm a / lib / FrontendTool / FrontendTool . cpp <nl> ppp b / lib / FrontendTool / FrontendTool . cpp <nl> <nl> # include " swift / AST / DiagnosticsSema . h " <nl> # include " swift / AST / IRGenOptions . h " <nl> # include " swift / AST / Mangle . h " <nl> + # include " swift / AST / ASTMangler . h " <nl> # include " swift / AST / NameLookup . h " <nl> # include " swift / AST / ReferencedNameTracker . h " <nl> # include " swift / AST / TypeRefinementContext . h " <nl> int swift : : performFrontend ( ArrayRef < const char * > Args , <nl> performCompile ( Instance , Invocation , Args , ReturnValue , observer ) | | <nl> Instance . getASTContext ( ) . hadError ( ) ; <nl> <nl> + if ( ! HadError ) { <nl> + NewMangling : : printManglingStats ( ) ; <nl> + } <nl> + <nl> if ( ! HadError & & ! Invocation . getFrontendOptions ( ) . DumpAPIPath . empty ( ) ) { <nl> HadError = dumpAPI ( Instance . getMainModule ( ) , <nl> Invocation . getFrontendOptions ( ) . DumpAPIPath ) ; <nl> mmm a / lib / IRGen / CMakeLists . txt <nl> ppp b / lib / IRGen / CMakeLists . txt <nl> add_swift_library ( swiftIRGen STATIC <nl> IRGen . cpp <nl> IRGenDebugInfo . cpp <nl> IRGenFunction . cpp <nl> + IRGenMangler . cpp <nl> IRGenModule . cpp <nl> IRGenSIL . cpp <nl> Linking . cpp <nl> new file mode 100644 <nl> index 000000000000 . . d08ba199a96a <nl> mmm / dev / null <nl> ppp b / lib / IRGen / IRGenMangler . cpp <nl> <nl> + / / = = = mmm IRGenMangler . h - mangling of IRGen symbols mmmmmmmmmmmmmmmmmmmmm - - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " IRGenMangler . h " <nl> + <nl> + using namespace swift ; <nl> + using namespace irgen ; <nl> + <nl> + std : : string IRGenMangler : : mangleValueWitness ( Type type , ValueWitness witness ) { <nl> + beginMangling ( ) ; <nl> + appendType ( type ) ; <nl> + <nl> + const char * Code = nullptr ; <nl> + switch ( witness ) { <nl> + # define VALUE_WITNESS ( MANGLING , NAME ) \ <nl> + case ValueWitness : : NAME : Code = # MANGLING ; break ; <nl> + # include " swift / Basic / ValueWitnessMangling . def " <nl> + case ValueWitness : : Size : <nl> + case ValueWitness : : Flags : <nl> + case ValueWitness : : Stride : <nl> + case ValueWitness : : ExtraInhabitantFlags : <nl> + llvm_unreachable ( " not a function witness " ) ; <nl> + } <nl> + appendOperator ( " w " , Code ) ; <nl> + return finalize ( ) ; <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 3b3b2cb0bab6 <nl> mmm / dev / null <nl> ppp b / lib / IRGen / IRGenMangler . h <nl> <nl> + / / = = = mmm IRGenMangler . h - mangling of IRGen symbols mmmmmmmmmmmm - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # ifndef SWIFT_IRGEN_IRGENMANGLER_H <nl> + # define SWIFT_IRGEN_IRGENMANGLER_H <nl> + <nl> + # include " swift / AST / ASTMangler . h " <nl> + # include " ValueWitness . h " <nl> + <nl> + namespace swift { <nl> + namespace irgen { <nl> + <nl> + / / / The mangler for all kind of symbols produced in IRGen . <nl> + class IRGenMangler : public NewMangling : : ASTMangler { <nl> + public : <nl> + IRGenMangler ( ) { } <nl> + <nl> + std : : string mangleValueWitness ( Type type , ValueWitness witness ) ; <nl> + <nl> + std : : string mangleValueWitnessTable ( Type type ) { <nl> + return mangleTypeSymbol ( type , " WV " ) ; <nl> + } <nl> + <nl> + std : : string mangleTypeMetadataAccessFunction ( Type type ) { <nl> + return mangleTypeSymbol ( type , " Ma " ) ; <nl> + } <nl> + <nl> + std : : string mangleTypeMetadataLazyCacheVariable ( Type type ) { <nl> + return mangleTypeSymbol ( type , " ML " ) ; <nl> + } <nl> + <nl> + std : : string mangleTypeFullMetadataFull ( Type type ) { <nl> + return mangleTypeSymbol ( type , " Mf " ) ; <nl> + } <nl> + <nl> + std : : string mangleTypeMetadataFull ( Type type , bool isPattern ) { <nl> + return mangleTypeSymbol ( type , isPattern ? " MP " : " N " ) ; <nl> + } <nl> + <nl> + std : : string mangleClassMetaClass ( const ClassDecl * Decl ) { <nl> + return mangleNominalTypeSymbol ( Decl , " Mm " ) ; <nl> + } <nl> + <nl> + std : : string mangleNominalTypeDescriptor ( const NominalTypeDecl * Decl ) { <nl> + return mangleNominalTypeSymbol ( Decl , " Mn " ) ; <nl> + } <nl> + <nl> + std : : string mangleProtocolDescriptor ( const ProtocolDecl * Decl ) { <nl> + beginMangling ( ) ; <nl> + appendProtocolName ( Decl ) ; <nl> + appendOperator ( " Mp " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleWitnessTableOffset ( const ValueDecl * Decl ) { <nl> + beginMangling ( ) ; <nl> + if ( auto ctor = dyn_cast < ConstructorDecl > ( Decl ) ) { <nl> + appendConstructorEntity ( ctor , / * isAllocating = * / true ) ; <nl> + } else { <nl> + appendEntity ( Decl ) ; <nl> + } <nl> + appendOperator ( " Wo " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleFieldOffsetFull ( const ValueDecl * Decl , bool isIndirect ) { <nl> + beginMangling ( ) ; <nl> + appendEntity ( Decl ) ; <nl> + appendOperator ( " Wv " , isIndirect ? " i " : " d " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleDirectProtocolWitnessTable ( const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( Type ( ) , C , " WP " ) ; <nl> + } <nl> + <nl> + std : : string mangleGenericProtocolWitnessTableCache ( <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( Type ( ) , C , " WG " ) ; <nl> + } <nl> + <nl> + std : : string mangleGenericProtocolWitnessTableInstantiationFunction ( <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( Type ( ) , C , " WI " ) ; <nl> + } <nl> + <nl> + std : : string mangleProtocolWitnessTableAccessFunction ( <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( Type ( ) , C , " Wa " ) ; <nl> + } <nl> + <nl> + std : : string mangleProtocolWitnessTableLazyAccessFunction ( Type type , <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( type , C , " Wl " ) ; <nl> + } <nl> + <nl> + std : : string mangleProtocolWitnessTableLazyCacheVariable ( Type type , <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( type , C , " WL " ) ; <nl> + } <nl> + <nl> + std : : string mangleAssociatedTypeMetadataAccessFunction ( <nl> + const ProtocolConformance * Conformance , <nl> + StringRef AssocTyName ) { <nl> + beginMangling ( ) ; <nl> + appendProtocolConformance ( Conformance ) ; <nl> + appendIdentifier ( AssocTyName ) ; <nl> + appendOperator ( " Wt " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleAssociatedTypeWitnessTableAccessFunction ( <nl> + const ProtocolConformance * Conformance , <nl> + StringRef AssocTyName , <nl> + const ProtocolDecl * Proto ) { <nl> + beginMangling ( ) ; <nl> + appendProtocolConformance ( Conformance ) ; <nl> + appendIdentifier ( AssocTyName ) ; <nl> + appendNominalType ( Proto ) ; <nl> + appendOperator ( " WT " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleReflectionBuiltinDescriptor ( Type type ) { <nl> + return mangleTypeSymbol ( type , " MB " ) ; <nl> + } <nl> + <nl> + std : : string mangleReflectionFieldDescriptor ( Type type ) { <nl> + return mangleTypeSymbol ( type , " MF " ) ; <nl> + } <nl> + <nl> + std : : string mangleReflectionAssociatedTypeDescriptor ( <nl> + const ProtocolConformance * C ) { <nl> + return mangleConformanceSymbol ( Type ( ) , C , " MA " ) ; <nl> + } <nl> + <nl> + std : : string mangleReflectionSuperclassDescriptor ( const ClassDecl * Decl ) { <nl> + return mangleNominalTypeSymbol ( Decl , " MC " ) ; <nl> + } <nl> + <nl> + <nl> + protected : <nl> + <nl> + std : : string mangleTypeSymbol ( Type type , const char * Op ) { <nl> + beginMangling ( ) ; <nl> + appendType ( type ) ; <nl> + appendOperator ( Op ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleNominalTypeSymbol ( const NominalTypeDecl * Decl , <nl> + const char * Op ) { <nl> + beginMangling ( ) ; <nl> + appendNominalType ( Decl ) ; <nl> + appendOperator ( Op ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + std : : string mangleConformanceSymbol ( Type type , <nl> + const ProtocolConformance * Conformance , <nl> + const char * Op ) { <nl> + beginMangling ( ) ; <nl> + if ( type ) <nl> + appendType ( type ) ; <nl> + appendProtocolConformance ( Conformance ) ; <nl> + appendOperator ( Op ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + } ; <nl> + <nl> + } / / end namespace irgen <nl> + } / / end namespace swift <nl> + <nl> + # endif <nl> mmm a / lib / SILOptimizer / Utils / CMakeLists . txt <nl> ppp b / lib / SILOptimizer / Utils / CMakeLists . txt <nl> set ( UTILS_SOURCES <nl> Utils / PerformanceInlinerUtils . cpp <nl> Utils / SILInliner . cpp <nl> Utils / SILSSAUpdater . cpp <nl> + Utils / SpecializationMangler . cpp <nl> PARENT_SCOPE ) <nl> <nl> new file mode 100644 <nl> index 000000000000 . . 19264f54109e <nl> mmm / dev / null <nl> ppp b / lib / SILOptimizer / Utils / SpecializationMangler . cpp <nl> <nl> + / / = = = mmm SpecializationMangler . cpp - mangling of specializations mmmmmmmmm - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2016 Apple Inc . and the Swift project authors <nl> + / / Licensed under Apache License v2 . 0 with Runtime Library Exception <nl> + / / <nl> + / / See http : / / swift . org / LICENSE . txt for license information <nl> + / / See http : / / swift . org / CONTRIBUTORS . txt for the list of Swift project authors <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + # include " swift / SILOptimizer / Utils / SpecializationMangler . h " <nl> + # include " swift / SIL / SILGlobalVariable . h " <nl> + # include " swift / Basic / Demangler . h " <nl> + # include " swift / Basic / ManglingMacros . h " <nl> + <nl> + using namespace swift ; <nl> + using namespace NewMangling ; <nl> + <nl> + void SpecializationMangler : : beginMangling ( ) { <nl> + ASTMangler : : beginMangling ( ) ; <nl> + if ( Fragile ) <nl> + ArgOpBuffer < < ' q ' ; <nl> + ArgOpBuffer < < char ( uint8_t ( Pass ) + ' 0 ' ) ; <nl> + } <nl> + <nl> + std : : string SpecializationMangler : : finalize ( ) { <nl> + std : : string MangledSpecialization = ASTMangler : : finalize ( ) ; <nl> + Demangler D ( MangledSpecialization ) ; <nl> + NodePointer TopLevel = D . demangleTopLevel ( ) ; <nl> + <nl> + StringRef FuncName = Function - > getName ( ) ; <nl> + NodePointer FuncTopLevel ; <nl> + if ( FuncName . startswith ( MANGLING_PREFIX_STR ) ) { <nl> + FuncTopLevel = Demangler ( FuncName ) . demangleTopLevel ( ) ; <nl> + assert ( FuncTopLevel ) ; <nl> + } else if ( FuncName . startswith ( " _T " ) ) { <nl> + FuncTopLevel = demangleSymbolAsNode ( FuncName . data ( ) , FuncName . size ( ) ) ; <nl> + } <nl> + if ( ! FuncTopLevel ) { <nl> + FuncTopLevel = NodeFactory : : create ( Node : : Kind : : Global ) ; <nl> + FuncTopLevel - > addChild ( NodeFactory : : create ( Node : : Kind : : Identifier , FuncName ) ) ; <nl> + } <nl> + for ( NodePointer FuncChild : * FuncTopLevel ) { <nl> + assert ( FuncChild - > getKind ( ) ! = Node : : Kind : : Suffix | | <nl> + FuncChild - > getText ( ) = = " merged " ) ; <nl> + TopLevel - > addChild ( FuncChild ) ; <nl> + } <nl> + return Demangle : : mangleNodeNew ( TopLevel ) ; <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Generic Specialization <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + std : : string GenericSpecializationMangler : : mangle ( ) { <nl> + beginMangling ( ) ; <nl> + <nl> + SILFunctionType * FTy = Function - > getLoweredFunctionType ( ) ; <nl> + CanGenericSignature Sig = FTy - > getGenericSignature ( ) ; <nl> + <nl> + unsigned idx = 0 ; <nl> + bool First = true ; <nl> + for ( Type DepType : Sig - > getAllDependentTypes ( ) ) { <nl> + / / It is sufficient to only mangle the substitutions of the " primary " <nl> + / / dependent types . As all other dependent types are just derived from the <nl> + / / primary types , this will give us unique symbol names . <nl> + if ( DepType - > is < GenericTypeParamType > ( ) ) { <nl> + appendType ( Subs [ idx ] . getReplacement ( ) - > getCanonicalType ( ) ) ; <nl> + appendListSeparator ( First ) ; <nl> + } <nl> + + + idx ; <nl> + } <nl> + assert ( idx = = Subs . size ( ) & & " subs not parallel to dependent types " ) ; <nl> + assert ( ! First & & " no generic substitutions " ) ; <nl> + <nl> + appendSpecializationOperator ( isReAbstracted ? " Tg " : " TG " ) ; <nl> + return finalize ( ) ; <nl> + } <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Function Signature Optimizations <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + FunctionSignatureSpecializationMangler : : <nl> + FunctionSignatureSpecializationMangler ( SpecializationPass P , <nl> + IsFragile_t Fragile , SILFunction * F ) <nl> + : SpecializationMangler ( P , Fragile , F ) { <nl> + for ( unsigned i = 0 , e = F - > getLoweredFunctionType ( ) - > getNumSILArguments ( ) ; <nl> + i ! = e ; + + i ) { <nl> + ( void ) i ; <nl> + Args . push_back ( { ArgumentModifierIntBase ( ArgumentModifier : : Unmodified ) , <nl> + nullptr } ) ; <nl> + } <nl> + ReturnValue = ReturnValueModifierIntBase ( ReturnValueModifier : : Unmodified ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentDead ( unsigned ArgNo ) { <nl> + Args [ ArgNo ] . first | = ArgumentModifierIntBase ( ArgumentModifier : : Dead ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentClosureProp ( unsigned ArgNo , PartialApplyInst * PAI ) { <nl> + auto & Info = Args [ ArgNo ] ; <nl> + Info . first = ArgumentModifierIntBase ( ArgumentModifier : : ClosureProp ) ; <nl> + Info . second = PAI ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentClosureProp ( unsigned ArgNo , ThinToThickFunctionInst * TTTFI ) { <nl> + auto & Info = Args [ ArgNo ] ; <nl> + Info . first = ArgumentModifierIntBase ( ArgumentModifier : : ClosureProp ) ; <nl> + Info . second = TTTFI ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentConstantProp ( unsigned ArgNo , LiteralInst * LI ) { <nl> + auto & Info = Args [ ArgNo ] ; <nl> + Info . first = ArgumentModifierIntBase ( ArgumentModifier : : ConstantProp ) ; <nl> + Info . second = LI ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentOwnedToGuaranteed ( unsigned ArgNo ) { <nl> + Args [ ArgNo ] . first | = ArgumentModifierIntBase ( ArgumentModifier : : OwnedToGuaranteed ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentSROA ( unsigned ArgNo ) { <nl> + Args [ ArgNo ] . first | = ArgumentModifierIntBase ( ArgumentModifier : : SROA ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentBoxToValue ( unsigned ArgNo ) { <nl> + Args [ ArgNo ] . first = ArgumentModifierIntBase ( ArgumentModifier : : BoxToValue ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setArgumentBoxToStack ( unsigned ArgNo ) { <nl> + Args [ ArgNo ] . first = ArgumentModifierIntBase ( ArgumentModifier : : BoxToStack ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : <nl> + setReturnValueOwnedToUnowned ( ) { <nl> + ReturnValue | = ReturnValueModifierIntBase ( ReturnValueModifier : : OwnedToUnowned ) ; <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : mangleConstantProp ( LiteralInst * LI ) { <nl> + / / Append the prefix for constant propagation ' p ' . <nl> + ArgOpBuffer < < ' p ' ; <nl> + <nl> + / / Then append the unique identifier of our literal . <nl> + switch ( LI - > getKind ( ) ) { <nl> + default : <nl> + llvm_unreachable ( " unknown literal " ) ; <nl> + case ValueKind : : FunctionRefInst : { <nl> + SILFunction * F = cast < FunctionRefInst > ( LI ) - > getReferencedFunction ( ) ; <nl> + ArgOpBuffer < < ' f ' ; <nl> + appendIdentifier ( F - > getName ( ) ) ; <nl> + break ; <nl> + } <nl> + case ValueKind : : GlobalAddrInst : { <nl> + SILGlobalVariable * G = cast < GlobalAddrInst > ( LI ) - > getReferencedGlobal ( ) ; <nl> + ArgOpBuffer < < ' g ' ; <nl> + appendIdentifier ( G - > getName ( ) ) ; <nl> + break ; <nl> + } <nl> + case ValueKind : : IntegerLiteralInst : { <nl> + APInt apint = cast < IntegerLiteralInst > ( LI ) - > getValue ( ) ; <nl> + ArgOpBuffer < < ' i ' < < apint ; <nl> + break ; <nl> + } <nl> + case ValueKind : : FloatLiteralInst : { <nl> + APInt apint = cast < FloatLiteralInst > ( LI ) - > getBits ( ) ; <nl> + ArgOpBuffer < < ' d ' < < apint ; <nl> + break ; <nl> + } <nl> + case ValueKind : : StringLiteralInst : { <nl> + StringLiteralInst * SLI = cast < StringLiteralInst > ( LI ) ; <nl> + StringRef V = SLI - > getValue ( ) ; <nl> + assert ( V . size ( ) < = 32 & & " Cannot encode string of length > 32 " ) ; <nl> + std : : string VBuffer ; <nl> + if ( V . size ( ) > 0 & & ( isDigit ( V [ 0 ] ) | | V [ 0 ] = = ' _ ' ) ) { <nl> + VBuffer = " _ " ; <nl> + VBuffer . append ( V . data ( ) , V . size ( ) ) ; <nl> + V = VBuffer ; <nl> + } <nl> + appendIdentifier ( V ) ; <nl> + <nl> + ArgOpBuffer < < ' s ' ; <nl> + switch ( SLI - > getEncoding ( ) ) { <nl> + case StringLiteralInst : : Encoding : : UTF8 : ArgOpBuffer < < ' b ' ; break ; <nl> + case StringLiteralInst : : Encoding : : UTF16 : ArgOpBuffer < < ' w ' ; break ; <nl> + case StringLiteralInst : : Encoding : : ObjCSelector : ArgOpBuffer < < ' c ' ; break ; <nl> + } <nl> + break ; <nl> + } <nl> + } <nl> + } <nl> + <nl> + void <nl> + FunctionSignatureSpecializationMangler : : mangleClosureProp ( SILInstruction * Inst ) { <nl> + ArgOpBuffer < < ' c ' ; <nl> + <nl> + / / Add in the partial applies function name if we can find one . Assert <nl> + / / otherwise . The reason why this is ok to do is currently we only perform <nl> + / / closure specialization if we know the function_ref in question . When this <nl> + / / restriction is removed , the assert here will fire . <nl> + if ( auto * TTTFI = dyn_cast < ThinToThickFunctionInst > ( Inst ) ) { <nl> + auto * FRI = cast < FunctionRefInst > ( TTTFI - > getCallee ( ) ) ; <nl> + appendIdentifier ( FRI - > getReferencedFunction ( ) - > getName ( ) ) ; <nl> + return ; <nl> + } <nl> + auto * PAI = cast < PartialApplyInst > ( Inst ) ; <nl> + auto * FRI = cast < FunctionRefInst > ( PAI - > getCallee ( ) ) ; <nl> + appendIdentifier ( FRI - > getReferencedFunction ( ) - > getName ( ) ) ; <nl> + <nl> + / / Then we mangle the types of the arguments that the partial apply is <nl> + / / specializing . <nl> + for ( auto & Op : PAI - > getArgumentOperands ( ) ) { <nl> + SILType Ty = Op . get ( ) - > getType ( ) ; <nl> + appendType ( Ty . getSwiftRValueType ( ) ) ; <nl> + } <nl> + } <nl> + <nl> + void FunctionSignatureSpecializationMangler : : mangleArgument ( <nl> + ArgumentModifierIntBase ArgMod , NullablePtr < SILInstruction > Inst ) { <nl> + if ( ArgMod = = ArgumentModifierIntBase ( ArgumentModifier : : ConstantProp ) ) { <nl> + mangleConstantProp ( cast < LiteralInst > ( Inst . get ( ) ) ) ; <nl> + return ; <nl> + } <nl> + <nl> + if ( ArgMod = = ArgumentModifierIntBase ( ArgumentModifier : : ClosureProp ) ) { <nl> + mangleClosureProp ( Inst . get ( ) ) ; <nl> + return ; <nl> + } <nl> + <nl> + if ( ArgMod = = ArgumentModifierIntBase ( ArgumentModifier : : Unmodified ) ) { <nl> + ArgOpBuffer < < ' n ' ; <nl> + return ; <nl> + } <nl> + <nl> + if ( ArgMod = = ArgumentModifierIntBase ( ArgumentModifier : : BoxToValue ) ) { <nl> + ArgOpBuffer < < ' i ' ; <nl> + return ; <nl> + } <nl> + <nl> + if ( ArgMod = = ArgumentModifierIntBase ( ArgumentModifier : : BoxToStack ) ) { <nl> + ArgOpBuffer < < ' s ' ; <nl> + return ; <nl> + } <nl> + <nl> + bool hasSomeMod = false ; <nl> + if ( ArgMod & ArgumentModifierIntBase ( ArgumentModifier : : Dead ) ) { <nl> + ArgOpBuffer < < ' d ' ; <nl> + hasSomeMod = true ; <nl> + } <nl> + <nl> + if ( ArgMod & ArgumentModifierIntBase ( ArgumentModifier : : OwnedToGuaranteed ) ) { <nl> + ArgOpBuffer < < ( hasSomeMod ? ' G ' : ' g ' ) ; <nl> + hasSomeMod = true ; <nl> + } <nl> + if ( ArgMod & ArgumentModifierIntBase ( ArgumentModifier : : SROA ) ) { <nl> + ArgOpBuffer < < ( hasSomeMod ? ' X ' : ' x ' ) ; <nl> + hasSomeMod = true ; <nl> + } <nl> + <nl> + assert ( hasSomeMod & & " Unknown modifier " ) ; <nl> + } <nl> + <nl> + void FunctionSignatureSpecializationMangler : : <nl> + mangleReturnValue ( ReturnValueModifierIntBase RetMod ) { <nl> + if ( RetMod = = ReturnValueModifierIntBase ( ReturnValueModifier : : Unmodified ) ) { <nl> + ArgOpBuffer < < ' n ' ; <nl> + return ; <nl> + } <nl> + <nl> + bool hasSomeMode = false ; <nl> + if ( RetMod & ReturnValueModifierIntBase ( ReturnValueModifier : : Dead ) ) { <nl> + ArgOpBuffer < < ' d ' ; <nl> + hasSomeMode = true ; <nl> + } <nl> + <nl> + if ( RetMod & ReturnValueModifierIntBase ( ReturnValueModifier : : OwnedToUnowned ) ) { <nl> + ArgOpBuffer < < ( hasSomeMode ? ' G ' : ' g ' ) ; <nl> + } <nl> + } <nl> + <nl> + std : : string FunctionSignatureSpecializationMangler : : mangle ( ) { <nl> + beginMangling ( ) ; <nl> + <nl> + for ( unsigned i : indices ( Args ) ) { <nl> + ArgumentModifierIntBase ArgMod ; <nl> + NullablePtr < SILInstruction > Inst ; <nl> + std : : tie ( ArgMod , Inst ) = Args [ i ] ; <nl> + mangleArgument ( ArgMod , Inst ) ; <nl> + } <nl> + ArgOpBuffer < < ' _ ' ; <nl> + mangleReturnValue ( ReturnValue ) ; <nl> + <nl> + appendSpecializationOperator ( " Tf " ) ; <nl> + return finalize ( ) ; <nl> + } <nl>
Mangling : mangler , demangler and remangler classes for the new mangling scheme .
apple/swift
684092d7d164fd427de09bc11a83c4e9b892a17b
2016-12-02T23:55:30Z
mmm a / xbmc / guilib / MatrixGLES . h <nl> ppp b / xbmc / guilib / MatrixGLES . h <nl> <nl> + # pragma once <nl> / * <nl> * Copyright ( C ) 2005 - 2008 Team XBMC <nl> * http : / / www . xbmc . org <nl> <nl> * <nl> * / <nl> <nl> - # ifndef MATRIX_GLES_H <nl> - # define MATRIX_GLES_H <nl> - <nl> - # pragma once <nl> - <nl> # include < vector > <nl> # include < string . h > <nl> <nl> - using namespace std ; <nl> - <nl> enum EMATRIXMODE <nl> { <nl> MM_PROJECTION = 0 , <nl> class CMatrixGLES <nl> float m_values [ 16 ] ; <nl> } ; <nl> <nl> - vector < struct MatrixWrapper > m_matrices [ ( int ) MM_MATRIXSIZE ] ; <nl> + std : : vector < struct MatrixWrapper > m_matrices [ ( int ) MM_MATRIXSIZE ] ; <nl> GLfloat * m_pMatrix ; <nl> EMATRIXMODE m_matrixMode ; <nl> } ; <nl> <nl> extern CMatrixGLES g_matrices ; <nl> - <nl> - # endif / / MATRIX_GLES_H <nl>
[ gles ] changed . 1 ) do not spew ' namespace std ' into the build , it is silly . 2 ) use # pragma once and drop the guard games , modern compilers support # pragma once
xbmc/xbmc
1f62d2f489971c7a587b996a69a37d8f2aaa3350
2012-03-29T16:39:17Z
mmm a / xbmc / lib / libPython / xbmcmodule / xbmcmodule . cpp <nl> ppp b / xbmc / lib / libPython / xbmcmodule / xbmcmodule . cpp <nl> namespace PYXBMC <nl> " \ n " <nl> " path : string or unicode - Path to format \ n " <nl> " \ n " <nl> - " * Note , Only useful if you are coding for both Linux and the Xbox . \ n " <nl> + " * Note , Only useful if you are coding for both Linux and Windows / Xbox . \ n " <nl> " e . g . Converts ' special : / / masterprofile / script_data ' - > ' / home / user / XBMC / UserData / script_data ' \ n " <nl> " on Linux . Would return ' special : / / masterprofile / script_data ' on the Xbox . \ n " <nl> " \ n " <nl> namespace PYXBMC <nl> return Py_BuildValue ( ( char * ) " s " , strPath . c_str ( ) ) ; <nl> } <nl> <nl> + / / validatePath function <nl> + PyDoc_STRVAR ( validatePath__doc__ , <nl> + " validatePath ( path ) - - Returns the validated path . \ n " <nl> + " \ n " <nl> + " path : string or unicode - Path to format \ n " <nl> + " \ n " <nl> + " * Note , Only useful if you are coding for both Linux and Windows / Xbox for fixing slash problems . \ n " <nl> + " e . g . Corrects ' Z : / / something ' - > ' Z : \ \ something ' \ n " <nl> + " \ n " <nl> + " example : \ n " <nl> + " - fpath = xbmc . validatePath ( somepath ) \ n " ) ; <nl> + <nl> + PyObject * XBMC_ValidatePath ( PyObject * self , PyObject * args ) <nl> + { <nl> + PyObject * pObjectText ; <nl> + if ( ! PyArg_ParseTuple ( args , ( char * ) " O " , & pObjectText ) ) return NULL ; <nl> + <nl> + CStdString strText ; <nl> + if ( ! PyXBMCGetUnicodeString ( strText , pObjectText , 1 ) ) return NULL ; <nl> + <nl> + return Py_BuildValue ( ( char * ) " s " , CUtil : : ValidatePath ( strText ) . c_str ( ) ) ; <nl> + } <nl> + <nl> / / getRegion function <nl> PyDoc_STRVAR ( getRegion__doc__ , <nl> " getRegion ( id ) - - Returns your regions setting as a string for the specified id . \ n " <nl>
added : Allow the use of our ValidatePath ( ) function in Python
xbmc/xbmc
69f92a1b6c5a8b7fc3b66e21514d1bcccfb67c15
2010-02-22T07:53:22Z
mmm a / templates / cocos2dx_files . json <nl> ppp b / templates / cocos2dx_files . json <nl> <nl> " cocos / network / CMakeLists . txt " , <nl> " cocos / network / HttpAsynConnection . h " , <nl> " cocos / network / HttpAsynConnection . m " , <nl> + " cocos / network / HttpClient - android . cpp " , <nl> " cocos / network / HttpClient - ios . mm " , <nl> " cocos / network / HttpClient . cpp " , <nl> " cocos / network / HttpClient . h " , <nl> <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxGLSurfaceView . java " , <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxHandler . java " , <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxHelper . java " , <nl> + " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxHttpURLConnection . java " , <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxLocalStorage . java " , <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxLuaJavaBridge . java " , <nl> " cocos / platform / android / java / src / org / cocos2dx / lib / Cocos2dxMusic . java " , <nl>
Merge pull request from CocosRobot / update_cocosfiles_1420002076
cocos2d/cocos2d-x
1c66f2c90d713a4726f8965d564274bbeb24d082
2014-12-31T05:34:50Z
mmm a / modules / perception / lib / pcl_util / BUILD <nl> ppp b / modules / perception / lib / pcl_util / BUILD <nl> cc_library ( <nl> srcs = [ ] , <nl> hdrs = glob ( [ " * . h " ] ) , <nl> deps = [ <nl> - " @ pcl " , <nl> + " @ pcl / / : pcl " , <nl> ] , <nl> ) <nl> <nl> mmm a / modules / perception / lib / pcl_util / pcl_types . h <nl> ppp b / modules / perception / lib / pcl_util / pcl_types . h <nl> <nl> # ifndef MODULES_PERCEPTION_LIB_PCL_UTIL_PCL_TYPES_H_ <nl> # define MODULES_PERCEPTION_LIB_PCL_UTIL_PCL_TYPES_H_ <nl> <nl> - # include " pcl / common / time . h " <nl> - # include " pcl / common / transforms . h " <nl> - # include " pcl / kdtree / kdtree_flann . h " <nl> - # include " pcl / point_cloud . h " <nl> - # include " pcl / point_types . h " <nl> - # include " pcl / search / impl / kdtree . hpp " <nl> + # include < pcl / common / time . h > <nl> + # include < pcl / common / transforms . h > <nl> + # include < pcl / kdtree / kdtree_flann . h > <nl> + # include < pcl / point_cloud . h > <nl> + # include < pcl / point_types . h > <nl> + # include < pcl / search / impl / kdtree . hpp > <nl> <nl> namespace apollo { <nl> namespace perception { <nl>
Perception : update pcl_util
ApolloAuto/apollo
82c2d2afb4254f656918d73287529f82d15f612a
2018-03-03T08:03:55Z
mmm a / atom / browser / atom_browser_context . cc <nl> ppp b / atom / browser / atom_browser_context . cc <nl> <nl> # include " base / command_line . h " <nl> # include " base / threading / sequenced_worker_pool . h " <nl> # include " base / threading / worker_pool . h " <nl> - # include " chrome / browser / browser_process . h " <nl> # include " content / public / browser / browser_thread . h " <nl> # include " content / public / common / url_constants . h " <nl> # include " net / ftp / ftp_network_layer . h " <nl> class NoCacheBackend : public net : : HttpCache : : BackendFactory { <nl> } / / namespace <nl> <nl> AtomBrowserContext : : AtomBrowserContext ( ) <nl> - : fake_browser_process_ ( new BrowserProcess ) , <nl> - job_factory_ ( new AtomURLRequestJobFactory ) { <nl> + : job_factory_ ( new AtomURLRequestJobFactory ) { <nl> } <nl> <nl> AtomBrowserContext : : ~ AtomBrowserContext ( ) { <nl> mmm a / atom / browser / atom_browser_context . h <nl> ppp b / atom / browser / atom_browser_context . h <nl> <nl> <nl> # include " brightray / browser / browser_context . h " <nl> <nl> - class BrowserProcess ; <nl> - <nl> namespace atom { <nl> <nl> class AtomURLRequestJobFactory ; <nl> class AtomBrowserContext : public brightray : : BrowserContext { <nl> AtomURLRequestJobFactory * job_factory ( ) const { return job_factory_ ; } <nl> <nl> private : <nl> - / / A fake BrowserProcess object that used to feed the source code from chrome . <nl> - scoped_ptr < BrowserProcess > fake_browser_process_ ; <nl> scoped_ptr < WebViewManager > guest_manager_ ; <nl> <nl> AtomURLRequestJobFactory * job_factory_ ; / / Weak reference . <nl> mmm a / atom / browser / atom_browser_main_parts . cc <nl> ppp b / atom / browser / atom_browser_main_parts . cc <nl> <nl> # include " atom / common / api / atom_bindings . h " <nl> # include " atom / common / node_bindings . h " <nl> # include " base / command_line . h " <nl> + # include " chrome / browser / browser_process . h " <nl> # include " v8 / include / v8 - debug . h " <nl> <nl> # if defined ( USE_X11 ) <nl> namespace atom { <nl> AtomBrowserMainParts * AtomBrowserMainParts : : self_ = NULL ; <nl> <nl> AtomBrowserMainParts : : AtomBrowserMainParts ( ) <nl> - : browser_ ( new Browser ) , <nl> + : fake_browser_process_ ( new BrowserProcess ) , <nl> + browser_ ( new Browser ) , <nl> node_bindings_ ( NodeBindings : : Create ( true ) ) , <nl> atom_bindings_ ( new AtomBindings ) , <nl> gc_timer_ ( true , true ) { <nl> mmm a / atom / browser / atom_browser_main_parts . h <nl> ppp b / atom / browser / atom_browser_main_parts . h <nl> <nl> # include " base / timer / timer . h " <nl> # include " brightray / browser / browser_main_parts . h " <nl> <nl> + class BrowserProcess ; <nl> + <nl> namespace atom { <nl> <nl> class AtomBindings ; <nl> class AtomBrowserMainParts : public brightray : : BrowserMainParts { <nl> void SetDPIFromGSettings ( ) ; <nl> # endif <nl> <nl> + / / A fake BrowserProcess object that used to feed the source code from chrome . <nl> + scoped_ptr < BrowserProcess > fake_browser_process_ ; <nl> + <nl> scoped_ptr < Browser > browser_ ; <nl> scoped_ptr < JavascriptEnvironment > js_env_ ; <nl> scoped_ptr < NodeBindings > node_bindings_ ; <nl>
Move BrowserProcess to BrowserMainParts
electron/electron
e6341ceaaa3b69f21ead550a273be0f25c3d7407
2015-06-18T08:34:02Z