diff
stringlengths
41
2.03M
msg
stringlengths
1
1.5k
repo
stringlengths
5
40
sha
stringlengths
40
40
time
stringlengths
20
20
mmm a / validation - test / stdlib / StringMemoryTest . swift <nl> ppp b / validation - test / stdlib / StringMemoryTest . swift <nl> func lowercase ( _ str : String ) - > String { <nl> / / / Make sure the hash function does not leak . <nl> <nl> let dict = [ " foo " : 1 ] <nl> - for _ in 0 . . < 1_000_000 { <nl> + for _ in 0 . . < 10_000_000 { <nl> if lookup ( " \ u { 1F1E7 } \ u { 1F1E7 } " , dict ) { <nl> print ( " Found ? ! " ) <nl> } <nl> getrusage ( RUSAGE_SELF , & usage ) <nl> / / CHECK : success <nl> / / CHECK - NOT : failure <nl> <nl> - / / We should not need 10MB for this . <nl> - if usage . ru_maxrss > 10 * 1024 * 1024 { <nl> - print ( " failure - should not need 10MB ! " ) <nl> + / / We should not need 50MB for this . <nl> + if usage . ru_maxrss > 50 * 1024 * 1024 { <nl> + print ( " failure - should not need 50MB ! " ) <nl> } else { <nl> print ( " success " ) <nl> } <nl>
Revert " [ StringMemoryTest ] Reduce # of iterations down to 1M and lower memory threshold "
apple/swift
98ad5a496ebea5dd03dbb74ecacd634ad7545eb4
2019-03-07T08:15:34Z
mmm a / cocos / 2d / CCLabel . h <nl> ppp b / cocos / 2d / CCLabel . h <nl> class CC_DLL Label : public SpriteBatchNode , public LabelProtocol , public RGBAPr <nl> <nl> / / CCLabelTextFormat protocol implementation <nl> virtual std : : vector < LetterInfo > * getLettersInfo ( ) override { return & _lettersInfo ; } ; <nl> - virtual bool recordLetterInfo ( const cocos2d : : Point & point , unsigned short int theChar , int spriteIndex ) override ; <nl> - virtual bool recordPlaceholderInfo ( int spriteIndex ) override ; <nl> - virtual float getLetterPosXLeft ( int index ) const override ; <nl> - virtual float getLetterPosXRight ( int index ) const override ; <nl> + virtual bool recordLetterInfo ( const cocos2d : : Point & point , unsigned short int theChar , int spriteIndex ) override ; <nl> + virtual bool recordPlaceholderInfo ( int spriteIndex ) override ; <nl> + virtual float getLetterPosXLeft ( int index ) const override ; <nl> + virtual float getLetterPosXRight ( int index ) const override ; <nl> <nl> - virtual Sprite * getLetter ( int ID ) override ; <nl> + virtual Sprite * getLetter ( int ID ) override ; <nl> <nl> / / font related stuff <nl> - virtual int getCommonLineHeight ( ) const override ; <nl> - virtual int getKerningForCharsPair ( unsigned short first , unsigned short second ) const override ; <nl> - virtual int getXOffsetForChar ( unsigned short c ) const override ; <nl> - virtual int getYOffsetForChar ( unsigned short c ) const override ; <nl> - virtual int getAdvanceForChar ( unsigned short c , int hintPositionInString ) const override ; <nl> - virtual Rect getRectForChar ( unsigned short c ) const override ; <nl> + virtual int getCommonLineHeight ( ) const override ; <nl> + virtual int getKerningForCharsPair ( unsigned short first , unsigned short second ) const override ; <nl> + virtual int getXOffsetForChar ( unsigned short c ) const override ; <nl> + virtual int getYOffsetForChar ( unsigned short c ) const override ; <nl> + virtual int getAdvanceForChar ( unsigned short c , int hintPositionInString ) const override ; <nl> + virtual Rect getRectForChar ( unsigned short c ) const override ; <nl> <nl> / / string related stuff <nl> - virtual int getStringNumLines ( ) const override ; <nl> - virtual int getStringLenght ( ) const override ; <nl> - virtual unsigned short getCharAtStringPosition ( int position ) const override ; <nl> - virtual unsigned short * getUTF8String ( ) const override ; <nl> - virtual void assignNewUTF8String ( unsigned short * newString ) override ; <nl> - virtual TextHAlignment getTextAlignment ( ) const override ; <nl> + virtual int getStringNumLines ( ) const override ; <nl> + virtual int getStringLenght ( ) const override ; <nl> + virtual unsigned short getCharAtStringPosition ( int position ) const override ; <nl> + virtual unsigned short * getUTF8String ( ) const override ; <nl> + virtual void assignNewUTF8String ( unsigned short * newString ) override ; <nl> + virtual TextHAlignment getTextAlignment ( ) const override ; <nl> <nl> / / label related stuff <nl> - virtual float getMaxLineWidth ( ) const override ; <nl> - virtual bool breakLineWithoutSpace ( ) const override ; <nl> - virtual Size getLabelContentSize ( ) const override ; <nl> - virtual void setLabelContentSize ( const Size & newSize ) override ; <nl> + virtual float getMaxLineWidth ( ) const override ; <nl> + virtual bool breakLineWithoutSpace ( ) const override ; <nl> + virtual Size getLabelContentSize ( ) const override ; <nl> + virtual void setLabelContentSize ( const Size & newSize ) override ; <nl> <nl> / / carloX <nl> - const char * getString ( ) const { return " not implemented " ; } <nl> - void addChild ( Node * child , int zOrder = 0 , int tag = 0 ) ; <nl> + virtual const std : : string & getString ( ) const override { static std : : string _ret ( " not implemented " ) ; return _ret ; } <nl> + void addChild ( Node * child , int zOrder = 0 , int tag = 0 ) override ; <nl> <nl> private : <nl> / * * <nl> mmm a / cocos / 2d / CCLabelAtlas . cpp <nl> ppp b / cocos / 2d / CCLabelAtlas . cpp <nl> void LabelAtlas : : setString ( const std : : string & label ) <nl> _quadsToDraw = len ; <nl> } <nl> <nl> - const char * LabelAtlas : : getString ( void ) const <nl> + const std : : string & LabelAtlas : : getString ( void ) const <nl> { <nl> - return _string . c_str ( ) ; <nl> + return _string ; <nl> } <nl> <nl> / / CCLabelAtlas - draw <nl> mmm a / cocos / 2d / CCLabelAtlas . h <nl> ppp b / cocos / 2d / CCLabelAtlas . h <nl> class CC_DLL LabelAtlas : public AtlasNode , public LabelProtocol <nl> <nl> / / super methods <nl> virtual void updateAtlasValues ( ) ; <nl> - virtual void setString ( const std : : string & label ) ; <nl> - virtual const char * getString ( void ) const ; <nl> + <nl> + virtual void setString ( const std : : string & label ) override ; <nl> + virtual const std : : string & getString ( void ) const override ; <nl> <nl> # if CC_LABELATLAS_DEBUG_DRAW <nl> - virtual void draw ( ) ; <nl> + virtual void draw ( ) override ; <nl> # endif <nl> <nl> protected : <nl> mmm a / cocos / 2d / CCLabelBMFont . cpp <nl> ppp b / cocos / 2d / CCLabelBMFont . cpp <nl> void LabelBMFont : : setString ( unsigned short * newString , bool needUpdateLabel ) <nl> } <nl> } <nl> <nl> - const char * LabelBMFont : : getString ( void ) const <nl> + const std : : string & LabelBMFont : : getString ( ) const <nl> { <nl> - return _initialStringUTF8 . c_str ( ) ; <nl> + return _initialStringUTF8 ; <nl> } <nl> <nl> void LabelBMFont : : setCString ( const char * label ) <nl> mmm a / cocos / 2d / CCLabelBMFont . h <nl> ppp b / cocos / 2d / CCLabelBMFont . h <nl> class CC_DLL LabelBMFont : public SpriteBatchNode , public LabelProtocol , public <nl> / * * updates the font chars based on the string to render * / <nl> void createFontChars ( ) ; <nl> / / super method <nl> - virtual void setString ( const std : : string & newString ) ; <nl> + virtual void setString ( const std : : string & newString ) override ; <nl> virtual void setString ( const std : : string & newString , bool needUpdateLabel ) ; <nl> <nl> - virtual const char * getString ( ) const ; <nl> + virtual const std : : string & getString ( ) const override ; <nl> virtual void setCString ( const char * label ) ; <nl> virtual void setAnchorPoint ( const Point & var ) ; <nl> virtual void updateLabel ( ) ; <nl> mmm a / cocos / 2d / CCLabelTTF . cpp <nl> ppp b / cocos / 2d / CCLabelTTF . cpp <nl> void LabelTTF : : setString ( const std : : string & string ) <nl> } <nl> } <nl> <nl> - const char * LabelTTF : : getString ( void ) const <nl> + const std : : string & LabelTTF : : getString ( ) const <nl> { <nl> - return _string . c_str ( ) ; <nl> + return _string ; <nl> } <nl> <nl> const char * LabelTTF : : description ( ) const <nl> mmm a / cocos / 2d / CCLabelTTF . h <nl> ppp b / cocos / 2d / CCLabelTTF . h <nl> class CC_DLL LabelTTF : public Sprite , public LabelProtocol <nl> / * * changes the string to render <nl> * @ warning Changing the string is as expensive as creating a new LabelTTF . To obtain better performance use LabelAtlas <nl> * / <nl> - virtual void setString ( const std : : string & label ) ; <nl> - virtual const char * getString ( void ) const ; <nl> + virtual void setString ( const std : : string & label ) override ; <nl> + virtual const std : : string & getString ( void ) const override ; <nl> <nl> TextHAlignment getHorizontalAlignment ( ) const ; <nl> void setHorizontalAlignment ( TextHAlignment alignment ) ; <nl> mmm a / cocos / 2d / CCProtocols . h <nl> ppp b / cocos / 2d / CCProtocols . h <nl> class CC_DLL LabelProtocol <nl> * @ js NA <nl> * @ lua NA <nl> * / <nl> - virtual const char * getString ( ) const = 0 ; <nl> + virtual const std : : string & getString ( ) const = 0 ; <nl> } ; <nl> <nl> / * * <nl> mmm a / cocos / 2d / CCTextFieldTTF . cpp <nl> ppp b / cocos / 2d / CCTextFieldTTF . cpp <nl> static int _calcCharCount ( const char * pszText ) <nl> TextFieldTTF : : TextFieldTTF ( ) <nl> : _delegate ( 0 ) <nl> , _charCount ( 0 ) <nl> - , _inputText ( new std : : string ) <nl> - , _placeHolder ( new std : : string ) / / prevent LabelTTF initWithString assertion <nl> + , _inputText ( " " ) <nl> + , _placeHolder ( " " ) / / prevent LabelTTF initWithString assertion <nl> , _secureTextEntry ( false ) <nl> { <nl> _colorSpaceHolder . r = _colorSpaceHolder . g = _colorSpaceHolder . b = 127 ; <nl> TextFieldTTF : : TextFieldTTF ( ) <nl> <nl> TextFieldTTF : : ~ TextFieldTTF ( ) <nl> { <nl> - CC_SAFE_DELETE ( _inputText ) ; <nl> - CC_SAFE_DELETE ( _placeHolder ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / static constructor <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> - TextFieldTTF * TextFieldTTF : : textFieldWithPlaceHolder ( const char * placeholder , const Size & dimensions , TextHAlignment alignment , const char * fontName , float fontSize ) <nl> + TextFieldTTF * TextFieldTTF : : textFieldWithPlaceHolder ( const std : : string & placeholder , const Size & dimensions , TextHAlignment alignment , const std : : string & fontName , float fontSize ) <nl> { <nl> - TextFieldTTF * pRet = new TextFieldTTF ( ) ; <nl> - if ( pRet & & pRet - > initWithPlaceHolder ( " " , dimensions , alignment , fontName , fontSize ) ) <nl> + TextFieldTTF * ret = new TextFieldTTF ( ) ; <nl> + if ( ret & & ret - > initWithPlaceHolder ( " " , dimensions , alignment , fontName , fontSize ) ) <nl> { <nl> - pRet - > autorelease ( ) ; <nl> - if ( placeholder ) <nl> + ret - > autorelease ( ) ; <nl> + if ( placeholder . size ( ) > 0 ) <nl> { <nl> - pRet - > setPlaceHolder ( placeholder ) ; <nl> + ret - > setPlaceHolder ( placeholder ) ; <nl> } <nl> - return pRet ; <nl> + return ret ; <nl> } <nl> - CC_SAFE_DELETE ( pRet ) ; <nl> + CC_SAFE_DELETE ( ret ) ; <nl> return NULL ; <nl> } <nl> <nl> - TextFieldTTF * TextFieldTTF : : textFieldWithPlaceHolder ( const char * placeholder , const char * fontName , float fontSize ) <nl> + TextFieldTTF * TextFieldTTF : : textFieldWithPlaceHolder ( const std : : string & placeholder , const std : : string & fontName , float fontSize ) <nl> { <nl> - TextFieldTTF * pRet = new TextFieldTTF ( ) ; <nl> - if ( pRet & & pRet - > initWithString ( " " , fontName , fontSize ) ) <nl> + TextFieldTTF * ret = new TextFieldTTF ( ) ; <nl> + if ( ret & & ret - > initWithString ( " " , fontName , fontSize ) ) <nl> { <nl> - pRet - > autorelease ( ) ; <nl> - if ( placeholder ) <nl> + ret - > autorelease ( ) ; <nl> + if ( placeholder . size ( ) > 0 ) <nl> { <nl> - pRet - > setPlaceHolder ( placeholder ) ; <nl> + ret - > setPlaceHolder ( placeholder ) ; <nl> } <nl> - return pRet ; <nl> + return ret ; <nl> } <nl> - CC_SAFE_DELETE ( pRet ) ; <nl> + CC_SAFE_DELETE ( ret ) ; <nl> return NULL ; <nl> } <nl> <nl> TextFieldTTF * TextFieldTTF : : textFieldWithPlaceHolder ( const char * placeholder , c <nl> / / initialize <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> - bool TextFieldTTF : : initWithPlaceHolder ( const char * placeholder , const Size & dimensions , TextHAlignment alignment , const char * fontName , float fontSize ) <nl> + bool TextFieldTTF : : initWithPlaceHolder ( const std : : string & placeholder , const Size & dimensions , TextHAlignment alignment , const std : : string & fontName , float fontSize ) <nl> { <nl> - if ( placeholder ) <nl> - { <nl> - CC_SAFE_DELETE ( _placeHolder ) ; <nl> - _placeHolder = new std : : string ( placeholder ) ; <nl> - } <nl> - return LabelTTF : : initWithString ( _placeHolder - > c_str ( ) , fontName , fontSize , dimensions , alignment ) ; <nl> + _placeHolder = placeholder ; <nl> + return LabelTTF : : initWithString ( _placeHolder , fontName , fontSize , dimensions , alignment ) ; <nl> } <nl> - bool TextFieldTTF : : initWithPlaceHolder ( const char * placeholder , const char * fontName , float fontSize ) <nl> + bool TextFieldTTF : : initWithPlaceHolder ( const std : : string & placeholder , const std : : string & fontName , float fontSize ) <nl> { <nl> - if ( placeholder ) <nl> - { <nl> - CC_SAFE_DELETE ( _placeHolder ) ; <nl> - _placeHolder = new std : : string ( placeholder ) ; <nl> - } <nl> - return LabelTTF : : initWithString ( _placeHolder - > c_str ( ) , fontName , fontSize ) ; <nl> + _placeHolder = std : : string ( placeholder ) ; <nl> + return LabelTTF : : initWithString ( _placeHolder , fontName , fontSize ) ; <nl> } <nl> <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> void TextFieldTTF : : insertText ( const char * text , int len ) <nl> } <nl> <nl> _charCount + = _calcCharCount ( sInsert . c_str ( ) ) ; <nl> - std : : string sText ( * _inputText ) ; <nl> + std : : string sText ( _inputText ) ; <nl> sText . append ( sInsert ) ; <nl> - setString ( sText . c_str ( ) ) ; <nl> + setString ( sText ) ; <nl> } <nl> <nl> if ( ( int ) sInsert . npos = = nPos ) { <nl> void TextFieldTTF : : insertText ( const char * text , int len ) <nl> <nl> void TextFieldTTF : : deleteBackward ( ) <nl> { <nl> - int nStrLen = _inputText - > length ( ) ; <nl> + int nStrLen = _inputText . length ( ) ; <nl> if ( ! nStrLen ) <nl> { <nl> / / there is no string <nl> void TextFieldTTF : : deleteBackward ( ) <nl> / / get the delete byte number <nl> int nDeleteLen = 1 ; / / default , erase 1 byte <nl> <nl> - while ( 0x80 = = ( 0xC0 & _inputText - > at ( nStrLen - nDeleteLen ) ) ) <nl> + while ( 0x80 = = ( 0xC0 & _inputText . at ( nStrLen - nDeleteLen ) ) ) <nl> { <nl> + + nDeleteLen ; <nl> } <nl> <nl> - if ( _delegate & & _delegate - > onTextFieldDeleteBackward ( this , _inputText - > c_str ( ) + nStrLen - nDeleteLen , nDeleteLen ) ) <nl> + if ( _delegate & & _delegate - > onTextFieldDeleteBackward ( this , _inputText . c_str ( ) + nStrLen - nDeleteLen , nDeleteLen ) ) <nl> { <nl> / / delegate doesn ' t wan ' t to delete backwards <nl> return ; <nl> void TextFieldTTF : : deleteBackward ( ) <nl> / / if all text deleted , show placeholder string <nl> if ( nStrLen < = nDeleteLen ) <nl> { <nl> - CC_SAFE_DELETE ( _inputText ) ; <nl> - _inputText = new std : : string ; <nl> + _inputText = " " ; <nl> _charCount = 0 ; <nl> - LabelTTF : : setString ( _placeHolder - > c_str ( ) ) ; <nl> + LabelTTF : : setString ( _placeHolder ) ; <nl> return ; <nl> } <nl> <nl> / / set new input text <nl> - std : : string sText ( _inputText - > c_str ( ) , nStrLen - nDeleteLen ) ; <nl> - setString ( sText . c_str ( ) ) ; <nl> + std : : string sText ( _inputText . c_str ( ) , nStrLen - nDeleteLen ) ; <nl> + setString ( sText ) ; <nl> } <nl> <nl> const char * TextFieldTTF : : getContentText ( ) <nl> { <nl> - return _inputText - > c_str ( ) ; <nl> + return _inputText . c_str ( ) ; <nl> } <nl> <nl> void TextFieldTTF : : draw ( ) <nl> void TextFieldTTF : : draw ( ) <nl> { <nl> return ; <nl> } <nl> - if ( _inputText - > length ( ) ) <nl> + if ( _inputText . length ( ) ) <nl> { <nl> LabelTTF : : draw ( ) ; <nl> return ; <nl> void TextFieldTTF : : setColorSpaceHolder ( const Color3B & color ) <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> / / input text property <nl> - void TextFieldTTF : : setString ( const char * text ) <nl> + void TextFieldTTF : : setString ( const std : : string & text ) <nl> { <nl> static char bulletString [ ] = { ( char ) 0xe2 , ( char ) 0x80 , ( char ) 0xa2 , ( char ) 0x00 } ; <nl> std : : string displayText ; <nl> int length ; <nl> <nl> - CC_SAFE_DELETE ( _inputText ) ; <nl> - <nl> - if ( text ) <nl> + if ( text . length ( ) > 0 ) <nl> { <nl> - _inputText = new std : : string ( text ) ; <nl> - displayText = * _inputText ; <nl> + _inputText = text ; <nl> + displayText = _inputText ; <nl> if ( _secureTextEntry ) <nl> { <nl> displayText = " " ; <nl> - length = _inputText - > length ( ) ; <nl> + length = _inputText . length ( ) ; <nl> while ( length ) <nl> { <nl> displayText . append ( bulletString ) ; <nl> void TextFieldTTF : : setString ( const char * text ) <nl> } <nl> else <nl> { <nl> - _inputText = new std : : string ; <nl> + _inputText = " " ; <nl> } <nl> <nl> / / if there is no input text , display placeholder instead <nl> - if ( ! _inputText - > length ( ) ) <nl> + if ( ! _inputText . length ( ) ) <nl> { <nl> - LabelTTF : : setString ( _placeHolder - > c_str ( ) ) ; <nl> + LabelTTF : : setString ( _placeHolder ) ; <nl> } <nl> else <nl> { <nl> - LabelTTF : : setString ( displayText . c_str ( ) ) ; <nl> + LabelTTF : : setString ( displayText ) ; <nl> } <nl> - _charCount = _calcCharCount ( _inputText - > c_str ( ) ) ; <nl> + _charCount = _calcCharCount ( _inputText . c_str ( ) ) ; <nl> } <nl> <nl> - const char * TextFieldTTF : : getString ( void ) const <nl> + const std : : string & TextFieldTTF : : getString ( ) const <nl> { <nl> - return _inputText - > c_str ( ) ; <nl> + return _inputText ; <nl> } <nl> <nl> / / place holder text property <nl> - void TextFieldTTF : : setPlaceHolder ( const char * text ) <nl> + void TextFieldTTF : : setPlaceHolder ( const std : : string & text ) <nl> { <nl> - CC_SAFE_DELETE ( _placeHolder ) ; <nl> - _placeHolder = ( text ) ? new std : : string ( text ) : new std : : string ; <nl> - if ( ! _inputText - > length ( ) ) <nl> + _placeHolder = text ; <nl> + if ( ! _inputText . length ( ) ) <nl> { <nl> - LabelTTF : : setString ( _placeHolder - > c_str ( ) ) ; <nl> + LabelTTF : : setString ( _placeHolder ) ; <nl> } <nl> } <nl> <nl> - const char * TextFieldTTF : : getPlaceHolder ( void ) <nl> + const std : : string & TextFieldTTF : : getPlaceHolder ( ) const <nl> { <nl> - return _placeHolder - > c_str ( ) ; <nl> + return _placeHolder ; <nl> } <nl> <nl> / / secureTextEntry <nl> mmm a / cocos / 2d / CCTextFieldTTF . h <nl> ppp b / cocos / 2d / CCTextFieldTTF . h <nl> class CC_DLL TextFieldTTF : public LabelTTF , public IMEDelegate <nl> / / char * description ( ) ; <nl> <nl> / * * creates a TextFieldTTF from a fontname , alignment , dimension and font size * / <nl> - static TextFieldTTF * textFieldWithPlaceHolder ( const char * placeholder , const Size & dimensions , TextHAlignment alignment , const char * fontName , float fontSize ) ; <nl> + static TextFieldTTF * textFieldWithPlaceHolder ( const std : : string & placeholder , const Size & dimensions , TextHAlignment alignment , const std : : string & fontName , float fontSize ) ; <nl> / * * creates a LabelTTF from a fontname and font size * / <nl> - static TextFieldTTF * textFieldWithPlaceHolder ( const char * placeholder , const char * fontName , float fontSize ) ; <nl> + static TextFieldTTF * textFieldWithPlaceHolder ( const std : : string & placeholder , const std : : string & fontName , float fontSize ) ; <nl> / * * initializes the TextFieldTTF with a font name , alignment , dimension and font size * / <nl> - bool initWithPlaceHolder ( const char * placeholder , const Size & dimensions , TextHAlignment alignment , const char * fontName , float fontSize ) ; <nl> + bool initWithPlaceHolder ( const std : : string & placeholder , const Size & dimensions , TextHAlignment alignment , const std : : string & fontName , float fontSize ) ; <nl> / * * initializes the TextFieldTTF with a font name and font size * / <nl> - bool initWithPlaceHolder ( const char * placeholder , const char * fontName , float fontSize ) ; <nl> + bool initWithPlaceHolder ( const std : : string & placeholder , const std : : string & fontName , float fontSize ) ; <nl> <nl> / * * <nl> @ brief Open keyboard and receive input text . <nl> class CC_DLL TextFieldTTF : public LabelTTF , public IMEDelegate <nl> <nl> / / input text property <nl> public : <nl> - virtual void setString ( const char * text ) ; <nl> - virtual const char * getString ( void ) const ; <nl> + virtual void setString ( const std : : string & text ) override ; <nl> + virtual const std : : string & getString ( ) const override ; <nl> protected : <nl> TextFieldDelegate * _delegate ; <nl> int _charCount ; <nl> <nl> - std : : string * _inputText ; <nl> + std : : string _inputText ; <nl> <nl> / / place holder text property <nl> / / place holder text displayed when there is no text in the text field . <nl> public : <nl> - virtual void setPlaceHolder ( const char * text ) ; <nl> - virtual const char * getPlaceHolder ( void ) ; <nl> + virtual void setPlaceHolder ( const std : : string & text ) ; <nl> + virtual const std : : string & getPlaceHolder ( void ) const ; <nl> protected : <nl> - std : : string * _placeHolder ; <nl> + std : : string _placeHolder ; <nl> Color3B _colorSpaceHolder ; <nl> public : <nl> virtual void setSecureTextEntry ( bool value ) ; <nl> class CC_DLL TextFieldTTF : public LabelTTF , public IMEDelegate <nl> / / IMEDelegate interface <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> <nl> - virtual bool canAttachWithIME ( ) ; <nl> - virtual bool canDetachWithIME ( ) ; <nl> - virtual void insertText ( const char * text , int len ) ; <nl> - virtual void deleteBackward ( ) ; <nl> - virtual const char * getContentText ( ) ; <nl> + virtual bool canAttachWithIME ( ) override ; <nl> + virtual bool canDetachWithIME ( ) override ; <nl> + virtual void insertText ( const char * text , int len ) override ; <nl> + virtual void deleteBackward ( ) override ; <nl> + virtual const char * getContentText ( ) override ; <nl> private : <nl> class LengthStack ; <nl> LengthStack * _lens ; <nl> mmm a / cocos / gui / UIButton . cpp <nl> ppp b / cocos / gui / UIButton . cpp <nl> void UIButton : : setPressedActionEnabled ( bool enabled ) <nl> _pressedActionEnabled = enabled ; <nl> } <nl> <nl> - void UIButton : : setTitleText ( const char * text ) <nl> + void UIButton : : setTitleText ( const std : : string & text ) <nl> { <nl> _titleRenderer - > setString ( text ) ; <nl> } <nl> <nl> - const char * UIButton : : getTitleText ( ) const <nl> + const std : : string & UIButton : : getTitleText ( ) const <nl> { <nl> return _titleRenderer - > getString ( ) ; <nl> } <nl> mmm a / cocos / gui / UIButton . h <nl> ppp b / cocos / gui / UIButton . h <nl> class UIButton : public UIWidget <nl> * / <nl> virtual const char * getDescription ( ) const ; <nl> <nl> - void setTitleText ( const char * text ) ; <nl> - const char * getTitleText ( ) const ; <nl> + void setTitleText ( const std : : string & text ) ; <nl> + const std : : string & getTitleText ( ) const ; <nl> void setTitleColor ( const cocos2d : : Color3B & color ) ; <nl> const cocos2d : : Color3B & getTitleColor ( ) const ; <nl> void setTitleFontSize ( float size ) ; <nl> mmm a / cocos / gui / UILabel . cpp <nl> ppp b / cocos / gui / UILabel . cpp <nl> void UILabel : : initRenderer ( ) <nl> _renderer - > addChild ( _labelRenderer ) ; <nl> } <nl> <nl> - void UILabel : : setText ( const char * text ) <nl> + void UILabel : : setText ( const std : : string & text ) <nl> { <nl> - if ( ! text ) <nl> - { <nl> + if ( text . size ( ) = = 0 ) <nl> return ; <nl> - } <nl> - std : : string strText ( text ) ; <nl> - _labelRenderer - > setString ( strText . c_str ( ) ) ; <nl> + <nl> + _labelRenderer - > setString ( text ) ; <nl> labelScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - const char * UILabel : : getStringValue ( ) <nl> + const std : : string & UILabel : : getStringValue ( ) <nl> { <nl> return _labelRenderer - > getString ( ) ; <nl> } <nl> <nl> int UILabel : : getStringLength ( ) <nl> { <nl> - const char * str = _labelRenderer - > getString ( ) ; <nl> - return strlen ( str ) ; <nl> + return _labelRenderer - > getString ( ) . size ( ) ; <nl> } <nl> <nl> void UILabel : : setFontSize ( int size ) <nl> void UILabel : : setFontSize ( int size ) <nl> labelScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - void UILabel : : setFontName ( const char * name ) <nl> + void UILabel : : setFontName ( const std : : string & name ) <nl> { <nl> _fontName = name ; <nl> _labelRenderer - > setFontName ( name ) ; <nl> mmm a / cocos / gui / UILabel . h <nl> ppp b / cocos / gui / UILabel . h <nl> class UILabel : public UIWidget <nl> * <nl> * @ param text string value . <nl> * / <nl> - void setText ( const char * text ) ; <nl> + void setText ( const std : : string & text ) ; <nl> <nl> / * * <nl> * Gets the string value of label . <nl> * <nl> * @ return text string value . <nl> * / <nl> - const char * getStringValue ( ) ; <nl> + const std : : string & getStringValue ( ) ; <nl> <nl> / * * <nl> * Gets the string length of label . <nl> class UILabel : public UIWidget <nl> * <nl> * @ param font name . <nl> * / <nl> - void setFontName ( const char * name ) ; <nl> + void setFontName ( const std : : string & name ) ; <nl> <nl> / * * <nl> * Sets the touch scale enabled of label . <nl> mmm a / cocos / gui / UILabelAtlas . cpp <nl> ppp b / cocos / gui / UILabelAtlas . cpp <nl> UICCLabelAtlas * UICCLabelAtlas : : create ( ) <nl> return NULL ; <nl> } <nl> <nl> - void UICCLabelAtlas : : setProperty ( const char * string , const char * charMapFile , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) <nl> + void UICCLabelAtlas : : setProperty ( const std : : string & string , const std : : string & charMapFile , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) <nl> { <nl> initWithString ( string , charMapFile , itemWidth , itemHeight , startCharMap ) ; <nl> } <nl> <nl> - void UICCLabelAtlas : : setProperty ( const char * string , cocos2d : : Texture2D * texture , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) <nl> + void UICCLabelAtlas : : setProperty ( const std : : string & string , cocos2d : : Texture2D * texture , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) <nl> { <nl> initWithString ( string , texture , itemWidth , itemHeight , startCharMap ) ; <nl> } <nl> void UILabelAtlas : : initRenderer ( ) <nl> _renderer - > addChild ( _laberAtlasRenderer ) ; <nl> } <nl> <nl> - void UILabelAtlas : : setProperty ( const char * stringValue , const char * charMapFile , int itemWidth , int itemHeight , const char * startCharMap ) <nl> + void UILabelAtlas : : setProperty ( const std : : string & stringValue , const std : : string & charMapFile , int itemWidth , int itemHeight , const std : : string & startCharMap ) <nl> { <nl> _stringValue = stringValue ; <nl> _charMapFileName = charMapFile ; <nl> void UILabelAtlas : : setProperty ( const char * stringValue , const char * charMapFile , <nl> labelAtlasScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - void UILabelAtlas : : setStringValue ( const char * value ) <nl> + void UILabelAtlas : : setStringValue ( const std : : string & value ) <nl> { <nl> _stringValue = value ; <nl> _laberAtlasRenderer - > setString ( value ) ; <nl> labelAtlasScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - const char * UILabelAtlas : : getStringValue ( ) <nl> + const std : : string & UILabelAtlas : : getStringValue ( ) const <nl> { <nl> return _laberAtlasRenderer - > getString ( ) ; <nl> } <nl> void UILabelAtlas : : copySpecialProperties ( UIWidget * widget ) <nl> UILabelAtlas * labelAtlas = dynamic_cast < UILabelAtlas * > ( widget ) ; <nl> if ( labelAtlas ) <nl> { <nl> - setProperty ( labelAtlas - > _stringValue . c_str ( ) , labelAtlas - > _charMapFileName . c_str ( ) , labelAtlas - > _itemWidth , labelAtlas - > _itemHeight , labelAtlas - > _startCharMap . c_str ( ) ) ; <nl> + setProperty ( labelAtlas - > _stringValue , labelAtlas - > _charMapFileName , labelAtlas - > _itemWidth , labelAtlas - > _itemHeight , labelAtlas - > _startCharMap ) ; <nl> } <nl> } <nl> <nl> mmm a / cocos / gui / UILabelAtlas . h <nl> ppp b / cocos / gui / UILabelAtlas . h <nl> class UICCLabelAtlas : public cocos2d : : LabelAtlas <nl> * Allocates and initializes . <nl> * / <nl> static UICCLabelAtlas * create ( ) ; <nl> - void setProperty ( const char * string , const char * charMapFile , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) ; <nl> - void setProperty ( const char * string , cocos2d : : Texture2D * texture , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) ; <nl> + void setProperty ( const std : : string & string , const std : : string & charMapFile , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) ; <nl> + void setProperty ( const std : : string & string , cocos2d : : Texture2D * texture , unsigned int itemWidth , unsigned int itemHeight , unsigned int startCharMap ) ; <nl> virtual void updateDisplayedOpacity ( GLubyte opacity ) ; <nl> virtual void draw ( void ) ; <nl> } ; <nl> class UILabelAtlas : public UIWidget <nl> static UILabelAtlas * create ( ) ; <nl> <nl> / * * initializes the UILabelAtlas with a string , a char map file ( the atlas ) , the width and height of each element and the starting char of the atlas * / <nl> - void setProperty ( const char * stringValue , const char * charMapFile , int itemWidth , int itemHeight , const char * startCharMap ) ; <nl> + void setProperty ( const std : : string & stringValue , const std : : string & charMapFile , int itemWidth , int itemHeight , const std : : string & startCharMap ) ; <nl> <nl> / / set string value for labelatlas . <nl> - void setStringValue ( const char * value ) ; <nl> + void setStringValue ( const std : : string & value ) ; <nl> <nl> / / get string value for labelatlas . <nl> - const char * getStringValue ( ) ; <nl> + const std : : string & getStringValue ( ) const ; <nl> <nl> / / override " setAnchorPoint " method of widget . <nl> virtual void setAnchorPoint ( const cocos2d : : Point & pt ) ; <nl> mmm a / cocos / gui / UITextField . cpp <nl> ppp b / cocos / gui / UITextField . cpp <nl> bool UICCTextField : : onTextFieldDetachWithIME ( cocos2d : : TextFieldTTF * pSender ) <nl> void UICCTextField : : insertText ( const char * text , int len ) <nl> { <nl> std : : string str_text = text ; <nl> - int str_len = strlen ( cocos2d : : TextFieldTTF : : getString ( ) ) ; <nl> + int str_len = cocos2d : : TextFieldTTF : : getString ( ) . size ( ) ; <nl> <nl> if ( strcmp ( text , " \ n " ) ! = 0 ) <nl> { <nl> void UICCTextField : : insertText ( const char * text , int len ) <nl> { <nl> if ( cocos2d : : TextFieldTTF : : getCharCount ( ) > 0 ) <nl> { <nl> - setPasswordText ( _inputText - > c_str ( ) ) ; <nl> + setPasswordText ( _inputText . c_str ( ) ) ; <nl> } <nl> } <nl> } <nl> void UICCTextField : : deleteBackward ( ) <nl> / / password <nl> if ( _passwordEnabled ) <nl> { <nl> - setPasswordText ( _inputText - > c_str ( ) ) ; <nl> + setPasswordText ( _inputText . c_str ( ) ) ; <nl> } <nl> } <nl> } <nl> void UITextField : : setTouchSize ( const cocos2d : : Size & size ) <nl> _touchHeight = size . height ; <nl> } <nl> <nl> - void UITextField : : setText ( const char * text ) <nl> + void UITextField : : setText ( const std : : string & text ) <nl> { <nl> - if ( ! text ) <nl> - { <nl> + if ( text . size ( ) = = 0 ) <nl> return ; <nl> - } <nl> - std : : string strText ( text ) ; <nl> - _textFieldRenderer - > setString ( strText . c_str ( ) ) ; <nl> + <nl> + _textFieldRenderer - > setString ( text ) ; <nl> textfieldRendererScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - void UITextField : : setPlaceHolder ( const char * value ) <nl> + void UITextField : : setPlaceHolder ( const std : : string & value ) <nl> { <nl> _textFieldRenderer - > setPlaceHolder ( value ) ; <nl> textfieldRendererScaleChangedWithSize ( ) ; <nl> void UITextField : : setFontSize ( int size ) <nl> textfieldRendererScaleChangedWithSize ( ) ; <nl> } <nl> <nl> - void UITextField : : setFontName ( const char * name ) <nl> + void UITextField : : setFontName ( const std : : string & name ) <nl> { <nl> _textFieldRenderer - > setFontName ( name ) ; <nl> textfieldRendererScaleChangedWithSize ( ) ; <nl> void UITextField : : didNotSelectSelf ( ) <nl> _textFieldRenderer - > detachWithIME ( ) ; <nl> } <nl> <nl> - const char * UITextField : : getStringValue ( ) <nl> + const std : : string & UITextField : : getStringValue ( ) <nl> { <nl> return _textFieldRenderer - > getString ( ) ; <nl> } <nl> mmm a / cocos / gui / UITextField . h <nl> ppp b / cocos / gui / UITextField . h <nl> class UITextField : public UIWidget <nl> virtual bool init ( ) ; <nl> virtual void initRenderer ( ) ; <nl> void setTouchSize ( const cocos2d : : Size & size ) ; <nl> - void setText ( const char * text ) ; <nl> - void setPlaceHolder ( const char * value ) ; <nl> + void setText ( const std : : string & text ) ; <nl> + void setPlaceHolder ( const std : : string & value ) ; <nl> void setFontSize ( int size ) ; <nl> - void setFontName ( const char * name ) ; <nl> + void setFontName ( const std : : string & name ) ; <nl> virtual void didNotSelectSelf ( ) ; <nl> - const char * getStringValue ( ) ; <nl> + const std : : string & getStringValue ( ) ; <nl> virtual bool onTouchBegan ( const cocos2d : : Point & touchPoint ) ; <nl> void setMaxLengthEnabled ( bool enable ) ; <nl> bool isMaxLengthEnabled ( ) ; <nl> mmm a / samples / Cpp / TestCpp / Classes / controller . cpp <nl> ppp b / samples / Cpp / TestCpp / Classes / controller . cpp <nl> struct { <nl> const char * test_name ; <nl> std : : function < TestScene * ( ) > callback ; <nl> } g_aTestNames [ ] = { <nl> + <nl> + / / <nl> + / / TESTS MUST BE ORDERED ALPHABETICALLY <nl> + / / violators will be prosecuted <nl> + / / <nl> { " Accelerometer " , [ ] ( ) { return new AccelerometerTestScene ( ) ; } } , <nl> { " ActionManagerTest " , [ ] ( ) { return new ActionManagerTestScene ( ) ; } } , <nl> { " ActionsEaseTest " , [ ] ( ) { return new ActionsEaseTestScene ( ) ; } } , <nl> struct { <nl> { " FontTest " , [ ] ( ) { return new FontTestScene ( ) ; } } , <nl> { " IntervalTest " , [ ] ( ) { return new IntervalTestScene ( ) ; } } , <nl> { " KeyboardTest " , [ ] ( ) { return new KeyboardTestScene ( ) ; } } , <nl> - { " MouseTest " , [ ] ( ) { return new MouseTestScene ( ) ; } } , <nl> # if ( CC_TARGET_PLATFORM ! = CC_PLATFORM_BADA ) <nl> { " KeypadTest " , [ ] ( ) { return new KeypadTestScene ( ) ; } } , <nl> # endif <nl> struct { <nl> { " LayerTest " , [ ] ( ) { return new LayerTestScene ( ) ; } } , <nl> { " MenuTest " , [ ] ( ) { return new MenuTestScene ( ) ; } } , <nl> { " MotionStreakTest " , [ ] ( ) { return new MotionStreakTestScene ( ) ; } } , <nl> + { " MouseTest " , [ ] ( ) { return new MouseTestScene ( ) ; } } , <nl> { " MutiTouchTest " , [ ] ( ) { return new MutiTouchTestScene ( ) ; } } , <nl> { " NodeTest " , [ ] ( ) { return new CocosNodeTestScene ( ) ; } } , <nl> { " ParallaxTest " , [ ] ( ) { return new ParallaxTestScene ( ) ; } } , <nl>
Merge pull request from ricardoquesada / love_in_textfield
cocos2d/cocos2d-x
56d7da8933ea06de597b0d7e7ef734fcc5c8682a
2013-11-08T03:14:35Z
mmm a / src / mongo / db / catalog / apply_ops . cpp <nl> ppp b / src / mongo / db / catalog / apply_ops . cpp <nl> namespace mongo { <nl> <nl> / / TODO : possibly use mutable BSON to remove preCondition field <nl> / / once it is available <nl> - BSONObjIterator iter ( applyOpCmd ) ; <nl> BSONObjBuilder cmdBuilder ; <nl> <nl> - while ( iter . more ( ) ) { <nl> - BSONElement elem ( iter . next ( ) ) ; <nl> - if ( strcmp ( elem . fieldName ( ) , " preCondition " ) ! = 0 ) { <nl> - cmdBuilder . append ( elem ) ; <nl> - } <nl> + for ( auto elem : applyOpCmd ) { <nl> + auto name = elem . fieldNameStringData ( ) ; <nl> + if ( name = = " preCondition " ) continue ; <nl> + if ( name = = " bypassDocumentValidation " ) continue ; <nl> + cmdBuilder . append ( elem ) ; <nl> } <nl> <nl> const BSONObj cmdRewritten = cmdBuilder . done ( ) ; <nl> mmm a / src / mongo / db / commands / apply_ops . cpp <nl> ppp b / src / mongo / db / commands / apply_ops . cpp <nl> <nl> # include " mongo / db / auth / privilege . h " <nl> # include " mongo / db / auth / resource_pattern . h " <nl> # include " mongo / db / catalog / apply_ops . h " <nl> + # include " mongo / db / catalog / document_validation . h " <nl> # include " mongo / db / client . h " <nl> # include " mongo / db / commands . h " <nl> # include " mongo / db / commands / dbhash . h " <nl> namespace mongo { <nl> int , <nl> string & errmsg , <nl> BSONObjBuilder & result ) { <nl> + boost : : optional < DisableDocumentValidation > maybeDisableValidation ; <nl> + if ( shouldBypassDocumentValidationforCommand ( cmdObj ) ) <nl> + maybeDisableValidation . emplace ( txn ) ; <nl> + <nl> if ( cmdObj . firstElement ( ) . type ( ) ! = Array ) { <nl> errmsg = " ops has to be an array " ; <nl> return false ; <nl>
SERVER - 18227 Add bypassDocumentValidation support to applyOps
mongodb/mongo
4f96c2817ac72f6d80458137acd8a90b5178e00a
2015-05-15T21:52:02Z
mmm a / lib / Sema / TypeCheckError . cpp <nl> ppp b / lib / Sema / TypeCheckError . cpp <nl> class Context { <nl> Kind TheKind ; <nl> bool DiagnoseErrorOnTry = false ; <nl> DeclContext * RethrowsDC = nullptr ; <nl> - InterpolatedStringLiteralExpr * InterpolatedString ; <nl> + InterpolatedStringLiteralExpr * InterpolatedString = nullptr ; <nl> <nl> explicit Context ( Kind kind ) : TheKind ( kind ) { } <nl> <nl> class Context { <nl> insertLoc = loc ; <nl> highlight = e - > getSourceRange ( ) ; <nl> <nl> - if ( InterpolatedString & & e - > getCalledValue ( ) - > getBaseName ( ) = = <nl> + if ( InterpolatedString & & <nl> + e - > getCalledValue ( ) & & <nl> + e - > getCalledValue ( ) - > getBaseName ( ) = = <nl> TC . Context . Id_appendInterpolation ) { <nl> message = diag : : throwing_interpolation_without_try ; <nl> insertLoc = InterpolatedString - > getLoc ( ) ; <nl> mmm a / test / decl / func / throwing_functions . swift <nl> ppp b / test / decl / func / throwing_functions . swift <nl> struct IllegalContext { <nl> } <nl> } <nl> } <nl> + <nl> + / / Crash in ' uncovered try ' diagnostic when calling a function value - rdar : / / 46973064 <nl> + struct FunctionHolder { <nl> + let fn : ( ) throws - > ( ) <nl> + func receive ( ) { <nl> + do { <nl> + _ = fn ( ) <nl> + / / expected - error @ - 1 { { call can throw but is not marked with ' try ' } } <nl> + / / expected - note @ - 2 { { did you mean to use ' try ' ? } } <nl> + / / expected - note @ - 3 { { did you mean to handle error as optional value ? } } <nl> + / / expected - note @ - 4 { { did you mean to disable error propagation ? } } <nl> + _ = " \ ( fn ( ) ) " <nl> + / / expected - error @ - 1 { { call can throw but is not marked with ' try ' } } <nl> + / / expected - note @ - 2 { { did you mean to use ' try ' ? } } <nl> + / / expected - note @ - 3 { { did you mean to handle error as optional value ? } } <nl> + / / expected - note @ - 4 { { did you mean to disable error propagation ? } } <nl> + } catch { } <nl> + } <nl> + } <nl> + <nl>
Sema : Fix crashes when a call of a closure value is missing a ' try '
apple/swift
f34d2024bebcaf818ccb7535ed166f720d7f40ea
2019-01-09T02:42:30Z
mmm a / src / video_core / renderer_opengl / gl_shader_decompiler . cpp <nl> ppp b / src / video_core / renderer_opengl / gl_shader_decompiler . cpp <nl> class GLSLRegisterManager { <nl> * @ param reg The destination register to use . <nl> * @ param elem The element to use for the operation . <nl> * @ param value The code representing the value to assign . Type has to be half float . <nl> - * @ param type Half float kind of assignment . <nl> - * @ param dest_num_components Number of components in the destionation . <nl> + * @ param merge Half float kind of assignment . <nl> + * @ param dest_num_components Number of components in the destination . <nl> * @ param value_num_components Number of components in the value . <nl> * @ param is_saturated Optional , when True , saturates the provided value . <nl> * @ param dest_elem Optional , the destination element to use for the operation . <nl> class GLSLRegisterManager { <nl> * @ param reg The destination register to use . <nl> * @ param elem The element to use for the operation . <nl> * @ param attribute The input attribute to use as the source value . <nl> + * @ param input_mode The input mode . <nl> * @ param vertex The register that decides which vertex to read from ( used in GS ) . <nl> * / <nl> void SetRegisterToInputAttibute ( const Register & reg , u64 elem , Attribute : : Index attribute , <nl> class GLSLGenerator { <nl> / / Can ' t assign to the constant predicate . <nl> ASSERT ( pred ! = static_cast < u64 > ( Pred : : UnusedIndex ) ) ; <nl> <nl> - const std : : string variable = ' p ' + std : : to_string ( pred ) + ' _ ' + suffix ; <nl> + std : : string variable = ' p ' + std : : to_string ( pred ) + ' _ ' + suffix ; <nl> shader . AddLine ( variable + " = " + value + ' ; ' ) ; <nl> declr_predicates . insert ( std : : move ( variable ) ) ; <nl> } <nl> class GLSLGenerator { <nl> / * <nl> * Transforms the input string GLSL operand into an unpacked half float pair . <nl> * @ note This function returns a float type pair instead of a half float pair . This is because <nl> - * real half floats are not standarized in GLSL but unpackHalf2x16 ( which returns a vec2 ) is . <nl> + * real half floats are not standardized in GLSL but unpackHalf2x16 ( which returns a vec2 ) is . <nl> * @ param operand Input operand . It has to be an unsigned integer . <nl> * @ param type How to unpack the unsigned integer to a half float pair . <nl> * @ param abs Get the absolute value of unpacked half floats . <nl> class GLSLGenerator { <nl> Tegra : : Shader : : VmadType type , u64 byte_height ) { <nl> const std : : string value = [ & ] ( ) { <nl> if ( ! is_chunk ) { <nl> - const auto offset = static_cast < u32 > ( byte_height * 8 ) ; <nl> - return " ( ( " + op + " > > " + std : : to_string ( offset ) + " ) & 0xff ) " ; <nl> + const auto shift = static_cast < u32 > ( byte_height * 8 ) ; <nl> + return " ( ( " + op + " > > " + std : : to_string ( shift ) + " ) & 0xff ) " ; <nl> } <nl> const std : : string zero = " 0 " ; <nl> <nl>
Merge pull request from lioncash / shader
yuzu-emu/yuzu
4cccfb4190ed62a056314043071c45452b98a443
2018-10-23T02:49:49Z
mmm a / hphp / hack / src / client / clientLsp . ml <nl> ppp b / hphp / hack / src / client / clientLsp . ml <nl> let do_initialize ( ) <nl> hoverProvider = true ; <nl> completionProvider = Some { <nl> resolveProvider = true ; <nl> - completion_triggerCharacters = [ " - " ; " > " ; " \ \ " ] ; <nl> + completion_triggerCharacters = [ " $ " ; " > " ; " \ \ " ] ; <nl> } ; <nl> signatureHelpProvider = None ; <nl> definitionProvider = true ; <nl>
autocomplete trigger includes ' $ '
facebook/hhvm
5a76887a71c04c637cd33caca87c9368fff50053
2017-07-14T17:12:20Z
mmm a / core / bind / core_bind . cpp <nl> ppp b / core / bind / core_bind . cpp <nl> String _File : : get_line ( ) const { <nl> return f - > get_line ( ) ; <nl> } <nl> <nl> - Vector < String > _File : : get_csv_line ( String delim ) const { <nl> + Vector < String > _File : : get_csv_line ( const String & p_delim ) const { <nl> ERR_FAIL_COND_V ( ! f , Vector < String > ( ) ) ; <nl> - return f - > get_csv_line ( delim ) ; <nl> + return f - > get_csv_line ( p_delim ) ; <nl> } <nl> <nl> / * * < use this for files WRITTEN in _big_ endian machines ( ie , amiga / mac ) <nl> void _File : : store_line ( const String & p_string ) { <nl> f - > store_line ( p_string ) ; <nl> } <nl> <nl> + void _File : : store_csv_line ( const Vector < String > & p_values , const String & p_delim ) { <nl> + ERR_FAIL_COND ( ! f ) ; <nl> + f - > store_csv_line ( p_values , p_delim ) ; <nl> + } <nl> + <nl> void _File : : store_buffer ( const PoolVector < uint8_t > & p_buffer ) { <nl> <nl> ERR_FAIL_COND ( ! f ) ; <nl> void _File : : _bind_methods ( ) { <nl> ClassDB : : bind_method ( D_METHOD ( " get_real " ) , & _File : : get_real ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_buffer " , " len " ) , & _File : : get_buffer ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_line " ) , & _File : : get_line ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " get_csv_line " , " delim " ) , & _File : : get_csv_line , DEFVAL ( " , " ) ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_as_text " ) , & _File : : get_as_text ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_md5 " , " path " ) , & _File : : get_md5 ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_sha256 " , " path " ) , & _File : : get_sha256 ) ; <nl> void _File : : _bind_methods ( ) { <nl> ClassDB : : bind_method ( D_METHOD ( " set_endian_swap " , " enable " ) , & _File : : set_endian_swap ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_error " ) , & _File : : get_error ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " get_var " ) , & _File : : get_var ) ; <nl> - ClassDB : : bind_method ( D_METHOD ( " get_csv_line " , " delim " ) , & _File : : get_csv_line , DEFVAL ( " , " ) ) ; <nl> <nl> ClassDB : : bind_method ( D_METHOD ( " store_8 " , " value " ) , & _File : : store_8 ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " store_16 " , " value " ) , & _File : : store_16 ) ; <nl> void _File : : _bind_methods ( ) { <nl> ClassDB : : bind_method ( D_METHOD ( " store_real " , " value " ) , & _File : : store_real ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " store_buffer " , " buffer " ) , & _File : : store_buffer ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " store_line " , " line " ) , & _File : : store_line ) ; <nl> + ClassDB : : bind_method ( D_METHOD ( " store_csv_line " , " values " , " delim " ) , & _File : : store_csv_line , DEFVAL ( " , " ) ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " store_string " , " string " ) , & _File : : store_string ) ; <nl> ClassDB : : bind_method ( D_METHOD ( " store_var " , " value " ) , & _File : : store_var ) ; <nl> <nl> mmm a / core / bind / core_bind . h <nl> ppp b / core / bind / core_bind . h <nl> class _File : public Reference { <nl> <nl> PoolVector < uint8_t > get_buffer ( int p_length ) const ; / / / < get an array of bytes <nl> String get_line ( ) const ; <nl> + Vector < String > get_csv_line ( const String & p_delim = " , " ) const ; <nl> String get_as_text ( ) const ; <nl> String get_md5 ( const String & p_path ) const ; <nl> String get_sha256 ( const String & p_path ) const ; <nl> class _File : public Reference { <nl> <nl> void store_string ( const String & p_string ) ; <nl> void store_line ( const String & p_string ) ; <nl> + void store_csv_line ( const Vector < String > & p_values , const String & p_delim = " , " ) ; <nl> <nl> virtual void store_pascal_string ( const String & p_string ) ; <nl> virtual String get_pascal_string ( ) ; <nl> <nl> - Vector < String > get_csv_line ( String delim = " , " ) const ; <nl> - <nl> void store_buffer ( const PoolVector < uint8_t > & p_buffer ) ; / / / < store an array of bytes <nl> <nl> void store_var ( const Variant & p_var ) ; <nl> mmm a / core / os / file_access . cpp <nl> ppp b / core / os / file_access . cpp <nl> String FileAccess : : get_line ( ) const { <nl> return String : : utf8 ( line . get_data ( ) ) ; <nl> } <nl> <nl> - Vector < String > FileAccess : : get_csv_line ( String delim ) const { <nl> + Vector < String > FileAccess : : get_csv_line ( const String & p_delim ) const { <nl> <nl> - ERR_FAIL_COND_V ( delim . length ( ) ! = 1 , Vector < String > ( ) ) ; <nl> + ERR_FAIL_COND_V ( p_delim . length ( ) ! = 1 , Vector < String > ( ) ) ; <nl> <nl> String l ; <nl> int qc = 0 ; <nl> Vector < String > FileAccess : : get_csv_line ( String delim ) const { <nl> CharType c = l [ i ] ; <nl> CharType s [ 2 ] = { 0 , 0 } ; <nl> <nl> - if ( ! in_quote & & c = = delim [ 0 ] ) { <nl> + if ( ! in_quote & & c = = p_delim [ 0 ] ) { <nl> strings . push_back ( current ) ; <nl> current = String ( ) ; <nl> } else if ( c = = ' " ' ) { <nl> void FileAccess : : store_line ( const String & p_line ) { <nl> store_8 ( ' \ n ' ) ; <nl> } <nl> <nl> + void FileAccess : : store_csv_line ( const Vector < String > & p_values , const String & p_delim ) { <nl> + <nl> + ERR_FAIL_COND ( p_delim . length ( ) ! = 1 ) ; <nl> + <nl> + String line = " " ; <nl> + int size = p_values . size ( ) ; <nl> + for ( int i = 0 ; i < size ; + + i ) { <nl> + String value = p_values [ i ] ; <nl> + <nl> + if ( value . find ( " \ " " ) ! = - 1 | | value . find ( p_delim ) ! = - 1 | | value . find ( " \ n " ) ) { <nl> + value = " \ " " + value . replace ( " \ " " , " \ " \ " " ) + " \ " " ; <nl> + } <nl> + if ( i < size - 1 ) { <nl> + value + = p_delim ; <nl> + } <nl> + <nl> + line + = value ; <nl> + } <nl> + <nl> + store_line ( line ) ; <nl> + } <nl> + <nl> void FileAccess : : store_buffer ( const uint8_t * p_src , int p_length ) { <nl> <nl> for ( int i = 0 ; i < p_length ; i + + ) <nl> mmm a / core / os / file_access . h <nl> ppp b / core / os / file_access . h <nl> class FileAccess { <nl> virtual int get_buffer ( uint8_t * p_dst , int p_length ) const ; / / / < get an array of bytes <nl> virtual String get_line ( ) const ; <nl> virtual String get_token ( ) const ; <nl> - virtual Vector < String > get_csv_line ( String delim = " , " ) const ; <nl> + virtual Vector < String > get_csv_line ( const String & p_delim = " , " ) const ; <nl> <nl> / * * < use this for files WRITTEN in _big_ endian machines ( ie , amiga / mac ) <nl> * It ' s not about the current CPU type but file formats . <nl> class FileAccess { <nl> <nl> virtual void store_string ( const String & p_string ) ; <nl> virtual void store_line ( const String & p_line ) ; <nl> + virtual void store_csv_line ( const Vector < String > & p_values , const String & p_delim = " , " ) ; <nl> <nl> virtual void store_pascal_string ( const String & p_string ) ; <nl> virtual String get_pascal_string ( ) ; <nl> mmm a / doc / classes / File . xml <nl> ppp b / doc / classes / File . xml <nl> <nl> < argument index = " 0 " name = " delim " type = " String " default = " & quot ; , & quot ; " > <nl> < / argument > <nl> < description > <nl> - Returns the next value of the file in CSV ( Comma Separated Values ) format . You can pass a different delimiter to use other than the default " , " ( comma ) . <nl> + Returns the next value of the file in CSV ( Comma Separated Values ) format . You can pass a different delimiter to use other than the default " , " ( comma ) , it should be one character long . <nl> < / description > <nl> < / method > <nl> < method name = " get_double " qualifiers = " const " > <nl> <nl> Stores the given array of bytes in the file . <nl> < / description > <nl> < / method > <nl> + < method name = " store_csv_line " > <nl> + < return type = " void " > <nl> + < / return > <nl> + < argument index = " 0 " name = " values " type = " PoolStringArray " default = " & quot ; , & quot ; " > <nl> + < / argument > <nl> + < argument index = " 1 " name = " delim " type = " String " default = " & quot ; , & quot ; " > <nl> + < / argument > <nl> + < description > <nl> + Store the given [ PoolStringArray ] in the file as a line formatted in the CSV ( Comma Separated Values ) format . You can pass a different delimiter to use other than the default " , " ( comma ) , it should be one character long . <nl> + < / description > <nl> + < / method > <nl> < method name = " store_double " > <nl> < return type = " void " > <nl> < / return > <nl>
Add store_csv_line method for File
godotengine/godot
48166a9f3c4ae79f7b8c9de19107b5da079bc175
2018-11-16T10:09:05Z
mmm a / test / brpc_streaming_rpc_unittest . cpp <nl> ppp b / test / brpc_streaming_rpc_unittest . cpp <nl> TEST_F ( StreamingRpcTest , idle_timeout ) { <nl> test : : EchoService_Stub stub ( & channel ) ; <nl> stub . Echo ( & cntl , & request , & response , NULL ) ; <nl> ASSERT_FALSE ( cntl . Failed ( ) ) < < cntl . ErrorText ( ) < < " request_stream = " < < request_stream ; <nl> - usleep ( 10 * 1000 + 800 ) ; <nl> + usleep ( 20 * 1000 + 800 ) ; <nl> ASSERT_EQ ( 0 , brpc : : StreamClose ( request_stream ) ) ; <nl> while ( ! handler . stopped ( ) ) { <nl> usleep ( 100 ) ; <nl>
add sleep time in test StreamingRpcTest idle_timeout
apache/incubator-brpc
8c6a997a654d96cb6e90d883397e61f2ffa1868b
2018-01-09T13:41:22Z
new file mode 100644 <nl> index 000000000 . . c20b9abd2 <nl> mmm / dev / null <nl> ppp b / cmake / FindGflags . cmake <nl> <nl> + set ( _gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES $ { CMAKE_FIND_LIBRARY_SUFFIXES } ) <nl> + <nl> + find_path ( Gflags_INCLUDE_PATH gflags / gflags . h ) <nl> + <nl> + if ( Gflags_STATIC ) <nl> + if ( WIN32 ) <nl> + set ( CMAKE_FIND_LIBRARY_SUFFIXES . lib $ { CMAKE_FIND_LIBRARY_SUFFIXES } ) <nl> + else ( WIN32 ) <nl> + set ( CMAKE_FIND_LIBRARY_SUFFIXES . a $ { CMAKE_FIND_LIBRARY_SUFFIXES } ) <nl> + endif ( WIN32 ) <nl> + endif ( Gflags_STATIC ) <nl> + find_library ( Gflags_LIBRARY NAMES gflags libgflags ) <nl> + if ( Gflags_INCLUDE_PATH AND Gflags_LIBRARY ) <nl> + set ( Gflags_FOUND TRUE ) <nl> + endif ( Gflags_INCLUDE_PATH AND Gflags_LIBRARY ) <nl> + if ( Gflags_FOUND ) <nl> + if ( NOT Gflags_FIND_QUIETLY ) <nl> + message ( STATUS " Found gflags : $ { Gflags_LIBRARY } " ) <nl> + endif ( NOT Gflags_FIND_QUIETLY ) <nl> + else ( Gflags_FOUND ) <nl> + if ( Gflags_FIND_REQUIRED ) <nl> + message ( FATAL_ERROR " Could not find gflags library . " ) <nl> + endif ( Gflags_FIND_REQUIRED ) <nl> + endif ( Gflags_FOUND ) <nl> + <nl> + set ( CMAKE_FIND_LIBRARY_SUFFIXES $ { _gflags_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES } ) <nl>
add FindGflags . cmake
apache/incubator-brpc
7f984db5b2e5d3f8895e61ace0032887d9d2d358
2017-12-07T02:50:54Z
mmm a / toolsrc / src / vcpkg_metrics_uploader . cpp <nl> ppp b / toolsrc / src / vcpkg_metrics_uploader . cpp <nl> using namespace vcpkg ; <nl> <nl> int WINAPI WinMain ( _In_ HINSTANCE , _In_opt_ HINSTANCE , _In_ LPSTR , _In_ int ) <nl> { <nl> - LPWSTR * szArgList ; <nl> int argCount ; <nl> - <nl> - szArgList = CommandLineToArgvW ( GetCommandLineW ( ) , & argCount ) ; <nl> + LPWSTR * szArgList = CommandLineToArgvW ( GetCommandLineW ( ) , & argCount ) ; <nl> <nl> Checks : : check_exit ( VCPKG_LINE_INFO , argCount = = 2 , " Requires exactly one argument , the path to the payload file " ) ; <nl> Metrics : : upload ( Files : : read_contents ( szArgList [ 1 ] ) . value_or_exit ( VCPKG_LINE_INFO ) ) ; <nl>
Join declaration with assignment
microsoft/vcpkg
d9a403453904261c6b34c5d33557134b9fe3a8a0
2017-04-04T23:47:08Z
mmm a / addons / skin . confluence / language / English / strings . po <nl> ppp b / addons / skin . confluence / language / English / strings . po <nl> msgstr " " <nl> # empty string with id 31407 <nl> <nl> msgctxt " # 31408 " <nl> - msgid " [ B ] CONFIGURE ADD - ONS [ / B ] [ CR ] [ CR ] Manage your installed Add - ons · Browse for and install Add - ons from xbmc . org [ CR ] Modify Add - on settings " <nl> + msgid " [ B ] CONFIGURE ADD - ONS [ / B ] [ CR ] [ CR ] Manage your installed Add - ons · Browse for and install Add - ons from kodi . tv [ CR ] Modify Add - on settings " <nl> msgstr " " <nl> <nl> msgctxt " # 31409 " <nl>
Merge pull request from phil65 / label_fix
xbmc/xbmc
96f3d33ff42ab67f91ff87d1294b7d95ba77f61e
2014-10-21T18:23:49Z
mmm a / dbms / src / Processors / Executors / PipelineExecutor . cpp <nl> ppp b / dbms / src / Processors / Executors / PipelineExecutor . cpp <nl> void PipelineExecutor : : executeSingleThread ( size_t thread_num , size_t num_threads <nl> } <nl> } ; <nl> <nl> - <nl> - / / auto prepare_all_processors = [ & ] ( Queue & queue ) <nl> - / / { <nl> - / / while ( ! stack . empty ( ) & & ! finished ) <nl> - / / { <nl> - / / auto current_processor = stack . top ( ) ; <nl> - / / stack . pop ( ) ; <nl> - / / <nl> - / / if ( prepare_processor ( current_processor ) ) <nl> - / / queue . push ( graph [ current_processor ] . execution_state . get ( ) ) ; <nl> - / / } <nl> - / / } ; <nl> - <nl> auto wake_up_executor = [ & ] ( size_t executor ) <nl> { <nl> std : : lock_guard guard ( executor_contexts [ executor ] - > mutex ) ; <nl> void PipelineExecutor : : executeSingleThread ( size_t thread_num , size_t num_threads <nl> executor_contexts [ executor ] - > condvar . notify_one ( ) ; <nl> } ; <nl> <nl> - / / auto process_pinned_tasks = [ & ] ( Queue & queue ) <nl> - / / { <nl> - / / Queue tmp_queue ; <nl> - / / <nl> - / / struct PinnedTask <nl> - / / { <nl> - / / ExecutionState * task ; <nl> - / / size_t thread_num ; <nl> - / / } ; <nl> - / / <nl> - / / std : : stack < PinnedTask > pinned_tasks ; <nl> - / / <nl> - / / while ( ! queue . empty ( ) ) <nl> - / / { <nl> - / / auto task = queue . front ( ) ; <nl> - / / queue . pop ( ) ; <nl> - / / <nl> - / / auto stream = task - > processor - > getStream ( ) ; <nl> - / / if ( stream ! = IProcessor : : NO_STREAM ) <nl> - / / pinned_tasks . push ( { . task = task , . thread_num = stream % num_threads } ) ; <nl> - / / else <nl> - / / tmp_queue . push ( task ) ; <nl> - / / } <nl> - / / <nl> - / / if ( ! pinned_tasks . empty ( ) ) <nl> - / / { <nl> - / / std : : stack < size_t > threads_to_wake ; <nl> - / / <nl> - / / { <nl> - / / std : : lock_guard lock ( task_queue_mutex ) ; <nl> - / / <nl> - / / while ( ! pinned_tasks . empty ( ) ) <nl> - / / { <nl> - / / auto & pinned_task = pinned_tasks . top ( ) ; <nl> - / / auto thread = pinned_task . thread_num ; <nl> - / / <nl> - / / executor_contexts [ thread ] - > pinned_tasks . push ( pinned_task . task ) ; <nl> - / / pinned_tasks . pop ( ) ; <nl> - / / <nl> - / / if ( threads_queue . has ( thread ) ) <nl> - / / { <nl> - / / threads_queue . pop ( thread ) ; <nl> - / / threads_to_wake . push ( thread ) ; <nl> - / / } <nl> - / / } <nl> - / / } <nl> - / / <nl> - / / while ( ! threads_to_wake . empty ( ) ) <nl> - / / { <nl> - / / wake_up_executor ( threads_to_wake . top ( ) ) ; <nl> - / / threads_to_wake . pop ( ) ; <nl> - / / } <nl> - / / } <nl> - / / <nl> - / / queue . swap ( tmp_queue ) ; <nl> - / / } ; <nl> - <nl> while ( ! finished ) <nl> { <nl> / / / First , find any processor to execute . <nl> void PipelineExecutor : : executeSingleThread ( size_t thread_num , size_t num_threads <nl> { <nl> std : : unique_lock lock ( task_queue_mutex ) ; <nl> <nl> - / / if ( ! executor_contexts [ thread_num ] - > pinned_tasks . empty ( ) ) <nl> - / / { <nl> - / / state = executor_contexts [ thread_num ] - > pinned_tasks . front ( ) ; <nl> - / / executor_contexts [ thread_num ] - > pinned_tasks . pop ( ) ; <nl> - / / <nl> - / / break ; <nl> - / / } <nl> - <nl> if ( ! task_queue . empty ( ) ) <nl> { <nl> state = task_queue . pop ( thread_num ) ; <nl> void PipelineExecutor : : executeSingleThread ( size_t thread_num , size_t num_threads <nl> prepare_processor ( state - > processors_id , queue ) ; <nl> state = nullptr ; <nl> <nl> - / / / Process all neighbours . Children will be on the top of stack , then parents . <nl> - / / / prepare_all_processors ( queue , children , children , parents ) ; <nl> - / / process_pinned_tasks ( queue ) ; <nl> - <nl> / / / Take local task from queue if has one . <nl> if ( ! queue . empty ( ) ) <nl> { <nl> void PipelineExecutor : : executeSingleThread ( size_t thread_num , size_t num_threads <nl> queue . pop ( ) ; <nl> } <nl> <nl> - / / / prepare_all_processors ( queue , parents , parents , parents ) ; <nl> - / / process_pinned_tasks ( queue ) ; <nl> - <nl> - / / / Take pinned task if has one . <nl> - / / { <nl> - / / std : : lock_guard guard ( task_queue_mutex ) ; <nl> - / / if ( ! executor_contexts [ thread_num ] - > pinned_tasks . empty ( ) ) <nl> - / / { <nl> - / / if ( state ) <nl> - / / queue . push ( state ) ; <nl> - / / <nl> - / / state = executor_contexts [ thread_num ] - > pinned_tasks . front ( ) ; <nl> - / / executor_contexts [ thread_num ] - > pinned_tasks . pop ( ) ; <nl> - / / } <nl> - / / } <nl> - <nl> / / / Push other tasks to global queue . <nl> if ( ! queue . empty ( ) ) <nl> { <nl>
Remove commented code .
ClickHouse/ClickHouse
d3060f42e0c50b49ea3c948920f355efc2a5c15e
2019-12-29T07:30:26Z
mmm a / src / factory . cc <nl> ppp b / src / factory . cc <nl> Handle < String > Factory : : InternalizeUtf8String ( Vector < const char > string ) { <nl> <nl> / / Internalized strings are created in the old generation ( data space ) . <nl> Handle < String > Factory : : InternalizeString ( Handle < String > string ) { <nl> - CALL_HEAP_FUNCTION ( isolate ( ) , <nl> - isolate ( ) - > heap ( ) - > InternalizeString ( * string ) , <nl> - String ) ; <nl> + if ( string - > IsInternalizedString ( ) ) return string ; <nl> + return StringTable : : LookupString ( isolate ( ) , string ) ; <nl> } <nl> <nl> <nl> Handle < String > Factory : : InternalizeTwoByteString ( Vector < const uc16 > string ) { <nl> <nl> template < class StringTableKey > <nl> Handle < String > Factory : : InternalizeStringWithKey ( StringTableKey * key ) { <nl> - CALL_HEAP_FUNCTION ( isolate ( ) , <nl> - isolate ( ) - > heap ( ) - > InternalizeStringWithKey ( key ) , <nl> - String ) ; <nl> + return StringTable : : LookupKey ( isolate ( ) , key ) ; <nl> } <nl> <nl> <nl> MaybeHandle < SeqTwoByteString > Factory : : NewRawTwoByteString ( <nl> } <nl> <nl> <nl> - Handle < String > Factory : : LookupSingleCharacterStringFromCode ( uint32_t index ) { <nl> - CALL_HEAP_FUNCTION ( <nl> - isolate ( ) , <nl> - isolate ( ) - > heap ( ) - > LookupSingleCharacterStringFromCode ( index ) , <nl> - String ) ; <nl> + Handle < String > Factory : : LookupSingleCharacterStringFromCode ( uint32_t code ) { <nl> + if ( code < = String : : kMaxOneByteCharCodeU ) { <nl> + { <nl> + DisallowHeapAllocation no_allocation ; <nl> + Object * value = single_character_string_cache ( ) - > get ( code ) ; <nl> + if ( value ! = * undefined_value ( ) ) { <nl> + return handle ( String : : cast ( value ) , isolate ( ) ) ; <nl> + } <nl> + } <nl> + uint8_t buffer [ 1 ] ; <nl> + buffer [ 0 ] = static_cast < uint8_t > ( code ) ; <nl> + Handle < String > result = <nl> + InternalizeOneByteString ( Vector < const uint8_t > ( buffer , 1 ) ) ; <nl> + single_character_string_cache ( ) - > set ( code , * result ) ; <nl> + return result ; <nl> + } <nl> + ASSERT ( code < = String : : kMaxUtf16CodeUnitU ) ; <nl> + <nl> + Handle < SeqTwoByteString > result = NewRawTwoByteString ( 1 ) . ToHandleChecked ( ) ; <nl> + result - > SeqTwoByteStringSet ( 0 , static_cast < uint16_t > ( code ) ) ; <nl> + return result ; <nl> } <nl> <nl> <nl> mmm a / src / factory . h <nl> ppp b / src / factory . h <nl> class Factory V8_FINAL { <nl> / / Create an empty TypeFeedbackInfo . <nl> Handle < TypeFeedbackInfo > NewTypeFeedbackInfo ( ) ; <nl> <nl> + / / Finds the internalized copy for string in the string table . <nl> + / / If not found , a new string is added to the table and returned . <nl> Handle < String > InternalizeUtf8String ( Vector < const char > str ) ; <nl> Handle < String > InternalizeUtf8String ( const char * str ) { <nl> return InternalizeUtf8String ( CStrVector ( str ) ) ; <nl> class Factory V8_FINAL { <nl> int length , <nl> PretenureFlag pretenure = NOT_TENURED ) ; <nl> <nl> - Handle < String > LookupSingleCharacterStringFromCode ( uint32_t index ) ; <nl> + / / Creates a single character string where the character has given code . <nl> + / / A cache is used for ASCII codes . <nl> + Handle < String > LookupSingleCharacterStringFromCode ( uint32_t code ) ; <nl> <nl> / / Create a new cons string object which consists of a pair of strings . <nl> MUST_USE_RESULT MaybeHandle < String > NewConsString ( Handle < String > left , <nl> class Factory V8_FINAL { <nl> INTERNALIZED_STRING_LIST ( STRING_ACCESSOR ) <nl> # undef STRING_ACCESSOR <nl> <nl> + inline void set_string_table ( Handle < StringTable > table ) { <nl> + isolate ( ) - > heap ( ) - > set_string_table ( * table ) ; <nl> + } <nl> + <nl> Handle < String > hidden_string ( ) { <nl> return Handle < String > ( & isolate ( ) - > heap ( ) - > hidden_string_ ) ; <nl> } <nl> mmm a / src / heap . cc <nl> ppp b / src / heap . cc <nl> MaybeObject * Heap : : AllocateForeign ( Address address , PretenureFlag pretenure ) { <nl> } <nl> <nl> <nl> - MaybeObject * Heap : : LookupSingleCharacterStringFromCode ( uint16_t code ) { <nl> - if ( code < = String : : kMaxOneByteCharCode ) { <nl> - Object * value = single_character_string_cache ( ) - > get ( code ) ; <nl> - if ( value ! = undefined_value ( ) ) return value ; <nl> - <nl> - uint8_t buffer [ 1 ] ; <nl> - buffer [ 0 ] = static_cast < uint8_t > ( code ) ; <nl> - Object * result ; <nl> - OneByteStringKey key ( Vector < const uint8_t > ( buffer , 1 ) , HashSeed ( ) ) ; <nl> - MaybeObject * maybe_result = InternalizeStringWithKey ( & key ) ; <nl> - <nl> - if ( ! maybe_result - > ToObject ( & result ) ) return maybe_result ; <nl> - single_character_string_cache ( ) - > set ( code , result ) ; <nl> - return result ; <nl> - } <nl> - <nl> - SeqTwoByteString * result ; <nl> - { MaybeObject * maybe_result = AllocateRawTwoByteString ( 1 , NOT_TENURED ) ; <nl> - if ( ! maybe_result - > To < SeqTwoByteString > ( & result ) ) return maybe_result ; <nl> - } <nl> - result - > SeqTwoByteStringSet ( 0 , code ) ; <nl> - return result ; <nl> - } <nl> - <nl> - <nl> MaybeObject * Heap : : AllocateByteArray ( int length , PretenureFlag pretenure ) { <nl> if ( length < 0 | | length > ByteArray : : kMaxLength ) { <nl> v8 : : internal : : Heap : : FatalProcessOutOfMemory ( " invalid array length " , true ) ; <nl> void Heap : : Verify ( ) { <nl> # endif <nl> <nl> <nl> - MaybeObject * Heap : : InternalizeUtf8String ( Vector < const char > string ) { <nl> - Utf8StringKey key ( string , HashSeed ( ) ) ; <nl> - return InternalizeStringWithKey ( & key ) ; <nl> - } <nl> - <nl> - <nl> - MaybeObject * Heap : : InternalizeString ( String * string ) { <nl> - if ( string - > IsInternalizedString ( ) ) return string ; <nl> - Object * result = NULL ; <nl> - Object * new_table ; <nl> - { MaybeObject * maybe_new_table = <nl> - string_table ( ) - > LookupString ( string , & result ) ; <nl> - if ( ! maybe_new_table - > ToObject ( & new_table ) ) return maybe_new_table ; <nl> - } <nl> - / / Can ' t use set_string_table because StringTable : : cast knows that <nl> - / / StringTable is a singleton and checks for identity . <nl> - roots_ [ kStringTableRootIndex ] = new_table ; <nl> - ASSERT ( result ! = NULL ) ; <nl> - return result ; <nl> - } <nl> - <nl> - <nl> bool Heap : : InternalizeStringIfExists ( String * string , String * * result ) { <nl> if ( string - > IsInternalizedString ( ) ) { <nl> * result = string ; <nl> bool Heap : : InternalizeStringIfExists ( String * string , String * * result ) { <nl> } <nl> <nl> <nl> - MaybeObject * Heap : : InternalizeStringWithKey ( HashTableKey * key ) { <nl> - Object * result = NULL ; <nl> - Object * new_table ; <nl> - { MaybeObject * maybe_new_table = <nl> - string_table ( ) - > LookupKey ( key , & result ) ; <nl> - if ( ! maybe_new_table - > ToObject ( & new_table ) ) return maybe_new_table ; <nl> - } <nl> - / / Can ' t use set_string_table because StringTable : : cast knows that <nl> - / / StringTable is a singleton and checks for identity . <nl> - roots_ [ kStringTableRootIndex ] = new_table ; <nl> - ASSERT ( result ! = NULL ) ; <nl> - return result ; <nl> - } <nl> - <nl> - <nl> void Heap : : ZapFromSpace ( ) { <nl> NewSpacePageIterator it ( new_space_ . FromSpaceStart ( ) , <nl> new_space_ . FromSpaceEnd ( ) ) ; <nl> mmm a / src / heap . h <nl> ppp b / src / heap . h <nl> class Heap { <nl> MUST_USE_RESULT MaybeObject * AllocateInternalizedStringImpl ( <nl> T t , int chars , uint32_t hash_field ) ; <nl> <nl> - / / Computes a single character string where the character has code . <nl> - / / A cache is used for ASCII codes . <nl> - / / Returns Failure : : RetryAfterGC ( requested_bytes , space ) if the allocation <nl> - / / failed . Please note this does not perform a garbage collection . <nl> - MUST_USE_RESULT MaybeObject * LookupSingleCharacterStringFromCode ( <nl> - uint16_t code ) ; <nl> - <nl> / / Allocate a byte array of the specified length <nl> / / Returns Failure : : RetryAfterGC ( requested_bytes , space ) if the allocation <nl> / / failed . <nl> class Heap { <nl> / / Returns Failure : : RetryAfterGC ( requested_bytes , space ) if allocation <nl> / / failed . <nl> / / Please note this function does not perform a garbage collection . <nl> - MUST_USE_RESULT MaybeObject * InternalizeUtf8String ( const char * str ) { <nl> - return InternalizeUtf8String ( CStrVector ( str ) ) ; <nl> - } <nl> - MUST_USE_RESULT MaybeObject * InternalizeUtf8String ( Vector < const char > str ) ; <nl> - <nl> - MUST_USE_RESULT MaybeObject * InternalizeString ( String * str ) ; <nl> MUST_USE_RESULT MaybeObject * InternalizeStringWithKey ( HashTableKey * key ) ; <nl> <nl> bool InternalizeStringIfExists ( String * str , String * * result ) ; <nl> mmm a / src / mark - compact . cc <nl> ppp b / src / mark - compact . cc <nl> void MarkCompactCollector : : MarkStringTable ( RootMarkingVisitor * visitor ) { <nl> StringTable * string_table = heap ( ) - > string_table ( ) ; <nl> / / Mark the string table itself . <nl> MarkBit string_table_mark = Marking : : MarkBitFrom ( string_table ) ; <nl> - SetMark ( string_table , string_table_mark ) ; <nl> + if ( ! string_table_mark . Get ( ) ) { <nl> + / / String table could have already been marked by visiting the handles list . <nl> + SetMark ( string_table , string_table_mark ) ; <nl> + } <nl> / / Explicitly mark the prefix . <nl> string_table - > IteratePrefix ( visitor ) ; <nl> ProcessMarkingDeque ( ) ; <nl> mmm a / src / objects - inl . h <nl> ppp b / src / objects - inl . h <nl> uc32 FlatStringReader : : Get ( int index ) { <nl> } <nl> <nl> <nl> + Handle < Object > HashTableKey : : AsHandle ( Isolate * isolate ) { <nl> + CALL_HEAP_FUNCTION ( isolate , AsObject ( isolate - > heap ( ) ) , Object ) ; <nl> + } <nl> + <nl> + <nl> template < typename Char > <nl> class SequentialStringKey : public HashTableKey { <nl> public : <nl> explicit SequentialStringKey ( Vector < const Char > string , uint32_t seed ) <nl> : string_ ( string ) , hash_field_ ( 0 ) , seed_ ( seed ) { } <nl> <nl> - virtual uint32_t Hash ( ) { <nl> + virtual uint32_t Hash ( ) V8_OVERRIDE { <nl> hash_field_ = StringHasher : : HashSequentialString < Char > ( string_ . start ( ) , <nl> string_ . length ( ) , <nl> seed_ ) ; <nl> class SequentialStringKey : public HashTableKey { <nl> } <nl> <nl> <nl> - virtual uint32_t HashForObject ( Object * other ) { <nl> + virtual uint32_t HashForObject ( Object * other ) V8_OVERRIDE { <nl> return String : : cast ( other ) - > Hash ( ) ; <nl> } <nl> <nl> class OneByteStringKey : public SequentialStringKey < uint8_t > { <nl> OneByteStringKey ( Vector < const uint8_t > str , uint32_t seed ) <nl> : SequentialStringKey < uint8_t > ( str , seed ) { } <nl> <nl> - virtual bool IsMatch ( Object * string ) { <nl> + virtual bool IsMatch ( Object * string ) V8_OVERRIDE { <nl> return String : : cast ( string ) - > IsOneByteEqualTo ( string_ ) ; <nl> } <nl> <nl> - virtual MaybeObject * AsObject ( Heap * heap ) ; <nl> + virtual MaybeObject * AsObject ( Heap * heap ) V8_OVERRIDE ; <nl> } ; <nl> <nl> <nl> class SubStringKey : public HashTableKey { <nl> ASSERT ( string_ - > IsSeqString ( ) | | string - > IsExternalString ( ) ) ; <nl> } <nl> <nl> - virtual uint32_t Hash ( ) { <nl> + virtual uint32_t Hash ( ) V8_OVERRIDE { <nl> ASSERT ( length_ > = 0 ) ; <nl> ASSERT ( from_ + length_ < = string_ - > length ( ) ) ; <nl> const Char * chars = GetChars ( ) + from_ ; <nl> class SubStringKey : public HashTableKey { <nl> return result ; <nl> } <nl> <nl> - virtual uint32_t HashForObject ( Object * other ) { <nl> + virtual uint32_t HashForObject ( Object * other ) V8_OVERRIDE { <nl> return String : : cast ( other ) - > Hash ( ) ; <nl> } <nl> <nl> - virtual bool IsMatch ( Object * string ) ; <nl> - virtual MaybeObject * AsObject ( Heap * heap ) ; <nl> + virtual bool IsMatch ( Object * string ) V8_OVERRIDE ; <nl> + virtual MaybeObject * AsObject ( Heap * heap ) V8_OVERRIDE ; <nl> <nl> private : <nl> const Char * GetChars ( ) ; <nl> class TwoByteStringKey : public SequentialStringKey < uc16 > { <nl> explicit TwoByteStringKey ( Vector < const uc16 > str , uint32_t seed ) <nl> : SequentialStringKey < uc16 > ( str , seed ) { } <nl> <nl> - virtual bool IsMatch ( Object * string ) { <nl> + virtual bool IsMatch ( Object * string ) V8_OVERRIDE { <nl> return String : : cast ( string ) - > IsTwoByteEqualTo ( string_ ) ; <nl> } <nl> <nl> - virtual MaybeObject * AsObject ( Heap * heap ) ; <nl> + virtual MaybeObject * AsObject ( Heap * heap ) V8_OVERRIDE ; <nl> } ; <nl> <nl> <nl> class Utf8StringKey : public HashTableKey { <nl> explicit Utf8StringKey ( Vector < const char > string , uint32_t seed ) <nl> : string_ ( string ) , hash_field_ ( 0 ) , seed_ ( seed ) { } <nl> <nl> - virtual bool IsMatch ( Object * string ) { <nl> + virtual bool IsMatch ( Object * string ) V8_OVERRIDE { <nl> return String : : cast ( string ) - > IsUtf8EqualTo ( string_ ) ; <nl> } <nl> <nl> - virtual uint32_t Hash ( ) { <nl> + virtual uint32_t Hash ( ) V8_OVERRIDE { <nl> if ( hash_field_ ! = 0 ) return hash_field_ > > String : : kHashShift ; <nl> hash_field_ = StringHasher : : ComputeUtf8Hash ( string_ , seed_ , & chars_ ) ; <nl> uint32_t result = hash_field_ > > String : : kHashShift ; <nl> class Utf8StringKey : public HashTableKey { <nl> return result ; <nl> } <nl> <nl> - virtual uint32_t HashForObject ( Object * other ) { <nl> + virtual uint32_t HashForObject ( Object * other ) V8_OVERRIDE { <nl> return String : : cast ( other ) - > Hash ( ) ; <nl> } <nl> <nl> - virtual MaybeObject * AsObject ( Heap * heap ) { <nl> + virtual MaybeObject * AsObject ( Heap * heap ) V8_OVERRIDE { <nl> if ( hash_field_ = = 0 ) Hash ( ) ; <nl> return heap - > AllocateInternalizedStringFromUtf8 ( string_ , <nl> chars_ , <nl> mmm a / src / objects . cc <nl> ppp b / src / objects . cc <nl> template class SubStringKey < uint16_t > ; <nl> / / InternalizedStringKey carries a string / internalized - string object as key . <nl> class InternalizedStringKey : public HashTableKey { <nl> public : <nl> - explicit InternalizedStringKey ( String * string ) <nl> + explicit InternalizedStringKey ( Handle < String > string ) <nl> : string_ ( string ) { } <nl> <nl> - bool IsMatch ( Object * string ) { <nl> - return String : : cast ( string ) - > Equals ( string_ ) ; <nl> + virtual bool IsMatch ( Object * string ) V8_OVERRIDE { <nl> + return String : : cast ( string ) - > Equals ( * string_ ) ; <nl> } <nl> <nl> - uint32_t Hash ( ) { return string_ - > Hash ( ) ; } <nl> + virtual uint32_t Hash ( ) V8_OVERRIDE { return string_ - > Hash ( ) ; } <nl> <nl> - uint32_t HashForObject ( Object * other ) { <nl> + virtual uint32_t HashForObject ( Object * other ) V8_OVERRIDE { <nl> return String : : cast ( other ) - > Hash ( ) ; <nl> } <nl> <nl> - MaybeObject * AsObject ( Heap * heap ) { <nl> + virtual MaybeObject * AsObject ( Heap * heap ) V8_OVERRIDE { <nl> / / Internalize the string if possible . <nl> - Map * map = heap - > InternalizedStringMapForString ( string_ ) ; <nl> + Map * map = heap - > InternalizedStringMapForString ( * string_ ) ; <nl> if ( map ! = NULL ) { <nl> string_ - > set_map_no_write_barrier ( map ) ; <nl> ASSERT ( string_ - > IsInternalizedString ( ) ) ; <nl> - return string_ ; <nl> + return * string_ ; <nl> } <nl> / / Otherwise allocate a new internalized string . <nl> return heap - > AllocateInternalizedStringImpl ( <nl> - string_ , string_ - > length ( ) , string_ - > hash_field ( ) ) ; <nl> + * string_ , string_ - > length ( ) , string_ - > hash_field ( ) ) ; <nl> } <nl> <nl> static uint32_t StringHash ( Object * obj ) { <nl> return String : : cast ( obj ) - > Hash ( ) ; <nl> } <nl> <nl> - String * string_ ; <nl> + Handle < String > string_ ; <nl> } ; <nl> <nl> <nl> Handle < PropertyCell > JSGlobalObject : : EnsurePropertyCell ( <nl> } <nl> <nl> <nl> - MaybeObject * StringTable : : LookupString ( String * string , Object * * s ) { <nl> - InternalizedStringKey key ( string ) ; <nl> - return LookupKey ( & key , s ) ; <nl> - } <nl> - <nl> - <nl> / / This class is used for looking up two character strings in the string table . <nl> / / If we don ' t have a hit we don ' t want to waste much time so we unroll the <nl> / / string hash calculation loop here for speed . Doesn ' t work if the two <nl> class TwoCharHashTableKey : public HashTableKey { <nl> <nl> bool StringTable : : LookupStringIfExists ( String * string , String * * result ) { <nl> SLOW_ASSERT ( this = = HeapObject : : cast ( this ) - > GetHeap ( ) - > string_table ( ) ) ; <nl> - InternalizedStringKey key ( string ) ; <nl> + DisallowHeapAllocation no_alloc ; <nl> + / / TODO ( ishell ) : Handlify all the callers and remove this scope . <nl> + HandleScope scope ( GetIsolate ( ) ) ; <nl> + InternalizedStringKey key ( handle ( string ) ) ; <nl> int entry = FindEntry ( & key ) ; <nl> if ( entry = = kNotFound ) { <nl> return false ; <nl> bool StringTable : : LookupTwoCharsStringIfExists ( uint16_t c1 , <nl> } <nl> <nl> <nl> - MaybeObject * StringTable : : LookupKey ( HashTableKey * key , Object * * s ) { <nl> - SLOW_ASSERT ( this = = HeapObject : : cast ( this ) - > GetHeap ( ) - > string_table ( ) ) ; <nl> - int entry = FindEntry ( key ) ; <nl> + Handle < String > StringTable : : LookupString ( Isolate * isolate , <nl> + Handle < String > string ) { <nl> + InternalizedStringKey key ( string ) ; <nl> + return LookupKey ( isolate , & key ) ; <nl> + } <nl> + <nl> + <nl> + / / TODO ( ishell ) : Maybehandlify callers . <nl> + Handle < String > StringTable : : LookupKey ( Isolate * isolate , HashTableKey * key ) { <nl> + Handle < StringTable > table = isolate - > factory ( ) - > string_table ( ) ; <nl> + int entry = table - > FindEntry ( key ) ; <nl> <nl> / / String already in table . <nl> if ( entry ! = kNotFound ) { <nl> - * s = KeyAt ( entry ) ; <nl> - return this ; <nl> + return handle ( String : : cast ( table - > KeyAt ( entry ) ) , isolate ) ; <nl> } <nl> <nl> / / Adding new string . Grow table if needed . <nl> - Object * obj ; <nl> - { MaybeObject * maybe_obj = EnsureCapacity ( 1 , key ) ; <nl> - if ( ! maybe_obj - > ToObject ( & obj ) ) return maybe_obj ; <nl> - } <nl> + table = StringTable : : EnsureCapacity ( table , 1 , key ) ; <nl> <nl> / / Create string object . <nl> - Object * string ; <nl> - { MaybeObject * maybe_string = key - > AsObject ( GetHeap ( ) ) ; <nl> - if ( ! maybe_string - > ToObject ( & string ) ) return maybe_string ; <nl> - } <nl> - <nl> - / / If the string table grew as part of EnsureCapacity , obj is not <nl> - / / the current string table and therefore we cannot use <nl> - / / StringTable : : cast here . <nl> - StringTable * table = reinterpret_cast < StringTable * > ( obj ) ; <nl> + Handle < Object > string = key - > AsHandle ( isolate ) ; <nl> + / / TODO ( ishell ) : Maybehandlify this . <nl> + if ( string . is_null ( ) ) return Handle < String > ( ) ; <nl> <nl> / / Add the new string and return it along with the string table . <nl> entry = table - > FindInsertionEntry ( key - > Hash ( ) ) ; <nl> - table - > set ( EntryToIndex ( entry ) , string ) ; <nl> + table - > set ( EntryToIndex ( entry ) , * string ) ; <nl> table - > ElementAdded ( ) ; <nl> - * s = string ; <nl> - return table ; <nl> + <nl> + isolate - > factory ( ) - > set_string_table ( table ) ; <nl> + return Handle < String > : : cast ( string ) ; <nl> } <nl> <nl> <nl> mmm a / src / objects . h <nl> ppp b / src / objects . h <nl> class HashTableKey { <nl> / / Returns the key object for storing into the hash table . <nl> / / If allocations fails a failure object is returned . <nl> MUST_USE_RESULT virtual MaybeObject * AsObject ( Heap * heap ) = 0 ; <nl> + / / TODO ( ishell ) : This should eventually replace AsObject ( ) . <nl> + inline Handle < Object > AsHandle ( Isolate * isolate ) ; <nl> / / Required . <nl> virtual ~ HashTableKey ( ) { } <nl> } ; <nl> class StringTable : public HashTable < StringTable , <nl> StringTableShape , <nl> HashTableKey * > { <nl> public : <nl> - / / Find string in the string table . If it is not there yet , it is <nl> - / / added . The return value is the string table which might have <nl> - / / been enlarged . If the return value is not a failure , the string <nl> - / / pointer * s is set to the string found . <nl> - MUST_USE_RESULT MaybeObject * LookupString ( String * key , Object * * s ) ; <nl> - MUST_USE_RESULT MaybeObject * LookupKey ( HashTableKey * key , Object * * s ) ; <nl> + / / Find string in the string table . If it is not there yet , it is <nl> + / / added . The return value is the string found . <nl> + static Handle < String > LookupString ( Isolate * isolate , Handle < String > key ) ; <nl> + static Handle < String > LookupKey ( Isolate * isolate , HashTableKey * key ) ; <nl> <nl> / / Looks up a string that is equal to the given string and returns <nl> / / true if it is found , assigning the string to the given output <nl> class String : public Name { <nl> static const int32_t kMaxOneByteCharCode = unibrow : : Latin1 : : kMaxChar ; <nl> static const uint32_t kMaxOneByteCharCodeU = unibrow : : Latin1 : : kMaxChar ; <nl> static const int kMaxUtf16CodeUnit = 0xffff ; <nl> + static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit ; <nl> <nl> / / Value of hash field containing computed hash equal to zero . <nl> static const int kEmptyStringHash = kIsNotArrayIndexMask ; <nl> mmm a / src / parser . cc <nl> ppp b / src / parser . cc <nl> bool RegExpParser : : simple ( ) { <nl> <nl> RegExpTree * RegExpParser : : ReportError ( Vector < const char > message ) { <nl> failed_ = true ; <nl> - * error_ = isolate ( ) - > factory ( ) - > NewStringFromAscii ( <nl> - message , NOT_TENURED ) . ToHandleChecked ( ) ; <nl> + * error_ = isolate ( ) - > factory ( ) - > NewStringFromAscii ( message ) . ToHandleChecked ( ) ; <nl> / / Zip to the end to make sure the no more input is read . <nl> current_ = kEndMarker ; <nl> next_pos_ = in ( ) - > length ( ) ; <nl> mmm a / test / cctest / test - api . cc <nl> ppp b / test / cctest / test - api . cc <nl> TEST ( VisitExternalStrings ) { <nl> CcTest : : heap ( ) - > CollectAllAvailableGarbage ( ) ; / / Tenure string . <nl> / / Turn into a symbol . <nl> i : : Handle < i : : String > string3_i = v8 : : Utils : : OpenHandle ( * string3 ) ; <nl> - CHECK ( ! CcTest : : heap ( ) - > InternalizeString ( * string3_i ) - > IsFailure ( ) ) ; <nl> + CHECK ( ! CcTest : : i_isolate ( ) - > factory ( ) - > InternalizeString ( <nl> + string3_i ) . is_null ( ) ) ; <nl> CHECK ( string3_i - > IsInternalizedString ( ) ) ; <nl> <nl> / / We need to add usages for string * to avoid warnings in GCC 4 . 7 <nl> mmm a / test / cctest / test - heap . cc <nl> ppp b / test / cctest / test - heap . cc <nl> static const char * not_so_random_string_table [ ] = { <nl> <nl> <nl> static void CheckInternalizedStrings ( const char * * strings ) { <nl> + Factory * factory = CcTest : : i_isolate ( ) - > factory ( ) ; <nl> for ( const char * string = * strings ; * strings ! = 0 ; string = * strings + + ) { <nl> - Object * a ; <nl> - MaybeObject * maybe_a = CcTest : : heap ( ) - > InternalizeUtf8String ( string ) ; <nl> - / / InternalizeUtf8String may return a failure if a GC is needed . <nl> - if ( ! maybe_a - > ToObject ( & a ) ) continue ; <nl> + Handle < String > a = factory - > InternalizeUtf8String ( string ) ; <nl> CHECK ( a - > IsInternalizedString ( ) ) ; <nl> - Object * b ; <nl> - MaybeObject * maybe_b = CcTest : : heap ( ) - > InternalizeUtf8String ( string ) ; <nl> - if ( ! maybe_b - > ToObject ( & b ) ) continue ; <nl> - CHECK_EQ ( b , a ) ; <nl> - CHECK ( String : : cast ( b ) - > IsUtf8EqualTo ( CStrVector ( string ) ) ) ; <nl> + Handle < String > b = factory - > InternalizeUtf8String ( string ) ; <nl> + CHECK_EQ ( * b , * a ) ; <nl> + CHECK ( String : : cast ( * b ) - > IsUtf8EqualTo ( CStrVector ( string ) ) ) ; <nl> } <nl> } <nl> <nl> static void CheckInternalizedStrings ( const char * * strings ) { <nl> TEST ( StringTable ) { <nl> CcTest : : InitializeVM ( ) ; <nl> <nl> + v8 : : HandleScope sc ( CcTest : : isolate ( ) ) ; <nl> CheckInternalizedStrings ( not_so_random_string_table ) ; <nl> CheckInternalizedStrings ( not_so_random_string_table ) ; <nl> } <nl>
StringTable : : LookupKey ( ) and all callers handlified .
v8/v8
4591771820036951b6433d9b68d00507a44d4af1
2014-04-23T15:43:39Z
mmm a / xbmc / interfaces / python / XBPyThread . cpp <nl> ppp b / xbmc / interfaces / python / XBPyThread . cpp <nl> void XBPyThread : : Process ( ) <nl> { <nl> / / run script from file <nl> / / We need to have python open the file because on Windows the DLL that python <nl> - / / is linked against may not be the DLL that xbmc is linked against so <nl> + / / is linked against may not be the DLL that xbmc is linked against so <nl> / / passing a FILE * to python from an fopen has the potential to crash . <nl> PyObject * file = PyFile_FromString ( ( char * ) _P ( m_source ) . c_str ( ) , ( char * ) " r " ) ; <nl> FILE * fp = PyFile_AsFile ( file ) ; <nl> void XBPyThread : : Process ( ) <nl> PyObject * f = PyString_FromString ( _P ( m_source ) . c_str ( ) ) ; <nl> PyDict_SetItemString ( moduleDict , " __file__ " , f ) ; <nl> Py_DECREF ( f ) ; <nl> - PyRun_File ( fp , _P ( m_source ) . c_str ( ) , m_Py_file_input , moduleDict , moduleDict ) ; <nl> - <nl> - / / Get a reference to the main module <nl> - / / and global dictionary <nl> - PyObject * main_module = PyImport_AddModule ( ( char * ) " __main__ " ) ; <nl> - PyObject * global_dict = PyModule_GetDict ( main_module ) ; <nl> - <nl> - / / Extract a reference to the function " func_name " <nl> - / / from the global dictionary <nl> - PyObject * expression = PyDict_GetItemString ( global_dict , " xbmcclosefilehack " ) ; <nl> - <nl> - if ( ! PyObject_CallFunction ( expression , ( char * ) " ( O ) " , file ) ) <nl> - CLog : : Log ( LOGERROR , " Failed to close the script file % s " , _P ( m_source ) . c_str ( ) ) ; <nl> + PyRun_FileExFlags ( fp , _P ( m_source ) . c_str ( ) , m_Py_file_input , moduleDict , moduleDict , 1 , NULL ) ; <nl> } <nl> else <nl> CLog : : Log ( LOGERROR , " % s not found ! " , m_source ) ; <nl> mmm a / xbmc / interfaces / python / XBPython . cpp <nl> ppp b / xbmc / interfaces / python / XBPython . cpp <nl> void XBPython : : InitializeInterpreter ( ) <nl> " import sys \ n " <nl> " sys . stdout = xbmcout ( ) \ n " <nl> " sys . stderr = xbmcout ( ) \ n " <nl> - " def xbmcclosefilehack ( f ) : \ n " <nl> - / / " \ txbmc . output ( \ " Closing Script File . \ " ) \ n " <nl> - " \ tf . close ( ) \ n " <nl> - " \ n " <nl> " print ' - - > Python Interpreter Initialized < - - ' \ n " <nl> " " ) = = - 1 ) <nl> { <nl>
The hack for closing a file from python was causing problems . This change uses the python api to close the file correctly .
xbmc/xbmc
91a101128e87e7acc7c512cfd70e365a16cac8d0
2011-04-10T13:19:51Z
mmm a / sorting / merge_sort . cpp <nl> ppp b / sorting / merge_sort . cpp <nl> <nl> / * * <nl> * \ addtogroup sorting Sorting Algorithms <nl> - * @ { <nl> + * @ file { <nl> * \ file <nl> - * \ brief [ Merege Sort Algorithm <nl> + * \ breif [ Merege Sort Algorithm <nl> * ( MEREGE SORT ) ] ( https : / / en . wikipedia . org / wiki / Merge_sort ) implementation <nl> * <nl> - * \ author [ Ayaan Khan ] ( http : / / github . com / ayaankhan98 ) <nl> + * \ author [ Ayaan Khan ] ( http : / / github . com / ayaankhan98 ) <nl> * <nl> - * \ details <nl> * Merge Sort is an efficient , general purpose , comparison <nl> * based sorting algorithm . <nl> * Merge Sort is a divide and conquer algorithm <nl> - * <nl> + * <nl> * / <nl> + <nl> # include < iostream > <nl> <nl> / * * <nl> * <nl> - * The merge ( ) function is used for merging two halves . <nl> - * The merge ( arr , l , m , r ) is key process that assumes that <nl> - * arr [ l . . m ] and arr [ m + 1 . . r ] are sorted and merges the two <nl> + * The merge ( ) function is used for merging two halves . <nl> + * The merge ( arr , l , m , r ) is key process that assumes that <nl> + * arr [ l . . m ] and arr [ m + 1 . . r ] are sorted and merges the two <nl> * sorted sub - arrays into one . <nl> * <nl> - * @ param arr - array with two halves arr [ l . . . m ] and arr [ m + 1 . . . l ] <nl> - * @ param l - left index or start index of first half array <nl> - * @ param m - right index or end index of first half array <nl> - * <nl> + * @ param arr [ ] is the array with two halves one is arr [ l . . . m ] and <nl> + * other is arr [ m + 1 . . . l ] <nl> + * @ param l is the left index of first half array <nl> + * @ param m is the end index of right index of first half array <nl> + * <nl> * ( The second array starts form m + 1 and goes till l ) <nl> - * <nl> - * @ param l - end index or right index of second half array <nl> + * <nl> + * @ param l is the end index of right index of second half array <nl> * / <nl> - void merge ( int * arr , int l , int m , int r ) { <nl> + void merge ( int arr [ ] , int l , int m , int r ) { <nl> int i , j , k ; <nl> int n1 = m - l + 1 ; <nl> int n2 = r - m ; <nl> void merge ( int * arr , int l , int m , int r ) { <nl> * input array into two halves and calls itself for the two halves <nl> * and then calls merge ( ) to merge the two halves <nl> * <nl> - * @ param arr - array to be sorted <nl> - * @ param l - left index or start index of array <nl> - * @ param r - right index or end index of array <nl> + * @ param arr [ ] the array which is to be sorted <nl> + * @ param l define the left index of array <nl> + * @ param r defines the right index of array <nl> * <nl> * / <nl> - void mergeSort ( int * arr , int l , int r ) { <nl> + void mergeSort ( int arr [ ] , int l , int r ) { <nl> if ( l < r ) { <nl> int m = l + ( r - l ) / 2 ; <nl> mergeSort ( arr , l , m ) ; <nl> void mergeSort ( int * arr , int l , int r ) { <nl> } <nl> <nl> / * * <nl> - * Utility function used to print the array after <nl> + * A simple utility function used to print the array after <nl> * sorting <nl> * / <nl> - void show ( int * arr , int size ) { <nl> - for ( int i = 0 ; i < size ; i + + ) std : : cout < < arr [ i ] < < " " ; <nl> + void show ( int arr [ ] , int size ) { <nl> + for ( int i = 0 ; i < size ; i + + ) std : : cout < < arr [ i ] < < " " ; <nl> std : : cout < < " \ n " ; <nl> } <nl> <nl> int main ( ) { <nl> for ( int i = 0 ; i < size ; + + i ) { <nl> std : : cin > > arr [ i ] ; <nl> } <nl> - mergeSort ( arr , 0 , size - 1 ) ; <nl> + mergeSort ( arr , 0 , size - 1 ) ; <nl> std : : cout < < " Sorted array : " ; <nl> - show ( arr , size - 1 ) ; <nl> + show ( arr , size - 1 ) ; <nl> delete [ ] arr ; <nl> return 0 ; <nl> } <nl>
Fixed Bug [ munmap_chunck ( ) core dumped ]
TheAlgorithms/C-Plus-Plus
46e07288ba5b259ae2fa7b32c289b0305ef2def0
2020-06-23T19:04:33Z
mmm a / tests / test_core . py <nl> ppp b / tests / test_core . py <nl> def test_cube2md5 ( self ) : <nl> <nl> def test_cube2hash ( self ) : <nl> # extra testing for various codegen modes <nl> - for x86 in [ 0 , 1 ] if self . run_name = = ' asm2 ' else [ 0 ] : <nl> - print ' x86 ' , x86 <nl> - try : <nl> - old_x86 = os . environ . get ( ' EMCC_LLVM_TARGET ' ) or ' ' <nl> - if x86 : <nl> - os . environ [ ' EMCC_LLVM_TARGET ' ] = " i386 - pc - linux - gnu " <nl> - try : <nl> - old_fastcomp = os . environ . get ( ' EMCC_FAST_COMPILER ' ) or ' ' <nl> - if x86 : <nl> - os . environ [ ' EMCC_FAST_COMPILER ' ] = " 0 " <nl> - try : <nl> - old_chunk_size = os . environ . get ( ' EMSCRIPT_MAX_CHUNK_SIZE ' ) or ' ' <nl> - <nl> - for chunk_size in [ ' 1 ' , old_chunk_size ] : # test splitting out each function to a chunk in emscripten . py ( 21 functions here ) <nl> - print ' chunks ' , chunk_size <nl> - os . environ [ ' EMSCRIPT_MAX_CHUNK_SIZE ' ] = chunk_size <nl> - <nl> - # A good test of i64 math <nl> - if Settings . USE_TYPED_ARRAYS ! = 2 : return self . skip ( ' requires ta2 C - style memory aliasing ' ) <nl> - self . do_run ( ' ' , ' Usage : hashstring < seed > ' , <nl> - libraries = self . get_library ( ' cube2hash ' , [ ' cube2hash . bc ' ] , configure = None , cache_name_extra = str ( x86 ) ) , <nl> - includes = [ path_from_root ( ' tests ' , ' cube2hash ' ) ] ) <nl> - <nl> - for text , output in [ ( ' fleefl ' , ' 892BDB6FD3F62E863D63DA55851700FDE3ACF30204798CE9 ' ) , <nl> - ( ' fleefl2 ' , ' AA2CC5F96FC9D540CA24FDAF1F71E2942753DB83E8A81B61 ' ) , <nl> - ( ' 64bitisslow ' , ' 64D8470573635EC354FEE7B7F87C566FCAF1EFB491041670 ' ) ] : <nl> - self . do_run ( ' ' , ' hash value : ' + output , [ text ] , no_build = True ) <nl> - finally : <nl> - os . environ [ ' EMSCRIPT_MAX_CHUNK_SIZE ' ] = old_chunk_size <nl> - finally : <nl> - if x86 : <nl> - if old_fastcomp : <nl> - os . environ [ ' EMCC_FAST_COMPILER ' ] = old_fastcomp <nl> - else : <nl> - del os . environ [ ' EMCC_FAST_COMPILER ' ] <nl> - finally : <nl> - if x86 : <nl> - if old_x86 : <nl> - os . environ [ ' EMCC_LLVM_TARGET ' ] = old_x86 <nl> - else : <nl> - del os . environ [ ' EMCC_LLVM_TARGET ' ] <nl> + try : <nl> + old_chunk_size = os . environ . get ( ' EMSCRIPT_MAX_CHUNK_SIZE ' ) or ' ' <nl> + <nl> + for chunk_size in [ ' 1 ' , old_chunk_size ] : # test splitting out each function to a chunk in emscripten . py ( 21 functions here ) <nl> + print ' chunks ' , chunk_size <nl> + os . environ [ ' EMSCRIPT_MAX_CHUNK_SIZE ' ] = chunk_size <nl> + <nl> + # A good test of i64 math <nl> + if Settings . USE_TYPED_ARRAYS ! = 2 : return self . skip ( ' requires ta2 C - style memory aliasing ' ) <nl> + self . do_run ( ' ' , ' Usage : hashstring < seed > ' , <nl> + libraries = self . get_library ( ' cube2hash ' , [ ' cube2hash . bc ' ] , configure = None ) , <nl> + includes = [ path_from_root ( ' tests ' , ' cube2hash ' ) ] ) <nl> + <nl> + for text , output in [ ( ' fleefl ' , ' 892BDB6FD3F62E863D63DA55851700FDE3ACF30204798CE9 ' ) , <nl> + ( ' fleefl2 ' , ' AA2CC5F96FC9D540CA24FDAF1F71E2942753DB83E8A81B61 ' ) , <nl> + ( ' 64bitisslow ' , ' 64D8470573635EC354FEE7B7F87C566FCAF1EFB491041670 ' ) ] : <nl> + self . do_run ( ' ' , ' hash value : ' + output , [ text ] , no_build = True ) <nl> + finally : <nl> + os . environ [ ' EMSCRIPT_MAX_CHUNK_SIZE ' ] = old_chunk_size <nl> <nl> def test_unaligned ( self ) : <nl> if Settings . QUANTUM_SIZE = = 1 : return self . skip ( ' No meaning to unaligned addresses in q1 ' ) <nl>
Disable testing the x86 triple i386 - pc - linux - gnu in asm2 . test_cube2hash , that triple is now deprecated .
emscripten-core/emscripten
b3af30a8b178cca331a0ec6b6d9d0b1012e3a70b
2014-05-22T23:20:06Z
mmm a / utils / build - presets . ini <nl> ppp b / utils / build - presets . ini <nl> assertions <nl> # Downstream projects that import llbuild + SwiftPM . <nl> sourcekit - lsp <nl> <nl> + # = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm = = = # <nl> + # Test Swift Syntax <nl> + # = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm = = = # <nl> + <nl> + [ preset : buildbot_swiftsyntax_macos ] <nl> + mixin - preset = mixin_swiftpm_package_macos_platform <nl> + release <nl> + assertions <nl> + swiftsyntax <nl> + swiftsyntax - verify - generated - files <nl> + <nl> # = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm = = = # <nl> # Test Swift Stress Tester <nl> # = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm = = = # <nl>
[ build - script ] Add preset for SwiftSyntax PR testing
apple/swift
f33c95d9d7ea88098f4840e88c5cf80353f66821
2019-10-22T21:31:55Z
mmm a / src / Processors / Formats / Impl / PrettyBlockOutputFormat . cpp <nl> ppp b / src / Processors / Formats / Impl / PrettyBlockOutputFormat . cpp <nl> void PrettyBlockOutputFormat : : calculateWidths ( <nl> / / / Note that it is just an estimation . 4 is the maximum size of Unicode code point in bytes in UTF - 8 . <nl> / / / But it ' s possible that the string is long in bytes but very short in visible size . <nl> / / / ( e . g . non - printable characters , diacritics , combining characters ) <nl> - if ( serialized_value . size ( ) > format_settings . pretty . max_value_width * 4 ) <nl> - serialized_value . resize ( format_settings . pretty . max_value_width * 4 ) ; <nl> + if ( format_settings . pretty . max_value_width ) <nl> + { <nl> + size_t max_byte_size = format_settings . pretty . max_value_width * 4 ; <nl> + if ( serialized_value . size ( ) > max_byte_size ) <nl> + serialized_value . resize ( max_byte_size ) ; <nl> + } <nl> <nl> widths [ i ] [ j ] = UTF8 : : computeWidth ( reinterpret_cast < const UInt8 * > ( serialized_value . data ( ) ) , serialized_value . size ( ) , prefix ) ; <nl> max_padded_widths [ i ] = std : : max ( max_padded_widths [ i ] , <nl> mmm a / tests / queries / 0_stateless / 00098_k_union_all . reference <nl> ppp b / tests / queries / 0_stateless / 00098_k_union_all . reference <nl> <nl> -  [ 1m1  [ 0m <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> -  [ 1m1  [ 0m <nl> + 1 <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> -  [ 1m1  [ 0m <nl> + 1 <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> -  [ 1m1  [ 0m <nl> + 1 <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> -  [ 1m1  [ 0m <nl> + 1 <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> -  [ 1m1  [ 0m <nl> + 1 <nl> +  [ 1m1  [ 0m <nl> <nl> - 1 <nl> + 1 <nl> mmm a / tests / queries / 0_stateless / 00305_http_and_readonly . reference <nl> ppp b / tests / queries / 0_stateless / 00305_http_and_readonly . reference <nl> <nl> - name value changed <nl> + name value changed <nl> <nl> - max_rows_to_read 10000 1 <nl> - readonly 0 0 <nl> - name value changed <nl> + max_rows_to_read 10000 1 <nl> + readonly 0 0 <nl> + name value changed <nl> <nl> - max_rows_to_read 10000 1 <nl> - readonly 2 1 <nl> - name value changed <nl> + max_rows_to_read 10000 1 <nl> + readonly 2 1 <nl> + name value changed <nl> <nl> - max_rows_to_read 10000 1 <nl> - readonly 1 1 <nl> - name value changed <nl> + max_rows_to_read 10000 1 <nl> + readonly 1 1 <nl> + name value changed <nl> <nl> - max_rows_to_read 10000 1 <nl> - readonly 2 1 <nl> + max_rows_to_read 10000 1 <nl> + readonly 2 1 <nl> Ok <nl> Ok <nl> 0 <nl> mmm a / tests / queries / 0_stateless / 00405_pretty_formats . reference <nl> ppp b / tests / queries / 0_stateless / 00405_pretty_formats . reference <nl> <nl> │ 8 │ 8 │ ( 8 , ' 8 ' ) │ 2 │ <nl> │ 9 │ 9 │ ( 9 , ' 9 ' ) │ ᴺᵁᴸᴸ │ <nl> └ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ <nl> -  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> +  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> <nl> - 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> - 1 1 ( 1 , ' 1 ' ) 1 <nl> - 2 2 ( 2 , ' 2 ' ) 2 <nl> - 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> - 4 4 ( 4 , ' 4 ' ) 1 <nl> -  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> + 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> + 1 1 ( 1 , ' 1 ' ) 1 <nl> + 2 2 ( 2 , ' 2 ' ) 2 <nl> + 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> + 4 4 ( 4 , ' 4 ' ) 1 <nl> +  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> <nl> - 5 5 ( 5 , ' 5 ' ) 2 <nl> - 6 6 ( 6 , ' 6 ' ) ᴺᵁᴸᴸ <nl> - 7 7 ( 7 , ' 7 ' ) 1 <nl> - 8 8 ( 8 , ' 8 ' ) 2 <nl> - 9 9 ( 9 , ' 9 ' ) ᴺᵁᴸᴸ <nl> + 5 5 ( 5 , ' 5 ' ) 2 <nl> + 6 6 ( 6 , ' 6 ' ) ᴺᵁᴸᴸ <nl> + 7 7 ( 7 , ' 7 ' ) 1 <nl> + 8 8 ( 8 , ' 8 ' ) 2 <nl> + 9 9 ( 9 , ' 9 ' ) ᴺᵁᴸᴸ <nl> ┌ ─  [ 1mhello  [ 0m ─ ┬ ─  [ 1mworld  [ 0m ─ ┬ ─  [ 1mtuple  [ 0m ─ ─ ─ ┬ ─  [ 1msometimes_nulls  [ 0m ─ ┐ <nl> │ 0 │ 0 │ ( 0 , ' 0 ' ) │ ᴺᵁᴸᴸ │ <nl> │ 1 │ 1 │ ( 1 , ' 1 ' ) │ 1 │ <nl> <nl> │ 8 │ 8 │ ( 8 , ' 8 ' ) │ 2 │ <nl> │ 9 │ 9 │ ( 9 , ' 9 ' ) │ ᴺᵁᴸᴸ │ <nl> └ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ <nl> - hello world tuple sometimes_nulls <nl> + hello world tuple sometimes_nulls <nl> <nl> - 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> - 1 1 ( 1 , ' 1 ' ) 1 <nl> - 2 2 ( 2 , ' 2 ' ) 2 <nl> - 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> - 4 4 ( 4 , ' 4 ' ) 1 <nl> - hello world tuple sometimes_nulls <nl> + 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> + 1 1 ( 1 , ' 1 ' ) 1 <nl> + 2 2 ( 2 , ' 2 ' ) 2 <nl> + 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> + 4 4 ( 4 , ' 4 ' ) 1 <nl> + hello world tuple sometimes_nulls <nl> <nl> - 5 5 ( 5 , ' 5 ' ) 2 <nl> - 6 6 ( 6 , ' 6 ' ) ᴺᵁᴸᴸ <nl> - 7 7 ( 7 , ' 7 ' ) 1 <nl> - 8 8 ( 8 , ' 8 ' ) 2 <nl> - 9 9 ( 9 , ' 9 ' ) ᴺᵁᴸᴸ <nl> + 5 5 ( 5 , ' 5 ' ) 2 <nl> + 6 6 ( 6 , ' 6 ' ) ᴺᵁᴸᴸ <nl> + 7 7 ( 7 , ' 7 ' ) 1 <nl> + 8 8 ( 8 , ' 8 ' ) 2 <nl> + 9 9 ( 9 , ' 9 ' ) ᴺᵁᴸᴸ <nl> ┏ ━ ━ ━ ━ ━ ━ ━ ┳ ━ ━ ━ ━ ━ ━ ━ ┳ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┳ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┓ <nl> ┃  [ 1mhello  [ 0m ┃  [ 1mworld  [ 0m ┃  [ 1mtuple  [ 0m ┃  [ 1msometimes_nulls  [ 0m ┃ <nl> ┡ ━ ━ ━ ━ ━ ━ ━ ╇ ━ ━ ━ ━ ━ ━ ━ ╇ ━ ━ ━ ━ ━ ━ ━ ━ ━ ╇ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┩ <nl> hello world tuple sometimes_nulls <nl> │ 5 │ 5 │ ( 5 , ' 5 ' ) │ 2 │ <nl> └ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ <nl> Showed first 6 . <nl> -  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> +  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> <nl> - 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> - 1 1 ( 1 , ' 1 ' ) 1 <nl> - 2 2 ( 2 , ' 2 ' ) 2 <nl> - 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> - 4 4 ( 4 , ' 4 ' ) 1 <nl> -  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> + 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> + 1 1 ( 1 , ' 1 ' ) 1 <nl> + 2 2 ( 2 , ' 2 ' ) 2 <nl> + 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> + 4 4 ( 4 , ' 4 ' ) 1 <nl> +  [ 1mhello  [ 0m  [ 1mworld  [ 0m  [ 1mtuple  [ 0m  [ 1msometimes_nulls  [ 0m <nl> <nl> - 5 5 ( 5 , ' 5 ' ) 2 <nl> + 5 5 ( 5 , ' 5 ' ) 2 <nl> <nl> Showed first 6 . <nl> ┌ ─  [ 1mhello  [ 0m ─ ┬ ─  [ 1mworld  [ 0m ─ ┬ ─  [ 1mtuple  [ 0m ─ ─ ─ ┬ ─  [ 1msometimes_nulls  [ 0m ─ ┐ <nl> Showed first 6 . <nl> │ 5 │ 5 │ ( 5 , ' 5 ' ) │ 2 │ <nl> └ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ <nl> Showed first 6 . <nl> - hello world tuple sometimes_nulls <nl> + hello world tuple sometimes_nulls <nl> <nl> - 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> - 1 1 ( 1 , ' 1 ' ) 1 <nl> - 2 2 ( 2 , ' 2 ' ) 2 <nl> - 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> - 4 4 ( 4 , ' 4 ' ) 1 <nl> - hello world tuple sometimes_nulls <nl> + 0 0 ( 0 , ' 0 ' ) ᴺᵁᴸᴸ <nl> + 1 1 ( 1 , ' 1 ' ) 1 <nl> + 2 2 ( 2 , ' 2 ' ) 2 <nl> + 3 3 ( 3 , ' 3 ' ) ᴺᵁᴸᴸ <nl> + 4 4 ( 4 , ' 4 ' ) 1 <nl> + hello world tuple sometimes_nulls <nl> <nl> - 5 5 ( 5 , ' 5 ' ) 2 <nl> + 5 5 ( 5 , ' 5 ' ) 2 <nl> <nl> Showed first 6 . <nl> mmm a / tests / queries / 0_stateless / 00476_pretty_formats_and_widths . reference <nl> ppp b / tests / queries / 0_stateless / 00476_pretty_formats_and_widths . reference <nl> <nl> │ 100000000 │ 100000000 │ <nl> │ 1000000000 │ 1000000000 │ <nl> └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ <nl> -  [ 1mx  [ 0m  [ 1ms  [ 0m <nl> +  [ 1mx  [ 0m  [ 1ms  [ 0m <nl> <nl> - 1 1 <nl> - 10 10 <nl> - 100 100 <nl> - 1000 1000 <nl> - 10000 10000 <nl> - 100000 100000 <nl> - 1000000 1000000 <nl> - 10000000 10000000 <nl> - 100000000 100000000 <nl> - 1000000000 1000000000 <nl> + 1 1 <nl> + 10 10 <nl> + 100 100 <nl> + 1000 1000 <nl> + 10000 10000 <nl> + 100000 100000 <nl> + 1000000 1000000 <nl> + 10000000 10000000 <nl> + 100000000 100000000 <nl> + 1000000000 1000000000 <nl> ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─  [ 1mx  [ 0m ─ ┬ ─  [ 1ms  [ 0m ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ <nl> │ 1 │ 1 │ <nl> │ 10 │ 10 │ <nl> mmm a / tests / queries / 0_stateless / 00569_parse_date_time_best_effort . reference <nl> ppp b / tests / queries / 0_stateless / 00569_parse_date_time_best_effort . reference <nl> <nl> - s a b <nl> + s a b <nl> <nl> - 0 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> - 0000 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> - 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> - 01 : 00 : 00 2000 - 01 - 01 01 : 00 : 00 2000 - 01 - 01 01 : 00 : 00 <nl> - 02 / 01 / 17 010203 MSK 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> - 02 / 01 / 17 010203 MSK + 0100 2017 - 01 - 01 21 : 02 : 03 2017 - 01 - 01 21 : 02 : 03 <nl> - 02 / 01 / 17 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> - 02 / 01 / 17 010203Z 2017 - 01 - 02 01 : 02 : 03 2017 - 01 - 02 01 : 02 : 03 <nl> - 02 / 01 / 1970 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> - 02 / 01 / 70 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> - 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> - 17 Apr 2 1 : 2 : 3 2000 - 04 - 17 01 : 02 : 03 2000 - 04 - 17 01 : 02 : 03 <nl> - 19700102 01 : 00 : 00 1970 - 01 - 02 01 : 00 : 00 1970 - 01 - 02 01 : 00 : 00 <nl> - 1970010201 : 00 : 00 2032 - 06 - 06 02 : 03 : 21 2032 - 06 - 06 02 : 03 : 21 <nl> - 19700102010203 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> - 19700102010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> - 1970 / 01 / 02 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> - 20 2000 - 01 - 20 00 : 00 : 00 2000 - 01 - 20 00 : 00 : 00 <nl> - 201 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 20160101 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> - 2016 - 01 - 01 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> - 201601 - 01 2016 - 01 - 01 01 : 00 : 00 2016 - 01 - 01 01 : 00 : 00 <nl> - 2016 - 01 - 01MSD 2015 - 12 - 31 20 : 00 : 00 2015 - 12 - 31 20 : 00 : 00 <nl> - 2016 - 01 - 01 MSD 2015 - 12 - 31 20 : 00 : 00 2015 - 12 - 31 20 : 00 : 00 <nl> - 201601 - 01 MSD 2016 - 01 - 01 04 : 00 : 00 2016 - 01 - 01 04 : 00 : 00 <nl> - 2016 - 01 - 01UTC 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> - 2016 - 01 - 01Z 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> - 2017 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> - 2017 / 01 / 00 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> - 2017 / 01 / 00 MSD 2016 - 12 - 31 20 : 00 : 00 2016 - 12 - 31 20 : 00 : 00 <nl> - 2017 / 01 / 00 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> - 2017 / 01 / 01 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> - 201701 02 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> - 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 0203 : 04 : 05 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 0 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 00 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 0000 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 030 2017 - 01 - 02 02 : 34 : 05 2017 - 01 - 02 02 : 34 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 0300 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 1 2017 - 01 - 02 02 : 04 : 05 2017 - 01 - 02 02 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 300 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 + 900 2017 - 01 - 01 18 : 04 : 05 2017 - 01 - 01 18 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05GMT 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 MSD 2017 - 01 - 01 23 : 04 : 05 2017 - 01 - 01 23 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 MSD Feb 2017 - 02 - 01 23 : 04 : 05 2017 - 02 - 01 23 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 MSD Jun 2017 - 06 - 01 23 : 04 : 05 2017 - 06 - 01 23 : 04 : 05 <nl> - 2017 - 01 - 02 03 : 04 : 05 MSK 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05 + 00 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05 + 0100 2017 - 01 - 02 02 : 04 : 05 2017 - 01 - 02 02 : 04 : 05 <nl> - 2017 - 01 - 02T03 : 04 : 05Z 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> - 2017 - 01 03 : 04 : 05 MSD Jun 2017 - 05 - 31 23 : 04 : 05 2017 - 05 - 31 23 : 04 : 05 <nl> - 2017 - 01 03 : 04 MSD Jun 2017 - 05 - 31 23 : 04 : 00 2017 - 05 - 31 23 : 04 : 00 <nl> - 2017 / 01 / 31 2017 - 01 - 31 00 : 00 : 00 2017 - 01 - 31 00 : 00 : 00 <nl> - 2017 / 01 / 32 0000 - 00 - 00 00 : 00 : 00 0000 - 00 - 00 00 : 00 : 00 <nl> - 2017 - 01 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> - 201701 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> - 2017 25 1 : 2 : 3 0000 - 00 - 00 00 : 00 : 00 0000 - 00 - 00 00 : 00 : 00 <nl> - 2017 25 Apr 1 : 2 : 3 2017 - 04 - 01 01 : 02 : 03 2017 - 04 - 01 01 : 02 : 03 <nl> - 2017 Apr 01 11 : 22 : 33 2017 - 04 - 01 11 : 22 : 33 2017 - 04 - 01 11 : 22 : 33 <nl> - 2017 Apr 02 01 / 02 / 03 UTC + 0300 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 2017 Apr 02 010203 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 01 : 2 : 3 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 1 : 02 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> - 2017 Apr 02 11 : 22 : 33 2017 - 04 - 02 11 : 22 : 33 2017 - 04 - 02 11 : 22 : 33 <nl> - 2017 Apr 02 1 : 2 : 03 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> - 2017 Apr 02 1 : 22 : 33 2017 - 04 - 02 01 : 22 : 33 2017 - 04 - 02 01 : 22 : 33 <nl> - 2017 Apr 02 1 : 2 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 33 2017 - 04 - 02 01 : 02 : 33 2017 - 04 - 02 01 : 02 : 33 <nl> - 2017 Apr 02 1 : 2 : 3 MSK 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 3 MSK 2017 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 3 MSK 2018 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 3 UTC + 0000 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 3 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> - 2017 Apr 02 1 : 2 : 3 UTC + 0400 2017 - 04 - 01 21 : 02 : 03 2017 - 04 - 01 21 : 02 : 03 <nl> - 2017 Apr 2 1 : 2 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> - 2017 Jan 02 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> - 25 Apr 2017 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 <nl> - 25 Apr 2017 1 : 2 : 3 2017 - 04 - 25 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 MSK 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3Z 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 0300 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 0300 OM ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 0300 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z + 03 : 30 PM 2017 - 01 - 25 09 : 32 : 03 2017 - 01 - 25 09 : 32 : 03 <nl> - 25 Jan 2017 1 : 2 : 3Z Mo ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 25 Jan 2017 1 : 2 : 3Z Mon 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3Z Moo ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> - 25 Jan 2017 1 : 2 : 3 Z PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3Z PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> - 25 Jan 2017 1 : 2 : 3 Z PM + 03 : 00 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> - Jun , 11 Feb 2018 06 : 40 : 50 + 0300 2000 - 06 - 01 00 : 00 : 00 2000 - 06 - 01 00 : 00 : 00 <nl> - Sun 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> - Sun , 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> + 0 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> + 0000 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> + 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 2000 - 01 - 01 00 : 00 : 00 <nl> + 01 : 00 : 00 2000 - 01 - 01 01 : 00 : 00 2000 - 01 - 01 01 : 00 : 00 <nl> + 02 / 01 / 17 010203 MSK 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> + 02 / 01 / 17 010203 MSK + 0100 2017 - 01 - 01 21 : 02 : 03 2017 - 01 - 01 21 : 02 : 03 <nl> + 02 / 01 / 17 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> + 02 / 01 / 17 010203Z 2017 - 01 - 02 01 : 02 : 03 2017 - 01 - 02 01 : 02 : 03 <nl> + 02 / 01 / 1970 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> + 02 / 01 / 70 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> + 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> + 17 Apr 2 1 : 2 : 3 2000 - 04 - 17 01 : 02 : 03 2000 - 04 - 17 01 : 02 : 03 <nl> + 19700102 01 : 00 : 00 1970 - 01 - 02 01 : 00 : 00 1970 - 01 - 02 01 : 00 : 00 <nl> + 1970010201 : 00 : 00 2032 - 06 - 06 02 : 03 : 21 2032 - 06 - 06 02 : 03 : 21 <nl> + 19700102010203 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> + 19700102010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> + 1970 / 01 / 02 010203Z 1970 - 01 - 02 01 : 02 : 03 1970 - 01 - 02 01 : 02 : 03 <nl> + 20 2000 - 01 - 20 00 : 00 : 00 2000 - 01 - 20 00 : 00 : 00 <nl> + 201 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 20160101 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> + 2016 - 01 - 01 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> + 201601 - 01 2016 - 01 - 01 01 : 00 : 00 2016 - 01 - 01 01 : 00 : 00 <nl> + 2016 - 01 - 01MSD 2015 - 12 - 31 20 : 00 : 00 2015 - 12 - 31 20 : 00 : 00 <nl> + 2016 - 01 - 01 MSD 2015 - 12 - 31 20 : 00 : 00 2015 - 12 - 31 20 : 00 : 00 <nl> + 201601 - 01 MSD 2016 - 01 - 01 04 : 00 : 00 2016 - 01 - 01 04 : 00 : 00 <nl> + 2016 - 01 - 01UTC 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> + 2016 - 01 - 01Z 2016 - 01 - 01 00 : 00 : 00 2016 - 01 - 01 00 : 00 : 00 <nl> + 2017 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> + 2017 / 01 / 00 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> + 2017 / 01 / 00 MSD 2016 - 12 - 31 20 : 00 : 00 2016 - 12 - 31 20 : 00 : 00 <nl> + 2017 / 01 / 00 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> + 2017 / 01 / 01 2017 - 01 - 01 00 : 00 : 00 2017 - 01 - 01 00 : 00 : 00 <nl> + 201701 02 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> + 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 0203 : 04 : 05 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 0 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 00 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 0000 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 030 2017 - 01 - 02 02 : 34 : 05 2017 - 01 - 02 02 : 34 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 0300 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 1 2017 - 01 - 02 02 : 04 : 05 2017 - 01 - 02 02 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 300 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 + 900 2017 - 01 - 01 18 : 04 : 05 2017 - 01 - 01 18 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05GMT 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 MSD 2017 - 01 - 01 23 : 04 : 05 2017 - 01 - 01 23 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 MSD Feb 2017 - 02 - 01 23 : 04 : 05 2017 - 02 - 01 23 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 MSD Jun 2017 - 06 - 01 23 : 04 : 05 2017 - 06 - 01 23 : 04 : 05 <nl> + 2017 - 01 - 02 03 : 04 : 05 MSK 2017 - 01 - 02 00 : 04 : 05 2017 - 01 - 02 00 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05 + 00 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05 - 0100 2017 - 01 - 02 04 : 04 : 05 2017 - 01 - 02 04 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05 + 0100 2017 - 01 - 02 02 : 04 : 05 2017 - 01 - 02 02 : 04 : 05 <nl> + 2017 - 01 - 02T03 : 04 : 05Z 2017 - 01 - 02 03 : 04 : 05 2017 - 01 - 02 03 : 04 : 05 <nl> + 2017 - 01 03 : 04 : 05 MSD Jun 2017 - 05 - 31 23 : 04 : 05 2017 - 05 - 31 23 : 04 : 05 <nl> + 2017 - 01 03 : 04 MSD Jun 2017 - 05 - 31 23 : 04 : 00 2017 - 05 - 31 23 : 04 : 00 <nl> + 2017 / 01 / 31 2017 - 01 - 31 00 : 00 : 00 2017 - 01 - 31 00 : 00 : 00 <nl> + 2017 / 01 / 32 0000 - 00 - 00 00 : 00 : 00 0000 - 00 - 00 00 : 00 : 00 <nl> + 2017 - 01 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> + 201701 MSD Jun 2017 - 05 - 31 20 : 00 : 00 2017 - 05 - 31 20 : 00 : 00 <nl> + 2017 25 1 : 2 : 3 0000 - 00 - 00 00 : 00 : 00 0000 - 00 - 00 00 : 00 : 00 <nl> + 2017 25 Apr 1 : 2 : 3 2017 - 04 - 01 01 : 02 : 03 2017 - 04 - 01 01 : 02 : 03 <nl> + 2017 Apr 01 11 : 22 : 33 2017 - 04 - 01 11 : 22 : 33 2017 - 04 - 01 11 : 22 : 33 <nl> + 2017 Apr 02 01 / 02 / 03 UTC + 0300 ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 2017 Apr 02 010203 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 01 : 2 : 3 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 1 : 02 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> + 2017 Apr 02 11 : 22 : 33 2017 - 04 - 02 11 : 22 : 33 2017 - 04 - 02 11 : 22 : 33 <nl> + 2017 Apr 02 1 : 2 : 03 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> + 2017 Apr 02 1 : 22 : 33 2017 - 04 - 02 01 : 22 : 33 2017 - 04 - 02 01 : 22 : 33 <nl> + 2017 Apr 02 1 : 2 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 33 2017 - 04 - 02 01 : 02 : 33 2017 - 04 - 02 01 : 02 : 33 <nl> + 2017 Apr 02 1 : 2 : 3 MSK 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 3 MSK 2017 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 3 MSK 2018 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 3 UTC + 0000 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 3 UTC + 0300 2017 - 04 - 01 22 : 02 : 03 2017 - 04 - 01 22 : 02 : 03 <nl> + 2017 Apr 02 1 : 2 : 3 UTC + 0400 2017 - 04 - 01 21 : 02 : 03 2017 - 04 - 01 21 : 02 : 03 <nl> + 2017 Apr 2 1 : 2 : 3 2017 - 04 - 02 01 : 02 : 03 2017 - 04 - 02 01 : 02 : 03 <nl> + 2017 Jan 02 010203 UTC + 0300 2017 - 01 - 01 22 : 02 : 03 2017 - 01 - 01 22 : 02 : 03 <nl> + 25 Apr 2017 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 <nl> + 25 Apr 2017 1 : 2 : 3 2017 - 04 - 25 01 : 02 : 03 2017 - 04 - 25 01 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 MSK 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3Z 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 0300 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 2017 - 01 - 24 22 : 02 : 03 2017 - 01 - 24 22 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 0300 OM ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 0300 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 03 : 00 PM 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z + 03 : 30 PM 2017 - 01 - 25 09 : 32 : 03 2017 - 01 - 25 09 : 32 : 03 <nl> + 25 Jan 2017 1 : 2 : 3Z Mo ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 25 Jan 2017 1 : 2 : 3Z Mon 2017 - 01 - 25 01 : 02 : 03 2017 - 01 - 25 01 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3Z Moo ᴺᵁᴸᴸ 0000 - 00 - 00 00 : 00 : 00 <nl> + 25 Jan 2017 1 : 2 : 3 Z PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3Z PM 2017 - 01 - 25 13 : 02 : 03 2017 - 01 - 25 13 : 02 : 03 <nl> + 25 Jan 2017 1 : 2 : 3 Z PM + 03 : 00 2017 - 01 - 25 10 : 02 : 03 2017 - 01 - 25 10 : 02 : 03 <nl> + Jun , 11 Feb 2018 06 : 40 : 50 + 0300 2000 - 06 - 01 00 : 00 : 00 2000 - 06 - 01 00 : 00 : 00 <nl> + Sun 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> + Sun , 11 Feb 2018 06 : 40 : 50 + 0300 2018 - 02 - 11 03 : 40 : 50 2018 - 02 - 11 03 : 40 : 50 <nl> mmm a / tests / queries / 0_stateless / 00813_parse_date_time_best_effort_more . reference <nl> ppp b / tests / queries / 0_stateless / 00813_parse_date_time_best_effort_more . reference <nl> <nl> - s a b <nl> + s a b <nl> <nl> - 24 . 12 . 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - 12 - 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 . 12 . 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - 12 - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - Dec - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 / DEC / 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 / DEC / 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 01 - OCT - 2015 2015 - 10 - 01 00 : 00 : 00 2015 - 10 - 01 00 : 00 : 00 <nl> - 24 . 12 . 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - 12 - 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 . 12 . 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - 12 - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 - Dec - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 / DEC / 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 24 / DEC / 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> - 01 - OCT - 2015 2015 - 10 - 01 00 : 00 : 00 2015 - 10 - 01 00 : 00 : 00 <nl> - 24 . 12 . 18 010203 2018 - 12 - 24 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 <nl> - 24 . 12 . 18 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 <nl> - 24 . DEC . 18T01 : 02 : 03 . 000 + 0300 2018 - 12 - 23 22 : 02 : 03 2018 - 12 - 23 22 : 02 : 03 <nl> - 01 - September - 2018 11 : 22 2018 - 09 - 01 11 : 22 : 00 2018 - 09 - 01 11 : 22 : 00 <nl> + 24 . 12 . 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - 12 - 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 . 12 . 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - 12 - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - Dec - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 / DEC / 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 / DEC / 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 01 - OCT - 2015 2015 - 10 - 01 00 : 00 : 00 2015 - 10 - 01 00 : 00 : 00 <nl> + 24 . 12 . 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - 12 - 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 . 12 . 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - 12 - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 - Dec - 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 / DEC / 18 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 24 / DEC / 2018 2018 - 12 - 24 00 : 00 : 00 2018 - 12 - 24 00 : 00 : 00 <nl> + 01 - OCT - 2015 2015 - 10 - 01 00 : 00 : 00 2015 - 10 - 01 00 : 00 : 00 <nl> + 24 . 12 . 18 010203 2018 - 12 - 24 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 <nl> + 24 . 12 . 18 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 2018 - 12 - 24 01 : 02 : 03 <nl> + 24 . DEC . 18T01 : 02 : 03 . 000 + 0300 2018 - 12 - 23 22 : 02 : 03 2018 - 12 - 23 22 : 02 : 03 <nl> + 01 - September - 2018 11 : 22 2018 - 09 - 01 11 : 22 : 00 2018 - 09 - 01 11 : 22 : 00 <nl>
Updated tests
ClickHouse/ClickHouse
cd07d61ce7e38a9a913e0caa6c7f48f03a6c4996
2020-06-02T02:39:21Z
mmm a / arangod / Replication / Syncer . cpp <nl> ppp b / arangod / Replication / Syncer . cpp <nl> int Syncer : : dropIndex ( arangodb : : velocypack : : Slice const & slice ) { <nl> TRI_voc_cid_t const cid = getCid ( slice ) ; <nl> std : : string cnameString = getCName ( slice ) ; <nl> <nl> - / / TODO <nl> - / / Backwards compatibility . old check to nullptr , new is empty string <nl> - / / Other api does not know yet . <nl> - char const * cname = nullptr ; <nl> - if ( ! cnameString . empty ( ) ) { <nl> - cname = cnameString . c_str ( ) ; <nl> - } <nl> - <nl> try { <nl> - CollectionGuard guard ( _vocbase , cid , std : : string ( cname ) ) ; <nl> + CollectionGuard guard ( _vocbase , cid , cnameString ) ; <nl> <nl> if ( guard . collection ( ) = = nullptr ) { <nl> return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND ; <nl>
fix potential nullptr dereference
arangodb/arangodb
a7616ed0f6ded464ee4715aa9eb77a5b13b04363
2016-12-27T17:42:22Z
mmm a / CONTRIBUTION . md <nl> ppp b / CONTRIBUTION . md <nl> If cpplint is ___not___ installed then do : <nl> Once cpplint is installed , test your file ( s ) with : <nl> * ` cpplint - - filter = - legal my_file . cpp my_other_file . cpp ` # Fix any issues and try again . <nl> <nl> + The [ __clang - format__ ] ( https : / / clang . llvm . org / docs / ClangFormat . html ) tool can fix many but not all _cpplint_ issues . <nl> + * On Macs only : ` brew install clang - format ` # Only needs to be installed once . <nl> + * All platforms : ` clang - format - - style = Google - i my_file . cpp ` <nl> + <nl> - Most importantly , <nl> - Happy coding ! <nl>
clang - format - - style = Google - i my_file . cpp
TheAlgorithms/C-Plus-Plus
4717db2a08238dd3dff1bc6246896709fd522648
2019-12-05T08:21:08Z
mmm a / lib / IRGen / IRGenModule . cpp <nl> ppp b / lib / IRGen / IRGenModule . cpp <nl> <nl> # include " swift / AST / Module . h " <nl> # include " swift / AST / DiagnosticsIRGen . h " <nl> # include " swift / AST / IRGenOptions . h " <nl> + # include " clang / Basic / CodeGenOptions . h " <nl> # include " swift / Basic / Dwarf . h " <nl> # include " swift / Basic / Version . h " <nl> # include " swift / ClangImporter / ClangImporter . h " <nl> <nl> # include " clang / Lex / PreprocessorOptions . h " <nl> # include " clang / Lex / HeaderSearch . h " <nl> # include " clang / Lex / HeaderSearchOptions . h " <nl> - # include " clang / Frontend / CodeGenOptions . h " <nl> # include " llvm / IR / Constants . h " <nl> # include " llvm / IR / DataLayout . h " <nl> # include " llvm / IR / DerivedTypes . h " <nl>
clang / Frontend / CodeGenOptions . h moved to clang / Basic .
apple/swift
9a584682b0a3846801a9ebdd0f85ad748a48d635
2016-04-14T17:13:09Z
mmm a / vnext / ReactUWP / Polyester / IconViewManager . cpp <nl> ppp b / vnext / ReactUWP / Polyester / IconViewManager . cpp <nl> using namespace Windows : : UI : : Xaml : : Media ; <nl> <nl> namespace react { namespace uwp { namespace polyester { <nl> <nl> - IconViewManager : : IconViewManager ( const std : : shared_ptr < IReactInstance > & reactInstance ) <nl> - : Super ( reactInstance ) <nl> + / / <nl> + / / IconShadowNode <nl> + / / <nl> + class IconShadowNode : public ShadowNodeBase <nl> { <nl> - } <nl> + using Super = ShadowNodeBase ; <nl> + public : <nl> + IconShadowNode ( ) = default ; <nl> <nl> - const char * IconViewManager : : GetName ( ) const <nl> - { <nl> - return " PLYIcon " ; <nl> - } <nl> + void createView ( ) override ; <nl> + void updateProperties ( const folly : : dynamic & & props ) override ; <nl> <nl> - folly : : dynamic IconViewManager : : GetNativeProps ( ) const <nl> - { <nl> - auto props = Super : : GetNativeProps ( ) ; <nl> - <nl> - props . update ( folly : : dynamic : : object <nl> - ( " fontUri " , " string " ) <nl> - ( " glyph " , " string " ) <nl> - ( " colorEnabled " , " boolean " ) <nl> - ) ; <nl> + private : <nl> + static void UpdateFontColorProps ( winrt : : Windows : : UI : : Xaml : : Documents : : Glyphs glyphs ) ; <nl> <nl> - return props ; <nl> - } <nl> + std : : optional < double > m_emSize ; <nl> + double m_height = 24 ; <nl> + } ; <nl> <nl> - XamlView IconViewManager : : CreateViewCore ( int64_t tag ) <nl> + void IconShadowNode : : createView ( ) <nl> { <nl> - winrt : : Glyphs glyphs = winrt : : Glyphs ( ) ; <nl> + Super : : createView ( ) ; <nl> + auto glyphs = GetView ( ) . as < winrt : : Glyphs > ( ) ; <nl> + <nl> glyphs . FontRenderingEmSize ( 24 ) ; <nl> UpdateFontColorProps ( glyphs ) ; <nl> - <nl> - return glyphs ; <nl> } <nl> <nl> - void IconViewManager : : UpdateProperties ( ShadowNodeBase * nodeToUpdate , const folly : : dynamic & reactDiffMap ) <nl> + void IconShadowNode : : updateProperties ( const folly : : dynamic & & props ) <nl> { <nl> - auto glyphs = nodeToUpdate - > GetView ( ) . as < winrt : : Glyphs > ( ) ; <nl> - if ( glyphs = = nullptr ) <nl> - return ; <nl> + m_updating = true ; <nl> + auto glyphs = GetView ( ) . as < winrt : : Glyphs > ( ) ; <nl> + bool updateEmSize = false ; <nl> <nl> - for ( const auto & pair : reactDiffMap . items ( ) ) <nl> + for ( auto & pair : props . items ( ) ) <nl> { <nl> const std : : string & propertyName = pair . first . getString ( ) ; <nl> const folly : : dynamic & propertyValue = pair . second ; <nl> void IconViewManager : : UpdateProperties ( ShadowNodeBase * nodeToUpdate , const folly <nl> else if ( propertyName = = " height " ) <nl> { <nl> if ( propertyValue . isNumber ( ) ) <nl> - glyphs . FontRenderingEmSize ( propertyValue . asDouble ( ) ) ; <nl> + m_height = propertyValue . asDouble ( ) ; <nl> + <nl> + updateEmSize = true ; <nl> } <nl> + else if ( propertyName = = " emSize " ) <nl> + { <nl> + if ( propertyValue . isNumber ( ) ) <nl> + m_emSize = propertyValue . asDouble ( ) ; <nl> + else <nl> + m_emSize . reset ( ) ; <nl> + <nl> + updateEmSize = true ; <nl> + } <nl> + } <nl> + <nl> + if ( updateEmSize ) <nl> + { <nl> + / / Default emSize to match height , unless its been explicitly set <nl> + <nl> + / / FUTURE : enable some default scaling of 0 . 75 to convert height px to em ? <nl> + / / The SegouUI Emoji font renders the full area of the emSize <nl> + / / where emSize should be height * 0 . 75 , but office icon fonts <nl> + / / do not and applying a scale would be wrong <nl> <nl> - continue ; <nl> + double emSize = m_height ; <nl> + if ( m_emSize . has_value ( ) ) <nl> + emSize = m_emSize . value ( ) ; <nl> + glyphs . FontRenderingEmSize ( emSize ) ; <nl> } <nl> <nl> - Super : : UpdateProperties ( nodeToUpdate , reactDiffMap ) ; <nl> + Super : : updateProperties ( std : : move ( props ) ) ; <nl> + m_updating = false ; <nl> } <nl> <nl> - / * static * / void IconViewManager : : UpdateFontColorProps ( winrt : : Glyphs glyphs ) <nl> + / * static * / void IconShadowNode : : UpdateFontColorProps ( winrt : : Glyphs glyphs ) <nl> { <nl> glyphs . IsColorFontEnabled ( false ) ; <nl> <nl> void IconViewManager : : UpdateProperties ( ShadowNodeBase * nodeToUpdate , const folly <nl> glyphs . Fill ( winrt : : SolidColorBrush ( color ) ) ; <nl> } <nl> <nl> + / / <nl> + / / IconViewManager <nl> + / / <nl> + IconViewManager : : IconViewManager ( const std : : shared_ptr < IReactInstance > & reactInstance ) <nl> + : Super ( reactInstance ) <nl> + { <nl> + } <nl> + <nl> + const char * IconViewManager : : GetName ( ) const <nl> + { <nl> + return " PLYIcon " ; <nl> + } <nl> + <nl> + facebook : : react : : ShadowNode * IconViewManager : : createShadow ( ) const <nl> + { <nl> + return new IconShadowNode ( ) ; <nl> + } <nl> + <nl> + folly : : dynamic IconViewManager : : GetNativeProps ( ) const <nl> + { <nl> + auto props = Super : : GetNativeProps ( ) ; <nl> + <nl> + props . update ( folly : : dynamic : : object <nl> + ( " emSize " , " number " ) <nl> + ( " fontUri " , " string " ) <nl> + ( " glyph " , " string " ) <nl> + ( " colorEnabled " , " boolean " ) <nl> + ) ; <nl> + <nl> + return props ; <nl> + } <nl> + <nl> + XamlView IconViewManager : : CreateViewCore ( int64_t tag ) <nl> + { <nl> + winrt : : Glyphs glyphs = winrt : : Glyphs ( ) ; <nl> + return glyphs ; <nl> + } <nl> + <nl> } } } <nl> mmm a / vnext / ReactUWP / Polyester / IconViewManager . h <nl> ppp b / vnext / ReactUWP / Polyester / IconViewManager . h <nl> class IconViewManager : public FrameworkElementViewManager <nl> IconViewManager ( const std : : shared_ptr < IReactInstance > & reactInstance ) ; <nl> <nl> const char * GetName ( ) const override ; <nl> + facebook : : react : : ShadowNode * createShadow ( ) const override ; <nl> folly : : dynamic GetNativeProps ( ) const override ; <nl> <nl> - void UpdateProperties ( ShadowNodeBase * nodeToUpdate , const folly : : dynamic & reactDiffMap ) override ; <nl> - <nl> protected : <nl> XamlView CreateViewCore ( int64_t tag ) override ; <nl> - <nl> - private : <nl> - static void UpdateFontColorProps ( winrt : : Windows : : UI : : Xaml : : Documents : : Glyphs glyphs ) ; <nl> } ; <nl> <nl> } } } <nl> new file mode 100644 <nl> index 0000000000 . . 6d4fcbf777 <nl> Binary files / dev / null and b / vnext / Universal . SampleApp / Assets / seguiemj . ttf differ <nl> mmm a / vnext / Universal . SampleApp / React . Windows . Universal . SampleApp . vcxproj <nl> ppp b / vnext / Universal . SampleApp / React . Windows . Universal . SampleApp . vcxproj <nl> <nl> < Project > { 2d5d43d9 - cffc - 4c40 - b4cd - 02efb4e2742b } < / Project > <nl> < / ProjectReference > <nl> < / ItemGroup > <nl> + < ItemGroup > <nl> + < Font Include = " Assets \ seguiemj . ttf " / > <nl> + < / ItemGroup > <nl> < Import Project = " $ ( VCTargetsPath ) \ Microsoft . Cpp . targets " / > <nl> < ImportGroup Label = " ExtensionTargets " > <nl> < Import Project = " $ ( SolutionDir ) \ packages \ boost . 1 . 68 . 0 . 0 \ build \ boost . targets " Condition = " Exists ( ' $ ( SolutionDir ) \ packages \ boost . 1 . 68 . 0 . 0 \ build \ boost . targets ' ) " / > <nl> mmm a / vnext / Universal . SampleApp / React . Windows . Universal . SampleApp . vcxproj . filters <nl> ppp b / vnext / Universal . SampleApp / React . Windows . Universal . SampleApp . vcxproj . filters <nl> <nl> < ItemGroup > <nl> < Natvis Include = " $ ( ReactNativeWindowsDir ) Folly \ Folly . natvis " / > <nl> < / ItemGroup > <nl> + < ItemGroup > <nl> + < Font Include = " Assets \ seguiemj . ttf " > <nl> + < Filter > Assets < / Filter > <nl> + < / Font > <nl> + < / ItemGroup > <nl> < / Project > <nl> \ No newline at end of file <nl> new file mode 100644 <nl> index 0000000000 . . cc1795bd74 <nl> mmm / dev / null <nl> ppp b / vnext / src / Libraries / Components / Glyph / Glyph . tsx <nl> <nl> + / / Copyright ( c ) Microsoft Corporation . All rights reserved . <nl> + / / Licensed under the MIT License . <nl> + ' use strict ' ; <nl> + <nl> + import * as React from ' react ' ; <nl> + import { GlyphProps } from ' . / GlyphProps ' ; <nl> + <nl> + export class Glyph extends React . PureComponent < GlyphProps > { <nl> + public render ( ) : JSX . Element | null { <nl> + return null ; <nl> + } <nl> + } <nl> + <nl> + export default Glyph ; <nl> new file mode 100644 <nl> index 0000000000 . . f95cb277a6 <nl> mmm / dev / null <nl> ppp b / vnext / src / Libraries / Components / Glyph / Glyph . uwp . tsx <nl> <nl> + / / Copyright ( c ) Microsoft Corporation . All rights reserved . <nl> + / / Licensed under the MIT License . <nl> + ' use strict ' ; <nl> + <nl> + import * as React from ' react ' ; <nl> + import { requireNativeComponent } from ' react - native ' ; <nl> + import { GlyphProps } from ' . / GlyphProps ' ; <nl> + <nl> + const RCTGlyph = requireNativeComponent ( ' PLYIcon ' ) ; <nl> + <nl> + / * * <nl> + * Glyph is a wrapper for the Xaml Glyph control <nl> + * <nl> + * This control is used to render Glyphs from a Font file , which might be <nl> + * used similar to SVG to have vector based images that also have the <nl> + * ability to be rendered with a specific color <nl> + * / <nl> + export class Glyph extends React . PureComponent < GlyphProps > { <nl> + public render ( ) : JSX . Element { <nl> + const props = { . . . this . props } ; <nl> + props . style = this . props . style ; <nl> + <nl> + return ( <nl> + < RCTGlyph <nl> + { . . . props } <nl> + / > <nl> + ) ; <nl> + } <nl> + } <nl> + <nl> + export default Glyph ; <nl> new file mode 100644 <nl> index 0000000000 . . 0a95cb260f <nl> mmm / dev / null <nl> ppp b / vnext / src / Libraries / Components / Glyph / GlyphProps . ts <nl> <nl> + / / Copyright ( c ) Microsoft Corporation . All rights reserved . <nl> + / / Licensed under the MIT License . <nl> + <nl> + import { StyleProp , ViewProps , ViewStyle } from ' react - native ' ; <nl> + <nl> + / / tslint : disable - next - line : interface - name <nl> + export interface GlyphStyle extends ViewStyle { <nl> + color ? : string ; <nl> + } <nl> + <nl> + / / tslint : disable - next - line : interface - name <nl> + export interface GlyphProps extends ViewProps { <nl> + style ? : StyleProp < GlyphStyle > ; <nl> + emSize ? : number ; <nl> + fontUri : string ; <nl> + glyph : string ; <nl> + colorEnabled ? : boolean ; <nl> + } <nl> new file mode 100644 <nl> index 0000000000 . . 2ecbc43624 <nl> mmm / dev / null <nl> ppp b / vnext / src / RNTester / GlyphExample . tsx <nl> <nl> + / / Copyright ( c ) Microsoft Corporation . All rights reserved . <nl> + / / Licensed under the MIT License . <nl> + <nl> + / * tslint : disable * / <nl> + <nl> + import React = require ( ' react ' ) ; <nl> + import { Text , View } from ' react - native ' ; <nl> + import { Glyph } from ' . . / . . / src / index . uwp ' ; <nl> + <nl> + class GlyphExamples extends React . Component { <nl> + public render ( ) { <nl> + return ( <nl> + < View > <nl> + < Text > Glyph : default Accent color < / Text > <nl> + < Glyph <nl> + style = { { width : 32 , height : 32 } } <nl> + emSize = { 24 } <nl> + fontUri = " ms - appx : / / / Assets / seguiemj . ttf " <nl> + glyph = " 300 " <nl> + / > <nl> + < Text > Glyph : red < / Text > <nl> + < Glyph <nl> + style = { { width : 32 , height : 32 , color : ' red ' } } <nl> + fontUri = " ms - appx : / / / Assets / seguiemj . ttf " <nl> + glyph = " 300 " <nl> + / > <nl> + < Text > Multiple glyphs : red < / Text > <nl> + < Glyph <nl> + style = { { width : 150 , height : 32 , color : ' red ' } } <nl> + emSize = { 24 } <nl> + fontUri = " ms - appx : / / / Assets / seguiemj . ttf " <nl> + glyph = " 300 ; 304 ; 703 ; 802 ; 803 " <nl> + / > <nl> + < Text > Multiple glyphs < / Text > <nl> + < Glyph <nl> + style = { { width : 150 , height : 32 , color : ' red ' } } <nl> + emSize = { 24 } <nl> + colorEnabled = { true } <nl> + fontUri = " ms - appx : / / / Assets / seguiemj . ttf " <nl> + glyph = " 804 ; 805 ; 806 ; 807 ; 808 ; 809 " <nl> + / > <nl> + <nl> + < / View > <nl> + ) ; <nl> + } <nl> + } <nl> + <nl> + <nl> + <nl> + <nl> + export const displayName = ( _undefined ? : string ) = > { } ; <nl> + export const title = ' < Glyph > UWP ' ; <nl> + export const description = ' Usage of Glyph control . ' ; <nl> + export const examples = [ <nl> + { <nl> + title : ' Glyph examples ' , <nl> + render : function ( ) : JSX . Element { <nl> + return < GlyphExamples / > ; <nl> + } , <nl> + } <nl> + ] ; <nl> mmm a / vnext / src / RNTester / RNTesterList . uwp . ts <nl> ppp b / vnext / src / RNTester / RNTesterList . uwp . ts <nl> const ComponentExamples : Array < IRNTesterExample > = [ <nl> key : ' FlyoutExample ' , <nl> module : require ( ' . / FlyoutExample . uwp ' ) , <nl> } , <nl> + { <nl> + key : ' GlyphExample ' , <nl> + module : require ( ' . / GlyphExample ' ) , <nl> + } , <nl> { <nl> key : ' ImageExample ' , <nl> module : require ( ' react - native / RNTester / js / ImageExample ' ) , <nl> mmm a / vnext / src / index . ts <nl> ppp b / vnext / src / index . ts <nl> export * from ' . / Libraries / Components / CheckBox / CheckBox ' ; <nl> export * from ' . / Libraries / Components / DatePicker / DatePicker ' ; <nl> export * from ' . / Libraries / Components / DatePicker / DatePickerProps ' ; <nl> export * from ' . / Libraries / Components / Flyout / Flyout ' ; <nl> + export * from ' . / Libraries / Components / Glyph / Glyph ' ; <nl> export * from ' . / Libraries / Components / Picker / PickerUWP ' ; <nl> export * from ' . / Libraries / Components / Popup / Popup ' ; <nl> mmm a / vnext / src / index . uwp . ts <nl> ppp b / vnext / src / index . uwp . ts <nl> export * from ' . / Libraries / Components / CheckBox / CheckBox . uwp ' ; <nl> export * from ' . / Libraries / Components / DatePicker / DatePicker . uwp ' ; <nl> export * from ' . / Libraries / Components / DatePicker / DatePickerProps ' ; <nl> export * from ' . / Libraries / Components / Flyout / Flyout . uwp ' ; <nl> + export * from ' . / Libraries / Components / Glyph / Glyph . uwp ' ; <nl> export * from ' . / Libraries / Components / Picker / PickerUWP . uwp ' ; <nl> export * from ' . / Libraries / Components / Popup / Popup . uwp ' ; <nl>
add < Glyph > component and example ( )
microsoft/react-native-windows
f67fa9cd78a7070fef2292bbda1d26b3e26f0228
2019-06-18T06:03:52Z
mmm a / src / runtime / vm / translator / translator . cpp <nl> ppp b / src / runtime / vm / translator / translator . cpp <nl> void Translator : : analyze ( const SrcKey * csk , Tracelet & t ) { <nl> getInputs ( t , ni , stackFrameOffset , inputInfos , tas ) ; <nl> bool noOp = applyInputMetaData ( metaHand , ni , tas , inputInfos ) ; <nl> if ( noOp ) { <nl> - if ( RuntimeOption : : EvalJitUseIR ) { <nl> + if ( m_useHHIR ) { <nl> t . m_instrStream . append ( ni ) ; <nl> + + t . m_numOpcodes ; <nl> } <nl>
Don ' t include Nopped instructions in the stream after a failed IR translation
facebook/hhvm
0e9d236276a0f51e683c53ee0bca503051d48491
2012-12-07T23:46:59Z
mmm a / lib / ClangImporter / ClangImporter . cpp <nl> ppp b / lib / ClangImporter / ClangImporter . cpp <nl> <nl> # include " clang / Basic / TargetInfo . h " <nl> # include " clang / Basic / Version . h " <nl> # include " llvm / ADT / STLExtras . h " <nl> - # include " llvm / Support / PathV2 . h " <nl> + # include " llvm / Support / Path . h " <nl> # include " llvm / Support / SourceMgr . h " <nl> # include < memory > <nl> # include < cstdlib > <nl> mmm a / lib / Parse / ParseDecl . cpp <nl> ppp b / lib / Parse / ParseDecl . cpp <nl> <nl> # include " swift / AST / Diagnostics . h " <nl> # include " swift / Basic / Fallthrough . h " <nl> # include " llvm / Support / MemoryBuffer . h " <nl> - # include " llvm / Support / PathV2 . h " <nl> + # include " llvm / Support / Path . h " <nl> # include " llvm / ADT / PointerUnion . h " <nl> # include " llvm / ADT / StringSwitch . h " <nl> # include " llvm / ADT / Twine . h " <nl> mmm a / tools / swift / Frontend . cpp <nl> ppp b / tools / swift / Frontend . cpp <nl> <nl> # include " swift / Parse / Lexer . h " <nl> # include " swift / Subsystems . h " <nl> # include " llvm / Support / MemoryBuffer . h " <nl> - # include " llvm / Support / PathV2 . h " <nl> + # include " llvm / Support / Path . h " <nl> # include " llvm / Support / SourceMgr . h " <nl> <nl> using namespace swift ; <nl>
LLVM ' s PathV2 . h has become Path . h . Update includes appropriately
apple/swift
720cb9348db3a7e8dc37865124c7dd8cca033526
2013-06-13T14:53:52Z
mmm a / include / swift / AST / DefaultArgumentKind . h <nl> ppp b / include / swift / AST / DefaultArgumentKind . h <nl> enum { NumDefaultArgumentKindBits = 4 } ; <nl> / / / an empty string if it has none . <nl> llvm : : StringRef getDefaultArgumentSpelling ( DefaultArgumentKind kind ) ; <nl> <nl> - / / / Infer a default argument kind from an expression , if the <nl> - / / / expression is the canonical way to spell that default argument . <nl> - DefaultArgumentKind inferDefaultArgumentKind ( Expr * expr ) ; <nl> - <nl> } / / end namespace swift <nl> <nl> # endif / / LLVM_SWIFT_DEFAULTARGUMENTKIND_H <nl> mmm a / lib / AST / DefaultArgumentKind . cpp <nl> ppp b / lib / AST / DefaultArgumentKind . cpp <nl> StringRef swift : : getDefaultArgumentSpelling ( DefaultArgumentKind kind ) { <nl> <nl> llvm_unreachable ( " Unhandled DefaultArgumentKind in switch . " ) ; <nl> } <nl> - <nl> - DefaultArgumentKind swift : : inferDefaultArgumentKind ( Expr * expr ) { <nl> - if ( auto call = dyn_cast < CallExpr > ( expr ) ) { <nl> - if ( auto ctorRefCall = dyn_cast < ConstructorRefCallExpr > ( call - > getFn ( ) ) ) { <nl> - if ( auto ctorRef = dyn_cast < DeclRefExpr > ( ctorRefCall - > getFn ( ) ) ) { <nl> - if ( auto ctor = dyn_cast < ConstructorDecl > ( ctorRef - > getDecl ( ) ) ) { <nl> - auto ctorArg = call - > getArg ( ) - > getSemanticsProvidingExpr ( ) ; <nl> - <nl> - / / # file , # line , # column , # function , # dsohandle . <nl> - if ( auto magic = dyn_cast < MagicIdentifierLiteralExpr > ( ctorArg ) ) { <nl> - switch ( magic - > getKind ( ) ) { <nl> - case MagicIdentifierLiteralExpr : : File : <nl> - return DefaultArgumentKind : : File ; <nl> - case MagicIdentifierLiteralExpr : : Line : <nl> - return DefaultArgumentKind : : Line ; <nl> - case MagicIdentifierLiteralExpr : : Column : <nl> - return DefaultArgumentKind : : Column ; <nl> - case MagicIdentifierLiteralExpr : : Function : <nl> - return DefaultArgumentKind : : Function ; <nl> - case MagicIdentifierLiteralExpr : : DSOHandle : <nl> - return DefaultArgumentKind : : DSOHandle ; <nl> - } <nl> - } <nl> - <nl> - / / nil . <nl> - if ( ctor - > getFullName ( ) . getArgumentNames ( ) . size ( ) = = 1 & & <nl> - ctor - > getFullName ( ) . getArgumentNames ( ) [ 0 ] <nl> - = = ctor - > getASTContext ( ) . Id_nilLiteral ) <nl> - return DefaultArgumentKind : : NilLiteral ; <nl> - } <nl> - } <nl> - } <nl> - } <nl> - <nl> - / / Empty array literals , [ ] . <nl> - if ( auto arrayExpr = dyn_cast < ArrayExpr > ( expr ) ) { <nl> - if ( arrayExpr - > getElements ( ) . empty ( ) ) <nl> - return DefaultArgumentKind : : EmptyArray ; <nl> - <nl> - return DefaultArgumentKind : : None ; <nl> - } <nl> - <nl> - / / Empty dictionary literals , [ : ] . <nl> - if ( auto dictionaryExpr = dyn_cast < DictionaryExpr > ( expr ) ) { <nl> - if ( dictionaryExpr - > getElements ( ) . empty ( ) ) <nl> - return DefaultArgumentKind : : EmptyDictionary ; <nl> - <nl> - return DefaultArgumentKind : : None ; <nl> - } <nl> - <nl> - return DefaultArgumentKind : : None ; <nl> - } <nl> - <nl>
AST : Remove unused inferDefaultArgumentKind ( ) function
apple/swift
d68ee9ff18787f183bd972b55cde373fa43fc05a
2018-03-17T08:33:39Z
deleted file mode 100644 <nl> index c99485e5080 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / allocators . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ALLOCATORS_H_ <nl> - # define RAPIDJSON_ALLOCATORS_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Allocator <nl> - <nl> - / * ! \ class rapidjson : : Allocator <nl> - \ brief Concept for allocating , resizing and freeing memory block . <nl> - <nl> - Note that Malloc ( ) and Realloc ( ) are non - static but Free ( ) is static . <nl> - <nl> - So if an allocator need to support Free ( ) , it needs to put its pointer in <nl> - the header of memory block . <nl> - <nl> - \ code <nl> - concept Allocator { <nl> - static const bool kNeedFree ; / / ! < Whether this allocator needs to call Free ( ) . <nl> - <nl> - / / Allocate a memory block . <nl> - / / \ param size of the memory block in bytes . <nl> - / / \ returns pointer to the memory block . <nl> - void * Malloc ( size_t size ) ; <nl> - <nl> - / / Resize a memory block . <nl> - / / \ param originalPtr The pointer to current memory block . Null pointer is permitted . <nl> - / / \ param originalSize The current size in bytes . ( Design issue : since some allocator may not book - keep this , explicitly pass to it can save memory . ) <nl> - / / \ param newSize the new size in bytes . <nl> - void * Realloc ( void * originalPtr , size_t originalSize , size_t newSize ) ; <nl> - <nl> - / / Free a memory block . <nl> - / / \ param pointer to the memory block . Null pointer is permitted . <nl> - static void Free ( void * ptr ) ; <nl> - } ; <nl> - \ endcode <nl> - * / <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / CrtAllocator <nl> - <nl> - / / ! C - runtime library allocator . <nl> - / * ! This class is just wrapper for standard C library memory routines . <nl> - \ note implements Allocator concept <nl> - * / <nl> - class CrtAllocator { <nl> - public : <nl> - static const bool kNeedFree = true ; <nl> - void * Malloc ( size_t size ) { return std : : malloc ( size ) ; } <nl> - void * Realloc ( void * originalPtr , size_t originalSize , size_t newSize ) { ( void ) originalSize ; return std : : realloc ( originalPtr , newSize ) ; } <nl> - static void Free ( void * ptr ) { std : : free ( ptr ) ; } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / MemoryPoolAllocator <nl> - <nl> - / / ! Default memory allocator used by the parser and DOM . <nl> - / * ! This allocator allocate memory blocks from pre - allocated memory chunks . <nl> - <nl> - It does not free memory blocks . And Realloc ( ) only allocate new memory . <nl> - <nl> - The memory chunks are allocated by BaseAllocator , which is CrtAllocator by default . <nl> - <nl> - User may also supply a buffer as the first chunk . <nl> - <nl> - If the user - buffer is full then additional chunks are allocated by BaseAllocator . <nl> - <nl> - The user - buffer is not deallocated by this allocator . <nl> - <nl> - \ tparam BaseAllocator the allocator type for allocating memory chunks . Default is CrtAllocator . <nl> - \ note implements Allocator concept <nl> - * / <nl> - template < typename BaseAllocator = CrtAllocator > <nl> - class MemoryPoolAllocator { <nl> - public : <nl> - static const bool kNeedFree = false ; / / ! < Tell users that no need to call Free ( ) with this allocator . ( concept Allocator ) <nl> - <nl> - / / ! Constructor with chunkSize . <nl> - / * ! \ param chunkSize The size of memory chunk . The default is kDefaultChunkSize . <nl> - \ param baseAllocator The allocator for allocating memory chunks . <nl> - * / <nl> - MemoryPoolAllocator ( size_t chunkSize = kDefaultChunkCapacity , BaseAllocator * baseAllocator = 0 ) : <nl> - chunkHead_ ( 0 ) , chunk_capacity_ ( chunkSize ) , userBuffer_ ( 0 ) , baseAllocator_ ( baseAllocator ) , ownBaseAllocator_ ( 0 ) <nl> - { <nl> - if ( ! baseAllocator_ ) <nl> - ownBaseAllocator_ = baseAllocator_ = new BaseAllocator ( ) ; <nl> - AddChunk ( chunk_capacity_ ) ; <nl> - } <nl> - <nl> - / / ! Constructor with user - supplied buffer . <nl> - / * ! The user buffer will be used firstly . When it is full , memory pool allocates new chunk with chunk size . <nl> - <nl> - The user buffer will not be deallocated when this allocator is destructed . <nl> - <nl> - \ param buffer User supplied buffer . <nl> - \ param size Size of the buffer in bytes . It must at least larger than sizeof ( ChunkHeader ) . <nl> - \ param chunkSize The size of memory chunk . The default is kDefaultChunkSize . <nl> - \ param baseAllocator The allocator for allocating memory chunks . <nl> - * / <nl> - MemoryPoolAllocator ( void * buffer , size_t size , size_t chunkSize = kDefaultChunkCapacity , BaseAllocator * baseAllocator = 0 ) : <nl> - chunkHead_ ( 0 ) , chunk_capacity_ ( chunkSize ) , userBuffer_ ( buffer ) , baseAllocator_ ( baseAllocator ) , ownBaseAllocator_ ( 0 ) <nl> - { <nl> - RAPIDJSON_ASSERT ( buffer ! = 0 ) ; <nl> - RAPIDJSON_ASSERT ( size > sizeof ( ChunkHeader ) ) ; <nl> - chunkHead_ = reinterpret_cast < ChunkHeader * > ( buffer ) ; <nl> - chunkHead_ - > capacity = size - sizeof ( ChunkHeader ) ; <nl> - chunkHead_ - > size = 0 ; <nl> - chunkHead_ - > next = 0 ; <nl> - } <nl> - <nl> - / / ! Destructor . <nl> - / * ! This deallocates all memory chunks , excluding the user - supplied buffer . <nl> - * / <nl> - ~ MemoryPoolAllocator ( ) { <nl> - Clear ( ) ; <nl> - delete ownBaseAllocator_ ; <nl> - } <nl> - <nl> - / / ! Deallocates all memory chunks , excluding the user - supplied buffer . <nl> - void Clear ( ) { <nl> - while ( chunkHead_ ! = 0 & & chunkHead_ ! = userBuffer_ ) { <nl> - ChunkHeader * next = chunkHead_ - > next ; <nl> - baseAllocator_ - > Free ( chunkHead_ ) ; <nl> - chunkHead_ = next ; <nl> - } <nl> - } <nl> - <nl> - / / ! Computes the total capacity of allocated memory chunks . <nl> - / * ! \ return total capacity in bytes . <nl> - * / <nl> - size_t Capacity ( ) const { <nl> - size_t capacity = 0 ; <nl> - for ( ChunkHeader * c = chunkHead_ ; c ! = 0 ; c = c - > next ) <nl> - capacity + = c - > capacity ; <nl> - return capacity ; <nl> - } <nl> - <nl> - / / ! Computes the memory blocks allocated . <nl> - / * ! \ return total used bytes . <nl> - * / <nl> - size_t Size ( ) const { <nl> - size_t size = 0 ; <nl> - for ( ChunkHeader * c = chunkHead_ ; c ! = 0 ; c = c - > next ) <nl> - size + = c - > size ; <nl> - return size ; <nl> - } <nl> - <nl> - / / ! Allocates a memory block . ( concept Allocator ) <nl> - void * Malloc ( size_t size ) { <nl> - size = RAPIDJSON_ALIGN ( size ) ; <nl> - if ( chunkHead_ = = 0 | | chunkHead_ - > size + size > chunkHead_ - > capacity ) <nl> - AddChunk ( chunk_capacity_ > size ? chunk_capacity_ : size ) ; <nl> - <nl> - void * buffer = reinterpret_cast < char * > ( chunkHead_ + 1 ) + chunkHead_ - > size ; <nl> - chunkHead_ - > size + = size ; <nl> - return buffer ; <nl> - } <nl> - <nl> - / / ! Resizes a memory block ( concept Allocator ) <nl> - void * Realloc ( void * originalPtr , size_t originalSize , size_t newSize ) { <nl> - if ( originalPtr = = 0 ) <nl> - return Malloc ( newSize ) ; <nl> - <nl> - / / Do not shrink if new size is smaller than original <nl> - if ( originalSize > = newSize ) <nl> - return originalPtr ; <nl> - <nl> - / / Simply expand it if it is the last allocation and there is sufficient space <nl> - if ( originalPtr = = ( char * ) ( chunkHead_ + 1 ) + chunkHead_ - > size - originalSize ) { <nl> - size_t increment = static_cast < size_t > ( newSize - originalSize ) ; <nl> - increment = RAPIDJSON_ALIGN ( increment ) ; <nl> - if ( chunkHead_ - > size + increment < = chunkHead_ - > capacity ) { <nl> - chunkHead_ - > size + = increment ; <nl> - return originalPtr ; <nl> - } <nl> - } <nl> - <nl> - / / Realloc process : allocate and copy memory , do not free original buffer . <nl> - void * newBuffer = Malloc ( newSize ) ; <nl> - RAPIDJSON_ASSERT ( newBuffer ! = 0 ) ; / / Do not handle out - of - memory explicitly . <nl> - return std : : memcpy ( newBuffer , originalPtr , originalSize ) ; <nl> - } <nl> - <nl> - / / ! Frees a memory block ( concept Allocator ) <nl> - static void Free ( void * ptr ) { ( void ) ptr ; } / / Do nothing <nl> - <nl> - private : <nl> - / / ! Copy constructor is not permitted . <nl> - MemoryPoolAllocator ( const MemoryPoolAllocator & rhs ) / * = delete * / ; <nl> - / / ! Copy assignment operator is not permitted . <nl> - MemoryPoolAllocator & operator = ( const MemoryPoolAllocator & rhs ) / * = delete * / ; <nl> - <nl> - / / ! Creates a new chunk . <nl> - / * ! \ param capacity Capacity of the chunk in bytes . <nl> - * / <nl> - void AddChunk ( size_t capacity ) { <nl> - ChunkHeader * chunk = reinterpret_cast < ChunkHeader * > ( baseAllocator_ - > Malloc ( sizeof ( ChunkHeader ) + capacity ) ) ; <nl> - chunk - > capacity = capacity ; <nl> - chunk - > size = 0 ; <nl> - chunk - > next = chunkHead_ ; <nl> - chunkHead_ = chunk ; <nl> - } <nl> - <nl> - static const int kDefaultChunkCapacity = 64 * 1024 ; / / ! < Default chunk capacity . <nl> - <nl> - / / ! Chunk header for perpending to each chunk . <nl> - / * ! Chunks are stored as a singly linked list . <nl> - * / <nl> - struct ChunkHeader { <nl> - size_t capacity ; / / ! < Capacity of the chunk in bytes ( excluding the header itself ) . <nl> - size_t size ; / / ! < Current size of allocated memory in bytes . <nl> - ChunkHeader * next ; / / ! < Next chunk in the linked list . <nl> - } ; <nl> - <nl> - ChunkHeader * chunkHead_ ; / / ! < Head of the chunk linked - list . Only the head chunk serves allocation . <nl> - size_t chunk_capacity_ ; / / ! < The minimum capacity of chunk when they are allocated . <nl> - void * userBuffer_ ; / / ! < User supplied buffer . <nl> - BaseAllocator * baseAllocator_ ; / / ! < base allocator for allocating memory chunks . <nl> - BaseAllocator * ownBaseAllocator_ ; / / ! < base allocator created by this object . <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_ENCODINGS_H_ <nl> deleted file mode 100644 <nl> index 0f7974738f6 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / document . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_DOCUMENT_H_ <nl> - # define RAPIDJSON_DOCUMENT_H_ <nl> - <nl> - / * ! \ file document . h * / <nl> - <nl> - # include " reader . h " <nl> - # include " internal / meta . h " <nl> - # include " internal / strfunc . h " <nl> - # include < new > / / placement new <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( 4127 ) / / conditional expression is constant <nl> - # elif defined ( __GNUC__ ) <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_HAS_STDSTRING <nl> - <nl> - # ifndef RAPIDJSON_HAS_STDSTRING <nl> - # ifdef RAPIDJSON_DOXYGEN_RUNNING <nl> - # define RAPIDJSON_HAS_STDSTRING 1 / / force generation of documentation <nl> - # else <nl> - # define RAPIDJSON_HAS_STDSTRING 0 / / no std : : string support by default <nl> - # endif <nl> - / * ! \ def RAPIDJSON_HAS_STDSTRING <nl> - \ ingroup RAPIDJSON_CONFIG <nl> - \ brief Enable RapidJSON support for \ c std : : string <nl> - <nl> - By defining this preprocessor symbol to \ c 1 , several convenience functions for using <nl> - \ ref rapidjson : : GenericValue with \ c std : : string are enabled , especially <nl> - for construction and comparison . <nl> - <nl> - \ hideinitializer <nl> - * / <nl> - # include < string > <nl> - # endif / / RAPIDJSON_HAS_STDSTRING <nl> - <nl> - # ifndef RAPIDJSON_NOMEMBERITERATORCLASS <nl> - # include < iterator > / / std : : iterator , std : : random_access_iterator_tag <nl> - # endif <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - # include < utility > / / std : : move <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / Forward declaration . <nl> - template < typename Encoding , typename Allocator > <nl> - class GenericValue ; <nl> - <nl> - / / ! Name - value pair in a JSON object value . <nl> - / * ! <nl> - This class was internal to GenericValue . It used to be a inner struct . <nl> - But a compiler ( IBM XL C / C + + for AIX ) have reported to have problem with that so it moved as a namespace scope struct . <nl> - https : / / code . google . com / p / rapidjson / issues / detail ? id = 64 <nl> - * / <nl> - template < typename Encoding , typename Allocator > <nl> - struct GenericMember { <nl> - GenericValue < Encoding , Allocator > name ; / / ! < name of member ( must be a string ) <nl> - GenericValue < Encoding , Allocator > value ; / / ! < value of member . <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericMemberIterator <nl> - <nl> - # ifndef RAPIDJSON_NOMEMBERITERATORCLASS <nl> - <nl> - / / ! ( Constant ) member iterator for a JSON object value <nl> - / * ! <nl> - \ tparam Const Is this a constant iterator ? <nl> - \ tparam Encoding Encoding of the value . ( Even non - string values need to have the same encoding in a document ) <nl> - \ tparam Allocator Allocator type for allocating memory of object , array and string . <nl> - <nl> - This class implements a Random Access Iterator for GenericMember elements <nl> - of a GenericValue , see ISO / IEC 14882 : 2003 ( E ) C + + standard , 24 . 1 [ lib . iterator . requirements ] . <nl> - <nl> - \ note This iterator implementation is mainly intended to avoid implicit <nl> - conversions from iterator values to \ c NULL , <nl> - e . g . from GenericValue : : FindMember . <nl> - <nl> - \ note Define \ c RAPIDJSON_NOMEMBERITERATORCLASS to fall back to a <nl> - pointer - based implementation , if your platform doesn ' t provide <nl> - the C + + < iterator > header . <nl> - <nl> - \ see GenericMember , GenericValue : : MemberIterator , GenericValue : : ConstMemberIterator <nl> - * / <nl> - template < bool Const , typename Encoding , typename Allocator > <nl> - class GenericMemberIterator <nl> - : public std : : iterator < std : : random_access_iterator_tag <nl> - , typename internal : : MaybeAddConst < Const , GenericMember < Encoding , Allocator > > : : Type > { <nl> - <nl> - friend class GenericValue < Encoding , Allocator > ; <nl> - template < bool , typename , typename > friend class GenericMemberIterator ; <nl> - <nl> - typedef GenericMember < Encoding , Allocator > PlainType ; <nl> - typedef typename internal : : MaybeAddConst < Const , PlainType > : : Type ValueType ; <nl> - typedef std : : iterator < std : : random_access_iterator_tag , ValueType > BaseType ; <nl> - <nl> - public : <nl> - / / ! Iterator type itself <nl> - typedef GenericMemberIterator Iterator ; <nl> - / / ! Constant iterator type <nl> - typedef GenericMemberIterator < true , Encoding , Allocator > ConstIterator ; <nl> - / / ! Non - constant iterator type <nl> - typedef GenericMemberIterator < false , Encoding , Allocator > NonConstIterator ; <nl> - <nl> - / / ! Pointer to ( const ) GenericMember <nl> - typedef typename BaseType : : pointer Pointer ; <nl> - / / ! Reference to ( const ) GenericMember <nl> - typedef typename BaseType : : reference Reference ; <nl> - / / ! Signed integer type ( e . g . \ c ptrdiff_t ) <nl> - typedef typename BaseType : : difference_type DifferenceType ; <nl> - <nl> - / / ! Default constructor ( singular value ) <nl> - / * ! Creates an iterator pointing to no element . <nl> - \ note All operations , except for comparisons , are undefined on such values . <nl> - * / <nl> - GenericMemberIterator ( ) : ptr_ ( ) { } <nl> - <nl> - / / ! Iterator conversions to more const <nl> - / * ! <nl> - \ param it ( Non - const ) iterator to copy from <nl> - <nl> - Allows the creation of an iterator from another GenericMemberIterator <nl> - that is " less const " . Especially , creating a non - constant iterator <nl> - from a constant iterator are disabled : <nl> - \ li const - > non - const ( not ok ) <nl> - \ li const - > const ( ok ) <nl> - \ li non - const - > const ( ok ) <nl> - \ li non - const - > non - const ( ok ) <nl> - <nl> - \ note If the \ c Const template parameter is already \ c false , this <nl> - constructor effectively defines a regular copy - constructor . <nl> - Otherwise , the copy constructor is implicitly defined . <nl> - * / <nl> - GenericMemberIterator ( const NonConstIterator & it ) : ptr_ ( it . ptr_ ) { } <nl> - <nl> - / / ! @ name stepping <nl> - / / @ { <nl> - Iterator & operator + + ( ) { + + ptr_ ; return * this ; } <nl> - Iterator & operator - - ( ) { - - ptr_ ; return * this ; } <nl> - Iterator operator + + ( int ) { Iterator old ( * this ) ; + + ptr_ ; return old ; } <nl> - Iterator operator - - ( int ) { Iterator old ( * this ) ; - - ptr_ ; return old ; } <nl> - / / @ } <nl> - <nl> - / / ! @ name increment / decrement <nl> - / / @ { <nl> - Iterator operator + ( DifferenceType n ) const { return Iterator ( ptr_ + n ) ; } <nl> - Iterator operator - ( DifferenceType n ) const { return Iterator ( ptr_ - n ) ; } <nl> - <nl> - Iterator & operator + = ( DifferenceType n ) { ptr_ + = n ; return * this ; } <nl> - Iterator & operator - = ( DifferenceType n ) { ptr_ - = n ; return * this ; } <nl> - / / @ } <nl> - <nl> - / / ! @ name relations <nl> - / / @ { <nl> - bool operator = = ( ConstIterator that ) const { return ptr_ = = that . ptr_ ; } <nl> - bool operator ! = ( ConstIterator that ) const { return ptr_ ! = that . ptr_ ; } <nl> - bool operator < = ( ConstIterator that ) const { return ptr_ < = that . ptr_ ; } <nl> - bool operator > = ( ConstIterator that ) const { return ptr_ > = that . ptr_ ; } <nl> - bool operator < ( ConstIterator that ) const { return ptr_ < that . ptr_ ; } <nl> - bool operator > ( ConstIterator that ) const { return ptr_ > that . ptr_ ; } <nl> - / / @ } <nl> - <nl> - / / ! @ name dereference <nl> - / / @ { <nl> - Reference operator * ( ) const { return * ptr_ ; } <nl> - Pointer operator - > ( ) const { return ptr_ ; } <nl> - Reference operator [ ] ( DifferenceType n ) const { return ptr_ [ n ] ; } <nl> - / / @ } <nl> - <nl> - / / ! Distance <nl> - DifferenceType operator - ( ConstIterator that ) const { return ptr_ - that . ptr_ ; } <nl> - <nl> - private : <nl> - / / ! Internal constructor from plain pointer <nl> - explicit GenericMemberIterator ( Pointer p ) : ptr_ ( p ) { } <nl> - <nl> - Pointer ptr_ ; / / ! < raw pointer <nl> - } ; <nl> - <nl> - # else / / RAPIDJSON_NOMEMBERITERATORCLASS <nl> - <nl> - / / class - based member iterator implementation disabled , use plain pointers <nl> - <nl> - template < bool Const , typename Encoding , typename Allocator > <nl> - struct GenericMemberIterator ; <nl> - <nl> - / / ! non - const GenericMemberIterator <nl> - template < typename Encoding , typename Allocator > <nl> - struct GenericMemberIterator < false , Encoding , Allocator > { <nl> - / / ! use plain pointer as iterator type <nl> - typedef GenericMember < Encoding , Allocator > * Iterator ; <nl> - } ; <nl> - / / ! const GenericMemberIterator <nl> - template < typename Encoding , typename Allocator > <nl> - struct GenericMemberIterator < true , Encoding , Allocator > { <nl> - / / ! use plain const pointer as iterator type <nl> - typedef const GenericMember < Encoding , Allocator > * Iterator ; <nl> - } ; <nl> - <nl> - # endif / / RAPIDJSON_NOMEMBERITERATORCLASS <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericStringRef <nl> - <nl> - / / ! Reference to a constant string ( not taking a copy ) <nl> - / * ! <nl> - \ tparam CharType character type of the string <nl> - <nl> - This helper class is used to automatically infer constant string <nl> - references for string literals , especially from \ c const \ b ( ! ) <nl> - character arrays . <nl> - <nl> - The main use is for creating JSON string values without copying the <nl> - source string via an \ ref Allocator . This requires that the referenced <nl> - string pointers have a sufficient lifetime , which exceeds the lifetime <nl> - of the associated GenericValue . <nl> - <nl> - \ b Example <nl> - \ code <nl> - Value v ( " foo " ) ; / / ok , no need to copy & calculate length <nl> - const char foo [ ] = " foo " ; <nl> - v . SetString ( foo ) ; / / ok <nl> - <nl> - const char * bar = foo ; <nl> - / / Value x ( bar ) ; / / not ok , can ' t rely on bar ' s lifetime <nl> - Value x ( StringRef ( bar ) ) ; / / lifetime explicitly guaranteed by user <nl> - Value y ( StringRef ( bar , 3 ) ) ; / / ok , explicitly pass length <nl> - \ endcode <nl> - <nl> - \ see StringRef , GenericValue : : SetString <nl> - * / <nl> - template < typename CharType > <nl> - struct GenericStringRef { <nl> - typedef CharType Ch ; / / ! < character type of the string <nl> - <nl> - / / ! Create string reference from \ c const character array <nl> - / * ! <nl> - This constructor implicitly creates a constant string reference from <nl> - a \ c const character array . It has better performance than <nl> - \ ref StringRef ( const CharType * ) by inferring the string \ ref length <nl> - from the array length , and also supports strings containing null <nl> - characters . <nl> - <nl> - \ tparam N length of the string , automatically inferred <nl> - <nl> - \ param str Constant character array , lifetime assumed to be longer <nl> - than the use of the string in e . g . a GenericValue <nl> - <nl> - \ post \ ref s = = str <nl> - <nl> - \ note Constant complexity . <nl> - \ note There is a hidden , private overload to disallow references to <nl> - non - const character arrays to be created via this constructor . <nl> - By this , e . g . function - scope arrays used to be filled via <nl> - \ c snprintf are excluded from consideration . <nl> - In such cases , the referenced string should be \ b copied to the <nl> - GenericValue instead . <nl> - * / <nl> - template < SizeType N > <nl> - GenericStringRef ( const CharType ( & str ) [ N ] ) RAPIDJSON_NOEXCEPT <nl> - : s ( str ) , length ( N - 1 ) { } <nl> - <nl> - / / ! Explicitly create string reference from \ c const character pointer <nl> - / * ! <nl> - This constructor can be used to \ b explicitly create a reference to <nl> - a constant string pointer . <nl> - <nl> - \ see StringRef ( const CharType * ) <nl> - <nl> - \ param str Constant character pointer , lifetime assumed to be longer <nl> - than the use of the string in e . g . a GenericValue <nl> - <nl> - \ post \ ref s = = str <nl> - <nl> - \ note There is a hidden , private overload to disallow references to <nl> - non - const character arrays to be created via this constructor . <nl> - By this , e . g . function - scope arrays used to be filled via <nl> - \ c snprintf are excluded from consideration . <nl> - In such cases , the referenced string should be \ b copied to the <nl> - GenericValue instead . <nl> - * / <nl> - explicit GenericStringRef ( const CharType * str ) <nl> - : s ( str ) , length ( internal : : StrLen ( str ) ) { RAPIDJSON_ASSERT ( s ! = NULL ) ; } <nl> - <nl> - / / ! Create constant string reference from pointer and length <nl> - / * ! \ param str constant string , lifetime assumed to be longer than the use of the string in e . g . a GenericValue <nl> - \ param len length of the string , excluding the trailing NULL terminator <nl> - <nl> - \ post \ ref s = = str & & \ ref length = = len <nl> - \ note Constant complexity . <nl> - * / <nl> - GenericStringRef ( const CharType * str , SizeType len ) <nl> - : s ( str ) , length ( len ) { RAPIDJSON_ASSERT ( s ! = NULL ) ; } <nl> - <nl> - / / ! implicit conversion to plain CharType pointer <nl> - operator const Ch * ( ) const { return s ; } <nl> - <nl> - const Ch * const s ; / / ! < plain CharType pointer <nl> - const SizeType length ; / / ! < length of the string ( excluding the trailing NULL terminator ) <nl> - <nl> - private : <nl> - / / ! Disallow copy - assignment <nl> - GenericStringRef operator = ( const GenericStringRef & ) ; <nl> - / / ! Disallow construction from non - const array <nl> - template < SizeType N > <nl> - GenericStringRef ( CharType ( & str ) [ N ] ) / * = delete * / ; <nl> - } ; <nl> - <nl> - / / ! Mark a character pointer as constant string <nl> - / * ! Mark a plain character pointer as a " string literal " . This function <nl> - can be used to avoid copying a character string to be referenced as a <nl> - value in a JSON GenericValue object , if the string ' s lifetime is known <nl> - to be valid long enough . <nl> - \ tparam CharType Character type of the string <nl> - \ param str Constant string , lifetime assumed to be longer than the use of the string in e . g . a GenericValue <nl> - \ return GenericStringRef string reference object <nl> - \ relatesalso GenericStringRef <nl> - <nl> - \ see GenericValue : : GenericValue ( StringRefType ) , GenericValue : : operator = ( StringRefType ) , GenericValue : : SetString ( StringRefType ) , GenericValue : : PushBack ( StringRefType , Allocator & ) , GenericValue : : AddMember <nl> - * / <nl> - template < typename CharType > <nl> - inline GenericStringRef < CharType > StringRef ( const CharType * str ) { <nl> - return GenericStringRef < CharType > ( str , internal : : StrLen ( str ) ) ; <nl> - } <nl> - <nl> - / / ! Mark a character pointer as constant string <nl> - / * ! Mark a plain character pointer as a " string literal " . This function <nl> - can be used to avoid copying a character string to be referenced as a <nl> - value in a JSON GenericValue object , if the string ' s lifetime is known <nl> - to be valid long enough . <nl> - <nl> - This version has better performance with supplied length , and also <nl> - supports string containing null characters . <nl> - <nl> - \ tparam CharType character type of the string <nl> - \ param str Constant string , lifetime assumed to be longer than the use of the string in e . g . a GenericValue <nl> - \ param length The length of source string . <nl> - \ return GenericStringRef string reference object <nl> - \ relatesalso GenericStringRef <nl> - * / <nl> - template < typename CharType > <nl> - inline GenericStringRef < CharType > StringRef ( const CharType * str , size_t length ) { <nl> - return GenericStringRef < CharType > ( str , SizeType ( length ) ) ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_STDSTRING <nl> - / / ! Mark a string object as constant string <nl> - / * ! Mark a string object ( e . g . \ c std : : string ) as a " string literal " . <nl> - This function can be used to avoid copying a string to be referenced as a <nl> - value in a JSON GenericValue object , if the string ' s lifetime is known <nl> - to be valid long enough . <nl> - <nl> - \ tparam CharType character type of the string <nl> - \ param str Constant string , lifetime assumed to be longer than the use of the string in e . g . a GenericValue <nl> - \ return GenericStringRef string reference object <nl> - \ relatesalso GenericStringRef <nl> - \ note Requires the definition of the preprocessor symbol \ ref RAPIDJSON_HAS_STDSTRING . <nl> - * / <nl> - template < typename CharType > <nl> - inline GenericStringRef < CharType > StringRef ( const std : : basic_string < CharType > & str ) { <nl> - return GenericStringRef < CharType > ( str . data ( ) , SizeType ( str . size ( ) ) ) ; <nl> - } <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericValue type traits <nl> - namespace internal { <nl> - <nl> - template < typename T , typename Encoding = void , typename Allocator = void > <nl> - struct IsGenericValueImpl : FalseType { } ; <nl> - <nl> - / / select candidates according to nested encoding and allocator types <nl> - template < typename T > struct IsGenericValueImpl < T , typename Void < typename T : : EncodingType > : : Type , typename Void < typename T : : AllocatorType > : : Type > <nl> - : IsBaseOf < GenericValue < typename T : : EncodingType , typename T : : AllocatorType > , T > : : Type { } ; <nl> - <nl> - / / helper to match arbitrary GenericValue instantiations , including derived classes <nl> - template < typename T > struct IsGenericValue : IsGenericValueImpl < T > : : Type { } ; <nl> - <nl> - } / / namespace internal <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericValue <nl> - <nl> - / / ! Represents a JSON value . Use Value for UTF8 encoding and default allocator . <nl> - / * ! <nl> - A JSON value can be one of 7 types . This class is a variant type supporting <nl> - these types . <nl> - <nl> - Use the Value if UTF8 and default allocator <nl> - <nl> - \ tparam Encoding Encoding of the value . ( Even non - string values need to have the same encoding in a document ) <nl> - \ tparam Allocator Allocator type for allocating memory of object , array and string . <nl> - * / <nl> - template < typename Encoding , typename Allocator = MemoryPoolAllocator < > > <nl> - class GenericValue { <nl> - public : <nl> - / / ! Name - value pair in an object . <nl> - typedef GenericMember < Encoding , Allocator > Member ; <nl> - typedef Encoding EncodingType ; / / ! < Encoding type from template parameter . <nl> - typedef Allocator AllocatorType ; / / ! < Allocator type from template parameter . <nl> - typedef typename Encoding : : Ch Ch ; / / ! < Character type derived from Encoding . <nl> - typedef GenericStringRef < Ch > StringRefType ; / / ! < Reference to a constant string <nl> - typedef typename GenericMemberIterator < false , Encoding , Allocator > : : Iterator MemberIterator ; / / ! < Member iterator for iterating in object . <nl> - typedef typename GenericMemberIterator < true , Encoding , Allocator > : : Iterator ConstMemberIterator ; / / ! < Constant member iterator for iterating in object . <nl> - typedef GenericValue * ValueIterator ; / / ! < Value iterator for iterating in array . <nl> - typedef const GenericValue * ConstValueIterator ; / / ! < Constant value iterator for iterating in array . <nl> - <nl> - / / ! @ name Constructors and destructor . <nl> - / / @ { <nl> - <nl> - / / ! Default constructor creates a null value . <nl> - GenericValue ( ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNullFlag ) { } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - / / ! Move constructor in C + + 11 <nl> - GenericValue ( GenericValue & & rhs ) RAPIDJSON_NOEXCEPT : data_ ( rhs . data_ ) , flags_ ( rhs . flags_ ) { <nl> - rhs . flags_ = kNullFlag ; / / give up contents <nl> - } <nl> - # endif <nl> - <nl> - private : <nl> - / / ! Copy constructor is not permitted . <nl> - GenericValue ( const GenericValue & rhs ) ; <nl> - <nl> - public : <nl> - <nl> - / / ! Constructor with JSON value type . <nl> - / * ! This creates a Value of specified type with default content . <nl> - \ param type Type of the value . <nl> - \ note Default content for number is zero . <nl> - * / <nl> - explicit GenericValue ( Type type ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( ) { <nl> - static const unsigned defaultFlags [ 7 ] = { <nl> - kNullFlag , kFalseFlag , kTrueFlag , kObjectFlag , kArrayFlag , kConstStringFlag , <nl> - kNumberAnyFlag <nl> - } ; <nl> - RAPIDJSON_ASSERT ( type < = kNumberType ) ; <nl> - flags_ = defaultFlags [ type ] ; <nl> - } <nl> - <nl> - / / ! Explicit copy constructor ( with allocator ) <nl> - / * ! Creates a copy of a Value by using the given Allocator <nl> - \ tparam SourceAllocator allocator of \ c rhs <nl> - \ param rhs Value to copy from ( read - only ) <nl> - \ param allocator Allocator for allocating copied elements and buffers . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ see CopyFrom ( ) <nl> - * / <nl> - template < typename SourceAllocator > <nl> - GenericValue ( const GenericValue < Encoding , SourceAllocator > & rhs , Allocator & allocator ) ; <nl> - <nl> - / / ! Constructor for boolean value . <nl> - / * ! \ param b Boolean value <nl> - \ note This constructor is limited to \ em real boolean values and rejects <nl> - implicitly converted types like arbitrary pointers . Use an explicit cast <nl> - to \ c bool , if you want to construct a boolean JSON value in such cases . <nl> - * / <nl> - # ifndef RAPIDJSON_DOXYGEN_RUNNING / / hide SFINAE from Doxygen <nl> - template < typename T > <nl> - explicit GenericValue ( T b , RAPIDJSON_ENABLEIF ( ( internal : : IsSame < T , bool > ) ) ) RAPIDJSON_NOEXCEPT <nl> - # else <nl> - explicit GenericValue ( bool b ) RAPIDJSON_NOEXCEPT <nl> - # endif <nl> - : data_ ( ) , flags_ ( b ? kTrueFlag : kFalseFlag ) { <nl> - / / safe - guard against failing SFINAE <nl> - RAPIDJSON_STATIC_ASSERT ( ( internal : : IsSame < bool , T > : : Value ) ) ; <nl> - } <nl> - <nl> - / / ! Constructor for int value . <nl> - explicit GenericValue ( int i ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNumberIntFlag ) { <nl> - data_ . n . i64 = i ; <nl> - if ( i > = 0 ) <nl> - flags_ | = kUintFlag | kUint64Flag ; <nl> - } <nl> - <nl> - / / ! Constructor for unsigned value . <nl> - explicit GenericValue ( unsigned u ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNumberUintFlag ) { <nl> - data_ . n . u64 = u ; <nl> - if ( ! ( u & 0x80000000 ) ) <nl> - flags_ | = kIntFlag | kInt64Flag ; <nl> - } <nl> - <nl> - / / ! Constructor for int64_t value . <nl> - explicit GenericValue ( int64_t i64 ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNumberInt64Flag ) { <nl> - data_ . n . i64 = i64 ; <nl> - if ( i64 > = 0 ) { <nl> - flags_ | = kNumberUint64Flag ; <nl> - if ( ! ( static_cast < uint64_t > ( i64 ) & RAPIDJSON_UINT64_C2 ( 0xFFFFFFFF , 0x00000000 ) ) ) <nl> - flags_ | = kUintFlag ; <nl> - if ( ! ( static_cast < uint64_t > ( i64 ) & RAPIDJSON_UINT64_C2 ( 0xFFFFFFFF , 0x80000000 ) ) ) <nl> - flags_ | = kIntFlag ; <nl> - } <nl> - else if ( i64 > = static_cast < int64_t > ( RAPIDJSON_UINT64_C2 ( 0xFFFFFFFF , 0x80000000 ) ) ) <nl> - flags_ | = kIntFlag ; <nl> - } <nl> - <nl> - / / ! Constructor for uint64_t value . <nl> - explicit GenericValue ( uint64_t u64 ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNumberUint64Flag ) { <nl> - data_ . n . u64 = u64 ; <nl> - if ( ! ( u64 & RAPIDJSON_UINT64_C2 ( 0x80000000 , 0x00000000 ) ) ) <nl> - flags_ | = kInt64Flag ; <nl> - if ( ! ( u64 & RAPIDJSON_UINT64_C2 ( 0xFFFFFFFF , 0x00000000 ) ) ) <nl> - flags_ | = kUintFlag ; <nl> - if ( ! ( u64 & RAPIDJSON_UINT64_C2 ( 0xFFFFFFFF , 0x80000000 ) ) ) <nl> - flags_ | = kIntFlag ; <nl> - } <nl> - <nl> - / / ! Constructor for double value . <nl> - explicit GenericValue ( double d ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( kNumberDoubleFlag ) { data_ . n . d = d ; } <nl> - <nl> - / / ! Constructor for constant string ( i . e . do not make a copy of string ) <nl> - GenericValue ( const Ch * s , SizeType length ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( ) { SetStringRaw ( StringRef ( s , length ) ) ; } <nl> - <nl> - / / ! Constructor for constant string ( i . e . do not make a copy of string ) <nl> - explicit GenericValue ( StringRefType s ) RAPIDJSON_NOEXCEPT : data_ ( ) , flags_ ( ) { SetStringRaw ( s ) ; } <nl> - <nl> - / / ! Constructor for copy - string ( i . e . do make a copy of string ) <nl> - GenericValue ( const Ch * s , SizeType length , Allocator & allocator ) : data_ ( ) , flags_ ( ) { SetStringRaw ( StringRef ( s , length ) , allocator ) ; } <nl> - <nl> - / / ! Constructor for copy - string ( i . e . do make a copy of string ) <nl> - GenericValue ( const Ch * s , Allocator & allocator ) : data_ ( ) , flags_ ( ) { SetStringRaw ( StringRef ( s ) , allocator ) ; } <nl> - <nl> - # if RAPIDJSON_HAS_STDSTRING <nl> - / / ! Constructor for copy - string from a string object ( i . e . do make a copy of string ) <nl> - / * ! \ note Requires the definition of the preprocessor symbol \ ref RAPIDJSON_HAS_STDSTRING . <nl> - * / <nl> - GenericValue ( const std : : basic_string < Ch > & s , Allocator & allocator ) : data_ ( ) , flags_ ( ) { SetStringRaw ( StringRef ( s ) , allocator ) ; } <nl> - # endif <nl> - <nl> - / / ! Destructor . <nl> - / * ! Need to destruct elements of array , members of object , or copy - string . <nl> - * / <nl> - ~ GenericValue ( ) { <nl> - if ( Allocator : : kNeedFree ) { / / Shortcut by Allocator ' s trait <nl> - switch ( flags_ ) { <nl> - case kArrayFlag : <nl> - for ( GenericValue * v = data_ . a . elements ; v ! = data_ . a . elements + data_ . a . size ; + + v ) <nl> - v - > ~ GenericValue ( ) ; <nl> - Allocator : : Free ( data_ . a . elements ) ; <nl> - break ; <nl> - <nl> - case kObjectFlag : <nl> - for ( MemberIterator m = MemberBegin ( ) ; m ! = MemberEnd ( ) ; + + m ) <nl> - m - > ~ Member ( ) ; <nl> - Allocator : : Free ( data_ . o . members ) ; <nl> - break ; <nl> - <nl> - case kCopyStringFlag : <nl> - Allocator : : Free ( const_cast < Ch * > ( data_ . s . str ) ) ; <nl> - break ; <nl> - <nl> - default : <nl> - break ; / / Do nothing for other types . <nl> - } <nl> - } <nl> - } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Assignment operators <nl> - / / @ { <nl> - <nl> - / / ! Assignment with move semantics . <nl> - / * ! \ param rhs Source of the assignment . It will become a null value after assignment . <nl> - * / <nl> - GenericValue & operator = ( GenericValue & rhs ) RAPIDJSON_NOEXCEPT { <nl> - RAPIDJSON_ASSERT ( this ! = & rhs ) ; <nl> - this - > ~ GenericValue ( ) ; <nl> - RawAssign ( rhs ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - / / ! Move assignment in C + + 11 <nl> - GenericValue & operator = ( GenericValue & & rhs ) RAPIDJSON_NOEXCEPT { <nl> - return * this = rhs . Move ( ) ; <nl> - } <nl> - # endif <nl> - <nl> - / / ! Assignment of constant string reference ( no copy ) <nl> - / * ! \ param str Constant string reference to be assigned <nl> - \ note This overload is needed to avoid clashes with the generic primitive type assignment overload below . <nl> - \ see GenericStringRef , operator = ( T ) <nl> - * / <nl> - GenericValue & operator = ( StringRefType str ) RAPIDJSON_NOEXCEPT { <nl> - GenericValue s ( str ) ; <nl> - return * this = s ; <nl> - } <nl> - <nl> - / / ! Assignment with primitive types . <nl> - / * ! \ tparam T Either \ ref Type , \ c int , \ c unsigned , \ c int64_t , \ c uint64_t <nl> - \ param value The value to be assigned . <nl> - <nl> - \ note The source type \ c T explicitly disallows all pointer types , <nl> - especially ( \ c const ) \ ref Ch * . This helps avoiding implicitly <nl> - referencing character strings with insufficient lifetime , use <nl> - \ ref SetString ( const Ch * , Allocator & ) ( for copying ) or <nl> - \ ref StringRef ( ) ( to explicitly mark the pointer as constant ) instead . <nl> - All other pointer types would implicitly convert to \ c bool , <nl> - use \ ref SetBool ( ) instead . <nl> - * / <nl> - template < typename T > <nl> - RAPIDJSON_DISABLEIF_RETURN ( ( internal : : IsPointer < T > ) , ( GenericValue & ) ) <nl> - operator = ( T value ) { <nl> - GenericValue v ( value ) ; <nl> - return * this = v ; <nl> - } <nl> - <nl> - / / ! Deep - copy assignment from Value <nl> - / * ! Assigns a \ b copy of the Value to the current Value object <nl> - \ tparam SourceAllocator Allocator type of \ c rhs <nl> - \ param rhs Value to copy from ( read - only ) <nl> - \ param allocator Allocator to use for copying <nl> - * / <nl> - template < typename SourceAllocator > <nl> - GenericValue & CopyFrom ( const GenericValue < Encoding , SourceAllocator > & rhs , Allocator & allocator ) { <nl> - RAPIDJSON_ASSERT ( ( void * ) this ! = ( void const * ) & rhs ) ; <nl> - this - > ~ GenericValue ( ) ; <nl> - new ( this ) GenericValue ( rhs , allocator ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - / / ! Exchange the contents of this value with those of other . <nl> - / * ! <nl> - \ param other Another value . <nl> - \ note Constant complexity . <nl> - * / <nl> - GenericValue & Swap ( GenericValue & other ) RAPIDJSON_NOEXCEPT { <nl> - GenericValue temp ; <nl> - temp . RawAssign ( * this ) ; <nl> - RawAssign ( other ) ; <nl> - other . RawAssign ( temp ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - / / ! Prepare Value for move semantics <nl> - / * ! \ return * this * / <nl> - GenericValue & Move ( ) RAPIDJSON_NOEXCEPT { return * this ; } <nl> - / / @ } <nl> - <nl> - / / ! @ name Equal - to and not - equal - to operators <nl> - / / @ { <nl> - / / ! Equal - to operator <nl> - / * ! <nl> - \ note If an object contains duplicated named member , comparing equality with any object is always \ c false . <nl> - \ note Linear time complexity ( number of all values in the subtree and total lengths of all strings ) . <nl> - * / <nl> - template < typename SourceAllocator > <nl> - bool operator = = ( const GenericValue < Encoding , SourceAllocator > & rhs ) const { <nl> - typedef GenericValue < Encoding , SourceAllocator > RhsType ; <nl> - if ( GetType ( ) ! = rhs . GetType ( ) ) <nl> - return false ; <nl> - <nl> - switch ( GetType ( ) ) { <nl> - case kObjectType : / / Warning : O ( n ^ 2 ) inner - loop <nl> - if ( data_ . o . size ! = rhs . data_ . o . size ) <nl> - return false ; <nl> - for ( ConstMemberIterator lhsMemberItr = MemberBegin ( ) ; lhsMemberItr ! = MemberEnd ( ) ; + + lhsMemberItr ) { <nl> - typename RhsType : : ConstMemberIterator rhsMemberItr = rhs . FindMember ( lhsMemberItr - > name ) ; <nl> - if ( rhsMemberItr = = rhs . MemberEnd ( ) | | lhsMemberItr - > value ! = rhsMemberItr - > value ) <nl> - return false ; <nl> - } <nl> - return true ; <nl> - <nl> - case kArrayType : <nl> - if ( data_ . a . size ! = rhs . data_ . a . size ) <nl> - return false ; <nl> - for ( SizeType i = 0 ; i < data_ . a . size ; i + + ) <nl> - if ( ( * this ) [ i ] ! = rhs [ i ] ) <nl> - return false ; <nl> - return true ; <nl> - <nl> - case kStringType : <nl> - return StringEqual ( rhs ) ; <nl> - <nl> - case kNumberType : <nl> - if ( IsDouble ( ) | | rhs . IsDouble ( ) ) <nl> - return GetDouble ( ) = = rhs . GetDouble ( ) ; / / May convert one operand from integer to double . <nl> - else <nl> - return data_ . n . u64 = = rhs . data_ . n . u64 ; <nl> - <nl> - default : / / kTrueType , kFalseType , kNullType <nl> - return true ; <nl> - } <nl> - } <nl> - <nl> - / / ! Equal - to operator with const C - string pointer <nl> - bool operator = = ( const Ch * rhs ) const { return * this = = GenericValue ( StringRef ( rhs ) ) ; } <nl> - <nl> - # if RAPIDJSON_HAS_STDSTRING <nl> - / / ! Equal - to operator with string object <nl> - / * ! \ note Requires the definition of the preprocessor symbol \ ref RAPIDJSON_HAS_STDSTRING . <nl> - * / <nl> - bool operator = = ( const std : : basic_string < Ch > & rhs ) const { return * this = = GenericValue ( StringRef ( rhs ) ) ; } <nl> - # endif <nl> - <nl> - / / ! Equal - to operator with primitive types <nl> - / * ! \ tparam T Either \ ref Type , \ c int , \ c unsigned , \ c int64_t , \ c uint64_t , \ c double , \ c true , \ c false <nl> - * / <nl> - template < typename T > RAPIDJSON_DISABLEIF_RETURN ( ( internal : : OrExpr < internal : : IsPointer < T > , internal : : IsGenericValue < T > > ) , ( bool ) ) operator = = ( const T & rhs ) const { return * this = = GenericValue ( rhs ) ; } <nl> - <nl> - / / ! Not - equal - to operator <nl> - / * ! \ return ! ( * this = = rhs ) <nl> - * / <nl> - template < typename SourceAllocator > <nl> - bool operator ! = ( const GenericValue < Encoding , SourceAllocator > & rhs ) const { return ! ( * this = = rhs ) ; } <nl> - <nl> - / / ! Not - equal - to operator with const C - string pointer <nl> - bool operator ! = ( const Ch * rhs ) const { return ! ( * this = = rhs ) ; } <nl> - <nl> - / / ! Not - equal - to operator with arbitrary types <nl> - / * ! \ return ! ( * this = = rhs ) <nl> - * / <nl> - template < typename T > RAPIDJSON_DISABLEIF_RETURN ( ( internal : : IsGenericValue < T > ) , ( bool ) ) operator ! = ( const T & rhs ) const { return ! ( * this = = rhs ) ; } <nl> - <nl> - / / ! Equal - to operator with arbitrary types ( symmetric version ) <nl> - / * ! \ return ( rhs = = lhs ) <nl> - * / <nl> - template < typename T > friend RAPIDJSON_DISABLEIF_RETURN ( ( internal : : IsGenericValue < T > ) , ( bool ) ) operator = = ( const T & lhs , const GenericValue & rhs ) { return rhs = = lhs ; } <nl> - <nl> - / / ! Not - Equal - to operator with arbitrary types ( symmetric version ) <nl> - / * ! \ return ! ( rhs = = lhs ) <nl> - * / <nl> - template < typename T > friend RAPIDJSON_DISABLEIF_RETURN ( ( internal : : IsGenericValue < T > ) , ( bool ) ) operator ! = ( const T & lhs , const GenericValue & rhs ) { return ! ( rhs = = lhs ) ; } <nl> - / / @ } <nl> - <nl> - / / ! @ name Type <nl> - / / @ { <nl> - <nl> - Type GetType ( ) const { return static_cast < Type > ( flags_ & kTypeMask ) ; } <nl> - bool IsNull ( ) const { return flags_ = = kNullFlag ; } <nl> - bool IsFalse ( ) const { return flags_ = = kFalseFlag ; } <nl> - bool IsTrue ( ) const { return flags_ = = kTrueFlag ; } <nl> - bool IsBool ( ) const { return ( flags_ & kBoolFlag ) ! = 0 ; } <nl> - bool IsObject ( ) const { return flags_ = = kObjectFlag ; } <nl> - bool IsArray ( ) const { return flags_ = = kArrayFlag ; } <nl> - bool IsNumber ( ) const { return ( flags_ & kNumberFlag ) ! = 0 ; } <nl> - bool IsInt ( ) const { return ( flags_ & kIntFlag ) ! = 0 ; } <nl> - bool IsUint ( ) const { return ( flags_ & kUintFlag ) ! = 0 ; } <nl> - bool IsInt64 ( ) const { return ( flags_ & kInt64Flag ) ! = 0 ; } <nl> - bool IsUint64 ( ) const { return ( flags_ & kUint64Flag ) ! = 0 ; } <nl> - bool IsDouble ( ) const { return ( flags_ & kDoubleFlag ) ! = 0 ; } <nl> - bool IsString ( ) const { return ( flags_ & kStringFlag ) ! = 0 ; } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Null <nl> - / / @ { <nl> - <nl> - GenericValue & SetNull ( ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( ) ; return * this ; } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Bool <nl> - / / @ { <nl> - <nl> - bool GetBool ( ) const { RAPIDJSON_ASSERT ( IsBool ( ) ) ; return flags_ = = kTrueFlag ; } <nl> - / / ! < Set boolean value <nl> - / * ! \ post IsBool ( ) = = true * / <nl> - GenericValue & SetBool ( bool b ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( b ) ; return * this ; } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Object <nl> - / / @ { <nl> - <nl> - / / ! Set this value as an empty object . <nl> - / * ! \ post IsObject ( ) = = true * / <nl> - GenericValue & SetObject ( ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( kObjectType ) ; return * this ; } <nl> - <nl> - / / ! Get the number of members in the object . <nl> - SizeType MemberCount ( ) const { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return data_ . o . size ; } <nl> - <nl> - / / ! Check whether the object is empty . <nl> - bool ObjectEmpty ( ) const { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return data_ . o . size = = 0 ; } <nl> - <nl> - / / ! Get a value from an object associated with the name . <nl> - / * ! \ pre IsObject ( ) = = true <nl> - \ tparam T Either \ c Ch or \ c const \ c Ch ( template used for disambiguation with \ ref operator [ ] ( SizeType ) ) <nl> - \ note In version 0 . 1x , if the member is not found , this function returns a null value . This makes issue 7 . <nl> - Since 0 . 2 , if the name is not correct , it will assert . <nl> - If user is unsure whether a member exists , user should use HasMember ( ) first . <nl> - A better approach is to use FindMember ( ) . <nl> - \ note Linear time complexity . <nl> - * / <nl> - template < typename T > <nl> - RAPIDJSON_DISABLEIF_RETURN ( ( internal : : NotExpr < internal : : IsSame < typename internal : : RemoveConst < T > : : Type , Ch > > ) , ( GenericValue & ) ) operator [ ] ( T * name ) { <nl> - GenericValue n ( StringRef ( name ) ) ; <nl> - return ( * this ) [ n ] ; <nl> - } <nl> - template < typename T > <nl> - RAPIDJSON_DISABLEIF_RETURN ( ( internal : : NotExpr < internal : : IsSame < typename internal : : RemoveConst < T > : : Type , Ch > > ) , ( const GenericValue & ) ) operator [ ] ( T * name ) const { return const_cast < GenericValue & > ( * this ) [ name ] ; } <nl> - <nl> - / / ! Get a value from an object associated with the name . <nl> - / * ! \ pre IsObject ( ) = = true <nl> - \ tparam SourceAllocator Allocator of the \ c name value <nl> - <nl> - \ note Compared to \ ref operator [ ] ( T * ) , this version is faster because it does not need a StrLen ( ) . <nl> - And it can also handle strings with embedded null characters . <nl> - <nl> - \ note Linear time complexity . <nl> - * / <nl> - template < typename SourceAllocator > <nl> - GenericValue & operator [ ] ( const GenericValue < Encoding , SourceAllocator > & name ) { <nl> - MemberIterator member = FindMember ( name ) ; <nl> - if ( member ! = MemberEnd ( ) ) <nl> - return member - > value ; <nl> - else { <nl> - RAPIDJSON_ASSERT ( false ) ; / / see above note <nl> - static GenericValue NullValue ; <nl> - return NullValue ; <nl> - } <nl> - } <nl> - template < typename SourceAllocator > <nl> - const GenericValue & operator [ ] ( const GenericValue < Encoding , SourceAllocator > & name ) const { return const_cast < GenericValue & > ( * this ) [ name ] ; } <nl> - <nl> - / / ! Const member iterator <nl> - / * ! \ pre IsObject ( ) = = true * / <nl> - ConstMemberIterator MemberBegin ( ) const { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return ConstMemberIterator ( data_ . o . members ) ; } <nl> - / / ! Const \ em past - the - end member iterator <nl> - / * ! \ pre IsObject ( ) = = true * / <nl> - ConstMemberIterator MemberEnd ( ) const { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return ConstMemberIterator ( data_ . o . members + data_ . o . size ) ; } <nl> - / / ! Member iterator <nl> - / * ! \ pre IsObject ( ) = = true * / <nl> - MemberIterator MemberBegin ( ) { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return MemberIterator ( data_ . o . members ) ; } <nl> - / / ! \ em Past - the - end member iterator <nl> - / * ! \ pre IsObject ( ) = = true * / <nl> - MemberIterator MemberEnd ( ) { RAPIDJSON_ASSERT ( IsObject ( ) ) ; return MemberIterator ( data_ . o . members + data_ . o . size ) ; } <nl> - <nl> - / / ! Check whether a member exists in the object . <nl> - / * ! <nl> - \ param name Member name to be searched . <nl> - \ pre IsObject ( ) = = true <nl> - \ return Whether a member with that name exists . <nl> - \ note It is better to use FindMember ( ) directly if you need the obtain the value as well . <nl> - \ note Linear time complexity . <nl> - * / <nl> - bool HasMember ( const Ch * name ) const { return FindMember ( name ) ! = MemberEnd ( ) ; } <nl> - <nl> - / / ! Check whether a member exists in the object with GenericValue name . <nl> - / * ! <nl> - This version is faster because it does not need a StrLen ( ) . It can also handle string with null character . <nl> - \ param name Member name to be searched . <nl> - \ pre IsObject ( ) = = true <nl> - \ return Whether a member with that name exists . <nl> - \ note It is better to use FindMember ( ) directly if you need the obtain the value as well . <nl> - \ note Linear time complexity . <nl> - * / <nl> - template < typename SourceAllocator > <nl> - bool HasMember ( const GenericValue < Encoding , SourceAllocator > & name ) const { return FindMember ( name ) ! = MemberEnd ( ) ; } <nl> - <nl> - / / ! Find member by name . <nl> - / * ! <nl> - \ param name Member name to be searched . <nl> - \ pre IsObject ( ) = = true <nl> - \ return Iterator to member , if it exists . <nl> - Otherwise returns \ ref MemberEnd ( ) . <nl> - <nl> - \ note Earlier versions of Rapidjson returned a \ c NULL pointer , in case <nl> - the requested member doesn ' t exist . For consistency with e . g . <nl> - \ c std : : map , this has been changed to MemberEnd ( ) now . <nl> - \ note Linear time complexity . <nl> - * / <nl> - MemberIterator FindMember ( const Ch * name ) { <nl> - GenericValue n ( StringRef ( name ) ) ; <nl> - return FindMember ( n ) ; <nl> - } <nl> - <nl> - ConstMemberIterator FindMember ( const Ch * name ) const { return const_cast < GenericValue & > ( * this ) . FindMember ( name ) ; } <nl> - <nl> - / / ! Find member by name . <nl> - / * ! <nl> - This version is faster because it does not need a StrLen ( ) . It can also handle string with null character . <nl> - \ param name Member name to be searched . <nl> - \ pre IsObject ( ) = = true <nl> - \ return Iterator to member , if it exists . <nl> - Otherwise returns \ ref MemberEnd ( ) . <nl> - <nl> - \ note Earlier versions of Rapidjson returned a \ c NULL pointer , in case <nl> - the requested member doesn ' t exist . For consistency with e . g . <nl> - \ c std : : map , this has been changed to MemberEnd ( ) now . <nl> - \ note Linear time complexity . <nl> - * / <nl> - template < typename SourceAllocator > <nl> - MemberIterator FindMember ( const GenericValue < Encoding , SourceAllocator > & name ) { <nl> - RAPIDJSON_ASSERT ( IsObject ( ) ) ; <nl> - RAPIDJSON_ASSERT ( name . IsString ( ) ) ; <nl> - MemberIterator member = MemberBegin ( ) ; <nl> - for ( ; member ! = MemberEnd ( ) ; + + member ) <nl> - if ( name . StringEqual ( member - > name ) ) <nl> - break ; <nl> - return member ; <nl> - } <nl> - template < typename SourceAllocator > ConstMemberIterator FindMember ( const GenericValue < Encoding , SourceAllocator > & name ) const { return const_cast < GenericValue & > ( * this ) . FindMember ( name ) ; } <nl> - <nl> - / / ! Add a member ( name - value pair ) to the object . <nl> - / * ! \ param name A string value as name of member . <nl> - \ param value Value of any type . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ note The ownership of \ c name and \ c value will be transferred to this object on success . <nl> - \ pre IsObject ( ) & & name . IsString ( ) <nl> - \ post name . IsNull ( ) & & value . IsNull ( ) <nl> - \ note Amortized Constant time complexity . <nl> - * / <nl> - GenericValue & AddMember ( GenericValue & name , GenericValue & value , Allocator & allocator ) { <nl> - RAPIDJSON_ASSERT ( IsObject ( ) ) ; <nl> - RAPIDJSON_ASSERT ( name . IsString ( ) ) ; <nl> - <nl> - Object & o = data_ . o ; <nl> - if ( o . size > = o . capacity ) { <nl> - if ( o . capacity = = 0 ) { <nl> - o . capacity = kDefaultObjectCapacity ; <nl> - o . members = reinterpret_cast < Member * > ( allocator . Malloc ( o . capacity * sizeof ( Member ) ) ) ; <nl> - } <nl> - else { <nl> - SizeType oldCapacity = o . capacity ; <nl> - o . capacity + = ( oldCapacity + 1 ) / 2 ; / / grow by factor 1 . 5 <nl> - o . members = reinterpret_cast < Member * > ( allocator . Realloc ( o . members , oldCapacity * sizeof ( Member ) , o . capacity * sizeof ( Member ) ) ) ; <nl> - } <nl> - } <nl> - o . members [ o . size ] . name . RawAssign ( name ) ; <nl> - o . members [ o . size ] . value . RawAssign ( value ) ; <nl> - o . size + + ; <nl> - return * this ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - GenericValue & AddMember ( GenericValue & & name , GenericValue & & value , Allocator & allocator ) { <nl> - return AddMember ( name , value , allocator ) ; <nl> - } <nl> - GenericValue & AddMember ( GenericValue & & name , GenericValue & value , Allocator & allocator ) { <nl> - return AddMember ( name , value , allocator ) ; <nl> - } <nl> - GenericValue & AddMember ( GenericValue & name , GenericValue & & value , Allocator & allocator ) { <nl> - return AddMember ( name , value , allocator ) ; <nl> - } <nl> - GenericValue & AddMember ( StringRefType name , GenericValue & & value , Allocator & allocator ) { <nl> - GenericValue n ( name ) ; <nl> - return AddMember ( n , value , allocator ) ; <nl> - } <nl> - # endif / / RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - <nl> - <nl> - / / ! Add a member ( name - value pair ) to the object . <nl> - / * ! \ param name A constant string reference as name of member . <nl> - \ param value Value of any type . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ note The ownership of \ c value will be transferred to this object on success . <nl> - \ pre IsObject ( ) <nl> - \ post value . IsNull ( ) <nl> - \ note Amortized Constant time complexity . <nl> - * / <nl> - GenericValue & AddMember ( StringRefType name , GenericValue & value , Allocator & allocator ) { <nl> - GenericValue n ( name ) ; <nl> - return AddMember ( n , value , allocator ) ; <nl> - } <nl> - <nl> - / / ! Add a constant string value as member ( name - value pair ) to the object . <nl> - / * ! \ param name A constant string reference as name of member . <nl> - \ param value constant string reference as value of member . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ pre IsObject ( ) <nl> - \ note This overload is needed to avoid clashes with the generic primitive type AddMember ( StringRefType , T , Allocator & ) overload below . <nl> - \ note Amortized Constant time complexity . <nl> - * / <nl> - GenericValue & AddMember ( StringRefType name , StringRefType value , Allocator & allocator ) { <nl> - GenericValue v ( value ) ; <nl> - return AddMember ( name , v , allocator ) ; <nl> - } <nl> - <nl> - / / ! Add any primitive value as member ( name - value pair ) to the object . <nl> - / * ! \ tparam T Either \ ref Type , \ c int , \ c unsigned , \ c int64_t , \ c uint64_t <nl> - \ param name A constant string reference as name of member . <nl> - \ param value Value of primitive type \ c T as value of member <nl> - \ param allocator Allocator for reallocating memory . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ pre IsObject ( ) <nl> - <nl> - \ note The source type \ c T explicitly disallows all pointer types , <nl> - especially ( \ c const ) \ ref Ch * . This helps avoiding implicitly <nl> - referencing character strings with insufficient lifetime , use <nl> - \ ref AddMember ( StringRefType , GenericValue & , Allocator & ) or \ ref <nl> - AddMember ( StringRefType , StringRefType , Allocator & ) . <nl> - All other pointer types would implicitly convert to \ c bool , <nl> - use an explicit cast instead , if needed . <nl> - \ note Amortized Constant time complexity . <nl> - * / <nl> - template < typename T > <nl> - RAPIDJSON_DISABLEIF_RETURN ( ( internal : : OrExpr < internal : : IsPointer < T > , internal : : IsGenericValue < T > > ) , ( GenericValue & ) ) <nl> - AddMember ( StringRefType name , T value , Allocator & allocator ) { <nl> - GenericValue n ( name ) ; <nl> - GenericValue v ( value ) ; <nl> - return AddMember ( n , v , allocator ) ; <nl> - } <nl> - <nl> - / / ! Remove all members in the object . <nl> - / * ! This function do not deallocate memory in the object , i . e . the capacity is unchanged . <nl> - \ note Linear time complexity . <nl> - * / <nl> - void RemoveAllMembers ( ) { <nl> - RAPIDJSON_ASSERT ( IsObject ( ) ) ; <nl> - for ( MemberIterator m = MemberBegin ( ) ; m ! = MemberEnd ( ) ; + + m ) <nl> - m - > ~ Member ( ) ; <nl> - data_ . o . size = 0 ; <nl> - } <nl> - <nl> - / / ! Remove a member in object by its name . <nl> - / * ! \ param name Name of member to be removed . <nl> - \ return Whether the member existed . <nl> - \ note This function may reorder the object members . Use \ ref <nl> - EraseMember ( ConstMemberIterator ) if you need to preserve the <nl> - relative order of the remaining members . <nl> - \ note Linear time complexity . <nl> - * / <nl> - bool RemoveMember ( const Ch * name ) { <nl> - GenericValue n ( StringRef ( name ) ) ; <nl> - return RemoveMember ( n ) ; <nl> - } <nl> - <nl> - template < typename SourceAllocator > <nl> - bool RemoveMember ( const GenericValue < Encoding , SourceAllocator > & name ) { <nl> - MemberIterator m = FindMember ( name ) ; <nl> - if ( m ! = MemberEnd ( ) ) { <nl> - RemoveMember ( m ) ; <nl> - return true ; <nl> - } <nl> - else <nl> - return false ; <nl> - } <nl> - <nl> - / / ! Remove a member in object by iterator . <nl> - / * ! \ param m member iterator ( obtained by FindMember ( ) or MemberBegin ( ) ) . <nl> - \ return the new iterator after removal . <nl> - \ note This function may reorder the object members . Use \ ref <nl> - EraseMember ( ConstMemberIterator ) if you need to preserve the <nl> - relative order of the remaining members . <nl> - \ note Constant time complexity . <nl> - * / <nl> - MemberIterator RemoveMember ( MemberIterator m ) { <nl> - RAPIDJSON_ASSERT ( IsObject ( ) ) ; <nl> - RAPIDJSON_ASSERT ( data_ . o . size > 0 ) ; <nl> - RAPIDJSON_ASSERT ( data_ . o . members ! = 0 ) ; <nl> - RAPIDJSON_ASSERT ( m > = MemberBegin ( ) & & m < MemberEnd ( ) ) ; <nl> - <nl> - MemberIterator last ( data_ . o . members + ( data_ . o . size - 1 ) ) ; <nl> - if ( data_ . o . size > 1 & & m ! = last ) { <nl> - / / Move the last one to this place <nl> - * m = * last ; <nl> - } <nl> - else { <nl> - / / Only one left , just destroy <nl> - m - > ~ Member ( ) ; <nl> - } <nl> - - - data_ . o . size ; <nl> - return m ; <nl> - } <nl> - <nl> - / / ! Remove a member from an object by iterator . <nl> - / * ! \ param pos iterator to the member to remove <nl> - \ pre IsObject ( ) = = true & & \ ref MemberBegin ( ) < = \ c pos < \ ref MemberEnd ( ) <nl> - \ return Iterator following the removed element . <nl> - If the iterator \ c pos refers to the last element , the \ ref MemberEnd ( ) iterator is returned . <nl> - \ note This function preserves the relative order of the remaining object <nl> - members . If you do not need this , use the more efficient \ ref RemoveMember ( MemberIterator ) . <nl> - \ note Linear time complexity . <nl> - * / <nl> - MemberIterator EraseMember ( ConstMemberIterator pos ) { <nl> - return EraseMember ( pos , pos + 1 ) ; <nl> - } <nl> - <nl> - / / ! Remove members in the range [ first , last ) from an object . <nl> - / * ! \ param first iterator to the first member to remove <nl> - \ param last iterator following the last member to remove <nl> - \ pre IsObject ( ) = = true & & \ ref MemberBegin ( ) < = \ c first < = \ c last < = \ ref MemberEnd ( ) <nl> - \ return Iterator following the last removed element . <nl> - \ note This function preserves the relative order of the remaining object <nl> - members . <nl> - \ note Linear time complexity . <nl> - * / <nl> - MemberIterator EraseMember ( ConstMemberIterator first , ConstMemberIterator last ) { <nl> - RAPIDJSON_ASSERT ( IsObject ( ) ) ; <nl> - RAPIDJSON_ASSERT ( data_ . o . size > 0 ) ; <nl> - RAPIDJSON_ASSERT ( data_ . o . members ! = 0 ) ; <nl> - RAPIDJSON_ASSERT ( first > = MemberBegin ( ) ) ; <nl> - RAPIDJSON_ASSERT ( first < = last ) ; <nl> - RAPIDJSON_ASSERT ( last < = MemberEnd ( ) ) ; <nl> - <nl> - MemberIterator pos = MemberBegin ( ) + ( first - MemberBegin ( ) ) ; <nl> - for ( MemberIterator itr = pos ; itr ! = last ; + + itr ) <nl> - itr - > ~ Member ( ) ; <nl> - std : : memmove ( & * pos , & * last , ( MemberEnd ( ) - last ) * sizeof ( Member ) ) ; <nl> - data_ . o . size - = ( last - first ) ; <nl> - return pos ; <nl> - } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Array <nl> - / / @ { <nl> - <nl> - / / ! Set this value as an empty array . <nl> - / * ! \ post IsArray = = true * / <nl> - GenericValue & SetArray ( ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( kArrayType ) ; return * this ; } <nl> - <nl> - / / ! Get the number of elements in array . <nl> - SizeType Size ( ) const { RAPIDJSON_ASSERT ( IsArray ( ) ) ; return data_ . a . size ; } <nl> - <nl> - / / ! Get the capacity of array . <nl> - SizeType Capacity ( ) const { RAPIDJSON_ASSERT ( IsArray ( ) ) ; return data_ . a . capacity ; } <nl> - <nl> - / / ! Check whether the array is empty . <nl> - bool Empty ( ) const { RAPIDJSON_ASSERT ( IsArray ( ) ) ; return data_ . a . size = = 0 ; } <nl> - <nl> - / / ! Remove all elements in the array . <nl> - / * ! This function do not deallocate memory in the array , i . e . the capacity is unchanged . <nl> - \ note Linear time complexity . <nl> - * / <nl> - void Clear ( ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - for ( SizeType i = 0 ; i < data_ . a . size ; + + i ) <nl> - data_ . a . elements [ i ] . ~ GenericValue ( ) ; <nl> - data_ . a . size = 0 ; <nl> - } <nl> - <nl> - / / ! Get an element from array by index . <nl> - / * ! \ pre IsArray ( ) = = true <nl> - \ param index Zero - based index of element . <nl> - \ see operator [ ] ( T * ) <nl> - * / <nl> - GenericValue & operator [ ] ( SizeType index ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - RAPIDJSON_ASSERT ( index < data_ . a . size ) ; <nl> - return data_ . a . elements [ index ] ; <nl> - } <nl> - const GenericValue & operator [ ] ( SizeType index ) const { return const_cast < GenericValue & > ( * this ) [ index ] ; } <nl> - <nl> - / / ! Element iterator <nl> - / * ! \ pre IsArray ( ) = = true * / <nl> - ValueIterator Begin ( ) { RAPIDJSON_ASSERT ( IsArray ( ) ) ; return data_ . a . elements ; } <nl> - / / ! \ em Past - the - end element iterator <nl> - / * ! \ pre IsArray ( ) = = true * / <nl> - ValueIterator End ( ) { RAPIDJSON_ASSERT ( IsArray ( ) ) ; return data_ . a . elements + data_ . a . size ; } <nl> - / / ! Constant element iterator <nl> - / * ! \ pre IsArray ( ) = = true * / <nl> - ConstValueIterator Begin ( ) const { return const_cast < GenericValue & > ( * this ) . Begin ( ) ; } <nl> - / / ! Constant \ em past - the - end element iterator <nl> - / * ! \ pre IsArray ( ) = = true * / <nl> - ConstValueIterator End ( ) const { return const_cast < GenericValue & > ( * this ) . End ( ) ; } <nl> - <nl> - / / ! Request the array to have enough capacity to store elements . <nl> - / * ! \ param newCapacity The capacity that the array at least need to have . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ note Linear time complexity . <nl> - * / <nl> - GenericValue & Reserve ( SizeType newCapacity , Allocator & allocator ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - if ( newCapacity > data_ . a . capacity ) { <nl> - data_ . a . elements = ( GenericValue * ) allocator . Realloc ( data_ . a . elements , data_ . a . capacity * sizeof ( GenericValue ) , newCapacity * sizeof ( GenericValue ) ) ; <nl> - data_ . a . capacity = newCapacity ; <nl> - } <nl> - return * this ; <nl> - } <nl> - <nl> - / / ! Append a GenericValue at the end of the array . <nl> - / * ! \ param value Value to be appended . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ pre IsArray ( ) = = true <nl> - \ post value . IsNull ( ) = = true <nl> - \ return The value itself for fluent API . <nl> - \ note The ownership of \ c value will be transferred to this array on success . <nl> - \ note If the number of elements to be appended is known , calls Reserve ( ) once first may be more efficient . <nl> - \ note Amortized constant time complexity . <nl> - * / <nl> - GenericValue & PushBack ( GenericValue & value , Allocator & allocator ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - if ( data_ . a . size > = data_ . a . capacity ) <nl> - Reserve ( data_ . a . capacity = = 0 ? kDefaultArrayCapacity : ( data_ . a . capacity + ( data_ . a . capacity + 1 ) / 2 ) , allocator ) ; <nl> - data_ . a . elements [ data_ . a . size + + ] . RawAssign ( value ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - GenericValue & PushBack ( GenericValue & & value , Allocator & allocator ) { <nl> - return PushBack ( value , allocator ) ; <nl> - } <nl> - # endif / / RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - <nl> - / / ! Append a constant string reference at the end of the array . <nl> - / * ! \ param value Constant string reference to be appended . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one used previously . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ pre IsArray ( ) = = true <nl> - \ return The value itself for fluent API . <nl> - \ note If the number of elements to be appended is known , calls Reserve ( ) once first may be more efficient . <nl> - \ note Amortized constant time complexity . <nl> - \ see GenericStringRef <nl> - * / <nl> - GenericValue & PushBack ( StringRefType value , Allocator & allocator ) { <nl> - return ( * this ) . template PushBack < StringRefType > ( value , allocator ) ; <nl> - } <nl> - <nl> - / / ! Append a primitive value at the end of the array . <nl> - / * ! \ tparam T Either \ ref Type , \ c int , \ c unsigned , \ c int64_t , \ c uint64_t <nl> - \ param value Value of primitive type T to be appended . <nl> - \ param allocator Allocator for reallocating memory . It must be the same one as used before . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ pre IsArray ( ) = = true <nl> - \ return The value itself for fluent API . <nl> - \ note If the number of elements to be appended is known , calls Reserve ( ) once first may be more efficient . <nl> - <nl> - \ note The source type \ c T explicitly disallows all pointer types , <nl> - especially ( \ c const ) \ ref Ch * . This helps avoiding implicitly <nl> - referencing character strings with insufficient lifetime , use <nl> - \ ref PushBack ( GenericValue & , Allocator & ) or \ ref <nl> - PushBack ( StringRefType , Allocator & ) . <nl> - All other pointer types would implicitly convert to \ c bool , <nl> - use an explicit cast instead , if needed . <nl> - \ note Amortized constant time complexity . <nl> - * / <nl> - template < typename T > <nl> - RAPIDJSON_DISABLEIF_RETURN ( ( internal : : OrExpr < internal : : IsPointer < T > , internal : : IsGenericValue < T > > ) , ( GenericValue & ) ) <nl> - PushBack ( T value , Allocator & allocator ) { <nl> - GenericValue v ( value ) ; <nl> - return PushBack ( v , allocator ) ; <nl> - } <nl> - <nl> - / / ! Remove the last element in the array . <nl> - / * ! <nl> - \ note Constant time complexity . <nl> - * / <nl> - GenericValue & PopBack ( ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - RAPIDJSON_ASSERT ( ! Empty ( ) ) ; <nl> - data_ . a . elements [ - - data_ . a . size ] . ~ GenericValue ( ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - / / ! Remove an element of array by iterator . <nl> - / * ! <nl> - \ param pos iterator to the element to remove <nl> - \ pre IsArray ( ) = = true & & \ ref Begin ( ) < = \ c pos < \ ref End ( ) <nl> - \ return Iterator following the removed element . If the iterator pos refers to the last element , the End ( ) iterator is returned . <nl> - \ note Linear time complexity . <nl> - * / <nl> - ValueIterator Erase ( ConstValueIterator pos ) { <nl> - return Erase ( pos , pos + 1 ) ; <nl> - } <nl> - <nl> - / / ! Remove elements in the range [ first , last ) of the array . <nl> - / * ! <nl> - \ param first iterator to the first element to remove <nl> - \ param last iterator following the last element to remove <nl> - \ pre IsArray ( ) = = true & & \ ref Begin ( ) < = \ c first < = \ c last < = \ ref End ( ) <nl> - \ return Iterator following the last removed element . <nl> - \ note Linear time complexity . <nl> - * / <nl> - ValueIterator Erase ( ConstValueIterator first , ConstValueIterator last ) { <nl> - RAPIDJSON_ASSERT ( IsArray ( ) ) ; <nl> - RAPIDJSON_ASSERT ( data_ . a . size > 0 ) ; <nl> - RAPIDJSON_ASSERT ( data_ . a . elements ! = 0 ) ; <nl> - RAPIDJSON_ASSERT ( first > = Begin ( ) ) ; <nl> - RAPIDJSON_ASSERT ( first < = last ) ; <nl> - RAPIDJSON_ASSERT ( last < = End ( ) ) ; <nl> - ValueIterator pos = Begin ( ) + ( first - Begin ( ) ) ; <nl> - for ( ValueIterator itr = pos ; itr ! = last ; + + itr ) <nl> - itr - > ~ GenericValue ( ) ; <nl> - std : : memmove ( pos , last , ( End ( ) - last ) * sizeof ( GenericValue ) ) ; <nl> - data_ . a . size - = ( last - first ) ; <nl> - return pos ; <nl> - } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name Number <nl> - / / @ { <nl> - <nl> - int GetInt ( ) const { RAPIDJSON_ASSERT ( flags_ & kIntFlag ) ; return data_ . n . i . i ; } <nl> - unsigned GetUint ( ) const { RAPIDJSON_ASSERT ( flags_ & kUintFlag ) ; return data_ . n . u . u ; } <nl> - int64_t GetInt64 ( ) const { RAPIDJSON_ASSERT ( flags_ & kInt64Flag ) ; return data_ . n . i64 ; } <nl> - uint64_t GetUint64 ( ) const { RAPIDJSON_ASSERT ( flags_ & kUint64Flag ) ; return data_ . n . u64 ; } <nl> - <nl> - double GetDouble ( ) const { <nl> - RAPIDJSON_ASSERT ( IsNumber ( ) ) ; <nl> - if ( ( flags_ & kDoubleFlag ) ! = 0 ) return data_ . n . d ; / / exact type , no conversion . <nl> - if ( ( flags_ & kIntFlag ) ! = 0 ) return data_ . n . i . i ; / / int - > double <nl> - if ( ( flags_ & kUintFlag ) ! = 0 ) return data_ . n . u . u ; / / unsigned - > double <nl> - if ( ( flags_ & kInt64Flag ) ! = 0 ) return ( double ) data_ . n . i64 ; / / int64_t - > double ( may lose precision ) <nl> - RAPIDJSON_ASSERT ( ( flags_ & kUint64Flag ) ! = 0 ) ; return ( double ) data_ . n . u64 ; / / uint64_t - > double ( may lose precision ) <nl> - } <nl> - <nl> - GenericValue & SetInt ( int i ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( i ) ; return * this ; } <nl> - GenericValue & SetUint ( unsigned u ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( u ) ; return * this ; } <nl> - GenericValue & SetInt64 ( int64_t i64 ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( i64 ) ; return * this ; } <nl> - GenericValue & SetUint64 ( uint64_t u64 ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( u64 ) ; return * this ; } <nl> - GenericValue & SetDouble ( double d ) { this - > ~ GenericValue ( ) ; new ( this ) GenericValue ( d ) ; return * this ; } <nl> - <nl> - / / @ } <nl> - <nl> - / / ! @ name String <nl> - / / @ { <nl> - <nl> - const Ch * GetString ( ) const { RAPIDJSON_ASSERT ( IsString ( ) ) ; return ( ( flags_ & kInlineStrFlag ) ? data_ . ss . str : data_ . s . str ) ; } <nl> - <nl> - / / ! Get the length of string . <nl> - / * ! Since rapidjson permits " \ \ u0000 " in the json string , strlen ( v . GetString ( ) ) may not equal to v . GetStringLength ( ) . <nl> - * / <nl> - SizeType GetStringLength ( ) const { RAPIDJSON_ASSERT ( IsString ( ) ) ; return ( ( flags_ & kInlineStrFlag ) ? ( data_ . ss . GetLength ( ) ) : data_ . s . length ) ; } <nl> - <nl> - / / ! Set this value as a string without copying source string . <nl> - / * ! This version has better performance with supplied length , and also support string containing null character . <nl> - \ param s source string pointer . <nl> - \ param length The length of source string , excluding the trailing null terminator . <nl> - \ return The value itself for fluent API . <nl> - \ post IsString ( ) = = true & & GetString ( ) = = s & & GetStringLength ( ) = = length <nl> - \ see SetString ( StringRefType ) <nl> - * / <nl> - GenericValue & SetString ( const Ch * s , SizeType length ) { return SetString ( StringRef ( s , length ) ) ; } <nl> - <nl> - / / ! Set this value as a string without copying source string . <nl> - / * ! \ param s source string reference <nl> - \ return The value itself for fluent API . <nl> - \ post IsString ( ) = = true & & GetString ( ) = = s & & GetStringLength ( ) = = s . length <nl> - * / <nl> - GenericValue & SetString ( StringRefType s ) { this - > ~ GenericValue ( ) ; SetStringRaw ( s ) ; return * this ; } <nl> - <nl> - / / ! Set this value as a string by copying from source string . <nl> - / * ! This version has better performance with supplied length , and also support string containing null character . <nl> - \ param s source string . <nl> - \ param length The length of source string , excluding the trailing null terminator . <nl> - \ param allocator Allocator for allocating copied buffer . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ post IsString ( ) = = true & & GetString ( ) ! = s & & strcmp ( GetString ( ) , s ) = = 0 & & GetStringLength ( ) = = length <nl> - * / <nl> - GenericValue & SetString ( const Ch * s , SizeType length , Allocator & allocator ) { this - > ~ GenericValue ( ) ; SetStringRaw ( StringRef ( s , length ) , allocator ) ; return * this ; } <nl> - <nl> - / / ! Set this value as a string by copying from source string . <nl> - / * ! \ param s source string . <nl> - \ param allocator Allocator for allocating copied buffer . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ post IsString ( ) = = true & & GetString ( ) ! = s & & strcmp ( GetString ( ) , s ) = = 0 & & GetStringLength ( ) = = length <nl> - * / <nl> - GenericValue & SetString ( const Ch * s , Allocator & allocator ) { return SetString ( s , internal : : StrLen ( s ) , allocator ) ; } <nl> - <nl> - # if RAPIDJSON_HAS_STDSTRING <nl> - / / ! Set this value as a string by copying from source string . <nl> - / * ! \ param s source string . <nl> - \ param allocator Allocator for allocating copied buffer . Commonly use GenericDocument : : GetAllocator ( ) . <nl> - \ return The value itself for fluent API . <nl> - \ post IsString ( ) = = true & & GetString ( ) ! = s . data ( ) & & strcmp ( GetString ( ) , s . data ( ) = = 0 & & GetStringLength ( ) = = s . size ( ) <nl> - \ note Requires the definition of the preprocessor symbol \ ref RAPIDJSON_HAS_STDSTRING . <nl> - * / <nl> - GenericValue & SetString ( const std : : basic_string < Ch > & s , Allocator & allocator ) { return SetString ( s . data ( ) , s . size ( ) , allocator ) ; } <nl> - # endif <nl> - <nl> - / / @ } <nl> - <nl> - / / ! Generate events of this value to a Handler . <nl> - / * ! This function adopts the GoF visitor pattern . <nl> - Typical usage is to output this JSON value as JSON text via Writer , which is a Handler . <nl> - It can also be used to deep clone this value via GenericDocument , which is also a Handler . <nl> - \ tparam Handler type of handler . <nl> - \ param handler An object implementing concept Handler . <nl> - * / <nl> - template < typename Handler > <nl> - bool Accept ( Handler & handler ) const { <nl> - switch ( GetType ( ) ) { <nl> - case kNullType : return handler . Null ( ) ; <nl> - case kFalseType : return handler . Bool ( false ) ; <nl> - case kTrueType : return handler . Bool ( true ) ; <nl> - <nl> - case kObjectType : <nl> - if ( ! handler . StartObject ( ) ) <nl> - return false ; <nl> - for ( ConstMemberIterator m = MemberBegin ( ) ; m ! = MemberEnd ( ) ; + + m ) { <nl> - if ( ! handler . Key ( m - > name . GetString ( ) , m - > name . GetStringLength ( ) , ( m - > name . flags_ & kCopyFlag ) ! = 0 ) ) <nl> - return false ; <nl> - if ( ! m - > value . Accept ( handler ) ) <nl> - return false ; <nl> - } <nl> - return handler . EndObject ( data_ . o . size ) ; <nl> - <nl> - case kArrayType : <nl> - if ( ! handler . StartArray ( ) ) <nl> - return false ; <nl> - for ( GenericValue * v = data_ . a . elements ; v ! = data_ . a . elements + data_ . a . size ; + + v ) <nl> - if ( ! v - > Accept ( handler ) ) <nl> - return false ; <nl> - return handler . EndArray ( data_ . a . size ) ; <nl> - <nl> - case kStringType : <nl> - return handler . String ( GetString ( ) , GetStringLength ( ) , ( flags_ & kCopyFlag ) ! = 0 ) ; <nl> - <nl> - case kNumberType : <nl> - if ( IsInt ( ) ) return handler . Int ( data_ . n . i . i ) ; <nl> - else if ( IsUint ( ) ) return handler . Uint ( data_ . n . u . u ) ; <nl> - else if ( IsInt64 ( ) ) return handler . Int64 ( data_ . n . i64 ) ; <nl> - else if ( IsUint64 ( ) ) return handler . Uint64 ( data_ . n . u64 ) ; <nl> - else return handler . Double ( data_ . n . d ) ; <nl> - <nl> - default : <nl> - RAPIDJSON_ASSERT ( false ) ; <nl> - } <nl> - return false ; <nl> - } <nl> - <nl> - private : <nl> - template < typename , typename > friend class GenericValue ; <nl> - template < typename , typename , typename > friend class GenericDocument ; <nl> - <nl> - enum { <nl> - kBoolFlag = 0x100 , <nl> - kNumberFlag = 0x200 , <nl> - kIntFlag = 0x400 , <nl> - kUintFlag = 0x800 , <nl> - kInt64Flag = 0x1000 , <nl> - kUint64Flag = 0x2000 , <nl> - kDoubleFlag = 0x4000 , <nl> - kStringFlag = 0x100000 , <nl> - kCopyFlag = 0x200000 , <nl> - kInlineStrFlag = 0x400000 , <nl> - <nl> - / / Initial flags of different types . <nl> - kNullFlag = kNullType , <nl> - kTrueFlag = kTrueType | kBoolFlag , <nl> - kFalseFlag = kFalseType | kBoolFlag , <nl> - kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag , <nl> - kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag , <nl> - kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag , <nl> - kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag , <nl> - kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag , <nl> - kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag , <nl> - kConstStringFlag = kStringType | kStringFlag , <nl> - kCopyStringFlag = kStringType | kStringFlag | kCopyFlag , <nl> - kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag , <nl> - kObjectFlag = kObjectType , <nl> - kArrayFlag = kArrayType , <nl> - <nl> - kTypeMask = 0xFF / / bitwise - and with mask of 0xFF can be optimized by compiler <nl> - } ; <nl> - <nl> - static const SizeType kDefaultArrayCapacity = 16 ; <nl> - static const SizeType kDefaultObjectCapacity = 16 ; <nl> - <nl> - struct String { <nl> - const Ch * str ; <nl> - SizeType length ; <nl> - unsigned hashcode ; / / ! < reserved <nl> - } ; / / 12 bytes in 32 - bit mode , 16 bytes in 64 - bit mode <nl> - <nl> - / / implementation detail : ShortString can represent zero - terminated strings up to MaxSize chars <nl> - / / ( excluding the terminating zero ) and store a value to determine the length of the contained <nl> - / / string in the last character str [ LenPos ] by storing " MaxSize - length " there . If the string <nl> - / / to store has the maximal length of MaxSize then str [ LenPos ] will be 0 and therefore act as <nl> - / / the string terminator as well . For getting the string length back from that value just use <nl> - / / " MaxSize - str [ LenPos ] " . <nl> - / / This allows to store 11 - chars strings in 32 - bit mode and 15 - chars strings in 64 - bit mode <nl> - / / inline ( for ` UTF8 ` - encoded strings ) . <nl> - struct ShortString { <nl> - enum { MaxChars = sizeof ( String ) / sizeof ( Ch ) , MaxSize = MaxChars - 1 , LenPos = MaxSize } ; <nl> - Ch str [ MaxChars ] ; <nl> - <nl> - inline static bool Usable ( SizeType len ) { return ( MaxSize > = len ) ; } <nl> - inline void SetLength ( SizeType len ) { str [ LenPos ] = ( Ch ) ( MaxSize - len ) ; } <nl> - inline SizeType GetLength ( ) const { return ( SizeType ) ( MaxSize - str [ LenPos ] ) ; } <nl> - } ; / / at most as many bytes as " String " above = > 12 bytes in 32 - bit mode , 16 bytes in 64 - bit mode <nl> - <nl> - / / By using proper binary layout , retrieval of different integer types do not need conversions . <nl> - union Number { <nl> - # if RAPIDJSON_ENDIAN = = RAPIDJSON_LITTLEENDIAN <nl> - struct I { <nl> - int i ; <nl> - char padding [ 4 ] ; <nl> - } i ; <nl> - struct U { <nl> - unsigned u ; <nl> - char padding2 [ 4 ] ; <nl> - } u ; <nl> - # else <nl> - struct I { <nl> - char padding [ 4 ] ; <nl> - int i ; <nl> - } i ; <nl> - struct U { <nl> - char padding2 [ 4 ] ; <nl> - unsigned u ; <nl> - } u ; <nl> - # endif <nl> - int64_t i64 ; <nl> - uint64_t u64 ; <nl> - double d ; <nl> - } ; / / 8 bytes <nl> - <nl> - struct Object { <nl> - Member * members ; <nl> - SizeType size ; <nl> - SizeType capacity ; <nl> - } ; / / 12 bytes in 32 - bit mode , 16 bytes in 64 - bit mode <nl> - <nl> - struct Array { <nl> - GenericValue * elements ; <nl> - SizeType size ; <nl> - SizeType capacity ; <nl> - } ; / / 12 bytes in 32 - bit mode , 16 bytes in 64 - bit mode <nl> - <nl> - union Data { <nl> - String s ; <nl> - ShortString ss ; <nl> - Number n ; <nl> - Object o ; <nl> - Array a ; <nl> - } ; / / 12 bytes in 32 - bit mode , 16 bytes in 64 - bit mode <nl> - <nl> - / / Initialize this value as array with initial data , without calling destructor . <nl> - void SetArrayRaw ( GenericValue * values , SizeType count , Allocator & allocator ) { <nl> - flags_ = kArrayFlag ; <nl> - data_ . a . elements = ( GenericValue * ) allocator . Malloc ( count * sizeof ( GenericValue ) ) ; <nl> - std : : memcpy ( data_ . a . elements , values , count * sizeof ( GenericValue ) ) ; <nl> - data_ . a . size = data_ . a . capacity = count ; <nl> - } <nl> - <nl> - / / ! Initialize this value as object with initial data , without calling destructor . <nl> - void SetObjectRaw ( Member * members , SizeType count , Allocator & allocator ) { <nl> - flags_ = kObjectFlag ; <nl> - data_ . o . members = ( Member * ) allocator . Malloc ( count * sizeof ( Member ) ) ; <nl> - std : : memcpy ( data_ . o . members , members , count * sizeof ( Member ) ) ; <nl> - data_ . o . size = data_ . o . capacity = count ; <nl> - } <nl> - <nl> - / / ! Initialize this value as constant string , without calling destructor . <nl> - void SetStringRaw ( StringRefType s ) RAPIDJSON_NOEXCEPT { <nl> - flags_ = kConstStringFlag ; <nl> - data_ . s . str = s ; <nl> - data_ . s . length = s . length ; <nl> - } <nl> - <nl> - / / ! Initialize this value as copy string with initial data , without calling destructor . <nl> - void SetStringRaw ( StringRefType s , Allocator & allocator ) { <nl> - Ch * str = NULL ; <nl> - if ( ShortString : : Usable ( s . length ) ) { <nl> - flags_ = kShortStringFlag ; <nl> - data_ . ss . SetLength ( s . length ) ; <nl> - str = data_ . ss . str ; <nl> - } else { <nl> - flags_ = kCopyStringFlag ; <nl> - data_ . s . length = s . length ; <nl> - str = ( Ch * ) allocator . Malloc ( ( s . length + 1 ) * sizeof ( Ch ) ) ; <nl> - data_ . s . str = str ; <nl> - } <nl> - std : : memcpy ( str , s , s . length * sizeof ( Ch ) ) ; <nl> - str [ s . length ] = ' \ 0 ' ; <nl> - } <nl> - <nl> - / / ! Assignment without calling destructor <nl> - void RawAssign ( GenericValue & rhs ) RAPIDJSON_NOEXCEPT { <nl> - data_ = rhs . data_ ; <nl> - flags_ = rhs . flags_ ; <nl> - rhs . flags_ = kNullFlag ; <nl> - } <nl> - <nl> - template < typename SourceAllocator > <nl> - bool StringEqual ( const GenericValue < Encoding , SourceAllocator > & rhs ) const { <nl> - RAPIDJSON_ASSERT ( IsString ( ) ) ; <nl> - RAPIDJSON_ASSERT ( rhs . IsString ( ) ) ; <nl> - <nl> - const SizeType len1 = GetStringLength ( ) ; <nl> - const SizeType len2 = rhs . GetStringLength ( ) ; <nl> - if ( len1 ! = len2 ) { return false ; } <nl> - <nl> - const Ch * const str1 = GetString ( ) ; <nl> - const Ch * const str2 = rhs . GetString ( ) ; <nl> - if ( str1 = = str2 ) { return true ; } / / fast path for constant string <nl> - <nl> - return ( std : : memcmp ( str1 , str2 , sizeof ( Ch ) * len1 ) = = 0 ) ; <nl> - } <nl> - <nl> - Data data_ ; <nl> - unsigned flags_ ; <nl> - } ; <nl> - <nl> - / / ! GenericValue with UTF8 encoding <nl> - typedef GenericValue < UTF8 < > > Value ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericDocument <nl> - <nl> - / / ! A document for parsing JSON text as DOM . <nl> - / * ! <nl> - \ note implements Handler concept <nl> - \ tparam Encoding Encoding for both parsing and string storage . <nl> - \ tparam Allocator Allocator for allocating memory for the DOM <nl> - \ tparam StackAllocator Allocator for allocating memory for stack during parsing . <nl> - \ warning Although GenericDocument inherits from GenericValue , the API does \ b not provide any virtual functions , especially no virtual destructor . To avoid memory leaks , do not \ c delete a GenericDocument object via a pointer to a GenericValue . <nl> - * / <nl> - template < typename Encoding , typename Allocator = MemoryPoolAllocator < > , typename StackAllocator = CrtAllocator > <nl> - class GenericDocument : public GenericValue < Encoding , Allocator > { <nl> - public : <nl> - typedef typename Encoding : : Ch Ch ; / / ! < Character type derived from Encoding . <nl> - typedef GenericValue < Encoding , Allocator > ValueType ; / / ! < Value type of the document . <nl> - typedef Allocator AllocatorType ; / / ! < Allocator type from template parameter . <nl> - <nl> - / / ! Constructor <nl> - / * ! \ param allocator Optional allocator for allocating memory . <nl> - \ param stackCapacity Optional initial capacity of stack in bytes . <nl> - \ param stackAllocator Optional allocator for allocating memory for stack . <nl> - * / <nl> - GenericDocument ( Allocator * allocator = 0 , size_t stackCapacity = kDefaultStackCapacity , StackAllocator * stackAllocator = 0 ) : <nl> - allocator_ ( allocator ) , ownAllocator_ ( 0 ) , stack_ ( stackAllocator , stackCapacity ) , parseResult_ ( ) <nl> - { <nl> - if ( ! allocator_ ) <nl> - ownAllocator_ = allocator_ = new Allocator ( ) ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - / / ! Move constructor in C + + 11 <nl> - GenericDocument ( GenericDocument & & rhs ) RAPIDJSON_NOEXCEPT <nl> - : ValueType ( std : : move ( rhs ) ) , <nl> - allocator_ ( rhs . allocator_ ) , <nl> - ownAllocator_ ( rhs . ownAllocator_ ) , <nl> - stack_ ( std : : move ( rhs . stack_ ) ) , <nl> - parseResult_ ( rhs . parseResult_ ) <nl> - { <nl> - rhs . allocator_ = 0 ; <nl> - rhs . ownAllocator_ = 0 ; <nl> - rhs . parseResult_ = ParseResult ( ) ; <nl> - } <nl> - # endif <nl> - <nl> - ~ GenericDocument ( ) { <nl> - Destroy ( ) ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - / / ! Move assignment in C + + 11 <nl> - GenericDocument & operator = ( GenericDocument & & rhs ) RAPIDJSON_NOEXCEPT <nl> - { <nl> - / / The cast to ValueType is necessary here , because otherwise it would <nl> - / / attempt to call GenericValue ' s templated assignment operator . <nl> - ValueType : : operator = ( std : : forward < ValueType > ( rhs ) ) ; <nl> - <nl> - / / Calling the destructor here would prematurely call stack_ ' s destructor <nl> - Destroy ( ) ; <nl> - <nl> - allocator_ = rhs . allocator_ ; <nl> - ownAllocator_ = rhs . ownAllocator_ ; <nl> - stack_ = std : : move ( rhs . stack_ ) ; <nl> - parseResult_ = rhs . parseResult_ ; <nl> - <nl> - rhs . allocator_ = 0 ; <nl> - rhs . ownAllocator_ = 0 ; <nl> - rhs . parseResult_ = ParseResult ( ) ; <nl> - <nl> - return * this ; <nl> - } <nl> - # endif <nl> - <nl> - / / ! @ name Parse from stream <nl> - / / ! @ { <nl> - <nl> - / / ! Parse JSON text from an input stream ( with Encoding conversion ) <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag . <nl> - \ tparam SourceEncoding Encoding of input stream <nl> - \ tparam InputStream Type of input stream , implementing Stream concept <nl> - \ param is Input stream to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - template < unsigned parseFlags , typename SourceEncoding , typename InputStream > <nl> - GenericDocument & ParseStream ( InputStream & is ) { <nl> - ValueType : : SetNull ( ) ; / / Remove existing root if exist <nl> - GenericReader < SourceEncoding , Encoding , Allocator > reader ( & GetAllocator ( ) ) ; <nl> - ClearStackOnExit scope ( * this ) ; <nl> - parseResult_ = reader . template Parse < parseFlags > ( is , * this ) ; <nl> - if ( parseResult_ ) { <nl> - RAPIDJSON_ASSERT ( stack_ . GetSize ( ) = = sizeof ( ValueType ) ) ; / / Got one and only one root object <nl> - this - > RawAssign ( * stack_ . template Pop < ValueType > ( 1 ) ) ; / / Add this - > to prevent issue 13 . <nl> - } <nl> - return * this ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from an input stream <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag . <nl> - \ tparam InputStream Type of input stream , implementing Stream concept <nl> - \ param is Input stream to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - template < unsigned parseFlags , typename InputStream > <nl> - GenericDocument & ParseStream ( InputStream & is ) { <nl> - return ParseStream < parseFlags , Encoding , InputStream > ( is ) ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from an input stream ( with \ ref kParseDefaultFlags ) <nl> - / * ! \ tparam InputStream Type of input stream , implementing Stream concept <nl> - \ param is Input stream to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - template < typename InputStream > <nl> - GenericDocument & ParseStream ( InputStream & is ) { <nl> - return ParseStream < kParseDefaultFlags , Encoding , InputStream > ( is ) ; <nl> - } <nl> - / / ! @ } <nl> - <nl> - / / ! @ name Parse in - place from mutable string <nl> - / / ! @ { <nl> - <nl> - / / ! Parse JSON text from a mutable string ( with Encoding conversion ) <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag . <nl> - \ tparam SourceEncoding Transcoding from input Encoding <nl> - \ param str Mutable zero - terminated string to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - template < unsigned parseFlags , typename SourceEncoding > <nl> - GenericDocument & ParseInsitu ( Ch * str ) { <nl> - GenericInsituStringStream < Encoding > s ( str ) ; <nl> - return ParseStream < parseFlags | kParseInsituFlag , SourceEncoding > ( s ) ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from a mutable string <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag . <nl> - \ param str Mutable zero - terminated string to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - template < unsigned parseFlags > <nl> - GenericDocument & ParseInsitu ( Ch * str ) { <nl> - return ParseInsitu < parseFlags , Encoding > ( str ) ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from a mutable string ( with \ ref kParseDefaultFlags ) <nl> - / * ! \ param str Mutable zero - terminated string to be parsed . <nl> - \ return The document itself for fluent API . <nl> - * / <nl> - GenericDocument & ParseInsitu ( Ch * str ) { <nl> - return ParseInsitu < kParseDefaultFlags , Encoding > ( str ) ; <nl> - } <nl> - / / ! @ } <nl> - <nl> - / / ! @ name Parse from read - only string <nl> - / / ! @ { <nl> - <nl> - / / ! Parse JSON text from a read - only string ( with Encoding conversion ) <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag ( must not contain \ ref kParseInsituFlag ) . <nl> - \ tparam SourceEncoding Transcoding from input Encoding <nl> - \ param str Read - only zero - terminated string to be parsed . <nl> - * / <nl> - template < unsigned parseFlags , typename SourceEncoding > <nl> - GenericDocument & Parse ( const Ch * str ) { <nl> - RAPIDJSON_ASSERT ( ! ( parseFlags & kParseInsituFlag ) ) ; <nl> - GenericStringStream < SourceEncoding > s ( str ) ; <nl> - return ParseStream < parseFlags , SourceEncoding > ( s ) ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from a read - only string <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag ( must not contain \ ref kParseInsituFlag ) . <nl> - \ param str Read - only zero - terminated string to be parsed . <nl> - * / <nl> - template < unsigned parseFlags > <nl> - GenericDocument & Parse ( const Ch * str ) { <nl> - return Parse < parseFlags , Encoding > ( str ) ; <nl> - } <nl> - <nl> - / / ! Parse JSON text from a read - only string ( with \ ref kParseDefaultFlags ) <nl> - / * ! \ param str Read - only zero - terminated string to be parsed . <nl> - * / <nl> - GenericDocument & Parse ( const Ch * str ) { <nl> - return Parse < kParseDefaultFlags > ( str ) ; <nl> - } <nl> - / / ! @ } <nl> - <nl> - / / ! @ name Handling parse errors <nl> - / / ! @ { <nl> - <nl> - / / ! Whether a parse error has occured in the last parsing . <nl> - bool HasParseError ( ) const { return parseResult_ . IsError ( ) ; } <nl> - <nl> - / / ! Get the \ ref ParseErrorCode of last parsing . <nl> - ParseErrorCode GetParseError ( ) const { return parseResult_ . Code ( ) ; } <nl> - <nl> - / / ! Get the position of last parsing error in input , 0 otherwise . <nl> - size_t GetErrorOffset ( ) const { return parseResult_ . Offset ( ) ; } <nl> - <nl> - / / ! @ } <nl> - <nl> - / / ! Get the allocator of this document . <nl> - Allocator & GetAllocator ( ) { return * allocator_ ; } <nl> - <nl> - / / ! Get the capacity of stack in bytes . <nl> - size_t GetStackCapacity ( ) const { return stack_ . GetCapacity ( ) ; } <nl> - <nl> - private : <nl> - / / clear stack on any exit from ParseStream , e . g . due to exception <nl> - struct ClearStackOnExit { <nl> - explicit ClearStackOnExit ( GenericDocument & d ) : d_ ( d ) { } <nl> - ~ ClearStackOnExit ( ) { d_ . ClearStack ( ) ; } <nl> - private : <nl> - ClearStackOnExit ( const ClearStackOnExit & ) ; <nl> - ClearStackOnExit & operator = ( const ClearStackOnExit & ) ; <nl> - GenericDocument & d_ ; <nl> - } ; <nl> - <nl> - / / callers of the following private Handler functions <nl> - template < typename , typename , typename > friend class GenericReader ; / / for parsing <nl> - template < typename , typename > friend class GenericValue ; / / for deep copying <nl> - <nl> - / / Implementation of Handler <nl> - bool Null ( ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( ) ; return true ; } <nl> - bool Bool ( bool b ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( b ) ; return true ; } <nl> - bool Int ( int i ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( i ) ; return true ; } <nl> - bool Uint ( unsigned i ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( i ) ; return true ; } <nl> - bool Int64 ( int64_t i ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( i ) ; return true ; } <nl> - bool Uint64 ( uint64_t i ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( i ) ; return true ; } <nl> - bool Double ( double d ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( d ) ; return true ; } <nl> - <nl> - bool String ( const Ch * str , SizeType length , bool copy ) { <nl> - if ( copy ) <nl> - new ( stack_ . template Push < ValueType > ( ) ) ValueType ( str , length , GetAllocator ( ) ) ; <nl> - else <nl> - new ( stack_ . template Push < ValueType > ( ) ) ValueType ( str , length ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool StartObject ( ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( kObjectType ) ; return true ; } <nl> - <nl> - bool Key ( const Ch * str , SizeType length , bool copy ) { return String ( str , length , copy ) ; } <nl> - <nl> - bool EndObject ( SizeType memberCount ) { <nl> - typename ValueType : : Member * members = stack_ . template Pop < typename ValueType : : Member > ( memberCount ) ; <nl> - stack_ . template Top < ValueType > ( ) - > SetObjectRaw ( members , ( SizeType ) memberCount , GetAllocator ( ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool StartArray ( ) { new ( stack_ . template Push < ValueType > ( ) ) ValueType ( kArrayType ) ; return true ; } <nl> - <nl> - bool EndArray ( SizeType elementCount ) { <nl> - ValueType * elements = stack_ . template Pop < ValueType > ( elementCount ) ; <nl> - stack_ . template Top < ValueType > ( ) - > SetArrayRaw ( elements , elementCount , GetAllocator ( ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - private : <nl> - / / ! Prohibit assignment <nl> - GenericDocument & operator = ( const GenericDocument & ) ; <nl> - <nl> - void ClearStack ( ) { <nl> - if ( Allocator : : kNeedFree ) <nl> - while ( stack_ . GetSize ( ) > 0 ) / / Here assumes all elements in stack array are GenericValue ( Member is actually 2 GenericValue objects ) <nl> - ( stack_ . template Pop < ValueType > ( 1 ) ) - > ~ ValueType ( ) ; <nl> - else <nl> - stack_ . Clear ( ) ; <nl> - stack_ . ShrinkToFit ( ) ; <nl> - } <nl> - <nl> - void Destroy ( ) { <nl> - delete ownAllocator_ ; <nl> - } <nl> - <nl> - static const size_t kDefaultStackCapacity = 1024 ; <nl> - Allocator * allocator_ ; <nl> - Allocator * ownAllocator_ ; <nl> - internal : : Stack < StackAllocator > stack_ ; <nl> - ParseResult parseResult_ ; <nl> - } ; <nl> - <nl> - / / ! GenericDocument with UTF8 encoding <nl> - typedef GenericDocument < UTF8 < > > Document ; <nl> - <nl> - / / defined here due to the dependency on GenericDocument <nl> - template < typename Encoding , typename Allocator > <nl> - template < typename SourceAllocator > <nl> - inline <nl> - GenericValue < Encoding , Allocator > : : GenericValue ( const GenericValue < Encoding , SourceAllocator > & rhs , Allocator & allocator ) <nl> - { <nl> - GenericDocument < Encoding , Allocator > d ( & allocator ) ; <nl> - rhs . Accept ( d ) ; <nl> - RawAssign ( * d . stack_ . template Pop < GenericValue > ( 1 ) ) ; <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # if defined ( _MSC_VER ) | | defined ( __GNUC__ ) <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_DOCUMENT_H_ <nl> deleted file mode 100644 <nl> index 9dc00c7afc3 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / encodedstream . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ENCODEDSTREAM_H_ <nl> - # define RAPIDJSON_ENCODEDSTREAM_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Input byte stream wrapper with a statically bound encoding . <nl> - / * ! <nl> - \ tparam Encoding The interpretation of encoding of the stream . Either UTF8 , UTF16LE , UTF16BE , UTF32LE , UTF32BE . <nl> - \ tparam InputByteStream Type of input byte stream . For example , FileReadStream . <nl> - * / <nl> - template < typename Encoding , typename InputByteStream > <nl> - class EncodedInputStream { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - public : <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - EncodedInputStream ( InputByteStream & is ) : is_ ( is ) { <nl> - current_ = Encoding : : TakeBOM ( is_ ) ; <nl> - } <nl> - <nl> - Ch Peek ( ) const { return current_ ; } <nl> - Ch Take ( ) { Ch c = current_ ; current_ = Encoding : : Take ( is_ ) ; return c ; } <nl> - size_t Tell ( ) const { return is_ . Tell ( ) ; } <nl> - <nl> - / / Not implemented <nl> - void Put ( Ch ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - void Flush ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - private : <nl> - EncodedInputStream ( const EncodedInputStream & ) ; <nl> - EncodedInputStream & operator = ( const EncodedInputStream & ) ; <nl> - <nl> - InputByteStream & is_ ; <nl> - Ch current_ ; <nl> - } ; <nl> - <nl> - / / ! Output byte stream wrapper with statically bound encoding . <nl> - / * ! <nl> - \ tparam Encoding The interpretation of encoding of the stream . Either UTF8 , UTF16LE , UTF16BE , UTF32LE , UTF32BE . <nl> - \ tparam InputByteStream Type of input byte stream . For example , FileWriteStream . <nl> - * / <nl> - template < typename Encoding , typename OutputByteStream > <nl> - class EncodedOutputStream { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - public : <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - EncodedOutputStream ( OutputByteStream & os , bool putBOM = true ) : os_ ( os ) { <nl> - if ( putBOM ) <nl> - Encoding : : PutBOM ( os_ ) ; <nl> - } <nl> - <nl> - void Put ( Ch c ) { Encoding : : Put ( os_ , c ) ; } <nl> - void Flush ( ) { os_ . Flush ( ) ; } <nl> - <nl> - / / Not implemented <nl> - Ch Peek ( ) const { RAPIDJSON_ASSERT ( false ) ; } <nl> - Ch Take ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - size_t Tell ( ) const { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - private : <nl> - EncodedOutputStream ( const EncodedOutputStream & ) ; <nl> - EncodedOutputStream & operator = ( const EncodedOutputStream & ) ; <nl> - <nl> - OutputByteStream & os_ ; <nl> - } ; <nl> - <nl> - # define RAPIDJSON_ENCODINGS_FUNC ( x ) UTF8 < Ch > : : x , UTF16LE < Ch > : : x , UTF16BE < Ch > : : x , UTF32LE < Ch > : : x , UTF32BE < Ch > : : x <nl> - <nl> - / / ! Input stream wrapper with dynamically bound encoding and automatic encoding detection . <nl> - / * ! <nl> - \ tparam CharType Type of character for reading . <nl> - \ tparam InputByteStream type of input byte stream to be wrapped . <nl> - * / <nl> - template < typename CharType , typename InputByteStream > <nl> - class AutoUTFInputStream { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - public : <nl> - typedef CharType Ch ; <nl> - <nl> - / / ! Constructor . <nl> - / * ! <nl> - \ param is input stream to be wrapped . <nl> - \ param type UTF encoding type if it is not detected from the stream . <nl> - * / <nl> - AutoUTFInputStream ( InputByteStream & is , UTFType type = kUTF8 ) : is_ ( & is ) , type_ ( type ) , hasBOM_ ( false ) { <nl> - DetectType ( ) ; <nl> - static const TakeFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( Take ) } ; <nl> - takeFunc_ = f [ type_ ] ; <nl> - current_ = takeFunc_ ( * is_ ) ; <nl> - } <nl> - <nl> - UTFType GetType ( ) const { return type_ ; } <nl> - bool HasBOM ( ) const { return hasBOM_ ; } <nl> - <nl> - Ch Peek ( ) const { return current_ ; } <nl> - Ch Take ( ) { Ch c = current_ ; current_ = takeFunc_ ( * is_ ) ; return c ; } <nl> - size_t Tell ( ) const { return is_ - > Tell ( ) ; } <nl> - <nl> - / / Not implemented <nl> - void Put ( Ch ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - void Flush ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - private : <nl> - AutoUTFInputStream ( const AutoUTFInputStream & ) ; <nl> - AutoUTFInputStream & operator = ( const AutoUTFInputStream & ) ; <nl> - <nl> - / / Detect encoding type with BOM or RFC 4627 <nl> - void DetectType ( ) { <nl> - / / BOM ( Byte Order Mark ) : <nl> - / / 00 00 FE FF UTF - 32BE <nl> - / / FF FE 00 00 UTF - 32LE <nl> - / / FE FF UTF - 16BE <nl> - / / FF FE UTF - 16LE <nl> - / / EF BB BF UTF - 8 <nl> - <nl> - const unsigned char * c = ( const unsigned char * ) is_ - > Peek4 ( ) ; <nl> - if ( ! c ) <nl> - return ; <nl> - <nl> - unsigned bom = c [ 0 ] | ( c [ 1 ] < < 8 ) | ( c [ 2 ] < < 16 ) | ( c [ 3 ] < < 24 ) ; <nl> - hasBOM_ = false ; <nl> - if ( bom = = 0xFFFE0000 ) { type_ = kUTF32BE ; hasBOM_ = true ; is_ - > Take ( ) ; is_ - > Take ( ) ; is_ - > Take ( ) ; is_ - > Take ( ) ; } <nl> - else if ( bom = = 0x0000FEFF ) { type_ = kUTF32LE ; hasBOM_ = true ; is_ - > Take ( ) ; is_ - > Take ( ) ; is_ - > Take ( ) ; is_ - > Take ( ) ; } <nl> - else if ( ( bom & 0xFFFF ) = = 0xFFFE ) { type_ = kUTF16BE ; hasBOM_ = true ; is_ - > Take ( ) ; is_ - > Take ( ) ; } <nl> - else if ( ( bom & 0xFFFF ) = = 0xFEFF ) { type_ = kUTF16LE ; hasBOM_ = true ; is_ - > Take ( ) ; is_ - > Take ( ) ; } <nl> - else if ( ( bom & 0xFFFFFF ) = = 0xBFBBEF ) { type_ = kUTF8 ; hasBOM_ = true ; is_ - > Take ( ) ; is_ - > Take ( ) ; is_ - > Take ( ) ; } <nl> - <nl> - / / RFC 4627 : Section 3 <nl> - / / " Since the first two characters of a JSON text will always be ASCII <nl> - / / characters [ RFC0020 ] , it is possible to determine whether an octet <nl> - / / stream is UTF - 8 , UTF - 16 ( BE or LE ) , or UTF - 32 ( BE or LE ) by looking <nl> - / / at the pattern of nulls in the first four octets . " <nl> - / / 00 00 00 xx UTF - 32BE <nl> - / / 00 xx 00 xx UTF - 16BE <nl> - / / xx 00 00 00 UTF - 32LE <nl> - / / xx 00 xx 00 UTF - 16LE <nl> - / / xx xx xx xx UTF - 8 <nl> - <nl> - if ( ! hasBOM_ ) { <nl> - unsigned pattern = ( c [ 0 ] ? 1 : 0 ) | ( c [ 1 ] ? 2 : 0 ) | ( c [ 2 ] ? 4 : 0 ) | ( c [ 3 ] ? 8 : 0 ) ; <nl> - switch ( pattern ) { <nl> - case 0x08 : type_ = kUTF32BE ; break ; <nl> - case 0x0A : type_ = kUTF16BE ; break ; <nl> - case 0x01 : type_ = kUTF32LE ; break ; <nl> - case 0x05 : type_ = kUTF16LE ; break ; <nl> - case 0x0F : type_ = kUTF8 ; break ; <nl> - default : break ; / / Use type defined by user . <nl> - } <nl> - } <nl> - <nl> - / / Runtime check whether the size of character type is sufficient . It only perform checks with assertion . <nl> - switch ( type_ ) { <nl> - case kUTF8 : <nl> - / / Do nothing <nl> - break ; <nl> - case kUTF16LE : <nl> - case kUTF16BE : <nl> - RAPIDJSON_ASSERT ( sizeof ( Ch ) > = 2 ) ; <nl> - break ; <nl> - case kUTF32LE : <nl> - case kUTF32BE : <nl> - RAPIDJSON_ASSERT ( sizeof ( Ch ) > = 4 ) ; <nl> - break ; <nl> - default : <nl> - RAPIDJSON_ASSERT ( false ) ; / / Invalid type <nl> - } <nl> - } <nl> - <nl> - typedef Ch ( * TakeFunc ) ( InputByteStream & is ) ; <nl> - InputByteStream * is_ ; <nl> - UTFType type_ ; <nl> - Ch current_ ; <nl> - TakeFunc takeFunc_ ; <nl> - bool hasBOM_ ; <nl> - } ; <nl> - <nl> - / / ! Output stream wrapper with dynamically bound encoding and automatic encoding detection . <nl> - / * ! <nl> - \ tparam CharType Type of character for writing . <nl> - \ tparam InputByteStream type of output byte stream to be wrapped . <nl> - * / <nl> - template < typename CharType , typename OutputByteStream > <nl> - class AutoUTFOutputStream { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - public : <nl> - typedef CharType Ch ; <nl> - <nl> - / / ! Constructor . <nl> - / * ! <nl> - \ param os output stream to be wrapped . <nl> - \ param type UTF encoding type . <nl> - \ param putBOM Whether to write BOM at the beginning of the stream . <nl> - * / <nl> - AutoUTFOutputStream ( OutputByteStream & os , UTFType type , bool putBOM ) : os_ ( & os ) , type_ ( type ) { <nl> - / / RUntime check whether the size of character type is sufficient . It only perform checks with assertion . <nl> - switch ( type_ ) { <nl> - case kUTF16LE : <nl> - case kUTF16BE : <nl> - RAPIDJSON_ASSERT ( sizeof ( Ch ) > = 2 ) ; <nl> - break ; <nl> - case kUTF32LE : <nl> - case kUTF32BE : <nl> - RAPIDJSON_ASSERT ( sizeof ( Ch ) > = 4 ) ; <nl> - break ; <nl> - case kUTF8 : <nl> - / / Do nothing <nl> - break ; <nl> - default : <nl> - RAPIDJSON_ASSERT ( false ) ; / / Invalid UTFType <nl> - } <nl> - <nl> - static const PutFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( Put ) } ; <nl> - putFunc_ = f [ type_ ] ; <nl> - <nl> - if ( putBOM ) <nl> - PutBOM ( ) ; <nl> - } <nl> - <nl> - UTFType GetType ( ) const { return type_ ; } <nl> - <nl> - void Put ( Ch c ) { putFunc_ ( * os_ , c ) ; } <nl> - void Flush ( ) { os_ - > Flush ( ) ; } <nl> - <nl> - / / Not implemented <nl> - Ch Peek ( ) const { RAPIDJSON_ASSERT ( false ) ; } <nl> - Ch Take ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - size_t Tell ( ) const { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - private : <nl> - AutoUTFOutputStream ( const AutoUTFOutputStream & ) ; <nl> - AutoUTFOutputStream & operator = ( const AutoUTFOutputStream & ) ; <nl> - <nl> - void PutBOM ( ) { <nl> - typedef void ( * PutBOMFunc ) ( OutputByteStream & ) ; <nl> - static const PutBOMFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( PutBOM ) } ; <nl> - f [ type_ ] ( * os_ ) ; <nl> - } <nl> - <nl> - typedef void ( * PutFunc ) ( OutputByteStream & , Ch ) ; <nl> - <nl> - OutputByteStream * os_ ; <nl> - UTFType type_ ; <nl> - PutFunc putFunc_ ; <nl> - } ; <nl> - <nl> - # undef RAPIDJSON_ENCODINGS_FUNC <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_FILESTREAM_H_ <nl> deleted file mode 100644 <nl> index 5c7da3e048c . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / encodings . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ENCODINGS_H_ <nl> - # define RAPIDJSON_ENCODINGS_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( 4244 ) / / conversion from ' type1 ' to ' type2 ' , possible loss of data <nl> - RAPIDJSON_DIAG_OFF ( 4702 ) / / unreachable code <nl> - # elif defined ( __GNUC__ ) <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Encoding <nl> - <nl> - / * ! \ class rapidjson : : Encoding <nl> - \ brief Concept for encoding of Unicode characters . <nl> - <nl> - \ code <nl> - concept Encoding { <nl> - typename Ch ; / / ! Type of character . A " character " is actually a code unit in unicode ' s definition . <nl> - <nl> - enum { supportUnicode = 1 } ; / / or 0 if not supporting unicode <nl> - <nl> - / / ! \ brief Encode a Unicode codepoint to an output stream . <nl> - / / ! \ param os Output stream . <nl> - / / ! \ param codepoint An unicode codepoint , ranging from 0x0 to 0x10FFFF inclusively . <nl> - template < typename OutputStream > <nl> - static void Encode ( OutputStream & os , unsigned codepoint ) ; <nl> - <nl> - / / ! \ brief Decode a Unicode codepoint from an input stream . <nl> - / / ! \ param is Input stream . <nl> - / / ! \ param codepoint Output of the unicode codepoint . <nl> - / / ! \ return true if a valid codepoint can be decoded from the stream . <nl> - template < typename InputStream > <nl> - static bool Decode ( InputStream & is , unsigned * codepoint ) ; <nl> - <nl> - / / ! \ brief Validate one Unicode codepoint from an encoded stream . <nl> - / / ! \ param is Input stream to obtain codepoint . <nl> - / / ! \ param os Output for copying one codepoint . <nl> - / / ! \ return true if it is valid . <nl> - / / ! \ note This function just validating and copying the codepoint without actually decode it . <nl> - template < typename InputStream , typename OutputStream > <nl> - static bool Validate ( InputStream & is , OutputStream & os ) ; <nl> - <nl> - / / The following functions are deal with byte streams . <nl> - <nl> - / / ! Take a character from input byte stream , skip BOM if exist . <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) ; <nl> - <nl> - / / ! Take a character from input byte stream . <nl> - template < typename InputByteStream > <nl> - static Ch Take ( InputByteStream & is ) ; <nl> - <nl> - / / ! Put BOM to output byte stream . <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) ; <nl> - <nl> - / / ! Put a character to output byte stream . <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , Ch c ) ; <nl> - } ; <nl> - \ endcode <nl> - * / <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / UTF8 <nl> - <nl> - / / ! UTF - 8 encoding . <nl> - / * ! http : / / en . wikipedia . org / wiki / UTF - 8 <nl> - http : / / tools . ietf . org / html / rfc3629 <nl> - \ tparam CharType Code unit for storing 8 - bit UTF - 8 data . Default is char . <nl> - \ note implements Encoding concept <nl> - * / <nl> - template < typename CharType = char > <nl> - struct UTF8 { <nl> - typedef CharType Ch ; <nl> - <nl> - enum { supportUnicode = 1 } ; <nl> - <nl> - template < typename OutputStream > <nl> - static void Encode ( OutputStream & os , unsigned codepoint ) { <nl> - if ( codepoint < = 0x7F ) <nl> - os . Put ( static_cast < Ch > ( codepoint & 0xFF ) ) ; <nl> - else if ( codepoint < = 0x7FF ) { <nl> - os . Put ( static_cast < Ch > ( 0xC0 | ( ( codepoint > > 6 ) & 0xFF ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( ( codepoint & 0x3F ) ) ) ) ; <nl> - } <nl> - else if ( codepoint < = 0xFFFF ) { <nl> - os . Put ( static_cast < Ch > ( 0xE0 | ( ( codepoint > > 12 ) & 0xFF ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( ( codepoint > > 6 ) & 0x3F ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( codepoint & 0x3F ) ) ) ; <nl> - } <nl> - else { <nl> - RAPIDJSON_ASSERT ( codepoint < = 0x10FFFF ) ; <nl> - os . Put ( static_cast < Ch > ( 0xF0 | ( ( codepoint > > 18 ) & 0xFF ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( ( codepoint > > 12 ) & 0x3F ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( ( codepoint > > 6 ) & 0x3F ) ) ) ; <nl> - os . Put ( static_cast < Ch > ( 0x80 | ( codepoint & 0x3F ) ) ) ; <nl> - } <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - static bool Decode ( InputStream & is , unsigned * codepoint ) { <nl> - # define COPY ( ) c = is . Take ( ) ; * codepoint = ( * codepoint < < 6 ) | ( ( unsigned char ) c & 0x3Fu ) <nl> - # define TRANS ( mask ) result & = ( ( GetRange ( ( unsigned char ) c ) & mask ) ! = 0 ) <nl> - # define TAIL ( ) COPY ( ) ; TRANS ( 0x70 ) <nl> - Ch c = is . Take ( ) ; <nl> - if ( ! ( c & 0x80 ) ) { <nl> - * codepoint = ( unsigned char ) c ; <nl> - return true ; <nl> - } <nl> - <nl> - unsigned char type = GetRange ( ( unsigned char ) c ) ; <nl> - * codepoint = ( 0xFF > > type ) & ( unsigned char ) c ; <nl> - bool result = true ; <nl> - switch ( type ) { <nl> - case 2 : TAIL ( ) ; return result ; <nl> - case 3 : TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 4 : COPY ( ) ; TRANS ( 0x50 ) ; TAIL ( ) ; return result ; <nl> - case 5 : COPY ( ) ; TRANS ( 0x10 ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 6 : TAIL ( ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 10 : COPY ( ) ; TRANS ( 0x20 ) ; TAIL ( ) ; return result ; <nl> - case 11 : COPY ( ) ; TRANS ( 0x60 ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - default : return false ; <nl> - } <nl> - # undef COPY <nl> - # undef TRANS <nl> - # undef TAIL <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - # define COPY ( ) os . Put ( c = is . Take ( ) ) <nl> - # define TRANS ( mask ) result & = ( ( GetRange ( ( unsigned char ) c ) & mask ) ! = 0 ) <nl> - # define TAIL ( ) COPY ( ) ; TRANS ( 0x70 ) <nl> - Ch c ; <nl> - COPY ( ) ; <nl> - if ( ! ( c & 0x80 ) ) <nl> - return true ; <nl> - <nl> - bool result = true ; <nl> - switch ( GetRange ( ( unsigned char ) c ) ) { <nl> - case 2 : TAIL ( ) ; return result ; <nl> - case 3 : TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 4 : COPY ( ) ; TRANS ( 0x50 ) ; TAIL ( ) ; return result ; <nl> - case 5 : COPY ( ) ; TRANS ( 0x10 ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 6 : TAIL ( ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - case 10 : COPY ( ) ; TRANS ( 0x20 ) ; TAIL ( ) ; return result ; <nl> - case 11 : COPY ( ) ; TRANS ( 0x60 ) ; TAIL ( ) ; TAIL ( ) ; return result ; <nl> - default : return false ; <nl> - } <nl> - # undef COPY <nl> - # undef TRANS <nl> - # undef TAIL <nl> - } <nl> - <nl> - static unsigned char GetRange ( unsigned char c ) { <nl> - / / Referring to DFA of http : / / bjoern . hoehrmann . de / utf - 8 / decoder / dfa / <nl> - / / With new mapping 1 - > 0x10 , 7 - > 0x20 , 9 - > 0x40 , such that AND operation can test multiple types . <nl> - static const unsigned char type [ ] = { <nl> - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , <nl> - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , <nl> - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , <nl> - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , <nl> - 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , <nl> - 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , <nl> - 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , <nl> - 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , 0x20 , <nl> - 8 , 8 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , <nl> - 10 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 3 , 3 , 11 , 6 , 6 , 6 , 5 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , <nl> - } ; <nl> - return type [ c ] ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - Ch c = Take ( is ) ; <nl> - if ( ( unsigned char ) c ! = 0xEFu ) return c ; <nl> - c = is . Take ( ) ; <nl> - if ( ( unsigned char ) c ! = 0xBBu ) return c ; <nl> - c = is . Take ( ) ; <nl> - if ( ( unsigned char ) c ! = 0xBFu ) return c ; <nl> - c = is . Take ( ) ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static Ch Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - return is . Take ( ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( 0xEFu ) ; os . Put ( 0xBBu ) ; os . Put ( 0xBFu ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , Ch c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( static_cast < typename OutputByteStream : : Ch > ( c ) ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / UTF16 <nl> - <nl> - / / ! UTF - 16 encoding . <nl> - / * ! http : / / en . wikipedia . org / wiki / UTF - 16 <nl> - http : / / tools . ietf . org / html / rfc2781 <nl> - \ tparam CharType Type for storing 16 - bit UTF - 16 data . Default is wchar_t . C + + 11 may use char16_t instead . <nl> - \ note implements Encoding concept <nl> - <nl> - \ note For in - memory access , no need to concern endianness . The code units and code points are represented by CPU ' s endianness . <nl> - For streaming , use UTF16LE and UTF16BE , which handle endianness . <nl> - * / <nl> - template < typename CharType = wchar_t > <nl> - struct UTF16 { <nl> - typedef CharType Ch ; <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( Ch ) > = 2 ) ; <nl> - <nl> - enum { supportUnicode = 1 } ; <nl> - <nl> - template < typename OutputStream > <nl> - static void Encode ( OutputStream & os , unsigned codepoint ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputStream : : Ch ) > = 2 ) ; <nl> - if ( codepoint < = 0xFFFF ) { <nl> - RAPIDJSON_ASSERT ( codepoint < 0xD800 | | codepoint > 0xDFFF ) ; / / Code point itself cannot be surrogate pair <nl> - os . Put ( static_cast < typename OutputStream : : Ch > ( codepoint ) ) ; <nl> - } <nl> - else { <nl> - RAPIDJSON_ASSERT ( codepoint < = 0x10FFFF ) ; <nl> - unsigned v = codepoint - 0x10000 ; <nl> - os . Put ( static_cast < typename OutputStream : : Ch > ( ( v > > 10 ) | 0xD800 ) ) ; <nl> - os . Put ( ( v & 0x3FF ) | 0xDC00 ) ; <nl> - } <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - static bool Decode ( InputStream & is , unsigned * codepoint ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputStream : : Ch ) > = 2 ) ; <nl> - Ch c = is . Take ( ) ; <nl> - if ( c < 0xD800 | | c > 0xDFFF ) { <nl> - * codepoint = c ; <nl> - return true ; <nl> - } <nl> - else if ( c < = 0xDBFF ) { <nl> - * codepoint = ( c & 0x3FF ) < < 10 ; <nl> - c = is . Take ( ) ; <nl> - * codepoint | = ( c & 0x3FF ) ; <nl> - * codepoint + = 0x10000 ; <nl> - return c > = 0xDC00 & & c < = 0xDFFF ; <nl> - } <nl> - return false ; <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputStream : : Ch ) > = 2 ) ; <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputStream : : Ch ) > = 2 ) ; <nl> - Ch c ; <nl> - os . Put ( c = is . Take ( ) ) ; <nl> - if ( c < 0xD800 | | c > 0xDFFF ) <nl> - return true ; <nl> - else if ( c < = 0xDBFF ) { <nl> - os . Put ( c = is . Take ( ) ) ; <nl> - return c > = 0xDC00 & & c < = 0xDFFF ; <nl> - } <nl> - return false ; <nl> - } <nl> - } ; <nl> - <nl> - / / ! UTF - 16 little endian encoding . <nl> - template < typename CharType = wchar_t > <nl> - struct UTF16LE : UTF16 < CharType > { <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = Take ( is ) ; <nl> - return ( unsigned short ) c = = 0xFEFFu ? Take ( is ) : c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = ( unsigned char ) is . Take ( ) ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 8 ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( 0xFFu ) ; os . Put ( 0xFEu ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , CharType c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( c & 0xFFu ) ; <nl> - os . Put ( ( c > > 8 ) & 0xFFu ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / ! UTF - 16 big endian encoding . <nl> - template < typename CharType = wchar_t > <nl> - struct UTF16BE : UTF16 < CharType > { <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = Take ( is ) ; <nl> - return ( unsigned short ) c = = 0xFEFFu ? Take ( is ) : c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = ( unsigned char ) is . Take ( ) < < 8 ; <nl> - c | = ( unsigned char ) is . Take ( ) ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( 0xFEu ) ; os . Put ( 0xFFu ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , CharType c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( ( c > > 8 ) & 0xFFu ) ; <nl> - os . Put ( c & 0xFFu ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / UTF32 <nl> - <nl> - / / ! UTF - 32 encoding . <nl> - / * ! http : / / en . wikipedia . org / wiki / UTF - 32 <nl> - \ tparam CharType Type for storing 32 - bit UTF - 32 data . Default is unsigned . C + + 11 may use char32_t instead . <nl> - \ note implements Encoding concept <nl> - <nl> - \ note For in - memory access , no need to concern endianness . The code units and code points are represented by CPU ' s endianness . <nl> - For streaming , use UTF32LE and UTF32BE , which handle endianness . <nl> - * / <nl> - template < typename CharType = unsigned > <nl> - struct UTF32 { <nl> - typedef CharType Ch ; <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( Ch ) > = 4 ) ; <nl> - <nl> - enum { supportUnicode = 1 } ; <nl> - <nl> - template < typename OutputStream > <nl> - static void Encode ( OutputStream & os , unsigned codepoint ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputStream : : Ch ) > = 4 ) ; <nl> - RAPIDJSON_ASSERT ( codepoint < = 0x10FFFF ) ; <nl> - os . Put ( codepoint ) ; <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - static bool Decode ( InputStream & is , unsigned * codepoint ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputStream : : Ch ) > = 4 ) ; <nl> - Ch c = is . Take ( ) ; <nl> - * codepoint = c ; <nl> - return c < = 0x10FFFF ; <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputStream : : Ch ) > = 4 ) ; <nl> - Ch c ; <nl> - os . Put ( c = is . Take ( ) ) ; <nl> - return c < = 0x10FFFF ; <nl> - } <nl> - } ; <nl> - <nl> - / / ! UTF - 32 little endian enocoding . <nl> - template < typename CharType = unsigned > <nl> - struct UTF32LE : UTF32 < CharType > { <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = Take ( is ) ; <nl> - return ( unsigned ) c = = 0x0000FEFFu ? Take ( is ) : c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = ( unsigned char ) is . Take ( ) ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 8 ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 16 ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 24 ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( 0xFFu ) ; os . Put ( 0xFEu ) ; os . Put ( 0x00u ) ; os . Put ( 0x00u ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , CharType c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( c & 0xFFu ) ; <nl> - os . Put ( ( c > > 8 ) & 0xFFu ) ; <nl> - os . Put ( ( c > > 16 ) & 0xFFu ) ; <nl> - os . Put ( ( c > > 24 ) & 0xFFu ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / ! UTF - 32 big endian encoding . <nl> - template < typename CharType = unsigned > <nl> - struct UTF32BE : UTF32 < CharType > { <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = Take ( is ) ; <nl> - return ( unsigned ) c = = 0x0000FEFFu ? Take ( is ) : c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - CharType c = ( unsigned char ) is . Take ( ) < < 24 ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 16 ; <nl> - c | = ( unsigned char ) is . Take ( ) < < 8 ; <nl> - c | = ( unsigned char ) is . Take ( ) ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( 0x00u ) ; os . Put ( 0x00u ) ; os . Put ( 0xFEu ) ; os . Put ( 0xFFu ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , CharType c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( ( c > > 24 ) & 0xFFu ) ; <nl> - os . Put ( ( c > > 16 ) & 0xFFu ) ; <nl> - os . Put ( ( c > > 8 ) & 0xFFu ) ; <nl> - os . Put ( c & 0xFFu ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / ASCII <nl> - <nl> - / / ! ASCII encoding . <nl> - / * ! http : / / en . wikipedia . org / wiki / ASCII <nl> - \ tparam CharType Code unit for storing 7 - bit ASCII data . Default is char . <nl> - \ note implements Encoding concept <nl> - * / <nl> - template < typename CharType = char > <nl> - struct ASCII { <nl> - typedef CharType Ch ; <nl> - <nl> - enum { supportUnicode = 0 } ; <nl> - <nl> - template < typename OutputStream > <nl> - static void Encode ( OutputStream & os , unsigned codepoint ) { <nl> - RAPIDJSON_ASSERT ( codepoint < = 0x7F ) ; <nl> - os . Put ( static_cast < Ch > ( codepoint & 0xFF ) ) ; <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - static bool Decode ( InputStream & is , unsigned * codepoint ) { <nl> - unsigned char c = static_cast < unsigned char > ( is . Take ( ) ) ; <nl> - * codepoint = c ; <nl> - return c < = 0X7F ; <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - unsigned char c = is . Take ( ) ; <nl> - os . Put ( c ) ; <nl> - return c < = 0x7F ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static CharType TakeBOM ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - Ch c = Take ( is ) ; <nl> - return c ; <nl> - } <nl> - <nl> - template < typename InputByteStream > <nl> - static Ch Take ( InputByteStream & is ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename InputByteStream : : Ch ) = = 1 ) ; <nl> - return is . Take ( ) ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void PutBOM ( OutputByteStream & os ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - ( void ) os ; <nl> - } <nl> - <nl> - template < typename OutputByteStream > <nl> - static void Put ( OutputByteStream & os , Ch c ) { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( typename OutputByteStream : : Ch ) = = 1 ) ; <nl> - os . Put ( static_cast < typename OutputByteStream : : Ch > ( c ) ) ; <nl> - } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / AutoUTF <nl> - <nl> - / / ! Runtime - specified UTF encoding type of a stream . <nl> - enum UTFType { <nl> - kUTF8 = 0 , / / ! < UTF - 8 . <nl> - kUTF16LE = 1 , / / ! < UTF - 16 little endian . <nl> - kUTF16BE = 2 , / / ! < UTF - 16 big endian . <nl> - kUTF32LE = 3 , / / ! < UTF - 32 little endian . <nl> - kUTF32BE = 4 / / ! < UTF - 32 big endian . <nl> - } ; <nl> - <nl> - / / ! Dynamically select encoding according to stream ' s runtime - specified UTF encoding type . <nl> - / * ! \ note This class can be used with AutoUTFInputtStream and AutoUTFOutputStream , which provides GetType ( ) . <nl> - * / <nl> - template < typename CharType > <nl> - struct AutoUTF { <nl> - typedef CharType Ch ; <nl> - <nl> - enum { supportUnicode = 1 } ; <nl> - <nl> - # define RAPIDJSON_ENCODINGS_FUNC ( x ) UTF8 < Ch > : : x , UTF16LE < Ch > : : x , UTF16BE < Ch > : : x , UTF32LE < Ch > : : x , UTF32BE < Ch > : : x <nl> - <nl> - template < typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static void Encode ( OutputStream & os , unsigned codepoint ) { <nl> - typedef void ( * EncodeFunc ) ( OutputStream & , unsigned ) ; <nl> - static const EncodeFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( Encode ) } ; <nl> - ( * f [ os . GetType ( ) ] ) ( os , codepoint ) ; <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Decode ( InputStream & is , unsigned * codepoint ) { <nl> - typedef bool ( * DecodeFunc ) ( InputStream & , unsigned * ) ; <nl> - static const DecodeFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( Decode ) } ; <nl> - return ( * f [ is . GetType ( ) ] ) ( is , codepoint ) ; <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - typedef bool ( * ValidateFunc ) ( InputStream & , OutputStream & ) ; <nl> - static const ValidateFunc f [ ] = { RAPIDJSON_ENCODINGS_FUNC ( Validate ) } ; <nl> - return ( * f [ is . GetType ( ) ] ) ( is , os ) ; <nl> - } <nl> - <nl> - # undef RAPIDJSON_ENCODINGS_FUNC <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Transcoder <nl> - <nl> - / / ! Encoding conversion . <nl> - template < typename SourceEncoding , typename TargetEncoding > <nl> - struct Transcoder { <nl> - / / ! Take one Unicode codepoint from source encoding , convert it to target encoding and put it to the output stream . <nl> - template < typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Transcode ( InputStream & is , OutputStream & os ) { <nl> - unsigned codepoint ; <nl> - if ( ! SourceEncoding : : Decode ( is , & codepoint ) ) <nl> - return false ; <nl> - TargetEncoding : : Encode ( os , codepoint ) ; <nl> - return true ; <nl> - } <nl> - <nl> - / / ! Validate one Unicode codepoint from an encoded stream . <nl> - template < typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - return Transcode ( is , os ) ; / / Since source / target encoding is different , must transcode . <nl> - } <nl> - } ; <nl> - <nl> - / / ! Specialization of Transcoder with same source and target encoding . <nl> - template < typename Encoding > <nl> - struct Transcoder < Encoding , Encoding > { <nl> - template < typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Transcode ( InputStream & is , OutputStream & os ) { <nl> - os . Put ( is . Take ( ) ) ; / / Just copy one code unit . This semantic is different from primary template class . <nl> - return true ; <nl> - } <nl> - <nl> - template < typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE static bool Validate ( InputStream & is , OutputStream & os ) { <nl> - return Encoding : : Validate ( is , os ) ; / / source / target encoding are the same <nl> - } <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # if defined ( __GNUC__ ) | | defined ( _MSV_VER ) <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_ENCODINGS_H_ <nl> deleted file mode 100644 <nl> index d153e04fc84 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / error / en . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ERROR_EN_H__ <nl> - # define RAPIDJSON_ERROR_EN_H__ <nl> - <nl> - # include " error . h " <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Maps error code of parsing into error message . <nl> - / * ! <nl> - \ ingroup RAPIDJSON_ERRORS <nl> - \ param parseErrorCode Error code obtained in parsing . <nl> - \ return the error message . <nl> - \ note User can make a copy of this function for localization . <nl> - Using switch - case is safer for future modification of error codes . <nl> - * / <nl> - inline const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En ( ParseErrorCode parseErrorCode ) { <nl> - switch ( parseErrorCode ) { <nl> - case kParseErrorNone : return RAPIDJSON_ERROR_STRING ( " No error . " ) ; <nl> - <nl> - case kParseErrorDocumentEmpty : return RAPIDJSON_ERROR_STRING ( " The document is empty . " ) ; <nl> - case kParseErrorDocumentRootNotSingular : return RAPIDJSON_ERROR_STRING ( " The document root must not follow by other values . " ) ; <nl> - <nl> - case kParseErrorValueInvalid : return RAPIDJSON_ERROR_STRING ( " Invalid value . " ) ; <nl> - <nl> - case kParseErrorObjectMissName : return RAPIDJSON_ERROR_STRING ( " Missing a name for object member . " ) ; <nl> - case kParseErrorObjectMissColon : return RAPIDJSON_ERROR_STRING ( " Missing a colon after a name of object member . " ) ; <nl> - case kParseErrorObjectMissCommaOrCurlyBracket : return RAPIDJSON_ERROR_STRING ( " Missing a comma or ' } ' after an object member . " ) ; <nl> - <nl> - case kParseErrorArrayMissCommaOrSquareBracket : return RAPIDJSON_ERROR_STRING ( " Missing a comma or ' ] ' after an array element . " ) ; <nl> - <nl> - case kParseErrorStringUnicodeEscapeInvalidHex : return RAPIDJSON_ERROR_STRING ( " Incorrect hex digit after \ \ u escape in string . " ) ; <nl> - case kParseErrorStringUnicodeSurrogateInvalid : return RAPIDJSON_ERROR_STRING ( " The surrogate pair in string is invalid . " ) ; <nl> - case kParseErrorStringEscapeInvalid : return RAPIDJSON_ERROR_STRING ( " Invalid escape character in string . " ) ; <nl> - case kParseErrorStringMissQuotationMark : return RAPIDJSON_ERROR_STRING ( " Missing a closing quotation mark in string . " ) ; <nl> - case kParseErrorStringInvalidEncoding : return RAPIDJSON_ERROR_STRING ( " Invalid encoding in string . " ) ; <nl> - <nl> - case kParseErrorNumberTooBig : return RAPIDJSON_ERROR_STRING ( " Number too big to be stored in double . " ) ; <nl> - case kParseErrorNumberMissFraction : return RAPIDJSON_ERROR_STRING ( " Miss fraction part in number . " ) ; <nl> - case kParseErrorNumberMissExponent : return RAPIDJSON_ERROR_STRING ( " Miss exponent in number . " ) ; <nl> - <nl> - case kParseErrorTermination : return RAPIDJSON_ERROR_STRING ( " Terminate parsing due to Handler error . " ) ; <nl> - case kParseErrorUnspecificSyntaxError : return RAPIDJSON_ERROR_STRING ( " Unspecific syntax error . " ) ; <nl> - <nl> - default : <nl> - return RAPIDJSON_ERROR_STRING ( " Unknown error . " ) ; <nl> - } <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_ERROR_EN_H__ <nl> deleted file mode 100644 <nl> index 146604439b1 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / error / error . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ERROR_ERROR_H__ <nl> - # define RAPIDJSON_ERROR_ERROR_H__ <nl> - <nl> - / * ! \ file error . h * / <nl> - <nl> - / * ! \ defgroup RAPIDJSON_ERRORS RapidJSON error handling * / <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_ERROR_CHARTYPE <nl> - <nl> - / / ! Character type of error messages . <nl> - / * ! \ ingroup RAPIDJSON_ERRORS <nl> - The default character type is \ c char . <nl> - On Windows , user can define this macro as \ c TCHAR for supporting both <nl> - unicode / non - unicode settings . <nl> - * / <nl> - # ifndef RAPIDJSON_ERROR_CHARTYPE <nl> - # define RAPIDJSON_ERROR_CHARTYPE char <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_ERROR_STRING <nl> - <nl> - / / ! Macro for converting string literial to \ ref RAPIDJSON_ERROR_CHARTYPE [ ] . <nl> - / * ! \ ingroup RAPIDJSON_ERRORS <nl> - By default this conversion macro does nothing . <nl> - On Windows , user can define this macro as \ c _T ( x ) for supporting both <nl> - unicode / non - unicode settings . <nl> - * / <nl> - # ifndef RAPIDJSON_ERROR_STRING <nl> - # define RAPIDJSON_ERROR_STRING ( x ) x <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / ParseErrorCode <nl> - <nl> - / / ! Error code of parsing . <nl> - / * ! \ ingroup RAPIDJSON_ERRORS <nl> - \ see GenericReader : : Parse , GenericReader : : GetParseErrorCode <nl> - * / <nl> - enum ParseErrorCode { <nl> - kParseErrorNone = 0 , / / ! < No error . <nl> - <nl> - kParseErrorDocumentEmpty , / / ! < The document is empty . <nl> - kParseErrorDocumentRootNotSingular , / / ! < The document root must not follow by other values . <nl> - <nl> - kParseErrorValueInvalid , / / ! < Invalid value . <nl> - <nl> - kParseErrorObjectMissName , / / ! < Missing a name for object member . <nl> - kParseErrorObjectMissColon , / / ! < Missing a colon after a name of object member . <nl> - kParseErrorObjectMissCommaOrCurlyBracket , / / ! < Missing a comma or ' } ' after an object member . <nl> - <nl> - kParseErrorArrayMissCommaOrSquareBracket , / / ! < Missing a comma or ' ] ' after an array element . <nl> - <nl> - kParseErrorStringUnicodeEscapeInvalidHex , / / ! < Incorrect hex digit after \ \ u escape in string . <nl> - kParseErrorStringUnicodeSurrogateInvalid , / / ! < The surrogate pair in string is invalid . <nl> - kParseErrorStringEscapeInvalid , / / ! < Invalid escape character in string . <nl> - kParseErrorStringMissQuotationMark , / / ! < Missing a closing quotation mark in string . <nl> - kParseErrorStringInvalidEncoding , / / ! < Invalid encoding in string . <nl> - <nl> - kParseErrorNumberTooBig , / / ! < Number too big to be stored in double . <nl> - kParseErrorNumberMissFraction , / / ! < Miss fraction part in number . <nl> - kParseErrorNumberMissExponent , / / ! < Miss exponent in number . <nl> - <nl> - kParseErrorTermination , / / ! < Parsing was terminated . <nl> - kParseErrorUnspecificSyntaxError , / / ! < Unspecific syntax error . <nl> - } ; <nl> - <nl> - / / ! Result of parsing ( wraps ParseErrorCode ) <nl> - / * ! <nl> - \ ingroup RAPIDJSON_ERRORS <nl> - \ code <nl> - Document doc ; <nl> - ParseResult ok = doc . Parse ( " [ 42 ] " ) ; <nl> - if ( ! ok ) { <nl> - fprintf ( stderr , " JSON parse error : % s ( % u ) " , <nl> - GetParseError_En ( ok . Code ( ) ) , ok . Offset ( ) ) ; <nl> - exit ( EXIT_FAILURE ) ; <nl> - } <nl> - \ endcode <nl> - \ see GenericReader : : Parse , GenericDocument : : Parse <nl> - * / <nl> - struct ParseResult { <nl> - <nl> - / / ! Default constructor , no error . <nl> - ParseResult ( ) : code_ ( kParseErrorNone ) , offset_ ( 0 ) { } <nl> - / / ! Constructor to set an error . <nl> - ParseResult ( ParseErrorCode code , size_t offset ) : code_ ( code ) , offset_ ( offset ) { } <nl> - <nl> - / / ! Get the error code . <nl> - ParseErrorCode Code ( ) const { return code_ ; } <nl> - / / ! Get the error offset , if \ ref IsError ( ) , 0 otherwise . <nl> - size_t Offset ( ) const { return offset_ ; } <nl> - <nl> - / / ! Conversion to \ c bool , returns \ c true , iff ! \ ref IsError ( ) . <nl> - operator bool ( ) const { return ! IsError ( ) ; } <nl> - / / ! Whether the result is an error . <nl> - bool IsError ( ) const { return code_ ! = kParseErrorNone ; } <nl> - <nl> - bool operator = = ( const ParseResult & that ) const { return code_ = = that . code_ ; } <nl> - bool operator = = ( ParseErrorCode code ) const { return code_ = = code ; } <nl> - friend bool operator = = ( ParseErrorCode code , const ParseResult & err ) { return code = = err . code_ ; } <nl> - <nl> - / / ! Reset error code . <nl> - void Clear ( ) { Set ( kParseErrorNone ) ; } <nl> - / / ! Update error code and offset . <nl> - void Set ( ParseErrorCode code , size_t offset = 0 ) { code_ = code ; offset_ = offset ; } <nl> - <nl> - private : <nl> - ParseErrorCode code_ ; <nl> - size_t offset_ ; <nl> - } ; <nl> - <nl> - / / ! Function pointer type of GetParseError ( ) . <nl> - / * ! \ ingroup RAPIDJSON_ERRORS <nl> - <nl> - This is the prototype for \ c GetParseError_X ( ) , where \ c X is a locale . <nl> - User can dynamically change locale in runtime , e . g . : <nl> - \ code <nl> - GetParseErrorFunc GetParseError = GetParseError_En ; / / or whatever <nl> - const RAPIDJSON_ERROR_CHARTYPE * s = GetParseError ( document . GetParseErrorCode ( ) ) ; <nl> - \ endcode <nl> - * / <nl> - typedef const RAPIDJSON_ERROR_CHARTYPE * ( * GetParseErrorFunc ) ( ParseErrorCode ) ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_ERROR_ERROR_H__ <nl> deleted file mode 100644 <nl> index 31c193bf98d . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / filereadstream . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_FILEREADSTREAM_H_ <nl> - # define RAPIDJSON_FILEREADSTREAM_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include < cstdio > <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! File byte stream for input using fread ( ) . <nl> - / * ! <nl> - \ note implements Stream concept <nl> - * / <nl> - class FileReadStream { <nl> - public : <nl> - typedef char Ch ; / / ! < Character type ( byte ) . <nl> - <nl> - / / ! Constructor . <nl> - / * ! <nl> - \ param fp File pointer opened for read . <nl> - \ param buffer user - supplied buffer . <nl> - \ param bufferSize size of buffer in bytes . Must > = 4 bytes . <nl> - * / <nl> - FileReadStream ( FILE * fp , char * buffer , size_t bufferSize ) : fp_ ( fp ) , buffer_ ( buffer ) , bufferSize_ ( bufferSize ) , bufferLast_ ( 0 ) , current_ ( buffer_ ) , readCount_ ( 0 ) , count_ ( 0 ) , eof_ ( false ) { <nl> - RAPIDJSON_ASSERT ( fp_ ! = 0 ) ; <nl> - RAPIDJSON_ASSERT ( bufferSize > = 4 ) ; <nl> - Read ( ) ; <nl> - } <nl> - <nl> - Ch Peek ( ) const { return * current_ ; } <nl> - Ch Take ( ) { Ch c = * current_ ; Read ( ) ; return c ; } <nl> - size_t Tell ( ) const { return count_ + static_cast < size_t > ( current_ - buffer_ ) ; } <nl> - <nl> - / / Not implemented <nl> - void Put ( Ch ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - void Flush ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - / / For encoding detection only . <nl> - const Ch * Peek4 ( ) const { <nl> - return ( current_ + 4 < = bufferLast_ ) ? current_ : 0 ; <nl> - } <nl> - <nl> - private : <nl> - void Read ( ) { <nl> - if ( current_ < bufferLast_ ) <nl> - + + current_ ; <nl> - else if ( ! eof_ ) { <nl> - count_ + = readCount_ ; <nl> - readCount_ = fread ( buffer_ , 1 , bufferSize_ , fp_ ) ; <nl> - bufferLast_ = buffer_ + readCount_ - 1 ; <nl> - current_ = buffer_ ; <nl> - <nl> - if ( readCount_ < bufferSize_ ) { <nl> - buffer_ [ readCount_ ] = ' \ 0 ' ; <nl> - + + bufferLast_ ; <nl> - eof_ = true ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - FILE * fp_ ; <nl> - Ch * buffer_ ; <nl> - size_t bufferSize_ ; <nl> - Ch * bufferLast_ ; <nl> - Ch * current_ ; <nl> - size_t readCount_ ; <nl> - size_t count_ ; / / ! < Number of characters read <nl> - bool eof_ ; <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_FILESTREAM_H_ <nl> deleted file mode 100644 <nl> index 5fe00362b56 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / filestream . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_FILESTREAM_H_ <nl> - # define RAPIDJSON_FILESTREAM_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include < cstdio > <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! ( Deprecated ) Wrapper of C file stream for input or output . <nl> - / * ! <nl> - This simple wrapper does not check the validity of the stream . <nl> - \ note implements Stream concept <nl> - \ note deprecated : This was only for basic testing in version 0 . 1 , it is found that the performance is very low by using fgetc ( ) . Use FileReadStream instead . <nl> - * / <nl> - class FileStream { <nl> - public : <nl> - typedef char Ch ; / / ! < Character type . Only support char . <nl> - <nl> - FileStream ( FILE * fp ) : fp_ ( fp ) , current_ ( ' \ 0 ' ) , count_ ( 0 ) { Read ( ) ; } <nl> - char Peek ( ) const { return current_ ; } <nl> - char Take ( ) { char c = current_ ; Read ( ) ; return c ; } <nl> - size_t Tell ( ) const { return count_ ; } <nl> - void Put ( char c ) { fputc ( c , fp_ ) ; } <nl> - void Flush ( ) { fflush ( fp_ ) ; } <nl> - <nl> - / / Not implemented <nl> - char * PutBegin ( ) { return 0 ; } <nl> - size_t PutEnd ( char * ) { return 0 ; } <nl> - <nl> - private : <nl> - / / Prohibit copy constructor & assignment operator . <nl> - FileStream ( const FileStream & ) ; <nl> - FileStream & operator = ( const FileStream & ) ; <nl> - <nl> - void Read ( ) { <nl> - RAPIDJSON_ASSERT ( fp_ ! = 0 ) ; <nl> - int c = fgetc ( fp_ ) ; <nl> - if ( c ! = EOF ) { <nl> - current_ = ( char ) c ; <nl> - count_ + + ; <nl> - } <nl> - else if ( current_ ! = ' \ 0 ' ) <nl> - current_ = ' \ 0 ' ; <nl> - } <nl> - <nl> - FILE * fp_ ; <nl> - char current_ ; <nl> - size_t count_ ; <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_FILESTREAM_H_ <nl> deleted file mode 100644 <nl> index 05c5ca09077 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / filewritestream . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_FILEWRITESTREAM_H_ <nl> - # define RAPIDJSON_FILEWRITESTREAM_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include < cstdio > <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Wrapper of C file stream for input using fread ( ) . <nl> - / * ! <nl> - \ note implements Stream concept <nl> - * / <nl> - class FileWriteStream { <nl> - public : <nl> - typedef char Ch ; / / ! < Character type . Only support char . <nl> - <nl> - FileWriteStream ( FILE * fp , char * buffer , size_t bufferSize ) : fp_ ( fp ) , buffer_ ( buffer ) , bufferEnd_ ( buffer + bufferSize ) , current_ ( buffer_ ) { <nl> - RAPIDJSON_ASSERT ( fp_ ! = 0 ) ; <nl> - } <nl> - <nl> - void Put ( char c ) { <nl> - if ( current_ > = bufferEnd_ ) <nl> - Flush ( ) ; <nl> - <nl> - * current_ + + = c ; <nl> - } <nl> - <nl> - void PutN ( char c , size_t n ) { <nl> - size_t avail = static_cast < size_t > ( bufferEnd_ - current_ ) ; <nl> - while ( n > avail ) { <nl> - std : : memset ( current_ , c , avail ) ; <nl> - current_ + = avail ; <nl> - Flush ( ) ; <nl> - n - = avail ; <nl> - avail = static_cast < size_t > ( bufferEnd_ - current_ ) ; <nl> - } <nl> - <nl> - if ( n > 0 ) { <nl> - std : : memset ( current_ , c , n ) ; <nl> - current_ + = n ; <nl> - } <nl> - } <nl> - <nl> - void Flush ( ) { <nl> - if ( current_ ! = buffer_ ) { <nl> - fwrite ( buffer_ , 1 , static_cast < size_t > ( current_ - buffer_ ) , fp_ ) ; <nl> - current_ = buffer_ ; <nl> - } <nl> - } <nl> - <nl> - / / Not implemented <nl> - char Peek ( ) const { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - char Take ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t Tell ( ) const { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - char * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - size_t PutEnd ( char * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - private : <nl> - / / Prohibit copy constructor & assignment operator . <nl> - FileWriteStream ( const FileWriteStream & ) ; <nl> - FileWriteStream & operator = ( const FileWriteStream & ) ; <nl> - <nl> - FILE * fp_ ; <nl> - char * buffer_ ; <nl> - char * bufferEnd_ ; <nl> - char * current_ ; <nl> - } ; <nl> - <nl> - / / ! Implement specialized version of PutN ( ) with memset ( ) for better performance . <nl> - template < > <nl> - inline void PutN ( FileWriteStream & stream , char c , size_t n ) { <nl> - stream . PutN ( c , n ) ; <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_FILESTREAM_H_ <nl> deleted file mode 100644 <nl> index 6ae588ac4aa . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / dtoa . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - / / This is a C + + header - only implementation of Grisu2 algorithm from the publication : <nl> - / / Loitsch , Florian . " Printing floating - point numbers quickly and accurately with <nl> - / / integers . " ACM Sigplan Notices 45 . 6 ( 2010 ) : 233 - 243 . <nl> - <nl> - # ifndef RAPIDJSON_DTOA_ <nl> - # define RAPIDJSON_DTOA_ <nl> - <nl> - # if defined ( _MSC_VER ) <nl> - # include < intrin . h > <nl> - # if defined ( _M_AMD64 ) <nl> - # pragma intrinsic ( _BitScanReverse64 ) <nl> - # endif <nl> - # endif <nl> - <nl> - # include " itoa . h " / / GetDigitsLut ( ) <nl> - <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - <nl> - struct DiyFp { <nl> - DiyFp ( ) { } <nl> - <nl> - DiyFp ( uint64_t f , int e ) : f ( f ) , e ( e ) { } <nl> - <nl> - DiyFp ( double d ) { <nl> - union { <nl> - double d ; <nl> - uint64_t u64 ; <nl> - } u = { d } ; <nl> - <nl> - int biased_e = static_cast < int > ( ( u . u64 & kDpExponentMask ) > > kDpSignificandSize ) ; <nl> - uint64_t significand = ( u . u64 & kDpSignificandMask ) ; <nl> - if ( biased_e ! = 0 ) { <nl> - f = significand + kDpHiddenBit ; <nl> - e = biased_e - kDpExponentBias ; <nl> - } <nl> - else { <nl> - f = significand ; <nl> - e = kDpMinExponent + 1 ; <nl> - } <nl> - } <nl> - <nl> - DiyFp operator - ( const DiyFp & rhs ) const { <nl> - return DiyFp ( f - rhs . f , e ) ; <nl> - } <nl> - <nl> - DiyFp operator * ( const DiyFp & rhs ) const { <nl> - # if defined ( _MSC_VER ) & & defined ( _M_AMD64 ) <nl> - uint64_t h ; <nl> - uint64_t l = _umul128 ( f , rhs . f , & h ) ; <nl> - if ( l & ( uint64_t ( 1 ) < < 63 ) ) / / rounding <nl> - h + + ; <nl> - return DiyFp ( h , e + rhs . e + 64 ) ; <nl> - # elif ( __GNUC__ > 4 | | ( __GNUC__ = = 4 & & __GNUC_MINOR__ > = 6 ) ) & & defined ( __x86_64__ ) <nl> - unsigned __int128 p = static_cast < unsigned __int128 > ( f ) * static_cast < unsigned __int128 > ( rhs . f ) ; <nl> - uint64_t h = static_cast < uint64_t > ( p > > 64 ) ; <nl> - uint64_t l = static_cast < uint64_t > ( p ) ; <nl> - if ( l & ( uint64_t ( 1 ) < < 63 ) ) / / rounding <nl> - h + + ; <nl> - return DiyFp ( h , e + rhs . e + 64 ) ; <nl> - # else <nl> - const uint64_t M32 = 0xFFFFFFFF ; <nl> - const uint64_t a = f > > 32 ; <nl> - const uint64_t b = f & M32 ; <nl> - const uint64_t c = rhs . f > > 32 ; <nl> - const uint64_t d = rhs . f & M32 ; <nl> - const uint64_t ac = a * c ; <nl> - const uint64_t bc = b * c ; <nl> - const uint64_t ad = a * d ; <nl> - const uint64_t bd = b * d ; <nl> - uint64_t tmp = ( bd > > 32 ) + ( ad & M32 ) + ( bc & M32 ) ; <nl> - tmp + = 1U < < 31 ; / / / mult_round <nl> - return DiyFp ( ac + ( ad > > 32 ) + ( bc > > 32 ) + ( tmp > > 32 ) , e + rhs . e + 64 ) ; <nl> - # endif <nl> - } <nl> - <nl> - DiyFp Normalize ( ) const { <nl> - # if defined ( _MSC_VER ) & & defined ( _M_AMD64 ) <nl> - unsigned long index ; <nl> - _BitScanReverse64 ( & index , f ) ; <nl> - return DiyFp ( f < < ( 63 - index ) , e - ( 63 - index ) ) ; <nl> - # elif defined ( __GNUC__ ) <nl> - int s = __builtin_clzll ( f ) ; <nl> - return DiyFp ( f < < s , e - s ) ; <nl> - # else <nl> - DiyFp res = * this ; <nl> - while ( ! ( res . f & kDpHiddenBit ) ) { <nl> - res . f < < = 1 ; <nl> - res . e - - ; <nl> - } <nl> - res . f < < = ( kDiySignificandSize - kDpSignificandSize - 1 ) ; <nl> - res . e = res . e - ( kDiySignificandSize - kDpSignificandSize - 1 ) ; <nl> - return res ; <nl> - # endif <nl> - } <nl> - <nl> - DiyFp NormalizeBoundary ( ) const { <nl> - # if defined ( _MSC_VER ) & & defined ( _M_AMD64 ) <nl> - unsigned long index ; <nl> - _BitScanReverse64 ( & index , f ) ; <nl> - return DiyFp ( f < < ( 63 - index ) , e - ( 63 - index ) ) ; <nl> - # else <nl> - DiyFp res = * this ; <nl> - while ( ! ( res . f & ( kDpHiddenBit < < 1 ) ) ) { <nl> - res . f < < = 1 ; <nl> - res . e - - ; <nl> - } <nl> - res . f < < = ( kDiySignificandSize - kDpSignificandSize - 2 ) ; <nl> - res . e = res . e - ( kDiySignificandSize - kDpSignificandSize - 2 ) ; <nl> - return res ; <nl> - # endif <nl> - } <nl> - <nl> - void NormalizedBoundaries ( DiyFp * minus , DiyFp * plus ) const { <nl> - DiyFp pl = DiyFp ( ( f < < 1 ) + 1 , e - 1 ) . NormalizeBoundary ( ) ; <nl> - DiyFp mi = ( f = = kDpHiddenBit ) ? DiyFp ( ( f < < 2 ) - 1 , e - 2 ) : DiyFp ( ( f < < 1 ) - 1 , e - 1 ) ; <nl> - mi . f < < = mi . e - pl . e ; <nl> - mi . e = pl . e ; <nl> - * plus = pl ; <nl> - * minus = mi ; <nl> - } <nl> - <nl> - static const int kDiySignificandSize = 64 ; <nl> - static const int kDpSignificandSize = 52 ; <nl> - static const int kDpExponentBias = 0x3FF + kDpSignificandSize ; <nl> - static const int kDpMinExponent = - kDpExponentBias ; <nl> - static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2 ( 0x7FF00000 , 0x00000000 ) ; <nl> - static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2 ( 0x000FFFFF , 0xFFFFFFFF ) ; <nl> - static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2 ( 0x00100000 , 0x00000000 ) ; <nl> - <nl> - uint64_t f ; <nl> - int e ; <nl> - } ; <nl> - <nl> - inline DiyFp GetCachedPower ( int e , int * K ) { <nl> - / / 10 ^ - 348 , 10 ^ - 340 , . . . , 10 ^ 340 <nl> - static const uint64_t kCachedPowers_F [ ] = { <nl> - RAPIDJSON_UINT64_C2 ( 0xfa8fd5a0 , 0x081c0288 ) , RAPIDJSON_UINT64_C2 ( 0xbaaee17f , 0xa23ebf76 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x8b16fb20 , 0x3055ac76 ) , RAPIDJSON_UINT64_C2 ( 0xcf42894a , 0x5dce35ea ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x9a6bb0aa , 0x55653b2d ) , RAPIDJSON_UINT64_C2 ( 0xe61acf03 , 0x3d1a45df ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xab70fe17 , 0xc79ac6ca ) , RAPIDJSON_UINT64_C2 ( 0xff77b1fc , 0xbebcdc4f ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xbe5691ef , 0x416bd60c ) , RAPIDJSON_UINT64_C2 ( 0x8dd01fad , 0x907ffc3c ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xd3515c28 , 0x31559a83 ) , RAPIDJSON_UINT64_C2 ( 0x9d71ac8f , 0xada6c9b5 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xea9c2277 , 0x23ee8bcb ) , RAPIDJSON_UINT64_C2 ( 0xaecc4991 , 0x4078536d ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x823c1279 , 0x5db6ce57 ) , RAPIDJSON_UINT64_C2 ( 0xc2109436 , 0x4dfb5637 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x9096ea6f , 0x3848984f ) , RAPIDJSON_UINT64_C2 ( 0xd77485cb , 0x25823ac7 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xa086cfcd , 0x97bf97f4 ) , RAPIDJSON_UINT64_C2 ( 0xef340a98 , 0x172aace5 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xb23867fb , 0x2a35b28e ) , RAPIDJSON_UINT64_C2 ( 0x84c8d4df , 0xd2c63f3b ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xc5dd4427 , 0x1ad3cdba ) , RAPIDJSON_UINT64_C2 ( 0x936b9fce , 0xbb25c996 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xdbac6c24 , 0x7d62a584 ) , RAPIDJSON_UINT64_C2 ( 0xa3ab6658 , 0x0d5fdaf6 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xf3e2f893 , 0xdec3f126 ) , RAPIDJSON_UINT64_C2 ( 0xb5b5ada8 , 0xaaff80b8 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x87625f05 , 0x6c7c4a8b ) , RAPIDJSON_UINT64_C2 ( 0xc9bcff60 , 0x34c13053 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x964e858c , 0x91ba2655 ) , RAPIDJSON_UINT64_C2 ( 0xdff97724 , 0x70297ebd ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xa6dfbd9f , 0xb8e5b88f ) , RAPIDJSON_UINT64_C2 ( 0xf8a95fcf , 0x88747d94 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xb9447093 , 0x8fa89bcf ) , RAPIDJSON_UINT64_C2 ( 0x8a08f0f8 , 0xbf0f156b ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xcdb02555 , 0x653131b6 ) , RAPIDJSON_UINT64_C2 ( 0x993fe2c6 , 0xd07b7fac ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xe45c10c4 , 0x2a2b3b06 ) , RAPIDJSON_UINT64_C2 ( 0xaa242499 , 0x697392d3 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xfd87b5f2 , 0x8300ca0e ) , RAPIDJSON_UINT64_C2 ( 0xbce50864 , 0x92111aeb ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x8cbccc09 , 0x6f5088cc ) , RAPIDJSON_UINT64_C2 ( 0xd1b71758 , 0xe219652c ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x9c400000 , 0x00000000 ) , RAPIDJSON_UINT64_C2 ( 0xe8d4a510 , 0x00000000 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xad78ebc5 , 0xac620000 ) , RAPIDJSON_UINT64_C2 ( 0x813f3978 , 0xf8940984 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xc097ce7b , 0xc90715b3 ) , RAPIDJSON_UINT64_C2 ( 0x8f7e32ce , 0x7bea5c70 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xd5d238a4 , 0xabe98068 ) , RAPIDJSON_UINT64_C2 ( 0x9f4f2726 , 0x179a2245 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xed63a231 , 0xd4c4fb27 ) , RAPIDJSON_UINT64_C2 ( 0xb0de6538 , 0x8cc8ada8 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x83c7088e , 0x1aab65db ) , RAPIDJSON_UINT64_C2 ( 0xc45d1df9 , 0x42711d9a ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x924d692c , 0xa61be758 ) , RAPIDJSON_UINT64_C2 ( 0xda01ee64 , 0x1a708dea ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xa26da399 , 0x9aef774a ) , RAPIDJSON_UINT64_C2 ( 0xf209787b , 0xb47d6b85 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xb454e4a1 , 0x79dd1877 ) , RAPIDJSON_UINT64_C2 ( 0x865b8692 , 0x5b9bc5c2 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xc83553c5 , 0xc8965d3d ) , RAPIDJSON_UINT64_C2 ( 0x952ab45c , 0xfa97a0b3 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xde469fbd , 0x99a05fe3 ) , RAPIDJSON_UINT64_C2 ( 0xa59bc234 , 0xdb398c25 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xf6c69a72 , 0xa3989f5c ) , RAPIDJSON_UINT64_C2 ( 0xb7dcbf53 , 0x54e9bece ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x88fcf317 , 0xf22241e2 ) , RAPIDJSON_UINT64_C2 ( 0xcc20ce9b , 0xd35c78a5 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x98165af3 , 0x7b2153df ) , RAPIDJSON_UINT64_C2 ( 0xe2a0b5dc , 0x971f303a ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xa8d9d153 , 0x5ce3b396 ) , RAPIDJSON_UINT64_C2 ( 0xfb9b7cd9 , 0xa4a7443c ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xbb764c4c , 0xa7a44410 ) , RAPIDJSON_UINT64_C2 ( 0x8bab8eef , 0xb6409c1a ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xd01fef10 , 0xa657842c ) , RAPIDJSON_UINT64_C2 ( 0x9b10a4e5 , 0xe9913129 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xe7109bfb , 0xa19c0c9d ) , RAPIDJSON_UINT64_C2 ( 0xac2820d9 , 0x623bf429 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x80444b5e , 0x7aa7cf85 ) , RAPIDJSON_UINT64_C2 ( 0xbf21e440 , 0x03acdd2d ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x8e679c2f , 0x5e44ff8f ) , RAPIDJSON_UINT64_C2 ( 0xd433179d , 0x9c8cb841 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0x9e19db92 , 0xb4e31ba9 ) , RAPIDJSON_UINT64_C2 ( 0xeb96bf6e , 0xbadf77d9 ) , <nl> - RAPIDJSON_UINT64_C2 ( 0xaf87023b , 0x9bf0ee6b ) <nl> - } ; <nl> - static const int16_t kCachedPowers_E [ ] = { <nl> - - 1220 , - 1193 , - 1166 , - 1140 , - 1113 , - 1087 , - 1060 , - 1034 , - 1007 , - 980 , <nl> - - 954 , - 927 , - 901 , - 874 , - 847 , - 821 , - 794 , - 768 , - 741 , - 715 , <nl> - - 688 , - 661 , - 635 , - 608 , - 582 , - 555 , - 529 , - 502 , - 475 , - 449 , <nl> - - 422 , - 396 , - 369 , - 343 , - 316 , - 289 , - 263 , - 236 , - 210 , - 183 , <nl> - - 157 , - 130 , - 103 , - 77 , - 50 , - 24 , 3 , 30 , 56 , 83 , <nl> - 109 , 136 , 162 , 189 , 216 , 242 , 269 , 295 , 322 , 348 , <nl> - 375 , 402 , 428 , 455 , 481 , 508 , 534 , 561 , 588 , 614 , <nl> - 641 , 667 , 694 , 720 , 747 , 774 , 800 , 827 , 853 , 880 , <nl> - 907 , 933 , 960 , 986 , 1013 , 1039 , 1066 <nl> - } ; <nl> - <nl> - / / int k = static_cast < int > ( ceil ( ( - 61 - e ) * 0 . 30102999566398114 ) ) + 374 ; <nl> - double dk = ( - 61 - e ) * 0 . 30102999566398114 + 347 ; / / dk must be positive , so can do ceiling in positive <nl> - int k = static_cast < int > ( dk ) ; <nl> - if ( k ! = dk ) <nl> - k + + ; <nl> - <nl> - unsigned index = static_cast < unsigned > ( ( k > > 3 ) + 1 ) ; <nl> - * K = - ( - 348 + static_cast < int > ( index < < 3 ) ) ; / / decimal exponent no need lookup table <nl> - <nl> - return DiyFp ( kCachedPowers_F [ index ] , kCachedPowers_E [ index ] ) ; <nl> - } <nl> - <nl> - inline void GrisuRound ( char * buffer , int len , uint64_t delta , uint64_t rest , uint64_t ten_kappa , uint64_t wp_w ) { <nl> - while ( rest < wp_w & & delta - rest > = ten_kappa & & <nl> - ( rest + ten_kappa < wp_w | | / / / closer <nl> - wp_w - rest > rest + ten_kappa - wp_w ) ) { <nl> - buffer [ len - 1 ] - - ; <nl> - rest + = ten_kappa ; <nl> - } <nl> - } <nl> - <nl> - inline unsigned CountDecimalDigit32 ( uint32_t n ) { <nl> - / / Simple pure C + + implementation was faster than __builtin_clz version in this situation . <nl> - if ( n < 10 ) return 1 ; <nl> - if ( n < 100 ) return 2 ; <nl> - if ( n < 1000 ) return 3 ; <nl> - if ( n < 10000 ) return 4 ; <nl> - if ( n < 100000 ) return 5 ; <nl> - if ( n < 1000000 ) return 6 ; <nl> - if ( n < 10000000 ) return 7 ; <nl> - if ( n < 100000000 ) return 8 ; <nl> - if ( n < 1000000000 ) return 9 ; <nl> - return 10 ; <nl> - } <nl> - <nl> - inline void DigitGen ( const DiyFp & W , const DiyFp & Mp , uint64_t delta , char * buffer , int * len , int * K ) { <nl> - static const uint32_t kPow10 [ ] = { 1 , 10 , 100 , 1000 , 10000 , 100000 , 1000000 , 10000000 , 100000000 , 1000000000 } ; <nl> - const DiyFp one ( uint64_t ( 1 ) < < - Mp . e , Mp . e ) ; <nl> - const DiyFp wp_w = Mp - W ; <nl> - uint32_t p1 = static_cast < uint32_t > ( Mp . f > > - one . e ) ; <nl> - uint64_t p2 = Mp . f & ( one . f - 1 ) ; <nl> - int kappa = CountDecimalDigit32 ( p1 ) ; <nl> - * len = 0 ; <nl> - <nl> - while ( kappa > 0 ) { <nl> - uint32_t d ; <nl> - switch ( kappa ) { <nl> - case 10 : d = p1 / 1000000000 ; p1 % = 1000000000 ; break ; <nl> - case 9 : d = p1 / 100000000 ; p1 % = 100000000 ; break ; <nl> - case 8 : d = p1 / 10000000 ; p1 % = 10000000 ; break ; <nl> - case 7 : d = p1 / 1000000 ; p1 % = 1000000 ; break ; <nl> - case 6 : d = p1 / 100000 ; p1 % = 100000 ; break ; <nl> - case 5 : d = p1 / 10000 ; p1 % = 10000 ; break ; <nl> - case 4 : d = p1 / 1000 ; p1 % = 1000 ; break ; <nl> - case 3 : d = p1 / 100 ; p1 % = 100 ; break ; <nl> - case 2 : d = p1 / 10 ; p1 % = 10 ; break ; <nl> - case 1 : d = p1 ; p1 = 0 ; break ; <nl> - default : <nl> - # if defined ( _MSC_VER ) <nl> - __assume ( 0 ) ; <nl> - # elif __GNUC__ > 4 | | ( __GNUC__ = = 4 & & __GNUC_MINOR__ > = 5 ) <nl> - __builtin_unreachable ( ) ; <nl> - # else <nl> - d = 0 ; <nl> - # endif <nl> - } <nl> - if ( d | | * len ) <nl> - buffer [ ( * len ) + + ] = static_cast < char > ( ' 0 ' + static_cast < char > ( d ) ) ; <nl> - kappa - - ; <nl> - uint64_t tmp = ( static_cast < uint64_t > ( p1 ) < < - one . e ) + p2 ; <nl> - if ( tmp < = delta ) { <nl> - * K + = kappa ; <nl> - GrisuRound ( buffer , * len , delta , tmp , static_cast < uint64_t > ( kPow10 [ kappa ] ) < < - one . e , wp_w . f ) ; <nl> - return ; <nl> - } <nl> - } <nl> - <nl> - / / kappa = 0 <nl> - for ( ; ; ) { <nl> - p2 * = 10 ; <nl> - delta * = 10 ; <nl> - char d = static_cast < char > ( p2 > > - one . e ) ; <nl> - if ( d | | * len ) <nl> - buffer [ ( * len ) + + ] = static_cast < char > ( ' 0 ' + d ) ; <nl> - p2 & = one . f - 1 ; <nl> - kappa - - ; <nl> - if ( p2 < delta ) { <nl> - * K + = kappa ; <nl> - GrisuRound ( buffer , * len , delta , p2 , one . f , wp_w . f * kPow10 [ - kappa ] ) ; <nl> - return ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - inline void Grisu2 ( double value , char * buffer , int * length , int * K ) { <nl> - const DiyFp v ( value ) ; <nl> - DiyFp w_m , w_p ; <nl> - v . NormalizedBoundaries ( & w_m , & w_p ) ; <nl> - <nl> - const DiyFp c_mk = GetCachedPower ( w_p . e , K ) ; <nl> - const DiyFp W = v . Normalize ( ) * c_mk ; <nl> - DiyFp Wp = w_p * c_mk ; <nl> - DiyFp Wm = w_m * c_mk ; <nl> - Wm . f + + ; <nl> - Wp . f - - ; <nl> - DigitGen ( W , Wp , Wp . f - Wm . f , buffer , length , K ) ; <nl> - } <nl> - <nl> - inline char * WriteExponent ( int K , char * buffer ) { <nl> - if ( K < 0 ) { <nl> - * buffer + + = ' - ' ; <nl> - K = - K ; <nl> - } <nl> - <nl> - if ( K > = 100 ) { <nl> - * buffer + + = static_cast < char > ( ' 0 ' + static_cast < char > ( K / 100 ) ) ; <nl> - K % = 100 ; <nl> - const char * d = GetDigitsLut ( ) + K * 2 ; <nl> - * buffer + + = d [ 0 ] ; <nl> - * buffer + + = d [ 1 ] ; <nl> - } <nl> - else if ( K > = 10 ) { <nl> - const char * d = GetDigitsLut ( ) + K * 2 ; <nl> - * buffer + + = d [ 0 ] ; <nl> - * buffer + + = d [ 1 ] ; <nl> - } <nl> - else <nl> - * buffer + + = static_cast < char > ( ' 0 ' + static_cast < char > ( K ) ) ; <nl> - <nl> - return buffer ; <nl> - } <nl> - <nl> - inline char * Prettify ( char * buffer , int length , int k ) { <nl> - const int kk = length + k ; / / 10 ^ ( kk - 1 ) < = v < 10 ^ kk <nl> - <nl> - if ( length < = kk & & kk < = 21 ) { <nl> - / / 1234e7 - > 12340000000 <nl> - for ( int i = length ; i < kk ; i + + ) <nl> - buffer [ i ] = ' 0 ' ; <nl> - buffer [ kk ] = ' . ' ; <nl> - buffer [ kk + 1 ] = ' 0 ' ; <nl> - return & buffer [ kk + 2 ] ; <nl> - } <nl> - else if ( 0 < kk & & kk < = 21 ) { <nl> - / / 1234e - 2 - > 12 . 34 <nl> - std : : memmove ( & buffer [ kk + 1 ] , & buffer [ kk ] , length - kk ) ; <nl> - buffer [ kk ] = ' . ' ; <nl> - return & buffer [ length + 1 ] ; <nl> - } <nl> - else if ( - 6 < kk & & kk < = 0 ) { <nl> - / / 1234e - 6 - > 0 . 001234 <nl> - const int offset = 2 - kk ; <nl> - std : : memmove ( & buffer [ offset ] , & buffer [ 0 ] , length ) ; <nl> - buffer [ 0 ] = ' 0 ' ; <nl> - buffer [ 1 ] = ' . ' ; <nl> - for ( int i = 2 ; i < offset ; i + + ) <nl> - buffer [ i ] = ' 0 ' ; <nl> - return & buffer [ length + offset ] ; <nl> - } <nl> - else if ( length = = 1 ) { <nl> - / / 1e30 <nl> - buffer [ 1 ] = ' e ' ; <nl> - return WriteExponent ( kk - 1 , & buffer [ 2 ] ) ; <nl> - } <nl> - else { <nl> - / / 1234e30 - > 1 . 234e33 <nl> - std : : memmove ( & buffer [ 2 ] , & buffer [ 1 ] , length - 1 ) ; <nl> - buffer [ 1 ] = ' . ' ; <nl> - buffer [ length + 1 ] = ' e ' ; <nl> - return WriteExponent ( kk - 1 , & buffer [ 0 + length + 2 ] ) ; <nl> - } <nl> - } <nl> - <nl> - inline char * dtoa ( double value , char * buffer ) { <nl> - if ( value = = 0 ) { <nl> - buffer [ 0 ] = ' 0 ' ; <nl> - buffer [ 1 ] = ' . ' ; <nl> - buffer [ 2 ] = ' 0 ' ; <nl> - return & buffer [ 3 ] ; <nl> - } <nl> - else { <nl> - if ( value < 0 ) { <nl> - * buffer + + = ' - ' ; <nl> - value = - value ; <nl> - } <nl> - int length , K ; <nl> - Grisu2 ( value , buffer , & length , & K ) ; <nl> - return Prettify ( buffer , length , K ) ; <nl> - } <nl> - } <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_DTOA_ <nl> deleted file mode 100644 <nl> index 425e9830c04 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / itoa . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_ITOA_ <nl> - # define RAPIDJSON_ITOA_ <nl> - <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - inline const char * GetDigitsLut ( ) { <nl> - static const char cDigitsLut [ 200 ] = { <nl> - ' 0 ' , ' 0 ' , ' 0 ' , ' 1 ' , ' 0 ' , ' 2 ' , ' 0 ' , ' 3 ' , ' 0 ' , ' 4 ' , ' 0 ' , ' 5 ' , ' 0 ' , ' 6 ' , ' 0 ' , ' 7 ' , ' 0 ' , ' 8 ' , ' 0 ' , ' 9 ' , <nl> - ' 1 ' , ' 0 ' , ' 1 ' , ' 1 ' , ' 1 ' , ' 2 ' , ' 1 ' , ' 3 ' , ' 1 ' , ' 4 ' , ' 1 ' , ' 5 ' , ' 1 ' , ' 6 ' , ' 1 ' , ' 7 ' , ' 1 ' , ' 8 ' , ' 1 ' , ' 9 ' , <nl> - ' 2 ' , ' 0 ' , ' 2 ' , ' 1 ' , ' 2 ' , ' 2 ' , ' 2 ' , ' 3 ' , ' 2 ' , ' 4 ' , ' 2 ' , ' 5 ' , ' 2 ' , ' 6 ' , ' 2 ' , ' 7 ' , ' 2 ' , ' 8 ' , ' 2 ' , ' 9 ' , <nl> - ' 3 ' , ' 0 ' , ' 3 ' , ' 1 ' , ' 3 ' , ' 2 ' , ' 3 ' , ' 3 ' , ' 3 ' , ' 4 ' , ' 3 ' , ' 5 ' , ' 3 ' , ' 6 ' , ' 3 ' , ' 7 ' , ' 3 ' , ' 8 ' , ' 3 ' , ' 9 ' , <nl> - ' 4 ' , ' 0 ' , ' 4 ' , ' 1 ' , ' 4 ' , ' 2 ' , ' 4 ' , ' 3 ' , ' 4 ' , ' 4 ' , ' 4 ' , ' 5 ' , ' 4 ' , ' 6 ' , ' 4 ' , ' 7 ' , ' 4 ' , ' 8 ' , ' 4 ' , ' 9 ' , <nl> - ' 5 ' , ' 0 ' , ' 5 ' , ' 1 ' , ' 5 ' , ' 2 ' , ' 5 ' , ' 3 ' , ' 5 ' , ' 4 ' , ' 5 ' , ' 5 ' , ' 5 ' , ' 6 ' , ' 5 ' , ' 7 ' , ' 5 ' , ' 8 ' , ' 5 ' , ' 9 ' , <nl> - ' 6 ' , ' 0 ' , ' 6 ' , ' 1 ' , ' 6 ' , ' 2 ' , ' 6 ' , ' 3 ' , ' 6 ' , ' 4 ' , ' 6 ' , ' 5 ' , ' 6 ' , ' 6 ' , ' 6 ' , ' 7 ' , ' 6 ' , ' 8 ' , ' 6 ' , ' 9 ' , <nl> - ' 7 ' , ' 0 ' , ' 7 ' , ' 1 ' , ' 7 ' , ' 2 ' , ' 7 ' , ' 3 ' , ' 7 ' , ' 4 ' , ' 7 ' , ' 5 ' , ' 7 ' , ' 6 ' , ' 7 ' , ' 7 ' , ' 7 ' , ' 8 ' , ' 7 ' , ' 9 ' , <nl> - ' 8 ' , ' 0 ' , ' 8 ' , ' 1 ' , ' 8 ' , ' 2 ' , ' 8 ' , ' 3 ' , ' 8 ' , ' 4 ' , ' 8 ' , ' 5 ' , ' 8 ' , ' 6 ' , ' 8 ' , ' 7 ' , ' 8 ' , ' 8 ' , ' 8 ' , ' 9 ' , <nl> - ' 9 ' , ' 0 ' , ' 9 ' , ' 1 ' , ' 9 ' , ' 2 ' , ' 9 ' , ' 3 ' , ' 9 ' , ' 4 ' , ' 9 ' , ' 5 ' , ' 9 ' , ' 6 ' , ' 9 ' , ' 7 ' , ' 9 ' , ' 8 ' , ' 9 ' , ' 9 ' <nl> - } ; <nl> - return cDigitsLut ; <nl> - } <nl> - <nl> - inline char * u32toa ( uint32_t value , char * buffer ) { <nl> - const char * cDigitsLut = GetDigitsLut ( ) ; <nl> - <nl> - if ( value < 10000 ) { <nl> - const uint32_t d1 = ( value / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( value % 100 ) < < 1 ; <nl> - <nl> - if ( value > = 1000 ) <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - if ( value > = 100 ) <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - if ( value > = 10 ) <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - } <nl> - else if ( value < 100000000 ) { <nl> - / / value = bbbbcccc <nl> - const uint32_t b = value / 10000 ; <nl> - const uint32_t c = value % 10000 ; <nl> - <nl> - const uint32_t d1 = ( b / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( b % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d3 = ( c / 100 ) < < 1 ; <nl> - const uint32_t d4 = ( c % 100 ) < < 1 ; <nl> - <nl> - if ( value > = 10000000 ) <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - if ( value > = 1000000 ) <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - if ( value > = 100000 ) <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - <nl> - * buffer + + = cDigitsLut [ d3 ] ; <nl> - * buffer + + = cDigitsLut [ d3 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d4 ] ; <nl> - * buffer + + = cDigitsLut [ d4 + 1 ] ; <nl> - } <nl> - else { <nl> - / / value = aabbbbcccc in decimal <nl> - <nl> - const uint32_t a = value / 100000000 ; / / 1 to 42 <nl> - value % = 100000000 ; <nl> - <nl> - if ( a > = 10 ) { <nl> - const unsigned i = a < < 1 ; <nl> - * buffer + + = cDigitsLut [ i ] ; <nl> - * buffer + + = cDigitsLut [ i + 1 ] ; <nl> - } <nl> - else <nl> - * buffer + + = static_cast < char > ( ' 0 ' + static_cast < char > ( a ) ) ; <nl> - <nl> - const uint32_t b = value / 10000 ; / / 0 to 9999 <nl> - const uint32_t c = value % 10000 ; / / 0 to 9999 <nl> - <nl> - const uint32_t d1 = ( b / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( b % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d3 = ( c / 100 ) < < 1 ; <nl> - const uint32_t d4 = ( c % 100 ) < < 1 ; <nl> - <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d3 ] ; <nl> - * buffer + + = cDigitsLut [ d3 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d4 ] ; <nl> - * buffer + + = cDigitsLut [ d4 + 1 ] ; <nl> - } <nl> - return buffer ; <nl> - } <nl> - <nl> - inline char * i32toa ( int32_t value , char * buffer ) { <nl> - if ( value < 0 ) { <nl> - * buffer + + = ' - ' ; <nl> - value = - value ; <nl> - } <nl> - <nl> - return u32toa ( static_cast < uint32_t > ( value ) , buffer ) ; <nl> - } <nl> - <nl> - inline char * u64toa ( uint64_t value , char * buffer ) { <nl> - const char * cDigitsLut = GetDigitsLut ( ) ; <nl> - const uint64_t kTen8 = 100000000 ; <nl> - const uint64_t kTen9 = kTen8 * 10 ; <nl> - const uint64_t kTen10 = kTen8 * 100 ; <nl> - const uint64_t kTen11 = kTen8 * 1000 ; <nl> - const uint64_t kTen12 = kTen8 * 10000 ; <nl> - const uint64_t kTen13 = kTen8 * 100000 ; <nl> - const uint64_t kTen14 = kTen8 * 1000000 ; <nl> - const uint64_t kTen15 = kTen8 * 10000000 ; <nl> - const uint64_t kTen16 = kTen8 * kTen8 ; <nl> - <nl> - if ( value < kTen8 ) { <nl> - uint32_t v = static_cast < uint32_t > ( value ) ; <nl> - if ( v < 10000 ) { <nl> - const uint32_t d1 = ( v / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( v % 100 ) < < 1 ; <nl> - <nl> - if ( v > = 1000 ) <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - if ( v > = 100 ) <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - if ( v > = 10 ) <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - } <nl> - else { <nl> - / / value = bbbbcccc <nl> - const uint32_t b = v / 10000 ; <nl> - const uint32_t c = v % 10000 ; <nl> - <nl> - const uint32_t d1 = ( b / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( b % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d3 = ( c / 100 ) < < 1 ; <nl> - const uint32_t d4 = ( c % 100 ) < < 1 ; <nl> - <nl> - if ( value > = 10000000 ) <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - if ( value > = 1000000 ) <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - if ( value > = 100000 ) <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - <nl> - * buffer + + = cDigitsLut [ d3 ] ; <nl> - * buffer + + = cDigitsLut [ d3 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d4 ] ; <nl> - * buffer + + = cDigitsLut [ d4 + 1 ] ; <nl> - } <nl> - } <nl> - else if ( value < kTen16 ) { <nl> - const uint32_t v0 = static_cast < uint32_t > ( value / kTen8 ) ; <nl> - const uint32_t v1 = static_cast < uint32_t > ( value % kTen8 ) ; <nl> - <nl> - const uint32_t b0 = v0 / 10000 ; <nl> - const uint32_t c0 = v0 % 10000 ; <nl> - <nl> - const uint32_t d1 = ( b0 / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( b0 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d3 = ( c0 / 100 ) < < 1 ; <nl> - const uint32_t d4 = ( c0 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t b1 = v1 / 10000 ; <nl> - const uint32_t c1 = v1 % 10000 ; <nl> - <nl> - const uint32_t d5 = ( b1 / 100 ) < < 1 ; <nl> - const uint32_t d6 = ( b1 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d7 = ( c1 / 100 ) < < 1 ; <nl> - const uint32_t d8 = ( c1 % 100 ) < < 1 ; <nl> - <nl> - if ( value > = kTen15 ) <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - if ( value > = kTen14 ) <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - if ( value > = kTen13 ) <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - if ( value > = kTen12 ) <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - if ( value > = kTen11 ) <nl> - * buffer + + = cDigitsLut [ d3 ] ; <nl> - if ( value > = kTen10 ) <nl> - * buffer + + = cDigitsLut [ d3 + 1 ] ; <nl> - if ( value > = kTen9 ) <nl> - * buffer + + = cDigitsLut [ d4 ] ; <nl> - if ( value > = kTen8 ) <nl> - * buffer + + = cDigitsLut [ d4 + 1 ] ; <nl> - <nl> - * buffer + + = cDigitsLut [ d5 ] ; <nl> - * buffer + + = cDigitsLut [ d5 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d6 ] ; <nl> - * buffer + + = cDigitsLut [ d6 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d7 ] ; <nl> - * buffer + + = cDigitsLut [ d7 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d8 ] ; <nl> - * buffer + + = cDigitsLut [ d8 + 1 ] ; <nl> - } <nl> - else { <nl> - const uint32_t a = static_cast < uint32_t > ( value / kTen16 ) ; / / 1 to 1844 <nl> - value % = kTen16 ; <nl> - <nl> - if ( a < 10 ) <nl> - * buffer + + = static_cast < char > ( ' 0 ' + static_cast < char > ( a ) ) ; <nl> - else if ( a < 100 ) { <nl> - const uint32_t i = a < < 1 ; <nl> - * buffer + + = cDigitsLut [ i ] ; <nl> - * buffer + + = cDigitsLut [ i + 1 ] ; <nl> - } <nl> - else if ( a < 1000 ) { <nl> - * buffer + + = static_cast < char > ( ' 0 ' + static_cast < char > ( a / 100 ) ) ; <nl> - <nl> - const uint32_t i = ( a % 100 ) < < 1 ; <nl> - * buffer + + = cDigitsLut [ i ] ; <nl> - * buffer + + = cDigitsLut [ i + 1 ] ; <nl> - } <nl> - else { <nl> - const uint32_t i = ( a / 100 ) < < 1 ; <nl> - const uint32_t j = ( a % 100 ) < < 1 ; <nl> - * buffer + + = cDigitsLut [ i ] ; <nl> - * buffer + + = cDigitsLut [ i + 1 ] ; <nl> - * buffer + + = cDigitsLut [ j ] ; <nl> - * buffer + + = cDigitsLut [ j + 1 ] ; <nl> - } <nl> - <nl> - const uint32_t v0 = static_cast < uint32_t > ( value / kTen8 ) ; <nl> - const uint32_t v1 = static_cast < uint32_t > ( value % kTen8 ) ; <nl> - <nl> - const uint32_t b0 = v0 / 10000 ; <nl> - const uint32_t c0 = v0 % 10000 ; <nl> - <nl> - const uint32_t d1 = ( b0 / 100 ) < < 1 ; <nl> - const uint32_t d2 = ( b0 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d3 = ( c0 / 100 ) < < 1 ; <nl> - const uint32_t d4 = ( c0 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t b1 = v1 / 10000 ; <nl> - const uint32_t c1 = v1 % 10000 ; <nl> - <nl> - const uint32_t d5 = ( b1 / 100 ) < < 1 ; <nl> - const uint32_t d6 = ( b1 % 100 ) < < 1 ; <nl> - <nl> - const uint32_t d7 = ( c1 / 100 ) < < 1 ; <nl> - const uint32_t d8 = ( c1 % 100 ) < < 1 ; <nl> - <nl> - * buffer + + = cDigitsLut [ d1 ] ; <nl> - * buffer + + = cDigitsLut [ d1 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d2 ] ; <nl> - * buffer + + = cDigitsLut [ d2 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d3 ] ; <nl> - * buffer + + = cDigitsLut [ d3 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d4 ] ; <nl> - * buffer + + = cDigitsLut [ d4 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d5 ] ; <nl> - * buffer + + = cDigitsLut [ d5 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d6 ] ; <nl> - * buffer + + = cDigitsLut [ d6 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d7 ] ; <nl> - * buffer + + = cDigitsLut [ d7 + 1 ] ; <nl> - * buffer + + = cDigitsLut [ d8 ] ; <nl> - * buffer + + = cDigitsLut [ d8 + 1 ] ; <nl> - } <nl> - <nl> - return buffer ; <nl> - } <nl> - <nl> - inline char * i64toa ( int64_t value , char * buffer ) { <nl> - if ( value < 0 ) { <nl> - * buffer + + = ' - ' ; <nl> - value = - value ; <nl> - } <nl> - <nl> - return u64toa ( static_cast < uint64_t > ( value ) , buffer ) ; <nl> - } <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_ITOA_ <nl> deleted file mode 100644 <nl> index dbe5450d6b9 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / meta . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_INTERNAL_META_H_ <nl> - # define RAPIDJSON_INTERNAL_META_H_ <nl> - <nl> - # ifndef RAPIDJSON_RAPIDJSON_H_ <nl> - # error < rapidjson . h > not yet included . Do not include this file directly . <nl> - # endif <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - # if defined ( _MSC_VER ) <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( 6334 ) <nl> - # endif <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_TYPETRAITS <nl> - # include < type_traits > <nl> - # endif <nl> - <nl> - / / @ cond RAPIDJSON_INTERNAL <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - / / Helper to wrap / convert arbitrary types to void , useful for arbitrary type matching <nl> - template < typename T > struct Void { typedef void Type ; } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / BoolType , TrueType , FalseType <nl> - / / <nl> - template < bool Cond > struct BoolType { <nl> - static const bool Value = Cond ; <nl> - typedef BoolType Type ; <nl> - } ; <nl> - typedef BoolType < true > TrueType ; <nl> - typedef BoolType < false > FalseType ; <nl> - <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / SelectIf , BoolExpr , NotExpr , AndExpr , OrExpr <nl> - / / <nl> - <nl> - template < bool C > struct SelectIfImpl { template < typename T1 , typename T2 > struct Apply { typedef T1 Type ; } ; } ; <nl> - template < > struct SelectIfImpl < false > { template < typename T1 , typename T2 > struct Apply { typedef T2 Type ; } ; } ; <nl> - template < bool C , typename T1 , typename T2 > struct SelectIfCond : SelectIfImpl < C > : : template Apply < T1 , T2 > { } ; <nl> - template < typename C , typename T1 , typename T2 > struct SelectIf : SelectIfCond < C : : Value , T1 , T2 > { } ; <nl> - <nl> - template < bool Cond1 , bool Cond2 > struct AndExprCond : FalseType { } ; <nl> - template < > struct AndExprCond < true , true > : TrueType { } ; <nl> - template < bool Cond1 , bool Cond2 > struct OrExprCond : TrueType { } ; <nl> - template < > struct OrExprCond < false , false > : FalseType { } ; <nl> - <nl> - template < typename C > struct BoolExpr : SelectIf < C , TrueType , FalseType > : : Type { } ; <nl> - template < typename C > struct NotExpr : SelectIf < C , FalseType , TrueType > : : Type { } ; <nl> - template < typename C1 , typename C2 > struct AndExpr : AndExprCond < C1 : : Value , C2 : : Value > : : Type { } ; <nl> - template < typename C1 , typename C2 > struct OrExpr : OrExprCond < C1 : : Value , C2 : : Value > : : Type { } ; <nl> - <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / AddConst , MaybeAddConst , RemoveConst <nl> - template < typename T > struct AddConst { typedef const T Type ; } ; <nl> - template < bool Constify , typename T > struct MaybeAddConst : SelectIfCond < Constify , const T , T > { } ; <nl> - template < typename T > struct RemoveConst { typedef T Type ; } ; <nl> - template < typename T > struct RemoveConst < const T > { typedef T Type ; } ; <nl> - <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / IsSame , IsConst , IsMoreConst , IsPointer <nl> - / / <nl> - template < typename T , typename U > struct IsSame : FalseType { } ; <nl> - template < typename T > struct IsSame < T , T > : TrueType { } ; <nl> - <nl> - template < typename T > struct IsConst : FalseType { } ; <nl> - template < typename T > struct IsConst < const T > : TrueType { } ; <nl> - <nl> - template < typename CT , typename T > <nl> - struct IsMoreConst <nl> - : AndExpr < IsSame < typename RemoveConst < CT > : : Type , typename RemoveConst < T > : : Type > , <nl> - BoolType < IsConst < CT > : : Value > = IsConst < T > : : Value > > : : Type { } ; <nl> - <nl> - template < typename T > struct IsPointer : FalseType { } ; <nl> - template < typename T > struct IsPointer < T * > : TrueType { } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / IsBaseOf <nl> - / / <nl> - # if RAPIDJSON_HAS_CXX11_TYPETRAITS <nl> - <nl> - template < typename B , typename D > struct IsBaseOf <nl> - : BoolType < : : std : : is_base_of < B , D > : : value > { } ; <nl> - <nl> - # else / / simplified version adopted from Boost <nl> - <nl> - template < typename B , typename D > struct IsBaseOfImpl { <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( B ) ! = 0 ) ; <nl> - RAPIDJSON_STATIC_ASSERT ( sizeof ( D ) ! = 0 ) ; <nl> - <nl> - typedef char ( & Yes ) [ 1 ] ; <nl> - typedef char ( & No ) [ 2 ] ; <nl> - <nl> - template < typename T > <nl> - static Yes Check ( const D * , T ) ; <nl> - static No Check ( const B * , int ) ; <nl> - <nl> - struct Host { <nl> - operator const B * ( ) const ; <nl> - operator const D * ( ) ; <nl> - } ; <nl> - <nl> - enum { Value = ( sizeof ( Check ( Host ( ) , 0 ) ) = = sizeof ( Yes ) ) } ; <nl> - } ; <nl> - <nl> - template < typename B , typename D > struct IsBaseOf <nl> - : OrExpr < IsSame < B , D > , BoolExpr < IsBaseOfImpl < B , D > > > : : Type { } ; <nl> - <nl> - # endif / / RAPIDJSON_HAS_CXX11_TYPETRAITS <nl> - <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / EnableIf / DisableIf <nl> - / / <nl> - template < bool Condition , typename T = void > struct EnableIfCond { typedef T Type ; } ; <nl> - template < typename T > struct EnableIfCond < false , T > { / * empty * / } ; <nl> - <nl> - template < bool Condition , typename T = void > struct DisableIfCond { typedef T Type ; } ; <nl> - template < typename T > struct DisableIfCond < true , T > { / * empty * / } ; <nl> - <nl> - template < typename Condition , typename T = void > <nl> - struct EnableIf : EnableIfCond < Condition : : Value , T > { } ; <nl> - <nl> - template < typename Condition , typename T = void > <nl> - struct DisableIf : DisableIfCond < Condition : : Value , T > { } ; <nl> - <nl> - / / SFINAE helpers <nl> - struct SfinaeTag { } ; <nl> - template < typename T > struct RemoveSfinaeTag ; <nl> - template < typename T > struct RemoveSfinaeTag < SfinaeTag & ( * ) ( T ) > { typedef T Type ; } ; <nl> - <nl> - # define RAPIDJSON_REMOVEFPTR_ ( type ) \ <nl> - typename : : rapidjson : : internal : : RemoveSfinaeTag \ <nl> - < : : rapidjson : : internal : : SfinaeTag & ( * ) type > : : Type <nl> - <nl> - # define RAPIDJSON_ENABLEIF ( cond ) \ <nl> - typename : : rapidjson : : internal : : EnableIf \ <nl> - < RAPIDJSON_REMOVEFPTR_ ( cond ) > : : Type * = NULL <nl> - <nl> - # define RAPIDJSON_DISABLEIF ( cond ) \ <nl> - typename : : rapidjson : : internal : : DisableIf \ <nl> - < RAPIDJSON_REMOVEFPTR_ ( cond ) > : : Type * = NULL <nl> - <nl> - # define RAPIDJSON_ENABLEIF_RETURN ( cond , returntype ) \ <nl> - typename : : rapidjson : : internal : : EnableIf \ <nl> - < RAPIDJSON_REMOVEFPTR_ ( cond ) , \ <nl> - RAPIDJSON_REMOVEFPTR_ ( returntype ) > : : Type <nl> - <nl> - # define RAPIDJSON_DISABLEIF_RETURN ( cond , returntype ) \ <nl> - typename : : rapidjson : : internal : : DisableIf \ <nl> - < RAPIDJSON_REMOVEFPTR_ ( cond ) , \ <nl> - RAPIDJSON_REMOVEFPTR_ ( returntype ) > : : Type <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - / / @ endcond <nl> - <nl> - # if defined ( __GNUC__ ) | | defined ( _MSC_VER ) <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_INTERNAL_META_H_ <nl> deleted file mode 100644 <nl> index 72e0dac9f6b . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / pow10 . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_POW10_ <nl> - # define RAPIDJSON_POW10_ <nl> - <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - / / ! Computes integer powers of 10 in double ( 10 . 0 ^ n ) . <nl> - / * ! This function uses lookup table for fast and accurate results . <nl> - \ param n non - negative exponent . Must < = 308 . <nl> - \ return 10 . 0 ^ n <nl> - * / <nl> - inline double Pow10 ( int n ) { <nl> - static const double e [ ] = { / / 1e - 0 . . . 1e308 : 309 * 8 bytes = 2472 bytes <nl> - 1e + 0 , <nl> - 1e + 1 , 1e + 2 , 1e + 3 , 1e + 4 , 1e + 5 , 1e + 6 , 1e + 7 , 1e + 8 , 1e + 9 , 1e + 10 , 1e + 11 , 1e + 12 , 1e + 13 , 1e + 14 , 1e + 15 , 1e + 16 , 1e + 17 , 1e + 18 , 1e + 19 , 1e + 20 , <nl> - 1e + 21 , 1e + 22 , 1e + 23 , 1e + 24 , 1e + 25 , 1e + 26 , 1e + 27 , 1e + 28 , 1e + 29 , 1e + 30 , 1e + 31 , 1e + 32 , 1e + 33 , 1e + 34 , 1e + 35 , 1e + 36 , 1e + 37 , 1e + 38 , 1e + 39 , 1e + 40 , <nl> - 1e + 41 , 1e + 42 , 1e + 43 , 1e + 44 , 1e + 45 , 1e + 46 , 1e + 47 , 1e + 48 , 1e + 49 , 1e + 50 , 1e + 51 , 1e + 52 , 1e + 53 , 1e + 54 , 1e + 55 , 1e + 56 , 1e + 57 , 1e + 58 , 1e + 59 , 1e + 60 , <nl> - 1e + 61 , 1e + 62 , 1e + 63 , 1e + 64 , 1e + 65 , 1e + 66 , 1e + 67 , 1e + 68 , 1e + 69 , 1e + 70 , 1e + 71 , 1e + 72 , 1e + 73 , 1e + 74 , 1e + 75 , 1e + 76 , 1e + 77 , 1e + 78 , 1e + 79 , 1e + 80 , <nl> - 1e + 81 , 1e + 82 , 1e + 83 , 1e + 84 , 1e + 85 , 1e + 86 , 1e + 87 , 1e + 88 , 1e + 89 , 1e + 90 , 1e + 91 , 1e + 92 , 1e + 93 , 1e + 94 , 1e + 95 , 1e + 96 , 1e + 97 , 1e + 98 , 1e + 99 , 1e + 100 , <nl> - 1e + 101 , 1e + 102 , 1e + 103 , 1e + 104 , 1e + 105 , 1e + 106 , 1e + 107 , 1e + 108 , 1e + 109 , 1e + 110 , 1e + 111 , 1e + 112 , 1e + 113 , 1e + 114 , 1e + 115 , 1e + 116 , 1e + 117 , 1e + 118 , 1e + 119 , 1e + 120 , <nl> - 1e + 121 , 1e + 122 , 1e + 123 , 1e + 124 , 1e + 125 , 1e + 126 , 1e + 127 , 1e + 128 , 1e + 129 , 1e + 130 , 1e + 131 , 1e + 132 , 1e + 133 , 1e + 134 , 1e + 135 , 1e + 136 , 1e + 137 , 1e + 138 , 1e + 139 , 1e + 140 , <nl> - 1e + 141 , 1e + 142 , 1e + 143 , 1e + 144 , 1e + 145 , 1e + 146 , 1e + 147 , 1e + 148 , 1e + 149 , 1e + 150 , 1e + 151 , 1e + 152 , 1e + 153 , 1e + 154 , 1e + 155 , 1e + 156 , 1e + 157 , 1e + 158 , 1e + 159 , 1e + 160 , <nl> - 1e + 161 , 1e + 162 , 1e + 163 , 1e + 164 , 1e + 165 , 1e + 166 , 1e + 167 , 1e + 168 , 1e + 169 , 1e + 170 , 1e + 171 , 1e + 172 , 1e + 173 , 1e + 174 , 1e + 175 , 1e + 176 , 1e + 177 , 1e + 178 , 1e + 179 , 1e + 180 , <nl> - 1e + 181 , 1e + 182 , 1e + 183 , 1e + 184 , 1e + 185 , 1e + 186 , 1e + 187 , 1e + 188 , 1e + 189 , 1e + 190 , 1e + 191 , 1e + 192 , 1e + 193 , 1e + 194 , 1e + 195 , 1e + 196 , 1e + 197 , 1e + 198 , 1e + 199 , 1e + 200 , <nl> - 1e + 201 , 1e + 202 , 1e + 203 , 1e + 204 , 1e + 205 , 1e + 206 , 1e + 207 , 1e + 208 , 1e + 209 , 1e + 210 , 1e + 211 , 1e + 212 , 1e + 213 , 1e + 214 , 1e + 215 , 1e + 216 , 1e + 217 , 1e + 218 , 1e + 219 , 1e + 220 , <nl> - 1e + 221 , 1e + 222 , 1e + 223 , 1e + 224 , 1e + 225 , 1e + 226 , 1e + 227 , 1e + 228 , 1e + 229 , 1e + 230 , 1e + 231 , 1e + 232 , 1e + 233 , 1e + 234 , 1e + 235 , 1e + 236 , 1e + 237 , 1e + 238 , 1e + 239 , 1e + 240 , <nl> - 1e + 241 , 1e + 242 , 1e + 243 , 1e + 244 , 1e + 245 , 1e + 246 , 1e + 247 , 1e + 248 , 1e + 249 , 1e + 250 , 1e + 251 , 1e + 252 , 1e + 253 , 1e + 254 , 1e + 255 , 1e + 256 , 1e + 257 , 1e + 258 , 1e + 259 , 1e + 260 , <nl> - 1e + 261 , 1e + 262 , 1e + 263 , 1e + 264 , 1e + 265 , 1e + 266 , 1e + 267 , 1e + 268 , 1e + 269 , 1e + 270 , 1e + 271 , 1e + 272 , 1e + 273 , 1e + 274 , 1e + 275 , 1e + 276 , 1e + 277 , 1e + 278 , 1e + 279 , 1e + 280 , <nl> - 1e + 281 , 1e + 282 , 1e + 283 , 1e + 284 , 1e + 285 , 1e + 286 , 1e + 287 , 1e + 288 , 1e + 289 , 1e + 290 , 1e + 291 , 1e + 292 , 1e + 293 , 1e + 294 , 1e + 295 , 1e + 296 , 1e + 297 , 1e + 298 , 1e + 299 , 1e + 300 , <nl> - 1e + 301 , 1e + 302 , 1e + 303 , 1e + 304 , 1e + 305 , 1e + 306 , 1e + 307 , 1e + 308 <nl> - } ; <nl> - RAPIDJSON_ASSERT ( n > = 0 & & n < = 308 ) ; <nl> - return e [ n ] ; <nl> - } <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_POW10_ <nl> deleted file mode 100644 <nl> index ea722c6f191 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / stack . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_INTERNAL_STACK_H_ <nl> - # define RAPIDJSON_INTERNAL_STACK_H_ <nl> - <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Stack <nl> - <nl> - / / ! A type - unsafe stack for storing different types of data . <nl> - / * ! \ tparam Allocator Allocator for allocating stack memory . <nl> - * / <nl> - template < typename Allocator > <nl> - class Stack { <nl> - public : <nl> - / / Optimization note : Do not allocate memory for stack_ in constructor . <nl> - / / Do it lazily when first Push ( ) - > Expand ( ) - > Resize ( ) . <nl> - Stack ( Allocator * allocator , size_t stackCapacity ) : allocator_ ( allocator ) , ownAllocator ( 0 ) , stack_ ( 0 ) , stackTop_ ( 0 ) , stackEnd_ ( 0 ) , initialCapacity_ ( stackCapacity ) { <nl> - RAPIDJSON_ASSERT ( stackCapacity > 0 ) ; <nl> - if ( ! allocator_ ) <nl> - ownAllocator = allocator_ = new Allocator ( ) ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - Stack ( Stack & & rhs ) <nl> - : allocator_ ( rhs . allocator_ ) , <nl> - ownAllocator ( rhs . ownAllocator ) , <nl> - stack_ ( rhs . stack_ ) , <nl> - stackTop_ ( rhs . stackTop_ ) , <nl> - stackEnd_ ( rhs . stackEnd_ ) , <nl> - initialCapacity_ ( rhs . initialCapacity_ ) <nl> - { <nl> - rhs . allocator_ = 0 ; <nl> - rhs . ownAllocator = 0 ; <nl> - rhs . stack_ = 0 ; <nl> - rhs . stackTop_ = 0 ; <nl> - rhs . stackEnd_ = 0 ; <nl> - rhs . initialCapacity_ = 0 ; <nl> - } <nl> - # endif <nl> - <nl> - ~ Stack ( ) { <nl> - Destroy ( ) ; <nl> - } <nl> - <nl> - # if RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - Stack & operator = ( Stack & & rhs ) { <nl> - if ( & rhs ! = this ) <nl> - { <nl> - Destroy ( ) ; <nl> - <nl> - allocator_ = rhs . allocator_ ; <nl> - ownAllocator = rhs . ownAllocator ; <nl> - stack_ = rhs . stack_ ; <nl> - stackTop_ = rhs . stackTop_ ; <nl> - stackEnd_ = rhs . stackEnd_ ; <nl> - initialCapacity_ = rhs . initialCapacity_ ; <nl> - <nl> - rhs . allocator_ = 0 ; <nl> - rhs . ownAllocator = 0 ; <nl> - rhs . stack_ = 0 ; <nl> - rhs . stackTop_ = 0 ; <nl> - rhs . stackEnd_ = 0 ; <nl> - rhs . initialCapacity_ = 0 ; <nl> - } <nl> - return * this ; <nl> - } <nl> - # endif <nl> - <nl> - void Clear ( ) { stackTop_ = stack_ ; } <nl> - <nl> - void ShrinkToFit ( ) { <nl> - if ( Empty ( ) ) { <nl> - / / If the stack is empty , completely deallocate the memory . <nl> - Allocator : : Free ( stack_ ) ; <nl> - stack_ = 0 ; <nl> - stackTop_ = 0 ; <nl> - stackEnd_ = 0 ; <nl> - } <nl> - else <nl> - Resize ( GetSize ( ) ) ; <nl> - } <nl> - <nl> - / / Optimization note : try to minimize the size of this function for force inline . <nl> - / / Expansion is run very infrequently , so it is moved to another ( probably non - inline ) function . <nl> - template < typename T > <nl> - RAPIDJSON_FORCEINLINE T * Push ( size_t count = 1 ) { <nl> - / / Expand the stack if needed <nl> - if ( stackTop_ + sizeof ( T ) * count > = stackEnd_ ) <nl> - Expand < T > ( count ) ; <nl> - <nl> - T * ret = reinterpret_cast < T * > ( stackTop_ ) ; <nl> - stackTop_ + = sizeof ( T ) * count ; <nl> - return ret ; <nl> - } <nl> - <nl> - template < typename T > <nl> - T * Pop ( size_t count ) { <nl> - RAPIDJSON_ASSERT ( GetSize ( ) > = count * sizeof ( T ) ) ; <nl> - stackTop_ - = count * sizeof ( T ) ; <nl> - return reinterpret_cast < T * > ( stackTop_ ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - T * Top ( ) { <nl> - RAPIDJSON_ASSERT ( GetSize ( ) > = sizeof ( T ) ) ; <nl> - return reinterpret_cast < T * > ( stackTop_ - sizeof ( T ) ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - T * Bottom ( ) { return ( T * ) stack_ ; } <nl> - <nl> - Allocator & GetAllocator ( ) { return * allocator_ ; } <nl> - bool Empty ( ) const { return stackTop_ = = stack_ ; } <nl> - size_t GetSize ( ) const { return static_cast < size_t > ( stackTop_ - stack_ ) ; } <nl> - size_t GetCapacity ( ) const { return static_cast < size_t > ( stackEnd_ - stack_ ) ; } <nl> - <nl> - private : <nl> - template < typename T > <nl> - void Expand ( size_t count ) { <nl> - / / Only expand the capacity if the current stack exists . Otherwise just create a stack with initial capacity . <nl> - size_t newCapacity ; <nl> - if ( stack_ = = 0 ) <nl> - newCapacity = initialCapacity_ ; <nl> - else { <nl> - newCapacity = GetCapacity ( ) ; <nl> - newCapacity + = ( newCapacity + 1 ) / 2 ; <nl> - } <nl> - size_t newSize = GetSize ( ) + sizeof ( T ) * count ; <nl> - if ( newCapacity < newSize ) <nl> - newCapacity = newSize ; <nl> - <nl> - Resize ( newCapacity ) ; <nl> - } <nl> - <nl> - void Resize ( size_t newCapacity ) { <nl> - const size_t size = GetSize ( ) ; / / Backup the current size <nl> - stack_ = ( char * ) allocator_ - > Realloc ( stack_ , GetCapacity ( ) , newCapacity ) ; <nl> - stackTop_ = stack_ + size ; <nl> - stackEnd_ = stack_ + newCapacity ; <nl> - } <nl> - <nl> - void Destroy ( ) { <nl> - Allocator : : Free ( stack_ ) ; <nl> - delete ownAllocator ; / / Only delete if it is owned by the stack <nl> - } <nl> - <nl> - / / Prohibit copy constructor & assignment operator . <nl> - Stack ( const Stack & ) ; <nl> - Stack & operator = ( const Stack & ) ; <nl> - <nl> - Allocator * allocator_ ; <nl> - Allocator * ownAllocator ; <nl> - char * stack_ ; <nl> - char * stackTop_ ; <nl> - char * stackEnd_ ; <nl> - size_t initialCapacity_ ; <nl> - } ; <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_STACK_H_ <nl> deleted file mode 100644 <nl> index 80adcb6b730 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / internal / strfunc . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ <nl> - # define RAPIDJSON_INTERNAL_STRFUNC_H_ <nl> - <nl> - namespace rapidjson { <nl> - namespace internal { <nl> - <nl> - / / ! Custom strlen ( ) which works on different character types . <nl> - / * ! \ tparam Ch Character type ( e . g . char , wchar_t , short ) <nl> - \ param s Null - terminated input string . <nl> - \ return Number of characters in the string . <nl> - \ note This has the same semantics as strlen ( ) , the return value is not number of Unicode codepoints . <nl> - * / <nl> - template < typename Ch > <nl> - inline SizeType StrLen ( const Ch * s ) { <nl> - const Ch * p = s ; <nl> - while ( * p ) + + p ; <nl> - return SizeType ( p - s ) ; <nl> - } <nl> - <nl> - } / / namespace internal <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_INTERNAL_STRFUNC_H_ <nl> deleted file mode 100644 <nl> index ef15c46780e . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / memorybuffer . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_MEMORYBUFFER_H_ <nl> - # define RAPIDJSON_MEMORYBUFFER_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include " internal / stack . h " <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Represents an in - memory output byte stream . <nl> - / * ! <nl> - This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream . <nl> - <nl> - It is similar to FileWriteBuffer but the destination is an in - memory buffer instead of a file . <nl> - <nl> - Differences between MemoryBuffer and StringBuffer : <nl> - 1 . StringBuffer has Encoding but MemoryBuffer is only a byte buffer . <nl> - 2 . StringBuffer : : GetString ( ) returns a null - terminated string . MemoryBuffer : : GetBuffer ( ) returns a buffer without terminator . <nl> - <nl> - \ tparam Allocator type for allocating memory buffer . <nl> - \ note implements Stream concept <nl> - * / <nl> - template < typename Allocator = CrtAllocator > <nl> - struct GenericMemoryBuffer { <nl> - typedef char Ch ; / / byte <nl> - <nl> - GenericMemoryBuffer ( Allocator * allocator = 0 , size_t capacity = kDefaultCapacity ) : stack_ ( allocator , capacity ) { } <nl> - <nl> - void Put ( Ch c ) { * stack_ . template Push < Ch > ( ) = c ; } <nl> - void Flush ( ) { } <nl> - <nl> - void Clear ( ) { stack_ . Clear ( ) ; } <nl> - void ShrinkToFit ( ) { stack_ . ShrinkToFit ( ) ; } <nl> - Ch * Push ( size_t count ) { return stack_ . template Push < Ch > ( count ) ; } <nl> - void Pop ( size_t count ) { stack_ . template Pop < Ch > ( count ) ; } <nl> - <nl> - const Ch * GetBuffer ( ) const { <nl> - return stack_ . template Bottom < Ch > ( ) ; <nl> - } <nl> - <nl> - size_t GetSize ( ) const { return stack_ . GetSize ( ) ; } <nl> - <nl> - static const size_t kDefaultCapacity = 256 ; <nl> - mutable internal : : Stack < Allocator > stack_ ; <nl> - } ; <nl> - <nl> - typedef GenericMemoryBuffer < > MemoryBuffer ; <nl> - <nl> - / / ! Implement specialized version of PutN ( ) with memset ( ) for better performance . <nl> - template < > <nl> - inline void PutN ( MemoryBuffer & memoryBuffer , char c , size_t n ) { <nl> - std : : memset ( memoryBuffer . stack_ . Push < char > ( n ) , c , n * sizeof ( c ) ) ; <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_MEMORYBUFFER_H_ <nl> deleted file mode 100644 <nl> index 6ed226e5a9c . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / memorystream . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_MEMORYSTREAM_H_ <nl> - # define RAPIDJSON_MEMORYSTREAM_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Represents an in - memory input byte stream . <nl> - / * ! <nl> - This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream . <nl> - <nl> - It is similar to FileReadBuffer but the source is an in - memory buffer instead of a file . <nl> - <nl> - Differences between MemoryStream and StringStream : <nl> - 1 . StringStream has encoding but MemoryStream is a byte stream . <nl> - 2 . MemoryStream needs size of the source buffer and the buffer don ' t need to be null terminated . StringStream assume null - terminated string as source . <nl> - 3 . MemoryStream supports Peek4 ( ) for encoding detection . StringStream is specified with an encoding so it should not have Peek4 ( ) . <nl> - \ note implements Stream concept <nl> - * / <nl> - struct MemoryStream { <nl> - typedef char Ch ; / / byte <nl> - <nl> - MemoryStream ( const Ch * src , size_t size ) : src_ ( src ) , begin_ ( src ) , end_ ( src + size ) , size_ ( size ) { } <nl> - <nl> - Ch Peek ( ) const { return ( src_ = = end_ ) ? ' \ 0 ' : * src_ ; } <nl> - Ch Take ( ) { return ( src_ = = end_ ) ? ' \ 0 ' : * src_ + + ; } <nl> - size_t Tell ( ) const { return static_cast < size_t > ( src_ - begin_ ) ; } <nl> - <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - void Put ( Ch ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - void Flush ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - / / For encoding detection only . <nl> - const Ch * Peek4 ( ) const { <nl> - return Tell ( ) + 4 < = size_ ? src_ : 0 ; <nl> - } <nl> - <nl> - const Ch * src_ ; / / ! < Current read position . <nl> - const Ch * begin_ ; / / ! < Original head of the string . <nl> - const Ch * end_ ; / / ! < End of stream . <nl> - size_t size_ ; / / ! < Size of the stream . <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_MEMORYBUFFER_H_ <nl> deleted file mode 100644 <nl> index ac7e32b6eef . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / msinttypes / inttypes . h <nl> ppp / dev / null <nl> <nl> - / / ISO C9x compliant inttypes . h for Microsoft Visual Studio <nl> - / / Based on ISO / IEC 9899 : TC2 Committee draft ( May 6 , 2005 ) WG14 / N1124 <nl> - / / <nl> - / / Copyright ( c ) 2006 - 2013 Alexander Chemeris <nl> - / / <nl> - / / Redistribution and use in source and binary forms , with or without <nl> - / / modification , are permitted provided that the following conditions are met : <nl> - / / <nl> - / / 1 . Redistributions of source code must retain the above copyright notice , <nl> - / / this list of conditions and the following disclaimer . <nl> - / / <nl> - / / 2 . Redistributions in binary form must reproduce the above copyright <nl> - / / notice , this list of conditions and the following disclaimer in the <nl> - / / documentation and / or other materials provided with the distribution . <nl> - / / <nl> - / / 3 . Neither the name of the product nor the names of its contributors may <nl> - / / be used to endorse or promote products derived from this software <nl> - / / without specific prior written permission . <nl> - / / <nl> - / / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR IMPLIED <nl> - / / WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF <nl> - / / MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO <nl> - / / EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , <nl> - / / SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , <nl> - / / PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; <nl> - / / OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , <nl> - / / WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR <nl> - / / OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF <nl> - / / ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> - / / <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - # ifndef _MSC_VER / / [ <nl> - # error " Use this header only with Microsoft Visual C + + compilers ! " <nl> - # endif / / _MSC_VER ] <nl> - <nl> - # ifndef _MSC_INTTYPES_H_ / / [ <nl> - # define _MSC_INTTYPES_H_ <nl> - <nl> - # if _MSC_VER > 1000 <nl> - # pragma once <nl> - # endif <nl> - <nl> - # include " stdint . h " <nl> - <nl> - / / 7 . 8 Format conversion of integer types <nl> - <nl> - typedef struct { <nl> - intmax_t quot ; <nl> - intmax_t rem ; <nl> - } imaxdiv_t ; <nl> - <nl> - / / 7 . 8 . 1 Macros for format specifiers <nl> - <nl> - # if ! defined ( __cplusplus ) | | defined ( __STDC_FORMAT_MACROS ) / / [ See footnote 185 at page 198 <nl> - <nl> - / / The fprintf macros for signed integers are : <nl> - # define PRId8 " d " <nl> - # define PRIi8 " i " <nl> - # define PRIdLEAST8 " d " <nl> - # define PRIiLEAST8 " i " <nl> - # define PRIdFAST8 " d " <nl> - # define PRIiFAST8 " i " <nl> - <nl> - # define PRId16 " hd " <nl> - # define PRIi16 " hi " <nl> - # define PRIdLEAST16 " hd " <nl> - # define PRIiLEAST16 " hi " <nl> - # define PRIdFAST16 " hd " <nl> - # define PRIiFAST16 " hi " <nl> - <nl> - # define PRId32 " I32d " <nl> - # define PRIi32 " I32i " <nl> - # define PRIdLEAST32 " I32d " <nl> - # define PRIiLEAST32 " I32i " <nl> - # define PRIdFAST32 " I32d " <nl> - # define PRIiFAST32 " I32i " <nl> - <nl> - # define PRId64 " I64d " <nl> - # define PRIi64 " I64i " <nl> - # define PRIdLEAST64 " I64d " <nl> - # define PRIiLEAST64 " I64i " <nl> - # define PRIdFAST64 " I64d " <nl> - # define PRIiFAST64 " I64i " <nl> - <nl> - # define PRIdMAX " I64d " <nl> - # define PRIiMAX " I64i " <nl> - <nl> - # define PRIdPTR " Id " <nl> - # define PRIiPTR " Ii " <nl> - <nl> - / / The fprintf macros for unsigned integers are : <nl> - # define PRIo8 " o " <nl> - # define PRIu8 " u " <nl> - # define PRIx8 " x " <nl> - # define PRIX8 " X " <nl> - # define PRIoLEAST8 " o " <nl> - # define PRIuLEAST8 " u " <nl> - # define PRIxLEAST8 " x " <nl> - # define PRIXLEAST8 " X " <nl> - # define PRIoFAST8 " o " <nl> - # define PRIuFAST8 " u " <nl> - # define PRIxFAST8 " x " <nl> - # define PRIXFAST8 " X " <nl> - <nl> - # define PRIo16 " ho " <nl> - # define PRIu16 " hu " <nl> - # define PRIx16 " hx " <nl> - # define PRIX16 " hX " <nl> - # define PRIoLEAST16 " ho " <nl> - # define PRIuLEAST16 " hu " <nl> - # define PRIxLEAST16 " hx " <nl> - # define PRIXLEAST16 " hX " <nl> - # define PRIoFAST16 " ho " <nl> - # define PRIuFAST16 " hu " <nl> - # define PRIxFAST16 " hx " <nl> - # define PRIXFAST16 " hX " <nl> - <nl> - # define PRIo32 " I32o " <nl> - # define PRIu32 " I32u " <nl> - # define PRIx32 " I32x " <nl> - # define PRIX32 " I32X " <nl> - # define PRIoLEAST32 " I32o " <nl> - # define PRIuLEAST32 " I32u " <nl> - # define PRIxLEAST32 " I32x " <nl> - # define PRIXLEAST32 " I32X " <nl> - # define PRIoFAST32 " I32o " <nl> - # define PRIuFAST32 " I32u " <nl> - # define PRIxFAST32 " I32x " <nl> - # define PRIXFAST32 " I32X " <nl> - <nl> - # define PRIo64 " I64o " <nl> - # define PRIu64 " I64u " <nl> - # define PRIx64 " I64x " <nl> - # define PRIX64 " I64X " <nl> - # define PRIoLEAST64 " I64o " <nl> - # define PRIuLEAST64 " I64u " <nl> - # define PRIxLEAST64 " I64x " <nl> - # define PRIXLEAST64 " I64X " <nl> - # define PRIoFAST64 " I64o " <nl> - # define PRIuFAST64 " I64u " <nl> - # define PRIxFAST64 " I64x " <nl> - # define PRIXFAST64 " I64X " <nl> - <nl> - # define PRIoMAX " I64o " <nl> - # define PRIuMAX " I64u " <nl> - # define PRIxMAX " I64x " <nl> - # define PRIXMAX " I64X " <nl> - <nl> - # define PRIoPTR " Io " <nl> - # define PRIuPTR " Iu " <nl> - # define PRIxPTR " Ix " <nl> - # define PRIXPTR " IX " <nl> - <nl> - / / The fscanf macros for signed integers are : <nl> - # define SCNd8 " d " <nl> - # define SCNi8 " i " <nl> - # define SCNdLEAST8 " d " <nl> - # define SCNiLEAST8 " i " <nl> - # define SCNdFAST8 " d " <nl> - # define SCNiFAST8 " i " <nl> - <nl> - # define SCNd16 " hd " <nl> - # define SCNi16 " hi " <nl> - # define SCNdLEAST16 " hd " <nl> - # define SCNiLEAST16 " hi " <nl> - # define SCNdFAST16 " hd " <nl> - # define SCNiFAST16 " hi " <nl> - <nl> - # define SCNd32 " ld " <nl> - # define SCNi32 " li " <nl> - # define SCNdLEAST32 " ld " <nl> - # define SCNiLEAST32 " li " <nl> - # define SCNdFAST32 " ld " <nl> - # define SCNiFAST32 " li " <nl> - <nl> - # define SCNd64 " I64d " <nl> - # define SCNi64 " I64i " <nl> - # define SCNdLEAST64 " I64d " <nl> - # define SCNiLEAST64 " I64i " <nl> - # define SCNdFAST64 " I64d " <nl> - # define SCNiFAST64 " I64i " <nl> - <nl> - # define SCNdMAX " I64d " <nl> - # define SCNiMAX " I64i " <nl> - <nl> - # ifdef _WIN64 / / [ <nl> - # define SCNdPTR " I64d " <nl> - # define SCNiPTR " I64i " <nl> - # else / / _WIN64 ] [ <nl> - # define SCNdPTR " ld " <nl> - # define SCNiPTR " li " <nl> - # endif / / _WIN64 ] <nl> - <nl> - / / The fscanf macros for unsigned integers are : <nl> - # define SCNo8 " o " <nl> - # define SCNu8 " u " <nl> - # define SCNx8 " x " <nl> - # define SCNX8 " X " <nl> - # define SCNoLEAST8 " o " <nl> - # define SCNuLEAST8 " u " <nl> - # define SCNxLEAST8 " x " <nl> - # define SCNXLEAST8 " X " <nl> - # define SCNoFAST8 " o " <nl> - # define SCNuFAST8 " u " <nl> - # define SCNxFAST8 " x " <nl> - # define SCNXFAST8 " X " <nl> - <nl> - # define SCNo16 " ho " <nl> - # define SCNu16 " hu " <nl> - # define SCNx16 " hx " <nl> - # define SCNX16 " hX " <nl> - # define SCNoLEAST16 " ho " <nl> - # define SCNuLEAST16 " hu " <nl> - # define SCNxLEAST16 " hx " <nl> - # define SCNXLEAST16 " hX " <nl> - # define SCNoFAST16 " ho " <nl> - # define SCNuFAST16 " hu " <nl> - # define SCNxFAST16 " hx " <nl> - # define SCNXFAST16 " hX " <nl> - <nl> - # define SCNo32 " lo " <nl> - # define SCNu32 " lu " <nl> - # define SCNx32 " lx " <nl> - # define SCNX32 " lX " <nl> - # define SCNoLEAST32 " lo " <nl> - # define SCNuLEAST32 " lu " <nl> - # define SCNxLEAST32 " lx " <nl> - # define SCNXLEAST32 " lX " <nl> - # define SCNoFAST32 " lo " <nl> - # define SCNuFAST32 " lu " <nl> - # define SCNxFAST32 " lx " <nl> - # define SCNXFAST32 " lX " <nl> - <nl> - # define SCNo64 " I64o " <nl> - # define SCNu64 " I64u " <nl> - # define SCNx64 " I64x " <nl> - # define SCNX64 " I64X " <nl> - # define SCNoLEAST64 " I64o " <nl> - # define SCNuLEAST64 " I64u " <nl> - # define SCNxLEAST64 " I64x " <nl> - # define SCNXLEAST64 " I64X " <nl> - # define SCNoFAST64 " I64o " <nl> - # define SCNuFAST64 " I64u " <nl> - # define SCNxFAST64 " I64x " <nl> - # define SCNXFAST64 " I64X " <nl> - <nl> - # define SCNoMAX " I64o " <nl> - # define SCNuMAX " I64u " <nl> - # define SCNxMAX " I64x " <nl> - # define SCNXMAX " I64X " <nl> - <nl> - # ifdef _WIN64 / / [ <nl> - # define SCNoPTR " I64o " <nl> - # define SCNuPTR " I64u " <nl> - # define SCNxPTR " I64x " <nl> - # define SCNXPTR " I64X " <nl> - # else / / _WIN64 ] [ <nl> - # define SCNoPTR " lo " <nl> - # define SCNuPTR " lu " <nl> - # define SCNxPTR " lx " <nl> - # define SCNXPTR " lX " <nl> - # endif / / _WIN64 ] <nl> - <nl> - # endif / / __STDC_FORMAT_MACROS ] <nl> - <nl> - / / 7 . 8 . 2 Functions for greatest - width integer types <nl> - <nl> - / / 7 . 8 . 2 . 1 The imaxabs function <nl> - # define imaxabs _abs64 <nl> - <nl> - / / 7 . 8 . 2 . 2 The imaxdiv function <nl> - <nl> - / / This is modified version of div ( ) function from Microsoft ' s div . c found <nl> - / / in % MSVC . NET % \ crt \ src \ div . c <nl> - # ifdef STATIC_IMAXDIV / / [ <nl> - static <nl> - # else / / STATIC_IMAXDIV ] [ <nl> - _inline <nl> - # endif / / STATIC_IMAXDIV ] <nl> - imaxdiv_t __cdecl imaxdiv ( intmax_t numer , intmax_t denom ) <nl> - { <nl> - imaxdiv_t result ; <nl> - <nl> - result . quot = numer / denom ; <nl> - result . rem = numer % denom ; <nl> - <nl> - if ( numer < 0 & & result . rem > 0 ) { <nl> - / / did division wrong ; must fix up <nl> - + + result . quot ; <nl> - result . rem - = denom ; <nl> - } <nl> - <nl> - return result ; <nl> - } <nl> - <nl> - / / 7 . 8 . 2 . 3 The strtoimax and strtoumax functions <nl> - # define strtoimax _strtoi64 <nl> - # define strtoumax _strtoui64 <nl> - <nl> - / / 7 . 8 . 2 . 4 The wcstoimax and wcstoumax functions <nl> - # define wcstoimax _wcstoi64 <nl> - # define wcstoumax _wcstoui64 <nl> - <nl> - <nl> - # endif / / _MSC_INTTYPES_H_ ] <nl> deleted file mode 100644 <nl> index bbad95af159 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / msinttypes / stdint . h <nl> ppp / dev / null <nl> <nl> - / / ISO C9x compliant stdint . h for Microsoft Visual Studio <nl> - / / Based on ISO / IEC 9899 : TC2 Committee draft ( May 6 , 2005 ) WG14 / N1124 <nl> - / / <nl> - / / Copyright ( c ) 2006 - 2013 Alexander Chemeris <nl> - / / <nl> - / / Redistribution and use in source and binary forms , with or without <nl> - / / modification , are permitted provided that the following conditions are met : <nl> - / / <nl> - / / 1 . Redistributions of source code must retain the above copyright notice , <nl> - / / this list of conditions and the following disclaimer . <nl> - / / <nl> - / / 2 . Redistributions in binary form must reproduce the above copyright <nl> - / / notice , this list of conditions and the following disclaimer in the <nl> - / / documentation and / or other materials provided with the distribution . <nl> - / / <nl> - / / 3 . Neither the name of the product nor the names of its contributors may <nl> - / / be used to endorse or promote products derived from this software <nl> - / / without specific prior written permission . <nl> - / / <nl> - / / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR IMPLIED <nl> - / / WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF <nl> - / / MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO <nl> - / / EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , <nl> - / / SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , <nl> - / / PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; <nl> - / / OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , <nl> - / / WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR <nl> - / / OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF <nl> - / / ADVISED OF THE POSSIBILITY OF SUCH DAMAGE . <nl> - / / <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - <nl> - # ifndef _MSC_VER / / [ <nl> - # error " Use this header only with Microsoft Visual C + + compilers ! " <nl> - # endif / / _MSC_VER ] <nl> - <nl> - # ifndef _MSC_STDINT_H_ / / [ <nl> - # define _MSC_STDINT_H_ <nl> - <nl> - # if _MSC_VER > 1000 <nl> - # pragma once <nl> - # endif <nl> - <nl> - / / miloyip : Originally Visual Studio 2010 uses its own stdint . h . However it generates warning with INT64_C ( ) , so change to use this file for vs2010 . <nl> - # if _MSC_VER > = 1600 / / [ <nl> - # include < stdint . h > <nl> - <nl> - # if ! defined ( __cplusplus ) | | defined ( __STDC_CONSTANT_MACROS ) / / [ See footnote 224 at page 260 <nl> - <nl> - # undef INT8_C <nl> - # undef INT16_C <nl> - # undef INT32_C <nl> - # undef INT64_C <nl> - # undef UINT8_C <nl> - # undef UINT16_C <nl> - # undef UINT32_C <nl> - # undef UINT64_C <nl> - <nl> - / / 7 . 18 . 4 . 1 Macros for minimum - width integer constants <nl> - <nl> - # define INT8_C ( val ) val # # i8 <nl> - # define INT16_C ( val ) val # # i16 <nl> - # define INT32_C ( val ) val # # i32 <nl> - # define INT64_C ( val ) val # # i64 <nl> - <nl> - # define UINT8_C ( val ) val # # ui8 <nl> - # define UINT16_C ( val ) val # # ui16 <nl> - # define UINT32_C ( val ) val # # ui32 <nl> - # define UINT64_C ( val ) val # # ui64 <nl> - <nl> - / / 7 . 18 . 4 . 2 Macros for greatest - width integer constants <nl> - / / These # ifndef ' s are needed to prevent collisions with < boost / cstdint . hpp > . <nl> - / / Check out Issue 9 for the details . <nl> - # ifndef INTMAX_C / / [ <nl> - # define INTMAX_C INT64_C <nl> - # endif / / INTMAX_C ] <nl> - # ifndef UINTMAX_C / / [ <nl> - # define UINTMAX_C UINT64_C <nl> - # endif / / UINTMAX_C ] <nl> - <nl> - # endif / / __STDC_CONSTANT_MACROS ] <nl> - <nl> - # else / / ] _MSC_VER > = 1700 [ <nl> - <nl> - # include < limits . h > <nl> - <nl> - / / For Visual Studio 6 in C + + mode and for many Visual Studio versions when <nl> - / / compiling for ARM we should wrap < wchar . h > include with ' extern " C + + " { } ' <nl> - / / or compiler give many errors like this : <nl> - / / error C2733 : second C linkage of overloaded function ' wmemchr ' not allowed <nl> - # ifdef __cplusplus <nl> - extern " C " { <nl> - # endif <nl> - # include < wchar . h > <nl> - # ifdef __cplusplus <nl> - } <nl> - # endif <nl> - <nl> - / / Define _W64 macros to mark types changing their size , like intptr_t . <nl> - # ifndef _W64 <nl> - # if ! defined ( __midl ) & & ( defined ( _X86_ ) | | defined ( _M_IX86 ) ) & & _MSC_VER > = 1300 <nl> - # define _W64 __w64 <nl> - # else <nl> - # define _W64 <nl> - # endif <nl> - # endif <nl> - <nl> - <nl> - / / 7 . 18 . 1 Integer types <nl> - <nl> - / / 7 . 18 . 1 . 1 Exact - width integer types <nl> - <nl> - / / Visual Studio 6 and Embedded Visual C + + 4 doesn ' t <nl> - / / realize that , e . g . char has the same size as __int8 <nl> - / / so we give up on __intX for them . <nl> - # if ( _MSC_VER < 1300 ) <nl> - typedef signed char int8_t ; <nl> - typedef signed short int16_t ; <nl> - typedef signed int int32_t ; <nl> - typedef unsigned char uint8_t ; <nl> - typedef unsigned short uint16_t ; <nl> - typedef unsigned int uint32_t ; <nl> - # else <nl> - typedef signed __int8 int8_t ; <nl> - typedef signed __int16 int16_t ; <nl> - typedef signed __int32 int32_t ; <nl> - typedef unsigned __int8 uint8_t ; <nl> - typedef unsigned __int16 uint16_t ; <nl> - typedef unsigned __int32 uint32_t ; <nl> - # endif <nl> - typedef signed __int64 int64_t ; <nl> - typedef unsigned __int64 uint64_t ; <nl> - <nl> - <nl> - / / 7 . 18 . 1 . 2 Minimum - width integer types <nl> - typedef int8_t int_least8_t ; <nl> - typedef int16_t int_least16_t ; <nl> - typedef int32_t int_least32_t ; <nl> - typedef int64_t int_least64_t ; <nl> - typedef uint8_t uint_least8_t ; <nl> - typedef uint16_t uint_least16_t ; <nl> - typedef uint32_t uint_least32_t ; <nl> - typedef uint64_t uint_least64_t ; <nl> - <nl> - / / 7 . 18 . 1 . 3 Fastest minimum - width integer types <nl> - typedef int8_t int_fast8_t ; <nl> - typedef int16_t int_fast16_t ; <nl> - typedef int32_t int_fast32_t ; <nl> - typedef int64_t int_fast64_t ; <nl> - typedef uint8_t uint_fast8_t ; <nl> - typedef uint16_t uint_fast16_t ; <nl> - typedef uint32_t uint_fast32_t ; <nl> - typedef uint64_t uint_fast64_t ; <nl> - <nl> - / / 7 . 18 . 1 . 4 Integer types capable of holding object pointers <nl> - # ifdef _WIN64 / / [ <nl> - typedef signed __int64 intptr_t ; <nl> - typedef unsigned __int64 uintptr_t ; <nl> - # else / / _WIN64 ] [ <nl> - typedef _W64 signed int intptr_t ; <nl> - typedef _W64 unsigned int uintptr_t ; <nl> - # endif / / _WIN64 ] <nl> - <nl> - / / 7 . 18 . 1 . 5 Greatest - width integer types <nl> - typedef int64_t intmax_t ; <nl> - typedef uint64_t uintmax_t ; <nl> - <nl> - <nl> - / / 7 . 18 . 2 Limits of specified - width integer types <nl> - <nl> - # if ! defined ( __cplusplus ) | | defined ( __STDC_LIMIT_MACROS ) / / [ See footnote 220 at page 257 and footnote 221 at page 259 <nl> - <nl> - / / 7 . 18 . 2 . 1 Limits of exact - width integer types <nl> - # define INT8_MIN ( ( int8_t ) _I8_MIN ) <nl> - # define INT8_MAX _I8_MAX <nl> - # define INT16_MIN ( ( int16_t ) _I16_MIN ) <nl> - # define INT16_MAX _I16_MAX <nl> - # define INT32_MIN ( ( int32_t ) _I32_MIN ) <nl> - # define INT32_MAX _I32_MAX <nl> - # define INT64_MIN ( ( int64_t ) _I64_MIN ) <nl> - # define INT64_MAX _I64_MAX <nl> - # define UINT8_MAX _UI8_MAX <nl> - # define UINT16_MAX _UI16_MAX <nl> - # define UINT32_MAX _UI32_MAX <nl> - # define UINT64_MAX _UI64_MAX <nl> - <nl> - / / 7 . 18 . 2 . 2 Limits of minimum - width integer types <nl> - # define INT_LEAST8_MIN INT8_MIN <nl> - # define INT_LEAST8_MAX INT8_MAX <nl> - # define INT_LEAST16_MIN INT16_MIN <nl> - # define INT_LEAST16_MAX INT16_MAX <nl> - # define INT_LEAST32_MIN INT32_MIN <nl> - # define INT_LEAST32_MAX INT32_MAX <nl> - # define INT_LEAST64_MIN INT64_MIN <nl> - # define INT_LEAST64_MAX INT64_MAX <nl> - # define UINT_LEAST8_MAX UINT8_MAX <nl> - # define UINT_LEAST16_MAX UINT16_MAX <nl> - # define UINT_LEAST32_MAX UINT32_MAX <nl> - # define UINT_LEAST64_MAX UINT64_MAX <nl> - <nl> - / / 7 . 18 . 2 . 3 Limits of fastest minimum - width integer types <nl> - # define INT_FAST8_MIN INT8_MIN <nl> - # define INT_FAST8_MAX INT8_MAX <nl> - # define INT_FAST16_MIN INT16_MIN <nl> - # define INT_FAST16_MAX INT16_MAX <nl> - # define INT_FAST32_MIN INT32_MIN <nl> - # define INT_FAST32_MAX INT32_MAX <nl> - # define INT_FAST64_MIN INT64_MIN <nl> - # define INT_FAST64_MAX INT64_MAX <nl> - # define UINT_FAST8_MAX UINT8_MAX <nl> - # define UINT_FAST16_MAX UINT16_MAX <nl> - # define UINT_FAST32_MAX UINT32_MAX <nl> - # define UINT_FAST64_MAX UINT64_MAX <nl> - <nl> - / / 7 . 18 . 2 . 4 Limits of integer types capable of holding object pointers <nl> - # ifdef _WIN64 / / [ <nl> - # define INTPTR_MIN INT64_MIN <nl> - # define INTPTR_MAX INT64_MAX <nl> - # define UINTPTR_MAX UINT64_MAX <nl> - # else / / _WIN64 ] [ <nl> - # define INTPTR_MIN INT32_MIN <nl> - # define INTPTR_MAX INT32_MAX <nl> - # define UINTPTR_MAX UINT32_MAX <nl> - # endif / / _WIN64 ] <nl> - <nl> - / / 7 . 18 . 2 . 5 Limits of greatest - width integer types <nl> - # define INTMAX_MIN INT64_MIN <nl> - # define INTMAX_MAX INT64_MAX <nl> - # define UINTMAX_MAX UINT64_MAX <nl> - <nl> - / / 7 . 18 . 3 Limits of other integer types <nl> - <nl> - # ifdef _WIN64 / / [ <nl> - # define PTRDIFF_MIN _I64_MIN <nl> - # define PTRDIFF_MAX _I64_MAX <nl> - # else / / _WIN64 ] [ <nl> - # define PTRDIFF_MIN _I32_MIN <nl> - # define PTRDIFF_MAX _I32_MAX <nl> - # endif / / _WIN64 ] <nl> - <nl> - # define SIG_ATOMIC_MIN INT_MIN <nl> - # define SIG_ATOMIC_MAX INT_MAX <nl> - <nl> - # ifndef SIZE_MAX / / [ <nl> - # ifdef _WIN64 / / [ <nl> - # define SIZE_MAX _UI64_MAX <nl> - # else / / _WIN64 ] [ <nl> - # define SIZE_MAX _UI32_MAX <nl> - # endif / / _WIN64 ] <nl> - # endif / / SIZE_MAX ] <nl> - <nl> - / / WCHAR_MIN and WCHAR_MAX are also defined in < wchar . h > <nl> - # ifndef WCHAR_MIN / / [ <nl> - # define WCHAR_MIN 0 <nl> - # endif / / WCHAR_MIN ] <nl> - # ifndef WCHAR_MAX / / [ <nl> - # define WCHAR_MAX _UI16_MAX <nl> - # endif / / WCHAR_MAX ] <nl> - <nl> - # define WINT_MIN 0 <nl> - # define WINT_MAX _UI16_MAX <nl> - <nl> - # endif / / __STDC_LIMIT_MACROS ] <nl> - <nl> - <nl> - / / 7 . 18 . 4 Limits of other integer types <nl> - <nl> - # if ! defined ( __cplusplus ) | | defined ( __STDC_CONSTANT_MACROS ) / / [ See footnote 224 at page 260 <nl> - <nl> - / / 7 . 18 . 4 . 1 Macros for minimum - width integer constants <nl> - <nl> - # define INT8_C ( val ) val # # i8 <nl> - # define INT16_C ( val ) val # # i16 <nl> - # define INT32_C ( val ) val # # i32 <nl> - # define INT64_C ( val ) val # # i64 <nl> - <nl> - # define UINT8_C ( val ) val # # ui8 <nl> - # define UINT16_C ( val ) val # # ui16 <nl> - # define UINT32_C ( val ) val # # ui32 <nl> - # define UINT64_C ( val ) val # # ui64 <nl> - <nl> - / / 7 . 18 . 4 . 2 Macros for greatest - width integer constants <nl> - / / These # ifndef ' s are needed to prevent collisions with < boost / cstdint . hpp > . <nl> - / / Check out Issue 9 for the details . <nl> - # ifndef INTMAX_C / / [ <nl> - # define INTMAX_C INT64_C <nl> - # endif / / INTMAX_C ] <nl> - # ifndef UINTMAX_C / / [ <nl> - # define UINTMAX_C UINT64_C <nl> - # endif / / UINTMAX_C ] <nl> - <nl> - # endif / / __STDC_CONSTANT_MACROS ] <nl> - <nl> - # endif / / _MSC_VER > = 1600 ] <nl> - <nl> - # endif / / _MSC_STDINT_H_ ] <nl> deleted file mode 100644 <nl> index 4eac8d76f83 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / prettywriter . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_PRETTYWRITER_H_ <nl> - # define RAPIDJSON_PRETTYWRITER_H_ <nl> - <nl> - # include " writer . h " <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( effc + + ) <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Writer with indentation and spacing . <nl> - / * ! <nl> - \ tparam OutputStream Type of ouptut os . <nl> - \ tparam SourceEncoding Encoding of source string . <nl> - \ tparam TargetEncoding Encoding of output stream . <nl> - \ tparam StackAllocator Type of allocator for allocating memory of stack . <nl> - * / <nl> - template < typename OutputStream , typename SourceEncoding = UTF8 < > , typename TargetEncoding = UTF8 < > , typename StackAllocator = CrtAllocator > <nl> - class PrettyWriter : public Writer < OutputStream , SourceEncoding , TargetEncoding , StackAllocator > { <nl> - public : <nl> - typedef Writer < OutputStream , SourceEncoding , TargetEncoding , StackAllocator > Base ; <nl> - typedef typename Base : : Ch Ch ; <nl> - <nl> - / / ! Constructor <nl> - / * ! \ param os Output stream . <nl> - \ param allocator User supplied allocator . If it is null , it will create a private one . <nl> - \ param levelDepth Initial capacity of stack . <nl> - * / <nl> - PrettyWriter ( OutputStream & os , StackAllocator * allocator = 0 , size_t levelDepth = Base : : kDefaultLevelDepth ) : <nl> - Base ( os , allocator , levelDepth ) , indentChar_ ( ' ' ) , indentCharCount_ ( 4 ) { } <nl> - <nl> - / / ! Set custom indentation . <nl> - / * ! \ param indentChar Character for indentation . Must be whitespace character ( ' ' , ' \ \ t ' , ' \ \ n ' , ' \ \ r ' ) . <nl> - \ param indentCharCount Number of indent characters for each indentation level . <nl> - \ note The default indentation is 4 spaces . <nl> - * / <nl> - PrettyWriter & SetIndent ( Ch indentChar , unsigned indentCharCount ) { <nl> - RAPIDJSON_ASSERT ( indentChar = = ' ' | | indentChar = = ' \ t ' | | indentChar = = ' \ n ' | | indentChar = = ' \ r ' ) ; <nl> - indentChar_ = indentChar ; <nl> - indentCharCount_ = indentCharCount ; <nl> - return * this ; <nl> - } <nl> - <nl> - / * ! @ name Implementation of Handler <nl> - \ see Handler <nl> - * / <nl> - / / @ { <nl> - <nl> - bool Null ( ) { PrettyPrefix ( kNullType ) ; return Base : : WriteNull ( ) ; } <nl> - bool Bool ( bool b ) { PrettyPrefix ( b ? kTrueType : kFalseType ) ; return Base : : WriteBool ( b ) ; } <nl> - bool Int ( int i ) { PrettyPrefix ( kNumberType ) ; return Base : : WriteInt ( i ) ; } <nl> - bool Uint ( unsigned u ) { PrettyPrefix ( kNumberType ) ; return Base : : WriteUint ( u ) ; } <nl> - bool Int64 ( int64_t i64 ) { PrettyPrefix ( kNumberType ) ; return Base : : WriteInt64 ( i64 ) ; } <nl> - bool Uint64 ( uint64_t u64 ) { PrettyPrefix ( kNumberType ) ; return Base : : WriteUint64 ( u64 ) ; } <nl> - bool Double ( double d ) { PrettyPrefix ( kNumberType ) ; return Base : : WriteDouble ( d ) ; } <nl> - <nl> - bool String ( const Ch * str , SizeType length , bool copy = false ) { <nl> - ( void ) copy ; <nl> - PrettyPrefix ( kStringType ) ; <nl> - return Base : : WriteString ( str , length ) ; <nl> - } <nl> - <nl> - bool StartObject ( ) { <nl> - PrettyPrefix ( kObjectType ) ; <nl> - new ( Base : : level_stack_ . template Push < typename Base : : Level > ( ) ) typename Base : : Level ( false ) ; <nl> - return Base : : WriteStartObject ( ) ; <nl> - } <nl> - <nl> - bool Key ( const Ch * str , SizeType length , bool copy = false ) { return String ( str , length , copy ) ; } <nl> - <nl> - bool EndObject ( SizeType memberCount = 0 ) { <nl> - ( void ) memberCount ; <nl> - RAPIDJSON_ASSERT ( Base : : level_stack_ . GetSize ( ) > = sizeof ( typename Base : : Level ) ) ; <nl> - RAPIDJSON_ASSERT ( ! Base : : level_stack_ . template Top < typename Base : : Level > ( ) - > inArray ) ; <nl> - bool empty = Base : : level_stack_ . template Pop < typename Base : : Level > ( 1 ) - > valueCount = = 0 ; <nl> - <nl> - if ( ! empty ) { <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - WriteIndent ( ) ; <nl> - } <nl> - if ( ! Base : : WriteEndObject ( ) ) <nl> - return false ; <nl> - if ( Base : : level_stack_ . Empty ( ) ) / / end of json text <nl> - Base : : os_ - > Flush ( ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool StartArray ( ) { <nl> - PrettyPrefix ( kArrayType ) ; <nl> - new ( Base : : level_stack_ . template Push < typename Base : : Level > ( ) ) typename Base : : Level ( true ) ; <nl> - return Base : : WriteStartArray ( ) ; <nl> - } <nl> - <nl> - bool EndArray ( SizeType memberCount = 0 ) { <nl> - ( void ) memberCount ; <nl> - RAPIDJSON_ASSERT ( Base : : level_stack_ . GetSize ( ) > = sizeof ( typename Base : : Level ) ) ; <nl> - RAPIDJSON_ASSERT ( Base : : level_stack_ . template Top < typename Base : : Level > ( ) - > inArray ) ; <nl> - bool empty = Base : : level_stack_ . template Pop < typename Base : : Level > ( 1 ) - > valueCount = = 0 ; <nl> - <nl> - if ( ! empty ) { <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - WriteIndent ( ) ; <nl> - } <nl> - if ( ! Base : : WriteEndArray ( ) ) <nl> - return false ; <nl> - if ( Base : : level_stack_ . Empty ( ) ) / / end of json text <nl> - Base : : os_ - > Flush ( ) ; <nl> - return true ; <nl> - } <nl> - <nl> - / / @ } <nl> - <nl> - / * ! @ name Convenience extensions * / <nl> - / / @ { <nl> - <nl> - / / ! Simpler but slower overload . <nl> - bool String ( const Ch * str ) { return String ( str , internal : : StrLen ( str ) ) ; } <nl> - bool Key ( const Ch * str ) { return Key ( str , internal : : StrLen ( str ) ) ; } <nl> - <nl> - / / @ } <nl> - protected : <nl> - void PrettyPrefix ( Type type ) { <nl> - ( void ) type ; <nl> - if ( Base : : level_stack_ . GetSize ( ) ! = 0 ) { / / this value is not at root <nl> - typename Base : : Level * level = Base : : level_stack_ . template Top < typename Base : : Level > ( ) ; <nl> - <nl> - if ( level - > inArray ) { <nl> - if ( level - > valueCount > 0 ) { <nl> - Base : : os_ - > Put ( ' , ' ) ; / / add comma if it is not the first element in array <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - } <nl> - else <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - WriteIndent ( ) ; <nl> - } <nl> - else { / / in object <nl> - if ( level - > valueCount > 0 ) { <nl> - if ( level - > valueCount % 2 = = 0 ) { <nl> - Base : : os_ - > Put ( ' , ' ) ; <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - } <nl> - else { <nl> - Base : : os_ - > Put ( ' : ' ) ; <nl> - Base : : os_ - > Put ( ' ' ) ; <nl> - } <nl> - } <nl> - else <nl> - Base : : os_ - > Put ( ' \ n ' ) ; <nl> - <nl> - if ( level - > valueCount % 2 = = 0 ) <nl> - WriteIndent ( ) ; <nl> - } <nl> - if ( ! level - > inArray & & level - > valueCount % 2 = = 0 ) <nl> - RAPIDJSON_ASSERT ( type = = kStringType ) ; / / if it ' s in object , then even number should be a name <nl> - level - > valueCount + + ; <nl> - } <nl> - else { <nl> - RAPIDJSON_ASSERT ( ! Base : : hasRoot_ ) ; / / Should only has one and only one root . <nl> - Base : : hasRoot_ = true ; <nl> - } <nl> - } <nl> - <nl> - void WriteIndent ( ) { <nl> - size_t count = ( Base : : level_stack_ . GetSize ( ) / sizeof ( typename Base : : Level ) ) * indentCharCount_ ; <nl> - PutN ( * Base : : os_ , indentChar_ , count ) ; <nl> - } <nl> - <nl> - Ch indentChar_ ; <nl> - unsigned indentCharCount_ ; <nl> - <nl> - private : <nl> - / / Prohibit copy constructor & assignment operator . <nl> - PrettyWriter ( const PrettyWriter & ) ; <nl> - PrettyWriter & operator = ( const PrettyWriter & ) ; <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # ifdef __GNUC__ <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_RAPIDJSON_H_ <nl> deleted file mode 100644 <nl> index 3f743234ddd . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / rapidjson . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_RAPIDJSON_H_ <nl> - # define RAPIDJSON_RAPIDJSON_H_ <nl> - <nl> - / / Copyright ( c ) 2011 Milo Yip ( miloyip @ gmail . com ) <nl> - / / Version 0 . 1 <nl> - <nl> - / * ! \ file rapidjson . h <nl> - \ brief common definitions and configuration <nl> - <nl> - \ see RAPIDJSON_CONFIG <nl> - * / <nl> - <nl> - / * ! \ defgroup RAPIDJSON_CONFIG RapidJSON configuration <nl> - \ brief Configuration macros for library features <nl> - <nl> - Some RapidJSON features are configurable to adapt the library to a wide <nl> - variety of platforms , environments and usage scenarios . Most of the <nl> - features can be configured in terms of overriden or predefined <nl> - preprocessor macros at compile - time . <nl> - <nl> - Some additional customization is available in the \ ref RAPIDJSON_ERRORS APIs . <nl> - <nl> - \ note These macros should be given on the compiler command - line <nl> - ( where applicable ) to avoid inconsistent values when compiling <nl> - different translation units of a single application . <nl> - * / <nl> - <nl> - # include < cstdlib > / / malloc ( ) , realloc ( ) , free ( ) , size_t <nl> - # include < cstring > / / memset ( ) , memcpy ( ) , memmove ( ) , memcmp ( ) <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_NO_INT64DEFINE <nl> - <nl> - / * ! \ def RAPIDJSON_NO_INT64DEFINE <nl> - \ ingroup RAPIDJSON_CONFIG <nl> - \ brief Use external 64 - bit integer types . <nl> - <nl> - RapidJSON requires the 64 - bit integer types \ c int64_t and \ c uint64_t types <nl> - to be available at global scope . <nl> - <nl> - If users have their own definition , define RAPIDJSON_NO_INT64DEFINE to <nl> - prevent RapidJSON from defining its own types . <nl> - * / <nl> - # ifndef RAPIDJSON_NO_INT64DEFINE <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - # ifdef _MSC_VER <nl> - # include " msinttypes / stdint . h " <nl> - # include " msinttypes / inttypes . h " <nl> - # else <nl> - / / Other compilers should have this . <nl> - # include < stdint . h > <nl> - # include < inttypes . h > <nl> - # endif <nl> - / / ! @ endcond <nl> - # ifdef RAPIDJSON_DOXYGEN_RUNNING <nl> - # define RAPIDJSON_NO_INT64DEFINE <nl> - # endif <nl> - # endif / / RAPIDJSON_NO_INT64TYPEDEF <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_FORCEINLINE <nl> - <nl> - # ifndef RAPIDJSON_FORCEINLINE <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - # ifdef _MSC_VER <nl> - # define RAPIDJSON_FORCEINLINE __forceinline <nl> - # elif defined ( __GNUC__ ) & & __GNUC__ > = 4 <nl> - # define RAPIDJSON_FORCEINLINE __attribute__ ( ( always_inline ) ) <nl> - # else <nl> - # define RAPIDJSON_FORCEINLINE <nl> - # endif <nl> - / / ! @ endcond <nl> - # endif / / RAPIDJSON_FORCEINLINE <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_ENDIAN <nl> - # define RAPIDJSON_LITTLEENDIAN 0 / / ! < Little endian machine <nl> - # define RAPIDJSON_BIGENDIAN 1 / / ! < Big endian machine <nl> - <nl> - / / ! Endianness of the machine . <nl> - / * ! <nl> - \ def RAPIDJSON_ENDIAN <nl> - \ ingroup RAPIDJSON_CONFIG <nl> - <nl> - GCC 4 . 6 provided macro for detecting endianness of the target machine . But other <nl> - compilers may not have this . User can define RAPIDJSON_ENDIAN to either <nl> - \ ref RAPIDJSON_LITTLEENDIAN or \ ref RAPIDJSON_BIGENDIAN . <nl> - <nl> - Default detection implemented with reference to <nl> - \ li https : / / gcc . gnu . org / onlinedocs / gcc - 4 . 6 . 0 / cpp / Common - Predefined - Macros . html <nl> - \ li http : / / www . boost . org / doc / libs / 1_42_0 / boost / detail / endian . hpp <nl> - * / <nl> - # ifndef RAPIDJSON_ENDIAN <nl> - / / Detect with GCC 4 . 6 ' s macro <nl> - # ifdef __BYTE_ORDER__ <nl> - # if __BYTE_ORDER__ = = __ORDER_LITTLE_ENDIAN__ <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN <nl> - # elif __BYTE_ORDER__ = = __ORDER_BIG_ENDIAN__ <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN <nl> - # else <nl> - # error Unknown machine endianess detected . User needs to define RAPIDJSON_ENDIAN . <nl> - # endif / / __BYTE_ORDER__ <nl> - / / Detect with GLIBC ' s endian . h <nl> - # elif defined ( __GLIBC__ ) <nl> - # include < endian . h > <nl> - # if ( __BYTE_ORDER = = __LITTLE_ENDIAN ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN <nl> - # elif ( __BYTE_ORDER = = __BIG_ENDIAN ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN <nl> - # else <nl> - # error Unknown machine endianess detected . User needs to define RAPIDJSON_ENDIAN . <nl> - # endif / / __GLIBC__ <nl> - / / Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro <nl> - # elif defined ( _LITTLE_ENDIAN ) & & ! defined ( _BIG_ENDIAN ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN <nl> - # elif defined ( _BIG_ENDIAN ) & & ! defined ( _LITTLE_ENDIAN ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN <nl> - / / Detect with architecture macros <nl> - # elif defined ( __sparc ) | | defined ( __sparc__ ) | | defined ( _POWER ) | | defined ( __powerpc__ ) | | defined ( __ppc__ ) | | defined ( __hpux ) | | defined ( __hppa ) | | defined ( _MIPSEB ) | | defined ( _POWER ) | | defined ( __s390__ ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN <nl> - # elif defined ( __i386__ ) | | defined ( __alpha__ ) | | defined ( __ia64 ) | | defined ( __ia64__ ) | | defined ( _M_IX86 ) | | defined ( _M_IA64 ) | | defined ( _M_ALPHA ) | | defined ( __amd64 ) | | defined ( __amd64__ ) | | defined ( _M_AMD64 ) | | defined ( __x86_64 ) | | defined ( __x86_64__ ) | | defined ( _M_X64 ) | | defined ( __bfin__ ) <nl> - # define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN <nl> - # elif defined ( RAPIDJSON_DOXYGEN_RUNNING ) <nl> - # define RAPIDJSON_ENDIAN <nl> - # else <nl> - # error Unknown machine endianess detected . User needs to define RAPIDJSON_ENDIAN . <nl> - # endif <nl> - # endif / / RAPIDJSON_ENDIAN <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_64BIT <nl> - <nl> - / / ! Whether using 64 - bit architecture <nl> - # ifndef RAPIDJSON_64BIT <nl> - # if defined ( __LP64__ ) | | defined ( _WIN64 ) <nl> - # define RAPIDJSON_64BIT 1 <nl> - # else <nl> - # define RAPIDJSON_64BIT 0 <nl> - # endif <nl> - # endif / / RAPIDJSON_64BIT <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_ALIGN <nl> - <nl> - / / ! Data alignment of the machine . <nl> - / * ! \ ingroup RAPIDJSON_CONFIG <nl> - \ param x pointer to align <nl> - <nl> - Some machines require strict data alignment . Currently the default uses 4 bytes <nl> - alignment . User can customize by defining the RAPIDJSON_ALIGN function macro . , <nl> - * / <nl> - # ifndef RAPIDJSON_ALIGN <nl> - # define RAPIDJSON_ALIGN ( x ) ( ( x + 3u ) & ~ 3u ) <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_UINT64_C2 <nl> - <nl> - / / ! Construct a 64 - bit literal by a pair of 32 - bit integer . <nl> - / * ! <nl> - 64 - bit literal with or without ULL suffix is prone to compiler warnings . <nl> - UINT64_C ( ) is C macro which cause compilation problems . <nl> - Use this macro to define 64 - bit constants by a pair of 32 - bit integer . <nl> - * / <nl> - # ifndef RAPIDJSON_UINT64_C2 <nl> - # define RAPIDJSON_UINT64_C2 ( high32 , low32 ) ( ( static_cast < uint64_t > ( high32 ) < < 32 ) | static_cast < uint64_t > ( low32 ) ) <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_SSE2 / RAPIDJSON_SSE42 / RAPIDJSON_SIMD <nl> - <nl> - / * ! \ def RAPIDJSON_SIMD <nl> - \ ingroup RAPIDJSON_CONFIG <nl> - \ brief Enable SSE2 / SSE4 . 2 optimization . <nl> - <nl> - RapidJSON supports optimized implementations for some parsing operations <nl> - based on the SSE2 or SSE4 . 2 SIMD extensions on modern Intel - compatible <nl> - processors . <nl> - <nl> - To enable these optimizations , two different symbols can be defined ; <nl> - \ code <nl> - / / Enable SSE2 optimization . <nl> - # define RAPIDJSON_SSE2 <nl> - <nl> - / / Enable SSE4 . 2 optimization . <nl> - # define RAPIDJSON_SSE42 <nl> - \ endcode <nl> - <nl> - \ c RAPIDJSON_SSE42 takes precedence , if both are defined . <nl> - <nl> - If any of these symbols is defined , RapidJSON defines the macro <nl> - \ c RAPIDJSON_SIMD to indicate the availability of the optimized code . <nl> - * / <nl> - # if defined ( RAPIDJSON_SSE2 ) | | defined ( RAPIDJSON_SSE42 ) \ <nl> - | | defined ( RAPIDJSON_DOXYGEN_RUNNING ) <nl> - # define RAPIDJSON_SIMD <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_NO_SIZETYPEDEFINE <nl> - <nl> - # ifndef RAPIDJSON_NO_SIZETYPEDEFINE <nl> - / * ! \ def RAPIDJSON_NO_SIZETYPEDEFINE <nl> - \ ingroup RAPIDJSON_CONFIG <nl> - \ brief User - provided \ c SizeType definition . <nl> - <nl> - In order to avoid using 32 - bit size types for indexing strings and arrays , <nl> - define this preprocessor symbol and provide the type rapidjson : : SizeType <nl> - before including RapidJSON : <nl> - \ code <nl> - # define RAPIDJSON_NO_SIZETYPEDEFINE <nl> - namespace rapidjson { typedef : : std : : size_t SizeType ; } <nl> - # include " rapidjson / . . . " <nl> - \ endcode <nl> - <nl> - \ see rapidjson : : SizeType <nl> - * / <nl> - # ifdef RAPIDJSON_DOXYGEN_RUNNING <nl> - # define RAPIDJSON_NO_SIZETYPEDEFINE <nl> - # endif <nl> - namespace rapidjson { <nl> - / / ! Size type ( for string lengths , array sizes , etc . ) <nl> - / * ! RapidJSON uses 32 - bit array / string indices even on 64 - bit platforms , <nl> - instead of using \ c size_t . Users may override the SizeType by defining <nl> - \ ref RAPIDJSON_NO_SIZETYPEDEFINE . <nl> - * / <nl> - typedef unsigned SizeType ; <nl> - } / / namespace rapidjson <nl> - # endif <nl> - <nl> - / / always import std : : size_t to rapidjson namespace <nl> - namespace rapidjson { <nl> - using std : : size_t ; <nl> - } / / namespace rapidjson <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_ASSERT <nl> - <nl> - / / ! Assertion . <nl> - / * ! \ ingroup RAPIDJSON_CONFIG <nl> - By default , rapidjson uses C \ c assert ( ) for internal assertions . <nl> - User can override it by defining RAPIDJSON_ASSERT ( x ) macro . <nl> - <nl> - \ note Parsing errors are handled and can be customized by the <nl> - \ ref RAPIDJSON_ERRORS APIs . <nl> - * / <nl> - # ifndef RAPIDJSON_ASSERT <nl> - # include < cassert > <nl> - # define RAPIDJSON_ASSERT ( x ) assert ( x ) <nl> - # endif / / RAPIDJSON_ASSERT <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_STATIC_ASSERT <nl> - <nl> - / / Adopt from boost <nl> - # ifndef RAPIDJSON_STATIC_ASSERT <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - namespace rapidjson { <nl> - <nl> - template < bool x > struct STATIC_ASSERTION_FAILURE ; <nl> - template < > struct STATIC_ASSERTION_FAILURE < true > { enum { value = 1 } ; } ; <nl> - template < int x > struct StaticAssertTest { } ; <nl> - } / / namespace rapidjson <nl> - <nl> - # define RAPIDJSON_JOIN ( X , Y ) RAPIDJSON_DO_JOIN ( X , Y ) <nl> - # define RAPIDJSON_DO_JOIN ( X , Y ) RAPIDJSON_DO_JOIN2 ( X , Y ) <nl> - # define RAPIDJSON_DO_JOIN2 ( X , Y ) X # # Y <nl> - <nl> - # if defined ( __GNUC__ ) <nl> - # define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE __attribute__ ( ( unused ) ) <nl> - # else <nl> - # define RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE <nl> - # endif <nl> - / / ! @ endcond <nl> - <nl> - / * ! \ def RAPIDJSON_STATIC_ASSERT <nl> - \ brief ( Internal ) macro to check for conditions at compile - time <nl> - \ param x compile - time condition <nl> - \ hideinitializer <nl> - * / <nl> - # define RAPIDJSON_STATIC_ASSERT ( x ) typedef : : rapidjson : : StaticAssertTest < \ <nl> - sizeof ( : : rapidjson : : STATIC_ASSERTION_FAILURE < bool ( x ) > ) > \ <nl> - RAPIDJSON_JOIN ( StaticAssertTypedef , __LINE__ ) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE <nl> - # endif <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Helpers <nl> - <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - <nl> - # define RAPIDJSON_MULTILINEMACRO_BEGIN do { <nl> - # define RAPIDJSON_MULTILINEMACRO_END \ <nl> - } while ( ( void ) 0 , 0 ) <nl> - <nl> - / / adopted from Boost <nl> - # define RAPIDJSON_VERSION_CODE ( x , y , z ) \ <nl> - ( ( ( x ) * 100000 ) + ( ( y ) * 100 ) + ( z ) ) <nl> - <nl> - / / token stringification <nl> - # define RAPIDJSON_STRINGIFY ( x ) RAPIDJSON_DO_STRINGIFY ( x ) <nl> - # define RAPIDJSON_DO_STRINGIFY ( x ) # x <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / RAPIDJSON_DIAG_PUSH / POP , RAPIDJSON_DIAG_OFF <nl> - <nl> - # if defined ( __GNUC__ ) <nl> - # define RAPIDJSON_GNUC \ <nl> - RAPIDJSON_VERSION_CODE ( __GNUC__ , __GNUC_MINOR__ , __GNUC_PATCHLEVEL__ ) <nl> - # endif <nl> - <nl> - # if defined ( __clang__ ) | | ( defined ( RAPIDJSON_GNUC ) & & RAPIDJSON_GNUC > = RAPIDJSON_VERSION_CODE ( 4 , 2 , 0 ) ) <nl> - <nl> - # define RAPIDJSON_PRAGMA ( x ) _Pragma ( RAPIDJSON_STRINGIFY ( x ) ) <nl> - # define RAPIDJSON_DIAG_PRAGMA ( x ) RAPIDJSON_PRAGMA ( GCC diagnostic x ) <nl> - # define RAPIDJSON_DIAG_OFF ( x ) \ <nl> - RAPIDJSON_DIAG_PRAGMA ( ignored RAPIDJSON_STRINGIFY ( RAPIDJSON_JOIN ( - W , x ) ) ) <nl> - <nl> - / / push / pop support in Clang and GCC > = 4 . 6 <nl> - # if defined ( __clang__ ) | | ( defined ( RAPIDJSON_GNUC ) & & RAPIDJSON_GNUC > = RAPIDJSON_VERSION_CODE ( 4 , 6 , 0 ) ) <nl> - # define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA ( push ) <nl> - # define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA ( pop ) <nl> - # else / / GCC > = 4 . 2 , < 4 . 6 <nl> - # define RAPIDJSON_DIAG_PUSH / * ignored * / <nl> - # define RAPIDJSON_DIAG_POP / * ignored * / <nl> - # endif <nl> - <nl> - # elif defined ( _MSC_VER ) <nl> - <nl> - / / pragma ( MSVC specific ) <nl> - # define RAPIDJSON_PRAGMA ( x ) __pragma ( x ) <nl> - # define RAPIDJSON_DIAG_PRAGMA ( x ) RAPIDJSON_PRAGMA ( warning ( x ) ) <nl> - <nl> - # define RAPIDJSON_DIAG_OFF ( x ) RAPIDJSON_DIAG_PRAGMA ( disable : x ) <nl> - # define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA ( push ) <nl> - # define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA ( pop ) <nl> - <nl> - # else <nl> - <nl> - # define RAPIDJSON_DIAG_OFF ( x ) / * ignored * / <nl> - # define RAPIDJSON_DIAG_PUSH / * ignored * / <nl> - # define RAPIDJSON_DIAG_POP / * ignored * / <nl> - <nl> - # endif / / RAPIDJSON_DIAG_ * <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / C + + 11 features <nl> - <nl> - # ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - # if defined ( __clang__ ) <nl> - # define RAPIDJSON_HAS_CXX11_RVALUE_REFS __has_feature ( cxx_rvalue_references ) <nl> - # elif ( defined ( RAPIDJSON_GNUC ) & & ( RAPIDJSON_GNUC > = RAPIDJSON_VERSION_CODE ( 4 , 3 , 0 ) ) & & defined ( __GXX_EXPERIMENTAL_CXX0X__ ) ) | | \ <nl> - ( defined ( _MSC_VER ) & & _MSC_VER > = 1600 ) <nl> - <nl> - # define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1 <nl> - # else <nl> - # define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0 <nl> - # endif <nl> - # endif / / RAPIDJSON_HAS_CXX11_RVALUE_REFS <nl> - <nl> - # ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT <nl> - # if defined ( __clang__ ) <nl> - # define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature ( cxx_noexcept ) <nl> - # elif ( defined ( RAPIDJSON_GNUC ) & & ( RAPIDJSON_GNUC > = RAPIDJSON_VERSION_CODE ( 4 , 6 , 0 ) ) & & defined ( __GXX_EXPERIMENTAL_CXX0X__ ) ) <nl> - / / ( defined ( _MSC_VER ) & & _MSC_VER > = ? ? ? ? ) / / not yet supported <nl> - # define RAPIDJSON_HAS_CXX11_NOEXCEPT 1 <nl> - # else <nl> - # define RAPIDJSON_HAS_CXX11_NOEXCEPT 0 <nl> - # endif <nl> - # endif <nl> - # if RAPIDJSON_HAS_CXX11_NOEXCEPT <nl> - # define RAPIDJSON_NOEXCEPT noexcept <nl> - # else <nl> - # define RAPIDJSON_NOEXCEPT / * noexcept * / <nl> - # endif / / RAPIDJSON_HAS_CXX11_NOEXCEPT <nl> - <nl> - / / no automatic detection , yet <nl> - # ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS <nl> - # define RAPIDJSON_HAS_CXX11_TYPETRAITS 0 <nl> - # endif <nl> - <nl> - / / ! @ endcond <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Allocators and Encodings <nl> - <nl> - # include " allocators . h " <nl> - # include " encodings . h " <nl> - <nl> - / / ! main RapidJSON namespace <nl> - namespace rapidjson { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Stream <nl> - <nl> - / * ! \ class rapidjson : : Stream <nl> - \ brief Concept for reading and writing characters . <nl> - <nl> - For read - only stream , no need to implement PutBegin ( ) , Put ( ) , Flush ( ) and PutEnd ( ) . <nl> - <nl> - For write - only stream , only need to implement Put ( ) and Flush ( ) . <nl> - <nl> - \ code <nl> - concept Stream { <nl> - typename Ch ; / / ! < Character type of the stream . <nl> - <nl> - / / ! Read the current character from stream without moving the read cursor . <nl> - Ch Peek ( ) const ; <nl> - <nl> - / / ! Read the current character from stream and moving the read cursor to next character . <nl> - Ch Take ( ) ; <nl> - <nl> - / / ! Get the current read cursor . <nl> - / / ! \ return Number of characters read from start . <nl> - size_t Tell ( ) ; <nl> - <nl> - / / ! Begin writing operation at the current read pointer . <nl> - / / ! \ return The begin writer pointer . <nl> - Ch * PutBegin ( ) ; <nl> - <nl> - / / ! Write a character . <nl> - void Put ( Ch c ) ; <nl> - <nl> - / / ! Flush the buffer . <nl> - void Flush ( ) ; <nl> - <nl> - / / ! End the writing operation . <nl> - / / ! \ param begin The begin write pointer returned by PutBegin ( ) . <nl> - / / ! \ return Number of characters written . <nl> - size_t PutEnd ( Ch * begin ) ; <nl> - } <nl> - \ endcode <nl> - * / <nl> - <nl> - / / ! Provides additional information for stream . <nl> - / * ! <nl> - By using traits pattern , this type provides a default configuration for stream . <nl> - For custom stream , this type can be specialized for other configuration . <nl> - See TEST ( Reader , CustomStringStream ) in readertest . cpp for example . <nl> - * / <nl> - template < typename Stream > <nl> - struct StreamTraits { <nl> - / / ! Whether to make local copy of stream for optimization during parsing . <nl> - / * ! <nl> - By default , for safety , streams do not use local copy optimization . <nl> - Stream that can be copied fast should specialize this , like StreamTraits < StringStream > . <nl> - * / <nl> - enum { copyOptimization = 0 } ; <nl> - } ; <nl> - <nl> - / / ! Put N copies of a character to a stream . <nl> - template < typename Stream , typename Ch > <nl> - inline void PutN ( Stream & stream , Ch c , size_t n ) { <nl> - for ( size_t i = 0 ; i < n ; i + + ) <nl> - stream . Put ( c ) ; <nl> - } <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / StringStream <nl> - <nl> - / / ! Read - only string stream . <nl> - / * ! \ note implements Stream concept <nl> - * / <nl> - template < typename Encoding > <nl> - struct GenericStringStream { <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - GenericStringStream ( const Ch * src ) : src_ ( src ) , head_ ( src ) { } <nl> - <nl> - Ch Peek ( ) const { return * src_ ; } <nl> - Ch Take ( ) { return * src_ + + ; } <nl> - size_t Tell ( ) const { return static_cast < size_t > ( src_ - head_ ) ; } <nl> - <nl> - Ch * PutBegin ( ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - void Put ( Ch ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - void Flush ( ) { RAPIDJSON_ASSERT ( false ) ; } <nl> - size_t PutEnd ( Ch * ) { RAPIDJSON_ASSERT ( false ) ; return 0 ; } <nl> - <nl> - const Ch * src_ ; / / ! < Current read position . <nl> - const Ch * head_ ; / / ! < Original head of the string . <nl> - } ; <nl> - <nl> - template < typename Encoding > <nl> - struct StreamTraits < GenericStringStream < Encoding > > { <nl> - enum { copyOptimization = 1 } ; <nl> - } ; <nl> - <nl> - / / ! String stream with UTF8 encoding . <nl> - typedef GenericStringStream < UTF8 < > > StringStream ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / InsituStringStream <nl> - <nl> - / / ! A read - write string stream . <nl> - / * ! This string stream is particularly designed for in - situ parsing . <nl> - \ note implements Stream concept <nl> - * / <nl> - template < typename Encoding > <nl> - struct GenericInsituStringStream { <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - GenericInsituStringStream ( Ch * src ) : src_ ( src ) , dst_ ( 0 ) , head_ ( src ) { } <nl> - <nl> - / / Read <nl> - Ch Peek ( ) { return * src_ ; } <nl> - Ch Take ( ) { return * src_ + + ; } <nl> - size_t Tell ( ) { return static_cast < size_t > ( src_ - head_ ) ; } <nl> - <nl> - / / Write <nl> - void Put ( Ch c ) { RAPIDJSON_ASSERT ( dst_ ! = 0 ) ; * dst_ + + = c ; } <nl> - <nl> - Ch * PutBegin ( ) { return dst_ = src_ ; } <nl> - size_t PutEnd ( Ch * begin ) { return static_cast < size_t > ( dst_ - begin ) ; } <nl> - void Flush ( ) { } <nl> - <nl> - Ch * Push ( size_t count ) { Ch * begin = dst_ ; dst_ + = count ; return begin ; } <nl> - void Pop ( size_t count ) { dst_ - = count ; } <nl> - <nl> - Ch * src_ ; <nl> - Ch * dst_ ; <nl> - Ch * head_ ; <nl> - } ; <nl> - <nl> - template < typename Encoding > <nl> - struct StreamTraits < GenericInsituStringStream < Encoding > > { <nl> - enum { copyOptimization = 1 } ; <nl> - } ; <nl> - <nl> - / / ! Insitu string stream with UTF8 encoding . <nl> - typedef GenericInsituStringStream < UTF8 < > > InsituStringStream ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Type <nl> - <nl> - / / ! Type of JSON value <nl> - enum Type { <nl> - kNullType = 0 , / / ! < null <nl> - kFalseType = 1 , / / ! < false <nl> - kTrueType = 2 , / / ! < true <nl> - kObjectType = 3 , / / ! < object <nl> - kArrayType = 4 , / / ! < array <nl> - kStringType = 5 , / / ! < string <nl> - kNumberType = 6 / / ! < number <nl> - } ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_RAPIDJSON_H_ <nl> deleted file mode 100644 <nl> index f41ba2fd7b8 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / reader . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_READER_H_ <nl> - # define RAPIDJSON_READER_H_ <nl> - <nl> - / * ! \ file reader . h * / <nl> - <nl> - # include " rapidjson . h " <nl> - # include " encodings . h " <nl> - # include " internal / meta . h " <nl> - # include " internal / pow10 . h " <nl> - # include " internal / stack . h " <nl> - <nl> - # if defined ( RAPIDJSON_SIMD ) & & defined ( _MSC_VER ) <nl> - # include < intrin . h > <nl> - # pragma intrinsic ( _BitScanForward ) <nl> - # endif <nl> - # ifdef RAPIDJSON_SSE42 <nl> - # include < nmmintrin . h > <nl> - # elif defined ( RAPIDJSON_SSE2 ) <nl> - # include < emmintrin . h > <nl> - # endif <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( 4127 ) / / conditional expression is constant <nl> - RAPIDJSON_DIAG_OFF ( 4702 ) / / unreachable code <nl> - # endif <nl> - <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - # define RAPIDJSON_NOTHING / * deliberately empty * / <nl> - # ifndef RAPIDJSON_PARSE_ERROR_EARLY_RETURN <nl> - # define RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( value ) \ <nl> - RAPIDJSON_MULTILINEMACRO_BEGIN \ <nl> - if ( HasParseError ( ) ) { return value ; } \ <nl> - RAPIDJSON_MULTILINEMACRO_END <nl> - # endif <nl> - # define RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID \ <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( RAPIDJSON_NOTHING ) <nl> - / / ! @ endcond <nl> - <nl> - / * ! \ def RAPIDJSON_PARSE_ERROR_NORETURN <nl> - \ ingroup RAPIDJSON_ERRORS <nl> - \ brief Macro to indicate a parse error . <nl> - \ param parseErrorCode \ ref rapidjson : : ParseErrorCode of the error <nl> - \ param offset position of the error in JSON input ( \ c size_t ) <nl> - <nl> - This macros can be used as a customization point for the internal <nl> - error handling mechanism of RapidJSON . <nl> - <nl> - A common usage model is to throw an exception instead of requiring the <nl> - caller to explicitly check the \ ref rapidjson : : GenericReader : : Parse ' s <nl> - return value : <nl> - <nl> - \ code <nl> - # define RAPIDJSON_PARSE_ERROR_NORETURN ( parseErrorCode , offset ) \ <nl> - throw ParseException ( parseErrorCode , # parseErrorCode , offset ) <nl> - <nl> - # include < stdexcept > / / std : : runtime_error <nl> - # include " rapidjson / error / error . h " / / rapidjson : : ParseResult <nl> - <nl> - struct ParseException : std : : runtime_error , rapidjson : : ParseResult { <nl> - ParseException ( rapidjson : : ParseErrorCode code , const char * msg , size_t offset ) <nl> - : std : : runtime_error ( msg ) , ParseResult ( code , offset ) { } <nl> - } ; <nl> - <nl> - # include " rapidjson / reader . h " <nl> - \ endcode <nl> - <nl> - \ see RAPIDJSON_PARSE_ERROR , rapidjson : : GenericReader : : Parse <nl> - * / <nl> - # ifndef RAPIDJSON_PARSE_ERROR_NORETURN <nl> - # define RAPIDJSON_PARSE_ERROR_NORETURN ( parseErrorCode , offset ) \ <nl> - RAPIDJSON_MULTILINEMACRO_BEGIN \ <nl> - RAPIDJSON_ASSERT ( ! HasParseError ( ) ) ; / * Error can only be assigned once * / \ <nl> - SetParseError ( parseErrorCode , offset ) ; \ <nl> - RAPIDJSON_MULTILINEMACRO_END <nl> - # endif <nl> - <nl> - / * ! \ def RAPIDJSON_PARSE_ERROR <nl> - \ ingroup RAPIDJSON_ERRORS <nl> - \ brief ( Internal ) macro to indicate and handle a parse error . <nl> - \ param parseErrorCode \ ref rapidjson : : ParseErrorCode of the error <nl> - \ param offset position of the error in JSON input ( \ c size_t ) <nl> - <nl> - Invokes RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing . <nl> - <nl> - \ see RAPIDJSON_PARSE_ERROR_NORETURN <nl> - \ hideinitializer <nl> - * / <nl> - # ifndef RAPIDJSON_PARSE_ERROR <nl> - # define RAPIDJSON_PARSE_ERROR ( parseErrorCode , offset ) \ <nl> - RAPIDJSON_MULTILINEMACRO_BEGIN \ <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( parseErrorCode , offset ) ; \ <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; \ <nl> - RAPIDJSON_MULTILINEMACRO_END <nl> - # endif <nl> - <nl> - # include " error / error . h " / / ParseErrorCode , ParseResult <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / ParseFlag <nl> - <nl> - / / ! Combination of parseFlags <nl> - / * ! \ see Reader : : Parse , Document : : Parse , Document : : ParseInsitu , Document : : ParseStream <nl> - * / <nl> - enum ParseFlag { <nl> - kParseDefaultFlags = 0 , / / ! < Default parse flags . Non - destructive parsing . Text strings are decoded into allocated buffer . <nl> - kParseInsituFlag = 1 , / / ! < In - situ ( destructive ) parsing . <nl> - kParseValidateEncodingFlag = 2 , / / ! < Validate encoding of JSON strings . <nl> - kParseIterativeFlag = 4 , / / ! < Iterative ( constant complexity in terms of function call stack size ) parsing . <nl> - kParseStopWhenDoneFlag = 8 / / ! < After parsing a complete JSON root from stream , stop further processing the rest of stream . When this flag is used , parser will not generate kParseErrorDocumentRootNotSingular error . <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / Handler <nl> - <nl> - / * ! \ class rapidjson : : Handler <nl> - \ brief Concept for receiving events from GenericReader upon parsing . <nl> - The functions return true if no error occurs . If they return false , <nl> - the event publisher should terminate the process . <nl> - \ code <nl> - concept Handler { <nl> - typename Ch ; <nl> - <nl> - bool Null ( ) ; <nl> - bool Bool ( bool b ) ; <nl> - bool Int ( int i ) ; <nl> - bool Uint ( unsigned i ) ; <nl> - bool Int64 ( int64_t i ) ; <nl> - bool Uint64 ( uint64_t i ) ; <nl> - bool Double ( double d ) ; <nl> - bool String ( const Ch * str , SizeType length , bool copy ) ; <nl> - bool StartObject ( ) ; <nl> - bool Key ( const Ch * str , SizeType length , bool copy ) ; <nl> - bool EndObject ( SizeType memberCount ) ; <nl> - bool StartArray ( ) ; <nl> - bool EndArray ( SizeType elementCount ) ; <nl> - } ; <nl> - \ endcode <nl> - * / <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / BaseReaderHandler <nl> - <nl> - / / ! Default implementation of Handler . <nl> - / * ! This can be used as base class of any reader handler . <nl> - \ note implements Handler concept <nl> - * / <nl> - template < typename Encoding = UTF8 < > , typename Derived = void > <nl> - struct BaseReaderHandler { <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - typedef typename internal : : SelectIf < internal : : IsSame < Derived , void > , BaseReaderHandler , Derived > : : Type Override ; <nl> - <nl> - bool Default ( ) { return true ; } <nl> - bool Null ( ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Bool ( bool ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Int ( int ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Uint ( unsigned ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Int64 ( int64_t ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Uint64 ( uint64_t ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Double ( double ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool String ( const Ch * , SizeType , bool ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool StartObject ( ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool Key ( const Ch * str , SizeType len , bool copy ) { return static_cast < Override & > ( * this ) . String ( str , len , copy ) ; } <nl> - bool EndObject ( SizeType ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool StartArray ( ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - bool EndArray ( SizeType ) { return static_cast < Override & > ( * this ) . Default ( ) ; } <nl> - } ; <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / StreamLocalCopy <nl> - <nl> - namespace internal { <nl> - <nl> - template < typename Stream , int = StreamTraits < Stream > : : copyOptimization > <nl> - class StreamLocalCopy ; <nl> - <nl> - / / ! Do copy optimization . <nl> - template < typename Stream > <nl> - class StreamLocalCopy < Stream , 1 > { <nl> - public : <nl> - StreamLocalCopy ( Stream & original ) : s ( original ) , original_ ( original ) { } <nl> - ~ StreamLocalCopy ( ) { original_ = s ; } <nl> - <nl> - Stream s ; <nl> - <nl> - private : <nl> - StreamLocalCopy & operator = ( const StreamLocalCopy & ) / * = delete * / ; <nl> - <nl> - Stream & original_ ; <nl> - } ; <nl> - <nl> - / / ! Keep reference . <nl> - template < typename Stream > <nl> - class StreamLocalCopy < Stream , 0 > { <nl> - public : <nl> - StreamLocalCopy ( Stream & original ) : s ( original ) { } <nl> - <nl> - Stream & s ; <nl> - <nl> - private : <nl> - StreamLocalCopy & operator = ( const StreamLocalCopy & ) / * = delete * / ; <nl> - } ; <nl> - <nl> - } / / namespace internal <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / SkipWhitespace <nl> - <nl> - / / ! Skip the JSON white spaces in a stream . <nl> - / * ! \ param is A input stream for skipping white spaces . <nl> - \ note This function has SSE2 / SSE4 . 2 specialization . <nl> - * / <nl> - template < typename InputStream > <nl> - void SkipWhitespace ( InputStream & is ) { <nl> - internal : : StreamLocalCopy < InputStream > copy ( is ) ; <nl> - InputStream & s ( copy . s ) ; <nl> - <nl> - while ( s . Peek ( ) = = ' ' | | s . Peek ( ) = = ' \ n ' | | s . Peek ( ) = = ' \ r ' | | s . Peek ( ) = = ' \ t ' ) <nl> - s . Take ( ) ; <nl> - } <nl> - <nl> - # ifdef RAPIDJSON_SSE42 <nl> - / / ! Skip whitespace with SSE 4 . 2 pcmpistrm instruction , testing 16 8 - byte characters at once . <nl> - inline const char * SkipWhitespace_SIMD ( const char * p ) { <nl> - / / Fast return for single non - whitespace <nl> - if ( * p = = ' ' | | * p = = ' \ n ' | | * p = = ' \ r ' | | * p = = ' \ t ' ) <nl> - + + p ; <nl> - else <nl> - return p ; <nl> - <nl> - / / 16 - byte align to the next boundary <nl> - const char * nextAligned = reinterpret_cast < const char * > ( ( reinterpret_cast < size_t > ( p ) + 15 ) & ~ 15 ) ; <nl> - while ( p ! = nextAligned ) <nl> - if ( * p = = ' ' | | * p = = ' \ n ' | | * p = = ' \ r ' | | * p = = ' \ t ' ) <nl> - + + p ; <nl> - else <nl> - return p ; <nl> - <nl> - / / The rest of string using SIMD <nl> - static const char whitespace [ 16 ] = " \ n \ r \ t " ; <nl> - const __m128i w = _mm_loadu_si128 ( ( const __m128i * ) & whitespace [ 0 ] ) ; <nl> - <nl> - for ( ; ; p + = 16 ) { <nl> - const __m128i s = _mm_load_si128 ( ( const __m128i * ) p ) ; <nl> - const unsigned r = _mm_cvtsi128_si32 ( _mm_cmpistrm ( w , s , _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_BIT_MASK | _SIDD_NEGATIVE_POLARITY ) ) ; <nl> - if ( r ! = 0 ) { / / some of characters is non - whitespace <nl> - # ifdef _MSC_VER / / Find the index of first non - whitespace <nl> - unsigned long offset ; <nl> - _BitScanForward ( & offset , r ) ; <nl> - return p + offset ; <nl> - # else <nl> - return p + __builtin_ffs ( r ) - 1 ; <nl> - # endif <nl> - } <nl> - } <nl> - } <nl> - <nl> - # elif defined ( RAPIDJSON_SSE2 ) <nl> - <nl> - / / ! Skip whitespace with SSE2 instructions , testing 16 8 - byte characters at once . <nl> - inline const char * SkipWhitespace_SIMD ( const char * p ) { <nl> - / / Fast return for single non - whitespace <nl> - if ( * p = = ' ' | | * p = = ' \ n ' | | * p = = ' \ r ' | | * p = = ' \ t ' ) <nl> - + + p ; <nl> - else <nl> - return p ; <nl> - <nl> - / / 16 - byte align to the next boundary <nl> - const char * nextAligned = reinterpret_cast < const char * > ( ( reinterpret_cast < size_t > ( p ) + 15 ) & ~ 15 ) ; <nl> - while ( p ! = nextAligned ) <nl> - if ( * p = = ' ' | | * p = = ' \ n ' | | * p = = ' \ r ' | | * p = = ' \ t ' ) <nl> - + + p ; <nl> - else <nl> - return p ; <nl> - <nl> - / / The rest of string <nl> - static const char whitespaces [ 4 ] [ 17 ] = { <nl> - " " , <nl> - " \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n " , <nl> - " \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r \ r " , <nl> - " \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t \ t " } ; <nl> - <nl> - const __m128i w0 = _mm_loadu_si128 ( ( const __m128i * ) & whitespaces [ 0 ] [ 0 ] ) ; <nl> - const __m128i w1 = _mm_loadu_si128 ( ( const __m128i * ) & whitespaces [ 1 ] [ 0 ] ) ; <nl> - const __m128i w2 = _mm_loadu_si128 ( ( const __m128i * ) & whitespaces [ 2 ] [ 0 ] ) ; <nl> - const __m128i w3 = _mm_loadu_si128 ( ( const __m128i * ) & whitespaces [ 3 ] [ 0 ] ) ; <nl> - <nl> - for ( ; ; p + = 16 ) { <nl> - const __m128i s = _mm_load_si128 ( ( const __m128i * ) p ) ; <nl> - __m128i x = _mm_cmpeq_epi8 ( s , w0 ) ; <nl> - x = _mm_or_si128 ( x , _mm_cmpeq_epi8 ( s , w1 ) ) ; <nl> - x = _mm_or_si128 ( x , _mm_cmpeq_epi8 ( s , w2 ) ) ; <nl> - x = _mm_or_si128 ( x , _mm_cmpeq_epi8 ( s , w3 ) ) ; <nl> - unsigned short r = ( unsigned short ) ~ _mm_movemask_epi8 ( x ) ; <nl> - if ( r ! = 0 ) { / / some of characters may be non - whitespace <nl> - # ifdef _MSC_VER / / Find the index of first non - whitespace <nl> - unsigned long offset ; <nl> - _BitScanForward ( & offset , r ) ; <nl> - return p + offset ; <nl> - # else <nl> - return p + __builtin_ffs ( r ) - 1 ; <nl> - # endif <nl> - } <nl> - } <nl> - } <nl> - <nl> - # endif / / RAPIDJSON_SSE2 <nl> - <nl> - # ifdef RAPIDJSON_SIMD <nl> - / / ! Template function specialization for InsituStringStream <nl> - template < > inline void SkipWhitespace ( InsituStringStream & is ) { <nl> - is . src_ = const_cast < char * > ( SkipWhitespace_SIMD ( is . src_ ) ) ; <nl> - } <nl> - <nl> - / / ! Template function specialization for StringStream <nl> - template < > inline void SkipWhitespace ( StringStream & is ) { <nl> - is . src_ = SkipWhitespace_SIMD ( is . src_ ) ; <nl> - } <nl> - # endif / / RAPIDJSON_SIMD <nl> - <nl> - / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> - / / GenericReader <nl> - <nl> - / / ! SAX - style JSON parser . Use \ ref Reader for UTF8 encoding and default allocator . <nl> - / * ! GenericReader parses JSON text from a stream , and send events synchronously to an <nl> - object implementing Handler concept . <nl> - <nl> - It needs to allocate a stack for storing a single decoded string during <nl> - non - destructive parsing . <nl> - <nl> - For in - situ parsing , the decoded string is directly written to the source <nl> - text string , no temporary buffer is required . <nl> - <nl> - A GenericReader object can be reused for parsing multiple JSON text . <nl> - <nl> - \ tparam SourceEncoding Encoding of the input stream . <nl> - \ tparam TargetEncoding Encoding of the parse output . <nl> - \ tparam StackAllocator Allocator type for stack . <nl> - * / <nl> - template < typename SourceEncoding , typename TargetEncoding , typename StackAllocator = CrtAllocator > <nl> - class GenericReader { <nl> - public : <nl> - typedef typename SourceEncoding : : Ch Ch ; / / ! < SourceEncoding character type <nl> - <nl> - / / ! Constructor . <nl> - / * ! \ param allocator Optional allocator for allocating stack memory . ( Only use for non - destructive parsing ) <nl> - \ param stackCapacity stack capacity in bytes for storing a single decoded string . ( Only use for non - destructive parsing ) <nl> - * / <nl> - GenericReader ( StackAllocator * stackAllocator = 0 , size_t stackCapacity = kDefaultStackCapacity ) : stack_ ( stackAllocator , stackCapacity ) , parseResult_ ( ) { } <nl> - <nl> - / / ! Parse JSON text . <nl> - / * ! \ tparam parseFlags Combination of \ ref ParseFlag . <nl> - \ tparam InputStream Type of input stream , implementing Stream concept . <nl> - \ tparam Handler Type of handler , implementing Handler concept . <nl> - \ param is Input stream to be parsed . <nl> - \ param handler The handler to receive events . <nl> - \ return Whether the parsing is successful . <nl> - * / <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - ParseResult Parse ( InputStream & is , Handler & handler ) { <nl> - if ( parseFlags & kParseIterativeFlag ) <nl> - return IterativeParse < parseFlags > ( is , handler ) ; <nl> - <nl> - parseResult_ . Clear ( ) ; <nl> - <nl> - ClearStackOnExit scope ( * this ) ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - if ( is . Peek ( ) = = ' \ 0 ' ) { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorDocumentEmpty , is . Tell ( ) ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( parseResult_ ) ; <nl> - } <nl> - else { <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( parseResult_ ) ; <nl> - <nl> - if ( ! ( parseFlags & kParseStopWhenDoneFlag ) ) { <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - if ( is . Peek ( ) ! = ' \ 0 ' ) { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorDocumentRootNotSingular , is . Tell ( ) ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( parseResult_ ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - return parseResult_ ; <nl> - } <nl> - <nl> - / / ! Parse JSON text ( with \ ref kParseDefaultFlags ) <nl> - / * ! \ tparam InputStream Type of input stream , implementing Stream concept <nl> - \ tparam Handler Type of handler , implementing Handler concept . <nl> - \ param is Input stream to be parsed . <nl> - \ param handler The handler to receive events . <nl> - \ return Whether the parsing is successful . <nl> - * / <nl> - template < typename InputStream , typename Handler > <nl> - ParseResult Parse ( InputStream & is , Handler & handler ) { <nl> - return Parse < kParseDefaultFlags > ( is , handler ) ; <nl> - } <nl> - <nl> - / / ! Whether a parse error has occured in the last parsing . <nl> - bool HasParseError ( ) const { return parseResult_ . IsError ( ) ; } <nl> - <nl> - / / ! Get the \ ref ParseErrorCode of last parsing . <nl> - ParseErrorCode GetParseErrorCode ( ) const { return parseResult_ . Code ( ) ; } <nl> - <nl> - / / ! Get the position of last parsing error in input , 0 otherwise . <nl> - size_t GetErrorOffset ( ) const { return parseResult_ . Offset ( ) ; } <nl> - <nl> - protected : <nl> - void SetParseError ( ParseErrorCode code , size_t offset ) { parseResult_ . Set ( code , offset ) ; } <nl> - <nl> - private : <nl> - / / Prohibit copy constructor & assignment operator . <nl> - GenericReader ( const GenericReader & ) ; <nl> - GenericReader & operator = ( const GenericReader & ) ; <nl> - <nl> - void ClearStack ( ) { stack_ . Clear ( ) ; } <nl> - <nl> - / / clear stack on any exit from ParseStream , e . g . due to exception <nl> - struct ClearStackOnExit { <nl> - explicit ClearStackOnExit ( GenericReader & r ) : r_ ( r ) { } <nl> - ~ ClearStackOnExit ( ) { r_ . ClearStack ( ) ; } <nl> - private : <nl> - GenericReader & r_ ; <nl> - ClearStackOnExit ( const ClearStackOnExit & ) ; <nl> - ClearStackOnExit & operator = ( const ClearStackOnExit & ) ; <nl> - } ; <nl> - <nl> - / / Parse object : { string : value , . . . } <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseObject ( InputStream & is , Handler & handler ) { <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' { ' ) ; <nl> - is . Take ( ) ; / / Skip ' { ' <nl> - <nl> - if ( ! handler . StartObject ( ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - if ( is . Peek ( ) = = ' } ' ) { <nl> - is . Take ( ) ; <nl> - if ( ! handler . EndObject ( 0 ) ) / / empty object <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - return ; <nl> - } <nl> - <nl> - for ( SizeType memberCount = 0 ; ; ) { <nl> - if ( is . Peek ( ) ! = ' " ' ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissName , is . Tell ( ) ) ; <nl> - <nl> - ParseString < parseFlags > ( is , handler , true ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - if ( is . Take ( ) ! = ' : ' ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissColon , is . Tell ( ) ) ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - + + memberCount ; <nl> - <nl> - switch ( is . Take ( ) ) { <nl> - case ' , ' : SkipWhitespace ( is ) ; break ; <nl> - case ' } ' : <nl> - if ( ! handler . EndObject ( memberCount ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - else <nl> - return ; <nl> - default : RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissCommaOrCurlyBracket , is . Tell ( ) ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - / / Parse array : [ value , . . . ] <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseArray ( InputStream & is , Handler & handler ) { <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' [ ' ) ; <nl> - is . Take ( ) ; / / Skip ' [ ' <nl> - <nl> - if ( ! handler . StartArray ( ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - if ( is . Peek ( ) = = ' ] ' ) { <nl> - is . Take ( ) ; <nl> - if ( ! handler . EndArray ( 0 ) ) / / empty array <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - return ; <nl> - } <nl> - <nl> - for ( SizeType elementCount = 0 ; ; ) { <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; <nl> - <nl> - + + elementCount ; <nl> - SkipWhitespace ( is ) ; <nl> - <nl> - switch ( is . Take ( ) ) { <nl> - case ' , ' : SkipWhitespace ( is ) ; break ; <nl> - case ' ] ' : <nl> - if ( ! handler . EndArray ( elementCount ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - else <nl> - return ; <nl> - default : RAPIDJSON_PARSE_ERROR ( kParseErrorArrayMissCommaOrSquareBracket , is . Tell ( ) ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseNull ( InputStream & is , Handler & handler ) { <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' n ' ) ; <nl> - is . Take ( ) ; <nl> - <nl> - if ( is . Take ( ) = = ' u ' & & is . Take ( ) = = ' l ' & & is . Take ( ) = = ' l ' ) { <nl> - if ( ! handler . Null ( ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorValueInvalid , is . Tell ( ) - 1 ) ; <nl> - } <nl> - <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseTrue ( InputStream & is , Handler & handler ) { <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' t ' ) ; <nl> - is . Take ( ) ; <nl> - <nl> - if ( is . Take ( ) = = ' r ' & & is . Take ( ) = = ' u ' & & is . Take ( ) = = ' e ' ) { <nl> - if ( ! handler . Bool ( true ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorValueInvalid , is . Tell ( ) - 1 ) ; <nl> - } <nl> - <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseFalse ( InputStream & is , Handler & handler ) { <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' f ' ) ; <nl> - is . Take ( ) ; <nl> - <nl> - if ( is . Take ( ) = = ' a ' & & is . Take ( ) = = ' l ' & & is . Take ( ) = = ' s ' & & is . Take ( ) = = ' e ' ) { <nl> - if ( ! handler . Bool ( false ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorValueInvalid , is . Tell ( ) - 1 ) ; <nl> - } <nl> - <nl> - / / Helper function to parse four hexidecimal digits in \ uXXXX in ParseString ( ) . <nl> - template < typename InputStream > <nl> - unsigned ParseHex4 ( InputStream & is ) { <nl> - unsigned codepoint = 0 ; <nl> - for ( int i = 0 ; i < 4 ; i + + ) { <nl> - Ch c = is . Take ( ) ; <nl> - codepoint < < = 4 ; <nl> - codepoint + = static_cast < unsigned > ( c ) ; <nl> - if ( c > = ' 0 ' & & c < = ' 9 ' ) <nl> - codepoint - = ' 0 ' ; <nl> - else if ( c > = ' A ' & & c < = ' F ' ) <nl> - codepoint - = ' A ' - 10 ; <nl> - else if ( c > = ' a ' & & c < = ' f ' ) <nl> - codepoint - = ' a ' - 10 ; <nl> - else { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorStringUnicodeEscapeInvalidHex , is . Tell ( ) - 1 ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN ( 0 ) ; <nl> - } <nl> - } <nl> - return codepoint ; <nl> - } <nl> - <nl> - class StackStream { <nl> - public : <nl> - typedef typename TargetEncoding : : Ch Ch ; <nl> - <nl> - StackStream ( internal : : Stack < StackAllocator > & stack ) : stack_ ( stack ) , length_ ( 0 ) { } <nl> - RAPIDJSON_FORCEINLINE void Put ( Ch c ) { <nl> - * stack_ . template Push < Ch > ( ) = c ; <nl> - + + length_ ; <nl> - } <nl> - internal : : Stack < StackAllocator > & stack_ ; <nl> - SizeType length_ ; <nl> - <nl> - private : <nl> - StackStream ( const StackStream & ) ; <nl> - StackStream & operator = ( const StackStream & ) ; <nl> - } ; <nl> - <nl> - / / Parse string and generate String event . Different code paths for kParseInsituFlag . <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseString ( InputStream & is , Handler & handler , bool isKey = false ) { <nl> - internal : : StreamLocalCopy < InputStream > copy ( is ) ; <nl> - InputStream & s ( copy . s ) ; <nl> - <nl> - bool success = false ; <nl> - if ( parseFlags & kParseInsituFlag ) { <nl> - typename InputStream : : Ch * head = s . PutBegin ( ) ; <nl> - ParseStringToStream < parseFlags , SourceEncoding , SourceEncoding > ( s , s ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; <nl> - size_t length = s . PutEnd ( head ) - 1 ; <nl> - RAPIDJSON_ASSERT ( length < = 0xFFFFFFFF ) ; <nl> - const typename TargetEncoding : : Ch * const str = ( typename TargetEncoding : : Ch * ) head ; <nl> - success = ( isKey ? handler . Key ( str , SizeType ( length ) , false ) : handler . String ( str , SizeType ( length ) , false ) ) ; <nl> - } <nl> - else { <nl> - StackStream stackStream ( stack_ ) ; <nl> - ParseStringToStream < parseFlags , SourceEncoding , TargetEncoding > ( s , stackStream ) ; <nl> - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID ; <nl> - const typename TargetEncoding : : Ch * const str = stack_ . template Pop < typename TargetEncoding : : Ch > ( stackStream . length_ ) ; <nl> - success = ( isKey ? handler . Key ( str , stackStream . length_ - 1 , true ) : handler . String ( str , stackStream . length_ - 1 , true ) ) ; <nl> - } <nl> - if ( ! success ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , s . Tell ( ) ) ; <nl> - } <nl> - <nl> - / / Parse string to an output is <nl> - / / This function handles the prefix / suffix double quotes , escaping , and optional encoding validation . <nl> - template < unsigned parseFlags , typename SEncoding , typename TEncoding , typename InputStream , typename OutputStream > <nl> - RAPIDJSON_FORCEINLINE void ParseStringToStream ( InputStream & is , OutputStream & os ) { <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - # define Z16 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 <nl> - static const char escape [ 256 ] = { <nl> - Z16 , Z16 , 0 , 0 , ' \ " ' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ' / ' , <nl> - Z16 , Z16 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ' \ \ ' , 0 , 0 , 0 , <nl> - 0 , 0 , ' \ b ' , 0 , 0 , 0 , ' \ f ' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ' \ n ' , 0 , <nl> - 0 , 0 , ' \ r ' , 0 , ' \ t ' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , <nl> - Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 <nl> - } ; <nl> - # undef Z16 <nl> - / / ! @ endcond <nl> - <nl> - RAPIDJSON_ASSERT ( is . Peek ( ) = = ' \ " ' ) ; <nl> - is . Take ( ) ; / / Skip ' \ " ' <nl> - <nl> - for ( ; ; ) { <nl> - Ch c = is . Peek ( ) ; <nl> - if ( c = = ' \ \ ' ) { / / Escape <nl> - is . Take ( ) ; <nl> - Ch e = is . Take ( ) ; <nl> - if ( ( sizeof ( Ch ) = = 1 | | unsigned ( e ) < 256 ) & & escape [ ( unsigned char ) e ] ) { <nl> - os . Put ( escape [ ( unsigned char ) e ] ) ; <nl> - } <nl> - else if ( e = = ' u ' ) { / / Unicode <nl> - unsigned codepoint = ParseHex4 ( is ) ; <nl> - if ( codepoint > = 0xD800 & & codepoint < = 0xDBFF ) { <nl> - / / Handle UTF - 16 surrogate pair <nl> - if ( is . Take ( ) ! = ' \ \ ' | | is . Take ( ) ! = ' u ' ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringUnicodeSurrogateInvalid , is . Tell ( ) - 2 ) ; <nl> - unsigned codepoint2 = ParseHex4 ( is ) ; <nl> - if ( codepoint2 < 0xDC00 | | codepoint2 > 0xDFFF ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringUnicodeSurrogateInvalid , is . Tell ( ) - 2 ) ; <nl> - codepoint = ( ( ( codepoint - 0xD800 ) < < 10 ) | ( codepoint2 - 0xDC00 ) ) + 0x10000 ; <nl> - } <nl> - TEncoding : : Encode ( os , codepoint ) ; <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringEscapeInvalid , is . Tell ( ) - 1 ) ; <nl> - } <nl> - else if ( c = = ' " ' ) { / / Closing double quote <nl> - is . Take ( ) ; <nl> - os . Put ( ' \ 0 ' ) ; / / null - terminate the string <nl> - return ; <nl> - } <nl> - else if ( c = = ' \ 0 ' ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringMissQuotationMark , is . Tell ( ) - 1 ) ; <nl> - else if ( ( unsigned ) c < 0x20 ) / / RFC 4627 : unescaped = % x20 - 21 / % x23 - 5B / % x5D - 10FFFF <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringEscapeInvalid , is . Tell ( ) - 1 ) ; <nl> - else { <nl> - if ( parseFlags & kParseValidateEncodingFlag ? <nl> - ! Transcoder < SEncoding , TEncoding > : : Validate ( is , os ) : <nl> - ! Transcoder < SEncoding , TEncoding > : : Transcode ( is , os ) ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorStringInvalidEncoding , is . Tell ( ) ) ; <nl> - } <nl> - } <nl> - } <nl> - <nl> - inline double StrtodFastPath ( double significand , int exp ) { <nl> - / / Fast path only works on limited range of values . <nl> - / / But for simplicity and performance , currently only implement this . <nl> - / / see http : / / www . exploringbinary . com / fast - path - decimal - to - floating - point - conversion / <nl> - if ( exp < - 308 ) <nl> - return 0 . 0 ; <nl> - else if ( exp > = 0 ) <nl> - return significand * internal : : Pow10 ( exp ) ; <nl> - else <nl> - return significand / internal : : Pow10 ( - exp ) ; <nl> - } <nl> - <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseNumber ( InputStream & is , Handler & handler ) { <nl> - internal : : StreamLocalCopy < InputStream > copy ( is ) ; <nl> - InputStream & s ( copy . s ) ; <nl> - <nl> - / / Parse minus <nl> - bool minus = false ; <nl> - if ( s . Peek ( ) = = ' - ' ) { <nl> - minus = true ; <nl> - s . Take ( ) ; <nl> - } <nl> - <nl> - / / Parse int : zero / ( digit1 - 9 * DIGIT ) <nl> - unsigned i = 0 ; <nl> - uint64_t i64 = 0 ; <nl> - bool use64bit = false ; <nl> - if ( s . Peek ( ) = = ' 0 ' ) { <nl> - i = 0 ; <nl> - s . Take ( ) ; <nl> - } <nl> - else if ( s . Peek ( ) > = ' 1 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - i = static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - <nl> - if ( minus ) <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( i > = 214748364 ) { / / 2 ^ 31 = 2147483648 <nl> - if ( i ! = 214748364 | | s . Peek ( ) > ' 8 ' ) { <nl> - i64 = i ; <nl> - use64bit = true ; <nl> - break ; <nl> - } <nl> - } <nl> - i = i * 10 + static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - } <nl> - else <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( i > = 429496729 ) { / / 2 ^ 32 - 1 = 4294967295 <nl> - if ( i ! = 429496729 | | s . Peek ( ) > ' 5 ' ) { <nl> - i64 = i ; <nl> - use64bit = true ; <nl> - break ; <nl> - } <nl> - } <nl> - i = i * 10 + static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - } <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorValueInvalid , s . Tell ( ) ) ; <nl> - <nl> - / / Parse 64bit int <nl> - double d = 0 . 0 ; <nl> - bool useDouble = false ; <nl> - if ( use64bit ) { <nl> - if ( minus ) <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( i64 > = RAPIDJSON_UINT64_C2 ( 0x0CCCCCCC , 0xCCCCCCCC ) ) / / 2 ^ 63 = 9223372036854775808 <nl> - if ( i64 ! = RAPIDJSON_UINT64_C2 ( 0x0CCCCCCC , 0xCCCCCCCC ) | | s . Peek ( ) > ' 8 ' ) { <nl> - d = ( double ) i64 ; <nl> - useDouble = true ; <nl> - break ; <nl> - } <nl> - i64 = i64 * 10 + static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - } <nl> - else <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( i64 > = RAPIDJSON_UINT64_C2 ( 0x19999999 , 0x99999999 ) ) / / 2 ^ 64 - 1 = 18446744073709551615 <nl> - if ( i64 ! = RAPIDJSON_UINT64_C2 ( 0x19999999 , 0x99999999 ) | | s . Peek ( ) > ' 5 ' ) { <nl> - d = ( double ) i64 ; <nl> - useDouble = true ; <nl> - break ; <nl> - } <nl> - i64 = i64 * 10 + static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - } <nl> - } <nl> - <nl> - / / Force double for big integer <nl> - if ( useDouble ) { <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( d > = 1 . 7976931348623157e307 ) / / DBL_MAX / 10 . 0 <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorNumberTooBig , s . Tell ( ) ) ; <nl> - d = d * 10 + ( s . Take ( ) - ' 0 ' ) ; <nl> - } <nl> - } <nl> - <nl> - / / Parse frac = decimal - point 1 * DIGIT <nl> - int expFrac = 0 ; <nl> - if ( s . Peek ( ) = = ' . ' ) { <nl> - s . Take ( ) ; <nl> - <nl> - # if RAPIDJSON_64BIT <nl> - / / Use i64 to store significand in 64 - bit architecture <nl> - if ( ! useDouble ) { <nl> - if ( ! use64bit ) <nl> - i64 = i ; <nl> - <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - if ( i64 > = RAPIDJSON_UINT64_C2 ( 0x19999999 , 0x99999999 ) ) <nl> - break ; <nl> - else { <nl> - i64 = i64 * 10 + static_cast < unsigned > ( s . Take ( ) - ' 0 ' ) ; <nl> - - - expFrac ; <nl> - } <nl> - } <nl> - <nl> - d = ( double ) i64 ; <nl> - } <nl> - # else <nl> - / / Use double to store significand in 32 - bit architecture <nl> - if ( ! useDouble ) <nl> - d = use64bit ? ( double ) i64 : ( double ) i ; <nl> - # endif <nl> - useDouble = true ; <nl> - <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - d = d * 10 + ( s . Take ( ) - ' 0 ' ) ; <nl> - - - expFrac ; <nl> - } <nl> - <nl> - if ( expFrac = = 0 ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorNumberMissFraction , s . Tell ( ) ) ; <nl> - } <nl> - <nl> - / / Parse exp = e [ minus / plus ] 1 * DIGIT <nl> - int exp = 0 ; <nl> - if ( s . Peek ( ) = = ' e ' | | s . Peek ( ) = = ' E ' ) { <nl> - if ( ! useDouble ) { <nl> - d = use64bit ? ( double ) i64 : ( double ) i ; <nl> - useDouble = true ; <nl> - } <nl> - s . Take ( ) ; <nl> - <nl> - bool expMinus = false ; <nl> - if ( s . Peek ( ) = = ' + ' ) <nl> - s . Take ( ) ; <nl> - else if ( s . Peek ( ) = = ' - ' ) { <nl> - s . Take ( ) ; <nl> - expMinus = true ; <nl> - } <nl> - <nl> - if ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - exp = s . Take ( ) - ' 0 ' ; <nl> - while ( s . Peek ( ) > = ' 0 ' & & s . Peek ( ) < = ' 9 ' ) { <nl> - exp = exp * 10 + ( s . Take ( ) - ' 0 ' ) ; <nl> - if ( exp > 308 & & ! expMinus ) / / exp > 308 should be rare , so it should be checked first . <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorNumberTooBig , s . Tell ( ) ) ; <nl> - } <nl> - } <nl> - else <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorNumberMissExponent , s . Tell ( ) ) ; <nl> - <nl> - if ( expMinus ) <nl> - exp = - exp ; <nl> - } <nl> - <nl> - / / Finish parsing , call event according to the type of number . <nl> - bool cont = true ; <nl> - if ( useDouble ) { <nl> - int expSum = exp + expFrac ; <nl> - if ( expSum < - 308 ) { <nl> - / / Prevent expSum < - 308 , making Pow10 ( expSum ) = 0 <nl> - d = StrtodFastPath ( d , exp ) ; <nl> - d = StrtodFastPath ( d , expFrac ) ; <nl> - } <nl> - else <nl> - d = StrtodFastPath ( d , expSum ) ; <nl> - <nl> - cont = handler . Double ( minus ? - d : d ) ; <nl> - } <nl> - else { <nl> - if ( use64bit ) { <nl> - if ( minus ) <nl> - cont = handler . Int64 ( - ( int64_t ) i64 ) ; <nl> - else <nl> - cont = handler . Uint64 ( i64 ) ; <nl> - } <nl> - else { <nl> - if ( minus ) <nl> - cont = handler . Int ( - ( int ) i ) ; <nl> - else <nl> - cont = handler . Uint ( i ) ; <nl> - } <nl> - } <nl> - if ( ! cont ) <nl> - RAPIDJSON_PARSE_ERROR ( kParseErrorTermination , s . Tell ( ) ) ; <nl> - } <nl> - <nl> - / / Parse any JSON value <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - void ParseValue ( InputStream & is , Handler & handler ) { <nl> - switch ( is . Peek ( ) ) { <nl> - case ' n ' : ParseNull < parseFlags > ( is , handler ) ; break ; <nl> - case ' t ' : ParseTrue < parseFlags > ( is , handler ) ; break ; <nl> - case ' f ' : ParseFalse < parseFlags > ( is , handler ) ; break ; <nl> - case ' " ' : ParseString < parseFlags > ( is , handler ) ; break ; <nl> - case ' { ' : ParseObject < parseFlags > ( is , handler ) ; break ; <nl> - case ' [ ' : ParseArray < parseFlags > ( is , handler ) ; break ; <nl> - default : ParseNumber < parseFlags > ( is , handler ) ; <nl> - } <nl> - } <nl> - <nl> - / / Iterative Parsing <nl> - <nl> - / / States <nl> - enum IterativeParsingState { <nl> - IterativeParsingStartState = 0 , <nl> - IterativeParsingFinishState , <nl> - IterativeParsingErrorState , <nl> - <nl> - / / Object states <nl> - IterativeParsingObjectInitialState , <nl> - IterativeParsingMemberKeyState , <nl> - IterativeParsingKeyValueDelimiterState , <nl> - IterativeParsingMemberValueState , <nl> - IterativeParsingMemberDelimiterState , <nl> - IterativeParsingObjectFinishState , <nl> - <nl> - / / Array states <nl> - IterativeParsingArrayInitialState , <nl> - IterativeParsingElementState , <nl> - IterativeParsingElementDelimiterState , <nl> - IterativeParsingArrayFinishState , <nl> - <nl> - / / Single value state <nl> - IterativeParsingValueState , <nl> - <nl> - cIterativeParsingStateCount <nl> - } ; <nl> - <nl> - / / Tokens <nl> - enum Token { <nl> - LeftBracketToken = 0 , <nl> - RightBracketToken , <nl> - <nl> - LeftCurlyBracketToken , <nl> - RightCurlyBracketToken , <nl> - <nl> - CommaToken , <nl> - ColonToken , <nl> - <nl> - StringToken , <nl> - FalseToken , <nl> - TrueToken , <nl> - NullToken , <nl> - NumberToken , <nl> - <nl> - kTokenCount <nl> - } ; <nl> - <nl> - RAPIDJSON_FORCEINLINE Token Tokenize ( Ch c ) { <nl> - <nl> - / / ! @ cond RAPIDJSON_HIDDEN_FROM_DOXYGEN <nl> - # define N NumberToken <nl> - # define N16 N , N , N , N , N , N , N , N , N , N , N , N , N , N , N , N <nl> - / / Maps from ASCII to Token <nl> - static const unsigned char tokenMap [ 256 ] = { <nl> - N16 , / / 00 ~ 0F <nl> - N16 , / / 10 ~ 1F <nl> - N , N , StringToken , N , N , N , N , N , N , N , N , N , CommaToken , N , N , N , / / 20 ~ 2F <nl> - N , N , N , N , N , N , N , N , N , N , ColonToken , N , N , N , N , N , / / 30 ~ 3F <nl> - N16 , / / 40 ~ 4F <nl> - N , N , N , N , N , N , N , N , N , N , N , LeftBracketToken , N , RightBracketToken , N , N , / / 50 ~ 5F <nl> - N , N , N , N , N , N , FalseToken , N , N , N , N , N , N , N , NullToken , N , / / 60 ~ 6F <nl> - N , N , N , N , TrueToken , N , N , N , N , N , N , LeftCurlyBracketToken , N , RightCurlyBracketToken , N , N , / / 70 ~ 7F <nl> - N16 , N16 , N16 , N16 , N16 , N16 , N16 , N16 / / 80 ~ FF <nl> - } ; <nl> - # undef N <nl> - # undef N16 <nl> - / / ! @ endcond <nl> - <nl> - if ( sizeof ( Ch ) = = 1 | | unsigned ( c ) < 256 ) <nl> - return ( Token ) tokenMap [ ( unsigned char ) c ] ; <nl> - else <nl> - return NumberToken ; <nl> - } <nl> - <nl> - RAPIDJSON_FORCEINLINE IterativeParsingState Predict ( IterativeParsingState state , Token token ) { <nl> - / / current state x one lookahead token - > new state <nl> - static const char G [ cIterativeParsingStateCount ] [ kTokenCount ] = { <nl> - / / Start <nl> - { <nl> - IterativeParsingArrayInitialState , / / Left bracket <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingObjectInitialState , / / Left curly bracket <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingValueState , / / String <nl> - IterativeParsingValueState , / / False <nl> - IterativeParsingValueState , / / True <nl> - IterativeParsingValueState , / / Null <nl> - IterativeParsingValueState / / Number <nl> - } , <nl> - / / Finish ( sink state ) <nl> - { <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState <nl> - } , <nl> - / / Error ( sink state ) <nl> - { <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState <nl> - } , <nl> - / / ObjectInitial <nl> - { <nl> - IterativeParsingErrorState , / / Left bracket <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingErrorState , / / Left curly bracket <nl> - IterativeParsingObjectFinishState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingMemberKeyState , / / String <nl> - IterativeParsingErrorState , / / False <nl> - IterativeParsingErrorState , / / True <nl> - IterativeParsingErrorState , / / Null <nl> - IterativeParsingErrorState / / Number <nl> - } , <nl> - / / MemberKey <nl> - { <nl> - IterativeParsingErrorState , / / Left bracket <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingErrorState , / / Left curly bracket <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingKeyValueDelimiterState , / / Colon <nl> - IterativeParsingErrorState , / / String <nl> - IterativeParsingErrorState , / / False <nl> - IterativeParsingErrorState , / / True <nl> - IterativeParsingErrorState , / / Null <nl> - IterativeParsingErrorState / / Number <nl> - } , <nl> - / / KeyValueDelimiter <nl> - { <nl> - IterativeParsingArrayInitialState , / / Left bracket ( push MemberValue state ) <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingObjectInitialState , / / Left curly bracket ( push MemberValue state ) <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingMemberValueState , / / String <nl> - IterativeParsingMemberValueState , / / False <nl> - IterativeParsingMemberValueState , / / True <nl> - IterativeParsingMemberValueState , / / Null <nl> - IterativeParsingMemberValueState / / Number <nl> - } , <nl> - / / MemberValue <nl> - { <nl> - IterativeParsingErrorState , / / Left bracket <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingErrorState , / / Left curly bracket <nl> - IterativeParsingObjectFinishState , / / Right curly bracket <nl> - IterativeParsingMemberDelimiterState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingErrorState , / / String <nl> - IterativeParsingErrorState , / / False <nl> - IterativeParsingErrorState , / / True <nl> - IterativeParsingErrorState , / / Null <nl> - IterativeParsingErrorState / / Number <nl> - } , <nl> - / / MemberDelimiter <nl> - { <nl> - IterativeParsingErrorState , / / Left bracket <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingErrorState , / / Left curly bracket <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingMemberKeyState , / / String <nl> - IterativeParsingErrorState , / / False <nl> - IterativeParsingErrorState , / / True <nl> - IterativeParsingErrorState , / / Null <nl> - IterativeParsingErrorState / / Number <nl> - } , <nl> - / / ObjectFinish ( sink state ) <nl> - { <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState <nl> - } , <nl> - / / ArrayInitial <nl> - { <nl> - IterativeParsingArrayInitialState , / / Left bracket ( push Element state ) <nl> - IterativeParsingArrayFinishState , / / Right bracket <nl> - IterativeParsingObjectInitialState , / / Left curly bracket ( push Element state ) <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingElementState , / / String <nl> - IterativeParsingElementState , / / False <nl> - IterativeParsingElementState , / / True <nl> - IterativeParsingElementState , / / Null <nl> - IterativeParsingElementState / / Number <nl> - } , <nl> - / / Element <nl> - { <nl> - IterativeParsingErrorState , / / Left bracket <nl> - IterativeParsingArrayFinishState , / / Right bracket <nl> - IterativeParsingErrorState , / / Left curly bracket <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingElementDelimiterState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingErrorState , / / String <nl> - IterativeParsingErrorState , / / False <nl> - IterativeParsingErrorState , / / True <nl> - IterativeParsingErrorState , / / Null <nl> - IterativeParsingErrorState / / Number <nl> - } , <nl> - / / ElementDelimiter <nl> - { <nl> - IterativeParsingArrayInitialState , / / Left bracket ( push Element state ) <nl> - IterativeParsingErrorState , / / Right bracket <nl> - IterativeParsingObjectInitialState , / / Left curly bracket ( push Element state ) <nl> - IterativeParsingErrorState , / / Right curly bracket <nl> - IterativeParsingErrorState , / / Comma <nl> - IterativeParsingErrorState , / / Colon <nl> - IterativeParsingElementState , / / String <nl> - IterativeParsingElementState , / / False <nl> - IterativeParsingElementState , / / True <nl> - IterativeParsingElementState , / / Null <nl> - IterativeParsingElementState / / Number <nl> - } , <nl> - / / ArrayFinish ( sink state ) <nl> - { <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState <nl> - } , <nl> - / / Single Value ( sink state ) <nl> - { <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , IterativeParsingErrorState , <nl> - IterativeParsingErrorState <nl> - } <nl> - } ; / / End of G <nl> - <nl> - return ( IterativeParsingState ) G [ state ] [ token ] ; <nl> - } <nl> - <nl> - / / Make an advance in the token stream and state based on the candidate destination state which was returned by Transit ( ) . <nl> - / / May return a new state on state pop . <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - RAPIDJSON_FORCEINLINE IterativeParsingState Transit ( IterativeParsingState src , Token token , IterativeParsingState dst , InputStream & is , Handler & handler ) { <nl> - switch ( dst ) { <nl> - case IterativeParsingStartState : <nl> - RAPIDJSON_ASSERT ( false ) ; <nl> - return IterativeParsingErrorState ; <nl> - <nl> - case IterativeParsingFinishState : <nl> - return dst ; <nl> - <nl> - case IterativeParsingErrorState : <nl> - return dst ; <nl> - <nl> - case IterativeParsingObjectInitialState : <nl> - case IterativeParsingArrayInitialState : <nl> - { <nl> - / / Push the state ( Element or MemeberValue ) if we are nested in another array or value of member . <nl> - / / In this way we can get the correct state on ObjectFinish or ArrayFinish by frame pop . <nl> - IterativeParsingState n = src ; <nl> - if ( src = = IterativeParsingArrayInitialState | | src = = IterativeParsingElementDelimiterState ) <nl> - n = IterativeParsingElementState ; <nl> - else if ( src = = IterativeParsingKeyValueDelimiterState ) <nl> - n = IterativeParsingMemberValueState ; <nl> - / / Push current state . <nl> - * stack_ . template Push < SizeType > ( 1 ) = n ; <nl> - / / Initialize and push the member / element count . <nl> - * stack_ . template Push < SizeType > ( 1 ) = 0 ; <nl> - / / Call handler <nl> - bool hr = ( dst = = IterativeParsingObjectInitialState ) ? handler . StartObject ( ) : handler . StartArray ( ) ; <nl> - / / On handler short circuits the parsing . <nl> - if ( ! hr ) { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - else { <nl> - is . Take ( ) ; <nl> - return dst ; <nl> - } <nl> - } <nl> - <nl> - case IterativeParsingMemberKeyState : <nl> - ParseString < parseFlags > ( is , handler , true ) ; <nl> - if ( HasParseError ( ) ) <nl> - return IterativeParsingErrorState ; <nl> - else <nl> - return dst ; <nl> - <nl> - case IterativeParsingKeyValueDelimiterState : <nl> - if ( token = = ColonToken ) { <nl> - is . Take ( ) ; <nl> - return dst ; <nl> - } <nl> - else <nl> - return IterativeParsingErrorState ; <nl> - <nl> - case IterativeParsingMemberValueState : <nl> - / / Must be non - compound value . Or it would be ObjectInitial or ArrayInitial state . <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - if ( HasParseError ( ) ) { <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - return dst ; <nl> - <nl> - case IterativeParsingElementState : <nl> - / / Must be non - compound value . Or it would be ObjectInitial or ArrayInitial state . <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - if ( HasParseError ( ) ) { <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - return dst ; <nl> - <nl> - case IterativeParsingMemberDelimiterState : <nl> - case IterativeParsingElementDelimiterState : <nl> - is . Take ( ) ; <nl> - / / Update member / element count . <nl> - * stack_ . template Top < SizeType > ( ) = * stack_ . template Top < SizeType > ( ) + 1 ; <nl> - return dst ; <nl> - <nl> - case IterativeParsingObjectFinishState : <nl> - { <nl> - / / Get member count . <nl> - SizeType c = * stack_ . template Pop < SizeType > ( 1 ) ; <nl> - / / If the object is not empty , count the last member . <nl> - if ( src = = IterativeParsingMemberValueState ) <nl> - + + c ; <nl> - / / Restore the state . <nl> - IterativeParsingState n = static_cast < IterativeParsingState > ( * stack_ . template Pop < SizeType > ( 1 ) ) ; <nl> - / / Transit to Finish state if this is the topmost scope . <nl> - if ( n = = IterativeParsingStartState ) <nl> - n = IterativeParsingFinishState ; <nl> - / / Call handler <nl> - bool hr = handler . EndObject ( c ) ; <nl> - / / On handler short circuits the parsing . <nl> - if ( ! hr ) { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - else { <nl> - is . Take ( ) ; <nl> - return n ; <nl> - } <nl> - } <nl> - <nl> - case IterativeParsingArrayFinishState : <nl> - { <nl> - / / Get element count . <nl> - SizeType c = * stack_ . template Pop < SizeType > ( 1 ) ; <nl> - / / If the array is not empty , count the last element . <nl> - if ( src = = IterativeParsingElementState ) <nl> - + + c ; <nl> - / / Restore the state . <nl> - IterativeParsingState n = static_cast < IterativeParsingState > ( * stack_ . template Pop < SizeType > ( 1 ) ) ; <nl> - / / Transit to Finish state if this is the topmost scope . <nl> - if ( n = = IterativeParsingStartState ) <nl> - n = IterativeParsingFinishState ; <nl> - / / Call handler <nl> - bool hr = handler . EndArray ( c ) ; <nl> - / / On handler short circuits the parsing . <nl> - if ( ! hr ) { <nl> - RAPIDJSON_PARSE_ERROR_NORETURN ( kParseErrorTermination , is . Tell ( ) ) ; <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - else { <nl> - is . Take ( ) ; <nl> - return n ; <nl> - } <nl> - } <nl> - <nl> - case IterativeParsingValueState : <nl> - / / Must be non - compound value . Or it would be ObjectInitial or ArrayInitial state . <nl> - ParseValue < parseFlags > ( is , handler ) ; <nl> - if ( HasParseError ( ) ) { <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - return IterativeParsingFinishState ; <nl> - <nl> - default : <nl> - RAPIDJSON_ASSERT ( false ) ; <nl> - return IterativeParsingErrorState ; <nl> - } <nl> - } <nl> - <nl> - template < typename InputStream > <nl> - void HandleError ( IterativeParsingState src , InputStream & is ) { <nl> - if ( HasParseError ( ) ) { <nl> - / / Error flag has been set . <nl> - return ; <nl> - } <nl> - <nl> - switch ( src ) { <nl> - case IterativeParsingStartState : RAPIDJSON_PARSE_ERROR ( kParseErrorDocumentEmpty , is . Tell ( ) ) ; <nl> - case IterativeParsingFinishState : RAPIDJSON_PARSE_ERROR ( kParseErrorDocumentRootNotSingular , is . Tell ( ) ) ; <nl> - case IterativeParsingObjectInitialState : <nl> - case IterativeParsingMemberDelimiterState : RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissName , is . Tell ( ) ) ; <nl> - case IterativeParsingMemberKeyState : RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissColon , is . Tell ( ) ) ; <nl> - case IterativeParsingMemberValueState : RAPIDJSON_PARSE_ERROR ( kParseErrorObjectMissCommaOrCurlyBracket , is . Tell ( ) ) ; <nl> - case IterativeParsingElementState : RAPIDJSON_PARSE_ERROR ( kParseErrorArrayMissCommaOrSquareBracket , is . Tell ( ) ) ; <nl> - default : RAPIDJSON_PARSE_ERROR ( kParseErrorUnspecificSyntaxError , is . Tell ( ) ) ; <nl> - } <nl> - } <nl> - <nl> - template < unsigned parseFlags , typename InputStream , typename Handler > <nl> - ParseResult IterativeParse ( InputStream & is , Handler & handler ) { <nl> - parseResult_ . Clear ( ) ; <nl> - ClearStackOnExit scope ( * this ) ; <nl> - IterativeParsingState state = IterativeParsingStartState ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - while ( is . Peek ( ) ! = ' \ 0 ' ) { <nl> - Token t = Tokenize ( is . Peek ( ) ) ; <nl> - IterativeParsingState n = Predict ( state , t ) ; <nl> - IterativeParsingState d = Transit < parseFlags > ( state , t , n , is , handler ) ; <nl> - <nl> - if ( d = = IterativeParsingErrorState ) { <nl> - HandleError ( state , is ) ; <nl> - break ; <nl> - } <nl> - <nl> - state = d ; <nl> - <nl> - / / Do not further consume streams if a root JSON has been parsed . <nl> - if ( ( parseFlags & kParseStopWhenDoneFlag ) & & state = = IterativeParsingFinishState ) <nl> - break ; <nl> - <nl> - SkipWhitespace ( is ) ; <nl> - } <nl> - <nl> - / / Handle the end of file . <nl> - if ( state ! = IterativeParsingFinishState ) <nl> - HandleError ( state , is ) ; <nl> - <nl> - return parseResult_ ; <nl> - } <nl> - <nl> - static const size_t kDefaultStackCapacity = 256 ; / / ! < Default stack capacity in bytes for storing a single decoded string . <nl> - internal : : Stack < StackAllocator > stack_ ; / / ! < A stack for storing decoded string temporarily during non - destructive parsing . <nl> - ParseResult parseResult_ ; <nl> - } ; / / class GenericReader <nl> - <nl> - / / ! Reader with UTF8 encoding and default allocator . <nl> - typedef GenericReader < UTF8 < > , UTF8 < > > Reader ; <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_READER_H_ <nl> deleted file mode 100644 <nl> index 55124f117ad . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / stringbuffer . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_STRINGBUFFER_H_ <nl> - # define RAPIDJSON_STRINGBUFFER_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include " internal / stack . h " <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! Represents an in - memory output stream . <nl> - / * ! <nl> - \ tparam Encoding Encoding of the stream . <nl> - \ tparam Allocator type for allocating memory buffer . <nl> - \ note implements Stream concept <nl> - * / <nl> - template < typename Encoding , typename Allocator = CrtAllocator > <nl> - struct GenericStringBuffer { <nl> - typedef typename Encoding : : Ch Ch ; <nl> - <nl> - GenericStringBuffer ( Allocator * allocator = 0 , size_t capacity = kDefaultCapacity ) : stack_ ( allocator , capacity ) { } <nl> - <nl> - void Put ( Ch c ) { * stack_ . template Push < Ch > ( ) = c ; } <nl> - void Flush ( ) { } <nl> - <nl> - void Clear ( ) { stack_ . Clear ( ) ; } <nl> - void ShrinkToFit ( ) { <nl> - / / Push and pop a null terminator . This is safe . <nl> - * stack_ . template Push < Ch > ( ) = ' \ 0 ' ; <nl> - stack_ . ShrinkToFit ( ) ; <nl> - stack_ . template Pop < Ch > ( 1 ) ; <nl> - } <nl> - Ch * Push ( size_t count ) { return stack_ . template Push < Ch > ( count ) ; } <nl> - void Pop ( size_t count ) { stack_ . template Pop < Ch > ( count ) ; } <nl> - <nl> - const Ch * GetString ( ) const { <nl> - / / Push and pop a null terminator . This is safe . <nl> - * stack_ . template Push < Ch > ( ) = ' \ 0 ' ; <nl> - stack_ . template Pop < Ch > ( 1 ) ; <nl> - <nl> - return stack_ . template Bottom < Ch > ( ) ; <nl> - } <nl> - <nl> - size_t GetSize ( ) const { return stack_ . GetSize ( ) ; } <nl> - <nl> - static const size_t kDefaultCapacity = 256 ; <nl> - mutable internal : : Stack < Allocator > stack_ ; <nl> - } ; <nl> - <nl> - / / ! String buffer with UTF8 encoding <nl> - typedef GenericStringBuffer < UTF8 < > > StringBuffer ; <nl> - <nl> - / / ! Implement specialized version of PutN ( ) with memset ( ) for better performance . <nl> - template < > <nl> - inline void PutN ( GenericStringBuffer < UTF8 < > > & stream , char c , size_t n ) { <nl> - std : : memset ( stream . stack_ . Push < char > ( n ) , c , n * sizeof ( c ) ) ; <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # endif / / RAPIDJSON_STRINGBUFFER_H_ <nl> deleted file mode 100644 <nl> index fb6601ef976 . . 00000000000 <nl> mmm a / tools / optimizer / rapidjson / writer . h <nl> ppp / dev / null <nl> <nl> - / / Copyright ( C ) 2011 Milo Yip <nl> - / / <nl> - / / Permission is hereby granted , free of charge , to any person obtaining a copy <nl> - / / of this software and associated documentation files ( the " Software " ) , to deal <nl> - / / in the Software without restriction , including without limitation the rights <nl> - / / to use , copy , modify , merge , publish , distribute , sublicense , and / or sell <nl> - / / copies 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 included in <nl> - / / all copies or substantial portions of the Software . <nl> - / / <nl> - / / THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR <nl> - / / IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , <nl> - / / FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE <nl> - / / AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER <nl> - / / LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , <nl> - / / OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN <nl> - / / THE SOFTWARE . <nl> - <nl> - # ifndef RAPIDJSON_WRITER_H_ <nl> - # define RAPIDJSON_WRITER_H_ <nl> - <nl> - # include " rapidjson . h " <nl> - # include " internal / stack . h " <nl> - # include " internal / strfunc . h " <nl> - # include " internal / dtoa . h " <nl> - # include " internal / itoa . h " <nl> - # include " stringbuffer . h " <nl> - # include < new > / / placement new <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_PUSH <nl> - RAPIDJSON_DIAG_OFF ( 4127 ) / / conditional expression is constant <nl> - # endif <nl> - <nl> - namespace rapidjson { <nl> - <nl> - / / ! JSON writer <nl> - / * ! Writer implements the concept Handler . <nl> - It generates JSON text by events to an output os . <nl> - <nl> - User may programmatically calls the functions of a writer to generate JSON text . <nl> - <nl> - On the other side , a writer can also be passed to objects that generates events , <nl> - <nl> - for example Reader : : Parse ( ) and Document : : Accept ( ) . <nl> - <nl> - \ tparam OutputStream Type of output stream . <nl> - \ tparam SourceEncoding Encoding of source string . <nl> - \ tparam TargetEncoding Encoding of output stream . <nl> - \ tparam StackAllocator Type of allocator for allocating memory of stack . <nl> - \ note implements Handler concept <nl> - * / <nl> - template < typename OutputStream , typename SourceEncoding = UTF8 < > , typename TargetEncoding = UTF8 < > , typename StackAllocator = CrtAllocator > <nl> - class Writer { <nl> - public : <nl> - typedef typename SourceEncoding : : Ch Ch ; <nl> - <nl> - / / ! Constructor <nl> - / * ! \ param os Output stream . <nl> - \ param allocator User supplied allocator . If it is null , it will create a private one . <nl> - \ param levelDepth Initial capacity of stack . <nl> - * / <nl> - Writer ( OutputStream & os , StackAllocator * stackAllocator = 0 , size_t levelDepth = kDefaultLevelDepth ) : <nl> - os_ ( & os ) , level_stack_ ( stackAllocator , levelDepth * sizeof ( Level ) ) , hasRoot_ ( false ) { } <nl> - <nl> - Writer ( StackAllocator * allocator = 0 , size_t levelDepth = kDefaultLevelDepth ) : <nl> - os_ ( 0 ) , level_stack_ ( allocator , levelDepth * sizeof ( Level ) ) , hasRoot_ ( false ) { } <nl> - <nl> - / / ! Reset the writer with a new stream . <nl> - / * ! <nl> - This function reset the writer with a new stream and default settings , <nl> - in order to make a Writer object reusable for output multiple JSONs . <nl> - <nl> - \ param os New output stream . <nl> - \ code <nl> - Writer < OutputStream > writer ( os1 ) ; <nl> - writer . StartObject ( ) ; <nl> - / / . . . <nl> - writer . EndObject ( ) ; <nl> - <nl> - writer . Reset ( os2 ) ; <nl> - writer . StartObject ( ) ; <nl> - / / . . . <nl> - writer . EndObject ( ) ; <nl> - \ endcode <nl> - * / <nl> - void Reset ( OutputStream & os ) { <nl> - os_ = & os ; <nl> - hasRoot_ = false ; <nl> - level_stack_ . Clear ( ) ; <nl> - } <nl> - <nl> - / / ! Checks whether the output is a complete JSON . <nl> - / * ! <nl> - A complete JSON has a complete root object or array . <nl> - * / <nl> - bool IsComplete ( ) const { <nl> - return hasRoot_ & & level_stack_ . Empty ( ) ; <nl> - } <nl> - <nl> - / * ! @ name Implementation of Handler <nl> - \ see Handler <nl> - * / <nl> - / / @ { <nl> - <nl> - bool Null ( ) { Prefix ( kNullType ) ; return WriteNull ( ) ; } <nl> - bool Bool ( bool b ) { Prefix ( b ? kTrueType : kFalseType ) ; return WriteBool ( b ) ; } <nl> - bool Int ( int i ) { Prefix ( kNumberType ) ; return WriteInt ( i ) ; } <nl> - bool Uint ( unsigned u ) { Prefix ( kNumberType ) ; return WriteUint ( u ) ; } <nl> - bool Int64 ( int64_t i64 ) { Prefix ( kNumberType ) ; return WriteInt64 ( i64 ) ; } <nl> - bool Uint64 ( uint64_t u64 ) { Prefix ( kNumberType ) ; return WriteUint64 ( u64 ) ; } <nl> - <nl> - / / ! Writes the given \ c double value to the stream <nl> - / * ! <nl> - \ param d The value to be written . <nl> - \ return Whether it is succeed . <nl> - * / <nl> - bool Double ( double d ) { Prefix ( kNumberType ) ; return WriteDouble ( d ) ; } <nl> - <nl> - bool String ( const Ch * str , SizeType length , bool copy = false ) { <nl> - ( void ) copy ; <nl> - Prefix ( kStringType ) ; <nl> - return WriteString ( str , length ) ; <nl> - } <nl> - <nl> - bool StartObject ( ) { <nl> - Prefix ( kObjectType ) ; <nl> - new ( level_stack_ . template Push < Level > ( ) ) Level ( false ) ; <nl> - return WriteStartObject ( ) ; <nl> - } <nl> - <nl> - bool Key ( const Ch * str , SizeType length , bool copy = false ) { return String ( str , length , copy ) ; } <nl> - <nl> - bool EndObject ( SizeType memberCount = 0 ) { <nl> - ( void ) memberCount ; <nl> - RAPIDJSON_ASSERT ( level_stack_ . GetSize ( ) > = sizeof ( Level ) ) ; <nl> - RAPIDJSON_ASSERT ( ! level_stack_ . template Top < Level > ( ) - > inArray ) ; <nl> - level_stack_ . template Pop < Level > ( 1 ) ; <nl> - bool ret = WriteEndObject ( ) ; <nl> - if ( level_stack_ . Empty ( ) ) / / end of json text <nl> - os_ - > Flush ( ) ; <nl> - return ret ; <nl> - } <nl> - <nl> - bool StartArray ( ) { <nl> - Prefix ( kArrayType ) ; <nl> - new ( level_stack_ . template Push < Level > ( ) ) Level ( true ) ; <nl> - return WriteStartArray ( ) ; <nl> - } <nl> - <nl> - bool EndArray ( SizeType elementCount = 0 ) { <nl> - ( void ) elementCount ; <nl> - RAPIDJSON_ASSERT ( level_stack_ . GetSize ( ) > = sizeof ( Level ) ) ; <nl> - RAPIDJSON_ASSERT ( level_stack_ . template Top < Level > ( ) - > inArray ) ; <nl> - level_stack_ . template Pop < Level > ( 1 ) ; <nl> - bool ret = WriteEndArray ( ) ; <nl> - if ( level_stack_ . Empty ( ) ) / / end of json text <nl> - os_ - > Flush ( ) ; <nl> - return ret ; <nl> - } <nl> - / / @ } <nl> - <nl> - / * ! @ name Convenience extensions * / <nl> - / / @ { <nl> - <nl> - / / ! Simpler but slower overload . <nl> - bool String ( const Ch * str ) { return String ( str , internal : : StrLen ( str ) ) ; } <nl> - bool Key ( const Ch * str ) { return Key ( str , internal : : StrLen ( str ) ) ; } <nl> - <nl> - / / @ } <nl> - <nl> - protected : <nl> - / / ! Information for each nested level <nl> - struct Level { <nl> - Level ( bool inArray_ ) : valueCount ( 0 ) , inArray ( inArray_ ) { } <nl> - size_t valueCount ; / / ! < number of values in this level <nl> - bool inArray ; / / ! < true if in array , otherwise in object <nl> - } ; <nl> - <nl> - static const size_t kDefaultLevelDepth = 32 ; <nl> - <nl> - bool WriteNull ( ) { <nl> - os_ - > Put ( ' n ' ) ; os_ - > Put ( ' u ' ) ; os_ - > Put ( ' l ' ) ; os_ - > Put ( ' l ' ) ; return true ; <nl> - } <nl> - <nl> - bool WriteBool ( bool b ) { <nl> - if ( b ) { <nl> - os_ - > Put ( ' t ' ) ; os_ - > Put ( ' r ' ) ; os_ - > Put ( ' u ' ) ; os_ - > Put ( ' e ' ) ; <nl> - } <nl> - else { <nl> - os_ - > Put ( ' f ' ) ; os_ - > Put ( ' a ' ) ; os_ - > Put ( ' l ' ) ; os_ - > Put ( ' s ' ) ; os_ - > Put ( ' e ' ) ; <nl> - } <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteInt ( int i ) { <nl> - char buffer [ 11 ] ; <nl> - const char * end = internal : : i32toa ( i , buffer ) ; <nl> - for ( const char * p = buffer ; p ! = end ; + + p ) <nl> - os_ - > Put ( * p ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteUint ( unsigned u ) { <nl> - char buffer [ 10 ] ; <nl> - const char * end = internal : : u32toa ( u , buffer ) ; <nl> - for ( const char * p = buffer ; p ! = end ; + + p ) <nl> - os_ - > Put ( * p ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteInt64 ( int64_t i64 ) { <nl> - char buffer [ 21 ] ; <nl> - const char * end = internal : : i64toa ( i64 , buffer ) ; <nl> - for ( const char * p = buffer ; p ! = end ; + + p ) <nl> - os_ - > Put ( * p ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteUint64 ( uint64_t u64 ) { <nl> - char buffer [ 20 ] ; <nl> - char * end = internal : : u64toa ( u64 , buffer ) ; <nl> - for ( char * p = buffer ; p ! = end ; + + p ) <nl> - os_ - > Put ( * p ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteDouble ( double d ) { <nl> - char buffer [ 25 ] ; <nl> - char * end = internal : : dtoa ( d , buffer ) ; <nl> - for ( char * p = buffer ; p ! = end ; + + p ) <nl> - os_ - > Put ( * p ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteString ( const Ch * str , SizeType length ) { <nl> - static const char hexDigits [ 16 ] = { ' 0 ' , ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' , ' 8 ' , ' 9 ' , ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' } ; <nl> - static const char escape [ 256 ] = { <nl> - # define Z16 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 <nl> - / / 0 1 2 3 4 5 6 7 8 9 A B C D E F <nl> - ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' b ' , ' t ' , ' n ' , ' u ' , ' f ' , ' r ' , ' u ' , ' u ' , / / 00 <nl> - ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , ' u ' , / / 10 <nl> - 0 , 0 , ' " ' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , / / 20 <nl> - Z16 , Z16 , / / 30 ~ 4F <nl> - 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ' \ \ ' , 0 , 0 , 0 , / / 50 <nl> - Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 , Z16 / / 60 ~ FF <nl> - # undef Z16 <nl> - } ; <nl> - <nl> - os_ - > Put ( ' \ " ' ) ; <nl> - GenericStringStream < SourceEncoding > is ( str ) ; <nl> - while ( is . Tell ( ) < length ) { <nl> - const Ch c = is . Peek ( ) ; <nl> - if ( ! TargetEncoding : : supportUnicode & & ( unsigned ) c > = 0x80 ) { <nl> - / / Unicode escaping <nl> - unsigned codepoint ; <nl> - if ( ! SourceEncoding : : Decode ( is , & codepoint ) ) <nl> - return false ; <nl> - os_ - > Put ( ' \ \ ' ) ; <nl> - os_ - > Put ( ' u ' ) ; <nl> - if ( codepoint < = 0xD7FF | | ( codepoint > = 0xE000 & & codepoint < = 0xFFFF ) ) { <nl> - os_ - > Put ( hexDigits [ ( codepoint > > 12 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( codepoint > > 8 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( codepoint > > 4 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( codepoint ) & 15 ] ) ; <nl> - } <nl> - else if ( codepoint > = 0x010000 & & codepoint < = 0x10FFFF ) { <nl> - / / Surrogate pair <nl> - unsigned s = codepoint - 0x010000 ; <nl> - unsigned lead = ( s > > 10 ) + 0xD800 ; <nl> - unsigned trail = ( s & 0x3FF ) + 0xDC00 ; <nl> - os_ - > Put ( hexDigits [ ( lead > > 12 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( lead > > 8 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( lead > > 4 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( lead ) & 15 ] ) ; <nl> - os_ - > Put ( ' \ \ ' ) ; <nl> - os_ - > Put ( ' u ' ) ; <nl> - os_ - > Put ( hexDigits [ ( trail > > 12 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( trail > > 8 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( trail > > 4 ) & 15 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( trail ) & 15 ] ) ; <nl> - } <nl> - else <nl> - return false ; / / invalid code point <nl> - } <nl> - else if ( ( sizeof ( Ch ) = = 1 | | ( unsigned ) c < 256 ) & & escape [ ( unsigned char ) c ] ) { <nl> - is . Take ( ) ; <nl> - os_ - > Put ( ' \ \ ' ) ; <nl> - os_ - > Put ( escape [ ( unsigned char ) c ] ) ; <nl> - if ( escape [ ( unsigned char ) c ] = = ' u ' ) { <nl> - os_ - > Put ( ' 0 ' ) ; <nl> - os_ - > Put ( ' 0 ' ) ; <nl> - os_ - > Put ( hexDigits [ ( unsigned char ) c > > 4 ] ) ; <nl> - os_ - > Put ( hexDigits [ ( unsigned char ) c & 0xF ] ) ; <nl> - } <nl> - } <nl> - else <nl> - Transcoder < SourceEncoding , TargetEncoding > : : Transcode ( is , * os_ ) ; <nl> - } <nl> - os_ - > Put ( ' \ " ' ) ; <nl> - return true ; <nl> - } <nl> - <nl> - bool WriteStartObject ( ) { os_ - > Put ( ' { ' ) ; return true ; } <nl> - bool WriteEndObject ( ) { os_ - > Put ( ' } ' ) ; return true ; } <nl> - bool WriteStartArray ( ) { os_ - > Put ( ' [ ' ) ; return true ; } <nl> - bool WriteEndArray ( ) { os_ - > Put ( ' ] ' ) ; return true ; } <nl> - <nl> - void Prefix ( Type type ) { <nl> - ( void ) type ; <nl> - if ( level_stack_ . GetSize ( ) ! = 0 ) { / / this value is not at root <nl> - Level * level = level_stack_ . template Top < Level > ( ) ; <nl> - if ( level - > valueCount > 0 ) { <nl> - if ( level - > inArray ) <nl> - os_ - > Put ( ' , ' ) ; / / add comma if it is not the first element in array <nl> - else / / in object <nl> - os_ - > Put ( ( level - > valueCount % 2 = = 0 ) ? ' , ' : ' : ' ) ; <nl> - } <nl> - if ( ! level - > inArray & & level - > valueCount % 2 = = 0 ) <nl> - RAPIDJSON_ASSERT ( type = = kStringType ) ; / / if it ' s in object , then even number should be a name <nl> - level - > valueCount + + ; <nl> - } <nl> - else { <nl> - RAPIDJSON_ASSERT ( ! hasRoot_ ) ; / / Should only has one and only one root . <nl> - hasRoot_ = true ; <nl> - } <nl> - } <nl> - <nl> - OutputStream * os_ ; <nl> - internal : : Stack < StackAllocator > level_stack_ ; <nl> - bool hasRoot_ ; <nl> - <nl> - private : <nl> - / / Prohibit copy constructor & assignment operator . <nl> - Writer ( const Writer & ) ; <nl> - Writer & operator = ( const Writer & ) ; <nl> - } ; <nl> - <nl> - / / Full specialization for StringStream to prevent memory copying <nl> - <nl> - template < > <nl> - inline bool Writer < StringBuffer > : : WriteInt ( int i ) { <nl> - char * buffer = os_ - > Push ( 11 ) ; <nl> - const char * end = internal : : i32toa ( i , buffer ) ; <nl> - os_ - > Pop ( 11 - ( end - buffer ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - template < > <nl> - inline bool Writer < StringBuffer > : : WriteUint ( unsigned u ) { <nl> - char * buffer = os_ - > Push ( 10 ) ; <nl> - const char * end = internal : : u32toa ( u , buffer ) ; <nl> - os_ - > Pop ( 10 - ( end - buffer ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - template < > <nl> - inline bool Writer < StringBuffer > : : WriteInt64 ( int64_t i64 ) { <nl> - char * buffer = os_ - > Push ( 21 ) ; <nl> - const char * end = internal : : i64toa ( i64 , buffer ) ; <nl> - os_ - > Pop ( 21 - ( end - buffer ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - template < > <nl> - inline bool Writer < StringBuffer > : : WriteUint64 ( uint64_t u ) { <nl> - char * buffer = os_ - > Push ( 20 ) ; <nl> - const char * end = internal : : u64toa ( u , buffer ) ; <nl> - os_ - > Pop ( 20 - ( end - buffer ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - template < > <nl> - inline bool Writer < StringBuffer > : : WriteDouble ( double d ) { <nl> - char * buffer = os_ - > Push ( 25 ) ; <nl> - char * end = internal : : dtoa ( d , buffer ) ; <nl> - os_ - > Pop ( 25 - ( end - buffer ) ) ; <nl> - return true ; <nl> - } <nl> - <nl> - } / / namespace rapidjson <nl> - <nl> - # ifdef _MSC_VER <nl> - RAPIDJSON_DIAG_POP <nl> - # endif <nl> - <nl> - # endif / / RAPIDJSON_RAPIDJSON_H_ <nl>
remove rapidjson
emscripten-core/emscripten
5eb2cedc7da3e9fa03e683242f2efaf222f404af
2014-11-08T18:40:35Z
mmm a / stdlib / toolchain / Compatibility51 / ProtocolConformance . cpp <nl> ppp b / stdlib / toolchain / Compatibility51 / ProtocolConformance . cpp <nl> <nl> / / <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> + # include " . . / . . / public / runtime / Private . h " <nl> # include " Concurrent . h " <nl> # include " Overrides . h " <nl> # include " swift / Basic / Lazy . h " <nl> - # include " . . / . . / public / runtime / Private . h " <nl> + # include < assert . h > <nl> + # include < dlfcn . h > <nl> # include < mach - o / dyld . h > <nl> # include < mach - o / getsect . h > <nl> # include < objc / runtime . h > <nl> - # include < assert . h > <nl> - # include < dlfcn . h > <nl> <nl> using namespace swift ; <nl> using swift : : overrides : : ConcurrentMap ; <nl>
standard library : sort headers
apple/swift
f83e537a4e5573426c58ea6ca9fdeebc4b677433
2020-05-14T20:44:11Z
mmm a / src / mongo / db / index_legacy . cpp <nl> ppp b / src / mongo / db / index_legacy . cpp <nl> namespace mongo { <nl> } <nl> <nl> / / static <nl> - BSONObj IndexLegacy : : getMissingField ( const BSONObj & infoObj ) { <nl> - if ( IndexNames : : HASHED = = CatalogHack : : getAccessMethodName ( infoObj . getObjectField ( " key " ) ) ) { <nl> + BSONObj IndexLegacy : : getMissingField ( Collection * collection , const BSONObj & infoObj ) { <nl> + BSONObj keyPattern = infoObj . getObjectField ( " key " ) ; <nl> + string accessMethodName ; <nl> + if ( collection ) <nl> + accessMethodName = collection - > getIndexCatalog ( ) - > getAccessMethodName ( keyPattern ) ; <nl> + else <nl> + accessMethodName = IndexNames : : findPluginName ( keyPattern ) ; <nl> + <nl> + if ( IndexNames : : HASHED = = accessMethodName ) { <nl> int hashVersion = infoObj [ " hashVersion " ] . numberInt ( ) ; <nl> HashSeed seed = infoObj [ " seed " ] . numberInt ( ) ; <nl> <nl> mmm a / src / mongo / db / index_legacy . h <nl> ppp b / src / mongo / db / index_legacy . h <nl> namespace mongo { <nl> * <nl> * This is a significant leak of index functionality out of the index layer . <nl> * / <nl> - static BSONObj getMissingField ( const BSONObj & infoObj ) ; <nl> + static BSONObj getMissingField ( Collection * collection , const BSONObj & infoObj ) ; <nl> <nl> / * * <nl> * Perform any post - build steps for this index . <nl> mmm a / src / mongo / dbtests / namespacetests . cpp <nl> ppp b / src / mongo / dbtests / namespacetests . cpp <nl> namespace NamespaceTests { <nl> public : <nl> void run ( ) { <nl> BSONObj spec ( BSON ( " key " < < BSON ( " a " < < 1 ) ) ) ; <nl> - ASSERT_EQUALS ( jstNULL , IndexLegacy : : getMissingField ( spec ) . firstElement ( ) . type ( ) ) ; <nl> + ASSERT_EQUALS ( jstNULL , IndexLegacy : : getMissingField ( NULL , spec ) . firstElement ( ) . type ( ) ) ; <nl> } <nl> } ; <nl> <nl> namespace NamespaceTests { <nl> public : <nl> void run ( ) { <nl> BSONObj spec ( BSON ( " key " < < BSON ( " a " < < " 2d " ) ) ) ; <nl> - ASSERT_EQUALS ( jstNULL , IndexLegacy : : getMissingField ( spec ) . firstElement ( ) . type ( ) ) ; <nl> + ASSERT_EQUALS ( jstNULL , IndexLegacy : : getMissingField ( NULL , spec ) . firstElement ( ) . type ( ) ) ; <nl> } <nl> } ; <nl> <nl> namespace NamespaceTests { <nl> ASSERT_EQUALS ( HashAccessMethod : : makeSingleKey ( nullObj . firstElement ( ) , 0 , 0 ) , <nl> nullFieldFromKey . Long ( ) ) ; <nl> <nl> - BSONObj missingField = IndexLegacy : : getMissingField ( spec ) ; <nl> + BSONObj missingField = IndexLegacy : : getMissingField ( NULL , spec ) ; <nl> ASSERT_EQUALS ( NumberLong , missingField . firstElement ( ) . type ( ) ) ; <nl> ASSERT_EQUALS ( nullFieldFromKey , missingField . firstElement ( ) ) ; <nl> } <nl> namespace NamespaceTests { <nl> <nl> / / Ensure that getMissingField recognizes that the seed is different ( and returns <nl> / / the right key ) . <nl> - BSONObj missingField = IndexLegacy : : getMissingField ( spec ) ; <nl> + BSONObj missingField = IndexLegacy : : getMissingField ( NULL , spec ) ; <nl> ASSERT_EQUALS ( NumberLong , missingField . firstElement ( ) . type ( ) ) ; <nl> ASSERT_EQUALS ( nullFieldFromKey , missingField . firstElement ( ) ) ; <nl> } <nl> mmm a / src / mongo / s / d_split . cpp <nl> ppp b / src / mongo / s / d_split . cpp <nl> namespace mongo { <nl> } <nl> <nl> Client : : ReadContext ctx ( ns ) ; <nl> - NamespaceDetails * d = nsdetails ( ns ) ; <nl> - if ( ! d ) { <nl> + Collection * collection = ctx . ctx ( ) . db ( ) - > getCollection ( ns ) ; <nl> + if ( ! collection ) { <nl> errmsg = " ns not found " ; <nl> return false ; <nl> } <nl> + NamespaceDetails * d = collection - > details ( ) ; <nl> <nl> const IndexDetails * idx = d - > findIndexByPrefix ( keyPattern , <nl> true ) ; / * require single key * / <nl> namespace mongo { <nl> / / this index . <nl> / / NOTE A local copy of ' missingField ' is made because indices may be <nl> / / invalidated during a db lock yield . <nl> - BSONObj missingFieldObj = IndexLegacy : : getMissingField ( idx - > info . obj ( ) ) ; <nl> + BSONObj missingFieldObj = IndexLegacy : : getMissingField ( collection , idx - > info . obj ( ) ) ; <nl> BSONElement missingField = missingFieldObj . firstElement ( ) ; <nl> <nl> / / for now , the only check is that all shard keys are filled <nl>
SERVER - 11178 : IndexLegacy : : getMissingField using IndexCatalog
mongodb/mongo
c83e2593e8ad68bd2ad09eaaa4e28df34d0da068
2013-11-02T17:19:54Z
mmm a / THCTensorRandom . cuh <nl> ppp b / THCTensorRandom . cuh <nl> condDiv ( T * q , long * J , long inputsize , T q_max ) { <nl> / / Normalizes the L1 norm of every row to 1 ; used by multinomial <nl> template < typename T > <nl> __global__ void renormRowsL1 ( T * dist , long rows , long cols ) { <nl> - extern __shared__ __align__ ( sizeof ( T ) ) unsigned char my_smem [ ] ; <nl> + extern __shared__ unsigned char my_smem [ ] ; <nl> T * smem = reinterpret_cast < T * > ( my_smem ) ; <nl> <nl> for ( long row = blockIdx . x ; row < rows ; row + = gridDim . x ) { <nl> sampleMultinomialOnce ( long * dest , <nl> int categories , <nl> T * sampled , <nl> T * dist ) { <nl> - extern __shared__ __align__ ( sizeof ( AccT ) ) unsigned char my_smem [ ] ; <nl> + extern __shared__ unsigned char my_smem [ ] ; <nl> __shared__ bool found ; <nl> <nl> / / Shared Memory hold blockdim . x T for holding the cumulative sum , <nl>
fix alignment warning
pytorch/pytorch
bc66c9da86c5652dd271c9711659ccd689253786
2017-09-11T21:54:47Z
mmm a / hphp / hack / src / server / serverExtractStandalone . ml <nl> ppp b / hphp / hack / src / server / serverExtractStandalone . ml <nl> let global_dep_name dep = <nl> | Extends _ - > <nl> raise UnexpectedDependency ) <nl> <nl> + let get_fun_mode name = <nl> + let open Option in <nl> + Decl_provider . get_fun name <nl> + > > = fun decl - > <nl> + let file_name = Pos . filename decl . fe_pos in <nl> + Ast_provider . find_fun_in_file file_name name <nl> + > > = ( fun fun_ - > Some fun_ . Aast . f_mode ) <nl> + <nl> + let get_class_mode name = <nl> + let open Option in <nl> + Decl_provider . get_class name <nl> + > > = fun decl - > <nl> + let file_name = Pos . filename ( Decl_provider . Class . pos decl ) in <nl> + Ast_provider . find_class_in_file file_name name <nl> + > > | ( fun class_ - > class_ . Aast . c_mode ) <nl> + <nl> + let get_typedef_mode name = <nl> + let open Option in <nl> + Decl_provider . get_typedef name <nl> + > > = fun decl - > <nl> + let file_name = Pos . filename decl . td_pos in <nl> + Ast_provider . find_typedef_in_file file_name name <nl> + > > | ( fun typedef - > typedef . Aast . t_mode ) <nl> + <nl> + let get_class_or_typedef_mode name = <nl> + match get_class_mode name with <nl> + | Some mode - > Some mode <nl> + | None - > get_typedef_mode name <nl> + <nl> + let get_gconst_mode name = <nl> + let open Option in <nl> + Decl_provider . get_gconst name <nl> + > > = fun ( ( r , _ ) , _ ) - > <nl> + let file_name = Pos . filename ( Typing_reason . to_pos r ) in <nl> + Ast_provider . find_gconst_in_file file_name name <nl> + > > = ( fun gconst - > Some gconst . Aast . cst_mode ) <nl> + <nl> + let get_dep_mode dep = <nl> + let open Typing_deps . Dep in <nl> + match dep with <nl> + | Fun name <nl> + | FunName name - > <nl> + get_fun_mode name <nl> + | Class name <nl> + | Const ( name , _ ) <nl> + | Method ( name , _ ) <nl> + | SMethod ( name , _ ) <nl> + | Prop ( name , _ ) <nl> + | SProp ( name , _ ) <nl> + | Cstr name - > <nl> + get_class_or_typedef_mode name <nl> + | GConst name <nl> + | GConstName name - > <nl> + get_gconst_mode name <nl> + | RecordDef _ <nl> + | AllMembers _ <nl> + | Extends _ - > <nl> + None <nl> + <nl> + let is_strict_dep dep = get_dep_mode dep = Some FileInfo . Mstrict <nl> + <nl> + let is_strict_fun name = is_strict_dep ( Typing_deps . Dep . Fun name ) <nl> + <nl> + let is_strict_class name = is_strict_dep ( Typing_deps . Dep . Class name ) <nl> + <nl> let is_builtin_dep dep = <nl> let is_in_hhi pos = <nl> String_utils . string_ends_with <nl> let tparam_name ( tp : Typing_defs . decl_tparam ) = snd tp . tp_name <nl> <nl> let function_make_default = " extract_standalone_make_default " <nl> <nl> - let call_make_default = Printf . sprintf " % s ( ) " function_make_default <nl> + let call_make_default = Printf . sprintf " \ \ % s ( ) " function_make_default <nl> <nl> let print_fun_args tcopt fun_type = <nl> let with_default arg_idx = <nl> let sort_by_namespace declarations = <nl> declarations , we " generate " a separate file for toplevel declarations , using <nl> hh_single_type_check multifile syntax . <nl> * ) <nl> - let get_code declarations = <nl> - let decl_names = SMap . keys declarations in <nl> - let global_namespace = sort_by_namespace decl_names in <nl> - let code_from_namespace_decls name acc = <nl> - Option . value ( SMap . get name declarations ) ~ default : [ ] @ acc <nl> + let get_code strict_declarations partial_declarations = <nl> + let get_code declarations = <nl> + let decl_names = SMap . keys declarations in <nl> + let global_namespace = sort_by_namespace decl_names in <nl> + let code_from_namespace_decls name acc = <nl> + Option . value ( SMap . get name declarations ) ~ default : [ ] @ acc <nl> + in <nl> + let toplevel = <nl> + HashSet . fold code_from_namespace_decls global_namespace . decls [ ] <nl> + in <nl> + let rec code_from_namespace nspace_name nspace_content code = <nl> + let code = " } " : : code in <nl> + let code = <nl> + Caml . Hashtbl . fold code_from_namespace nspace_content . namespaces code <nl> + in <nl> + let code = <nl> + HashSet . fold code_from_namespace_decls nspace_content . decls code <nl> + in <nl> + Printf . sprintf " namespace % s { " nspace_name : : code <nl> + in <nl> + let namespaces = <nl> + Caml . Hashtbl . fold code_from_namespace global_namespace . namespaces [ ] <nl> + in <nl> + ( toplevel , namespaces ) <nl> in <nl> - let hh_prefix = " < ? hh " in <nl> - ( * Toplevel code has to be in a separate file * ) <nl> + let ( strict_toplevel , strict_namespaces ) = get_code strict_declarations in <nl> + let ( partial_toplevel , partial_namespaces ) = get_code partial_declarations in <nl> let helper = <nl> Printf . sprintf <nl> " function % s ( ) : nothing { throw new Exception ( ) ; } " <nl> function_make_default <nl> in <nl> - let toplevel = <nl> - HashSet . fold code_from_namespace_decls global_namespace . decls [ helper ] <nl> - in <nl> - let toplevel = <nl> - format @ @ String . concat ~ sep : " \ n " @ @ ( hh_prefix : : toplevel ) <nl> + let strict_hh_prefix = " < ? hh " in <nl> + let partial_hh_prefix = " < ? hh / / partial " in <nl> + let sections = <nl> + [ <nl> + ( " / / / / strict_toplevel . php " , <nl> + ( strict_hh_prefix , strict_toplevel @ [ helper ] ) ) ; <nl> + ( " / / / / partial_toplevel . php " , ( partial_hh_prefix , partial_toplevel ) ) ; <nl> + ( " / / / / strict_namespaces . php " , ( strict_hh_prefix , strict_namespaces ) ) ; <nl> + ( " / / / / partial_namespaces . php " , ( partial_hh_prefix , partial_namespaces ) ) ; <nl> + ] <nl> in <nl> - let rec code_from_namespace nspace_name nspace_content code = <nl> - let code = " } " : : code in <nl> - let code = <nl> - Caml . Hashtbl . fold code_from_namespace nspace_content . namespaces code <nl> - in <nl> - let code = <nl> - HashSet . fold code_from_namespace_decls nspace_content . decls code <nl> - in <nl> - Printf . sprintf " namespace % s { " nspace_name : : code <nl> - in <nl> - let namespaced = <nl> - Caml . Hashtbl . fold code_from_namespace global_namespace . namespaces [ ] <nl> + let non_empty_sections = <nl> + List . filter sections ~ f : ( fun ( _ , ( _ , decls ) ) - > not ( List . is_empty decls ) ) <nl> in <nl> - let namespaced = <nl> - format @ @ String . concat ~ sep : " \ n " @ @ ( hh_prefix : : namespaced ) <nl> + let format_section ( prefix , decls ) = <nl> + prefix ^ " \ n " ^ format ( String . concat ~ sep : " \ n " decls ) <nl> in <nl> - let has_code text = String . strip text < > hh_prefix in <nl> - if has_code toplevel & & has_code namespaced then <nl> - Printf . sprintf <nl> - " / / / / toplevel . php \ n % s \ n / / / / namespaces . php \ n % s " <nl> - toplevel <nl> - namespaced <nl> - else if has_code toplevel then <nl> - toplevel <nl> - else <nl> - namespaced <nl> + match non_empty_sections with <nl> + | [ ( _ , section ) ] - > format_section section <nl> + | _ - > <nl> + String . concat ~ sep : " \ n " <nl> + @ @ List . map non_empty_sections ~ f : ( fun ( comment , section ) - > <nl> + comment ^ " \ n " ^ format_section section ) <nl> <nl> let get_declarations tcopt target class_dependencies global_dependencies = <nl> + let ( strict_class_dependencies , partial_class_dependencies ) = <nl> + SMap . partition ( fun cls _ - > is_strict_class cls ) class_dependencies <nl> + in <nl> + let ( strict_global_dependencies , partial_global_dependencies ) = <nl> + List . partition_tf global_dependencies ~ f : is_strict_dep <nl> + in <nl> let add_declaration declarations name declaration = <nl> SMap . add name [ declaration ] declarations ~ combine : ( fun x y - > y @ x ) <nl> in <nl> let get_declarations tcopt target class_dependencies global_dependencies = <nl> cls <nl> ( construct_type_declaration tcopt cls ~ full_method fields ) <nl> in <nl> - let add_target_declaration declarations = <nl> - match target with <nl> - | Function function_name - > <nl> - let function_text = extract_body target in <nl> - add_declaration declarations function_name function_text <nl> - | Method _ - > declarations <nl> + let strict_declarations = <nl> + List . fold_left <nl> + strict_global_dependencies <nl> + ~ f : add_global_declaration <nl> + ~ init : SMap . empty <nl> + | > SMap . fold add_class_declaration strict_class_dependencies <nl> in <nl> - List . fold_left global_dependencies ~ f : add_global_declaration ~ init : SMap . empty <nl> - | > SMap . fold add_class_declaration class_dependencies <nl> - | > add_target_declaration <nl> + let partial_declarations = <nl> + List . fold_left <nl> + partial_global_dependencies <nl> + ~ f : add_global_declaration <nl> + ~ init : SMap . empty <nl> + | > SMap . fold add_class_declaration partial_class_dependencies <nl> + in <nl> + match target with <nl> + | Function name - > <nl> + let decl = extract_body target in <nl> + if is_strict_fun name then <nl> + ( add_declaration strict_declarations name decl , partial_declarations ) <nl> + else <nl> + ( strict_declarations , add_declaration partial_declarations name decl ) <nl> + | Method _ - > ( strict_declarations , partial_declarations ) <nl> <nl> let go tcopt target = <nl> try <nl> let go tcopt target = <nl> let ( class_dependencies , global_dependencies ) = <nl> List . partition_tf dependencies ~ f : is_class_dependency <nl> in <nl> - let declarations = <nl> + let ( strict_declarations , partial_declarations ) = <nl> get_declarations <nl> tcopt <nl> target <nl> ( group_class_dependencies_by_class class_dependencies ) <nl> global_dependencies <nl> in <nl> - get_code declarations <nl> + get_code strict_declarations partial_declarations <nl> with <nl> | NotFound - > " Not found ! " <nl> | InvalidInput - > <nl> mmm a / hphp / hack / test / integration / data / dependencies / builtins . php <nl> ppp b / hphp / hack / test / integration / data / dependencies / builtins . php <nl> <nl> - < ? hh <nl> + < ? hh / / partial <nl> / / Copyright ( c ) Facebook , Inc . and its affiliates . All Rights Reserved . <nl> <nl> namespace HH \ Lib \ PHP ; <nl> <nl> - function ini_set ( string $ varname , mixed $ newvalue ) : void { } <nl> + function ini_set ( string $ varname , mixed $ newvalue = null ) { } <nl> mmm a / hphp / hack / test / integration / data / dependencies / expected / __Ns__same_name_different_namespaces . php . exp <nl> ppp b / hphp / hack / test / integration / data / dependencies / expected / __Ns__same_name_different_namespaces . php . exp <nl> <nl> - / / / / toplevel . php <nl> + / / / / strict_toplevel . php <nl> < ? hh <nl> function extract_standalone_make_default ( ) : nothing { <nl> throw new Exception ( ) ; <nl> } <nl> <nl> - / / / / namespaces . php <nl> + / / / / strict_namespaces . php <nl> < ? hh <nl> namespace Test1 { <nl> function f ( int $ x ) : \ Test1 \ A { <nl> mmm a / hphp / hack / test / integration / data / dependencies / expected / __call_defaulted . php . exp <nl> ppp b / hphp / hack / test / integration / data / dependencies / expected / __call_defaulted . php . exp <nl> function call_defaulted ( int $ arg ) : void { <nl> with_defaults ( ) ; <nl> } <nl> function with_defaults ( <nl> - int $ arg = extract_standalone_make_default ( ) , <nl> - float $ argf = extract_standalone_make_default ( ) , <nl> + int $ arg = \ extract_standalone_make_default ( ) , <nl> + float $ argf = \ extract_standalone_make_default ( ) , <nl> ) : void { <nl> throw new \ Exception ( ) ; <nl> } <nl> function extract_standalone_make_default ( ) : nothing { <nl> throw new Exception ( ) ; <nl> } <nl> - <nl> - <nl> mmm a / hphp / hack / test / integration / data / dependencies / expected / __use_properties . php . exp <nl> ppp b / hphp / hack / test / integration / data / dependencies / expected / __use_properties . php . exp <nl> <nl> class WithProperties { <nl> public static int $ third = 0 ; <nl> public function __construct ( int $ arg ) { <nl> - $ this - > second = extract_standalone_make_default ( ) ; <nl> - $ this - > first = extract_standalone_make_default ( ) ; <nl> + $ this - > second = \ extract_standalone_make_default ( ) ; <nl> + $ this - > first = \ extract_standalone_make_default ( ) ; <nl> } <nl> public int $ second ; <nl> public int $ first ; <nl> mmm a / hphp / hack / test / integration / data / dependencies / expected / __with_mapped_namespace . php . exp <nl> ppp b / hphp / hack / test / integration / data / dependencies / expected / __with_mapped_namespace . php . exp <nl> <nl> - / / / / toplevel . php <nl> + / / / / strict_toplevel . php <nl> < ? hh <nl> function with_mapped_namespace ( ) : void { <nl> PHP \ ini_set ( ' foo ' , ' bar ' ) ; <nl> function extract_standalone_make_default ( ) : nothing { <nl> throw new Exception ( ) ; <nl> } <nl> <nl> - / / / / namespaces . php <nl> - < ? hh <nl> + / / / / partial_namespaces . php <nl> + < ? hh / / partial <nl> namespace HH { <nl> namespace Lib { <nl> namespace PHP { <nl> - function ini_set ( string $ varname , mixed $ newvalue ) : void { <nl> + function ini_set ( <nl> + string $ varname , <nl> + mixed $ newvalue = \ extract_standalone_make_default ( ) , <nl> + ) { <nl> throw new \ Exception ( ) ; <nl> } <nl> } <nl>
Put declarations originating from partial mode files into partial mode sections of the output
facebook/hhvm
3ba2a9b1238abee3deac18a86b6ed1922ca5be51
2019-10-08T14:01:27Z
mmm a / lib / SILPasses / ConstantPropagation . cpp <nl> ppp b / lib / SILPasses / ConstantPropagation . cpp <nl> static SILInstruction * constantFoldInstruction ( SILInstruction & I , <nl> for ( auto MD : SD - > getPhysicalFields ( ) ) { <nl> if ( MD = = SEI - > getField ( ) ) { <nl> ValueBase * E = Struct - > getElements ( ) [ FieldNo ] . getDef ( ) ; <nl> - / / If the element the struct_extract is extraciong is const , fold it . <nl> + / / If the element the struct_extract is extracting is const , fold it . <nl> if ( IntegerLiteralInst * ConstE = dyn_cast < IntegerLiteralInst > ( E ) ) { <nl> return ConstE ; <nl> } <nl>
[ SIL CCP ] fix typo
apple/swift
2f3664d9f724ce608eda30b571c743c4e27c40ac
2013-08-22T22:10:37Z
mmm a / chipmunk / chipmunk . vcproj <nl> ppp b / chipmunk / chipmunk . vcproj <nl> <nl> > <nl> < / File > <nl> < / Filter > <nl> - < Filter <nl> - Name = " uphonefw " <nl> - > <nl> - < File <nl> - RelativePath = " . \ uphonefw \ chipmunkUnicodeScript . h " <nl> - > <nl> - < / File > <nl> - < File <nl> - RelativePath = " . \ uphonefw \ chipmunkUnicodeScript_str . h " <nl> - > <nl> - < / File > <nl> - < File <nl> - RelativePath = " . \ uphonefw \ NewDeleteOp . cpp " <nl> - > <nl> - < / File > <nl> - < File <nl> - RelativePath = " . \ uphonefw \ TG3AppDllEntry . cpp " <nl> - > <nl> - < / File > <nl> - < File <nl> - RelativePath = " . \ uphonefw \ TG3AppDllEntry . h " <nl> - > <nl> - < / File > <nl> - < / Filter > <nl> < / Files > <nl> < Globals > <nl> < / Globals > <nl>
issue
cocos2d/cocos2d-x
1c122e1f3ee54cde8484b915679d6f5bc5b415e4
2010-09-13T07:38:26Z
mmm a / src / python / grpcio_tests / tests / tests . json <nl> ppp b / src / python / grpcio_tests / tests / tests . json <nl> <nl> " unit . _cython . cygrpc_test . SecureServerSecureClient " , <nl> " unit . _cython . cygrpc_test . TypeSmokeTest " , <nl> " unit . _dns_resolver_test . DNSResolverTest " , <nl> + " unit . _dynamic_stubs_test . DynamicStubTest " , <nl> " unit . _empty_message_test . EmptyMessageTest " , <nl> " unit . _error_message_encoding_test . ErrorMessageEncodingTest " , <nl> " unit . _exit_test . ExitTest " , <nl> mmm a / src / python / grpcio_tests / tests / unit / BUILD . bazel <nl> ppp b / src / python / grpcio_tests / tests / unit / BUILD . bazel <nl> py_library ( <nl> for test_file_name in GRPCIO_TESTS_UNIT <nl> ] <nl> <nl> - # TODO : Somehow incorporate into setup . py workflow . <nl> py2and3_test ( <nl> name = " _dynamic_stubs_test " , <nl> size = " small " , <nl> mmm a / src / python / grpcio_tests / tests / unit / _dynamic_stubs_test . py <nl> ppp b / src / python / grpcio_tests / tests / unit / _dynamic_stubs_test . py <nl> <nl> def _grpc_tools_unimportable ( ) : <nl> original_sys_path = sys . path <nl> sys . path = [ path for path in sys . path if " grpcio_tools " not in path ] <nl> + try : <nl> + import grpc_tools <nl> + except ImportError : <nl> + pass <nl> + else : <nl> + del grpc_tools <nl> + sys . path = original_sys_path <nl> + raise unittest . SkipTest ( " Failed to make grpc_tools unimportable . " ) <nl> try : <nl> yield <nl> finally : <nl> mmm a / tools / distrib / python / grpcio_tools / _parallel_compile_patch . py <nl> ppp b / tools / distrib / python / grpcio_tools / _parallel_compile_patch . py <nl> <nl> <nl> try : <nl> BUILD_EXT_COMPILER_JOBS = int ( <nl> - os . environ . get ( ' GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS ' , ' 1 ' ) ) <nl> - except ValueError : <nl> - BUILD_EXT_COMPILER_JOBS = 1 <nl> + os . environ . get ( ' GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS ' ) ) <nl> + except KeyError : <nl> + import multiprocessing <nl> + BUILD_EXT_COMPILER_JOBS = multiprocessing . cpu_count ( ) <nl> <nl> <nl> # monkey - patch for parallel compilation <nl> mmm a / tools / distrib / python / grpcio_tools / grpc_tools / test / protoc_test . py <nl> ppp b / tools / distrib / python / grpcio_tools / grpc_tools / test / protoc_test . py <nl> def _test_syntax_errors ( ) : <nl> assert False , " Compile error expected . None occurred . " <nl> <nl> <nl> - # TODO : Test warnings . <nl> - <nl> - <nl> class ProtocTest ( unittest . TestCase ) : <nl> <nl> def test_import_protos ( self ) : <nl> def test_combined_import ( self ) : <nl> def test_syntax_errors ( self ) : <nl> _run_in_subprocess ( _test_syntax_errors ) <nl> <nl> - # TODO : Write test to ensure the right module loader is used . <nl> - <nl> <nl> if __name__ = = ' __main__ ' : <nl> unittest . main ( ) <nl>
Run tests under setup . py
grpc/grpc
d4e8d9956cfbe2d0e7c086dac61859cba34aacad
2020-06-26T19:11:31Z
mmm a / include / swift / AST / Type . h <nl> ppp b / include / swift / AST / Type . h <nl> inline T * staticCastHelper ( const Type & Ty ) { <nl> template < typename T > <nl> using TypeArrayView = ArrayRefView < Type , T * , staticCastHelper , <nl> / * AllowOrigAccess * / true > ; <nl> - <nl> } / / end namespace swift <nl> <nl> namespace llvm { <nl> mmm a / include / swift / Basic / Statistics . def <nl> ppp b / include / swift / Basic / Statistics . def <nl> FRONTEND_STATISTIC ( Sema , NumUnloadedLazyIterableDeclContexts ) <nl> # include " swift / AST / AccessTypeIDZone . def " <nl> # include " swift / AST / NameLookupTypeIDZone . def " <nl> # include " swift / AST / TypeCheckerTypeIDZone . def " <nl> + # include " swift / Sema / IDETypeCheckingRequestIDZone . def " <nl> # include " swift / IDE / IDERequestIDZone . def " <nl> # undef SWIFT_TYPEID <nl> <nl> new file mode 100644 <nl> index 000000000000 . . 02dfb6f06bb6 <nl> mmm / dev / null <nl> ppp b / include / swift / Sema / IDETypeCheckingRequestIDZone . def <nl> <nl> + / / = = = mmmmmm - - IDETypeCheckingIDZone . def mmmmmmmmmmmmmmmmmmmmmmmm - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2019 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 definition file describes the types in the IDE requests <nl> + / / TypeID zone , for use with the TypeID template . <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + SWIFT_TYPEID ( IsDeclApplicableRequest ) <nl> new file mode 100644 <nl> index 000000000000 . . 11d1f77b597f <nl> mmm / dev / null <nl> ppp b / include / swift / Sema / IDETypeCheckingRequests . h <nl> <nl> + / / = = = mmm - - IDETypeCheckingRequests . h - IDE type - check Requests - - * - C + + - * - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2019 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 defines IDE type checking request using the evaluator model . <nl> + / / The file needs to exist in sema because it needs internal implementation <nl> + / / of the type checker to fulfill some requests <nl> + / / <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + # ifndef SWIFT_IDE_TYPE_CHECKING_REQUESTS_H <nl> + # define SWIFT_IDE_TYPE_CHECKING_REQUESTS_H <nl> + <nl> + # include " swift / AST / ASTTypeIDs . h " <nl> + # include " swift / AST / Evaluator . h " <nl> + # include " swift / AST / SimpleRequest . h " <nl> + # include " swift / AST / TypeCheckRequests . h " <nl> + <nl> + namespace swift { <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - / / <nl> + / / Decl applicability checking <nl> + / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - / / <nl> + struct DeclApplicabilityOwner { <nl> + const DeclContext * DC ; <nl> + const Type Ty ; <nl> + const Decl * ExtensionOrMember ; <nl> + <nl> + DeclApplicabilityOwner ( const DeclContext * DC , Type Ty , const ExtensionDecl * ED ) : <nl> + DC ( DC ) , Ty ( Ty ) , ExtensionOrMember ( ED ) { } <nl> + DeclApplicabilityOwner ( const DeclContext * DC , Type Ty , const ValueDecl * VD ) : <nl> + DC ( DC ) , Ty ( Ty ) , ExtensionOrMember ( VD ) { } <nl> + <nl> + friend llvm : : hash_code hash_value ( const DeclApplicabilityOwner & CI ) { <nl> + return hash_combine ( hash_value ( CI . Ty . getPointer ( ) ) , <nl> + hash_value ( CI . ExtensionOrMember ) ) ; <nl> + } <nl> + <nl> + friend bool operator = = ( const DeclApplicabilityOwner & lhs , <nl> + const DeclApplicabilityOwner & rhs ) { <nl> + return lhs . Ty . getPointer ( ) = = rhs . Ty . getPointer ( ) & & <nl> + lhs . ExtensionOrMember = = rhs . ExtensionOrMember ; <nl> + } <nl> + <nl> + friend bool operator ! = ( const DeclApplicabilityOwner & lhs , <nl> + const DeclApplicabilityOwner & rhs ) { <nl> + return ! ( lhs = = rhs ) ; <nl> + } <nl> + <nl> + friend void simple_display ( llvm : : raw_ostream & out , <nl> + const DeclApplicabilityOwner & owner ) { <nl> + out < < " Checking if " ; <nl> + simple_display ( out , owner . ExtensionOrMember ) ; <nl> + out < < " is applicable for " ; <nl> + simple_display ( out , owner . Ty ) ; <nl> + } <nl> + } ; <nl> + <nl> + class IsDeclApplicableRequest : <nl> + public SimpleRequest < IsDeclApplicableRequest , <nl> + bool ( DeclApplicabilityOwner ) , <nl> + CacheKind : : Cached > { <nl> + public : <nl> + using SimpleRequest : : SimpleRequest ; <nl> + <nl> + private : <nl> + friend SimpleRequest ; <nl> + <nl> + / / Evaluation . <nl> + llvm : : Expected < bool > evaluate ( Evaluator & evaluator , <nl> + DeclApplicabilityOwner Owner ) const ; <nl> + <nl> + public : <nl> + / / Caching <nl> + bool isCached ( ) const { return true ; } <nl> + / / Source location <nl> + SourceLoc getNearestLoc ( ) const { return SourceLoc ( ) ; } ; <nl> + } ; <nl> + <nl> + <nl> + / / / The zone number for the IDE . <nl> + # define SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE 97 <nl> + # define SWIFT_TYPEID_ZONE SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE <nl> + # define SWIFT_TYPEID_HEADER " swift / Sema / IDETypeCheckingRequestIDZone . def " <nl> + # include " swift / Basic / DefineTypeIDZone . h " <nl> + # undef SWIFT_TYPEID_ZONE <nl> + # undef SWIFT_TYPEID_HEADER <nl> + <nl> + / / Set up reporting of evaluated requests . <nl> + # define SWIFT_TYPEID ( RequestType ) \ <nl> + template < > \ <nl> + inline void reportEvaluatedRequest ( UnifiedStatsReporter & stats , \ <nl> + const RequestType & request ) { \ <nl> + + + stats . getFrontendCounters ( ) . RequestType ; \ <nl> + } <nl> + # include " swift / Sema / IDETypeCheckingRequestIDZone . def " <nl> + # undef SWIFT_TYPEID <nl> + <nl> + } / / end namespace swift <nl> + <nl> + # endif / / SWIFT_IDE_REQUESTS_H <nl> mmm a / include / swift / Subsystems . h <nl> ppp b / include / swift / Subsystems . h <nl> namespace swift { <nl> / / / The ASTContext will automatically call these upon construction . <nl> void registerIDERequestFunctions ( Evaluator & evaluator ) ; <nl> <nl> + / / / Register type check request functions for IDE ' s usage with the evaluator . <nl> + / / / <nl> + / / / The ASTContext will automatically call these upon construction . <nl> + / / / Calling registerIDERequestFunctions will invoke this function as well . <nl> + void registerIDETypeCheckRequestFunctions ( Evaluator & evaluator ) ; <nl> + <nl> } / / end namespace swift <nl> <nl> # endif / / SWIFT_SUBSYSTEMS_H <nl> mmm a / lib / Frontend / Frontend . cpp <nl> ppp b / lib / Frontend / Frontend . cpp <nl> bool CompilerInstance : : setUpASTContextIfNeeded ( ) { <nl> Diagnostics ) ) ; <nl> registerTypeCheckerRequestFunctions ( Context - > evaluator ) ; <nl> <nl> - / / Migrator and indexing need some IDE requests . <nl> + / / Migrator , indexing and typo correction need some IDE requests . <nl> if ( Invocation . getMigratorOptions ( ) . shouldRunMigrator ( ) | | <nl> - ! Invocation . getFrontendOptions ( ) . IndexStorePath . empty ( ) ) { <nl> + ! Invocation . getFrontendOptions ( ) . IndexStorePath . empty ( ) | | <nl> + Invocation . getLangOptions ( ) . TypoCorrectionLimit ) { <nl> registerIDERequestFunctions ( Context - > evaluator ) ; <nl> } <nl> if ( setUpModuleLoaders ( ) ) <nl> mmm a / lib / IDE / IDERequests . cpp <nl> ppp b / lib / IDE / IDERequests . cpp <nl> reinterpret_cast < AbstractRequestFunction * > ( & Name : : evaluateRequest ) , <nl> void swift : : registerIDERequestFunctions ( Evaluator & evaluator ) { <nl> evaluator . registerRequestFunctions ( SWIFT_IDE_REQUESTS_TYPEID_ZONE , <nl> ideRequestFunctions ) ; <nl> + registerIDETypeCheckRequestFunctions ( evaluator ) ; <nl> } <nl> <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - / / <nl> mmm a / lib / IDE / IDETypeChecking . cpp <nl> ppp b / lib / IDE / IDETypeChecking . cpp <nl> <nl> # include " swift / AST / ASTDemangler . h " <nl> # include " swift / AST / ProtocolConformance . h " <nl> # include " swift / Sema / IDETypeChecking . h " <nl> + # include " swift / Sema / IDETypeCheckingRequests . h " <nl> # include " swift / IDE / SourceEntityWalker . h " <nl> # include " swift / IDE / IDERequests . h " <nl> # include " swift / Parse / Lexer . h " <nl> collectAllOverriddenDecls ( ValueDecl * VD , bool IncludeProtocolRequirements , <nl> CollectOverriddenDeclsRequest ( OverridenDeclsOwner ( VD , <nl> IncludeProtocolRequirements , Transitive ) ) , ArrayRef < ValueDecl * > ( ) ) ; <nl> } <nl> + <nl> + bool swift : : isExtensionApplied ( const DeclContext * DC , Type BaseTy , <nl> + const ExtensionDecl * ED ) { <nl> + return evaluateOrDefault ( DC - > getASTContext ( ) . evaluator , <nl> + IsDeclApplicableRequest ( DeclApplicabilityOwner ( DC , BaseTy , ED ) ) , false ) ; <nl> + } <nl> + <nl> + bool swift : : isMemberDeclApplied ( const DeclContext * DC , Type BaseTy , <nl> + const ValueDecl * VD ) { <nl> + return evaluateOrDefault ( DC - > getASTContext ( ) . evaluator , <nl> + IsDeclApplicableRequest ( DeclApplicabilityOwner ( DC , BaseTy , VD ) ) , false ) ; <nl> + } <nl> mmm a / lib / Sema / CMakeLists . txt <nl> ppp b / lib / Sema / CMakeLists . txt <nl> add_swift_host_library ( swiftSema STATIC <nl> TypeCheckSwitchStmt . cpp <nl> TypeCheckType . cpp <nl> TypeChecker . cpp <nl> + IDETypeCheckingRequests . cpp <nl> <nl> $ { EXTRA_TYPECHECKER_FLAGS } ) <nl> target_link_libraries ( swiftSema PRIVATE <nl> mmm a / lib / Sema / CSGen . cpp <nl> ppp b / lib / Sema / CSGen . cpp <nl> void ConstraintSystem : : optimizeConstraints ( Expr * e ) { <nl> e - > walk ( optimizer ) ; <nl> } <nl> <nl> - static bool areGenericRequirementsSatisfied ( <nl> + bool swift : : areGenericRequirementsSatisfied ( <nl> const DeclContext * DC , const GenericSignature * sig , <nl> const SubstitutionMap & Substitutions , bool isExtension ) { <nl> <nl> static bool areGenericRequirementsSatisfied ( <nl> return CS . solveSingle ( ) . hasValue ( ) ; <nl> } <nl> <nl> - bool swift : : isExtensionApplied ( const DeclContext * DC , Type BaseTy , <nl> - const ExtensionDecl * ED ) { <nl> - / / We can ' t do anything if the base type has unbound generic parameters . <nl> - / / We can ' t leak type variables into another constraint system . <nl> - if ( BaseTy - > hasTypeVariable ( ) | | BaseTy - > hasUnboundGenericType ( ) | | <nl> - BaseTy - > hasUnresolvedType ( ) | | BaseTy - > hasError ( ) ) <nl> - return true ; <nl> - <nl> - if ( ! ED - > isConstrainedExtension ( ) ) <nl> - return true ; <nl> - <nl> - TypeChecker * TC = & createTypeChecker ( DC - > getASTContext ( ) ) ; <nl> - TC - > validateExtension ( const_cast < ExtensionDecl * > ( ED ) ) ; <nl> - <nl> - GenericSignature * genericSig = ED - > getGenericSignature ( ) ; <nl> - SubstitutionMap substMap = BaseTy - > getContextSubstitutionMap ( <nl> - DC - > getParentModule ( ) , ED - > getExtendedNominal ( ) ) ; <nl> - return areGenericRequirementsSatisfied ( DC , genericSig , substMap , <nl> - / * isExtension = * / true ) ; <nl> - } <nl> - <nl> - bool swift : : isMemberDeclApplied ( const DeclContext * DC , Type BaseTy , <nl> - const ValueDecl * VD ) { <nl> - / / We can ' t leak type variables into another constraint system . <nl> - / / We can ' t do anything if the base type has unbound generic parameters . <nl> - if ( BaseTy - > hasTypeVariable ( ) | | BaseTy - > hasUnboundGenericType ( ) | | <nl> - BaseTy - > hasUnresolvedType ( ) | | BaseTy - > hasError ( ) ) <nl> - return true ; <nl> - <nl> - const GenericContext * genericDecl = VD - > getAsGenericContext ( ) ; <nl> - if ( ! genericDecl ) <nl> - return true ; <nl> - const GenericSignature * genericSig = genericDecl - > getGenericSignature ( ) ; <nl> - if ( ! genericSig ) <nl> - return true ; <nl> - <nl> - SubstitutionMap substMap = BaseTy - > getContextSubstitutionMap ( <nl> - DC - > getParentModule ( ) , VD - > getDeclContext ( ) ) ; <nl> - return areGenericRequirementsSatisfied ( DC , genericSig , substMap , <nl> - / * isExtension = * / false ) ; <nl> - } <nl> - <nl> static bool canSatisfy ( Type type1 , Type type2 , bool openArchetypes , <nl> ConstraintKind kind , DeclContext * dc ) { <nl> std : : unique_ptr < TypeChecker > CreatedTC ; <nl> new file mode 100644 <nl> index 000000000000 . . bbf761ea144e <nl> mmm / dev / null <nl> ppp b / lib / Sema / IDETypeCheckingRequests . cpp <nl> <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / <nl> + / / This source file is part of the Swift . org open source project <nl> + / / <nl> + / / Copyright ( c ) 2014 - 2019 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> + # include " swift / AST / ASTPrinter . h " <nl> + # include " swift / AST / Decl . h " <nl> + # include " swift / AST / NameLookup . h " <nl> + # include " swift / Basic / SourceManager . h " <nl> + # include " swift / Frontend / Frontend . h " <nl> + # include " swift / Sema / IDETypeCheckingRequests . h " <nl> + # include " swift / Subsystems . h " <nl> + # include " TypeChecker . h " <nl> + <nl> + using namespace swift ; <nl> + <nl> + namespace swift { <nl> + / / Implement the IDE type zone . <nl> + # define SWIFT_TYPEID_ZONE SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE <nl> + # define SWIFT_TYPEID_HEADER " swift / Sema / IDETypeCheckingRequestIDZone . def " <nl> + # include " swift / Basic / ImplementTypeIDZone . h " <nl> + # undef SWIFT_TYPEID_ZONE <nl> + # undef SWIFT_TYPEID_HEADER <nl> + } <nl> + <nl> + / / Define request evaluation functions for each of the IDE type check requests . <nl> + static AbstractRequestFunction * ideTypeCheckRequestFunctions [ ] = { <nl> + # define SWIFT_TYPEID ( Name ) \ <nl> + reinterpret_cast < AbstractRequestFunction * > ( & Name : : evaluateRequest ) , <nl> + # include " swift / Sema / IDETypeCheckingRequestIDZone . def " <nl> + # undef SWIFT_TYPEID <nl> + } ; <nl> + <nl> + void swift : : registerIDETypeCheckRequestFunctions ( Evaluator & evaluator ) { <nl> + evaluator . registerRequestFunctions ( SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE , <nl> + ideTypeCheckRequestFunctions ) ; <nl> + } <nl> + <nl> + static bool isExtensionAppliedInternal ( const DeclContext * DC , Type BaseTy , <nl> + const ExtensionDecl * ED ) { <nl> + / / We can ' t do anything if the base type has unbound generic parameters . <nl> + / / We can ' t leak type variables into another constraint system . <nl> + if ( BaseTy - > hasTypeVariable ( ) | | BaseTy - > hasUnboundGenericType ( ) | | <nl> + BaseTy - > hasUnresolvedType ( ) | | BaseTy - > hasError ( ) ) <nl> + return true ; <nl> + <nl> + if ( ! ED - > isConstrainedExtension ( ) ) <nl> + return true ; <nl> + <nl> + TypeChecker * TC = & TypeChecker : : createForContext ( ( DC - > getASTContext ( ) ) ) ; <nl> + TC - > validateExtension ( const_cast < ExtensionDecl * > ( ED ) ) ; <nl> + <nl> + GenericSignature * genericSig = ED - > getGenericSignature ( ) ; <nl> + SubstitutionMap substMap = BaseTy - > getContextSubstitutionMap ( <nl> + DC - > getParentModule ( ) , ED - > getExtendedNominal ( ) ) ; <nl> + return areGenericRequirementsSatisfied ( DC , genericSig , substMap , <nl> + / * isExtension = * / true ) ; <nl> + } <nl> + <nl> + static bool isMemberDeclAppliedInternal ( const DeclContext * DC , Type BaseTy , <nl> + const ValueDecl * VD ) { <nl> + / / We can ' t leak type variables into another constraint system . <nl> + / / We can ' t do anything if the base type has unbound generic parameters . <nl> + if ( BaseTy - > hasTypeVariable ( ) | | BaseTy - > hasUnboundGenericType ( ) | | <nl> + BaseTy - > hasUnresolvedType ( ) | | BaseTy - > hasError ( ) ) <nl> + return true ; <nl> + <nl> + const GenericContext * genericDecl = VD - > getAsGenericContext ( ) ; <nl> + if ( ! genericDecl ) <nl> + return true ; <nl> + const GenericSignature * genericSig = genericDecl - > getGenericSignature ( ) ; <nl> + if ( ! genericSig ) <nl> + return true ; <nl> + <nl> + SubstitutionMap substMap = BaseTy - > getContextSubstitutionMap ( <nl> + DC - > getParentModule ( ) , VD - > getDeclContext ( ) ) ; <nl> + return areGenericRequirementsSatisfied ( DC , genericSig , substMap , <nl> + / * isExtension = * / false ) ; <nl> + } <nl> + <nl> + llvm : : Expected < bool > <nl> + IsDeclApplicableRequest : : evaluate ( Evaluator & evaluator , <nl> + DeclApplicabilityOwner Owner ) const { <nl> + if ( auto * VD = dyn_cast < ValueDecl > ( Owner . ExtensionOrMember ) ) { <nl> + return isMemberDeclAppliedInternal ( Owner . DC , Owner . Ty , VD ) ; <nl> + } else if ( auto * ED = dyn_cast < ExtensionDecl > ( Owner . ExtensionOrMember ) ) { <nl> + return isExtensionAppliedInternal ( Owner . DC , Owner . Ty , ED ) ; <nl> + } else { <nl> + llvm_unreachable ( " unhandled decl kind " ) ; <nl> + } <nl> + } <nl> mmm a / lib / Sema / LookupVisibleDecls . cpp <nl> ppp b / lib / Sema / LookupVisibleDecls . cpp <nl> <nl> # include " swift / AST / ProtocolConformance . h " <nl> # include " swift / Basic / SourceManager . h " <nl> # include " swift / Basic / STLExtras . h " <nl> + # include " swift / Sema / IDETypeCheckingRequests . h " <nl> # include " swift / Sema / IDETypeChecking . h " <nl> # include " llvm / ADT / SetVector . h " <nl> # include < set > <nl> static void collectVisibleMemberDecls ( const DeclContext * CurrDC , LookupState LS , <nl> continue ; <nl> if ( ! isDeclVisibleInLookupMode ( VD , LS , CurrDC , TypeResolver ) ) <nl> continue ; <nl> - if ( ! isMemberDeclApplied ( CurrDC , BaseType , VD ) ) <nl> + if ( ! evaluateOrDefault ( CurrDC - > getASTContext ( ) . evaluator , <nl> + IsDeclApplicableRequest ( DeclApplicabilityOwner ( CurrDC , BaseType , VD ) ) , <nl> + false ) ) <nl> continue ; <nl> FoundDecls . push_back ( VD ) ; <nl> } <nl> static void doGlobalExtensionLookup ( Type BaseType , <nl> <nl> / / Look in each extension of this type . <nl> for ( auto extension : nominal - > getExtensions ( ) ) { <nl> - if ( ! isExtensionApplied ( const_cast < DeclContext * > ( CurrDC ) , BaseType , <nl> - extension ) ) <nl> + if ( ! evaluateOrDefault ( CurrDC - > getASTContext ( ) . evaluator , <nl> + IsDeclApplicableRequest ( DeclApplicabilityOwner ( CurrDC , BaseType , <nl> + extension ) ) , false ) ) <nl> continue ; <nl> <nl> collectVisibleMemberDecls ( CurrDC , LS , BaseType , extension , FoundDecls , <nl> mmm a / lib / Sema / TypeChecker . h <nl> ppp b / lib / Sema / TypeChecker . h <nl> bool fixDeclarationObjCName ( InFlightDiagnostic & diag , ValueDecl * decl , <nl> Optional < ObjCSelector > targetNameOpt , <nl> bool ignoreImpliedName = false ) ; <nl> <nl> + bool areGenericRequirementsSatisfied ( const DeclContext * DC , <nl> + const GenericSignature * sig , <nl> + const SubstitutionMap & Substitutions , <nl> + bool isExtension ) ; <nl> + <nl> } / / end namespace swift <nl> <nl> # endif <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftCompletion . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftCompletion . cpp <nl> static bool swiftCodeCompleteImpl ( <nl> * CI . getASTContext ( ) . getClangModuleLoader ( ) ) ; <nl> SwiftConsumer . setContext ( & CI . getASTContext ( ) , & Invocation , <nl> & CompletionContext ) ; <nl> + registerIDETypeCheckRequestFunctions ( CI . getASTContext ( ) . evaluator ) ; <nl> CI . performSema ( ) ; <nl> SwiftConsumer . clearContext ( ) ; <nl> <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftConformingMethodList . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftConformingMethodList . cpp <nl> static bool swiftConformingMethodListImpl ( <nl> / / FIXME : error ? <nl> return true ; <nl> } <nl> + registerIDETypeCheckRequestFunctions ( CI . getASTContext ( ) . evaluator ) ; <nl> CI . performSema ( ) ; <nl> <nl> return true ; <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftEditorInterfaceGen . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftEditorInterfaceGen . cpp <nl> SwiftInterfaceGenContext : : createForTypeInterface ( CompilerInvocation Invocation , <nl> ErrorMsg = " Error during invocation setup " ; <nl> return nullptr ; <nl> } <nl> + registerIDETypeCheckRequestFunctions ( CI . getASTContext ( ) . evaluator ) ; <nl> CI . performSema ( ) ; <nl> ASTContext & Ctx = CI . getASTContext ( ) ; <nl> CloseClangModuleFiles scopedCloseFiles ( * Ctx . getClangModuleLoader ( ) ) ; <nl> mmm a / tools / SourceKit / lib / SwiftLang / SwiftTypeContextInfo . cpp <nl> ppp b / tools / SourceKit / lib / SwiftLang / SwiftTypeContextInfo . cpp <nl> static bool swiftTypeContextInfoImpl ( SwiftLangSupport & Lang , <nl> / / FIXME : error ? <nl> return true ; <nl> } <nl> + registerIDETypeCheckRequestFunctions ( CI . getASTContext ( ) . evaluator ) ; <nl> CI . performSema ( ) ; <nl> <nl> return true ; <nl>
Merge remote - tracking branch ' origin / master ' into master - next
apple/swift
9cbb87abb2d4ce5a488f11dab6da36486e29ed66
2019-07-22T21:09:39Z
mmm a / include / spdlog / async_logger . h <nl> ppp b / include / spdlog / async_logger . h <nl> <nl> <nl> # include < chrono > <nl> # include < functional > <nl> + # include < string > <nl> + # include < memory > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / common . h <nl> ppp b / include / spdlog / common . h <nl> <nl> # include < initializer_list > <nl> # include < chrono > <nl> # include < memory > <nl> + # include < exception > <nl> <nl> / / visual studio does not support noexcept yet <nl> # ifndef _MSC_VER <nl> class spdlog_ex : public std : : exception <nl> <nl> } ; <nl> <nl> - } / / spdlog <nl> \ No newline at end of file <nl> + } / / spdlog <nl> mmm a / include / spdlog / details / async_log_helper . h <nl> ppp b / include / spdlog / details / async_log_helper . h <nl> <nl> # include < spdlog / formatter . h > <nl> <nl> # include < chrono > <nl> - # include < thread > <nl> + # include < exception > <nl> # include < functional > <nl> + # include < memory > <nl> + # include < string > <nl> + # include < thread > <nl> + # include < utility > <nl> # include < vector > <nl> <nl> namespace spdlog <nl> mmm a / include / spdlog / details / async_logger_impl . h <nl> ppp b / include / spdlog / details / async_logger_impl . h <nl> <nl> # include < spdlog / details / async_log_helper . h > <nl> # include < spdlog / async_logger . h > <nl> <nl> + # include < string > <nl> + # include < functional > <nl> + # include < chrono > <nl> + # include < memory > <nl> <nl> template < class It > <nl> inline spdlog : : async_logger : : async_logger ( const std : : string & logger_name , <nl> mmm a / include / spdlog / details / file_helper . h <nl> ppp b / include / spdlog / details / file_helper . h <nl> <nl> # include < spdlog / details / os . h > <nl> # include < spdlog / details / log_msg . h > <nl> <nl> + # include < chrono > <nl> + # include < cstdio > <nl> # include < string > <nl> # include < thread > <nl> - # include < chrono > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / details / line_logger_impl . h <nl> ppp b / include / spdlog / details / line_logger_impl . h <nl> <nl> # include < spdlog / common . h > <nl> # include < spdlog / logger . h > <nl> <nl> + # include < string > <nl> + # include < utility > <nl> + <nl> / / Line logger class - aggregates operator < < calls to fast ostream <nl> / / and logs upon destruction <nl> <nl> mmm a / include / spdlog / details / log_msg . h <nl> ppp b / include / spdlog / details / log_msg . h <nl> <nl> # include < spdlog / common . h > <nl> # include < spdlog / details / format . h > <nl> <nl> - # include < thread > <nl> + # include < string > <nl> + # include < utility > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / details / logger_impl . h <nl> ppp b / include / spdlog / details / logger_impl . h <nl> <nl> <nl> # include < spdlog / logger . h > <nl> <nl> + # include < atomic > <nl> + # include < memory > <nl> + # include < string > <nl> + <nl> / / create logger with given name , sinks and the default pattern formatter <nl> / / all other ctors will call this one <nl> template < class It > <nl> mmm a / include / spdlog / details / mpmc_bounded_q . h <nl> ppp b / include / spdlog / details / mpmc_bounded_q . h <nl> Distributed under the MIT License ( http : / / opensource . org / licenses / MIT ) <nl> # include < spdlog / common . h > <nl> <nl> # include < atomic > <nl> + # include < utility > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / details / os . h <nl> ppp b / include / spdlog / details / os . h <nl> <nl> <nl> # include < spdlog / common . h > <nl> <nl> - # include < string > <nl> # include < cstdio > <nl> # include < ctime > <nl> + # include < functional > <nl> + # include < string > <nl> <nl> # ifdef _WIN32 <nl> # ifndef WIN32_LEAN_AND_MEAN <nl> <nl> # include < sys / syscall . h > / / Use gettid ( ) syscall under linux to get thread id <nl> # include < sys / stat . h > <nl> # include < unistd . h > <nl> + # include < chrono > <nl> # else <nl> # include < thread > <nl> # endif <nl> mmm a / include / spdlog / details / pattern_formatter_impl . h <nl> ppp b / include / spdlog / details / pattern_formatter_impl . h <nl> <nl> # include < spdlog / details / log_msg . h > <nl> # include < spdlog / details / os . h > <nl> <nl> - # include < string > <nl> # include < chrono > <nl> + # include < ctime > <nl> # include < memory > <nl> - # include < vector > <nl> - # include < thread > <nl> # include < mutex > <nl> + # include < string > <nl> + # include < thread > <nl> + # include < utility > <nl> + # include < vector > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / details / registry . h <nl> ppp b / include / spdlog / details / registry . h <nl> <nl> # include < spdlog / async_logger . h > <nl> # include < spdlog / common . h > <nl> <nl> - # include < string > <nl> + # include < chrono > <nl> + # include < functional > <nl> + # include < memory > <nl> # include < mutex > <nl> + # include < string > <nl> # include < unordered_map > <nl> - # include < functional > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / details / spdlog_impl . h <nl> ppp b / include / spdlog / details / spdlog_impl . h <nl> <nl> # include < spdlog / sinks / stdout_sinks . h > <nl> # include < spdlog / sinks / syslog_sink . h > <nl> <nl> + # include < chrono > <nl> + # include < functional > <nl> + # include < memory > <nl> + # include < string > <nl> + <nl> inline void spdlog : : register_logger ( std : : shared_ptr < logger > logger ) <nl> { <nl> return details : : registry : : instance ( ) . register_logger ( logger ) ; <nl> mmm a / include / spdlog / formatter . h <nl> ppp b / include / spdlog / formatter . h <nl> <nl> # include < spdlog / details / log_msg . h > <nl> <nl> # include < vector > <nl> + # include < string > <nl> + # include < memory > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / logger . h <nl> ppp b / include / spdlog / logger . h <nl> <nl> <nl> # include < vector > <nl> # include < memory > <nl> + # include < atomic > <nl> + # include < string > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / android_sink . h <nl> ppp b / include / spdlog / sinks / android_sink . h <nl> <nl> # include < android / log . h > <nl> <nl> # include < mutex > <nl> + # include < string > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / base_sink . h <nl> ppp b / include / spdlog / sinks / base_sink . h <nl> <nl> # include < spdlog / common . h > <nl> # include < spdlog / details / log_msg . h > <nl> <nl> - # include < string > <nl> # include < mutex > <nl> - # include < atomic > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / dist_sink . h <nl> ppp b / include / spdlog / sinks / dist_sink . h <nl> <nl> # include < algorithm > <nl> # include < memory > <nl> # include < mutex > <nl> - # include < list > <nl> + # include < vector > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / file_sinks . h <nl> ppp b / include / spdlog / sinks / file_sinks . h <nl> <nl> # include < spdlog / details / file_helper . h > <nl> # include < spdlog / details / format . h > <nl> <nl> + # include < algorithm > <nl> + # include < chrono > <nl> + # include < cstdio > <nl> + # include < ctime > <nl> # include < mutex > <nl> + # include < string > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / ostream_sink . h <nl> ppp b / include / spdlog / sinks / ostream_sink . h <nl> <nl> <nl> # include < ostream > <nl> # include < mutex > <nl> - # include < memory > <nl> <nl> namespace spdlog <nl> { <nl> mmm a / include / spdlog / sinks / stdout_sinks . h <nl> ppp b / include / spdlog / sinks / stdout_sinks . h <nl> <nl> # include < spdlog / details / null_mutex . h > <nl> <nl> # include < iostream > <nl> + # include < memory > <nl> # include < mutex > <nl> <nl> namespace spdlog <nl> mmm a / include / spdlog / spdlog . h <nl> ppp b / include / spdlog / spdlog . h <nl> <nl> # include < spdlog / common . h > <nl> # include < spdlog / logger . h > <nl> <nl> + # include < memory > <nl> + # include < functional > <nl> + # include < chrono > <nl> + # include < string > <nl> + <nl> namespace spdlog <nl> { <nl> / / Return an existing logger or nullptr if a logger with such name doesn ' t exist . <nl>
Added missing standard header includes .
gabime/spdlog
077c3095ebec15959057c84d0e5a84371cfd6f13
2016-02-25T04:20:07Z
mmm a / CMakeLists . txt <nl> ppp b / CMakeLists . txt <nl> endif ( ) <nl> add_dependencies ( buildtests_c endpoint_pair_test ) <nl> add_dependencies ( buildtests_c error_test ) <nl> if ( _gRPC_PLATFORM_LINUX ) <nl> + add_dependencies ( buildtests_c ev_epollex_linux_test ) <nl> + endif ( ) <nl> + if ( _gRPC_PLATFORM_LINUX ) <nl> add_dependencies ( buildtests_c ev_epollsig_linux_test ) <nl> endif ( ) <nl> add_dependencies ( buildtests_c fake_resolver_test ) <nl> endif ( gRPC_BUILD_TESTS ) <nl> if ( gRPC_BUILD_TESTS ) <nl> if ( _gRPC_PLATFORM_LINUX ) <nl> <nl> + add_executable ( ev_epollex_linux_test <nl> + test / core / iomgr / ev_epollex_linux_test . cc <nl> + ) <nl> + <nl> + <nl> + target_include_directories ( ev_epollex_linux_test <nl> + PRIVATE $ { CMAKE_CURRENT_SOURCE_DIR } <nl> + PRIVATE $ { CMAKE_CURRENT_SOURCE_DIR } / include <nl> + PRIVATE $ { _gRPC_SSL_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_PROTOBUF_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_ZLIB_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_BENCHMARK_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_CARES_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_GFLAGS_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_ADDRESS_SORTING_INCLUDE_DIR } <nl> + PRIVATE $ { _gRPC_NANOPB_INCLUDE_DIR } <nl> + ) <nl> + <nl> + target_link_libraries ( ev_epollex_linux_test <nl> + $ { _gRPC_ALLTARGETS_LIBRARIES } <nl> + grpc_test_util <nl> + grpc <nl> + gpr_test_util <nl> + gpr <nl> + ) <nl> + <nl> + endif ( ) <nl> + endif ( gRPC_BUILD_TESTS ) <nl> + if ( gRPC_BUILD_TESTS ) <nl> + if ( _gRPC_PLATFORM_LINUX ) <nl> + <nl> add_executable ( ev_epollsig_linux_test <nl> test / core / iomgr / ev_epollsig_linux_test . cc <nl> ) <nl> mmm a / Makefile <nl> ppp b / Makefile <nl> dns_resolver_test : $ ( BINDIR ) / $ ( CONFIG ) / dns_resolver_test <nl> dualstack_socket_test : $ ( BINDIR ) / $ ( CONFIG ) / dualstack_socket_test <nl> endpoint_pair_test : $ ( BINDIR ) / $ ( CONFIG ) / endpoint_pair_test <nl> error_test : $ ( BINDIR ) / $ ( CONFIG ) / error_test <nl> + ev_epollex_linux_test : $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test <nl> ev_epollsig_linux_test : $ ( BINDIR ) / $ ( CONFIG ) / ev_epollsig_linux_test <nl> fake_resolver_test : $ ( BINDIR ) / $ ( CONFIG ) / fake_resolver_test <nl> fake_transport_security_test : $ ( BINDIR ) / $ ( CONFIG ) / fake_transport_security_test <nl> buildtests_c : privatelibs_c \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / dualstack_socket_test \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / endpoint_pair_test \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / error_test \ <nl> + $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / ev_epollsig_linux_test \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / fake_resolver_test \ <nl> $ ( BINDIR ) / $ ( CONFIG ) / fake_transport_security_test \ <nl> test_c : buildtests_c <nl> $ ( Q ) $ ( BINDIR ) / $ ( CONFIG ) / endpoint_pair_test | | ( echo test endpoint_pair_test failed ; exit 1 ) <nl> $ ( E ) " [ RUN ] Testing error_test " <nl> $ ( Q ) $ ( BINDIR ) / $ ( CONFIG ) / error_test | | ( echo test error_test failed ; exit 1 ) <nl> + $ ( E ) " [ RUN ] Testing ev_epollex_linux_test " <nl> + $ ( Q ) $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test | | ( echo test ev_epollex_linux_test failed ; exit 1 ) <nl> $ ( E ) " [ RUN ] Testing ev_epollsig_linux_test " <nl> $ ( Q ) $ ( BINDIR ) / $ ( CONFIG ) / ev_epollsig_linux_test | | ( echo test ev_epollsig_linux_test failed ; exit 1 ) <nl> $ ( E ) " [ RUN ] Testing fake_resolver_test " <nl> endif <nl> endif <nl> <nl> <nl> + EV_EPOLLEX_LINUX_TEST_SRC = \ <nl> + test / core / iomgr / ev_epollex_linux_test . cc \ <nl> + <nl> + EV_EPOLLEX_LINUX_TEST_OBJS = $ ( addprefix $ ( OBJDIR ) / $ ( CONFIG ) / , $ ( addsuffix . o , $ ( basename $ ( EV_EPOLLEX_LINUX_TEST_SRC ) ) ) ) <nl> + ifeq ( $ ( NO_SECURE ) , true ) <nl> + <nl> + # You can ' t build secure targets if you don ' t have OpenSSL . <nl> + <nl> + $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test : openssl_dep_error <nl> + <nl> + else <nl> + <nl> + <nl> + <nl> + $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test : $ ( EV_EPOLLEX_LINUX_TEST_OBJS ) $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a <nl> + $ ( E ) " [ LD ] Linking $ @ " <nl> + $ ( Q ) mkdir - p ` dirname $ @ ` <nl> + $ ( Q ) $ ( LD ) $ ( LDFLAGS ) $ ( EV_EPOLLEX_LINUX_TEST_OBJS ) $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a $ ( LDLIBS ) $ ( LDLIBS_SECURE ) - o $ ( BINDIR ) / $ ( CONFIG ) / ev_epollex_linux_test <nl> + <nl> + endif <nl> + <nl> + $ ( OBJDIR ) / $ ( CONFIG ) / test / core / iomgr / ev_epollex_linux_test . o : $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgrpc . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr_test_util . a $ ( LIBDIR ) / $ ( CONFIG ) / libgpr . a <nl> + <nl> + deps_ev_epollex_linux_test : $ ( EV_EPOLLEX_LINUX_TEST_OBJS : . o = . dep ) <nl> + <nl> + ifneq ( $ ( NO_SECURE ) , true ) <nl> + ifneq ( $ ( NO_DEPS ) , true ) <nl> + - include $ ( EV_EPOLLEX_LINUX_TEST_OBJS : . o = . dep ) <nl> + endif <nl> + endif <nl> + <nl> + <nl> EV_EPOLLSIG_LINUX_TEST_SRC = \ <nl> test / core / iomgr / ev_epollsig_linux_test . cc \ <nl> <nl> mmm a / build . yaml <nl> ppp b / build . yaml <nl> targets : <nl> - gpr_test_util <nl> - gpr <nl> uses_polling : false <nl> + - name : ev_epollex_linux_test <nl> + cpu_cost : 3 <nl> + build : test <nl> + language : c <nl> + src : <nl> + - test / core / iomgr / ev_epollex_linux_test . cc <nl> + deps : <nl> + - grpc_test_util <nl> + - grpc <nl> + - gpr_test_util <nl> + - gpr <nl> + exclude_iomgrs : <nl> + - uv <nl> + platforms : <nl> + - linux <nl> - name : ev_epollsig_linux_test <nl> cpu_cost : 3 <nl> build : test <nl> mmm a / src / core / lib / iomgr / ev_epollex_linux . cc <nl> ppp b / src / core / lib / iomgr / ev_epollex_linux . cc <nl> struct pollable { <nl> int epfd ; <nl> grpc_wakeup_fd wakeup ; <nl> <nl> - / / only for type fd . . . one ref to the owner fd <nl> - grpc_fd * owner_fd ; <nl> + / / The following are relevant only for type PO_FD <nl> + grpc_fd * owner_fd ; / / Set to the owner_fd if the type is PO_FD <nl> + gpr_mu owner_orphan_mu ; / / Synchronizes access to owner_orphaned field <nl> + bool owner_orphaned ; / / Is the owner fd orphaned <nl> <nl> grpc_pollset_set * pollset_set ; <nl> pollable * next ; <nl> static void ref_by ( grpc_fd * fd , int n ) { <nl> GPR_ASSERT ( gpr_atm_no_barrier_fetch_add ( & fd - > refst , n ) > 0 ) ; <nl> } <nl> <nl> + # ifndef NDEBUG <nl> + # define INVALIDATE_FD ( fd ) invalidate_fd ( fd ) <nl> + / * Since an fd is never really destroyed ( i . e gpr_free ( ) is not called ) , it is <nl> + * hard to cases where fd fields are accessed even after calling fd_destroy ( ) . <nl> + * The following invalidates fd fields to make catching such errors easier * / <nl> + static void invalidate_fd ( grpc_fd * fd ) { <nl> + fd - > fd = - 1 ; <nl> + fd - > salt = - 1 ; <nl> + gpr_atm_no_barrier_store ( & fd - > refst , - 1 ) ; <nl> + memset ( & fd - > orphan_mu , - 1 , sizeof ( fd - > orphan_mu ) ) ; <nl> + memset ( & fd - > pollable_mu , - 1 , sizeof ( fd - > pollable_mu ) ) ; <nl> + fd - > pollable_obj = nullptr ; <nl> + fd - > on_done_closure = nullptr ; <nl> + gpr_atm_no_barrier_store ( & fd - > read_notifier_pollset , 0 ) ; <nl> + memset ( & fd - > iomgr_object , - 1 , sizeof ( fd - > iomgr_object ) ) ; <nl> + fd - > track_err = false ; <nl> + } <nl> + # else <nl> + # define INVALIDATE_FD ( fd ) <nl> + # endif <nl> + <nl> + / * Uninitialize and add to the freelist * / <nl> static void fd_destroy ( void * arg , grpc_error * error ) { <nl> grpc_fd * fd = static_cast < grpc_fd * > ( arg ) ; <nl> - / * Add the fd to the freelist * / <nl> grpc_iomgr_unregister_object ( & fd - > iomgr_object ) ; <nl> POLLABLE_UNREF ( fd - > pollable_obj , " fd_pollable " ) ; <nl> gpr_mu_destroy ( & fd - > pollable_mu ) ; <nl> gpr_mu_destroy ( & fd - > orphan_mu ) ; <nl> - gpr_mu_lock ( & fd_freelist_mu ) ; <nl> - fd - > freelist_next = fd_freelist ; <nl> - fd_freelist = fd ; <nl> <nl> fd - > read_closure - > DestroyEvent ( ) ; <nl> fd - > write_closure - > DestroyEvent ( ) ; <nl> fd - > error_closure - > DestroyEvent ( ) ; <nl> <nl> + INVALIDATE_FD ( fd ) ; <nl> + <nl> + / * Add the fd to the freelist * / <nl> + gpr_mu_lock ( & fd_freelist_mu ) ; <nl> + fd - > freelist_next = fd_freelist ; <nl> + fd_freelist = fd ; <nl> gpr_mu_unlock ( & fd_freelist_mu ) ; <nl> } <nl> <nl> static grpc_fd * fd_create ( int fd , const char * name , bool track_err ) { <nl> new_fd - > error_closure . Init ( ) ; <nl> } <nl> <nl> - gpr_mu_init ( & new_fd - > pollable_mu ) ; <nl> - gpr_mu_init ( & new_fd - > orphan_mu ) ; <nl> - new_fd - > pollable_obj = nullptr ; <nl> - gpr_atm_rel_store ( & new_fd - > refst , ( gpr_atm ) 1 ) ; <nl> new_fd - > fd = fd ; <nl> - new_fd - > track_err = track_err ; <nl> new_fd - > salt = gpr_atm_no_barrier_fetch_add ( & g_fd_salt , 1 ) ; <nl> + gpr_atm_rel_store ( & new_fd - > refst , ( gpr_atm ) 1 ) ; <nl> + gpr_mu_init ( & new_fd - > orphan_mu ) ; <nl> + gpr_mu_init ( & new_fd - > pollable_mu ) ; <nl> + new_fd - > pollable_obj = nullptr ; <nl> new_fd - > read_closure - > InitEvent ( ) ; <nl> new_fd - > write_closure - > InitEvent ( ) ; <nl> new_fd - > error_closure - > InitEvent ( ) ; <nl> - gpr_atm_no_barrier_store ( & new_fd - > read_notifier_pollset , ( gpr_atm ) NULL ) ; <nl> - <nl> new_fd - > freelist_next = nullptr ; <nl> new_fd - > on_done_closure = nullptr ; <nl> + gpr_atm_no_barrier_store ( & new_fd - > read_notifier_pollset , ( gpr_atm ) NULL ) ; <nl> <nl> char * fd_name ; <nl> gpr_asprintf ( & fd_name , " % s fd = % d " , name , fd ) ; <nl> static grpc_fd * fd_create ( int fd , const char * name , bool track_err ) { <nl> } <nl> # endif <nl> gpr_free ( fd_name ) ; <nl> + <nl> + new_fd - > track_err = track_err ; <nl> return new_fd ; <nl> } <nl> <nl> static void fd_orphan ( grpc_fd * fd , grpc_closure * on_done , int * release_fd , <nl> <nl> gpr_mu_lock ( & fd - > orphan_mu ) ; <nl> <nl> + / / Get the fd - > pollable_obj and set the owner_orphaned on that pollable to <nl> + / / true so that the pollable will no longer access its owner_fd field . <nl> + gpr_mu_lock ( & fd - > pollable_mu ) ; <nl> + pollable * pollable_obj = fd - > pollable_obj ; <nl> + gpr_mu_unlock ( & fd - > pollable_mu ) ; <nl> + <nl> + if ( pollable_obj ) { <nl> + gpr_mu_lock ( & pollable_obj - > owner_orphan_mu ) ; <nl> + pollable_obj - > owner_orphaned = true ; <nl> + } <nl> + <nl> fd - > on_done_closure = on_done ; <nl> <nl> / * If release_fd is not NULL , we should be relinquishing control of the file <nl> static void fd_orphan ( grpc_fd * fd , grpc_closure * on_done , int * release_fd , <nl> <nl> GRPC_CLOSURE_SCHED ( fd - > on_done_closure , GRPC_ERROR_NONE ) ; <nl> <nl> + if ( pollable_obj ) { <nl> + gpr_mu_unlock ( & pollable_obj - > owner_orphan_mu ) ; <nl> + } <nl> + <nl> gpr_mu_unlock ( & fd - > orphan_mu ) ; <nl> <nl> UNREF_BY ( fd , 2 , reason ) ; / * Drop the reference * / <nl> static grpc_error * pollable_create ( pollable_type type , pollable * * p ) { <nl> gpr_mu_init ( & ( * p ) - > mu ) ; <nl> ( * p ) - > epfd = epfd ; <nl> ( * p ) - > owner_fd = nullptr ; <nl> + gpr_mu_init ( & ( * p ) - > owner_orphan_mu ) ; <nl> + ( * p ) - > owner_orphaned = false ; <nl> ( * p ) - > pollset_set = nullptr ; <nl> ( * p ) - > next = ( * p ) - > prev = * p ; <nl> ( * p ) - > root_worker = nullptr ; <nl> static void pollable_unref ( pollable * p , int line , const char * reason ) { <nl> GRPC_FD_TRACE ( " pollable_unref : Closing epfd : % d " , p - > epfd ) ; <nl> close ( p - > epfd ) ; <nl> grpc_wakeup_fd_destroy ( & p - > wakeup ) ; <nl> + gpr_mu_destroy ( & p - > owner_orphan_mu ) ; <nl> gpr_free ( p ) ; <nl> } <nl> } <nl> static void fd_become_writable ( grpc_fd * fd ) { fd - > write_closure - > SetReady ( ) ; } <nl> <nl> static void fd_has_errors ( grpc_fd * fd ) { fd - > error_closure - > SetReady ( ) ; } <nl> <nl> - static grpc_error * fd_get_or_become_pollable ( grpc_fd * fd , pollable * * p ) { <nl> + / * Get the pollable_obj attached to this fd . If none is attached , create a new <nl> + * pollable object ( of type PO_FD ) , attach it to the fd and return it <nl> + * <nl> + * Note that if a pollable object is already attached to the fd , it may be of <nl> + * either PO_FD or PO_MULTI type * / <nl> + static grpc_error * get_fd_pollable ( grpc_fd * fd , pollable * * p ) { <nl> gpr_mu_lock ( & fd - > pollable_mu ) ; <nl> grpc_error * error = GRPC_ERROR_NONE ; <nl> - static const char * err_desc = " fd_get_or_become_pollable " ; <nl> + static const char * err_desc = " get_fd_pollable " ; <nl> if ( fd - > pollable_obj = = nullptr ) { <nl> if ( append_error ( & error , pollable_create ( PO_FD , & fd - > pollable_obj ) , <nl> err_desc ) ) { <nl> static grpc_error * pollset_transition_pollable_from_empty_to_fd_locked ( <nl> } <nl> append_error ( & error , pollset_kick_all ( pollset ) , err_desc ) ; <nl> POLLABLE_UNREF ( pollset - > active_pollable , " pollset " ) ; <nl> - append_error ( & error , fd_get_or_become_pollable ( fd , & pollset - > active_pollable ) , <nl> + append_error ( & error , get_fd_pollable ( fd , & pollset - > active_pollable ) , <nl> err_desc ) ; <nl> return error ; <nl> } <nl> static grpc_error * pollset_add_fd_locked ( grpc_pollset * pollset , grpc_fd * fd ) { <nl> error = pollset_transition_pollable_from_empty_to_fd_locked ( pollset , fd ) ; <nl> break ; <nl> case PO_FD : <nl> - gpr_mu_lock ( & po_at_start - > owner_fd - > orphan_mu ) ; <nl> - if ( ( gpr_atm_no_barrier_load ( & pollset - > active_pollable - > owner_fd - > refst ) & <nl> - 1 ) = = 0 ) { <nl> + gpr_mu_lock ( & po_at_start - > owner_orphan_mu ) ; <nl> + if ( po_at_start - > owner_orphaned ) { <nl> error = <nl> pollset_transition_pollable_from_empty_to_fd_locked ( pollset , fd ) ; <nl> } else { <nl> static grpc_error * pollset_add_fd_locked ( grpc_pollset * pollset , grpc_fd * fd ) { <nl> error = <nl> pollset_transition_pollable_from_fd_to_multi_locked ( pollset , fd ) ; <nl> } <nl> - gpr_mu_unlock ( & po_at_start - > owner_fd - > orphan_mu ) ; <nl> + gpr_mu_unlock ( & po_at_start - > owner_orphan_mu ) ; <nl> break ; <nl> case PO_MULTI : <nl> error = pollable_add_fd ( pollset - > active_pollable , fd ) ; <nl> static grpc_error * pollset_as_multipollable_locked ( grpc_pollset * pollset , <nl> append_error ( & error , pollset_kick_all ( pollset ) , err_desc ) ; <nl> break ; <nl> case PO_FD : <nl> - gpr_mu_lock ( & po_at_start - > owner_fd - > orphan_mu ) ; <nl> - if ( ( gpr_atm_no_barrier_load ( & pollset - > active_pollable - > owner_fd - > refst ) & <nl> - 1 ) = = 0 ) { <nl> + gpr_mu_lock ( & po_at_start - > owner_orphan_mu ) ; <nl> + if ( po_at_start - > owner_orphaned ) { <nl> + / / Unlock before Unref ' ing the pollable <nl> + gpr_mu_unlock ( & po_at_start - > owner_orphan_mu ) ; <nl> POLLABLE_UNREF ( pollset - > active_pollable , " pollset " ) ; <nl> error = pollable_create ( PO_MULTI , & pollset - > active_pollable ) ; <nl> } else { <nl> error = pollset_transition_pollable_from_fd_to_multi_locked ( pollset , <nl> nullptr ) ; <nl> + gpr_mu_unlock ( & po_at_start - > owner_orphan_mu ) ; <nl> } <nl> - gpr_mu_unlock ( & po_at_start - > owner_fd - > orphan_mu ) ; <nl> break ; <nl> case PO_MULTI : <nl> break ; <nl> mmm a / test / core / iomgr / BUILD <nl> ppp b / test / core / iomgr / BUILD <nl> licenses ( [ " notice " ] ) # Apache v2 <nl> <nl> load ( " / / test / core / util : grpc_fuzzer . bzl " , " grpc_fuzzer " ) <nl> <nl> - grpc_package ( name = " test / core / iomgr " , visibility = " public " ) # Useful for third party devs to test their io manager implementation . <nl> + grpc_package ( <nl> + name = " test / core / iomgr " , <nl> + visibility = " public " , <nl> + ) # Useful for third party devs to test their io manager implementation . <nl> <nl> grpc_cc_library ( <nl> name = " endpoint_tests " , <nl> grpc_cc_test ( <nl> ] , <nl> ) <nl> <nl> + grpc_cc_test ( <nl> + name = " ev_epollex_linux_test " , <nl> + srcs = [ " ev_epollex_linux_test . cc " ] , <nl> + language = " C + + " , <nl> + deps = [ <nl> + " / / : gpr " , <nl> + " / / : grpc " , <nl> + " / / test / core / util : gpr_test_util " , <nl> + " / / test / core / util : grpc_test_util " , <nl> + ] , <nl> + ) <nl> + <nl> grpc_cc_test ( <nl> name = " ev_epollsig_linux_test " , <nl> srcs = [ " ev_epollsig_linux_test . cc " ] , <nl> + language = " C + + " , <nl> deps = [ <nl> " / / : gpr " , <nl> " / / : grpc " , <nl> " / / test / core / util : gpr_test_util " , <nl> " / / test / core / util : grpc_test_util " , <nl> ] , <nl> - language = " C + + " , <nl> ) <nl> <nl> grpc_cc_test ( <nl> grpc_cc_test ( <nl> name = " tcp_server_posix_test " , <nl> srcs = [ " tcp_server_posix_test . cc " ] , <nl> language = " C + + " , <nl> + tags = [ " manual " ] , # TODO ( adelez ) : Remove once this works on Foundry . <nl> deps = [ <nl> " / / : gpr " , <nl> " / / : grpc " , <nl> " / / test / core / util : gpr_test_util " , <nl> " / / test / core / util : grpc_test_util " , <nl> ] , <nl> - tags = [ " manual " ] , # TODO ( adelez ) : Remove once this works on Foundry . <nl> ) <nl> <nl> grpc_cc_test ( <nl> new file mode 100644 <nl> index 00000000000 . . 08d1e68b398 <nl> mmm / dev / null <nl> ppp b / test / core / iomgr / ev_epollex_linux_test . cc <nl> <nl> + / * <nl> + * <nl> + * Copyright 2018 gRPC authors . <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> + # include " src / core / lib / iomgr / port . h " <nl> + <nl> + / * This test only relevant on linux systems where epoll ( ) is available * / <nl> + # if defined ( GRPC_LINUX_EPOLL_CREATE1 ) & & defined ( GRPC_LINUX_EVENTFD ) <nl> + # include " src / core / lib / iomgr / ev_epollex_linux . h " <nl> + <nl> + # include < grpc / grpc . h > <nl> + # include < string . h > <nl> + # include < sys / eventfd . h > <nl> + <nl> + # include " test / core / util / test_config . h " <nl> + <nl> + static void pollset_destroy ( void * ps , grpc_error * error ) { <nl> + grpc_pollset_destroy ( static_cast < grpc_pollset * > ( ps ) ) ; <nl> + gpr_free ( ps ) ; <nl> + } <nl> + <nl> + / / This test is added to cover the case found in bug : <nl> + / / https : / / github . com / grpc / grpc / issues / 15760 <nl> + static void test_pollable_owner_fd ( ) { <nl> + grpc_core : : ExecCtx exec_ctx ; <nl> + int ev_fd1 ; <nl> + int ev_fd2 ; <nl> + grpc_fd * grpc_fd1 ; <nl> + grpc_fd * grpc_fd2 ; <nl> + grpc_pollset * ps ; <nl> + gpr_mu * mu ; <nl> + <nl> + / / = = Create two grpc_fds = = <nl> + / / All we need is two file descriptors . Doesn ' t matter what type . We use <nl> + / / eventfd type here for the purpose of this test <nl> + ev_fd1 = eventfd ( 0 , EFD_NONBLOCK | EFD_CLOEXEC ) ; <nl> + ev_fd2 = eventfd ( 0 , EFD_NONBLOCK | EFD_CLOEXEC ) ; <nl> + if ( ev_fd1 < 0 | | ev_fd2 < 0 ) { <nl> + gpr_log ( GPR_ERROR , " Error in creating event fds for the test " ) ; <nl> + return ; <nl> + } <nl> + grpc_fd1 = grpc_fd_create ( ev_fd1 , " epollex - test - fd1 " , false ) ; <nl> + grpc_fd2 = grpc_fd_create ( ev_fd2 , " epollex - test - fd2 " , false ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = = Create a pollset = = <nl> + ps = static_cast < grpc_pollset * > ( gpr_zalloc ( grpc_pollset_size ( ) ) ) ; <nl> + grpc_pollset_init ( ps , & mu ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = = Add fd1 to pollset = = <nl> + grpc_pollset_add_fd ( ps , grpc_fd1 ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = = Destroy fd1 = = <nl> + grpc_fd_orphan ( grpc_fd1 , nullptr , nullptr , " test fd1 orphan " ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = Add fd2 to pollset = = <nl> + / / <nl> + / / Before https : / / github . com / grpc / grpc / issues / 15760 , the following line caused <nl> + / / unexpected behavior ( The previous grpc_pollset_add_fd ( ps , grpc_fd1 ) created <nl> + / / an underlying structure in epollex that held a reference to grpc_fd1 which <nl> + / / was being accessed here even after grpc_fd_orphan ( grpc_fd1 ) was called <nl> + grpc_pollset_add_fd ( ps , grpc_fd2 ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = = Destroy fd2 = = <nl> + grpc_fd_orphan ( grpc_fd2 , nullptr , nullptr , " test fd2 orphan " ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + <nl> + / / = = Destroy pollset <nl> + grpc_closure ps_destroy_closure ; <nl> + GRPC_CLOSURE_INIT ( & ps_destroy_closure , pollset_destroy , ps , <nl> + grpc_schedule_on_exec_ctx ) ; <nl> + grpc_pollset_shutdown ( ps , & ps_destroy_closure ) ; <nl> + grpc_core : : ExecCtx : : Get ( ) - > Flush ( ) ; <nl> + } <nl> + <nl> + int main ( int argc , char * * argv ) { <nl> + const char * poll_strategy = nullptr ; <nl> + grpc_test_init ( argc , argv ) ; <nl> + grpc_init ( ) ; <nl> + { <nl> + grpc_core : : ExecCtx exec_ctx ; <nl> + poll_strategy = grpc_get_poll_strategy_name ( ) ; <nl> + if ( poll_strategy ! = nullptr & & strcmp ( poll_strategy , " epollex " ) = = 0 ) { <nl> + test_pollable_owner_fd ( ) ; <nl> + } else { <nl> + gpr_log ( GPR_INFO , <nl> + " Skipping the test . The test is only relevant for ' epollex ' " <nl> + " strategy . and the current strategy is : ' % s ' " , <nl> + poll_strategy ) ; <nl> + } <nl> + } <nl> + <nl> + grpc_shutdown ( ) ; <nl> + return 0 ; <nl> + } <nl> + # else / * defined ( GRPC_LINUX_EPOLL_CREATE1 ) & & defined ( GRPC_LINUX_EVENTFD ) * / <nl> + int main ( int argc , char * * argv ) { return 0 ; } <nl> + # endif <nl> mmm a / tools / run_tests / generated / sources_and_headers . json <nl> ppp b / tools / run_tests / generated / sources_and_headers . json <nl> <nl> " third_party " : false , <nl> " type " : " target " <nl> } , <nl> + { <nl> + " deps " : [ <nl> + " gpr " , <nl> + " gpr_test_util " , <nl> + " grpc " , <nl> + " grpc_test_util " <nl> + ] , <nl> + " headers " : [ ] , <nl> + " is_filegroup " : false , <nl> + " language " : " c " , <nl> + " name " : " ev_epollex_linux_test " , <nl> + " src " : [ <nl> + " test / core / iomgr / ev_epollex_linux_test . cc " <nl> + ] , <nl> + " third_party " : false , <nl> + " type " : " target " <nl> + } , <nl> { <nl> " deps " : [ <nl> " gpr " , <nl> mmm a / tools / run_tests / generated / tests . json <nl> ppp b / tools / run_tests / generated / tests . json <nl> <nl> ] , <nl> " uses_polling " : false <nl> } , <nl> + { <nl> + " args " : [ ] , <nl> + " benchmark " : false , <nl> + " ci_platforms " : [ <nl> + " linux " <nl> + ] , <nl> + " cpu_cost " : 3 , <nl> + " exclude_configs " : [ ] , <nl> + " exclude_iomgrs " : [ <nl> + " uv " <nl> + ] , <nl> + " flaky " : false , <nl> + " gtest " : false , <nl> + " language " : " c " , <nl> + " name " : " ev_epollex_linux_test " , <nl> + " platforms " : [ <nl> + " linux " <nl> + ] , <nl> + " uses_polling " : true <nl> + } , <nl> { <nl> " args " : [ ] , <nl> " benchmark " : false , <nl>
Merge pull request from sreecha / epollex - ownerfd - fix
grpc/grpc
e0198fce70c3f79475f63860af7c46840496765d
2018-06-25T20:37:36Z
mmm a / include / internal / catch_runner_impl . hpp <nl> ppp b / include / internal / catch_runner_impl . hpp <nl> namespace Catch { <nl> m_reporter - > sectionStarting ( testCaseSection ) ; <nl> try { <nl> m_lastAssertionInfo = AssertionInfo ( " TEST_CASE " , testCaseInfo . lineInfo , " " , ResultDisposition : : Normal ) ; <nl> - m_testCaseTracker - > enter ( ) ; <nl> + TestCaseTracker : : Guard guard ( * m_testCaseTracker ) ; <nl> <nl> if ( m_reporter - > getPreferences ( ) . shouldRedirectStdOut ) { <nl> StreamRedirect coutRedir ( std : : cout , redirectedCout ) ; <nl> namespace Catch { <nl> else { <nl> m_activeTestCase - > invoke ( ) ; <nl> } <nl> - m_testCaseTracker - > leave ( ) ; <nl> } <nl> catch ( TestFailureException & ) { <nl> / / This just means the test was aborted due to failure <nl> - m_testCaseTracker - > leave ( ) ; / / ! TBD : RAII <nl> } <nl> catch ( . . . ) { <nl> - m_testCaseTracker - > leave ( ) ; <nl> ExpressionResultBuilder exResult ( ResultWas : : ThrewException ) ; <nl> exResult < < translateActiveException ( ) ; <nl> actOnCurrentResult ( exResult . buildResult ( m_lastAssertionInfo ) ) ; <nl> mmm a / include / internal / catch_test_case_tracker . hpp <nl> ppp b / include / internal / catch_test_case_tracker . hpp <nl> namespace SectionTracking { <nl> <nl> } ; <nl> <nl> - class SectionTracker { <nl> + class TestCaseTracker { <nl> public : <nl> - SectionTracker ( TrackedSection & testCase ) <nl> - : m_currentSection ( & testCase ) , <nl> + TestCaseTracker ( std : : string const & testCaseName ) <nl> + : m_testCase ( testCaseName , NULL ) , <nl> + m_currentSection ( & m_testCase ) , <nl> m_completedASectionThisRun ( false ) <nl> { } <nl> - <nl> + <nl> bool enterSection ( std : : string const & name ) { <nl> if ( m_completedASectionThisRun ) <nl> return false ; <nl> namespace SectionTracking { <nl> return false ; <nl> } <nl> } <nl> - <nl> void leaveSection ( ) { <nl> m_currentSection - > leave ( ) ; <nl> m_currentSection = m_currentSection - > getParent ( ) ; <nl> namespace SectionTracking { <nl> m_completedASectionThisRun = true ; <nl> } <nl> <nl> - bool currentSectinHasChildren ( ) const { <nl> + bool currentSectionHasChildren ( ) const { <nl> return m_currentSection - > hasChildren ( ) ; <nl> } <nl> + bool isCompleted ( ) const { <nl> + return m_testCase . runState ( ) = = TrackedSection : : Completed ; <nl> + } <nl> <nl> - private : <nl> - TrackedSection * m_currentSection ; <nl> - bool m_completedASectionThisRun ; <nl> - } ; <nl> - <nl> - class TestCaseTracker { <nl> - public : <nl> - <nl> - TestCaseTracker ( std : : string const & testCaseName ) <nl> - : m_testCase ( testCaseName , NULL ) , <nl> - m_sections ( m_testCase ) <nl> - { } <nl> + class Guard { <nl> + public : <nl> + Guard ( TestCaseTracker & tracker ) <nl> + : m_tracker ( tracker ) <nl> + { <nl> + m_tracker . enterTestCase ( ) ; <nl> + } <nl> + ~ Guard ( ) { <nl> + m_tracker . leaveTestCase ( ) ; <nl> + } <nl> + private : <nl> + TestCaseTracker & m_tracker ; <nl> + } ; <nl> <nl> - void enter ( ) { <nl> - m_sections = SectionTracker ( m_testCase ) ; <nl> + private : <nl> + void enterTestCase ( ) { <nl> + m_currentSection = & m_testCase ; <nl> + m_completedASectionThisRun = false ; <nl> m_testCase . enter ( ) ; <nl> } <nl> - void leave ( ) { <nl> + void leaveTestCase ( ) { <nl> m_testCase . leave ( ) ; <nl> } <nl> <nl> - bool enterSection ( std : : string const & name ) { <nl> - return m_sections . enterSection ( name ) ; <nl> - } <nl> - void leaveSection ( ) { <nl> - m_sections . leaveSection ( ) ; <nl> - } <nl> - <nl> - bool isCompleted ( ) const { <nl> - return m_testCase . runState ( ) = = TrackedSection : : Completed ; <nl> - } <nl> - <nl> - bool currentSectionHasChildren ( ) const { <nl> - return m_sections . currentSectinHasChildren ( ) ; <nl> - } <nl> - <nl> - private : <nl> TrackedSection m_testCase ; <nl> - SectionTracker m_sections ; <nl> + TrackedSection * m_currentSection ; <nl> + bool m_completedASectionThisRun ; <nl> } ; <nl> <nl> } / / namespace SectionTracking <nl> mmm a / projects / SelfTest / SectionTrackerTests . cpp <nl> ppp b / projects / SelfTest / SectionTrackerTests . cpp <nl> TEST_CASE ( " section tracking " ) { <nl> <nl> SECTION ( " test case with no sections " ) { <nl> <nl> - testCaseTracker . enter ( ) ; <nl> - CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> - <nl> - testCaseTracker . leave ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> + CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> + } <nl> CHECK ( testCaseTracker . isCompleted ( ) ) ; <nl> } <nl> <nl> SECTION ( " test case with one section " ) { <nl> <nl> - / / Enter test case <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> - CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> + / / Enter section ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> - / / Leave test case - incomplete ( still need to visit section ) <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - incomplete ( still need to visit section ) <nl> + } <nl> CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> / / . . . <nl> <nl> / / Enter test case again <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section ? - yes <nl> - CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section ? - yes <nl> + CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Leave section and test case - now complete <nl> - testCaseTracker . leaveSection ( ) ; <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave section and test case - now complete <nl> + testCaseTracker . leaveSection ( ) ; <nl> + } <nl> CHECK ( testCaseTracker . isCompleted ( ) ) ; <nl> } <nl> <nl> SECTION ( " test case with two consecutive sections " ) { <nl> <nl> / / Enter test case <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section 1 ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Enter section 2 ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> + / / Enter section 2 ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> <nl> - / / Leave test case - incomplete ( still need to visit sections ) <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - incomplete ( still need to visit sections ) <nl> + } <nl> CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> / / . . . <nl> <nl> / / Enter test case again <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - yes <nl> - CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> - testCaseTracker . leaveSection ( ) ; <nl> + / / Enter section 1 ? - yes <nl> + CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + testCaseTracker . leaveSection ( ) ; <nl> <nl> - / / Enter section 2 ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> + / / Enter section 2 ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> <nl> - / / Leave test case - incomplete ( still need to visit section 2 ) <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - incomplete ( still need to visit section 2 ) <nl> + } <nl> CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> / / . . . <nl> <nl> / / Enter test case again <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - no , already done now <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section 1 ? - no , already done now <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Enter section 2 ? - yes - finally <nl> - CHECK ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> - testCaseTracker . leaveSection ( ) ; <nl> + / / Enter section 2 ? - yes - finally <nl> + CHECK ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> + testCaseTracker . leaveSection ( ) ; <nl> <nl> - / / Leave test case - now complete <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - now complete <nl> + } <nl> CHECK ( testCaseTracker . isCompleted ( ) ) ; <nl> } <nl> <nl> SECTION ( " test case with one section within another " ) { <nl> <nl> / / Enter test case <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section 1 ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Leave test case - incomplete ( still need to visit sections ) <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - incomplete ( still need to visit sections ) <nl> + } <nl> CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> / / . . . <nl> <nl> / / Enter test case again <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - yes <nl> - CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section 1 ? - yes <nl> + CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Enter section 2 ? - no , not yet <nl> - CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> + / / Enter section 2 ? - no , not yet <nl> + CHECK_FALSE ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> <nl> - testCaseTracker . leaveSection ( ) ; / / section 1 - incomplete ( section 2 ) <nl> + testCaseTracker . leaveSection ( ) ; / / section 1 - incomplete ( section 2 ) <nl> <nl> - / / Leave test case - incomplete <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - incomplete <nl> + } <nl> CHECK_FALSE ( testCaseTracker . isCompleted ( ) ) ; <nl> <nl> / / . . . <nl> <nl> / / Enter test case again <nl> - testCaseTracker . enter ( ) ; <nl> + { <nl> + TestCaseTracker : : Guard guard ( testCaseTracker ) ; <nl> <nl> - / / Enter section 1 ? - yes - so we can execute section 2 <nl> - CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> + / / Enter section 1 ? - yes - so we can execute section 2 <nl> + CHECK ( testCaseTracker . enterSection ( section1Name ) ) ; <nl> <nl> - / / Enter section 2 ? - yes - finally <nl> - CHECK ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> - testCaseTracker . leaveSection ( ) ; / / section 2 <nl> - testCaseTracker . leaveSection ( ) ; / / section 1 <nl> + / / Enter section 2 ? - yes - finally <nl> + CHECK ( testCaseTracker . enterSection ( section2Name ) ) ; <nl> + testCaseTracker . leaveSection ( ) ; / / section 2 <nl> + testCaseTracker . leaveSection ( ) ; / / section 1 <nl> <nl> - / / Leave test case - now complete <nl> - testCaseTracker . leave ( ) ; <nl> + / / Leave test case - now complete <nl> + } <nl> CHECK ( testCaseTracker . isCompleted ( ) ) ; <nl> } <nl> } <nl>
Merged TestCaseTracker and SectionTracker and introduced TestCaseTracker : : Guard
catchorg/Catch2
28d3881ff984488f3e85fc6d7834f1bae299aaef
2013-07-25T07:07:55Z
mmm a / . clang - tidy <nl> ppp b / . clang - tidy <nl> Checks : ' <nl> , - cert - err58 - cpp <nl> , - modernize - make - unique <nl> , - cppcoreguidelines - owning - memory <nl> + , - readability - named - parameter <nl> ' <nl> WarningsAsErrors : ' ' <nl> HeaderFilterRegex : ' torch / csrc / ' <nl> new file mode 100644 <nl> index 000000000000 . . 7988c876603a <nl> mmm / dev / null <nl> ppp b / test / cpp / api / any . cpp <nl> <nl> + # include < catch . hpp > <nl> + <nl> + # include < torch / torch . h > <nl> + <nl> + # include < torch / nn / modules / any . h > <nl> + <nl> + # include < algorithm > <nl> + # include < string > <nl> + <nl> + using namespace torch ; <nl> + using namespace torch : : nn ; <nl> + using namespace torch : : detail ; <nl> + <nl> + using Catch : : Contains ; <nl> + using Catch : : StartsWith ; <nl> + <nl> + TEST_CASE ( " any - module " ) { <nl> + SECTION ( " int ( ) " ) { <nl> + struct M : nn : : Module { <nl> + int forward ( ) { <nl> + return 123 ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE ( any . forward ( ) . get < int > ( ) = = 123 ) ; <nl> + } <nl> + SECTION ( " int ( int ) " ) { <nl> + struct M : nn : : Module { <nl> + int forward ( int x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE ( any . forward ( 5 ) . get < int > ( ) = = 5 ) ; <nl> + } <nl> + SECTION ( " const char * ( const char * ) " ) { <nl> + struct M : nn : : Module { <nl> + const char * forward ( const char * x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE ( any . forward ( " hello " ) . get < const char * > ( ) = = std : : string ( " hello " ) ) ; <nl> + } <nl> + <nl> + SECTION ( " string ( int , const double ) " ) { <nl> + struct M : nn : : Module { <nl> + std : : string forward ( int x , const double f ) { <nl> + return std : : to_string ( static_cast < int > ( x + f ) ) ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + int x = 4 ; <nl> + REQUIRE ( any . forward ( x , 3 . 14 ) . get < std : : string > ( ) = = std : : string ( " 7 " ) ) ; <nl> + } <nl> + <nl> + SECTION ( " Variable ( string , const string & , string & & ) " ) { <nl> + struct M : nn : : Module { <nl> + autograd : : Variable forward ( <nl> + std : : string a , <nl> + const std : : string & b , <nl> + std : : string & & c ) { <nl> + const auto s = a + b + c ; <nl> + return autograd : : make_variable ( <nl> + at : : ones ( at : : CPU ( at : : kFloat ) , { static_cast < int64_t > ( s . size ( ) ) } ) ) ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE ( <nl> + any . forward ( std : : string ( " a " ) , std : : string ( " ab " ) , std : : string ( " abc " ) ) <nl> + . get < autograd : : Variable > ( ) <nl> + . sum ( ) <nl> + . toCInt ( ) = = 6 ) ; <nl> + } <nl> + SECTION ( " wrong argument type " ) { <nl> + struct M : nn : : Module { <nl> + int forward ( float x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . forward ( 5 . 0 ) , <nl> + StartsWith ( " Expected argument # 0 to be of type float , " <nl> + " but received value of type double " ) ) ; <nl> + } <nl> + SECTION ( " wrong number of arguments " ) { <nl> + struct M : nn : : Module { <nl> + int forward ( int a , int b ) { <nl> + return a + b ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { } ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . forward ( ) , <nl> + Contains ( " M ' s forward ( ) method expects 2 arguments , but received 0 " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . forward ( 5 ) , <nl> + Contains ( " M ' s forward ( ) method expects 2 arguments , but received 1 " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . forward ( 1 , 2 , 3 ) , <nl> + Contains ( " M ' s forward ( ) method expects 2 arguments , but received 3 " ) ) ; <nl> + } <nl> + SECTION ( " get ( ) " ) { <nl> + struct M : nn : : Module { <nl> + explicit M ( int value_ ) : nn : : Module ( " M " ) , value ( value_ ) { } <nl> + int value ; <nl> + int forward ( float x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { 5 } ) ; <nl> + <nl> + SECTION ( " good cast " ) { <nl> + REQUIRE ( any . get < M > ( ) . value = = 5 ) ; <nl> + } <nl> + <nl> + SECTION ( " bad cast " ) { <nl> + struct N : nn : : Module { } ; <nl> + REQUIRE_THROWS_WITH ( any . get < N > ( ) , StartsWith ( " Attempted to cast module " ) ) ; <nl> + } <nl> + } <nl> + SECTION ( " ptr ( ) " ) { <nl> + struct M : nn : : Module { <nl> + explicit M ( int value_ ) : nn : : Module ( " M " ) , value ( value_ ) { } <nl> + int value ; <nl> + int forward ( float x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ( M { 5 } ) ; <nl> + <nl> + SECTION ( " base class cast " ) { <nl> + auto ptr = any . ptr ( ) ; <nl> + REQUIRE ( ptr ! = nullptr ) ; <nl> + REQUIRE ( ptr - > name ( ) = = " M " ) ; <nl> + } <nl> + <nl> + SECTION ( " good downcast " ) { <nl> + auto ptr = any . ptr < M > ( ) ; <nl> + REQUIRE ( ptr ! = nullptr ) ; <nl> + REQUIRE ( ptr - > value = = 5 ) ; <nl> + } <nl> + <nl> + SECTION ( " bad downcast " ) { <nl> + struct N : nn : : Module { } ; <nl> + REQUIRE_THROWS_WITH ( any . ptr < N > ( ) , StartsWith ( " Attempted to cast module " ) ) ; <nl> + } <nl> + } <nl> + SECTION ( " default state is empty " ) { <nl> + struct M : nn : : Module { <nl> + explicit M ( int value_ ) : value ( value_ ) { } <nl> + int value ; <nl> + int forward ( float x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ; <nl> + REQUIRE ( any . is_empty ( ) ) ; <nl> + any = std : : make_shared < M > ( 5 ) ; <nl> + REQUIRE ( ! any . is_empty ( ) ) ; <nl> + REQUIRE ( any . get < M > ( ) . value = = 5 ) ; <nl> + } <nl> + SECTION ( " all methods throw for empty AnyModule " ) { <nl> + struct M : nn : : Module { <nl> + int forward ( int x ) { <nl> + return x ; <nl> + } <nl> + } ; <nl> + AnyModule any ; <nl> + REQUIRE ( any . is_empty ( ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . get < M > ( ) , StartsWith ( " Cannot call get ( ) on an empty AnyModule " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . ptr < M > ( ) , StartsWith ( " Cannot call ptr ( ) on an empty AnyModule " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . ptr ( ) , StartsWith ( " Cannot call ptr ( ) on an empty AnyModule " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . type_info ( ) , <nl> + StartsWith ( " Cannot call type_info ( ) on an empty AnyModule " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + any . forward < int > ( 5 ) , <nl> + StartsWith ( " Cannot call forward ( ) on an empty AnyModule " ) ) ; <nl> + } <nl> + SECTION ( " can move assign differentm modules " ) { <nl> + struct M : nn : : Module { <nl> + std : : string forward ( int x ) { <nl> + return std : : to_string ( x ) ; <nl> + } <nl> + } ; <nl> + struct N : nn : : Module { <nl> + int forward ( float x ) { <nl> + return 3 + x ; <nl> + } <nl> + } ; <nl> + AnyModule any ; <nl> + REQUIRE ( any . is_empty ( ) ) ; <nl> + any = std : : make_shared < M > ( ) ; <nl> + REQUIRE ( ! any . is_empty ( ) ) ; <nl> + REQUIRE ( any . forward ( 5 ) . get < std : : string > ( ) = = " 5 " ) ; <nl> + any = std : : make_shared < N > ( ) ; <nl> + REQUIRE ( ! any . is_empty ( ) ) ; <nl> + REQUIRE ( any . forward ( 5 . 0f ) . get < int > ( ) = = 8 ) ; <nl> + } <nl> + SECTION ( " has reference semantics " ) { <nl> + Sequential first ( <nl> + Linear ( 2 , 3 ) . build ( ) , Linear ( 4 , 4 ) . build ( ) , Linear ( 4 , 5 ) . build ( ) ) ; <nl> + Sequential second ( first ) ; <nl> + <nl> + REQUIRE ( first . size ( ) = = second . size ( ) ) ; <nl> + REQUIRE ( std : : equal ( first . begin ( ) , first . end ( ) , second . begin ( ) ) ) ; <nl> + } <nl> + } <nl> + <nl> + namespace torch { <nl> + namespace nn { <nl> + struct TestValue { <nl> + template < typename T > <nl> + explicit TestValue ( T & & value ) : value_ ( std : : forward < T > ( value ) ) { } <nl> + AnyModule : : Value operator ( ) ( ) { <nl> + return std : : move ( value_ ) ; <nl> + } <nl> + AnyModule : : Value value_ ; <nl> + } ; <nl> + template < typename T > <nl> + AnyModule : : Value make_value ( T & & value ) { <nl> + return TestValue ( std : : forward < T > ( value ) ) ( ) ; <nl> + } <nl> + } / / namespace nn <nl> + } / / namespace torch <nl> + <nl> + TEST_CASE ( " any - value " ) { <nl> + SECTION ( " gets the correct value for the right type " ) { <nl> + SECTION ( " int " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + / / const and non - const types have the same typeid ( ) <nl> + REQUIRE ( value . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . try_get < const int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . get < int > ( ) = = 5 ) ; <nl> + } <nl> + SECTION ( " const int " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + REQUIRE ( value . try_get < const int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . get < const int > ( ) = = 5 ) ; <nl> + } <nl> + SECTION ( " const char * " ) { <nl> + auto value = make_value ( " hello " ) ; <nl> + REQUIRE ( value . try_get < const char * > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . get < const char * > ( ) = = std : : string ( " hello " ) ) ; <nl> + } <nl> + SECTION ( " std : : string " ) { <nl> + auto value = make_value ( std : : string ( " hello " ) ) ; <nl> + REQUIRE ( value . try_get < std : : string > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . get < std : : string > ( ) = = " hello " ) ; <nl> + } <nl> + SECTION ( " pointers " ) { <nl> + std : : string s ( " hello " ) ; <nl> + std : : string * p = & s ; <nl> + auto value = make_value ( p ) ; <nl> + REQUIRE ( value . try_get < std : : string * > ( ) ! = nullptr ) ; <nl> + REQUIRE ( * value . get < std : : string * > ( ) = = " hello " ) ; <nl> + } <nl> + SECTION ( " references " ) { <nl> + std : : string s ( " hello " ) ; <nl> + const std : : string & t = s ; <nl> + auto value = make_value ( t ) ; <nl> + REQUIRE ( value . try_get < std : : string > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . get < std : : string > ( ) = = " hello " ) ; <nl> + } <nl> + } <nl> + SECTION ( " try_get returns nullptr for the wrong type " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + REQUIRE ( value . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( value . try_get < float > ( ) = = nullptr ) ; <nl> + REQUIRE ( value . try_get < long > ( ) = = nullptr ) ; <nl> + REQUIRE ( value . try_get < std : : string > ( ) = = nullptr ) ; <nl> + } <nl> + SECTION ( " get throws for the wrong type " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + REQUIRE ( value . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + value . get < float > ( ) , <nl> + StartsWith ( " Attempted to cast Value to float , " <nl> + " but its actual type is int " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + value . get < long > ( ) , <nl> + StartsWith ( " Attempted to cast Value to long , " <nl> + " but its actual type is int " ) ) ; <nl> + } <nl> + SECTION ( " move is allowed " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + SECTION ( " construction " ) { <nl> + auto copy = make_value ( std : : move ( value ) ) ; <nl> + REQUIRE ( copy . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( copy . get < int > ( ) = = 5 ) ; <nl> + } <nl> + SECTION ( " assignment " ) { <nl> + auto copy = make_value ( 10 ) ; <nl> + copy = std : : move ( value ) ; <nl> + REQUIRE ( copy . try_get < int > ( ) ! = nullptr ) ; <nl> + REQUIRE ( copy . get < int > ( ) = = 5 ) ; <nl> + } <nl> + } <nl> + SECTION ( " type_info is correct " ) { <nl> + SECTION ( " int " ) { <nl> + auto value = make_value ( 5 ) ; <nl> + REQUIRE ( value . type_info ( ) . hash_code ( ) = = typeid ( int ) . hash_code ( ) ) ; <nl> + } <nl> + SECTION ( " const char " ) { <nl> + auto value = make_value ( " hello " ) ; <nl> + REQUIRE ( value . type_info ( ) . hash_code ( ) = = typeid ( const char * ) . hash_code ( ) ) ; <nl> + } <nl> + SECTION ( " std : : string " ) { <nl> + auto value = make_value ( std : : string ( " hello " ) ) ; <nl> + REQUIRE ( value . type_info ( ) . hash_code ( ) = = typeid ( std : : string ) . hash_code ( ) ) ; <nl> + } <nl> + } <nl> + } <nl> mmm a / test / cpp / api / container . cpp <nl> ppp b / test / cpp / api / container . cpp <nl> <nl> <nl> # include < torch / torch . h > <nl> <nl> + # include < test / cpp / api / util . h > <nl> + <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> class TestModel : public Module { <nl> l3 = register_module ( " l3 " , Linear ( 5 , 100 ) . build ( ) ) ; <nl> } <nl> <nl> - variable_list forward ( variable_list input ) override { <nl> + variable_list forward ( variable_list input ) { <nl> return input ; <nl> } <nl> <nl> class NestedModel : public Module { <nl> register_parameter ( " param " , at : : CPU ( at : : kFloat ) . tensor ( { 3 , 2 , 21 } ) ) ; <nl> } <nl> <nl> - variable_list forward ( variable_list input ) override { <nl> + variable_list forward ( variable_list input ) { <nl> return input ; <nl> } ; <nl> <nl> TEST_CASE ( " containers " ) { <nl> <nl> REQUIRE ( model - > parameters ( ) . at ( " weight " ) . grad ( ) . numel ( ) = = 2 * 5 ) ; <nl> } <nl> + } <nl> <nl> - SECTION ( " sequential " ) { <nl> - auto model = std : : make_shared < ContainerList > ( ) ; <nl> - model - > append ( Linear ( 10 , 3 ) . build ( ) ) ; <nl> - model - > append ( Linear ( 3 , 5 ) . build ( ) ) ; <nl> - model - > append ( Linear ( 5 , 100 ) . build ( ) ) ; <nl> - <nl> - auto x = Var ( at : : CPU ( at : : kFloat ) . randn ( { 1000 , 10 } ) ) ; <nl> - for ( auto layer : * model ) { <nl> - x = layer - > forward ( { x } ) [ 0 ] ; <nl> - x = x . clamp_min ( 0 ) ; / / relu <nl> - } <nl> - <nl> - backward ( x ) ; <nl> - REQUIRE ( x . ndimension ( ) = = 2 ) ; <nl> - REQUIRE ( x . size ( 0 ) = = 1000 ) ; <nl> - REQUIRE ( x . size ( 1 ) = = 100 ) ; <nl> - REQUIRE ( x . data ( ) . min ( ) . toCFloat ( ) = = 0 ) ; <nl> - } <nl> - <nl> - SECTION ( " simple " ) { <nl> - auto model = std : : make_shared < Sequential > ( ) ; <nl> - auto l1 = model - > add ( Linear ( 10 , 3 ) . build ( ) , " l1 " ) ; <nl> - auto l2 = model - > add ( Linear ( 3 , 5 ) . build ( ) , " l2 " ) ; <nl> - auto l3 = model - > add ( Linear ( 5 , 100 ) . build ( ) , " l3 " ) ; <nl> - <nl> - auto x = Var ( at : : CPU ( at : : kFloat ) . randn ( { 1000 , 10 } ) ) ; <nl> - x = l1 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> - x = l2 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> - x = l3 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> - <nl> - backward ( x ) ; <nl> - REQUIRE ( x . ndimension ( ) = = 2 ) ; <nl> - REQUIRE ( x . size ( 0 ) = = 1000 ) ; <nl> - REQUIRE ( x . size ( 1 ) = = 100 ) ; <nl> - REQUIRE ( x . data ( ) . min ( ) . toCFloat ( ) = = 0 ) ; <nl> - } <nl> + SECTION ( " simple " ) { <nl> + auto model = std : : make_shared < SimpleContainer > ( ) ; <nl> + auto l1 = model - > add ( Linear ( 10 , 3 ) . build ( ) , " l1 " ) ; <nl> + auto l2 = model - > add ( Linear ( 3 , 5 ) . build ( ) , " l2 " ) ; <nl> + auto l3 = model - > add ( Linear ( 5 , 100 ) . build ( ) , " l3 " ) ; <nl> + <nl> + auto x = Var ( at : : CPU ( at : : kFloat ) . randn ( { 1000 , 10 } ) ) ; <nl> + x = l1 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> + x = l2 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> + x = l3 - > forward ( { x } ) [ 0 ] . clamp_min ( 0 ) ; <nl> + <nl> + backward ( x ) ; <nl> + REQUIRE ( x . ndimension ( ) = = 2 ) ; <nl> + REQUIRE ( x . size ( 0 ) = = 1000 ) ; <nl> + REQUIRE ( x . size ( 1 ) = = 100 ) ; <nl> + REQUIRE ( x . data ( ) . min ( ) . toCFloat ( ) = = 0 ) ; <nl> } <nl> <nl> SECTION ( " embedding " ) { <nl> mmm a / test / cpp / api / integration . cpp <nl> ppp b / test / cpp / api / integration . cpp <nl> <nl> <nl> # include < ATen / Error . h > <nl> <nl> + # include < test / cpp / api / util . h > <nl> + <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> # include < iostream > <nl> + # include < random > <nl> <nl> class CartPole { <nl> / / Translated from openai / gym ' s cartpole . py <nl> bool test_mnist ( <nl> FILE * fp_ ; <nl> <nl> explicit MNIST_Reader ( const char * path ) { <nl> - fp_ = fopen ( path , " rb " ) ; <nl> + fp_ = fopen ( path , " rbe " ) ; <nl> if ( ! fp_ ) <nl> throw std : : runtime_error ( " failed to open file " ) ; <nl> } <nl> bool test_mnist ( <nl> auto a_data = data . accessor < int64_t , 1 > ( ) ; <nl> <nl> for ( int i = 0 ; i < label_count ; + + i ) { <nl> - a_data [ i ] = long ( rd . read_byte ( ) ) ; <nl> + a_data [ i ] = static_cast < int64_t > ( rd . read_byte ( ) ) ; <nl> } <nl> return data . toBackend ( useGPU ? at : : kCUDA : at : : kCPU ) ; <nl> } ; <nl> bool test_mnist ( <nl> model - > cuda ( ) ; <nl> } <nl> <nl> + std : : random_device device ; <nl> + std : : mt19937 generator ( device ( ) ) ; <nl> + <nl> for ( auto epoch = 0U ; epoch < num_epochs ; epoch + + ) { <nl> auto shuffled_inds = std : : vector < int > ( trdata . size ( 0 ) ) ; <nl> for ( int i = 0 ; i < trdata . size ( 0 ) ; i + + ) { <nl> shuffled_inds [ i ] = i ; <nl> } <nl> - std : : random_shuffle ( shuffled_inds . begin ( ) , shuffled_inds . end ( ) ) ; <nl> + std : : shuffle ( shuffled_inds . begin ( ) , shuffled_inds . end ( ) , generator ) ; <nl> <nl> auto inp = ( useGPU ? at : : CUDA : at : : CPU ) ( at : : kFloat ) <nl> . tensor ( { batch_size , 1 , trdata . size ( 2 ) , trdata . size ( 3 ) } ) ; <nl> bool test_mnist ( <nl> no_grad_guard guard ; <nl> auto result = std : : get < 1 > ( forward_op ( Var ( tedata , false ) ) . max ( 1 ) ) ; <nl> Variable correct = ( result = = Var ( telabel ) ) . toType ( at : : kFloat ) ; <nl> - std : : cout < < " Num correct : " < < correct . data ( ) . sum ( ) . toCFloat ( ) < < " out of " <nl> + std : : cout < < " Num correct : " < < correct . data ( ) . sum ( ) . toCFloat ( ) < < " out of " <nl> < < telabel . size ( 0 ) < < std : : endl ; <nl> return correct . data ( ) . sum ( ) . toCFloat ( ) > telabel . size ( 0 ) * 0 . 8 ; <nl> } ; <nl> TEST_CASE ( " integration " ) { <nl> std : : cerr <nl> < < " Training episodic policy gradient with a critic for up to 3000 " <nl> " episodes , rest your eyes for a bit ! \ n " ; <nl> - auto model = std : : make_shared < Sequential > ( ) ; <nl> + auto model = std : : make_shared < SimpleContainer > ( ) ; <nl> auto linear = model - > add ( Linear ( 4 , 128 ) . build ( ) , " linear " ) ; <nl> auto policyHead = model - > add ( Linear ( 128 , 2 ) . build ( ) , " policy " ) ; <nl> auto valueHead = model - > add ( Linear ( 128 , 1 ) . build ( ) , " action " ) ; <nl> TEST_CASE ( " integration " ) { <nl> / / This should probably be actually implemented in autogradpp . . . <nl> auto p = probs / probs . sum ( - 1 , true ) ; <nl> auto log_prob = p [ action ] . log ( ) ; <nl> - saved_log_probs . push_back ( log_prob ) ; <nl> + saved_log_probs . emplace_back ( log_prob ) ; <nl> saved_values . push_back ( value ) ; <nl> return action ; <nl> } ; <nl> TEST_CASE ( " integration " ) { <nl> } <nl> <nl> TEST_CASE ( " integration / mnist " , " [ cuda ] " ) { <nl> - auto model = std : : make_shared < Sequential > ( ) ; <nl> + auto model = std : : make_shared < SimpleContainer > ( ) ; <nl> auto conv1 = model - > add ( Conv2d ( 1 , 10 , 5 ) . build ( ) , " conv1 " ) ; <nl> auto conv2 = model - > add ( Conv2d ( 10 , 20 , 5 ) . build ( ) , " conv2 " ) ; <nl> auto drop = Dropout ( 0 . 3 ) . build ( ) ; <nl> TEST_CASE ( " integration / mnist " , " [ cuda ] " ) { <nl> } <nl> <nl> TEST_CASE ( " integration / mnist / batchnorm " , " [ cuda ] " ) { <nl> - auto model = std : : make_shared < Sequential > ( ) ; <nl> + auto model = std : : make_shared < SimpleContainer > ( ) ; <nl> auto conv1 = model - > add ( Conv2d ( 1 , 10 , 5 ) . build ( ) , " conv1 " ) ; <nl> auto batchnorm2d = <nl> model - > add ( BatchNorm ( 10 ) . stateful ( true ) . build ( ) , " batchnorm2d " ) ; <nl> mmm a / test / cpp / api / main . cpp <nl> ppp b / test / cpp / api / main . cpp <nl> int main ( int argc , char * argv [ ] ) { <nl> if ( ! torch : : hasCuda ( ) ) { <nl> std : : cerr < < " CUDA not available . Disabling CUDA tests " < < std : : endl ; <nl> / / ~ disables the [ cuda ] tag . <nl> - session . configData ( ) . testsOrTags . push_back ( " ~ [ cuda ] " ) ; <nl> + session . configData ( ) . testsOrTags . emplace_back ( " ~ [ cuda ] " ) ; <nl> } <nl> <nl> return session . run ( ) ; <nl> mmm a / test / cpp / api / misc . cpp <nl> ppp b / test / cpp / api / misc . cpp <nl> <nl> # include < torch / expanding_array . h > <nl> # include < torch / torch . h > <nl> <nl> + # include < torch / csrc / utils / memory . h > <nl> + <nl> + # include < ATen / optional . h > <nl> + <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> TEST_CASE ( " expanding - array " ) { <nl> } <nl> } <nl> } <nl> + <nl> + TEST_CASE ( " make_unique " ) { <nl> + struct Test { <nl> + explicit Test ( const int & x ) : lvalue_ ( x ) { } <nl> + explicit Test ( int & & x ) : rvalue_ ( x ) { } <nl> + <nl> + at : : optional < int > lvalue_ ; <nl> + at : : optional < int > rvalue_ ; <nl> + } ; <nl> + <nl> + SECTION ( " forwards rvalues correctly " ) { <nl> + auto ptr = torch : : make_unique < Test > ( 123 ) ; <nl> + REQUIRE ( ! ptr - > lvalue_ . has_value ( ) ) ; <nl> + REQUIRE ( ptr - > rvalue_ . has_value ( ) ) ; <nl> + REQUIRE ( * ptr - > rvalue_ = = 123 ) ; <nl> + } <nl> + <nl> + SECTION ( " forwards lvalues correctly " ) { <nl> + int x = 5 ; <nl> + auto ptr = torch : : make_unique < Test > ( x ) ; <nl> + REQUIRE ( ptr - > lvalue_ . has_value ( ) ) ; <nl> + REQUIRE ( * ptr - > lvalue_ = = 5 ) ; <nl> + REQUIRE ( ! ptr - > rvalue_ . has_value ( ) ) ; <nl> + } <nl> + <nl> + SECTION ( " Can construct unique_ptr of array " ) { <nl> + auto ptr = torch : : make_unique < int [ ] > ( 3 ) ; <nl> + / / Value initialization is required by the standard . <nl> + REQUIRE ( ptr [ 0 ] = = 0 ) ; <nl> + REQUIRE ( ptr [ 1 ] = = 0 ) ; <nl> + REQUIRE ( ptr [ 2 ] = = 0 ) ; <nl> + } <nl> + } <nl> mmm a / test / cpp / api / module . cpp <nl> ppp b / test / cpp / api / module . cpp <nl> <nl> <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> + <nl> using Catch : : StartsWith ; <nl> <nl> - struct AGIUnit : nn : : Module { <nl> - variable_list forward ( variable_list ) { <nl> - return { } ; <nl> - } <nl> - } ; <nl> + struct AGIUnit : nn : : Module { } ; <nl> <nl> namespace test { <nl> - struct AGIUnit : nn : : Module { <nl> - variable_list forward ( variable_list ) { <nl> - return { } ; <nl> - } <nl> - } ; <nl> + struct AGIUnit : nn : : Module { } ; <nl> struct AGIUnit2 : nn : : Module { <nl> AGIUnit2 ( ) : nn : : Module ( " Foo " ) { } <nl> - variable_list forward ( variable_list ) { <nl> - return { } ; <nl> - } <nl> } ; <nl> } / / namespace test <nl> <nl> struct TestModule : public CloneableModule < TestModule > { <nl> register_parameter ( " weight " , at : : ones ( at : : CPU ( at : : kFloat ) , { 4 , 4 } ) ) ; <nl> } <nl> <nl> - variable_list forward ( variable_list input ) override { <nl> - return input ; <nl> - } <nl> - <nl> Variable weight ; <nl> int value = 0 ; <nl> } ; <nl> TEST_CASE ( " module / clone " ) { <nl> SECTION ( <nl> " a module that does not override clone ( ) throws when clone ( ) is called " ) { <nl> struct UnCloneable : Module { <nl> - variable_list forward ( variable_list ) override { <nl> + variable_list forward ( variable_list ) { <nl> return { } ; <nl> } <nl> } ; <nl> TEST_CASE ( " module / clone " ) { <nl> SECTION ( <nl> " a module that overrides clone ( ) does not throw when clone ( ) is called " ) { <nl> struct Cloneable : Module { <nl> - variable_list forward ( variable_list ) override { <nl> + variable_list forward ( variable_list ) { <nl> return { } ; <nl> } <nl> std : : shared_ptr < Module > clone ( ) const override { <nl> TEST_CASE ( " module / clone " ) { <nl> l3 = register_module ( " l3 " , Linear ( 5 , 100 ) . build ( ) ) ; <nl> } <nl> <nl> - variable_list forward ( variable_list input ) override { <nl> - return input ; <nl> - } <nl> - <nl> std : : shared_ptr < Linear > l1 , l2 , l3 ; <nl> } ; <nl> <nl> TEST_CASE ( " module / clone " ) { <nl> void reset ( ) override { <nl> module = register_module ( " module " , TestModule ( ) . build ( ) ) ; <nl> } <nl> - variable_list forward ( variable_list inputs ) override { <nl> - return inputs ; <nl> - } <nl> std : : shared_ptr < TestModule > module ; <nl> } ; <nl> <nl> TEST_CASE ( " module / parameters " ) { <nl> c = register_parameter ( " c " , at : : ones ( at : : CPU ( at : : kFloat ) , { 2 , 2 } ) * 2 ) ; <nl> } <nl> <nl> - variable_list forward ( variable_list ) override { <nl> - return { } ; <nl> - } <nl> - <nl> Variable a , b , c ; <nl> } ; <nl> <nl> mmm a / test / cpp / api / optim . cpp <nl> ppp b / test / cpp / api / optim . cpp <nl> <nl> # include < catch . hpp > <nl> <nl> - # include < torch / torch . h > <nl> + # include < torch / nn / module . h > <nl> + # include < torch / nn / modules / linear . h > <nl> + # include < torch / nn / modules / sequential . h > <nl> + # include < torch / optimizers . h > <nl> + <nl> + # include < test / cpp / api / util . h > <nl> <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> - bool test_optimizer_xor ( Optimizer optim , std : : shared_ptr < ContainerList > model ) { <nl> + bool test_optimizer_xor ( Optimizer optim , std : : shared_ptr < Sequential > model ) { <nl> float running_loss = 1 ; <nl> int epoch = 0 ; <nl> while ( running_loss > 0 . 1 ) { <nl> bool test_optimizer_xor ( Optimizer optim , std : : shared_ptr < ContainerList > model ) { <nl> lab [ i ] = c ; <nl> } <nl> / / forward <nl> - auto input = Var ( inp ) ; <nl> - auto target = Var ( lab , false ) ; <nl> - <nl> + auto y = Var ( lab , false ) ; <nl> std : : function < at : : Scalar ( ) > closure = [ & ] ( ) - > at : : Scalar { <nl> optim - > zero_grad ( ) ; <nl> - auto x = input ; <nl> - for ( auto & layer : * model ) <nl> - x = layer - > forward ( { x } ) [ 0 ] . sigmoid_ ( ) ; <nl> - Variable loss = at : : binary_cross_entropy ( x , target ) ; <nl> + auto x = model - > forward < Variable > ( Var ( inp ) ) ; <nl> + Variable loss = at : : binary_cross_entropy ( x , y ) ; <nl> backward ( loss ) ; <nl> return at : : Scalar ( loss . data ( ) ) ; <nl> } ; <nl> bool test_optimizer_xor ( Optimizer optim , std : : shared_ptr < ContainerList > model ) { <nl> TEST_CASE ( " optim " ) { <nl> std : : srand ( 0 ) ; <nl> setSeed ( 0 ) ; <nl> - auto model = std : : make_shared < ContainerList > ( ) ; <nl> - model - > append ( Linear ( 2 , 8 ) . build ( ) ) ; <nl> - model - > append ( Linear ( 8 , 1 ) . build ( ) ) ; <nl> + auto model = std : : make_shared < Sequential > ( <nl> + SigmoidLinear ( Linear ( 2 , 8 ) . build ( ) ) , SigmoidLinear ( Linear ( 8 , 1 ) . build ( ) ) ) ; <nl> <nl> - SECTION ( " lbfgs " ) { <nl> - auto optim = LBFGS ( model , 5e - 2 ) . max_iter ( 5 ) . make ( ) ; <nl> - REQUIRE ( test_optimizer_xor ( optim , model ) ) ; <nl> - } <nl> + / / FLAKY ! <nl> + / / SECTION ( " lbfgs " ) { <nl> + / / auto optim = LBFGS ( model , 5e - 2 ) . max_iter ( 5 ) . make ( ) ; <nl> + / / REQUIRE ( test_optimizer_xor ( optim , model ) ) ; <nl> + / / } <nl> <nl> SECTION ( " sgd " ) { <nl> auto optim = <nl> mmm a / test / cpp / api / rnn . cpp <nl> ppp b / test / cpp / api / rnn . cpp <nl> <nl> <nl> # include < torch / torch . h > <nl> <nl> + # include < test / cpp / api / util . h > <nl> + <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> template < typename R , typename Func > <nl> bool test_RNN_xor ( Func & & model_maker , bool cuda = false ) { <nl> auto nhid = 32 ; <nl> - auto model = std : : make_shared < Sequential > ( ) ; <nl> + auto model = std : : make_shared < SimpleContainer > ( ) ; <nl> auto l1 = model - > add ( Linear ( 1 , nhid ) . build ( ) , " l1 " ) ; <nl> auto rnn = model - > add ( model_maker ( nhid ) , " rnn " ) ; <nl> auto lo = model - > add ( Linear ( nhid , 1 ) . build ( ) , " lo " ) ; <nl> new file mode 100644 <nl> index 000000000000 . . e5b7ffd46be4 <nl> mmm / dev / null <nl> ppp b / test / cpp / api / sequential . cpp <nl> <nl> + # include < catch . hpp > <nl> + <nl> + # include < torch / nn / modules / linear . h > <nl> + # include < torch / nn / modules / sequential . h > <nl> + <nl> + # include < vector > <nl> + <nl> + using namespace torch ; <nl> + using namespace torch : : nn ; <nl> + <nl> + using Catch : : StartsWith ; <nl> + <nl> + TEST_CASE ( " sequential " ) { <nl> + SECTION ( " construction " ) { <nl> + Sequential sequential ( <nl> + Linear ( 2 , 3 ) . build ( ) , Linear ( 2 , 3 ) , Linear ( 2 , 3 ) . build ( ) ) ; <nl> + REQUIRE ( sequential . size ( ) = = 3 ) ; <nl> + } <nl> + SECTION ( " push_back " ) { <nl> + Sequential sequential ; <nl> + REQUIRE ( sequential . size ( ) = = 0 ) ; <nl> + REQUIRE ( sequential . is_empty ( ) ) ; <nl> + sequential . push_back ( Linear ( 3 , 4 ) . build ( ) ) ; <nl> + REQUIRE ( sequential . size ( ) = = 1 ) ; <nl> + sequential . push_back ( Linear ( 4 , 5 ) . build ( ) ) ; <nl> + REQUIRE ( sequential . size ( ) = = 2 ) ; <nl> + } <nl> + SECTION ( " access " ) { <nl> + std : : vector < std : : shared_ptr < Linear > > modules = { <nl> + Linear ( 2 , 3 ) . build ( ) , Linear ( 3 , 4 ) . build ( ) , Linear ( 4 , 5 ) . build ( ) } ; <nl> + <nl> + Sequential sequential ; <nl> + for ( auto & module : modules ) { <nl> + sequential . push_back ( module ) ; <nl> + } <nl> + REQUIRE ( sequential . size ( ) = = 3 ) ; <nl> + <nl> + SECTION ( " at ( ) " ) { <nl> + SECTION ( " returns the correct module for a given index " ) { <nl> + for ( size_t i = 0 ; i < modules . size ( ) ; + + i ) { <nl> + REQUIRE ( & sequential . at < Linear > ( i ) = = modules [ i ] . get ( ) ) ; <nl> + } <nl> + } <nl> + SECTION ( " throws for a bad index " ) { <nl> + REQUIRE_THROWS_WITH ( <nl> + sequential . at < Linear > ( modules . size ( ) + 1 ) , <nl> + StartsWith ( " Index out of range " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + sequential . at < Linear > ( modules . size ( ) + 1000000 ) , <nl> + StartsWith ( " Index out of range " ) ) ; <nl> + } <nl> + } <nl> + <nl> + SECTION ( " ptr ( ) " ) { <nl> + SECTION ( " returns the correct module for a given index " ) { <nl> + for ( size_t i = 0 ; i < modules . size ( ) ; + + i ) { <nl> + REQUIRE ( sequential . ptr ( i ) . get ( ) = = modules [ i ] . get ( ) ) ; <nl> + REQUIRE ( sequential [ i ] . get ( ) = = modules [ i ] . get ( ) ) ; <nl> + REQUIRE ( sequential . ptr < Linear > ( i ) . get ( ) = = modules [ i ] . get ( ) ) ; <nl> + } <nl> + } <nl> + SECTION ( " throws for a bad index " ) { <nl> + REQUIRE_THROWS_WITH ( <nl> + sequential . ptr ( modules . size ( ) + 1 ) , <nl> + StartsWith ( " Index out of range " ) ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + sequential . ptr ( modules . size ( ) + 1000000 ) , <nl> + StartsWith ( " Index out of range " ) ) ; <nl> + } <nl> + } <nl> + } <nl> + SECTION ( " forward " ) { <nl> + SECTION ( " calling forward ( ) on an empty sequential is disallowed " ) { <nl> + Sequential empty ; <nl> + REQUIRE_THROWS_WITH ( <nl> + empty . forward < int > ( ) , <nl> + StartsWith ( " Cannot call forward ( ) on an empty Sequential " ) ) ; <nl> + } <nl> + <nl> + SECTION ( " calling forward ( ) on a non - empty sequential chains correctly " ) { <nl> + struct MockModule : nn : : Module { <nl> + explicit MockModule ( int value ) : expected ( value ) { } <nl> + int expected ; <nl> + int forward ( int value ) { <nl> + REQUIRE ( value = = expected ) ; <nl> + return value + 1 ; <nl> + } <nl> + } ; <nl> + <nl> + Sequential sequential ( MockModule { 1 } , MockModule { 2 } , MockModule { 3 } ) ; <nl> + <nl> + REQUIRE ( sequential . forward < int > ( 1 ) = = 4 ) ; <nl> + } <nl> + <nl> + SECTION ( " calling forward ( ) with the wrong return type throws " ) { <nl> + struct M : public nn : : Module { <nl> + int forward ( ) { <nl> + return 5 ; <nl> + } <nl> + } ; <nl> + <nl> + Sequential sequential ( M { } ) ; <nl> + REQUIRE ( sequential . forward < int > ( ) = = 5 ) ; <nl> + REQUIRE_THROWS_WITH ( <nl> + sequential . forward < float > ( ) , <nl> + StartsWith ( " The type of the return value " <nl> + " is int , but you asked for type float " ) ) ; <nl> + } <nl> + <nl> + SECTION ( " The return type of forward ( ) defaults to Variable " ) { <nl> + struct M : public nn : : Module { <nl> + autograd : : Variable forward ( autograd : : Variable v ) { <nl> + return v ; <nl> + } <nl> + } ; <nl> + <nl> + Sequential sequential ( M { } ) ; <nl> + auto variable = <nl> + autograd : : make_variable ( at : : CPU ( at : : kFloat ) . ones ( { 3 , 3 } ) , true ) ; <nl> + REQUIRE ( sequential . forward ( variable ) . equal ( variable ) ) ; <nl> + } <nl> + } <nl> + <nl> + SECTION ( " returns the last value " ) { <nl> + Sequential sequential ( <nl> + Linear ( 10 , 3 ) . build ( ) , Linear ( 3 , 5 ) . build ( ) , Linear ( 5 , 100 ) . build ( ) ) ; <nl> + <nl> + auto x = Var ( at : : CPU ( at : : kFloat ) . randn ( { 1000 , 10 } ) ) ; <nl> + auto y = sequential . forward < variable_list > ( variable_list { x } ) . front ( ) ; <nl> + REQUIRE ( y . ndimension ( ) = = 2 ) ; <nl> + REQUIRE ( y . size ( 0 ) = = 1000 ) ; <nl> + REQUIRE ( y . size ( 1 ) = = 100 ) ; <nl> + } <nl> + } <nl> mmm a / test / cpp / api / serialization . cpp <nl> ppp b / test / cpp / api / serialization . cpp <nl> <nl> # include < catch . hpp > <nl> <nl> - # include < torch / torch . h > <nl> + # include < torch / nn / modules / linear . h > <nl> + # include < torch / nn / modules / sequential . h > <nl> + # include < torch / optimizers . h > <nl> + # include < torch / serialization . h > <nl> <nl> - # include " cereal / archives / portable_binary . hpp " <nl> + # include < test / cpp / api / util . h > <nl> + <nl> + # include < cereal / archives / portable_binary . hpp > <nl> + <nl> + # include < memory > <nl> + # include < sstream > <nl> + # include < string > <nl> + # include < vector > <nl> <nl> using namespace torch ; <nl> using namespace torch : : nn ; <nl> <nl> + namespace { <nl> + std : : shared_ptr < Sequential > xor_model ( ) { <nl> + return std : : make_shared < Sequential > ( SigmoidLinear ( 2 , 8 ) , SigmoidLinear ( 8 , 1 ) ) ; <nl> + } <nl> + } / / namespace <nl> + <nl> TEST_CASE ( " serialization " ) { <nl> SECTION ( " undefined " ) { <nl> auto x = at : : Tensor ( ) ; <nl> TEST_CASE ( " serialization " ) { <nl> REQUIRE ( x . sizes ( ) . vec ( ) = = y . sizes ( ) . vec ( ) ) ; <nl> REQUIRE ( x . allclose ( y ) ) ; <nl> } <nl> - <nl> SECTION ( " portable_binary " ) { <nl> auto x = at : : CPU ( at : : kFloat ) . randn ( { 5 , 5 } ) ; <nl> auto y = at : : Tensor ( ) ; <nl> TEST_CASE ( " serialization " ) { <nl> REQUIRE ( x . sizes ( ) . vec ( ) = = y . sizes ( ) . vec ( ) ) ; <nl> REQUIRE ( x . allclose ( y ) ) ; <nl> } <nl> - <nl> SECTION ( " sliced " ) { <nl> auto x = at : : CPU ( at : : kFloat ) . randn ( { 11 , 5 } ) ; <nl> x = x . slice ( 0 , 1 , 3 ) ; <nl> TEST_CASE ( " serialization " ) { <nl> <nl> SECTION ( " xor " ) { <nl> / / We better be able to save and load a XOR model ! <nl> - auto makeModel = [ ] ( ) { <nl> - auto list = std : : make_shared < ContainerList > ( ) ; <nl> - list - > append ( Linear ( 2 , 8 ) . build ( ) ) ; <nl> - list - > append ( Linear ( 8 , 1 ) . build ( ) ) ; <nl> - return list ; <nl> - } ; <nl> - auto getLoss = [ ] ( std : : shared_ptr < ContainerList > model , uint32_t bs ) { <nl> + auto getLoss = [ ] ( std : : shared_ptr < Sequential > model , uint32_t bs ) { <nl> auto inp = at : : CPU ( at : : kFloat ) . tensor ( { bs , 2 } ) ; <nl> auto lab = at : : CPU ( at : : kFloat ) . tensor ( { bs } ) ; <nl> for ( auto i = 0U ; i < bs ; i + + ) { <nl> TEST_CASE ( " serialization " ) { <nl> } <nl> <nl> / / forward <nl> - auto x = Var ( inp ) ; <nl> + auto x = model - > forward < Variable > ( Var ( inp ) ) ; <nl> auto y = Var ( lab , false ) ; <nl> - for ( auto layer : * model ) <nl> - x = layer - > forward ( { x } ) [ 0 ] . sigmoid_ ( ) ; <nl> return at : : binary_cross_entropy ( x , y ) ; <nl> } ; <nl> <nl> - auto model = makeModel ( ) ; <nl> - auto model2 = makeModel ( ) ; <nl> - auto model3 = makeModel ( ) ; <nl> + auto model = xor_model ( ) ; <nl> + auto model2 = xor_model ( ) ; <nl> + auto model3 = xor_model ( ) ; <nl> auto optim = <nl> SGD ( model , 1e - 1 ) . momentum ( 0 . 9 ) . nesterov ( ) . weight_decay ( 1e - 6 ) . make ( ) ; <nl> <nl> TEST_CASE ( " serialization " ) { <nl> <nl> auto x = Var ( at : : CPU ( at : : kFloat ) . ones ( { 10 , 5 } ) , true ) ; <nl> <nl> - auto step = [ & ] ( Optimizer optim , std : : shared_ptr < Module > model ) { <nl> + auto step = [ & ] ( Optimizer optim , std : : shared_ptr < Linear > model ) { <nl> optim - > zero_grad ( ) ; <nl> auto y = model - > forward ( { x } ) [ 0 ] . sum ( ) ; <nl> backward ( y ) ; <nl> TEST_CASE ( " serialization " ) { <nl> TEST_CASE ( " serialization_cuda " , " [ cuda ] " ) { <nl> SECTION ( " xor " ) { <nl> / / We better be able to save and load a XOR model ! <nl> - auto makeModel = [ ] ( ) { <nl> - auto list = std : : make_shared < ContainerList > ( ) ; <nl> - list - > append ( Linear ( 2 , 8 ) . build ( ) ) ; <nl> - list - > append ( Linear ( 8 , 1 ) . build ( ) ) ; <nl> - return list ; <nl> - } ; <nl> - auto getLoss = [ ] ( std : : shared_ptr < ContainerList > model , uint32_t bs ) { <nl> + auto getLoss = [ ] ( std : : shared_ptr < Sequential > model , uint32_t bs ) { <nl> auto inp = at : : CPU ( at : : kFloat ) . tensor ( { bs , 2 } ) ; <nl> auto lab = at : : CPU ( at : : kFloat ) . tensor ( { bs } ) ; <nl> for ( auto i = 0U ; i < bs ; i + + ) { <nl> TEST_CASE ( " serialization_cuda " , " [ cuda ] " ) { <nl> } <nl> <nl> / / forward <nl> - auto x = Var ( inp ) ; <nl> + auto x = model - > forward < Variable > ( Var ( inp ) ) ; <nl> auto y = Var ( lab , false ) ; <nl> - for ( auto layer : * model ) <nl> - x = layer - > forward ( { x } ) [ 0 ] . sigmoid_ ( ) ; <nl> return at : : binary_cross_entropy ( x , y ) ; <nl> } ; <nl> <nl> - auto model = makeModel ( ) ; <nl> - auto model2 = makeModel ( ) ; <nl> - auto model3 = makeModel ( ) ; <nl> + auto model = xor_model ( ) ; <nl> + auto model2 = xor_model ( ) ; <nl> + auto model3 = xor_model ( ) ; <nl> auto optim = <nl> SGD ( model , 1e - 1 ) . momentum ( 0 . 9 ) . nesterov ( ) . weight_decay ( 1e - 6 ) . make ( ) ; <nl> <nl> new file mode 100644 <nl> index 000000000000 . . 1db97685287b <nl> mmm / dev / null <nl> ppp b / test / cpp / api / static . cpp <nl> <nl> + # include < catch . hpp > <nl> + <nl> + # include < torch / detail / static . h > <nl> + # include < torch / nn / module . h > <nl> + # include < torch / nn / modules / any . h > <nl> + # include < torch / nn / modules / linear . h > <nl> + <nl> + # include < torch / csrc / utils / variadic . h > <nl> + <nl> + # include < string > <nl> + # include < vector > <nl> + <nl> + template < <nl> + typename T , <nl> + typename = torch : : enable_if_t < ! torch : : detail : : is_module < T > : : value > > <nl> + bool f ( T & & m ) { <nl> + return false ; <nl> + } <nl> + <nl> + template < typename T > <nl> + torch : : detail : : enable_if_module_t < T , bool > f ( T & & m ) { <nl> + return true ; <nl> + } <nl> + <nl> + TEST_CASE ( " static " ) { <nl> + SECTION ( " all_of " ) { <nl> + REQUIRE ( torch : : all_of < > : : value = = true ) ; <nl> + REQUIRE ( torch : : all_of < true > : : value = = true ) ; <nl> + REQUIRE ( torch : : all_of < true , true , true > : : value = = true ) ; <nl> + REQUIRE ( torch : : all_of < false > : : value = = false ) ; <nl> + REQUIRE ( torch : : all_of < false , false , false > : : value = = false ) ; <nl> + REQUIRE ( torch : : all_of < true , true , false > : : value = = false ) ; <nl> + } <nl> + SECTION ( " any_of " ) { <nl> + REQUIRE ( torch : : any_of < > : : value = = false ) ; <nl> + REQUIRE ( torch : : any_of < true > : : value = = true ) ; <nl> + REQUIRE ( torch : : any_of < true , true , true > : : value = = true ) ; <nl> + REQUIRE ( torch : : any_of < false > : : value = = false ) ; <nl> + REQUIRE ( torch : : any_of < true , true , false > : : value = = true ) ; <nl> + } <nl> + SECTION ( " enable_if_module_t " ) { <nl> + REQUIRE ( f ( torch : : nn : : Linear ( 1 , 2 ) ) = = true ) ; <nl> + REQUIRE ( f ( 5 ) = = false ) ; <nl> + } <nl> + SECTION ( " check_not_lvalue_references " ) { <nl> + REQUIRE ( torch : : detail : : check_not_lvalue_references < int > ( ) = = true ) ; <nl> + REQUIRE ( <nl> + torch : : detail : : check_not_lvalue_references < float , int , char > ( ) = = true ) ; <nl> + REQUIRE ( <nl> + torch : : detail : : check_not_lvalue_references < float , int & , char > ( ) = = <nl> + false ) ; <nl> + REQUIRE ( torch : : detail : : check_not_lvalue_references < std : : string > ( ) = = true ) ; <nl> + REQUIRE ( <nl> + torch : : detail : : check_not_lvalue_references < std : : string & > ( ) = = false ) ; <nl> + } <nl> + SECTION ( " apply " ) { <nl> + std : : vector < int > v ; <nl> + torch : : apply ( [ & v ] ( int x ) { v . push_back ( x ) ; } , 1 , 2 , 3 , 4 , 5 ) ; <nl> + REQUIRE ( v . size ( ) = = 5 ) ; <nl> + for ( size_t i = 0 ; i < v . size ( ) ; + + i ) { <nl> + REQUIRE ( v . at ( i ) = = 1 + i ) ; <nl> + } <nl> + } <nl> + } <nl> new file mode 100644 <nl> index 000000000000 . . 0a94db55fc1a <nl> mmm / dev / null <nl> ppp b / test / cpp / api / util . h <nl> <nl> + # include < torch / nn / module . h > <nl> + # include < torch / nn / modules / linear . h > <nl> + <nl> + # include < memory > <nl> + # include < stdexcept > <nl> + # include < string > <nl> + # include < utility > <nl> + <nl> + namespace torch { <nl> + <nl> + / / Lets you use a container without making a new class , <nl> + / / for experimental implementations <nl> + class SimpleContainer : public nn : : CloneableModule < SimpleContainer > { <nl> + public : <nl> + virtual variable_list forward ( variable_list ) { <nl> + throw std : : runtime_error ( <nl> + " SimpleContainer has no forward , maybe you " <nl> + " wanted to subclass and override this function ? " ) ; <nl> + } <nl> + <nl> + void reset ( ) { } <nl> + <nl> + template < typename Derived > <nl> + std : : shared_ptr < Derived > add ( <nl> + std : : shared_ptr < Derived > module , <nl> + std : : string name = std : : string ( ) ) { <nl> + return Module : : register_module ( std : : move ( name ) , module ) ; <nl> + } <nl> + } ; <nl> + <nl> + struct SigmoidLinear : nn : : Module { <nl> + SigmoidLinear ( size_t in , size_t out ) : linear ( nn : : Linear ( in , out ) . build ( ) ) { <nl> + register_module ( " linear " , linear ) ; <nl> + } <nl> + <nl> + explicit SigmoidLinear ( std : : shared_ptr < nn : : Linear > linear_ ) <nl> + : linear ( std : : move ( linear_ ) ) { <nl> + register_module ( " linear " , linear ) ; <nl> + } <nl> + Variable forward ( Variable input ) { <nl> + return linear - > forward ( { input } ) . front ( ) . sigmoid ( ) ; <nl> + } <nl> + std : : shared_ptr < nn : : Linear > linear ; <nl> + } ; <nl> + <nl> + } / / namespace torch <nl> mmm a / tools / cpp_build / libtorch / CMakeLists . txt <nl> ppp b / tools / cpp_build / libtorch / CMakeLists . txt <nl> if ( TORCH_BUILD_TEST ) <nl> set ( TORCH_API_TEST_DIR " $ { TORCH_SRC_DIR } / . . / test / cpp / api " ) <nl> <nl> add_executable ( test_api <nl> + $ { TORCH_API_TEST_DIR } / any . cpp <nl> $ { TORCH_API_TEST_DIR } / container . cpp <nl> $ { TORCH_API_TEST_DIR } / integration . cpp <nl> $ { TORCH_API_TEST_DIR } / main . cpp <nl> $ { TORCH_API_TEST_DIR } / misc . cpp <nl> $ { TORCH_API_TEST_DIR } / module . cpp <nl> $ { TORCH_API_TEST_DIR } / optim . cpp <nl> + $ { TORCH_API_TEST_DIR } / sequential . cpp <nl> $ { TORCH_API_TEST_DIR } / rnn . cpp <nl> - $ { TORCH_API_TEST_DIR } / serialization . cpp ) <nl> + $ { TORCH_API_TEST_DIR } / serialization . cpp <nl> + $ { TORCH_API_TEST_DIR } / static . cpp ) <nl> <nl> - target_include_directories ( test_api <nl> - PUBLIC <nl> - " $ { TORCH_SRC_DIR } / . . / third_party / catch / single_include " ) <nl> + target_include_directories ( test_api <nl> + PUBLIC <nl> + " $ { TORCH_SRC_DIR } / . . / third_party / catch / single_include " ) <nl> <nl> target_link_libraries ( test_api torch ) <nl> endif ( ) <nl> new file mode 100644 <nl> index 000000000000 . . e33e2c27e126 <nl> mmm / dev / null <nl> ppp b / torch / csrc / api / include / torch / detail / static . h <nl> <nl> + # pragma once <nl> + <nl> + # include < cstdint > <nl> + # include < type_traits > <nl> + <nl> + namespace torch { <nl> + namespace nn { <nl> + class Module ; <nl> + } / / namespace nn <nl> + } / / namespace torch <nl> + <nl> + namespace torch { <nl> + namespace detail { <nl> + / / / Detects if a type T has a forward ( ) method . <nl> + template < typename T > <nl> + struct has_forward { <nl> + / / Declare two types with differing size . <nl> + using yes = int8_t ; <nl> + using no = int16_t ; <nl> + <nl> + / / Here we declare two functions . The first is only enabled if ` & U : : forward ` <nl> + / / is well - formed and returns the ` yes ` type . In C + + , the ellipsis parameter <nl> + / / type ( ` . . . ` ) always puts the function at the bottom of overload resolution . <nl> + / / This is specified in the standard as : 1 ) A standard conversion sequence is <nl> + / / always better than a user - defined conversion sequence or an ellipsis <nl> + / / conversion sequence . 2 ) A user - defined conversion sequence is always better <nl> + / / than an ellipsis conversion sequence This means that if the first overload <nl> + / / is viable , it will be preferred over the second as long as we pass any <nl> + / / convertible type . The type of ` & U : : forward ` is a pointer type , so we can <nl> + / / pass e . g . 0 . <nl> + template < typename U > <nl> + static yes test ( decltype ( & U : : forward ) ) ; <nl> + template < typename U > <nl> + static no test ( . . . ) ; <nl> + <nl> + / / Finally we test statically whether the size of the type returned by the <nl> + / / selected overload is the size of the ` yes ` type . <nl> + static constexpr bool value = ( sizeof ( test < T > ( nullptr ) ) = = sizeof ( yes ) ) ; <nl> + } ; <nl> + <nl> + template < typename Head = void , typename . . . Tail > <nl> + constexpr bool check_not_lvalue_references ( ) { <nl> + return ( ! std : : is_lvalue_reference < Head > : : value | | <nl> + std : : is_const < typename std : : remove_reference < Head > : : type > : : value ) & & <nl> + check_not_lvalue_references < Tail . . . > ( ) ; <nl> + } <nl> + <nl> + template < > <nl> + inline constexpr bool check_not_lvalue_references < void > ( ) { <nl> + return true ; <nl> + } <nl> + <nl> + / / / A type trait whose ` : : value ` member is true if ` M ` derives from ` Module ` . <nl> + template < typename M > <nl> + using is_module = std : : is_base_of < torch : : nn : : Module , typename std : : decay < M > : : type > ; <nl> + <nl> + template < typename M , typename T = void > <nl> + using enable_if_module_t = <nl> + typename std : : enable_if < is_module < M > : : value , T > : : type ; <nl> + } / / namespace detail <nl> + } / / namespace torch <nl> mmm a / torch / csrc / api / include / torch / nn / module . h <nl> ppp b / torch / csrc / api / include / torch / nn / module . h <nl> <nl> # include < map > <nl> # include < memory > <nl> # include < string > <nl> + # include < type_traits > <nl> # include < unordered_map > <nl> <nl> namespace torch { <nl> class Module { <nl> / / / Returns the name of the ` Module ` . <nl> const std : : string & name ( ) const noexcept ; <nl> <nl> - virtual variable_list forward ( variable_list ) = 0 ; <nl> virtual std : : shared_ptr < Module > clone ( ) const ; <nl> <nl> + / / Only construct parameters in initialize_parameters , and <nl> + / / containers in initialize_containers . Most of the time , the containers are <nl> + / / the only thing you need to add . <nl> + / / You are guaranteed that containers are added before parameters . <nl> + virtual void initialize_containers ( ) { } <nl> + virtual void initialize_parameters ( ) { } <nl> + virtual void reset_parameters ( ) { } <nl> + <nl> std : : map < std : : string , Variable > parameters ( ) const ; <nl> Variable & param ( std : : string const & ) ; <nl> <nl> new file mode 100644 <nl> index 000000000000 . . 8bbba6e9ac0c <nl> mmm / dev / null <nl> ppp b / torch / csrc / api / include / torch / nn / modules / any . h <nl> <nl> + # pragma once <nl> + <nl> + # include < torch / detail / static . h > <nl> + # include < torch / nn / module . h > <nl> + <nl> + # include < torch / csrc / autograd / variable . h > <nl> + # include < torch / csrc / utils / memory . h > <nl> + # include < torch / csrc / utils / variadic . h > <nl> + <nl> + # include < memory > <nl> + # include < type_traits > <nl> + # include < typeinfo > <nl> + # include < utility > <nl> + # include < vector > <nl> + <nl> + namespace torch { <nl> + namespace nn { <nl> + <nl> + / / / A class to store a type erasd module , whose ` forward ( ) ` method can be <nl> + / / / invoked , with dynamic type checking . An ` AnyModule ` has an empty state , into <nl> + / / / which it is default constructed . ` is_empty ( ) ` can be used to query whether <nl> + / / / the ` AnyModule ` is empty . <nl> + class AnyModule { <nl> + public : <nl> + / / / A type - erased value . <nl> + class Value ; <nl> + <nl> + / / / A default - constructed ` AnyModule ` is in an empty state . <nl> + AnyModule ( ) = default ; <nl> + <nl> + / / / Constructs an ` AnyModule ` from a ` shared_ptr ` to concrete module object . <nl> + template < typename ModuleType > <nl> + explicit AnyModule ( std : : shared_ptr < ModuleType > module ) ; <nl> + <nl> + / / / Constructs an ` AnyModule ` from a concrete module object . <nl> + template < typename ModuleType > <nl> + explicit AnyModule ( ModuleType & & module ) ; <nl> + <nl> + / / / Move construction and assignment is allowed , and follows the default <nl> + / / / behavior of move for ` std : : unique_ptr ` . <nl> + AnyModule ( AnyModule & & ) = default ; <nl> + AnyModule & operator = ( AnyModule & & ) = default ; <nl> + <nl> + / / / Copy is disallowed . <nl> + AnyModule ( const AnyModule & other ) = delete ; <nl> + AnyModule & operator = ( const AnyModule & other ) = delete ; <nl> + <nl> + / / / Assigns a module to the ` AnyModule ` ( to circumvent the explicit <nl> + / / / constructor ) . <nl> + template < typename ModuleType > <nl> + AnyModule & operator = ( std : : shared_ptr < ModuleType > module ) ; <nl> + <nl> + / / / Invokes ` forward ( ) ` on the contained module with the given arguments , and <nl> + / / / returns the return value as an ` Value ` . Use this method when chaining <nl> + / / / ` AnyModule ` s in a loop . <nl> + template < typename . . . ArgumentTypes > <nl> + Value forward ( ArgumentTypes & & . . . arguments ) ; <nl> + <nl> + / / / Attempts to cast the underlying module to the given module type . Throws an <nl> + / / / exception if the types do not match . <nl> + template < typename T , typename = torch : : detail : : enable_if_module_t < T > > <nl> + T & get ( ) ; <nl> + <nl> + / / / Attempts to cast the underlying module to the given module type . Throws an <nl> + / / / exception if the types do not match . <nl> + template < typename T , typename = torch : : detail : : enable_if_module_t < T > > <nl> + const T & get ( ) const ; <nl> + <nl> + / / / Returns a ` std : : shared_ptr ` whose dynamic type is that of the underlying <nl> + / / / module . <nl> + std : : shared_ptr < Module > ptr ( ) const ; <nl> + <nl> + / / / Like ` ptr ( ) ` , but casts the pointer to the given type . <nl> + template < typename T , typename = torch : : detail : : enable_if_module_t < T > > <nl> + std : : shared_ptr < T > ptr ( ) const ; <nl> + <nl> + / / / Returns the ` type_info ` object of the contained value . <nl> + const std : : type_info & type_info ( ) const ; <nl> + <nl> + / / / Returns true if the ` AnyModule ` does not contain a module . <nl> + bool is_empty ( ) const noexcept ; <nl> + <nl> + private : <nl> + / / / The static type of the object we store in the ` AnyModule ` , which erases <nl> + / / / the actual type , but allows us to call ` forward ( ) ` on the underlying <nl> + / / / module . <nl> + struct Placeholder ; <nl> + <nl> + / / / The dynamic type of the object stored in the ` AnyModule ` . It contains the <nl> + / / / concrete instance to which all calls are forwarded . It is parameterized <nl> + / / / over the concrete type of the module , and the types of the arguments the <nl> + / / / module takes in its ` forward ( ) ` method . <nl> + template < typename ModuleType , typename . . . ArgumentTypes > <nl> + struct Holder ; <nl> + <nl> + / / / Creates a ` unique_ptr < Placeholder > ` pointing to a ` Holder ` of the correct <nl> + / / / type . This method is used to deduce the arguments of the module ' s <nl> + / / / ` forward ( ) ` method . <nl> + template < <nl> + typename ModuleType , <nl> + typename Class , / / = std : : remove_reference < ModuleType > : : type <nl> + typename ReturnType , <nl> + typename . . . ArgumentTypes > <nl> + std : : unique_ptr < Placeholder > make_holder ( <nl> + std : : shared_ptr < ModuleType > & & module , <nl> + ReturnType ( Class : : * ) ( ArgumentTypes . . . ) ) ; <nl> + <nl> + / / / Helper method invoked by const and non - const ` get ( ) ` . <nl> + template < typename T > <nl> + T & get_ ( ) const ; <nl> + <nl> + / / / The type erased module . <nl> + std : : unique_ptr < Placeholder > content_ ; <nl> + } ; <nl> + <nl> + / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AnyModule : : Value ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + <nl> + / / / A simplified implementation of ` std : : any ` which stores <nl> + / / / a type erased object , whose concrete value can be retrieved at runtime by <nl> + / / / checking if the ` typeid ( ) ` of a requested type matches the ` typeid ( ) ` of <nl> + / / / the object stored . It is simplified in that it does not handle copying , as <nl> + / / / we do not require it for our use cases . Moves are sufficient . <nl> + class AnyModule : : Value { <nl> + public : <nl> + / / / Move construction and assignment is allowed , and follows the default <nl> + / / / behavior of move for ` std : : unique_ptr ` . <nl> + Value ( Value & & ) = default ; <nl> + Value & operator = ( Value & & ) = default ; <nl> + <nl> + / / / Copy is disallowed , because we don ' t need it . <nl> + Value ( const Value & other ) = delete ; <nl> + Value & operator = ( const Value & other ) = delete ; <nl> + <nl> + / / / Returns a pointer to the value contained in the ` Value ` if the type passed <nl> + / / / as template parameter matches the type of the value stored , and returns a <nl> + / / / null pointer otherwise . <nl> + template < typename T > <nl> + T * try_get ( ) { <nl> + static_assert ( <nl> + ! std : : is_reference < T > : : value , <nl> + " Value stores decayed types , you cannot cast it to a reference type " ) ; <nl> + static_assert ( <nl> + ! std : : is_array < T > : : value , <nl> + " Value stores decayed types , you must cast it to T * instead of T [ ] " ) ; <nl> + if ( typeid ( T ) . hash_code ( ) = = type_info ( ) . hash_code ( ) ) { <nl> + return & static_cast < Holder < T > & > ( * content_ ) . value ; <nl> + } <nl> + return nullptr ; <nl> + } <nl> + <nl> + / / / Returns the value contained in the ` Value ` if the type passed as template <nl> + / / / parameter matches the type of the value stored , and throws an exception <nl> + / / / otherwise . <nl> + template < typename T > <nl> + T get ( ) { <nl> + if ( auto * maybe_value = try_get < T > ( ) ) { <nl> + return * maybe_value ; <nl> + } <nl> + AT_ERROR ( <nl> + " Attempted to cast Value to " , <nl> + at : : demangle ( typeid ( T ) . name ( ) ) , <nl> + " , but its actual type is " , <nl> + at : : demangle ( type_info ( ) . name ( ) ) ) ; <nl> + } <nl> + <nl> + / / / Returns the ` type_info ` object of the contained value . <nl> + const std : : type_info & type_info ( ) const noexcept { <nl> + return content_ - > type_info ; <nl> + } <nl> + <nl> + private : <nl> + friend class AnyModule ; <nl> + friend class TestValue ; <nl> + <nl> + / / / Constructs the ` Value ` from value type . <nl> + template < typename T > <nl> + explicit Value ( T & & value ) <nl> + : content_ ( <nl> + torch : : make_unique < Holder < decay_t < T > > > ( std : : forward < T > ( value ) ) ) { } <nl> + <nl> + / / / The static type of the object we store in the ` Value ` , which erases the <nl> + / / / actual object ' s type , allowing us only to check the ` type_info ` of the <nl> + / / / type stored in the dynamic type . <nl> + struct Placeholder { <nl> + explicit Placeholder ( const std : : type_info & type_info_ ) noexcept <nl> + : type_info ( type_info_ ) { } <nl> + virtual ~ Placeholder ( ) = default ; <nl> + const std : : type_info & type_info ; <nl> + } ; <nl> + <nl> + / / / The dynamic type of the object we store in the ` Value ` , which hides the <nl> + / / / actual object we have erased in this ` Value ` . <nl> + template < typename T > <nl> + struct Holder : public Placeholder { <nl> + / / / A template because T & & would not be universal reference here . <nl> + template < typename U > <nl> + explicit Holder ( U & & value_ ) noexcept <nl> + : Placeholder ( typeid ( T ) ) , value ( std : : forward < U > ( value_ ) ) { } <nl> + T value ; <nl> + } ; <nl> + <nl> + / / / The type erased object . <nl> + std : : unique_ptr < Placeholder > content_ ; <nl> + } ; <nl> + <nl> + / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AnyModule : : Placeholder ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + <nl> + struct AnyModule : : Placeholder : public AnyModule : : Value : : Placeholder { <nl> + using AnyModule : : Value : : Placeholder : : Placeholder ; <nl> + <nl> + / / / The " erased " ` forward ( ) ` method . <nl> + virtual Value forward ( std : : vector < Value > & & arguments ) = 0 ; <nl> + <nl> + / / / Returns std : : shared_ptr < Module > pointing to the erased module . <nl> + virtual std : : shared_ptr < Module > ptr ( ) = 0 ; <nl> + } ; <nl> + <nl> + / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AnyModule : : Holder ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + <nl> + template < typename ModuleType , typename . . . ArgumentTypes > <nl> + struct AnyModule : : Holder : public AnyModule : : Placeholder { <nl> + struct CheckedGetter { <nl> + template < typename T > <nl> + decay_t < T > & & operator ( ) ( size_t index ) { <nl> + AT_ASSERT ( index < arguments_ . size ( ) ) ; <nl> + auto & value = arguments_ [ index ] ; <nl> + if ( auto * maybe_value = value . template try_get < decay_t < T > > ( ) ) { <nl> + return std : : move ( * maybe_value ) ; <nl> + } <nl> + AT_ERROR ( <nl> + " Expected argument # " , <nl> + index , <nl> + " to be of type " , <nl> + at : : demangle ( typeid ( T ) . name ( ) ) , <nl> + " , but received value of type " , <nl> + at : : demangle ( value . type_info ( ) . name ( ) ) ) ; <nl> + } <nl> + std : : vector < Value > & arguments_ ; <nl> + } ; <nl> + <nl> + struct InvokeForward { <nl> + template < typename . . . Ts > <nl> + Value operator ( ) ( Ts & & . . . ts ) { <nl> + return Value ( module_ - > forward ( std : : forward < Ts > ( ts ) . . . ) ) ; <nl> + } <nl> + std : : shared_ptr < ModuleType > & module_ ; <nl> + } ; <nl> + <nl> + / / / Constructs the ` Holder ` from a concrete module . <nl> + explicit Holder ( std : : shared_ptr < ModuleType > & & module_ ) <nl> + : Placeholder ( typeid ( ModuleType ) ) , module ( std : : move ( module_ ) ) { } <nl> + <nl> + / / / Calls ` forward ( ) ` on the underlying module , casting each ` Value ` in the <nl> + / / / argument vector to a concrete value . <nl> + Value forward ( std : : vector < Value > & & arguments ) override { <nl> + AT_CHECK ( <nl> + arguments . size ( ) = = sizeof . . . ( ArgumentTypes ) , <nl> + at : : demangle ( type_info . name ( ) ) , <nl> + " ' s forward ( ) method expects " , <nl> + sizeof . . . ( ArgumentTypes ) , <nl> + " arguments , but received " , <nl> + arguments . size ( ) ) ; <nl> + / / FYI : During invocation of a module ' s ` forward ( ) ` method , the values live <nl> + / / in the ` arguments ` vector inside this function . <nl> + return torch : : unpack < ArgumentTypes . . . > ( <nl> + InvokeForward { module } , CheckedGetter { arguments } ) ; <nl> + } <nl> + <nl> + std : : shared_ptr < Module > ptr ( ) override { <nl> + return module ; <nl> + } <nl> + <nl> + / / / The actual concrete module instance . <nl> + std : : shared_ptr < ModuleType > module ; <nl> + } ; <nl> + <nl> + / / ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ AnyModule ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ <nl> + <nl> + template < typename ModuleType > <nl> + AnyModule : : AnyModule ( std : : shared_ptr < ModuleType > module ) <nl> + : content_ ( make_holder ( <nl> + std : : move ( module ) , <nl> + & std : : remove_reference < ModuleType > : : type : : forward ) ) { } <nl> + <nl> + template < typename ModuleType > <nl> + AnyModule : : AnyModule ( ModuleType & & module ) <nl> + : AnyModule ( <nl> + std : : make_shared < ModuleType > ( std : : forward < ModuleType > ( module ) ) ) { } <nl> + <nl> + template < typename ModuleType > <nl> + AnyModule & AnyModule : : operator = ( std : : shared_ptr < ModuleType > module ) { <nl> + return ( * this = AnyModule ( std : : move ( module ) ) ) ; <nl> + } <nl> + <nl> + template < typename . . . ArgumentTypes > <nl> + AnyModule : : Value AnyModule : : forward ( ArgumentTypes & & . . . arguments ) { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call forward ( ) on an empty AnyModule " ) ; <nl> + std : : vector < Value > values ; <nl> + values . reserve ( sizeof . . . ( ArgumentTypes ) ) ; <nl> + torch : : apply ( <nl> + [ & values ] ( Value & & value ) { values . push_back ( std : : move ( value ) ) ; } , <nl> + Value ( std : : forward < ArgumentTypes > ( arguments ) ) . . . ) ; <nl> + return content_ - > forward ( std : : move ( values ) ) ; <nl> + } <nl> + <nl> + template < typename T , typename > <nl> + T & AnyModule : : get ( ) { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call get ( ) on an empty AnyModule " ) ; <nl> + return get_ < T > ( ) ; <nl> + } <nl> + <nl> + template < typename T , typename > <nl> + const T & AnyModule : : get ( ) const { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call get ( ) on an empty AnyModule " ) ; <nl> + return get_ < T > ( ) ; <nl> + } <nl> + <nl> + inline std : : shared_ptr < Module > AnyModule : : ptr ( ) const { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call ptr ( ) on an empty AnyModule " ) ; <nl> + return content_ - > ptr ( ) ; <nl> + } <nl> + <nl> + template < typename T , typename > <nl> + std : : shared_ptr < T > AnyModule : : ptr ( ) const { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call ptr ( ) on an empty AnyModule " ) ; <nl> + / / / Call get ( ) but discard the value , just to do the type checking . <nl> + get_ < T > ( ) ; <nl> + return std : : static_pointer_cast < T > ( ptr ( ) ) ; <nl> + } <nl> + <nl> + inline const std : : type_info & AnyModule : : type_info ( ) const { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call type_info ( ) on an empty AnyModule " ) ; <nl> + return content_ - > type_info ; <nl> + } <nl> + <nl> + inline bool AnyModule : : is_empty ( ) const noexcept { <nl> + return content_ = = nullptr ; <nl> + } <nl> + <nl> + / / Private Methods <nl> + <nl> + template < <nl> + typename ModuleType , <nl> + typename Class , <nl> + typename ReturnType , <nl> + typename . . . ArgumentTypes > <nl> + std : : unique_ptr < AnyModule : : Placeholder > AnyModule : : make_holder ( <nl> + std : : shared_ptr < ModuleType > & & module , <nl> + ReturnType ( Class : : * ) ( ArgumentTypes . . . ) ) { <nl> + static_assert ( <nl> + torch : : detail : : check_not_lvalue_references < ArgumentTypes . . . > ( ) , <nl> + " Modules stored inside AnyModule must not take references . " <nl> + " Use pointers instead . " ) ; <nl> + static_assert ( <nl> + ! std : : is_void < ReturnType > : : value , <nl> + " AnyModule cannot store modules that return void " <nl> + " ( you can return a dummy value ) . " ) ; <nl> + return torch : : make_unique < Holder < decay_t < ModuleType > , ArgumentTypes . . . > > ( <nl> + std : : move ( module ) ) ; <nl> + } <nl> + <nl> + template < typename T > <nl> + T & AnyModule : : get_ ( ) const { <nl> + if ( typeid ( T ) . hash_code ( ) = = type_info ( ) . hash_code ( ) ) { <nl> + return * static_cast < Holder < T > & > ( * content_ ) . module ; <nl> + } <nl> + AT_ERROR ( <nl> + " Attempted to cast module of type " , <nl> + at : : demangle ( type_info ( ) . name ( ) ) , <nl> + " to type " , <nl> + at : : demangle ( typeid ( T ) . name ( ) ) ) ; <nl> + } <nl> + <nl> + } / / namespace nn <nl> + } / / namespace torch <nl> mmm a / torch / csrc / api / include / torch / nn / modules / batchnorm . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / batchnorm . h <nl> class BatchNorm : public torch : : nn : : CloneableModule < BatchNorm > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list ) override ; <nl> + variable_list forward ( variable_list ) ; <nl> <nl> TORCH_ATTR ( int64_t , features ) ; <nl> TORCH_ATTR ( bool , affine ) = true ; <nl> deleted file mode 100644 <nl> index 4567bbcb9fbd . . 000000000000 <nl> mmm a / torch / csrc / api / include / torch / nn / modules / containers . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < torch / detail . h > <nl> - # include < torch / nn / module . h > <nl> - <nl> - # include < torch / csrc / autograd / variable . h > <nl> - <nl> - namespace torch { <nl> - namespace nn { <nl> - <nl> - template < class Derived > <nl> - class ContainerListImpl : public Module { <nl> - / / Lets you use a container like a vector without making a new class , <nl> - / / just for simple implementations <nl> - public : <nl> - virtual variable_list forward ( variable_list ) override { <nl> - throw std : : runtime_error ( <nl> - " ContainerList has no forward , maybe you " <nl> - " wanted to subclass and override this function ? " ) ; <nl> - } <nl> - <nl> - std : : shared_ptr < Module > add ( std : : shared_ptr < Module > m ) { <nl> - return append ( m ) . modules_ . back ( ) ; <nl> - } <nl> - <nl> - ContainerListImpl < Derived > & append ( std : : shared_ptr < Module > m ) { <nl> - modules_ . push_back ( <nl> - register_module ( std : : to_string ( size ( ) - 1 ) , std : : move ( m ) ) ) ; <nl> - return * this ; <nl> - } <nl> - <nl> - std : : shared_ptr < Module > & operator [ ] ( int index ) { <nl> - return modules_ [ index ] ; <nl> - } <nl> - <nl> - int size ( ) { <nl> - return modules_ . size ( ) ; <nl> - } <nl> - <nl> - std : : vector < std : : shared_ptr < Module > > : : iterator begin ( ) { <nl> - return modules_ . begin ( ) ; <nl> - } <nl> - <nl> - std : : vector < std : : shared_ptr < Module > > : : iterator end ( ) { <nl> - return modules_ . end ( ) ; <nl> - } <nl> - <nl> - std : : vector < std : : shared_ptr < Module > > modules_ ; <nl> - } ; <nl> - <nl> - class ContainerList : public ContainerListImpl < ContainerList > { } ; <nl> - <nl> - class Sequential : public ContainerListImpl < Sequential > { <nl> - / / Mimics nn . Sequential from pytorch . <nl> - public : <nl> - variable_list forward ( variable_list input ) override { <nl> - for ( auto & container : modules_ ) { <nl> - input = container - > forward ( input ) ; <nl> - } <nl> - return input ; <nl> - } <nl> - <nl> - std : : shared_ptr < Module > add ( <nl> - std : : shared_ptr < Module > m , <nl> - std : : string name = " " ) { <nl> - return append ( m , name ) . modules_ . back ( ) ; <nl> - } <nl> - <nl> - Sequential & append ( std : : shared_ptr < Module > m , std : : string name = " " ) { <nl> - if ( name = = " " ) { <nl> - name = std : : to_string ( size ( ) ) ; <nl> - } <nl> - modules_ . push_back ( register_module ( name , std : : move ( m ) ) ) ; <nl> - return * this ; <nl> - } <nl> - } ; <nl> - } / / namespace nn <nl> - } / / namespace torch <nl> mmm a / torch / csrc / api / include / torch / nn / modules / conv . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / conv . h <nl> class Conv : public torch : : nn : : CloneableModule < Derived > { <nl> class Conv # # dimensions # # d : public Conv < ( dimensions ) , Conv # # dimensions # # d > { \ <nl> public : \ <nl> using Conv < ( dimensions ) , Conv # # dimensions # # d > : : Conv ; \ <nl> - variable_list forward ( variable_list ) override ; \ <nl> + variable_list forward ( variable_list ) ; \ <nl> } <nl> <nl> CONV_D ( 1 ) ; <nl> mmm a / torch / csrc / api / include / torch / nn / modules / dropout . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / dropout . h <nl> class DropoutBase : public torch : : nn : : CloneableModule < T > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list input ) override ; <nl> + variable_list forward ( variable_list input ) ; <nl> <nl> TORCH_ATTR ( double , rate ) = 0 . 5 ; <nl> <nl> mmm a / torch / csrc / api / include / torch / nn / modules / embedding . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / embedding . h <nl> class Embedding : public torch : : nn : : CloneableModule < Embedding > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list ) override ; <nl> + variable_list forward ( variable_list ) ; <nl> <nl> TORCH_ATTR ( int64_t , count ) ; <nl> TORCH_ATTR ( int64_t , dimension ) ; <nl> mmm a / torch / csrc / api / include / torch / nn / modules / functional . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / functional . h <nl> class Functional : public torch : : nn : : CloneableModule < Functional > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list input ) override ; <nl> + variable_list forward ( variable_list input ) ; <nl> <nl> TORCH_ATTR ( Function , function ) ; <nl> } ; <nl> mmm a / torch / csrc / api / include / torch / nn / modules / linear . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / linear . h <nl> class Linear : public torch : : nn : : CloneableModule < Linear > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list ) override ; <nl> + variable_list forward ( variable_list ) ; <nl> + <nl> + TORCH_AUTOGRAD_KWARG ( Linear , bool , no_bias , false , true ) ; <nl> <nl> TORCH_ATTR ( int64_t , in ) ; <nl> TORCH_ATTR ( int64_t , out ) ; <nl> mmm a / torch / csrc / api / include / torch / nn / modules / modules . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / modules . h <nl> <nl> # pragma once <nl> <nl> # include < torch / nn / modules / batchnorm . h > <nl> - # include < torch / nn / modules / containers . h > <nl> # include < torch / nn / modules / conv . h > <nl> # include < torch / nn / modules / dropout . h > <nl> # include < torch / nn / modules / embedding . h > <nl> <nl> # include < torch / nn / modules / linear . h > <nl> # include < torch / nn / modules / modules . h > <nl> # include < torch / nn / modules / rnn . h > <nl> + # include < torch / nn / modules / sequential . h > <nl> mmm a / torch / csrc / api / include / torch / nn / modules / rnn . h <nl> ppp b / torch / csrc / api / include / torch / nn / modules / rnn . h <nl> class Dropout ; <nl> <nl> namespace torch { <nl> namespace nn { <nl> + <nl> template < typename Derived > <nl> class RNNBase : public CloneableModule < Derived > { <nl> public : <nl> class RNNBase : public CloneableModule < Derived > { <nl> <nl> void reset ( ) override ; <nl> <nl> - variable_list forward ( variable_list ) override ; <nl> + variable_list forward ( variable_list ) ; <nl> <nl> void to ( at : : Type & type ) override ; <nl> void to ( at : : ScalarType scalar_type ) override ; <nl> new file mode 100644 <nl> index 000000000000 . . 8baef30b5460 <nl> mmm / dev / null <nl> ppp b / torch / csrc / api / include / torch / nn / modules / sequential . h <nl> <nl> + # pragma once <nl> + <nl> + # include < torch / detail / static . h > <nl> + # include < torch / nn / module . h > <nl> + # include < torch / nn / modules / any . h > <nl> + <nl> + # include < torch / csrc / autograd / variable . h > <nl> + <nl> + # include < ATen / Error . h > <nl> + <nl> + # include < cstdint > <nl> + # include < memory > <nl> + # include < string > <nl> + # include < type_traits > <nl> + # include < utility > <nl> + # include < vector > <nl> + <nl> + namespace torch { <nl> + namespace nn { <nl> + / / / A ` Sequential ` module is a container for any number of other modules . Its <nl> + / / / ` forward ( ) ` method chains outputs to inputs and returns the final output . <nl> + / / / The ` Sequential ` class reference semantics . <nl> + class Sequential : public CloneableModule < Sequential > { <nl> + public : <nl> + using Iterator = std : : vector < std : : shared_ptr < AnyModule > > : : iterator ; <nl> + <nl> + / / / Constructs the ` Sequential ` from a pack of modules . Each module can either <nl> + / / / be a plain value ( e . g . ` Linear ` ) or a boxed value ( e . g . <nl> + / / / ` shared_ptr < Linear > ` ) . Unboxed modules will be moved into ` shared_ptr ` s <nl> + / / / internally . <nl> + template < <nl> + typename . . . Modules , <nl> + typename = disable_if_contains_t < Sequential , Modules . . . > > <nl> + explicit Sequential ( Modules & & . . . modules ) { <nl> + modules_ . reserve ( sizeof . . . ( Modules ) ) ; <nl> + push_back ( std : : forward < Modules > ( modules ) . . . ) ; <nl> + } <nl> + <nl> + / / / reset ( ) is empty for ` Sequential ` , since it does not have parameter of its <nl> + / / / own . <nl> + void reset ( ) override { } <nl> + <nl> + / / / Feeds the ` inputs ` to the first module , then chains the output of each <nl> + / / / module with the input of the next , in order of construction . <nl> + template < typename ReturnType = autograd : : Variable , typename . . . ArgumentTypes > <nl> + ReturnType forward ( ArgumentTypes & & . . . arguments ) { <nl> + AT_CHECK ( ! is_empty ( ) , " Cannot call forward ( ) on an empty Sequential " ) ; <nl> + <nl> + auto iterator = modules_ . begin ( ) ; <nl> + auto input = <nl> + ( * iterator ) - > forward ( std : : forward < ArgumentTypes > ( arguments ) . . . ) ; <nl> + <nl> + for ( + + iterator ; iterator ! = modules_ . end ( ) ; + + iterator ) { <nl> + input = ( * iterator ) - > forward ( std : : move ( input ) ) ; <nl> + } <nl> + <nl> + / / Check the return value and give a nice error message if the requsted <nl> + / / return type was incorrect . <nl> + if ( auto * return_value = input . template try_get < ReturnType > ( ) ) { <nl> + return std : : move ( * return_value ) ; <nl> + } <nl> + AT_ERROR ( <nl> + " The type of the return value is " , <nl> + at : : demangle ( input . type_info ( ) . name ( ) ) , <nl> + " , but you asked for type " , <nl> + at : : demangle ( typeid ( ReturnType ) . name ( ) ) ) ; <nl> + } <nl> + <nl> + / / / Adds a new ( boxed ) ` Module ` to the ` Sequential ` container . <nl> + template < typename ModuleType > <nl> + void push_back ( std : : shared_ptr < ModuleType > module_ptr ) { <nl> + / / Nesting Sequential doesn ' t work because ` forward ( ) ` ' s return type is <nl> + / / templatized , so it ' ll give a nasty compiler error . <nl> + static_assert ( <nl> + ! std : : is_same < Sequential , ModuleType > : : value , <nl> + " Sequential is not nestable " ) ; <nl> + static_assert ( <nl> + torch : : detail : : is_module < ModuleType > : : value , <nl> + " Can only add objects derived from nn : : Module to Sequential " ) ; <nl> + static_assert ( <nl> + torch : : detail : : has_forward < ModuleType > : : value , <nl> + " Can only add modules with a forward ( ) method to Sequential " ) ; <nl> + modules_ . push_back ( std : : make_shared < AnyModule > ( std : : move ( module_ptr ) ) ) ; <nl> + const auto index = modules_ . size ( ) - 1 ; <nl> + register_module ( std : : to_string ( index ) , modules_ [ index ] - > ptr ( ) ) ; <nl> + } <nl> + <nl> + / / / Adds a new ` Module ` to the ` Sequential ` container , moving or copying it <nl> + / / / into a ` shared_ptr ` internally . This method allows passing value types , <nl> + / / / and letting the container deal with the boxing . This means you can write <nl> + / / / ` Sequential ( Linear ( 3 , 4 ) , ReLU ( ) ) ` instead of <nl> + / / / ` Sequential ( std : : make_shared < Linear > ( 3 , 4 ) , std : : make_shared < ReLU > ( ) ) ` . <nl> + template < typename M > <nl> + void push_back ( M & & module ) { <nl> + / / Need to get rid of any reference components for make_unique . <nl> + using Type = typename std : : remove_reference < M > : : type ; <nl> + / / Here we move ( or copy ) the module into a new shared_ptr . <nl> + push_back ( std : : make_shared < Type > ( std : : forward < M > ( module ) ) ) ; <nl> + } <nl> + <nl> + / / / Returns an iterator to the start of the ` Sequential ` . <nl> + Iterator begin ( ) { <nl> + return modules_ . begin ( ) ; <nl> + } <nl> + <nl> + / / / Returns an iterator to the end of the ` Sequential ` . <nl> + Iterator end ( ) { <nl> + return modules_ . end ( ) ; <nl> + } <nl> + <nl> + / / / Attempts to return the module at the given index as the requested type . <nl> + / / / Throws an exception if the index is out of bounds or the types do not <nl> + / / / match . <nl> + template < typename T > <nl> + T & at ( size_t index ) { <nl> + static_assert ( <nl> + torch : : detail : : is_module < T > : : value , <nl> + " Can only call Sequential : : at with an nn : : Module type " ) ; <nl> + AT_CHECK ( index < size ( ) , " Index out of range " ) ; <nl> + return modules_ [ index ] - > get < T > ( ) ; <nl> + } <nl> + <nl> + / / / Attempts to return the module at the given index as the requested type . <nl> + / / / Throws an exception if the index is out of bounds or the types do not <nl> + / / / match . <nl> + template < typename T > <nl> + const T & at ( size_t index ) const { <nl> + static_assert ( <nl> + torch : : detail : : is_module < T > : : value , <nl> + " Can only call Sequential : : at with an nn : : Module type " ) ; <nl> + AT_CHECK ( index < size ( ) , " Index out of range " ) ; <nl> + return modules_ [ index ] - > get < T > ( ) ; <nl> + } <nl> + <nl> + / / / Attempts to return a ` std : : shared_ptr ` whose dynamic type is that of the <nl> + / / / underlying module at the given index . Throws an exception if the index is <nl> + / / / out of bounds . <nl> + std : : shared_ptr < Module > ptr ( size_t index ) const { <nl> + AT_CHECK ( index < size ( ) , " Index out of range " ) ; <nl> + return modules_ [ index ] - > ptr ( ) ; <nl> + } <nl> + <nl> + / / / Attempts to return a ` std : : shared_ptr ` whose type is the one provided . <nl> + / / / Throws an exception if the index is out of bounds or the types do not <nl> + / / / match . <nl> + template < typename T > <nl> + std : : shared_ptr < T > ptr ( size_t index ) const { <nl> + static_assert ( <nl> + torch : : detail : : is_module < T > : : value , <nl> + " Can only call Sequential : : ptr with an nn : : Module type " ) ; <nl> + AT_CHECK ( index < size ( ) , " Index out of range " ) ; <nl> + return modules_ [ index ] - > ptr < T > ( ) ; <nl> + } <nl> + <nl> + / / / Like ` ptr ( index ) ` . <nl> + std : : shared_ptr < Module > operator [ ] ( size_t index ) const { <nl> + / / This is the only method we can call without a type . <nl> + return ptr ( index ) ; <nl> + } <nl> + <nl> + / / / The current size of the ` Sequential ` container . <nl> + size_t size ( ) const noexcept { <nl> + return modules_ . size ( ) ; <nl> + } <nl> + <nl> + / / / True if there are no modules in the ` Sequential ` . <nl> + bool is_empty ( ) const noexcept { <nl> + return size ( ) = = 0 ; <nl> + } <nl> + <nl> + private : <nl> + / / / Takes a First * and * Second parameter , to avoid ambiguity when a parameter <nl> + / / / pack has only one type , in which case the template would be preferred , <nl> + / / / even if the other ` push_back ` functions are better fits ( e . g . ` unique_ptr ` <nl> + / / / - > ` shared_ptr ` overload ) . <nl> + template < typename First , typename Second , typename . . . Rest > <nl> + void push_back ( First & & first , Second & & second , Rest & & . . . rest ) { <nl> + push_back ( std : : forward < First > ( first ) ) ; <nl> + / / Recursively calls this method , until the parameter pack only thas this <nl> + / / entry left . Then calls ` push_back ( ) ` a final time ( above ) . <nl> + push_back ( std : : forward < Second > ( second ) , std : : forward < Rest > ( rest ) . . . ) ; <nl> + } <nl> + <nl> + / / / The base case , when the list of modules is empty . <nl> + void push_back ( ) { } <nl> + <nl> + / / Box the AnyModules to give Sequential reference semantics , like the rest of <nl> + / / the API . Note that this is not required otherwise , this could just be a <nl> + / / ` vector < AnyModule > ` . <nl> + std : : vector < std : : shared_ptr < AnyModule > > modules_ ; <nl> + } ; <nl> + } / / namespace nn <nl> + } / / namespace torch <nl> new file mode 100644 <nl> index 000000000000 . . 775e960233e4 <nl> mmm / dev / null <nl> ppp b / torch / csrc / utils / memory . h <nl> <nl> + # pragma once <nl> + <nl> + # include < memory > <nl> + <nl> + namespace torch { <nl> + <nl> + / / Reference : <nl> + / / https : / / github . com / llvm - mirror / libcxx / blob / master / include / memory # L3091 <nl> + <nl> + template < typename T > <nl> + struct unique_type_for { <nl> + using value = std : : unique_ptr < T > ; <nl> + } ; <nl> + <nl> + template < typename T > <nl> + struct unique_type_for < T [ ] > { <nl> + using unbounded_array = std : : unique_ptr < T [ ] > ; <nl> + } ; <nl> + <nl> + template < typename T , size_t N > <nl> + struct unique_type_for < T [ N ] > { <nl> + using bounded_array = void ; <nl> + } ; <nl> + <nl> + template < typename T , typename . . . Args > <nl> + typename unique_type_for < T > : : value make_unique ( Args & & . . . args ) { <nl> + return std : : unique_ptr < T > ( new T ( std : : forward < Args > ( args ) . . . ) ) ; <nl> + } <nl> + <nl> + template < typename T > <nl> + typename unique_type_for < T > : : unbounded_array make_unique ( size_t size ) { <nl> + using U = typename std : : remove_extent < T > : : type ; <nl> + return std : : unique_ptr < T > ( new U [ size ] ( ) ) ; <nl> + } <nl> + <nl> + template < typename T , size_t N , typename . . . Args > <nl> + typename unique_type_for < T > : : bounded_array make_unique ( Args & & . . . ) = delete ; <nl> + } / / namespace torch <nl> mmm a / torch / csrc / utils / variadic . h <nl> ppp b / torch / csrc / utils / variadic . h <nl> <nl> # include " torch / csrc / autograd / variable . h " <nl> <nl> # include < cstdint > <nl> - # include < utility > <nl> # include < tuple > <nl> # include < type_traits > <nl> + # include < utility > <nl> <nl> namespace torch { <nl> <nl> namespace torch { <nl> template < typename F > <nl> struct IterArgs { <nl> template < typename . . . Args > <nl> - inline F & apply ( ) { return self ( ) ; } <nl> + inline F & apply ( ) { <nl> + return self ( ) ; <nl> + } <nl> <nl> / / NB : Use perfect forwarding here , otherwise we ' ll make value <nl> / / copies of all arguments ! <nl> struct IterArgs { <nl> void operator ( ) ( at : : ArrayRef < T > args ) { <nl> for ( const auto & arg : args ) { <nl> self ( ) ( arg ) ; <nl> - if ( short_circuit ( ) ) return ; <nl> + if ( short_circuit ( ) ) <nl> + return ; <nl> } <nl> } <nl> <nl> struct IterArgs { <nl> self ( ) ( at : : ArrayRef < T > { args } ) ; <nl> } <nl> <nl> - bool short_circuit ( ) { return false ; } <nl> + bool short_circuit ( ) { <nl> + return false ; <nl> + } <nl> <nl> - private : <nl> + private : <nl> inline F & self ( ) { <nl> return * static_cast < F * > ( this ) ; <nl> } <nl> struct IterArgs { <nl> <nl> struct CountTensors : IterArgs < CountTensors > { <nl> size_t out = 0 ; <nl> - void operator ( ) ( const at : : Tensor & x ) { out + = 1 ; } <nl> - void operator ( ) ( at : : ArrayRef < at : : Tensor > xs ) { out + = xs . size ( ) ; } <nl> + void operator ( ) ( const at : : Tensor & x ) { <nl> + out + = 1 ; <nl> + } <nl> + void operator ( ) ( at : : ArrayRef < at : : Tensor > xs ) { <nl> + out + = xs . size ( ) ; <nl> + } <nl> } ; <nl> <nl> template < typename . . . Args > <nl> size_t count_tensors ( Args & & . . . args ) { <nl> <nl> struct CountVariables : IterArgs < CountVariables > { <nl> size_t out = 0 ; <nl> - void operator ( ) ( const autograd : : Variable & x ) { out + = 1 ; } <nl> - void operator ( ) ( at : : ArrayRef < autograd : : Variable > xs ) { out + = xs . size ( ) ; } <nl> + void operator ( ) ( const autograd : : Variable & x ) { <nl> + out + = 1 ; <nl> + } <nl> + void operator ( ) ( at : : ArrayRef < autograd : : Variable > xs ) { <nl> + out + = xs . size ( ) ; <nl> + } <nl> } ; <nl> <nl> - template < typename . . . Args > <nl> + template < typename . . . Args > <nl> inline size_t count_variables ( Args & & . . . args ) { <nl> return CountVariables ( ) . apply ( std : : forward < Args > ( args ) . . . ) . out ; <nl> } <nl> inline size_t count_variables ( Args & & . . . args ) { <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> / / A container of type - template parameter indices . <nl> - template < size_t . . . Is > <nl> + template < size_t . . . Is > <nl> struct Indices { } ; <nl> <nl> / / Decrements the index N , adds N - 1 to the list of indices and forwards <nl> / / whatever we arleady have . <nl> - template < size_t N , size_t . . . Is > <nl> - struct MakeIndices : MakeIndices < N - 1 , N - 1 , Is . . . > { } ; <nl> + template < size_t N , size_t . . . Is > <nl> + struct MakeIndices : MakeIndices < N - 1 , N - 1 , Is . . . > { } ; <nl> <nl> / / Partial specialization that forms our base case . When N is zero , we stop <nl> / / and define a typedef that will be visible to earlier classes due to <nl> / / inheritance . The typedef we define is an index list containing the numbers <nl> / / 0 through N - 1 . <nl> - template < size_t . . . Is > <nl> - struct MakeIndices < 0 , Is . . . > { using indices = Indices < Is . . . > ; } ; <nl> + template < size_t . . . Is > <nl> + struct MakeIndices < 0 , Is . . . > { <nl> + using indices = Indices < Is . . . > ; <nl> + } ; <nl> + <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + / / Utilities <nl> + / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> + <nl> + template < bool value , typename T = void > <nl> + using enable_if_t = typename std : : enable_if < value , T > : : type ; <nl> + <nl> + template < bool value , typename T = void > <nl> + using disable_if_t = enable_if_t < ! value , T > ; <nl> + <nl> + template < typename T > <nl> + using decay_t = typename std : : decay < T > : : type ; <nl> + <nl> + namespace detail { <nl> + template < bool . . . > <nl> + struct pack ; <nl> + } / / namespace detail <nl> + <nl> + template < bool . . . values > <nl> + struct all_of : std : : is_same < <nl> + detail : : pack < values . . . , true > , <nl> + detail : : pack < true , values . . . > > { } ; <nl> + <nl> + template < bool . . . > <nl> + struct any_of ; <nl> + <nl> + template < > <nl> + struct any_of < > : std : : false_type { } ; <nl> + <nl> + template < bool head , bool . . . tail > <nl> + struct any_of < head , tail . . . > { <nl> + static constexpr bool value = head | | any_of < tail . . . > : : value ; <nl> + } ; <nl> + <nl> + template < bool . . . values > <nl> + struct none_of { <nl> + static constexpr bool value = ! any_of < values . . . > : : value ; <nl> + } ; <nl> + <nl> + template < bool . . . values > <nl> + using enable_if_all_of_t = enable_if_t < all_of < values . . . > : : value > ; <nl> + <nl> + template < typename T , typename . . . Ts > <nl> + using disable_if_contains_t = <nl> + enable_if_all_of_t < ( ! std : : is_same < T , decay_t < Ts > > : : value ) . . . > ; <nl> + <nl> + template < typename Function , typename . . . Ts > <nl> + void apply ( Function function , Ts & & . . . ts ) { <nl> + / / <nl> + / / https : / / stackoverflow . com / questions / 13978916 / inserting - a - variadic - argument - list - into - a - vector <nl> + / / Creates a dummy array , so that each function call is evaluated in order . <nl> + / / ` ( function ( ) , 0 ) ` is because ` function ` should ( ! ) return ` void ` , so <nl> + / / according to the comma operator , it is evaluated and its result ( ` void ` ) <nl> + / / is discarded . Then the zero is evaluated and used as an element in the <nl> + / / array . The first zero ensures the array is not empty . <nl> + int _ [ ] { 0 , ( function ( std : : forward < Ts > ( ts ) ) , 0 ) . . . } ; <nl> + ( void ) _ ; <nl> + } <nl> + <nl> + template < typename . . . Ts , typename Function , typename Accessor > <nl> + auto unpack ( Function function , Accessor accessor ) <nl> + - > decltype ( function ( std : : declval < Ts > ( ) . . . ) ) { <nl> + return unpack < Ts . . . > ( <nl> + std : : move ( function ) , <nl> + std : : move ( accessor ) , <nl> + typename MakeIndices < sizeof . . . ( Ts ) > : : indices ( ) ) ; <nl> + } <nl> + <nl> + template < typename . . . Ts , typename Function , typename Accessor , size_t . . . Is > <nl> + auto unpack ( Function function , Accessor accessor , Indices < Is . . . > ) <nl> + - > decltype ( function ( std : : declval < Ts > ( ) . . . ) ) { <nl> + return function ( accessor . template operator ( ) < Ts > ( Is ) . . . ) ; <nl> + } <nl> } / / namespace torch <nl>
[ C + + API ] Remove virtual forward and implement Sequential based on Any ( Module ) ( )
pytorch/pytorch
b12164005fe60d58b7f613411ad8c9b6ae549946
2018-05-24T19:46:51Z
mmm a / Code / CryEngine / CryAISystem / Navigation / MNM / TileGenerator . cpp <nl> ppp b / Code / CryEngine / CryAISystem / Navigation / MNM / TileGenerator . cpp <nl> <nl> <nl> namespace MNM <nl> { <nl> - / / Code relies on the ordering ( specifically we must list l / r / u / d cyclically before corners ) <nl> + / / Code relies on the ordering ( specifically we must list u / r / d / l cyclically before corners ) <nl> static const int NeighbourOffset_TileGenerator [ 8 ] [ 2 ] = <nl> { <nl> - { 0 , 1 } , <nl> - { - 1 , 0 } , <nl> - { 1 , 0 } , <nl> - { 0 , - 1 } , <nl> - { - 1 , - 1 } , <nl> - { 1 , - 1 } , <nl> - { 1 , 1 } , <nl> - { - 1 , 1 } , } ; <nl> + { 0 , - 1 } , <nl> + { 1 , 0 } , <nl> + { 0 , 1 } , <nl> + { - 1 , 0 } , <nl> + { - 1 , - 1 } , <nl> + { 1 , - 1 } , <nl> + { 1 , 1 } , <nl> + { - 1 , 1 } , <nl> + } ; <nl> <nl> / * <nl> Expanded s_CornerTable , easier to read <nl> void CTileGenerator : : FilterWalkable ( const AABB & aabb , bool fullyContained ) <nl> <nl> size_t nonWalkableCount = 0 ; <nl> <nl> + / / First pass - clearance is set here <nl> + nonWalkableCount + = FilterWalkable_CheckBackfaceDepthAndClearance ( filterParams ) ; <nl> + <nl> + / / Second pass - clearance is used when checking neighbouring spans <nl> + nonWalkableCount + = FilterWalkable_CheckNeighboursAndInclination ( filterParams ) ; <nl> + <nl> + / / Apply navigation area and exclude area boundaries <nl> + if ( ! fullyContained ) <nl> + { <nl> + nonWalkableCount + = FilterWalkable_CheckBoundaries ( aabb , filterParams . gridWidth , filterParams . gridHeight ) ; <nl> + } <nl> + <nl> + CompactSpanGrid compact ; <nl> + compact . CompactExcluding ( m_spanGrid , NotWalkable , m_spanGrid . GetSpanCount ( ) - nonWalkableCount ) ; <nl> + <nl> + m_profiler . AddMemory ( CompactSpanGridMemory , compact . GetMemoryUsage ( ) ) ; <nl> + <nl> + compact . Swap ( m_spanGrid ) ; <nl> + <nl> + m_profiler . StopTimer ( Filter ) ; <nl> + <nl> + if ( m_params . flags & Params : : DebugInfo ) <nl> + m_spanGridFlagged . Swap ( compact ) ; <nl> + else <nl> + m_profiler . FreeMemory ( CompactSpanGridMemory , compact . GetMemoryUsage ( ) ) ; <nl> + } <nl> + <nl> + size_t CTileGenerator : : FilterWalkable_CheckBackfaceDepthAndClearance ( const SFilterWalkableParams & filterParams ) <nl> + { <nl> + size_t nonWalkableCount = 0 ; <nl> + <nl> for ( size_t y = 0 ; y < filterParams . gridHeight ; + + y ) <nl> { <nl> const size_t ymult = y * filterParams . gridWidth ; <nl> void CTileGenerator : : FilterWalkable ( const AABB & aabb , bool fullyContained ) <nl> <nl> span . flags | = boundaryFlag ; <nl> <nl> - if ( ! FilterWalkableSpan ( span , spanCoord , cell , filterParams ) ) <nl> + if ( ! FilterWalkableSpanAndSetClearance ( span , spanCoord , cell , filterParams ) ) <nl> { <nl> span . flags | = NotWalkable ; <nl> + + nonWalkableCount ; <nl> } <nl> } / / for s <nl> - } / / if cell <nl> - } / / for x <nl> - } / / for y <nl> + } / / if cell <nl> + } / / for x <nl> + } / / for y <nl> <nl> - / / apply boundaries <nl> - if ( ! fullyContained ) <nl> + return nonWalkableCount ; <nl> + } <nl> + <nl> + size_t CTileGenerator : : FilterWalkable_CheckNeighboursAndInclination ( const SFilterWalkableParams & filterParams ) <nl> + { <nl> + size_t nonWalkableCount = 0 ; <nl> + <nl> + for ( size_t y = 0 ; y < filterParams . gridHeight ; + + y ) <nl> { <nl> - FilterWalkable_CheckBoundaries ( aabb , filterParams . gridWidth , filterParams . gridHeight ) ; <nl> - } <nl> + const size_t ymult = y * filterParams . gridWidth ; <nl> <nl> - / / TODO pavloi 2016 . 03 . 10 : CheckBoundaries is not adding to nonWalkableCount , so new compact grid will <nl> - / / reserve more spans than required . <nl> - CompactSpanGrid compact ; <nl> - compact . CompactExcluding ( m_spanGrid , NotWalkable , m_spanGrid . GetSpanCount ( ) - nonWalkableCount ) ; <nl> + for ( size_t x = 0 ; x < filterParams . gridWidth ; + + x ) <nl> + { <nl> + if ( const CompactSpanGrid : : Cell cell = m_spanGrid [ x + ymult ] ) <nl> + { <nl> + const size_t count = cell . count ; <nl> <nl> - m_profiler . AddMemory ( CompactSpanGridMemory , compact . GetMemoryUsage ( ) ) ; <nl> + for ( size_t s = 0 ; s < count ; + + s ) <nl> + { <nl> + CompactSpanGrid : : Span & span = m_spanGrid . GetSpan ( cell . index + s ) ; <nl> + if ( span . flags & NotWalkable ) <nl> + continue ; <nl> <nl> - / / TODO pavloi 2016 . 03 . 10 : m_spanGrid is used to visualize " Raw voxels " , but actually contains <nl> - / / only walkable voxels after this point . m_spanGridFlagged contains all ( but already flagged ) voxels . <nl> - compact . Swap ( m_spanGrid ) ; <nl> + const SSpanCoord spanCoord ( x , y , s , cell . index + s ) ; <nl> <nl> - m_profiler . StopTimer ( Filter ) ; <nl> + SNonWalkableNeighbourReason * pNeighbourReason = nullptr ; <nl> + # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> + SNonWalkableNeighbourReason neighbourReason ; <nl> + IF_UNLIKELY ( m_params . flags & Params : : DebugInfo ) <nl> + { <nl> + pNeighbourReason = & neighbourReason ; <nl> + } <nl> + # endif <nl> <nl> - if ( m_params . flags & Params : : DebugInfo ) <nl> - m_spanGridFlagged . Swap ( compact ) ; <nl> - else <nl> - m_profiler . FreeMemory ( CompactSpanGridMemory , compact . GetMemoryUsage ( ) ) ; <nl> + const size_t spanTop = span . bottom + span . height ; <nl> + if ( FilterWalkableSpan_CheckNeighbours ( spanCoord , spanTop , spanTop + span . clearance , filterParams , pNeighbourReason ) ) <nl> + { <nl> + if ( pNeighbourReason ) <nl> + DebugAddNonWalkableReason ( spanCoord , SNonWalkableReason ( " neighbour " , * pNeighbourReason ) ) ; <nl> + <nl> + span . flags | = NotWalkable ; <nl> + + + nonWalkableCount ; <nl> + } <nl> + } / / for s <nl> + } / / if cell <nl> + } / / for x <nl> + } / / for y <nl> + <nl> + return nonWalkableCount ; <nl> } <nl> <nl> - bool CTileGenerator : : FilterWalkableSpan ( CompactSpanGrid : : Span & span , const SSpanCoord & spanCoord , const CompactSpanGrid : : Cell & cell , const SFilterWalkableParams & filterParams ) <nl> + bool CTileGenerator : : FilterWalkableSpanAndSetClearance ( CompactSpanGrid : : Span & span , const SSpanCoord & spanCoord , const CompactSpanGrid : : Cell & cell , const SFilterWalkableParams & filterParams ) <nl> { <nl> - if ( FilterWalkable_CheckSpanBackface ( span ) ) <nl> + if ( FilterWalkableSpan_CheckBackface ( span ) ) <nl> { <nl> DebugAddNonWalkableReason ( spanCoord , " backface " ) ; <nl> return false ; <nl> } <nl> <nl> - if ( FilterWalkable_CheckSpanWaterDepth ( span , m_params ) ) <nl> + if ( FilterWalkableSpan_CheckWaterDepth ( span , m_params ) ) <nl> { <nl> DebugAddNonWalkableReason ( spanCoord , " water " ) ; <nl> return false ; <nl> bool CTileGenerator : : FilterWalkableSpan ( CompactSpanGrid : : Span & span , const SSpan <nl> <nl> const SSpanClearance spanClearance ( spanCoord , span , cell , filterParams , m_spanGrid ) ; <nl> const size_t clearanceValue = spanClearance . Clearance ( ) ; <nl> + span . clearance = clearanceValue ; <nl> if ( clearanceValue < filterParams . heightVoxelCount ) <nl> { <nl> if ( clearanceValue > = filterParams . minValidHeightVoxelCount ) <nl> { <nl> span . flags | = LessThanAgentHeight ; <nl> - span . clearance = clearanceValue ; <nl> } <nl> else <nl> { <nl> bool CTileGenerator : : FilterWalkableSpan ( CompactSpanGrid : : Span & span , const SSpan <nl> return false ; <nl> } <nl> } <nl> - <nl> - SNonWalkableNeighbourReason * pNeighbourReason = nullptr ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - SNonWalkableNeighbourReason neighbourReason ; <nl> - IF_UNLIKELY ( m_params . flags & Params : : DebugInfo ) <nl> - { <nl> - pNeighbourReason = & neighbourReason ; <nl> - } <nl> - # endif <nl> - <nl> - if ( FilterWalkable_CheckNeighbours ( spanCoord , spanClearance , filterParams , pNeighbourReason ) ) <nl> - { <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - if ( pNeighbourReason ) <nl> - { <nl> - m_debugNonWalkableReasonMap [ spanCoord ] = SNonWalkableReason ( " neighbour " , * pNeighbourReason ) ; <nl> - } <nl> - # endif <nl> - return false ; <nl> - } <nl> return true ; <nl> } <nl> <nl> - / * static * / bool CTileGenerator : : FilterWalkable_CheckSpanBackface ( const CompactSpanGrid : : Span & span ) <nl> + / * static * / bool CTileGenerator : : FilterWalkableSpan_CheckBackface ( const CompactSpanGrid : : Span & span ) <nl> { <nl> return span . backface ; <nl> } <nl> <nl> - / * static * / bool CTileGenerator : : FilterWalkable_CheckSpanWaterDepth ( const CompactSpanGrid : : Span & span , const Params & params ) <nl> + / * static * / bool CTileGenerator : : FilterWalkableSpan_CheckWaterDepth ( const CompactSpanGrid : : Span & span , const Params & params ) <nl> { <nl> return span . depth > params . agent . maxWaterDepth ; <nl> } <nl> <nl> - / * static * / bool CTileGenerator : : FilterWalkable_CheckNeighbours ( const SSpanCoord & spanCoord , const SSpanClearance & spanClearance , const SFilterWalkableParams & filterParams , SNonWalkableNeighbourReason * pOutReason ) <nl> + struct CTileGenerator : : SWalkableProbeCheckParams <nl> { <nl> - const size_t axisNeighbourCount = 4 ; <nl> + SWalkableProbeCheckParams ( const SSpanCoord & spanCoord , const SFilterWalkableParams & filterParams , const size_t originTop , SNonWalkableNeighbourReason * pOutReason ) <nl> + : spanCoord ( spanCoord ) <nl> + , filterParams ( filterParams ) <nl> + , originTop ( originTop ) <nl> + , pOutReason ( pOutReason ) <nl> + { } <nl> + <nl> + const SSpanCoord & spanCoord ; <nl> + const SFilterWalkableParams & filterParams ; <nl> + const size_t originTop ; <nl> + SNonWalkableNeighbourReason * pOutReason ; <nl> + size_t dir ; <nl> + size_t firstProbeSpanTop ; <nl> + size_t firstProbeSpanNextBottom ; <nl> + size_t firstSpanTopDiffAbsolute ; <nl> + int firstSpanTopDiffSigned ; <nl> + } ; <nl> + <nl> + / * static * / bool CTileGenerator : : CheckWalkableProbeStep ( const SWalkableProbeCheckParams & params ) <nl> + { <nl> + const size_t stepTestCount = size_t ( ceil ( params . firstSpanTopDiffAbsolute * params . filterParams . climbableStepRatio ) ) ; <nl> + const size_t stepTestTolerance = size_t ( ceil ( stepTestCount * params . filterParams . climbableStepRatio ) ) - 1 ; <nl> <nl> - bool neighbourTest ( true ) ; <nl> + bool failedStepTest = false ; <nl> <nl> - float probeInclinationVars [ axisNeighbourCount ] = { 0 . 0f } ; <nl> + size_t probeSpansTopDiffMax = params . firstSpanTopDiffAbsolute ; <nl> + size_t lastSpanTop = params . firstProbeSpanTop ; <nl> + size_t lastSpanNextBottom = params . firstProbeSpanNextBottom ; <nl> <nl> - for ( size_t n = 0 ; n < axisNeighbourCount ; + + n ) <nl> + / / The first neighbour to the starting span is checked already , start with the next one <nl> + for ( size_t probeIdx = 2 ; probeIdx < = stepTestCount ; + + probeIdx ) <nl> { <nl> - const size_t nx = spanCoord . cellX + NeighbourOffset_TileGenerator [ n ] [ 0 ] ; <nl> - const size_t ny = spanCoord . cellY + NeighbourOffset_TileGenerator [ n ] [ 1 ] ; <nl> + const size_t px = params . spanCoord . cellX + NeighbourOffset_TileGenerator [ params . dir ] [ 0 ] * probeIdx ; <nl> + const size_t py = params . spanCoord . cellY + NeighbourOffset_TileGenerator [ params . dir ] [ 1 ] * probeIdx ; <nl> <nl> - / / Neighbour off grid - pass <nl> - / / NOTE : ( 0 - 1 ) will underflow to size_t : : max , which is also > gridWidth . <nl> - if ( nx > = filterParams . gridWidth | | ny > = filterParams . gridHeight ) <nl> - continue ; <nl> + const CompactSpanGrid : : Cell pcell = params . filterParams . spanGrid . GetCell ( px , py ) ; <nl> <nl> - const size_t neighbourCellGridIndex = ( ny * filterParams . gridWidth ) + nx ; <nl> - const CompactSpanGrid : : Cell & ncell = filterParams . spanGrid [ neighbourCellGridIndex ] ; <nl> - if ( ! ncell ) <nl> + if ( ! pcell ) <nl> + break ; / / Empty neighbour - stop probe ( but no fail ) <nl> + <nl> + const size_t pcount = pcell . count ; <nl> + const size_t pindex = pcell . index ; <nl> + <nl> + bool isCellValid = false ; <nl> + <nl> + for ( size_t ps = 0 ; ps < pcount ; + + ps ) <nl> { <nl> - / / Empty neighbour on grid - fail <nl> - neighbourTest = false ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( pOutReason ) <nl> + const size_t psindex = pindex + ps ; <nl> + const CompactSpanGrid : : Span & probeSpan = params . filterParams . spanGrid . GetSpan ( psindex ) ; <nl> + <nl> + const size_t probeSpanTop = probeSpan . bottom + probeSpan . height ; <nl> + const size_t probeSpanNextBottom = probeSpanTop + probeSpan . clearance ; <nl> + <nl> + const int probeSpanTopDiffSigned = probeSpanTop - lastSpanTop ; <nl> + const size_t probeSpanTopDiffAbsolute = abs ( probeSpanTopDiffSigned ) ; <nl> + <nl> + / / Test validity <nl> + if ( probeSpanTopDiffAbsolute < = params . filterParams . climbableVoxelCount <nl> + & & min ( lastSpanNextBottom , probeSpanNextBottom ) > = max ( lastSpanTop , probeSpanTop ) + params . filterParams . minValidHeightVoxelCount ) <nl> { <nl> - pOutReason - > szReason = " empty " ; <nl> + const size_t pTopOffs = abs ( int ( probeSpanTop - params . originTop ) ) ; <nl> + probeSpansTopDiffMax = max ( probeSpansTopDiffMax , pTopOffs ) ; <nl> + <nl> + lastSpanTop = probeSpanTop ; <nl> + lastSpanNextBottom = probeSpanNextBottom ; <nl> + <nl> + isCellValid = true ; <nl> + <nl> + break ; <nl> } <nl> - # endif <nl> + } <nl> + <nl> + if ( ! isCellValid ) <nl> break ; <nl> + <nl> + if ( probeSpansTopDiffMax > stepTestTolerance + params . firstSpanTopDiffAbsolute ) <nl> + { <nl> + failedStepTest = true ; <nl> } <nl> + } / / for all probes in the direction <nl> <nl> - const size_t ncount = ncell . count ; <nl> - const size_t nindex = ncell . index ; <nl> + if ( failedStepTest & & ( probeSpansTopDiffMax > params . filterParams . climbableVoxelCount ) ) <nl> + { <nl> + return false ; <nl> + } <nl> + return true ; <nl> + } <nl> <nl> - size_t ptopLast ; <nl> - size_t pnextBottomLast ; <nl> - size_t dpTopFirst ; <nl> - size_t dpTopLast ; <nl> + / * static * / bool CTileGenerator : : CheckWalkableProbeIncline ( const SWalkableProbeCheckParams & params , float * probeInclinationVars ) <nl> + { <nl> + const size_t probeTestCount = params . filterParams . inclineTestCount ; <nl> <nl> - int sdpTopFirst ; <nl> - int sdpTopLast ; <nl> + size_t probeSpansTopMin = params . firstProbeSpanTop ; <nl> + size_t probeSpansTopMax = params . firstProbeSpanTop ; <nl> + size_t lastSpanTop = params . firstProbeSpanTop ; <nl> + size_t lastSpanNextBottom = params . firstProbeSpanNextBottom ; <nl> <nl> - / / Assume this neighbour cell is not valid . Succeed when we find just one valid adjacent span <nl> - bool nCellValid ( false ) ; <nl> + / / The first neighbour to the starting span is checked already , start with the next one <nl> + size_t probeIdx = 2 ; <nl> + for ( ; probeIdx < = probeTestCount ; + + probeIdx ) <nl> + { <nl> + const size_t px = params . spanCoord . cellX + NeighbourOffset_TileGenerator [ params . dir ] [ 0 ] * probeIdx ; <nl> + const size_t py = params . spanCoord . cellY + NeighbourOffset_TileGenerator [ params . dir ] [ 1 ] * probeIdx ; <nl> <nl> - for ( size_t ns = 0 ; ns < ncount ; + + ns ) <nl> + const CompactSpanGrid : : Cell probeCell = params . filterParams . spanGrid . GetCell ( px , py ) ; <nl> + <nl> + if ( ! probeCell ) <nl> + break ; / / Empty neighbour - stop probe ( but no fail ) <nl> + <nl> + bool isCellValid = false ; <nl> + int lastSpanTopDiffSigned ; <nl> + <nl> + const size_t pcount = probeCell . count ; <nl> + const size_t pindex = probeCell . index ; <nl> + <nl> + for ( size_t ps = 0 ; ps < pcount ; + + ps ) <nl> { <nl> - const size_t nsindex = nindex + ns ; <nl> - const CompactSpanGrid : : Span & nspan = filterParams . spanGrid . GetSpan ( nsindex ) ; <nl> + const size_t psindex = pindex + ps ; <nl> + const CompactSpanGrid : : Span & probeSpan = params . filterParams . spanGrid . GetSpan ( psindex ) ; <nl> <nl> - const SSpanCoord neighbourCoord ( nx , ny , ns , nsindex ) ; <nl> - const SSpanClearance neighbourClearance ( neighbourCoord , nspan , ncell , filterParams , filterParams . spanGrid ) ; <nl> + const size_t probeSpanTop = probeSpan . bottom + probeSpan . height ; <nl> + const size_t probeSpanNextBottom = probeSpanTop + probeSpan . clearance ; <nl> <nl> - const size_t dTop = ( size_t ) abs ( ( int ) ( neighbourClearance . top - spanClearance . top ) ) ; <nl> + const int probeSpanTopDiffSigned = probeSpanTop - lastSpanTop ; <nl> + const size_t probeSpanTopDiffAbsolute = abs ( probeSpanTopDiffSigned ) ; <nl> <nl> / / Test validity <nl> - if ( dTop < = filterParams . climbableVoxelCount <nl> - & & min ( spanClearance . nextBottom , neighbourClearance . nextBottom ) > = max ( spanClearance . top , neighbourClearance . top ) + filterParams . minValidHeightVoxelCount ) <nl> + if ( probeSpanTopDiffAbsolute < = params . filterParams . climbableVoxelCount <nl> + & & min ( lastSpanNextBottom , probeSpanNextBottom ) > = max ( lastSpanTop , probeSpanTop ) + params . filterParams . minValidHeightVoxelCount ) <nl> { <nl> - ptopLast = neighbourClearance . top ; <nl> - pnextBottomLast = neighbourClearance . nextBottom ; <nl> - dpTopFirst = dpTopLast = dTop ; <nl> + / / Track range of tops in probe <nl> + probeSpansTopMin = min ( probeSpansTopMin , probeSpanTop ) ; <nl> + probeSpansTopMax = max ( probeSpansTopMax , probeSpanTop ) ; <nl> + <nl> + lastSpanTopDiffSigned = probeSpanTopDiffSigned ; <nl> <nl> - sdpTopFirst = sdpTopLast = int ( neighbourClearance . top ) - int ( spanClearance . top ) ; <nl> + lastSpanTop = probeSpanTop ; <nl> + lastSpanNextBottom = probeSpanNextBottom ; <nl> <nl> - nCellValid = true ; <nl> + isCellValid = true ; <nl> <nl> break ; <nl> } <nl> } <nl> <nl> - if ( ! nCellValid ) <nl> - { <nl> - neighbourTest = false ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( pOutReason ) <nl> - { <nl> - pOutReason - > szReason = " clearance " ; <nl> - } <nl> - # endif <nl> + if ( ! isCellValid ) <nl> break ; <nl> - } <nl> <nl> - if ( dpTopFirst > 0 ) <nl> + if ( lastSpanTopDiffSigned > params . firstSpanTopDiffSigned + 1 | | lastSpanTopDiffSigned < params . firstSpanTopDiffSigned - 1 ) <nl> { <nl> - size_t const stepTestCount ( ( size_t ) ceil ( dpTopFirst * filterParams . climbableStepRatio ) ) ; <nl> - size_t const stepTestTolerance ( stepTestCount - 1 ) ; <nl> - bool const isStep ( dpTopFirst > ( filterParams . climbableInclineGradientLowerBound + 1 ) ) ; <nl> - bool stepTest ( true ) ; <nl> - <nl> - AIAssert ( stepTestCount < = filterParams . inclineTestCount ) ; <nl> - <nl> - size_t ptopMin ( ptopLast ) ; <nl> - size_t ptopMax ( ptopLast ) ; <nl> - <nl> - size_t pTopOffsMax ( dpTopFirst ) ; <nl> + / / stop probe ( but no fail ) <nl> + break ; <nl> + } <nl> + } / / for all probes in the direction <nl> <nl> - size_t pc ( 2 ) ; <nl> + const size_t checkedProbesDist = probeIdx - 2 ; <nl> + if ( checkedProbesDist > 0 ) <nl> + { <nl> + const float inclinationValue = float ( probeSpansTopMax - probeSpansTopMin ) / checkedProbesDist ; <nl> + if ( inclinationValue > params . filterParams . climbableInclineGradient ) <nl> + return false ; <nl> <nl> - for ( ; pc < = filterParams . inclineTestCount ; + + pc ) <nl> - { <nl> - size_t px = spanCoord . cellX + NeighbourOffset_TileGenerator [ n ] [ 0 ] * pc ; <nl> - size_t py = spanCoord . cellY + NeighbourOffset_TileGenerator [ n ] [ 1 ] * pc ; <nl> + probeInclinationVars [ params . dir ] = inclinationValue ; <nl> + } <nl> + return true ; <nl> + } <nl> <nl> - const CompactSpanGrid : : Cell pcell = filterParams . spanGrid . GetCell ( px , py ) ; <nl> + # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> + # define MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , szReasonName ) \ <nl> + IF_UNLIKELY ( pOutReason ) { pOutReason - > szReason = szReasonName ; } <nl> + # else <nl> + # define MNM_SET_NONWALKABLE_FAIL_REASON <nl> + # endif <nl> <nl> - if ( ! pcell ) <nl> - { <nl> - / / Empty neighbour - stop probe ( but no fail ) <nl> - break ; <nl> - } <nl> + / * static * / bool CTileGenerator : : FilterWalkableSpan_CheckNeighbours ( const SSpanCoord & spanCoord , const size_t originTop , const size_t originNextBottom , const SFilterWalkableParams & filterParams , SNonWalkableNeighbourReason * pOutReason ) <nl> + { <nl> + const size_t axisNeighbourCount = 4 ; <nl> <nl> - const size_t pcount = pcell . count ; <nl> - const size_t pindex = pcell . index ; <nl> + SWalkableProbeCheckParams probesParams ( spanCoord , filterParams , originTop , pOutReason ) ; <nl> <nl> - for ( size_t ps = 0 ; ps < pcount ; + + ps ) <nl> - { <nl> - const size_t psindex = pindex + ps ; <nl> - const CompactSpanGrid : : Span & pspan = filterParams . spanGrid . GetSpan ( psindex ) ; <nl> + float probeInclinationVars [ axisNeighbourCount ] = { 0 . 0f } ; <nl> <nl> - const SSpanCoord probeCoord ( px , py , ps , psindex ) ; <nl> - const SSpanClearance probeClearance ( probeCoord , pspan , pcell , filterParams , filterParams . spanGrid ) ; <nl> + for ( size_t dir = 0 ; dir < axisNeighbourCount ; + + dir ) <nl> + { <nl> + const size_t nx = spanCoord . cellX + NeighbourOffset_TileGenerator [ dir ] [ 0 ] ; <nl> + const size_t ny = spanCoord . cellY + NeighbourOffset_TileGenerator [ dir ] [ 1 ] ; <nl> <nl> - const size_t dpTop = ( size_t ) abs ( ( int ) ( probeClearance . top - ptopLast ) ) ; <nl> + / / Neighbour off grid - pass <nl> + / / NOTE : ( 0 - 1 ) will underflow to size_t : : max , which is also > gridWidth . <nl> + if ( nx > = filterParams . gridWidth | | ny > = filterParams . gridHeight ) <nl> + continue ; <nl> <nl> - / / Test validity <nl> - if ( dpTop < = filterParams . climbableVoxelCount <nl> - & & min ( pnextBottomLast , probeClearance . nextBottom ) > = max ( ptopLast , probeClearance . top ) + filterParams . minValidHeightVoxelCount ) <nl> - { <nl> - / / Track range of tops in probe <nl> - ptopMin = min ( ptopMin , probeClearance . top ) ; <nl> - ptopMax = max ( ptopMax , probeClearance . top ) ; <nl> + const size_t neighbourCellGridIndex = ( ny * filterParams . gridWidth ) + nx ; <nl> + const CompactSpanGrid : : Cell & ncell = filterParams . spanGrid [ neighbourCellGridIndex ] ; <nl> + if ( ! ncell ) <nl> + { <nl> + / / Empty neighbour on grid - fail <nl> + MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , " empty " ) ; <nl> + return true ; <nl> + } <nl> <nl> - const size_t pTopOffs = ( size_t ) abs ( int ( probeClearance . top ) - int ( spanClearance . top ) ) ; <nl> - pTopOffsMax = max ( pTopOffsMax , pTopOffs ) ; <nl> + const size_t ncount = ncell . count ; <nl> + const size_t nindex = ncell . index ; <nl> <nl> - sdpTopLast = ( int ) ( probeClearance . top - ptopLast ) ; <nl> + / / Assume this neighbour cell is not valid . Succeed when we find just one valid adjacent span . <nl> + bool isCellValid = false ; <nl> <nl> - ptopLast = probeClearance . top ; <nl> - pnextBottomLast = probeClearance . nextBottom ; <nl> - dpTopLast = dpTop ; <nl> + for ( size_t ns = 0 ; ns < ncount ; + + ns ) <nl> + { <nl> + const size_t nsindex = nindex + ns ; <nl> + const CompactSpanGrid : : Span & nspan = filterParams . spanGrid . GetSpan ( nsindex ) ; <nl> <nl> - nCellValid = true ; <nl> + const size_t nSpanTop = nspan . bottom + nspan . height ; <nl> + const size_t nSpanNextBottom = nSpanTop + nspan . clearance ; <nl> <nl> - break ; <nl> - } <nl> - } <nl> + const int sdTop = nSpanTop - originTop ; <nl> + const size_t dTop = abs ( sdTop ) ; <nl> <nl> - if ( ! nCellValid ) <nl> - { <nl> - break ; <nl> - } <nl> + / / Test validity of neighbour span . <nl> + if ( dTop < = filterParams . climbableVoxelCount <nl> + & & min ( originNextBottom , nSpanNextBottom ) > = max ( originTop , nSpanTop ) + filterParams . minValidHeightVoxelCount ) <nl> + { <nl> + probesParams . firstProbeSpanTop = nSpanTop ; <nl> + probesParams . firstProbeSpanNextBottom = nSpanNextBottom ; <nl> + probesParams . firstSpanTopDiffAbsolute = dTop ; <nl> + probesParams . firstSpanTopDiffSigned = sdTop ; <nl> + probesParams . dir = dir ; <nl> + isCellValid = true ; <nl> + break ; <nl> + } <nl> + } <nl> <nl> - if ( isStep ) <nl> - { <nl> - if ( pc < = stepTestCount <nl> - & & pTopOffsMax > stepTestTolerance + dpTopFirst ) <nl> - { <nl> - stepTest = false ; <nl> - } <nl> - } <nl> - else <nl> - { <nl> - if ( sdpTopLast > sdpTopFirst + 1 <nl> - | | sdpTopLast < sdpTopFirst - 1 ) <nl> - { <nl> - / / stop probe ( but no fail ) <nl> - break ; <nl> - } <nl> + if ( ! isCellValid ) <nl> + { <nl> + / / It ' s not possible to move to neighbour span in this direction . <nl> + MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , " clearance " ) ; <nl> + return true ; <nl> + } <nl> <nl> - probeInclinationVars [ n ] = ( float ) ( ptopMax - ptopMin ) ; <nl> - } <nl> - } <nl> + / / Skip this direction if the neighbouring span is in the same level <nl> + / / TODO : this doesn ' t work well with lower inclineGradient ( less than 1 . 0 ) and when spans of a slope don ' t raise so quickly . <nl> + if ( probesParams . firstSpanTopDiffAbsolute < = 0 ) <nl> + continue ; <nl> <nl> - if ( isStep <nl> - & & ! stepTest <nl> - & & ( pTopOffsMax > filterParams . climbableVoxelCount ) ) <nl> + const bool isStep = probesParams . firstSpanTopDiffAbsolute > ( filterParams . climbableInclineGradientLowerBound + 1 ) ; <nl> + if ( isStep ) <nl> + { <nl> + / / The change in the levels is too big - a step up / down needs to be done in order to move to neighbour span <nl> + / / Check whether the steepness of the surface after the step isn ' t bigger than ' climbableStepRatio ' . <nl> + if ( ! CheckWalkableProbeStep ( probesParams ) ) <nl> { <nl> - neighbourTest = false ; <nl> - <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( pOutReason ) <nl> - { <nl> - pOutReason - > szReason = " step test " ; <nl> - } <nl> - # endif <nl> + MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , " step test " ) ; <nl> + return true ; <nl> } <nl> - else <nl> + } <nl> + else <nl> + { <nl> + / / Check the steepness of the surface and whether it isn ' t bigger than ' climbableInclineGradient ' . <nl> + if ( ! CheckWalkableProbeIncline ( probesParams , probeInclinationVars ) ) <nl> { <nl> - probeInclinationVars [ n ] / = pc - 1 ; <nl> + MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , " inclination " ) ; <nl> + return true ; <nl> } <nl> } <nl> - } <nl> <nl> - if ( neighbourTest ) <nl> + } / / for all directions <nl> + <nl> { <nl> - float previousProbeGainSquared ( probeInclinationVars [ axisNeighbourCount - 1 ] * probeInclinationVars [ axisNeighbourCount - 1 ] ) ; <nl> - <nl> - / / Test for probe pairs at 90degrees giving a net incline above tolerance <nl> - <nl> - / / TODO pavloi 2016 . 03 . 10 : I do not fully understand the meaning of the metric we have here , but <nl> - / / I think , there may be an error . Neighbours in the NeighbourOffset_TileGenerator are listed in order y , - x , x , - y , <nl> - / / so the compared probe pairs are ( y , - y ) , ( - x , y ) , ( x , - x ) , ( - y , x ) . <nl> - / / I think , expected order is something like ( x , y ) , ( y , - x ) , ( - x , - y ) , ( - y , x ) , so there are never cases , <nl> - / / when we compare ( y , - y ) and ( x , - x ) . <nl> - / / I don ' t see any other piece of code , which depends on the order of first four elements of NeighbourOffset_TileGenerator , so <nl> - / / should be save to reorder them . <nl> - / / But still , a comment before NeighbourOffset_TileGenerator states , that this order is really expected . Who to belive ? <nl> - <nl> - / / TODO pavloi 2016 . 03 . 11 : if we perform stepTest for neighbours , then all probeInclinationVars will stay 0 and condition in this loop <nl> - / / will never be true , so neighbourTest will also stay true . This whole loop is not required then . <nl> - for ( size_t n = 0 ; n < axisNeighbourCount ; + + n ) <nl> + / / Compute average gradients from partial gradients . <nl> + const float gradientX = 0 . 5f * ( probeInclinationVars [ 0 ] + probeInclinationVars [ 2 ] ) ; <nl> + const float gradientY = 0 . 5f * ( probeInclinationVars [ 1 ] + probeInclinationVars [ 3 ] ) ; <nl> + <nl> + const Vec2 gradient ( gradientX , gradientY ) ; <nl> + if ( gradient . GetLengthSquared ( ) > filterParams . climbableInclineGradientSquared ) <nl> { <nl> - float thisProbeGainSquared ( probeInclinationVars [ n ] * probeInclinationVars [ n ] ) ; <nl> - if ( ( float ) ( thisProbeGainSquared + previousProbeGainSquared ) > filterParams . climbableInclineGradientSquared ) <nl> - { <nl> - neighbourTest = false ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( pOutReason ) <nl> - { <nl> - pOutReason - > szReason = " inclination " ; <nl> - } <nl> - # endif <nl> - break ; <nl> - } <nl> - previousProbeGainSquared = thisProbeGainSquared ; <nl> + MNM_SET_NONWALKABLE_FAIL_REASON ( pOutReason , " inclination " ) ; <nl> + return true ; <nl> } <nl> } <nl> - <nl> - return ! neighbourTest ; <nl> + return false ; <nl> } <nl> <nl> - void CTileGenerator : : FilterWalkable_CheckBoundaries ( const AABB & aabb , const size_t gridWidth , const size_t gridHeight ) <nl> + size_t CTileGenerator : : FilterWalkable_CheckBoundaries ( const AABB & aabb , const size_t gridWidth , const size_t gridHeight ) <nl> { <nl> const float convX = 1 . 0f / m_params . voxelSize . x ; <nl> const float convY = 1 . 0f / m_params . voxelSize . y ; <nl> void CTileGenerator : : FilterWalkable_CheckBoundaries ( const AABB & aabb , const size <nl> <nl> const Vec3 bmax = aabb . max - aabb . min ; <nl> <nl> + size_t nonWalkableCount = 0 ; <nl> + <nl> for ( size_t e = 0 ; e < m_params . exclusionCount ; + + e ) <nl> { <nl> const BoundingVolume & exclusion = m_params . exclusions [ e ] ; <nl> void CTileGenerator : : FilterWalkable_CheckBoundaries ( const AABB & aabb , const size <nl> <nl> if ( exclusion . Contains ( point ) ) <nl> { <nl> + + + nonWalkableCount ; <nl> span . flags | = NotWalkable ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( m_params . flags & Params : : DebugInfo ) <nl> - { <nl> - m_debugNonWalkableReasonMap [ SSpanCoord ( x , y , s , cell . index + s ) ] = SNonWalkableReason ( " exclusion " ) ; <nl> - } <nl> - # endif <nl> + <nl> + DebugAddNonWalkableReason ( SSpanCoord ( x , y , s , cell . index + s ) , " exclusion " ) ; <nl> } <nl> } <nl> } <nl> void CTileGenerator : : FilterWalkable_CheckBoundaries ( const AABB & aabb , const size <nl> <nl> if ( ! boundary . Contains ( point ) ) <nl> { <nl> + + + nonWalkableCount ; <nl> span . flags | = NotWalkable ; <nl> - # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> - IF_UNLIKELY ( m_params . flags & Params : : DebugInfo ) <nl> - { <nl> - m_debugNonWalkableReasonMap [ SSpanCoord ( x , y , s , cell . index + s ) ] = SNonWalkableReason ( " boundary " ) ; <nl> - } <nl> - # endif <nl> + DebugAddNonWalkableReason ( SSpanCoord ( x , y , s , cell . index + s ) , " boundary " ) ; <nl> } <nl> } <nl> } <nl> } <nl> } <nl> } <nl> + <nl> + return nonWalkableCount ; <nl> } <nl> <nl> inline bool IsBorderLabel ( uint16 label ) <nl> void CTileGenerator : : DetermineContourVertex ( const Vec2i & vertex , const Vec2i & di <nl> contourVertex . flags = static_cast < uint16 > ( flags ) ; <nl> } <nl> <nl> - void CTileGenerator : : AssessNeighbour ( NeighbourInfo & info , size_t erosion , size_t climbableVoxelCount ) <nl> + void CTileGenerator : : AssessNeighbour ( NeighbourInfo & info , const size_t climbableVoxelCount ) <nl> { <nl> - / / TODO pavloi 2016 . 03 . 15 : erosion is not used . <nl> if ( info . isValid = m_spanGrid . GetSpanAt ( info . pos . x , info . pos . y , info . top , climbableVoxelCount , info . index ) ) <nl> { <nl> const CompactSpanGrid : : Span & span = m_spanGrid . GetSpan ( info . index ) ; <nl> void CTileGenerator : : AssessNeighbour ( NeighbourInfo & info , size_t erosion , size_t <nl> } <nl> } <nl> <nl> - void CTileGenerator : : TraceContour ( CTileGenerator : : TracerPath & path , const Tracer & start , size_t erosion , size_t climbableVoxelCount , const NeighbourInfoRequirements & contourReq ) <nl> + void CTileGenerator : : TraceContour ( CTileGenerator : : TracerPath & path , const Tracer & start , const size_t climbableVoxelCount , const NeighbourInfoRequirements & contourReq ) <nl> { <nl> - / / TODO pavloi 2016 . 03 . 15 : erosion is not used in AssessNeighbour and so is not used here . <nl> - <nl> Tracer tracer = start ; <nl> path . steps . clear ( ) ; <nl> path . steps . reserve ( 2048 ) ; <nl> void CTileGenerator : : TraceContour ( CTileGenerator : : TracerPath & path , const Tracer <nl> NeighbourInfo frontLeft ( tracer . GetFrontLeft ( ) ) ; <nl> NeighbourInfo front ( tracer . GetFront ( ) ) ; <nl> <nl> - AssessNeighbour ( left , erosion , climbableVoxelCount ) ; <nl> - AssessNeighbour ( frontLeft , erosion , climbableVoxelCount ) ; <nl> - AssessNeighbour ( front , erosion , climbableVoxelCount ) ; <nl> + AssessNeighbour ( left , climbableVoxelCount ) ; <nl> + AssessNeighbour ( frontLeft , climbableVoxelCount ) ; <nl> + AssessNeighbour ( front , climbableVoxelCount ) ; <nl> <nl> if ( left . Check ( contourReq ) ) <nl> { <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> <nl> TracerPath path ; <nl> <nl> - / / TODO pavloi 2016 . 03 . 15 : same erosion calculated in CalcPaintValues . And it ' s not even required here - see <nl> - / / comments in AssessNeighbour and TraceContour . <nl> - / / Or it is required , in LabelTracerPath ( ) - DetermineContourVertex ( ) , where it ' s calcluated again . <nl> - const size_t erosion = m_params . flags & Params : : NoErosion ? 0 : m_params . agent . radius < < 1 ; <nl> const size_t climbableVoxelCount = m_params . agent . climbableHeight ; <nl> <nl> for ( size_t y = borderH ; y < gridHeight - borderH ; + + y ) <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> const size_t top = span . bottom + span . height ; <nl> <nl> NeighbourInfo prev ( Vec2i ( x - 1 , y ) , top ) ; <nl> - AssessNeighbour ( * & prev , erosion , climbableVoxelCount ) ; <nl> + AssessNeighbour ( * & prev , climbableVoxelCount ) ; <nl> <nl> const uint16 prevLabelSafe = ( prev . label & NoLabel ) ; <nl> <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> NeighbourInfoRequirements contourReq ; <nl> contourReq . paint = paint ; <nl> <nl> - TraceContour ( path , startTracer , erosion , climbableVoxelCount , contourReq ) ; <nl> + TraceContour ( path , startTracer , climbableVoxelCount , contourReq ) ; <nl> if ( path . turns > 0 ) <nl> { <nl> / / Store for Debugging . <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> NeighbourInfoRequirements holeReq ; <nl> holeReq . notPaint = prev . paint ; <nl> <nl> - TraceContour ( path , startTracer , erosion , climbableVoxelCount , holeReq ) ; <nl> + TraceContour ( path , startTracer , climbableVoxelCount , holeReq ) ; <nl> LabelTracerPath ( path , climbableVoxelCount , holeRegion , holeRegion . holes . back ( ) , NoLabel , InternalContour , prev . label , true ) ; <nl> <nl> / / Store for Debugging . <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> / / Trace the new region <nl> NeighbourInfoRequirements contourReq ; <nl> contourReq . paint = paint ; <nl> - TraceContour ( path , startTracer , erosion , climbableVoxelCount , contourReq ) ; <nl> + TraceContour ( path , startTracer , climbableVoxelCount , contourReq ) ; <nl> <nl> if ( path . turns > 0 ) <nl> { <nl> size_t CTileGenerator : : ExtractContours ( const AABB & aabb ) <nl> NeighbourInfoRequirements holeReq ; <nl> holeReq . notPaint = prev . paint ; <nl> <nl> - TraceContour ( path , startTracer , erosion , climbableVoxelCount , holeReq ) ; <nl> + TraceContour ( path , startTracer , climbableVoxelCount , holeReq ) ; <nl> LabelTracerPath ( path , climbableVoxelCount , holeRegion , holeRegion . holes . back ( ) , NoLabel , InternalContour , prev . label , true ) ; <nl> <nl> / / Store for Debugging . <nl> mmm a / Code / CryEngine / CryAISystem / Navigation / MNM / TileGenerator . h <nl> ppp b / Code / CryEngine / CryAISystem / Navigation / MNM / TileGenerator . h <nl> class CTileGenerator <nl> inline bool IsBoundaryVertexV ( size_t z ) const <nl> { <nl> const size_t borderV = BorderSizeV ( m_params ) ; <nl> - <nl> return ( z = = borderV ) | | ( z = = Top ( m_params ) + borderV ) ; <nl> } <nl> <nl> class CTileGenerator <nl> struct SFilterWalkableParams ; <nl> struct SSpanClearance ; <nl> struct SNonWalkableNeighbourReason ; <nl> + struct SWalkableProbeCheckParams ; <nl> <nl> bool GenerateFromVoxelizedVolume ( const AABB & aabb , const bool fullyContained ) ; <nl> <nl> void FilterWalkable ( const AABB & aabb , bool fullyContained = true ) ; <nl> - bool FilterWalkableSpan ( CompactSpanGrid : : Span & span , const SSpanCoord & spanCoord , const CompactSpanGrid : : Cell & cell , const SFilterWalkableParams & filterParams ) ; <nl> - static bool FilterWalkable_CheckSpanBackface ( const CompactSpanGrid : : Span & span ) ; <nl> - static bool FilterWalkable_CheckSpanWaterDepth ( const CompactSpanGrid : : Span & span , const Params & params ) ; <nl> - static bool FilterWalkable_CheckNeighbours ( const SSpanCoord & spanCoord , const SSpanClearance & spanClearance , const SFilterWalkableParams & filterParams , SNonWalkableNeighbourReason * pOutReason ) ; <nl> - void FilterWalkable_CheckBoundaries ( const AABB & aabb , const size_t gridWidth , const size_t gridHeight ) ; <nl> + size_t FilterWalkable_CheckBackfaceDepthAndClearance ( const SFilterWalkableParams & filterParams ) ; <nl> + size_t FilterWalkable_CheckNeighboursAndInclination ( const SFilterWalkableParams & filterParams ) ; <nl> + bool FilterWalkableSpanAndSetClearance ( CompactSpanGrid : : Span & span , const SSpanCoord & spanCoord , const CompactSpanGrid : : Cell & cell , const SFilterWalkableParams & filterParams ) ; <nl> + static bool FilterWalkableSpan_CheckBackface ( const CompactSpanGrid : : Span & span ) ; <nl> + static bool FilterWalkableSpan_CheckWaterDepth ( const CompactSpanGrid : : Span & span , const Params & params ) ; <nl> + static bool FilterWalkableSpan_CheckNeighbours ( const SSpanCoord & spanCoord , const size_t originTop , const size_t originNextBottom , const SFilterWalkableParams & filterParams , SNonWalkableNeighbourReason * pOutReason ) ; <nl> + <nl> + static bool CheckWalkableProbeStep ( const SWalkableProbeCheckParams & params ) ; <nl> + static bool CheckWalkableProbeIncline ( const SWalkableProbeCheckParams & params , float * probeInclinationVars ) ; <nl> + <nl> + <nl> + size_t FilterWalkable_CheckBoundaries ( const AABB & aabb , const size_t gridWidth , const size_t gridHeight ) ; <nl> <nl> void ComputeDistanceTransform ( ) ; <nl> void ExpandAreaForPaint ( const uint16 paint ) ; <nl> - void BlurDistanceTransform ( ) ; <nl> <nl> void LabelBorders ( ) ; <nl> <nl> class CTileGenerator <nl> } <nl> } ; <nl> <nl> - void AssessNeighbour ( NeighbourInfo & info , size_t erosion , size_t climbableVoxelCount ) ; <nl> + void AssessNeighbour ( NeighbourInfo & info , const size_t climbableVoxelCount ) ; <nl> <nl> enum TracerDir <nl> { <nl> class CTileGenerator <nl> int turns ; <nl> } ; <nl> <nl> - void TraceContour ( CTileGenerator : : TracerPath & path , const Tracer & start , size_t erosion , size_t climbableVoxelCount , const NeighbourInfoRequirements & contourReq ) ; <nl> + void TraceContour ( CTileGenerator : : TracerPath & path , const Tracer & start , const size_t climbableVoxelCount , const NeighbourInfoRequirements & contourReq ) ; <nl> int LabelTracerPath ( const CTileGenerator : : TracerPath & path , size_t climbableVoxelCount , Region & region , Contour & contour , const uint16 internalLabel , const uint16 internalLabelFlags , const uint16 externalLabel , const bool bIsHole ) ; <nl> <nl> void TidyUpContourEnd ( Contour & contour ) ; <nl> class CTileGenerator <nl> <nl> # endif / / DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> <nl> - inline void DebugAddNonWalkableReason ( const SSpanCoord & spanCoord , const char * szReason ) <nl> - { <nl> # if DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> + inline void DebugAddNonWalkableReason ( const SSpanCoord & spanCoord , SNonWalkableReason & & reason ) <nl> + { <nl> IF_UNLIKELY ( m_params . flags & Params : : DebugInfo ) <nl> { <nl> - m_debugNonWalkableReasonMap [ spanCoord ] = SNonWalkableReason ( szReason ) ; <nl> + m_debugNonWalkableReasonMap [ spanCoord ] = reason ; <nl> } <nl> - # endif / / DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> } <nl> + # else <nl> + # define DebugAddNonWalkableReason ( spanCoord , reason ) <nl> + # endif / / DEBUG_MNM_GATHER_NONWALKABLE_REASONS <nl> <nl> friend class CContourRenderer ; <nl> # if DEBUG_MNM_GATHER_EXTRA_CONTOUR_VERTEX_INFO <nl>
! R ( AISystem ) ( DEV - 7814 ) Improved precision of slope parameters and NavMesh generated based on them
CRYTEK/CRYENGINE
d9f78c03912f4fbff43ccc4d397828d2549bc604
2019-03-21T09:02:10Z
mmm a / editor / plugins / spatial_editor_plugin . cpp <nl> ppp b / editor / plugins / spatial_editor_plugin . cpp <nl> void SpatialEditorViewport : : _preview_exited_scene ( ) { <nl> preview_camera - > disconnect ( " toggled " , this , " _toggle_camera_preview " ) ; <nl> preview_camera - > set_pressed ( false ) ; <nl> _toggle_camera_preview ( false ) ; <nl> + preview_camera - > connect ( " toggled " , this , " _toggle_camera_preview " ) ; <nl> view_menu - > show ( ) ; <nl> } <nl> <nl> SpatialEditorViewport : : SpatialEditorViewport ( SpatialEditor * p_spatial_editor , Ed <nl> vbox - > add_child ( preview_camera ) ; <nl> preview_camera - > set_h_size_flags ( 0 ) ; <nl> preview_camera - > hide ( ) ; <nl> + preview_camera - > connect ( " toggled " , this , " _toggle_camera_preview " ) ; <nl> previewing = NULL ; <nl> gizmo_scale = 1 . 0 ; <nl> <nl>
Merge pull request from nekomatata / camera - preview - new - scene
godotengine/godot
78f7cca69e95d266bd77a38edeaca4c6ca19e26b
2019-11-09T18:49:24Z
mmm a / utils / build - presets . ini <nl> ppp b / utils / build - presets . ini <nl> build - swift - examples = 0 <nl> swift - include - tests = 0 <nl> darwin - deployment - version - ios = 10 . 0 <nl> darwin - crash - reporter - client = 1 <nl> + <nl> + [ preset : build_swiftsyntax_release ] <nl> + release <nl> + no - assertions <nl> + build - libparser - only <nl> + swiftsyntax <nl>
build - script / presets : add a preset to only build parser library and SwiftSyntax
apple/swift
c73a9580cab50c3305c6da9e758c562c539271bd
2019-01-18T23:58:19Z
mmm a / lib / browser / guest - view - manager . js <nl> ppp b / lib / browser / guest - view - manager . js <nl> const supportedWebViewEvents = [ <nl> ' did - get - redirect - request ' , <nl> ' dom - ready ' , <nl> ' console - message ' , <nl> + ' context - menu ' , <nl> ' devtools - opened ' , <nl> ' devtools - closed ' , <nl> ' devtools - focused ' , <nl> mmm a / lib / renderer / web - view / guest - view - internal . js <nl> ppp b / lib / renderer / web - view / guest - view - internal . js <nl> const WEB_VIEW_EVENTS = { <nl> ' did - get - redirect - request ' : [ ' oldURL ' , ' newURL ' , ' isMainFrame ' ] , <nl> ' dom - ready ' : [ ] , <nl> ' console - message ' : [ ' level ' , ' message ' , ' line ' , ' sourceId ' ] , <nl> + ' context - menu ' : [ ' params ' ] , <nl> ' devtools - opened ' : [ ] , <nl> ' devtools - closed ' : [ ] , <nl> ' devtools - focused ' : [ ] , <nl>
Merge pull request from javan / add - context - menu - event - to - webview
electron/electron
9089d553422bc8b76dd31ffaf4773ace6f9fa39c
2017-01-16T17:04:32Z
mmm a / modules / prediction / evaluator / vehicle / cruise_mlp_evaluator . cc <nl> ppp b / modules / prediction / evaluator / vehicle / cruise_mlp_evaluator . cc <nl> void CruiseMLPEvaluator : : SetLaneFeatureValues <nl> double diff_x = lane_point . position ( ) . x ( ) - feature . position ( ) . x ( ) ; <nl> double diff_y = lane_point . position ( ) . y ( ) - feature . position ( ) . y ( ) ; <nl> double angle = std : : atan2 ( diff_y , diff_x ) ; <nl> - feature_values - > push_back ( lane_point . kappa ( ) ) ; <nl> + double deviation_angle = angle - heading ; <nl> + double relative_l = std : : sqrt ( diff_x * diff_x + diff_y * diff_y ) <nl> + * std : : sin ( deviation_angle ) ; <nl> + <nl> + / / The lateral deviation of the lane - point from vehicle facing : <nl> + feature_values - > push_back ( relative_l ) ; <nl> + / / The extrapolated normal acceleration : <nl> feature_values - > push_back ( speed * speed * lane_point . kappa ( ) ) ; <nl> - feature_values - > push_back ( std : : sin ( angle - heading ) ) ; <nl> - feature_values - > push_back ( lane_point . relative_l ( ) ) ; <nl> - feature_values - > push_back ( lane_point . heading ( ) ) ; <nl> - feature_values - > push_back ( lane_point . angle_diff ( ) ) ; <nl> + / / The lane - point ' s heading w . r . t . vehicle ' s facing direction : <nl> + feature_values - > push_back ( common : : math : : AngleDiff <nl> + ( heading , lane_pont . heading ( ) ) ) ; <nl> + feature_values - > push_back ( diff_x ) ; <nl> + feature_values - > push_back ( diff_y ) ; <nl> } <nl> } <nl> <nl> / / If the lane points are not sufficient , apply a linear extrapolation . <nl> std : : size_t size = feature_values - > size ( ) ; <nl> - while ( size > = 6 & & size < LANE_FEATURE_SIZE ) { <nl> - double lane_kappa = feature_values - > operator [ ] ( size - 6 ) ; <nl> - double centri_acc = feature_values - > operator [ ] ( size - 5 ) ; <nl> - double heading_diff = feature_values - > operator [ ] ( size - 4 ) ; <nl> - double lane_l_diff = feature_values - > operator [ ] ( size - 3 ) ; <nl> - double heading = feature_values - > operator [ ] ( size - 2 ) ; <nl> - double angle_diff = feature_values - > operator [ ] ( size - 1 ) ; <nl> - feature_values - > push_back ( lane_kappa ) ; <nl> - feature_values - > push_back ( centri_acc ) ; <nl> - feature_values - > push_back ( heading_diff ) ; <nl> - feature_values - > push_back ( lane_l_diff ) ; <nl> - feature_values - > push_back ( heading ) ; <nl> - feature_values - > push_back ( angle_diff ) ; <nl> + while ( size > = 10 & & size < LANE_FEATURE_SIZE ) { <nl> + double diff_x_new = 2 * feature_values - > operator [ ] ( size - 2 ) - <nl> + feature_values - > operator [ ] ( size - 7 ) ; <nl> + double diff_y_new = 2 * feature_values - > operator [ ] ( size - 1 ) - <nl> + feature_values - > operator [ ] ( size - 6 ) ; <nl> + double angle_new = std : : atan2 ( diff_y_new , diff_x_new ) ; <nl> + double deviation_angle_new = angle_new - heading ; <nl> + double relative_l_new = std : : sqrt ( diff_x_new * diff_x_new + <nl> + diff_y_new * diff_y_new ) <nl> + * std : : sin ( deviation_angle_new ) ; <nl> + double centri_acc_new = 0 . 0 ; <nl> + double angle_diff_new = feature_values - > operator [ ] ( size - 3 ) ; <nl> + <nl> + feature_values - > push_back ( relative_l_new ) ; <nl> + feature_values - > push_back ( centri_acc_new ) ; <nl> + feature_values - > push_back ( angle_diff_new ) ; <nl> + feature_values - > push_back ( diff_x_new ) ; <nl> + feature_values - > push_back ( diff_y_new ) ; <nl> size = feature_values - > size ( ) ; <nl> } <nl> } <nl> mmm a / modules / prediction / evaluator / vehicle / cruise_mlp_evaluator . h <nl> ppp b / modules / prediction / evaluator / vehicle / cruise_mlp_evaluator . h <nl> class CruiseMLPEvaluator : public Evaluator { <nl> private : <nl> static const size_t OBSTACLE_FEATURE_SIZE = 23 ; <nl> static const size_t INTERACTION_FEATURE_SIZE = 8 ; <nl> - static const size_t LANE_FEATURE_SIZE = 180 ; <nl> + static const size_t LANE_FEATURE_SIZE = 150 ; <nl> std : : unique_ptr < FnnVehicleModel > model_ptr_ ; <nl> } ; <nl> <nl> mmm a / modules / tools / prediction / mlp_train / common / configure . py <nl> ppp b / modules / tools / prediction / mlp_train / common / configure . py <nl> <nl> ' dim_output ' : 1 <nl> } , <nl> ' cruise_mlp ' : { <nl> - ' dim_input ' : 23 + 8 + 180 , <nl> + ' dim_input ' : 23 + 8 + 150 , <nl> ' dim_hidden_1 ' : 50 , <nl> ' dim_hidden_2 ' : 18 , <nl> ' dim_output ' : 2 <nl>
Prediction : cruise feature refactor ( modified . cc )
ApolloAuto/apollo
9dce46c1b18e80c3ef1492ef5fd9a8608a9d71ec
2018-12-13T23:18:54Z
mmm a / tensorflow / python / ops / nn_grad . py <nl> ppp b / tensorflow / python / ops / nn_grad . py <nl> def _SparseSoftmaxCrossEntropyWithLogitsGrad ( op , grad_loss , grad_grad ) : <nl> if grad_grad is not None and not _IsZero ( grad_grad ) : <nl> softmax = nn_ops . softmax ( logits ) <nl> <nl> - grad + = ( ( grad_grad - array_ops . squeeze ( <nl> - math_ops . matmul ( array_ops . expand_dims ( grad_grad , 1 ) , <nl> - array_ops . expand_dims ( softmax , 2 ) ) , <nl> - axis = 1 ) ) * <nl> - softmax ) <nl> + grad + = ( ( grad_grad <nl> + - array_ops . squeeze ( <nl> + math_ops . matmul ( array_ops . expand_dims ( grad_grad , 1 ) , <nl> + array_ops . expand_dims ( softmax , 2 ) ) , <nl> + axis = 1 ) <nl> + ) * softmax ) <nl> <nl> return grad , None <nl> <nl>
Improve formatting
tensorflow/tensorflow
6538102fe8e55f88c3e57eda21916d8dc39d6e97
2019-04-06T17:14:29Z
mmm a / scripts / generate_serialize_macros . py <nl> ppp b / scripts / generate_serialize_macros . py <nl> def generate_make_serializable_macro ( nfields ) : <nl> print " # define RDB_IMPL_SERIALIZABLE_ % d_SINCE_v2_4 ( type_t % s ) \ \ " % ( nfields , fields ) <nl> print " RDB_IMPL_SERIALIZABLE_ % d ( type_t % s ) ; \ \ " % ( nfields , fields ) <nl> print " INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) " <nl> + print <nl> + print " # define RDB_IMPL_SERIALIZABLE_ % d_SINCE_v2_5 ( type_t % s ) \ \ " % ( nfields , fields ) <nl> + print " RDB_IMPL_SERIALIZABLE_ % d ( type_t % s ) ; \ \ " % ( nfields , fields ) <nl> + print " INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) " <nl> <nl> print " # define RDB_MAKE_ME_SERIALIZABLE_ % d ( type_t % s ) \ \ " % \ <nl> ( nfields , fields ) <nl> mmm a / src / clustering / administration / persist / migrate / migrate_v1_16 . cc <nl> ppp b / src / clustering / administration / persist / migrate / migrate_v1_16 . cc <nl> void migrate_table ( const server_id_t & this_server_id , <nl> metadata_v1_16 : : write_ack_config_t : : mode_t : : single ? <nl> : : write_ack_config_t : : SINGLE : : : write_ack_config_t : : MAJORITY ; <nl> config . config . durability = old_config . config . durability ; <nl> + config . config . user_data = default_user_data ( ) ; <nl> config . shard_scheme . split_points = old_config . shard_scheme . split_points ; <nl> <nl> / / Scan the servers in the old shard config - need to remove deleted and nil servers <nl> mmm a / src / clustering / administration / real_reql_cluster_interface . cc <nl> ppp b / src / clustering / administration / real_reql_cluster_interface . cc <nl> bool real_reql_cluster_interface_t : : table_create ( <nl> <nl> config . config . write_ack_config = write_ack_config_t : : MAJORITY ; <nl> config . config . durability = durability ; <nl> + config . config . user_data = default_user_data ( ) ; <nl> <nl> table_id = generate_uuid ( ) ; <nl> m_table_meta_client - > create ( table_id , config , & interruptor_on_home ) ; <nl> void real_reql_cluster_interface_t : : reconfigure_internal ( <nl> new_config . config . sindexes = old_config . config . sindexes ; <nl> new_config . config . write_ack_config = old_config . config . write_ack_config ; <nl> new_config . config . durability = old_config . config . durability ; <nl> + new_config . config . user_data = old_config . config . user_data ; <nl> <nl> calculate_split_points_intelligently ( <nl> table_id , <nl> mmm a / src / clustering / administration / tables / table_config . cc <nl> ppp b / src / clustering / administration / tables / table_config . cc <nl> bool convert_sindexes_from_datum ( <nl> return true ; <nl> } <nl> <nl> - / * This is separate from ` format_row ( ) ` because it needs to be publicly exposed so it can <nl> - be used to create the return value of ` table . reconfigure ( ) ` . * / <nl> + / * This is separate from ` format_row ( ) ` because it needs to be publicly exposed so it <nl> + can be used to create the return value of ` table . reconfigure ( ) ` . * / <nl> ql : : datum_t convert_table_config_to_datum ( <nl> namespace_id_t table_id , <nl> const ql : : datum_t & db_name_or_uuid , <nl> ql : : datum_t convert_table_config_to_datum ( <nl> convert_write_ack_config_to_datum ( config . write_ack_config ) ) ; <nl> builder . overwrite ( " durability " , <nl> convert_durability_to_datum ( config . durability ) ) ; <nl> + builder . overwrite ( " data " , config . user_data . datum ) ; <nl> return std : : move ( builder ) . to_datum ( ) ; <nl> } <nl> <nl> bool convert_table_config_and_name_from_datum ( <nl> } <nl> <nl> / * As a special case , we allow the user to omit ` indexes ` , ` primary_key ` , ` shards ` , <nl> - ` write_acks ` , and / or ` durability ` for newly - created tables . * / <nl> + ` write_acks ` , ` durability ` , and / or ` data ` for newly - created tables . * / <nl> <nl> if ( converter . has ( " indexes " ) ) { <nl> ql : : datum_t indexes_datum ; <nl> bool convert_table_config_and_name_from_datum ( <nl> } <nl> } <nl> <nl> + if ( existed_before | | converter . has ( " data " ) ) { <nl> + ql : : datum_t user_data_datum ; <nl> + if ( ! converter . get ( " data " , & user_data_datum , error_out ) ) { <nl> + return false ; <nl> + } <nl> + config_out - > user_data = { std : : move ( user_data_datum ) } ; <nl> + } else { <nl> + config_out - > user_data = default_user_data ( ) ; <nl> + } <nl> + <nl> if ( ! converter . check_no_extra_keys ( error_out ) ) { <nl> return false ; <nl> } <nl> mmm a / src / clustering / administration / tables / table_metadata . cc <nl> ppp b / src / clustering / administration / tables / table_metadata . cc <nl> RDB_IMPL_SERIALIZABLE_3_SINCE_v2_1 ( table_config_t : : shard_t , <nl> RDB_IMPL_EQUALITY_COMPARABLE_3 ( table_config_t : : shard_t , <nl> all_replicas , nonvoting_replicas , primary_replica ) ; <nl> <nl> - template < cluster_version_t W > <nl> - void serialize ( write_message_t * wm , const table_config_t & tc ) { <nl> - table_basic_config_t basic = tc . basic ; <nl> - serialize < W > ( wm , basic ) ; <nl> - <nl> - std : : vector < table_config_t : : shard_t > shards = tc . shards ; <nl> - serialize < W > ( wm , shards ) ; <nl> - <nl> - std : : map < std : : string , sindex_config_t > sindexes = tc . sindexes ; <nl> - serialize < W > ( wm , sindexes ) ; <nl> + / / We start with an empty object , not null - - because a good user would set fields of <nl> + / / that object . <nl> + user_data_t default_user_data ( ) { <nl> + return user_data_t { ql : : datum_t : : empty_object ( ) } ; <nl> + } <nl> <nl> - optional < write_hook_config_t > write_hook = tc . write_hook ; <nl> - serialize < W > ( wm , write_hook ) ; <nl> + RDB_MAKE_SERIALIZABLE_1 ( user_data_t , datum ) ; <nl> <nl> - write_ack_config_t write_ack_config = tc . write_ack_config ; <nl> - serialize < W > ( wm , write_ack_config ) ; <nl> + RDB_IMPL_EQUALITY_COMPARABLE_1 ( user_data_t , datum ) ; <nl> <nl> - write_durability_t durability = tc . durability ; <nl> - serialize < W > ( wm , durability ) ; <nl> - } <nl> - <nl> - INSTANTIATE_SERIALIZE_FOR_CLUSTER_AND_DISK ( table_config_t ) ; <nl> + RDB_DECLARE_SERIALIZABLE ( table_config_t ) ; <nl> <nl> template < cluster_version_t W > <nl> archive_result_t deserialize_table_config_pre_v2_4 ( <nl> archive_result_t deserialize_table_config_pre_v2_4 ( <nl> tc - > sindexes = std : : move ( sindexes ) ; <nl> tc - > write_ack_config = std : : move ( write_ack_config ) ; <nl> tc - > durability = std : : move ( durability ) ; <nl> + tc - > user_data = default_user_data ( ) ; <nl> <nl> return res ; <nl> } <nl> <nl> - template < cluster_version_t W > <nl> - archive_result_t deserialize ( <nl> + archive_result_t deserialize_table_config_v2_4 ( <nl> read_stream_t * s , table_config_t * tc ) { <nl> + const cluster_version_t W = cluster_version_t : : v2_4 ; <nl> archive_result_t res ; <nl> <nl> table_basic_config_t basic ; <nl> archive_result_t deserialize ( <nl> std : : move ( sindexes ) , <nl> std : : move ( write_hook ) , <nl> std : : move ( write_ack_config ) , <nl> - std : : move ( durability ) } ; <nl> + std : : move ( durability ) , <nl> + default_user_data ( ) } ; <nl> <nl> return res ; <nl> } <nl> archive_result_t deserialize < cluster_version_t : : v2_3 > ( <nl> return deserialize_table_config_pre_v2_4 < cluster_version_t : : v2_3 > ( s , tc ) ; <nl> } <nl> <nl> - template archive_result_t deserialize < cluster_version_t : : v2_4 > ( <nl> - read_stream_t * , table_config_t * ) ; <nl> + template < > <nl> + archive_result_t deserialize < cluster_version_t : : v2_4 > ( <nl> + read_stream_t * s , table_config_t * tc ) { <nl> + return deserialize_table_config_v2_4 ( s , tc ) ; <nl> + } <nl> <nl> - template archive_result_t deserialize < cluster_version_t : : v2_5_is_latest > ( <nl> - read_stream_t * , table_config_t * ) ; <nl> + RDB_IMPL_SERIALIZABLE_7_SINCE_v2_5 ( table_config_t , <nl> + basic , shards , write_hook , sindexes , write_ack_config , durability , user_data ) ; <nl> <nl> - RDB_IMPL_EQUALITY_COMPARABLE_6 ( table_config_t , <nl> - basic , shards , write_hook , sindexes , write_ack_config , durability ) ; <nl> + RDB_IMPL_EQUALITY_COMPARABLE_7 ( table_config_t , <nl> + basic , shards , write_hook , sindexes , write_ack_config , durability , user_data ) ; <nl> <nl> RDB_IMPL_SERIALIZABLE_1_SINCE_v1_16 ( table_shard_scheme_t , split_points ) ; <nl> RDB_IMPL_EQUALITY_COMPARABLE_1 ( table_shard_scheme_t , split_points ) ; <nl> mmm a / src / clustering / administration / tables / table_metadata . hpp <nl> ppp b / src / clustering / administration / tables / table_metadata . hpp <nl> ARCHIVE_PRIM_MAKE_RANGED_SERIALIZABLE ( <nl> write_ack_config_t : : SINGLE , <nl> write_ack_config_t : : MAJORITY ) ; <nl> <nl> + class user_data_t { <nl> + public : <nl> + ql : : datum_t datum ; <nl> + } ; <nl> + <nl> + user_data_t default_user_data ( ) ; <nl> + <nl> / * ` table_config_t ` describes the complete contents of the ` rethinkdb . table_config ` <nl> artificial table . * / <nl> <nl> class table_config_t { <nl> optional < write_hook_config_t > write_hook ; <nl> write_ack_config_t write_ack_config ; <nl> write_durability_t durability ; <nl> + user_data_t user_data ; / / has user - exposed name " data " <nl> } ; <nl> <nl> RDB_DECLARE_EQUALITY_COMPARABLE ( table_config_t ) ; <nl> mmm a / src / clustering / table_contract / emergency_repair . cc <nl> ppp b / src / clustering / table_contract / emergency_repair . cc <nl> void calculate_emergency_repair ( <nl> new_state_out - > config . config . write_ack_config = <nl> old_state . config . config . write_ack_config ; <nl> new_state_out - > config . config . durability = old_state . config . config . durability ; <nl> + new_state_out - > config . config . user_data = old_state . config . config . user_data ; <nl> <nl> / * We first calculate all the voting and nonvoting replicas for each range in a <nl> ` range_map_t ` . * / <nl> mmm a / src / containers / archive / versioned . hpp <nl> ppp b / src / containers / archive / versioned . hpp <nl> size_t serialized_size_for_version ( cluster_version_t version , <nl> INSTANTIATE_SERIALIZE_FOR_CLUSTER_AND_DISK ( typ ) ; \ <nl> INSTANTIATE_DESERIALIZE_SINCE_v2_4 ( typ ) <nl> <nl> + # define INSTANTIATE_DESERIALIZE_SINCE_v2_5 ( typ ) \ <nl> + template archive_result_t deserialize < cluster_version_t : : v2_5_is_latest > ( \ <nl> + read_stream_t * , typ * ) ; <nl> + <nl> + # define INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( typ ) \ <nl> + INSTANTIATE_SERIALIZE_FOR_CLUSTER_AND_DISK ( typ ) ; \ <nl> + INSTANTIATE_DESERIALIZE_SINCE_v2_5 ( typ ) <nl> + <nl> # define INSTANTIATE_SERIALIZABLE_FOR_CLUSTER ( typ ) \ <nl> INSTANTIATE_SERIALIZE_FOR_CLUSTER ( typ ) ; \ <nl> template archive_result_t deserialize < cluster_version_t : : CLUSTER > ( \ <nl> mmm a / src / rpc / serialize_macros . hpp <nl> ppp b / src / rpc / serialize_macros . hpp <nl> <nl> # ifndef RPC_SERIALIZE_MACROS_HPP_ <nl> # define RPC_SERIALIZE_MACROS_HPP_ <nl> <nl> - / * This file is automatically generated by ' scripts / generate_serialize_macros . py ' . <nl> - Please modify ' scripts / generate_serialize_macros . py ' instead of modifying this file . * / <nl> + / * This file is automatically generated by ' . . / scripts / generate_serialize_macros . py ' . <nl> + Please modify ' . . / scripts / generate_serialize_macros . py ' instead of modifying this file . * / <nl> <nl> # include < type_traits > <nl> <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_0_SINCE_v2_4 ( type_t ) \ <nl> RDB_IMPL_SERIALIZABLE_0 ( type_t ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_0_SINCE_v2_5 ( type_t ) \ <nl> + RDB_IMPL_SERIALIZABLE_0 ( type_t ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_0 ( type_t ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( UNUSED write_message_t * wm , UNUSED const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_1_SINCE_v2_4 ( type_t , field1 ) \ <nl> RDB_IMPL_SERIALIZABLE_1 ( type_t , field1 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_1_SINCE_v2_5 ( type_t , field1 ) \ <nl> + RDB_IMPL_SERIALIZABLE_1 ( type_t , field1 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_1 ( type_t , field1 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_2_SINCE_v2_4 ( type_t , field1 , field2 ) \ <nl> RDB_IMPL_SERIALIZABLE_2 ( type_t , field1 , field2 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_2_SINCE_v2_5 ( type_t , field1 , field2 ) \ <nl> + RDB_IMPL_SERIALIZABLE_2 ( type_t , field1 , field2 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_2 ( type_t , field1 , field2 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_3_SINCE_v2_4 ( type_t , field1 , field2 , field3 ) \ <nl> RDB_IMPL_SERIALIZABLE_3 ( type_t , field1 , field2 , field3 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_3_SINCE_v2_5 ( type_t , field1 , field2 , field3 ) \ <nl> + RDB_IMPL_SERIALIZABLE_3 ( type_t , field1 , field2 , field3 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_3 ( type_t , field1 , field2 , field3 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_4_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 ) \ <nl> RDB_IMPL_SERIALIZABLE_4 ( type_t , field1 , field2 , field3 , field4 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_4_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 ) \ <nl> + RDB_IMPL_SERIALIZABLE_4 ( type_t , field1 , field2 , field3 , field4 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_4 ( type_t , field1 , field2 , field3 , field4 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_5_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 ) \ <nl> RDB_IMPL_SERIALIZABLE_5 ( type_t , field1 , field2 , field3 , field4 , field5 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_5_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 ) \ <nl> + RDB_IMPL_SERIALIZABLE_5 ( type_t , field1 , field2 , field3 , field4 , field5 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_5 ( type_t , field1 , field2 , field3 , field4 , field5 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_6_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 ) \ <nl> RDB_IMPL_SERIALIZABLE_6 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_6_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 ) \ <nl> + RDB_IMPL_SERIALIZABLE_6 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_6 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_7_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 ) \ <nl> RDB_IMPL_SERIALIZABLE_7 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_7_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 ) \ <nl> + RDB_IMPL_SERIALIZABLE_7 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_7 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_8_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 ) \ <nl> RDB_IMPL_SERIALIZABLE_8 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_8_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 ) \ <nl> + RDB_IMPL_SERIALIZABLE_8 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_8 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_9_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 ) \ <nl> RDB_IMPL_SERIALIZABLE_9 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_9_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 ) \ <nl> + RDB_IMPL_SERIALIZABLE_9 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_9 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_10_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 ) \ <nl> RDB_IMPL_SERIALIZABLE_10 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_10_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 ) \ <nl> + RDB_IMPL_SERIALIZABLE_10 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_10 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_11_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 ) \ <nl> RDB_IMPL_SERIALIZABLE_11 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_11_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 ) \ <nl> + RDB_IMPL_SERIALIZABLE_11 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_11 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_12_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 ) \ <nl> RDB_IMPL_SERIALIZABLE_12 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_12_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 ) \ <nl> + RDB_IMPL_SERIALIZABLE_12 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_12 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_13_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 ) \ <nl> RDB_IMPL_SERIALIZABLE_13 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_13_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 ) \ <nl> + RDB_IMPL_SERIALIZABLE_13 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_13 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_14_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 ) \ <nl> RDB_IMPL_SERIALIZABLE_14 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_14_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 ) \ <nl> + RDB_IMPL_SERIALIZABLE_14 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_14 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_15_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 ) \ <nl> RDB_IMPL_SERIALIZABLE_15 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_15_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 ) \ <nl> + RDB_IMPL_SERIALIZABLE_15 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_15 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_16_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 ) \ <nl> RDB_IMPL_SERIALIZABLE_16 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_16_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 ) \ <nl> + RDB_IMPL_SERIALIZABLE_16 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_16 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_17_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 ) \ <nl> RDB_IMPL_SERIALIZABLE_17 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_17_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 ) \ <nl> + RDB_IMPL_SERIALIZABLE_17 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_17 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_18_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 ) \ <nl> RDB_IMPL_SERIALIZABLE_18 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_18_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 ) \ <nl> + RDB_IMPL_SERIALIZABLE_18 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_18 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> struct always_false <nl> # define RDB_IMPL_SERIALIZABLE_19_SINCE_v2_4 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 , field19 ) \ <nl> RDB_IMPL_SERIALIZABLE_19 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 , field19 ) ; \ <nl> INSTANTIATE_SERIALIZABLE_SINCE_v2_4 ( type_t ) <nl> + <nl> + # define RDB_IMPL_SERIALIZABLE_19_SINCE_v2_5 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 , field19 ) \ <nl> + RDB_IMPL_SERIALIZABLE_19 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 , field19 ) ; \ <nl> + INSTANTIATE_SERIALIZABLE_SINCE_v2_5 ( type_t ) <nl> # define RDB_MAKE_ME_SERIALIZABLE_19 ( type_t , field1 , field2 , field3 , field4 , field5 , field6 , field7 , field8 , field9 , field10 , field11 , field12 , field13 , field14 , field15 , field16 , field17 , field18 , field19 ) \ <nl> template < cluster_version_t W > \ <nl> friend void serialize ( write_message_t * wm , const type_t & thing ) { \ <nl> mmm a / src / unittest / clustering_contract_coordinator . cc <nl> ppp b / src / unittest / clustering_contract_coordinator . cc <nl> class coordinator_tester_t { <nl> cs . config . basic . primary_key = " id " ; <nl> cs . config . write_ack_config = write_ack_config_t : : MAJORITY ; <nl> cs . config . durability = write_durability_t : : HARD ; <nl> + cs . config . user_data = default_user_data ( ) ; <nl> <nl> key_range_t : : right_bound_t prev_right ( store_key_t : : min ( ) ) ; <nl> for ( const quick_shard_args_t & qs : qss ) { <nl> mmm a / src / unittest / clustering_raft_storage . cc <nl> ppp b / src / unittest / clustering_raft_storage . cc <nl> table_config_and_shards_t make_table_config_and_shards ( ) { <nl> calculate_split_points_for_uuids ( 1 , & table_config_and_shards . shard_scheme ) ; <nl> table_config_and_shards . config . write_ack_config = write_ack_config_t : : MAJORITY ; <nl> table_config_and_shards . config . durability = write_durability_t : : HARD ; <nl> + table_config_and_shards . config . user_data = default_user_data ( ) ; <nl> table_config_and_shards . server_names . names [ shard . primary_replica ] = <nl> std : : make_pair ( 0ul , name_string_t : : guarantee_valid ( " primary " ) ) ; <nl> <nl>
Added user data field to table_config_t .
rethinkdb/rethinkdb
6d4cac7ec3c3214fa6fc73cf889975b072211429
2017-06-13T02:35:06Z
mmm a / lib / SILOptimizer / Analysis / RCIdentityAnalysis . cpp <nl> ppp b / lib / SILOptimizer / Analysis / RCIdentityAnalysis . cpp <nl> SILValue RCIdentityFunctionInfo : : stripRCIdentityPreservingOps ( SILValue V , <nl> return V ; <nl> } <nl> <nl> + <nl> + SILValue RCIdentityFunctionInfo : : getRCIdentityRootInner ( SILValue V , <nl> + unsigned RecursionDepth ) { <nl> + / / Only allow this method to be recursed on for a limited number of times to <nl> + / / make sure we don ' t explode compile time . <nl> + if ( RecursionDepth > = MaxRecursionDepth ) <nl> + return SILValue ( ) ; <nl> + <nl> + SILValue NewValue = stripRCIdentityPreservingOps ( V , RecursionDepth ) ; <nl> + if ( ! NewValue ) <nl> + return SILValue ( ) ; <nl> + <nl> + / / We can get back V if our analysis completely fails . There is no point in <nl> + / / storing this value into the cache so just return it . <nl> + if ( NewValue = = V ) <nl> + return V ; <nl> + <nl> + return NewValue ; <nl> + } <nl> + <nl> + SILValue RCIdentityFunctionInfo : : getRCIdentityRoot ( SILValue V ) { <nl> + SILValue Root = getRCIdentityRootInner ( V , 0 ) ; <nl> + VisitedArgs . clear ( ) ; <nl> + <nl> + / / If we fail to find a root , return V . <nl> + if ( ! Root ) <nl> + return V ; <nl> + <nl> + return Root ; <nl> + } <nl> + <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> / / RCUser Analysis <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> void RCIdentityFunctionInfo : : getRCUsers ( <nl> / / Main Entry Point <nl> / / = = = mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - = = = / / <nl> <nl> - SILValue RCIdentityFunctionInfo : : getRCIdentityRootInner ( SILValue V , <nl> - unsigned RecursionDepth ) { <nl> - / / Only allow this method to be recursed on for a limited number of times to <nl> - / / make sure we don ' t explode compile time . <nl> - if ( RecursionDepth > = MaxRecursionDepth ) <nl> - return SILValue ( ) ; <nl> - <nl> - SILValue NewValue = stripRCIdentityPreservingOps ( V , RecursionDepth ) ; <nl> - if ( ! NewValue ) <nl> - return SILValue ( ) ; <nl> - <nl> - / / We can get back V if our analysis completely fails . There is no point in <nl> - / / storing this value into the cache so just return it . <nl> - if ( NewValue = = V ) <nl> - return V ; <nl> - <nl> - return NewValue ; <nl> - } <nl> - <nl> - SILValue RCIdentityFunctionInfo : : getRCIdentityRoot ( SILValue V ) { <nl> - SILValue Root = getRCIdentityRootInner ( V , 0 ) ; <nl> - VisitedArgs . clear ( ) ; <nl> - <nl> - / / If we fail to find a root , return V . <nl> - if ( ! Root ) <nl> - return V ; <nl> - <nl> - return Root ; <nl> - } <nl> - <nl> void RCIdentityAnalysis : : initialize ( SILPassManager * PM ) { <nl> DA = PM - > getAnalysis < DominanceAnalysis > ( ) ; <nl> } <nl>
[ gardening ] [ rc - id ] Move the main RCIdentityRoot analysis entry point into the RCIdentityRoot analysis section .
apple/swift
1b83009456efa861cb66f2a7f0fe2e7df0d732d8
2016-01-12T22:31:10Z
mmm a / dbms / src / Functions / FunctionBinaryArithmetic . h <nl> ppp b / dbms / src / Functions / FunctionBinaryArithmetic . h <nl> <nl> # pragma once <nl> <nl> + / / Include this first , because ` # define _asan_poison_address ` from <nl> + / / llvm / Support / Compiler . h conflicts with its forward declaration in <nl> + / / sanitizer / asan_interface . h <nl> + # include < Common / Arena . h > <nl> + <nl> # include < DataTypes / DataTypesNumber . h > <nl> # include < DataTypes / DataTypesDecimal . h > <nl> # include < DataTypes / DataTypeDate . h > <nl> <nl> # include " castTypeToEither . h " <nl> # include " FunctionFactory . h " <nl> # include < Common / typeid_cast . h > <nl> - # include < Common / Arena . h > <nl> # include < Common / config . h > <nl> <nl> # if USE_EMBEDDED_COMPILER <nl>
Include asan_interface . h before including LLVM internals .
ClickHouse/ClickHouse
b44552542628463b9d6c5d8e742b3ecb166f5eca
2019-07-02T17:48:00Z
mmm a / utils / update - checkout <nl> ppp b / utils / update - checkout <nl> def obtain_additional_swift_sources ( <nl> shell . call ( [ ' git ' , ' - - git - dir ' , src_path , ' - - work - tree ' , <nl> os . path . join ( SWIFT_SOURCE_ROOT , repo_name ) , <nl> ' checkout ' , repo_branch ] , echo = False ) <nl> - with shell . pushd ( os . path . join ( SWIFT_SOURCE_ROOT , dir_name ) , <nl> + with shell . pushd ( os . path . join ( SWIFT_SOURCE_ROOT , repo_name ) , <nl> dry_run = False , echo = False ) : <nl> shell . call ( [ " git " , " submodule " , " update " , " - - recursive " ] , <nl> echo = False ) <nl>
[ utils ] Fix dir_name - > repo_name
apple/swift
b2903a9b3d0bb7de3d98b4dc9a9fecc3aaad6daf
2016-06-21T21:52:25Z
mmm a / include / swift / SIL / SILFunction . h <nl> ppp b / include / swift / SIL / SILFunction . h <nl> class SILFunction <nl> / / / SILFunction . <nl> SILType mapTypeIntoContext ( SILType type ) const ; <nl> <nl> - / / / Map the given type , which is based on a contextual SILFunctionType and may <nl> - / / / therefore contain context archetypes , to an interface type . <nl> - Type mapTypeOutOfContext ( Type type ) const ; <nl> - <nl> / / / Converts the given function definition to a declaration . <nl> void convertToDeclaration ( ) ; <nl> <nl> mmm a / lib / IRGen / GenReflection . cpp <nl> ppp b / lib / IRGen / GenReflection . cpp <nl> class BoxDescriptorBuilder : public ReflectionMetadataBuilder { <nl> / / / captures are generic . <nl> class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { <nl> swift : : reflection : : MetadataSourceBuilder SourceBuilder ; <nl> - SILFunction & Caller ; <nl> CanSILFunctionType OrigCalleeType ; <nl> CanSILFunctionType SubstCalleeType ; <nl> SubstitutionList Subs ; <nl> class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { <nl> <nl> public : <nl> CaptureDescriptorBuilder ( IRGenModule & IGM , <nl> - SILFunction & Caller , <nl> CanSILFunctionType OrigCalleeType , <nl> CanSILFunctionType SubstCalleeType , <nl> SubstitutionList Subs , <nl> const HeapLayout & Layout ) <nl> : ReflectionMetadataBuilder ( IGM ) , <nl> - Caller ( Caller ) , OrigCalleeType ( OrigCalleeType ) , <nl> + OrigCalleeType ( OrigCalleeType ) , <nl> SubstCalleeType ( SubstCalleeType ) , Subs ( Subs ) , <nl> Layout ( Layout ) { } <nl> <nl> class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { <nl> <nl> auto Source = SourceBuilder . createClosureBinding ( i ) ; <nl> auto BindingType = Bindings [ i ] . TypeParameter ; <nl> - auto InterfaceType = Caller . mapTypeOutOfContext ( BindingType ) ; <nl> + auto InterfaceType = BindingType - > mapTypeOutOfContext ( ) ; <nl> SourceMap . push_back ( { InterfaceType - > getCanonicalType ( ) , Source } ) ; <nl> } <nl> <nl> class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { <nl> auto Src = Path . getMetadataSource ( SourceBuilder , Root ) ; <nl> <nl> auto SubstType = GenericParam . subst ( SubstMap ) ; <nl> - auto InterfaceType = Caller . mapTypeOutOfContext ( SubstType ) ; <nl> + auto InterfaceType = SubstType - > mapTypeOutOfContext ( ) ; <nl> SourceMap . push_back ( { InterfaceType - > getCanonicalType ( ) , Src } ) ; <nl> } ) ; <nl> <nl> class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { <nl> } ) - > getCanonicalType ( ) ; <nl> } <nl> <nl> - auto InterfaceType = Caller . mapTypeOutOfContext ( SwiftType ) ; <nl> + auto InterfaceType = SwiftType - > mapTypeOutOfContext ( ) ; <nl> CaptureTypes . push_back ( InterfaceType - > getCanonicalType ( ) ) ; <nl> } <nl> <nl> IRGenModule : : getAddrOfCaptureDescriptor ( SILFunction & Caller , <nl> if ( CaptureDescriptorBuilder : : hasOpenedExistential ( OrigCalleeType , Layout ) ) <nl> return llvm : : Constant : : getNullValue ( CaptureDescriptorPtrTy ) ; <nl> <nl> - CaptureDescriptorBuilder builder ( * this , Caller , <nl> + CaptureDescriptorBuilder builder ( * this , <nl> OrigCalleeType , SubstCalleeType , Subs , <nl> Layout ) ; <nl> auto var = builder . emit ( ) ; <nl> mmm a / lib / IRGen / IRGenSIL . cpp <nl> ppp b / lib / IRGen / IRGenSIL . cpp <nl> void IRGenSILFunction : : visitRetainValueAddrInst ( swift : : RetainValueAddrInst * i ) { <nl> llvm : : Type * llvmType = addr . getAddress ( ) - > getType ( ) ; <nl> const TypeInfo & addrTI = getTypeInfo ( addrTy ) ; <nl> auto * outlinedF = IGM . getOrCreateRetainFunction ( <nl> - addrTI , i - > getFunction ( ) <nl> - - > mapTypeOutOfContext ( objectT . getSwiftRValueType ( ) ) <nl> + addrTI , objectT . getSwiftRValueType ( ) - > mapTypeOutOfContext ( ) <nl> - > getCanonicalType ( ) , <nl> llvmType ) ; <nl> llvm : : Value * args [ ] = { addr . getAddress ( ) } ; <nl> void IRGenSILFunction : : visitReleaseValueAddrInst ( <nl> llvm : : Type * llvmType = addr . getAddress ( ) - > getType ( ) ; <nl> const TypeInfo & addrTI = getTypeInfo ( addrTy ) ; <nl> auto * outlinedF = IGM . getOrCreateReleaseFunction ( <nl> - addrTI , i - > getFunction ( ) <nl> - - > mapTypeOutOfContext ( objectT . getSwiftRValueType ( ) ) <nl> + addrTI , objectT . getSwiftRValueType ( ) - > mapTypeOutOfContext ( ) <nl> - > getCanonicalType ( ) , <nl> llvmType ) ; <nl> llvm : : Value * args [ ] = { addr . getAddress ( ) } ; <nl> mmm a / lib / SIL / SILFunction . cpp <nl> ppp b / lib / SIL / SILFunction . cpp <nl> SILType GenericEnvironment : : mapTypeIntoContext ( SILModule & M , <nl> genericSig ) ; <nl> } <nl> <nl> - Type SILFunction : : mapTypeOutOfContext ( Type type ) const { <nl> - return type - > mapTypeOutOfContext ( ) ; <nl> - } <nl> - <nl> bool SILFunction : : isNoReturnFunction ( ) const { <nl> return SILType : : getPrimitiveObjectType ( getLoweredFunctionType ( ) ) <nl> . isNoReturnFunction ( ) ; <nl> mmm a / lib / SILGen / SILGen . h <nl> ppp b / lib / SILGen / SILGen . h <nl> class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor < SILGenModule > { <nl> / / / Get or create the declaration of a reabstraction thunk with the <nl> / / / given signature . <nl> SILFunction * getOrCreateReabstractionThunk ( <nl> - GenericEnvironment * genericEnv , <nl> CanSILFunctionType thunkType , <nl> CanSILFunctionType fromType , <nl> CanSILFunctionType toType , <nl> mmm a / lib / SILGen / SILGenBridging . cpp <nl> ppp b / lib / SILGen / SILGenBridging . cpp <nl> ManagedValue SILGenFunction : : emitFuncToBlock ( SILLocation loc , <nl> / / Build the invoke function signature . The block will capture the original <nl> / / function value . <nl> auto fnInterfaceTy = cast < SILFunctionType > ( <nl> - F . mapTypeOutOfContext ( loweredFuncTy ) - > getCanonicalType ( ) ) ; <nl> + loweredFuncTy - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ) ; <nl> auto blockInterfaceTy = cast < SILFunctionType > ( <nl> - F . mapTypeOutOfContext ( loweredBlockTy ) - > getCanonicalType ( ) ) ; <nl> + loweredBlockTy - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ) ; <nl> <nl> assert ( ! blockInterfaceTy - > isCoroutine ( ) ) ; <nl> <nl> ManagedValue SILGenFunction : : emitFuncToBlock ( SILLocation loc , <nl> <nl> / / Create the invoke function . Borrow the mangling scheme from reabstraction <nl> / / thunks , which is what we are in spirit . <nl> - auto thunk = SGM . getOrCreateReabstractionThunk ( genericEnv , <nl> - invokeTy , <nl> + auto thunk = SGM . getOrCreateReabstractionThunk ( invokeTy , <nl> loweredFuncTy , <nl> loweredBlockTy , <nl> F . isSerialized ( ) ) ; <nl> SILGenFunction : : emitBlockToFunc ( SILLocation loc , <nl> inputSubstType , outputSubstType , <nl> genericEnv , interfaceSubs ) ; <nl> <nl> - auto thunk = SGM . getOrCreateReabstractionThunk ( genericEnv , <nl> - thunkTy , <nl> + auto thunk = SGM . getOrCreateReabstractionThunk ( thunkTy , <nl> loweredBlockTy , <nl> loweredFuncTy , <nl> F . isSerialized ( ) ) ; <nl> mmm a / lib / SILGen / SILGenExpr . cpp <nl> ppp b / lib / SILGen / SILGenExpr . cpp <nl> RValue RValueEmitter : : visitKeyPathExpr ( KeyPathExpr * E , SGFContext C ) { <nl> bool needsGenericContext = false ; <nl> if ( rootTy - > hasArchetype ( ) ) { <nl> needsGenericContext = true ; <nl> - rootTy = SGF . F . mapTypeOutOfContext ( rootTy ) - > getCanonicalType ( ) ; <nl> + rootTy = rootTy - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ; <nl> } <nl> <nl> auto baseTy = rootTy ; <nl> RValue RValueEmitter : : visitKeyPathExpr ( KeyPathExpr * E , SGFContext C ) { <nl> baseSubscriptTy = genSubscriptTy <nl> - > substGenericArgs ( component . getDeclRef ( ) . getSubstitutions ( ) ) ; <nl> auto baseSubscriptInterfaceTy = cast < AnyFunctionType > ( <nl> - SGF . F . mapTypeOutOfContext ( baseSubscriptTy ) - > getCanonicalType ( ) ) ; <nl> + baseSubscriptTy - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ) ; <nl> <nl> baseTy = baseSubscriptInterfaceTy . getResult ( ) ; <nl> <nl> RValue RValueEmitter : : visitKeyPathExpr ( KeyPathExpr * E , SGFContext C ) { <nl> hashable . getConcrete ( ) - > getType ( ) - > isEqual ( indexValues [ i ] . getType ( ) ) ) ; <nl> auto & value = indexValues [ i ] ; <nl> <nl> - auto indexTy = SGF . F . mapTypeOutOfContext ( value . getType ( ) ) - > getCanonicalType ( ) ; <nl> + auto indexTy = value . getType ( ) - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ; <nl> auto indexLoweredTy = SGF . getLoweredType ( value . getType ( ) ) ; <nl> indexLoweredTy = SILType : : getPrimitiveType ( <nl> - SGF . F . mapTypeOutOfContext ( indexLoweredTy . getSwiftRValueType ( ) ) <nl> + indexLoweredTy . getSwiftRValueType ( ) - > mapTypeOutOfContext ( ) <nl> - > getCanonicalType ( ) , <nl> indexLoweredTy . getCategory ( ) ) ; <nl> indexPatterns . push_back ( { ( unsigned ) operands . size ( ) , <nl> mmm a / lib / SILGen / SILGenPoly . cpp <nl> ppp b / lib / SILGen / SILGenPoly . cpp <nl> static ManagedValue createThunk ( SILGenFunction & SGF , <nl> genericEnv , <nl> interfaceSubs ) ; <nl> auto thunk = SGF . SGM . getOrCreateReabstractionThunk ( <nl> - genericEnv , <nl> thunkType , <nl> sourceType , <nl> toType , <nl> mmm a / lib / SILGen / SILGenThunk . cpp <nl> ppp b / lib / SILGen / SILGenThunk . cpp <nl> SILValue SILGenFunction : : emitGlobalFunctionRef ( SILLocation loc , <nl> } <nl> <nl> SILFunction * SILGenModule : : <nl> - getOrCreateReabstractionThunk ( GenericEnvironment * genericEnv , <nl> - CanSILFunctionType thunkType , <nl> + getOrCreateReabstractionThunk ( CanSILFunctionType thunkType , <nl> CanSILFunctionType fromType , <nl> CanSILFunctionType toType , <nl> IsSerialized_t Serialized ) { <nl> mmm a / lib / SILOptimizer / IPO / CapturePropagation . cpp <nl> ppp b / lib / SILOptimizer / IPO / CapturePropagation . cpp <nl> void CapturePropagationCloner : : cloneBlocks ( <nl> } <nl> <nl> CanSILFunctionType getPartialApplyInterfaceResultType ( PartialApplyInst * PAI ) { <nl> - SILFunction * OrigF = PAI - > getReferencedFunction ( ) ; <nl> / / The new partial_apply will no longer take any arguments - - they are all <nl> / / expressed as literals . So its callee signature will be the same as its <nl> / / return signature . <nl> auto FTy = PAI - > getType ( ) . castTo < SILFunctionType > ( ) ; <nl> assert ( ! PAI - > hasSubstitutions ( ) | | ! hasArchetypes ( PAI - > getSubstitutions ( ) ) ) ; <nl> FTy = cast < SILFunctionType > ( <nl> - OrigF - > mapTypeOutOfContext ( FTy ) - > getCanonicalType ( ) ) ; <nl> + FTy - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ) ; <nl> auto NewFTy = FTy ; <nl> return NewFTy ; <nl> } <nl> mmm a / lib / SILOptimizer / Transforms / FunctionSignatureOpts . cpp <nl> ppp b / lib / SILOptimizer / Transforms / FunctionSignatureOpts . cpp <nl> mapInterfaceTypes ( SILFunction * F , <nl> if ( ! Param . getType ( ) - > hasArchetype ( ) ) <nl> continue ; <nl> Param = SILParameterInfo ( <nl> - F - > mapTypeOutOfContext ( Param . getType ( ) ) - > getCanonicalType ( ) , <nl> + Param . getType ( ) - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) , <nl> Param . getConvention ( ) ) ; <nl> } <nl> <nl> mapInterfaceTypes ( SILFunction * F , <nl> if ( ! Result . getType ( ) - > hasArchetype ( ) ) <nl> continue ; <nl> auto InterfaceResult = Result . getWithType ( <nl> - F - > mapTypeOutOfContext ( Result . getType ( ) ) - > getCanonicalType ( ) ) ; <nl> + Result . getType ( ) - > mapTypeOutOfContext ( ) - > getCanonicalType ( ) ) ; <nl> Result = InterfaceResult ; <nl> } <nl> <nl> if ( InterfaceErrorResult . hasValue ( ) ) { <nl> if ( InterfaceErrorResult . getValue ( ) . getType ( ) - > hasArchetype ( ) ) { <nl> InterfaceErrorResult = SILResultInfo ( <nl> - F - > mapTypeOutOfContext ( InterfaceErrorResult . getValue ( ) . getType ( ) ) <nl> + InterfaceErrorResult . getValue ( ) . getType ( ) - > mapTypeOutOfContext ( ) <nl> - > getCanonicalType ( ) , <nl> InterfaceErrorResult . getValue ( ) . getConvention ( ) ) ; <nl> } <nl>
SIL : Remove SILFunction : : mapTypeOutOfContext ( )
apple/swift
cce30cc9bb19980bf2926069e90897447ceac8e6
2017-11-16T06:52:28Z
mmm a / src / core / lib / iomgr / ev_epoll_linux . c <nl> ppp b / src / core / lib / iomgr / ev_epoll_linux . c <nl> static void fd_global_init ( void ) ; <nl> static void fd_global_shutdown ( void ) ; <nl> <nl> # define CLOSURE_NOT_READY ( ( gpr_atm ) 0 ) <nl> - # define CLOSURE_READY ( ( gpr_atm ) 1 ) <nl> + # define CLOSURE_READY ( ( gpr_atm ) 2 ) <nl> <nl> # define FD_SHUTDOWN_BIT 1 <nl> <nl>
Distinguish between CLOSURE_READY and ( GRPC_ERROR_NONE | FD_SHUTDOWN_BIT )
grpc/grpc
ff4b25d802845d3237e3890db240f3059d0ff784
2017-02-16T23:07:11Z
mmm a / examples / opengl3_example / imgui_impl_glfw_gl3 . cpp <nl> ppp b / examples / opengl3_example / imgui_impl_glfw_gl3 . cpp <nl> void ImGui_ImplGlfwGL3_NewFrame ( ) <nl> <nl> / / Setup inputs <nl> / / ( we already got mouse wheel , keyboard keys & characters from glfw callbacks polled in glfwPollEvents ( ) ) <nl> - double mouse_x , mouse_y ; <nl> - glfwGetCursorPos ( g_Window , & mouse_x , & mouse_y ) ; <nl> - mouse_x * = ( float ) display_w / w ; / / Convert mouse coordinates to pixels <nl> - mouse_y * = ( float ) display_h / h ; <nl> - io . MousePos = ImVec2 ( ( float ) mouse_x , ( float ) mouse_y ) ; / / Mouse position , in pixels ( set to - 1 , - 1 if no mouse / on another screen , etc . ) <nl> + if ( glfwGetWindowAttrib ( g_Window , GLFW_FOCUSED ) ) <nl> + { <nl> + double mouse_x , mouse_y ; <nl> + glfwGetCursorPos ( g_Window , & mouse_x , & mouse_y ) ; <nl> + mouse_x * = ( float ) display_w / w ; / / Convert mouse coordinates to pixels <nl> + mouse_y * = ( float ) display_h / h ; <nl> + io . MousePos = ImVec2 ( ( float ) mouse_x , ( float ) mouse_y ) ; / / Mouse position , in pixels ( set to - 1 , - 1 if no mouse / on another screen , etc . ) <nl> + } <nl> + else <nl> + { <nl> + io . MousePos = ImVec2 ( - 1 , - 1 ) ; <nl> + } <nl> <nl> for ( int i = 0 ; i < 3 ; i + + ) <nl> { <nl> mmm a / examples / opengl_example / imgui_impl_glfw . cpp <nl> ppp b / examples / opengl_example / imgui_impl_glfw . cpp <nl> void ImGui_ImplGlfw_NewFrame ( ) <nl> <nl> / / Setup inputs <nl> / / ( we already got mouse wheel , keyboard keys & characters from glfw callbacks polled in glfwPollEvents ( ) ) <nl> - double mouse_x , mouse_y ; <nl> - glfwGetCursorPos ( g_Window , & mouse_x , & mouse_y ) ; <nl> - mouse_x * = ( float ) display_w / w ; / / Convert mouse coordinates to pixels <nl> - mouse_y * = ( float ) display_h / h ; <nl> - io . MousePos = ImVec2 ( ( float ) mouse_x , ( float ) mouse_y ) ; / / Mouse position , in pixels ( set to - 1 , - 1 if no mouse / on another screen , etc . ) <nl> + if ( glfwGetWindowAttrib ( g_Window , GLFW_FOCUSED ) ) <nl> + { <nl> + double mouse_x , mouse_y ; <nl> + glfwGetCursorPos ( g_Window , & mouse_x , & mouse_y ) ; <nl> + mouse_x * = ( float ) display_w / w ; / / Convert mouse coordinates to pixels <nl> + mouse_y * = ( float ) display_h / h ; <nl> + io . MousePos = ImVec2 ( ( float ) mouse_x , ( float ) mouse_y ) ; / / Mouse position , in pixels ( set to - 1 , - 1 if no mouse / on another screen , etc . ) <nl> + } <nl> + else <nl> + { <nl> + io . MousePos = ImVec2 ( - 1 , - 1 ) ; <nl> + } <nl> <nl> for ( int i = 0 ; i < 3 ; i + + ) <nl> { <nl>
opengl3 + opengl example : if content window doesn ' t have focus , tell ImGui we don ' t have a mouse position . e . g . avoids tooltips popping up in imgui app when you ' re interacting with a different app window that overlaps it .
ocornut/imgui
f2ff88b03ad03644b756d11a8b839dafa34a8741
2015-03-16T10:47:14Z
mmm a / src / compiler / representation - change . cc <nl> ppp b / src / compiler / representation - change . cc <nl> Node * RepresentationChanger : : GetTaggedPointerRepresentationFor ( <nl> } <nl> op = simplified ( ) - > ChangeFloat64ToTaggedPointer ( ) ; <nl> } else if ( output_rep = = MachineRepresentation : : kFloat32 ) { <nl> - / / float32 - > float64 - > tagged <nl> - node = InsertChangeFloat32ToFloat64 ( node ) ; <nl> - op = simplified ( ) - > ChangeFloat64ToTaggedPointer ( ) ; <nl> + if ( output_type - > Is ( Type : : Number ( ) ) ) { <nl> + / / float32 - > float64 - > tagged <nl> + node = InsertChangeFloat32ToFloat64 ( node ) ; <nl> + op = simplified ( ) - > ChangeFloat64ToTaggedPointer ( ) ; <nl> + } else { <nl> + return TypeError ( node , output_rep , output_type , <nl> + MachineRepresentation : : kTaggedPointer ) ; <nl> + } <nl> } else if ( output_rep = = MachineRepresentation : : kFloat64 ) { <nl> - / / float64 - > tagged <nl> - op = simplified ( ) - > ChangeFloat64ToTaggedPointer ( ) ; <nl> + if ( output_type - > Is ( Type : : Number ( ) ) ) { <nl> + / / float64 - > tagged <nl> + op = simplified ( ) - > ChangeFloat64ToTaggedPointer ( ) ; <nl> + } else { <nl> + return TypeError ( node , output_rep , output_type , <nl> + MachineRepresentation : : kTaggedPointer ) ; <nl> + } <nl> } else if ( CanBeTaggedSigned ( output_rep ) & & <nl> use_info . type_check ( ) = = TypeCheckKind : : kHeapObject ) { <nl> if ( ! output_type - > Maybe ( Type : : SignedSmall ( ) ) ) { <nl> Node * RepresentationChanger : : GetTaggedRepresentationFor ( <nl> Type : : Unsigned32 ( ) ) ) { / / float64 - > uint32 - > tagged <nl> node = InsertChangeFloat64ToUint32 ( node ) ; <nl> op = simplified ( ) - > ChangeUint32ToTagged ( ) ; <nl> - } else { <nl> + } else if ( output_type - > Is ( Type : : Number ( ) ) ) { <nl> op = simplified ( ) - > ChangeFloat64ToTagged ( <nl> output_type - > Maybe ( Type : : MinusZero ( ) ) <nl> ? CheckForMinusZeroMode : : kCheckForMinusZero <nl> : CheckForMinusZeroMode : : kDontCheckForMinusZero ) ; <nl> + } else { <nl> + return TypeError ( node , output_rep , output_type , <nl> + MachineRepresentation : : kTagged ) ; <nl> } <nl> } else { <nl> return TypeError ( node , output_rep , output_type , <nl>
[ turbofan ] Remove self - healing wrt . ChangeFloat64ToTagged .
v8/v8
6b4e8c2114b04d3d9f39f4d7c49108ea4d56ae12
2017-05-04T12:32:27Z
mmm a / core / io / image_loader . cpp <nl> ppp b / core / io / image_loader . cpp <nl> RES ResourceFormatLoaderImage : : load ( const String & p_path , const String & p_origin <nl> if ( r_error ) { <nl> * r_error = ERR_CANT_OPEN ; <nl> } <nl> - memdelete ( f ) ; <nl> return RES ( ) ; <nl> } <nl> <nl> mmm a / modules / theora / video_stream_theora . cpp <nl> ppp b / modules / theora / video_stream_theora . cpp <nl> RES ResourceFormatLoaderTheora : : load ( const String & p_path , const String & p_origi <nl> if ( r_error ) { <nl> * r_error = ERR_CANT_OPEN ; <nl> } <nl> - memdelete ( f ) ; <nl> return RES ( ) ; <nl> } <nl> <nl> mmm a / modules / webm / video_stream_webm . cpp <nl> ppp b / modules / webm / video_stream_webm . cpp <nl> RES ResourceFormatLoaderWebm : : load ( const String & p_path , const String & p_origina <nl> if ( r_error ) { <nl> * r_error = ERR_CANT_OPEN ; <nl> } <nl> - memdelete ( f ) ; <nl> return RES ( ) ; <nl> } <nl> <nl>
Merge pull request from Zylann / fix_load_memdelete_null
godotengine/godot
08dd03589931859b8e038e831e71f060584fc6d3
2018-10-05T19:41:57Z
mmm a / python / mxnet / ndarray / ndarray . py <nl> ppp b / python / mxnet / ndarray / ndarray . py <nl> def __setstate__ ( self , state ) : <nl> else : <nl> self . handle = None <nl> <nl> + # pylint : disable = line - too - long <nl> def __setitem__ ( self , key , value ) : <nl> " " " x . __setitem__ ( i , y ) < = > x [ i ] = y <nl> <nl> - Set self [ key ] to value . <nl> + Sets value to self [ key ] . This functions supports advanced indexing defined in the following reference with <nl> + some restrictions . <nl> + <nl> + https : / / docs . scipy . org / doc / numpy - 1 . 13 . 0 / reference / arrays . indexing . html # combining - advanced - and - basic - indexing <nl> + <nl> + - If key is a list type , only a list of integers is supported , e . g . key = [ 1 , 2 ] is supported , <nl> + while not for key = [ [ 1 , 2 ] ] . <nl> + - Ellipsis ( . . . ) and np . newaxis are not supported . <nl> + - Boolean array indexing is not supported . <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - key : int , slice or tuple <nl> + key : int , slice , list , np . ndarray , NDArray , or tuple of all previous types <nl> The indexing key . <nl> - value : scalar , NDArray or numpy . ndarray <nl> + value : scalar or array - like object that can be broadcast to the shape of self [ key ] <nl> The value to set . <nl> <nl> Examples <nl> def __setitem__ ( self , key , value ) : <nl> else : <nl> raise ValueError ( ' Indexing NDArray with index = % s and type = % s is not supported ' <nl> % ( str ( key ) , str ( type ( key ) ) ) ) <nl> + # pylint : enable = line - too - long <nl> <nl> # pylint : disable = line - too - long <nl> def __getitem__ ( self , key ) : <nl> " " " x . __getitem__ ( i ) < = > x [ i ] <nl> + <nl> Returns a sliced view of this array if the elements fetched are contiguous in memory ; <nl> otherwise , returns a newly created NDArray . <nl> This functions supports advanced indexing defined in the following reference with <nl> - some limitations . <nl> + some restrictions . <nl> + <nl> https : / / docs . scipy . org / doc / numpy - 1 . 13 . 0 / reference / arrays . indexing . html # combining - advanced - and - basic - indexing <nl> - The following features / functionality are not supported for now : <nl> - 1 . If key is a list type , only a list of integers is supported , <nl> - i . e . key = [ 1 , 2 ] is okay , while not for key = [ [ 1 ] ] . <nl> - 2 . Ellipsis ( . . . ) and np . newaxis are not supported . <nl> - 3 . Boolean array indexing . <nl> + <nl> + - If key is a list type , only a list of integers is supported , e . g . key = [ 1 , 2 ] is supported , <nl> + while not for key = [ [ 1 , 2 ] ] . <nl> + - Ellipsis ( . . . ) and np . newaxis are not supported . <nl> + - Boolean array indexing is not supported . <nl> <nl> Parameters <nl> mmmmmmmmm - <nl> - key : int or slice , or array like <nl> + key : int , slice , list , np . ndarray , NDArray , or tuple of all previous types <nl> Indexing key . <nl> <nl> Examples <nl>
Fix docstring format ( )
apache/incubator-mxnet
4dc893382cb9d391fb66cfedca19a022c85eb012
2017-11-21T03:20:00Z
mmm a / tools / swift - reflection - dump / swift - reflection - dump . cpp <nl> ppp b / tools / swift - reflection - dump / swift - reflection - dump . cpp <nl> class Image { <nl> <nl> uint64_t HeaderAddress ; <nl> std : : vector < Segment > Segments ; <nl> + llvm : : DenseMap < uint64_t , StringRef > DynamicRelocations ; <nl> <nl> void scanMachO ( const MachOObjectFile * O ) { <nl> using namespace llvm : : MachO ; <nl> <nl> HeaderAddress = UINT64_MAX ; <nl> <nl> + / / Collect the segment preferred vm mappings . <nl> for ( const auto & Load : O - > load_commands ( ) ) { <nl> if ( Load . C . cmd = = LC_SEGMENT_64 ) { <nl> auto Seg = O - > getSegment64LoadCommand ( Load ) ; <nl> class Image { <nl> HeaderAddress = std : : min ( HeaderAddress , ( uint64_t ) Seg . vmaddr ) ; <nl> } <nl> } <nl> + <nl> + / / Walk through the bindings list to collect all the external references <nl> + / / in the image . <nl> + llvm : : Error error = llvm : : Error : : success ( ) ; <nl> + auto OO = const_cast < MachOObjectFile * > ( O ) ; <nl> + <nl> + for ( auto bind : OO - > bindTable ( error ) ) { <nl> + if ( error ) { <nl> + llvm : : consumeError ( std : : move ( error ) ) ; <nl> + break ; <nl> + } <nl> + <nl> + DynamicRelocations . insert ( { bind . address ( ) , bind . symbolName ( ) } ) ; <nl> + } <nl> + if ( error ) { <nl> + llvm : : consumeError ( std : : move ( error ) ) ; <nl> + } <nl> } <nl> <nl> template < typename ELFT > <nl> class Image { <nl> } <nl> return { } ; <nl> } <nl> + <nl> + RemoteAbsolutePointer <nl> + resolvePointer ( uint64_t Addr , uint64_t pointerValue ) const { <nl> + auto found = DynamicRelocations . find ( Addr ) ; <nl> + if ( found = = DynamicRelocations . end ( ) ) <nl> + return RemoteAbsolutePointer ( " " , pointerValue ) ; <nl> + <nl> + return RemoteAbsolutePointer ( found - > second , pointerValue ) ; <nl> + } <nl> } ; <nl> <nl> / / / MemoryReader that reads from the on - disk representation of an executable <nl> class Image { <nl> / / / the image . <nl> class ObjectMemoryReader : public MemoryReader { <nl> std : : vector < Image > Images ; <nl> + <nl> + std : : pair < const Image * , uint64_t > <nl> + decodeImageIndexAndAddress ( uint64_t Addr ) const { <nl> + unsigned index = Addr > > 48 ; <nl> + if ( index > = Images . size ( ) ) <nl> + return { nullptr , 0 } ; <nl> + <nl> + return { & Images [ index ] , Addr & ( ( 1ull < < 48 ) - 1 ) } ; <nl> + } <nl> + <nl> + uint64_t <nl> + encodeImageIndexAndAddress ( const Image * image , uint64_t imageAddr ) const { <nl> + unsigned index = image - Images . data ( ) ; <nl> + return imageAddr | ( ( uint64_t ) index < < 48 ) ; <nl> + } <nl> <nl> StringRef getContentsAtAddress ( uint64_t Addr , uint64_t Size ) { <nl> - auto imageIndex = Addr > > 48 ; <nl> - if ( imageIndex > = Images . size ( ) ) <nl> + const Image * image ; <nl> + uint64_t imageAddr ; <nl> + std : : tie ( image , imageAddr ) = decodeImageIndexAndAddress ( Addr ) ; <nl> + <nl> + if ( ! image ) <nl> return StringRef ( ) ; <nl> <nl> - return Images [ imageIndex ] <nl> - . getContentsAtAddress ( Addr & 0xFFFFFFFFFFFFull , Size ) ; <nl> + return image - > getContentsAtAddress ( imageAddr , Size ) ; <nl> } <nl> <nl> public : <nl> class ObjectMemoryReader : public MemoryReader { <nl> RemoteAddress getImageStartAddress ( unsigned i ) const { <nl> assert ( i < Images . size ( ) ) ; <nl> <nl> - return RemoteAddress ( Images [ i ] . getStartAddress ( ) | ( ( uint64_t ) i < < 48 ) ) ; <nl> + return RemoteAddress ( <nl> + encodeImageIndexAndAddress ( & Images [ i ] , Images [ i ] . getStartAddress ( ) ) ) ; <nl> } <nl> <nl> / / TODO : We could consult the dynamic symbol tables of the images to <nl> class ObjectMemoryReader : public MemoryReader { <nl> Dest . append ( resultBuffer . begin ( ) , resultBuffer . begin ( ) + i ) ; <nl> return true ; <nl> } <nl> + <nl> + RemoteAbsolutePointer resolvePointer ( RemoteAddress Addr , <nl> + uint64_t pointerValue ) override { <nl> + auto addrValue = Addr . getAddressData ( ) ; <nl> + const Image * image ; <nl> + uint64_t imageAddr ; <nl> + std : : tie ( image , imageAddr ) = <nl> + decodeImageIndexAndAddress ( addrValue ) ; <nl> + <nl> + if ( ! image ) <nl> + return RemoteAbsolutePointer ( ) ; <nl> + <nl> + auto resolved = image - > resolvePointer ( imageAddr , pointerValue ) ; <nl> + <nl> + if ( resolved & & resolved . isResolved ( ) ) { <nl> + / / Mix in the image index again to produce a remote address pointing into <nl> + / / the same image . <nl> + return RemoteAbsolutePointer ( " " , encodeImageIndexAndAddress ( image , <nl> + resolved . getResolvedAddress ( ) . getAddressData ( ) ) ) ; <nl> + } <nl> + / / If the pointer is relative to an unresolved relocation , leave it as is . <nl> + return resolved ; <nl> + } <nl> } ; <nl> <nl> static int doDumpReflectionSections ( ArrayRef < std : : string > BinaryFilenames , <nl>
swift - reflection - dump : Mach - O binding list support
apple/swift
bce163608fef896547a52a32e141ef6a4f4a794d
2019-10-01T19:36:55Z
mmm a / dlib / cmake_utils / cmake_find_blas . txt <nl> ppp b / dlib / cmake_utils / cmake_find_blas . txt <nl> if ( NOT blas_found ) <nl> endif ( ) <nl> endif ( ) <nl> <nl> - if ( NOT lapack_found ) <nl> + if ( blas_found AND NOT lapack_found ) <nl> find_package ( LAPACK QUIET ) <nl> if ( $ { LAPACK_FOUND } ) <nl> set ( lapack_libraries $ { LAPACK_LIBRARIES } ) <nl>
Fixed confusing warning message from cmake about BLAS .
davisking/dlib
06acdcacffca2131752dbfa3b64244baf4335322
2018-02-07T20:57:35Z
mmm a / site / source / docs / api_reference / val . h . rst <nl> ppp b / site / source / docs / api_reference / val . h . rst <nl> Guide material for this class can be found in : ref : ` embind - val - guide ` . <nl> val xhr = val : : global ( " XMLHttpRequest " ) . new_ ( ) ; <nl> xhr . call ( " open " , std : : string ( " GET " ) , std : : string ( " http : / / url " ) ) ; <nl> <nl> + You can test whether the ` ` open ` ` method call was successful using : cpp : func : ` ~ emscripten : : val : : operator [ ] ` to read an object property , then : cpp : func : ` ~ emscripten : : val : : as ` to coerce the type : <nl> + <nl> + . . code : : cpp <nl> + <nl> + const char * state ; <nl> + switch ( xhr [ " readyState " ] . as < int > ( ) ) { <nl> + case 0 : <nl> + state = " UNSENT " ; break ; <nl> + case 1 : <nl> + state = " OPENED " ; break ; <nl> + default : <nl> + state = " etc " ; <nl> + } <nl> <nl> See : ref : ` embind - val - guide ` for other examples . <nl> <nl>
Added minimum val [ ] and as ( ) docs ( )
emscripten-core/emscripten
041988e095b50f6cdfa11a3440c3078e933a0152
2020-01-02T19:05:23Z
mmm a / libraries / chain / controller . cpp <nl> ppp b / libraries / chain / controller . cpp <nl> struct controller_impl { <nl> transaction_trace_ptr push_transaction ( const transaction_metadata_ptr & trx , <nl> fc : : time_point deadline , <nl> uint32_t billed_cpu_time_us , <nl> - bool explicit_billed_cpu_time = false ) <nl> + bool explicit_billed_cpu_time ) <nl> { <nl> EOS_ASSERT ( deadline ! = fc : : time_point ( ) , transaction_exception , " deadline cannot be uninitialized " ) ; <nl> <nl> struct controller_impl { <nl> ? transaction_receipt : : executed <nl> : transaction_receipt : : delayed ; <nl> trace - > receipt = push_receipt ( * trx - > packed_trx ( ) , s , trx_context . billed_cpu_time_us , trace - > net_usage ) ; <nl> + trx - > billed_cpu_time_us = trx_context . billed_cpu_time_us ; <nl> pending - > _block_stage . get < building_block > ( ) . _pending_trx_metas . emplace_back ( trx ) ; <nl> } else { <nl> transaction_receipt_header r ; <nl> bool controller : : in_immutable_mode ( ) const { <nl> return ( db_mode_is_immutable ( get_read_mode ( ) ) ) ; <nl> } <nl> <nl> - transaction_trace_ptr controller : : push_transaction ( const transaction_metadata_ptr & trx , fc : : time_point deadline , uint32_t billed_cpu_time_us ) { <nl> + transaction_trace_ptr controller : : push_transaction ( const transaction_metadata_ptr & trx , fc : : time_point deadline , <nl> + uint32_t billed_cpu_time_us , bool explicit_billed_cpu_time ) { <nl> validate_db_available_size ( ) ; <nl> EOS_ASSERT ( ! in_immutable_mode ( ) , transaction_type_exception , " push transaction not allowed in read - only mode " ) ; <nl> EOS_ASSERT ( trx & & ! trx - > implicit & & ! trx - > scheduled , transaction_type_exception , " Implicit / Scheduled transaction not allowed " ) ; <nl> - return my - > push_transaction ( trx , deadline , billed_cpu_time_us , billed_cpu_time_us > 0 ) ; <nl> + return my - > push_transaction ( trx , deadline , billed_cpu_time_us , explicit_billed_cpu_time ) ; <nl> } <nl> <nl> transaction_trace_ptr controller : : push_scheduled_transaction ( const transaction_id_type & trxid , fc : : time_point deadline , uint32_t billed_cpu_time_us ) <nl> mmm a / libraries / chain / include / eosio / chain / controller . hpp <nl> ppp b / libraries / chain / include / eosio / chain / controller . hpp <nl> namespace eosio { namespace chain { <nl> / * * <nl> * <nl> * / <nl> - transaction_trace_ptr push_transaction ( const transaction_metadata_ptr & trx , fc : : time_point deadline , uint32_t billed_cpu_time_us = 0 ) ; <nl> + transaction_trace_ptr push_transaction ( const transaction_metadata_ptr & trx , fc : : time_point deadline , <nl> + uint32_t billed_cpu_time_us , bool explicit_billed_cpu_time ) ; <nl> <nl> / * * <nl> * Attempt to execute a specific transaction in our deferred trx database <nl> mmm a / libraries / chain / include / eosio / chain / transaction_metadata . hpp <nl> ppp b / libraries / chain / include / eosio / chain / transaction_metadata . hpp <nl> class transaction_metadata { <nl> public : <nl> const bool implicit ; <nl> const bool scheduled ; <nl> - bool accepted = false ; / / not thread safe <nl> + bool accepted = false ; / / not thread safe <nl> + uint32_t billed_cpu_time_us = 0 ; / / not thread safe <nl> <nl> private : <nl> struct private_type { } ; <nl> mmm a / libraries / chain / transaction_context . cpp <nl> ppp b / libraries / chain / transaction_context . cpp <nl> namespace eosio { namespace chain { <nl> <nl> initial_objective_duration_limit = objective_duration_limit ; <nl> <nl> - if ( billed_cpu_time_us > 0 ) / / could also call on explicit_billed_cpu_time but it would be redundant <nl> + if ( explicit_billed_cpu_time ) <nl> validate_cpu_usage_to_bill ( billed_cpu_time_us , false ) ; / / Fail early if the amount to be billed is too high <nl> <nl> / / Record accounts to be billed for network and CPU usage <nl> namespace eosio { namespace chain { <nl> deadline_exception_code = billing_timer_exception_code ; <nl> } <nl> <nl> + if ( ! explicit_billed_cpu_time ) { <nl> + if ( account_cpu_limit < billed_cpu_time_us ) { / / if account no longer has enough cpu to exec trx , don ' t try <nl> + EOS_THROW ( deadline_exception , " account cpu $ { cpu } not sufficient for trx $ { t } us " , <nl> + ( " cpu " , account_cpu_limit ) ( " t " , billed_cpu_time_us ) ) ; <nl> + } <nl> + } <nl> + <nl> eager_net_limit = ( eager_net_limit / 8 ) * 8 ; / / Round down to nearest multiple of word size ( 8 bytes ) so check_net_usage can be efficient <nl> <nl> if ( initial_net_usage > 0 ) <nl> mmm a / libraries / testing / tester . cpp <nl> ppp b / libraries / testing / tester . cpp <nl> namespace eosio { namespace testing { <nl> <nl> if ( ! skip_pending_trxs ) { <nl> for ( auto itr = unapplied_transactions . begin ( ) ; itr ! = unapplied_transactions . end ( ) ; ) { <nl> - auto trace = control - > push_transaction ( itr - > trx_meta , fc : : time_point : : maximum ( ) , DEFAULT_BILLED_CPU_TIME_US ) ; <nl> + auto trace = control - > push_transaction ( itr - > trx_meta , fc : : time_point : : maximum ( ) , DEFAULT_BILLED_CPU_TIME_US , true ) ; <nl> if ( trace - > except ) { <nl> trace - > except - > dynamic_rethrow_exception ( ) ; <nl> } <nl> namespace eosio { namespace testing { <nl> fc : : microseconds : : maximum ( ) : <nl> fc : : microseconds ( deadline - fc : : time_point : : now ( ) ) ; <nl> auto fut = transaction_metadata : : start_recover_keys ( ptrx , control - > get_thread_pool ( ) , control - > get_chain_id ( ) , time_limit ) ; <nl> - auto r = control - > push_transaction ( fut . get ( ) , deadline , billed_cpu_time_us ) ; <nl> + auto r = control - > push_transaction ( fut . get ( ) , deadline , billed_cpu_time_us , billed_cpu_time_us > 0 ) ; <nl> if ( r - > except_ptr ) std : : rethrow_exception ( r - > except_ptr ) ; <nl> if ( r - > except ) throw * r - > except ; <nl> return r ; <nl> namespace eosio { namespace testing { <nl> fc : : microseconds ( deadline - fc : : time_point : : now ( ) ) ; <nl> auto ptrx = std : : make_shared < packed_transaction > ( trx , c ) ; <nl> auto fut = transaction_metadata : : start_recover_keys ( ptrx , control - > get_thread_pool ( ) , control - > get_chain_id ( ) , time_limit ) ; <nl> - auto r = control - > push_transaction ( fut . get ( ) , deadline , billed_cpu_time_us ) ; <nl> + auto r = control - > push_transaction ( fut . get ( ) , deadline , billed_cpu_time_us , billed_cpu_time_us > 0 ) ; <nl> if ( no_throw ) return r ; <nl> if ( r - > except_ptr ) std : : rethrow_exception ( r - > except_ptr ) ; <nl> if ( r - > except ) throw * r - > except ; <nl> mmm a / plugins / producer_plugin / producer_plugin . cpp <nl> ppp b / plugins / producer_plugin / producer_plugin . cpp <nl> class producer_plugin_impl : public std : : enable_shared_from_this < producer_plugin <nl> deadline = block_deadline ; <nl> } <nl> <nl> - auto trace = chain . push_transaction ( trx , deadline ) ; <nl> + auto trace = chain . push_transaction ( trx , deadline , trx - > billed_cpu_time_us , false ) ; <nl> if ( trace - > except ) { <nl> if ( failure_is_subjective ( * trace - > except , deadline_is_subjective ) ) { <nl> _pending_incoming_transactions . add ( trx , persist_until_expired , next ) ; <nl> bool producer_plugin_impl : : process_unapplied_trxs ( const fc : : time_point & deadlin <nl> trx_deadline = deadline ; <nl> } <nl> <nl> - auto trace = chain . push_transaction ( trx , trx_deadline ) ; <nl> + auto trace = chain . push_transaction ( trx , trx_deadline , trx - > billed_cpu_time_us , false ) ; <nl> if ( trace - > except ) { <nl> if ( failure_is_subjective ( * trace - > except , deadline_is_subjective ) ) { <nl> exhausted = true ; <nl>
Do not attempt to exec a trx if account cpu does not have sufficient cpu to execute according to last time trx was executed .
EOSIO/eos
edc194602a5b639392aeaa7f5eb73343a1fca358
2020-02-12T21:08:08Z
mmm a / src / PreferencesDialog . cpp <nl> ppp b / src / PreferencesDialog . cpp <nl> PreferencesDialog : : PreferencesDialog ( QWidget * parent ) <nl> ui - > setupUi ( this ) ; <nl> ui - > treeSyntaxHighlighting - > setColumnHidden ( 0 , true ) ; <nl> <nl> - ui - > frameNullBgColour - > installEventFilter ( this ) ; <nl> - ui - > frameNullFgColour - > installEventFilter ( this ) ; <nl> + ui - > fr_bin_bg - > installEventFilter ( this ) ; <nl> + ui - > fr_bin_fg - > installEventFilter ( this ) ; <nl> + ui - > fr_reg_bg - > installEventFilter ( this ) ; <nl> + ui - > fr_reg_fg - > installEventFilter ( this ) ; <nl> + ui - > fr_null_bg - > installEventFilter ( this ) ; <nl> + ui - > fr_null_fg - > installEventFilter ( this ) ; <nl> <nl> # ifndef CHECKNEWVERSION <nl> ui - > labelUpdates - > setVisible ( false ) ; <nl> void PreferencesDialog : : loadSettings ( ) <nl> ui - > foreignKeysCheckBox - > setChecked ( getSettingsValue ( " db " , " foreignkeys " ) . toBool ( ) ) ; <nl> ui - > spinPrefetchSize - > setValue ( getSettingsValue ( " db " , " prefetchsize " ) . toInt ( ) ) ; <nl> <nl> - QPalette palette = ui - > frameNullBgColour - > palette ( ) ; <nl> - palette . setColor ( ui - > frameNullBgColour - > backgroundRole ( ) , <nl> - QColor ( getSettingsValue ( " databrowser " , " null_bg_colour " ) . toString ( ) ) ) ; <nl> - ui - > frameNullBgColour - > setPalette ( palette ) ; <nl> - <nl> - palette = ui - > frameNullFgColour - > palette ( ) ; <nl> - palette . setColor ( ui - > frameNullFgColour - > backgroundRole ( ) , <nl> - QColor ( getSettingsValue ( " databrowser " , " null_fg_colour " ) . toString ( ) ) ) ; <nl> - ui - > frameNullFgColour - > setPalette ( palette ) ; <nl> + loadColorSetting ( ui - > fr_null_fg , " null_fg " ) ; <nl> + loadColorSetting ( ui - > fr_null_bg , " null_bg " ) ; <nl> + loadColorSetting ( ui - > fr_reg_fg , " reg_fg " ) ; <nl> + loadColorSetting ( ui - > fr_reg_bg , " reg_bg " ) ; <nl> + loadColorSetting ( ui - > fr_bin_fg , " bin_fg " ) ; <nl> + loadColorSetting ( ui - > fr_bin_bg , " bin_bg " ) ; <nl> <nl> ui - > txtNull - > setText ( getSettingsValue ( " databrowser " , " null_text " ) . toString ( ) ) ; <nl> <nl> void PreferencesDialog : : saveSettings ( ) <nl> <nl> setSettingsValue ( " checkversion " , " enabled " , ui - > checkUpdates - > isChecked ( ) ) ; <nl> <nl> - setSettingsValue ( " databrowser " , " null_bg_colour " , <nl> - ui - > frameNullBgColour - > palette ( ) . color ( ui - > frameNullBgColour - > backgroundRole ( ) ) ) ; <nl> - setSettingsValue ( " databrowser " , " null_fg_colour " , <nl> - ui - > frameNullFgColour - > palette ( ) . color ( ui - > frameNullFgColour - > backgroundRole ( ) ) ) ; <nl> + saveColorSetting ( ui - > fr_null_fg , " null_fg " ) ; <nl> + saveColorSetting ( ui - > fr_null_bg , " null_bg " ) ; <nl> + saveColorSetting ( ui - > fr_reg_fg , " reg_fg " ) ; <nl> + saveColorSetting ( ui - > fr_reg_bg , " reg_bg " ) ; <nl> + saveColorSetting ( ui - > fr_bin_fg , " bin_fg " ) ; <nl> + saveColorSetting ( ui - > fr_bin_bg , " bin_bg " ) ; <nl> setSettingsValue ( " databrowser " , " null_text " , ui - > txtNull - > text ( ) ) ; <nl> <nl> for ( int i = 0 ; i < ui - > treeSyntaxHighlighting - > topLevelItemCount ( ) ; + + i ) <nl> QVariant PreferencesDialog : : getSettingsDefaultValue ( const QString & group , const <nl> return QColor ( Qt : : lightGray ) . name ( ) ; <nl> if ( name = = " null_bg_colour " ) <nl> return QColor ( Qt : : white ) . name ( ) ; <nl> + if ( name = = " reg_fg_colour " ) <nl> + return QColor ( Qt : : black ) . name ( ) ; <nl> + if ( name = = " reg_bg_colour " ) <nl> + return QColor ( Qt : : white ) . name ( ) ; <nl> + if ( name = = " bin_fg_colour " ) <nl> + return QColor ( Qt : : lightGray ) . name ( ) ; <nl> + if ( name = = " bin_bg_colour " ) <nl> + return QColor ( Qt : : white ) . name ( ) ; <nl> } <nl> <nl> / / syntaxhighlighter ? <nl> void PreferencesDialog : : showColourDialog ( QTreeWidgetItem * item , int column ) <nl> bool PreferencesDialog : : eventFilter ( QObject * obj , QEvent * event ) <nl> { <nl> / / Use mouse click and enter press on the frames to pop up a colour dialog <nl> - if ( obj = = ui - > frameNullBgColour | | obj = = ui - > frameNullFgColour ) <nl> + if ( obj = = ui - > fr_bin_bg | | obj = = ui - > fr_bin_fg | | <nl> + obj = = ui - > fr_reg_bg | | obj = = ui - > fr_reg_fg | | <nl> + obj = = ui - > fr_null_bg | | obj = = ui - > fr_null_fg ) <nl> { <nl> if ( event - > type ( ) = = QEvent : : KeyPress ) <nl> { <nl> void PreferencesDialog : : fillLanguageBox ( ) <nl> ui - > languageComboBox - > insertItem ( 0 , chosenIcon , chosenLanguage , chosenLocale ) ; <nl> ui - > languageComboBox - > setCurrentIndex ( 0 ) ; <nl> } <nl> + <nl> + void PreferencesDialog : : loadColorSetting ( QFrame * frame , const QString & settingName ) <nl> + { <nl> + QPalette palette = frame - > palette ( ) ; <nl> + palette . setColor ( frame - > backgroundRole ( ) , <nl> + QColor ( getSettingsValue ( " databrowser " , settingName + " _colour " ) . toString ( ) ) ) ; <nl> + frame - > setPalette ( palette ) ; <nl> + } <nl> + <nl> + void PreferencesDialog : : saveColorSetting ( QFrame * frame , const QString & settingName ) <nl> + { <nl> + setSettingsValue ( " databrowser " , settingName + " _colour " , <nl> + frame - > palette ( ) . color ( frame - > backgroundRole ( ) ) ) ; <nl> + } <nl> mmm a / src / PreferencesDialog . h <nl> ppp b / src / PreferencesDialog . h <nl> <nl> # include < QHash > <nl> <nl> class QTreeWidgetItem ; <nl> + class QFrame ; <nl> <nl> namespace Ui { <nl> class PreferencesDialog ; <nl> private slots : <nl> static QHash < QString , QVariant > m_hCache ; <nl> <nl> void fillLanguageBox ( ) ; <nl> + void loadColorSetting ( QFrame * frame , const QString & name ) ; <nl> + void saveColorSetting ( QFrame * frame , const QString & name ) ; <nl> <nl> protected : <nl> bool eventFilter ( QObject * obj , QEvent * event ) ; <nl> mmm a / src / PreferencesDialog . ui <nl> ppp b / src / PreferencesDialog . ui <nl> <nl> < attribute name = " title " > <nl> < string > Data & amp ; Browser < / string > <nl> < / attribute > <nl> - < layout class = " QHBoxLayout " name = " horizontalLayout_3 " > <nl> - < item > <nl> + < layout class = " QGridLayout " name = " gridLayout_2 " > <nl> + < item row = " 0 " column = " 0 " > <nl> < spacer name = " horizontalSpacer " > <nl> < property name = " orientation " > <nl> < enum > Qt : : Horizontal < / enum > <nl> <nl> < / property > <nl> < / spacer > <nl> < / item > <nl> - < item > <nl> + < item row = " 0 " column = " 3 " > <nl> + < spacer name = " horizontalSpacer_3 " > <nl> + < property name = " orientation " > <nl> + < enum > Qt : : Horizontal < / enum > <nl> + < / property > <nl> + < property name = " sizeHint " stdset = " 0 " > <nl> + < size > <nl> + < width > 40 < / width > <nl> + < height > 20 < / height > <nl> + < / size > <nl> + < / property > <nl> + < / spacer > <nl> + < / item > <nl> + < item row = " 0 " column = " 1 " rowspan = " 2 " colspan = " 2 " > <nl> < layout class = " QVBoxLayout " name = " verticalLayout_5 " > <nl> < item > <nl> < widget class = " QGroupBox " name = " groupBox " > <nl> QGroupBox : : title { <nl> < property name = " rightMargin " > <nl> < number > 50 < / number > <nl> < / property > <nl> - < item row = " 1 " column = " 1 " > <nl> - < widget class = " QFrame " name = " frameNullFgColour " > <nl> - < property name = " minimumSize " > <nl> - < size > <nl> - < width > 70 < / width > <nl> - < height > 20 < / height > <nl> - < / size > <nl> + < item row = " 0 " column = " 1 " > <nl> + < widget class = " QLineEdit " name = " txtNull " > <nl> + < property name = " text " > <nl> + < string notr = " true " / > <nl> + < / property > <nl> + < property name = " maxLength " > <nl> + < number > 15 < / number > <nl> + < / property > <nl> + < property name = " alignment " > <nl> + < set > Qt : : AlignCenter < / set > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 0 " column = " 0 " > <nl> + < widget class = " QLabel " name = " label_12 " > <nl> + < property name = " text " > <nl> + < string > & amp ; Text < / string > <nl> + < / property > <nl> + < property name = " alignment " > <nl> + < set > Qt : : AlignRight | Qt : : AlignTrailing | Qt : : AlignVCenter < / set > <nl> + < / property > <nl> + < property name = " buddy " > <nl> + < cstring > txtNull < / cstring > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < / layout > <nl> + < / widget > <nl> + < / item > <nl> + < item > <nl> + < widget class = " QGroupBox " name = " groupBox_2 " > <nl> + < property name = " autoFillBackground " > <nl> + < bool > false < / bool > <nl> + < / property > <nl> + < property name = " styleSheet " > <nl> + < string notr = " true " > QGroupBox { <nl> + border : 1px solid gray ; <nl> + border - radius : 4px ; <nl> + margin - top : 1ex ; <nl> + } <nl> + <nl> + QGroupBox : : title { <nl> + subcontrol - origin : margin ; <nl> + subcontrol - position : top left ; <nl> + left : 10px ; <nl> + padding : 0 3px 0 3px ; <nl> + } < / string > <nl> + < / property > <nl> + < property name = " title " > <nl> + < string > Fields colors < / string > <nl> + < / property > <nl> + < layout class = " QGridLayout " name = " gridLayout_3 " > <nl> + < item row = " 2 " column = " 0 " > <nl> + < widget class = " QLabel " name = " lb_null " > <nl> + < property name = " text " > <nl> + < string > NULL < / string > <nl> + < / property > <nl> + < property name = " alignment " > <nl> + < set > Qt : : AlignLeading | Qt : : AlignLeft | Qt : : AlignVCenter < / set > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 4 " column = " 0 " > <nl> + < widget class = " QLabel " name = " lb_regular " > <nl> + < property name = " text " > <nl> + < string > Regular < / string > <nl> + < / property > <nl> + < property name = " alignment " > <nl> + < set > Qt : : AlignLeading | Qt : : AlignLeft | Qt : : AlignVCenter < / set > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 0 " column = " 0 " > <nl> + < widget class = " QLabel " name = " label_16 " > <nl> + < property name = " text " > <nl> + < string / > <nl> < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 4 " column = " 1 " > <nl> + < widget class = " QFrame " name = " fr_reg_fg " > <nl> < property name = " focusPolicy " > <nl> < enum > Qt : : StrongFocus < / enum > <nl> < / property > <nl> QGroupBox : : title { <nl> < bool > true < / bool > <nl> < / property > <nl> < property name = " frameShape " > <nl> - < enum > QFrame : : Box < / enum > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> < / property > <nl> < property name = " frameShadow " > <nl> - < enum > QFrame : : Plain < / enum > <nl> + < enum > QFrame : : Raised < / enum > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> < item row = " 0 " column = " 1 " > <nl> - < widget class = " QLineEdit " name = " txtNull " > <nl> + < widget class = " QLabel " name = " lb_text " > <nl> < property name = " text " > <nl> - < string notr = " true " / > <nl> - < / property > <nl> - < property name = " maxLength " > <nl> - < number > 15 < / number > <nl> + < string > Text < / string > <nl> < / property > <nl> < property name = " alignment " > <nl> < set > Qt : : AlignCenter < / set > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 2 " column = " 1 " > <nl> - < widget class = " QFrame " name = " frameNullBgColour " > <nl> - < property name = " minimumSize " > <nl> - < size > <nl> - < width > 70 < / width > <nl> - < height > 20 < / height > <nl> - < / size > <nl> + < item row = " 3 " column = " 0 " > <nl> + < widget class = " QLabel " name = " lb_binary " > <nl> + < property name = " text " > <nl> + < string > Binary < / string > <nl> + < / property > <nl> + < property name = " alignment " > <nl> + < set > Qt : : AlignLeading | Qt : : AlignLeft | Qt : : AlignVCenter < / set > <nl> < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 2 " column = " 1 " > <nl> + < widget class = " QFrame " name = " fr_null_fg " > <nl> < property name = " focusPolicy " > <nl> < enum > Qt : : StrongFocus < / enum > <nl> < / property > <nl> QGroupBox : : title { <nl> < bool > true < / bool > <nl> < / property > <nl> < property name = " frameShape " > <nl> - < enum > QFrame : : Box < / enum > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> < / property > <nl> < property name = " frameShadow " > <nl> - < enum > QFrame : : Plain < / enum > <nl> + < enum > QFrame : : Raised < / enum > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 1 " column = " 0 " > <nl> - < widget class = " QLabel " name = " label_10 " > <nl> + < item row = " 0 " column = " 2 " > <nl> + < widget class = " QLabel " name = " lb_background " > <nl> < property name = " text " > <nl> - < string > Text & amp ; colour < / string > <nl> + < string > Background < / string > <nl> < / property > <nl> < property name = " alignment " > <nl> - < set > Qt : : AlignRight | Qt : : AlignTrailing | Qt : : AlignVCenter < / set > <nl> + < set > Qt : : AlignCenter < / set > <nl> < / property > <nl> - < property name = " buddy " > <nl> - < cstring > frameNullFgColour < / cstring > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 3 " column = " 1 " > <nl> + < widget class = " QFrame " name = " fr_bin_fg " > <nl> + < property name = " focusPolicy " > <nl> + < enum > Qt : : StrongFocus < / enum > <nl> + < / property > <nl> + < property name = " autoFillBackground " > <nl> + < bool > true < / bool > <nl> + < / property > <nl> + < property name = " frameShape " > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> + < / property > <nl> + < property name = " frameShadow " > <nl> + < enum > QFrame : : Raised < / enum > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 0 " column = " 0 " > <nl> - < widget class = " QLabel " name = " label_12 " > <nl> - < property name = " text " > <nl> - < string > & amp ; Text < / string > <nl> + < item row = " 2 " column = " 2 " > <nl> + < widget class = " QFrame " name = " fr_null_bg " > <nl> + < property name = " focusPolicy " > <nl> + < enum > Qt : : StrongFocus < / enum > <nl> < / property > <nl> - < property name = " alignment " > <nl> - < set > Qt : : AlignRight | Qt : : AlignTrailing | Qt : : AlignVCenter < / set > <nl> + < property name = " autoFillBackground " > <nl> + < bool > true < / bool > <nl> < / property > <nl> - < property name = " buddy " > <nl> - < cstring > txtNull < / cstring > <nl> + < property name = " frameShape " > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> + < / property > <nl> + < property name = " frameShadow " > <nl> + < enum > QFrame : : Raised < / enum > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> - < item row = " 2 " column = " 0 " > <nl> - < widget class = " QLabel " name = " label_11 " > <nl> - < property name = " text " > <nl> - < string > Bac & amp ; kground colour < / string > <nl> + < item row = " 3 " column = " 2 " > <nl> + < widget class = " QFrame " name = " fr_bin_bg " > <nl> + < property name = " focusPolicy " > <nl> + < enum > Qt : : StrongFocus < / enum > <nl> < / property > <nl> - < property name = " alignment " > <nl> - < set > Qt : : AlignRight | Qt : : AlignTrailing | Qt : : AlignVCenter < / set > <nl> + < property name = " autoFillBackground " > <nl> + < bool > true < / bool > <nl> < / property > <nl> - < property name = " buddy " > <nl> - < cstring > frameNullBgColour < / cstring > <nl> + < property name = " frameShape " > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> + < / property > <nl> + < property name = " frameShadow " > <nl> + < enum > QFrame : : Raised < / enum > <nl> + < / property > <nl> + < / widget > <nl> + < / item > <nl> + < item row = " 4 " column = " 2 " > <nl> + < widget class = " QFrame " name = " fr_reg_bg " > <nl> + < property name = " focusPolicy " > <nl> + < enum > Qt : : StrongFocus < / enum > <nl> + < / property > <nl> + < property name = " autoFillBackground " > <nl> + < bool > true < / bool > <nl> + < / property > <nl> + < property name = " frameShape " > <nl> + < enum > QFrame : : StyledPanel < / enum > <nl> + < / property > <nl> + < property name = " frameShadow " > <nl> + < enum > QFrame : : Raised < / enum > <nl> < / property > <nl> < / widget > <nl> < / item > <nl> < / layout > <nl> < / widget > <nl> < / item > <nl> - < item > <nl> - < spacer name = " verticalSpacer_2 " > <nl> - < property name = " orientation " > <nl> - < enum > Qt : : Vertical < / enum > <nl> - < / property > <nl> - < property name = " sizeHint " stdset = " 0 " > <nl> - < size > <nl> - < width > 20 < / width > <nl> - < height > 40 < / height > <nl> - < / size > <nl> - < / property > <nl> - < / spacer > <nl> - < / item > <nl> < / layout > <nl> < / item > <nl> - < item > <nl> - < spacer name = " horizontalSpacer_3 " > <nl> + < item row = " 2 " column = " 1 " > <nl> + < spacer name = " verticalSpacer_2 " > <nl> < property name = " orientation " > <nl> - < enum > Qt : : Horizontal < / enum > <nl> + < enum > Qt : : Vertical < / enum > <nl> < / property > <nl> < property name = " sizeHint " stdset = " 0 " > <nl> < size > <nl> - < width > 40 < / width > <nl> - < height > 20 < / height > <nl> + < width > 20 < / width > <nl> + < height > 274 < / height > <nl> < / size > <nl> < / property > <nl> < / spacer > <nl> QGroupBox : : title { <nl> < / layout > <nl> < / widget > <nl> < tabstops > <nl> - < tabstop > tabWidget < / tabstop > <nl> < tabstop > comboDefaultLocation < / tabstop > <nl> < tabstop > locationEdit < / tabstop > <nl> < tabstop > setLocationButton < / tabstop > <nl> QGroupBox : : title { <nl> < tabstop > checkHideSchemaLinebreaks < / tabstop > <nl> < tabstop > spinPrefetchSize < / tabstop > <nl> < tabstop > txtNull < / tabstop > <nl> - < tabstop > frameNullFgColour < / tabstop > <nl> - < tabstop > frameNullBgColour < / tabstop > <nl> + < tabstop > fr_null_fg < / tabstop > <nl> + < tabstop > fr_null_bg < / tabstop > <nl> + < tabstop > fr_bin_fg < / tabstop > <nl> + < tabstop > fr_bin_bg < / tabstop > <nl> + < tabstop > fr_reg_fg < / tabstop > <nl> + < tabstop > fr_reg_bg < / tabstop > <nl> < tabstop > treeSyntaxHighlighting < / tabstop > <nl> < tabstop > comboEditorFont < / tabstop > <nl> < tabstop > spinEditorFontSize < / tabstop > <nl> mmm a / src / sqlitetablemodel . cpp <nl> ppp b / src / sqlitetablemodel . cpp <nl> QVariant SqliteTableModel : : data ( const QModelIndex & index , int role ) const <nl> if ( m_data . at ( index . row ( ) ) . at ( index . column ( ) ) . isNull ( ) ) <nl> return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " null_fg_colour " ) . toString ( ) ) ; <nl> else if ( isBinary ( index ) ) <nl> - return QColor ( Qt : : gray ) ; <nl> - return QVariant ( ) ; <nl> + return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " bin_fg_colour " ) . toString ( ) ) ; <nl> + return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " reg_fg_colour " ) . toString ( ) ) ; <nl> } else if ( role = = Qt : : BackgroundRole ) { <nl> if ( m_data . at ( index . row ( ) ) . at ( index . column ( ) ) . isNull ( ) ) <nl> return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " null_bg_colour " ) . toString ( ) ) ; <nl> - return QVariant ( ) ; <nl> + else if ( isBinary ( index ) ) <nl> + return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " bin_bg_colour " ) . toString ( ) ) ; <nl> + return QColor ( PreferencesDialog : : getSettingsValue ( " databrowser " , " reg_bg_colour " ) . toString ( ) ) ; <nl> } else if ( role = = Qt : : ToolTipRole ) { <nl> sqlb : : ForeignKeyClause fk = getForeignKeyClause ( index . column ( ) - 1 ) ; <nl> if ( fk . isSet ( ) ) <nl>
enhancement : advanced data browser colors preferences
sqlitebrowser/sqlitebrowser
b2e8dc35008db7f81ccc9811de9328e6b247d3c0
2015-07-01T17:20:14Z
mmm a / drivers / python / rethinkdb / utils_common . py <nl> ppp b / drivers / python / rethinkdb / utils_common . py <nl> <nl> <nl> import collections , copy , distutils . version , getpass , inspect , optparse , os , re , sys , threading <nl> <nl> - from . import net <nl> + from . import net , version <nl> r = net . Connection . _r <nl> <nl> class RetryQuery ( object ) : <nl> def take_action ( self , action , dest , opt , value , values , parser ) : <nl> if caller . __doc__ : <nl> kwargs [ ' description ' ] = caller . __doc__ <nl> <nl> + # - - add version <nl> + <nl> + if not ' version ' in kwargs : <nl> + kwargs [ ' version ' ] = " % % prog % s " % version . version <nl> + <nl> + # - - call super <nl> + <nl> super ( CommonOptionsParser , self ) . __init__ ( * args , * * kwargs ) <nl> <nl> # - - add common options <nl>
adding - - version option to Python driver commands
rethinkdb/rethinkdb
f20c0b637081f033010a45f3658bd753db5a610b
2016-07-19T23:36:55Z
mmm a / tools / interop_matrix / client_matrix . py <nl> ppp b / tools / interop_matrix / client_matrix . py <nl> def __init__ ( self , patch = [ ] , runtimes = [ ] , testcases_file = None ) : <nl> ( ' v1 . 18 . 0 ' , ReleaseInfo ( runtimes = [ ' java_oracle8 ' ] ) ) , <nl> ( ' v1 . 19 . 0 ' , ReleaseInfo ( runtimes = [ ' java_oracle8 ' ] ) ) , <nl> ( ' v1 . 20 . 0 ' , ReleaseInfo ( runtimes = [ ' java_oracle8 ' ] ) ) , <nl> - ( ' v1 . 21 . 0 ' , ReleaseInfo ( runtimes = [ ' java_oracle8 ' ] ) ) ) , <nl> + ( ' v1 . 21 . 0 ' , ReleaseInfo ( runtimes = [ ' java_oracle8 ' ] ) ) , <nl> ] ) , <nl> ' python ' : <nl> OrderedDict ( [ <nl>
Fix syntax error
grpc/grpc
ad103834caf394a93a46fbadbe90ee9cd3bbd58b
2019-06-03T11:55:13Z
mmm a / include / swift / SILAnalysis / CallGraph . h <nl> ppp b / include / swift / SILAnalysis / CallGraph . h <nl> class CallGraph { <nl> unsigned EdgeOrdinal ; <nl> <nl> public : <nl> + # ifndef NDEBUG <nl> + friend struct OrderedCallGraph ; <nl> + # endif <nl> + <nl> friend class CallGraphEditor ; <nl> <nl> CallGraph ( SILModule * M , bool completeModule ) ; <nl> ~ CallGraph ( ) ; <nl> <nl> - / / Query funtions for getting nodes and edges from the call graph . <nl> - <nl> - CallGraphNode * getCallGraphNode ( SILFunction * F ) const { <nl> - return const_cast < CallGraph * > ( this ) - > getCallGraphNode ( F ) ; <nl> - } <nl> - <nl> - CallGraphNode * getCallGraphNode ( SILFunction * F ) { <nl> - auto * CGN = tryGetCallGraphNode ( F ) ; <nl> - assert ( CGN & & " Expected call graph node for function ! " ) ; <nl> - return CGN ; <nl> - } <nl> - <nl> - CallGraphEdge * getCallGraphEdge ( FullApplySite AI ) { <nl> - auto Found = ApplyToEdgeMap . find ( AI ) ; <nl> - if ( Found = = ApplyToEdgeMap . end ( ) ) <nl> - return nullptr ; <nl> - <nl> - assert ( Found - > second & & " Unexpected null call graph edge in map ! " ) ; <nl> - return Found - > second ; <nl> - } <nl> - <nl> - CallGraphEdge * getCallGraphEdge ( FullApplySite AI ) const { <nl> - return const_cast < CallGraph * > ( this ) - > getCallGraphEdge ( AI ) ; <nl> - } <nl> - <nl> - CallGraphEdge : : CalleeSetType * <nl> - tryGetCalleeSetForClassMethod ( SILDeclRef Decl ) ; <nl> - <nl> - CallGraphEdge : : CalleeSetType * <nl> - getOrCreateCalleeSetForClassMethod ( SILDeclRef Decl ) ; <nl> - <nl> / / Functions for getting bottom - up lists of SCCs or functions in the <nl> / / call graph . <nl> ArrayRef < CallGraphSCC * > getBottomUpSCCOrder ( ) { <nl> class CallGraph { <nl> <nl> void verify ( SILFunction * F ) const ; <nl> private : <nl> + / / Query funtions for getting nodes and edges from the call graph . <nl> + <nl> + CallGraphNode * getCallGraphNode ( SILFunction * F ) const { <nl> + return const_cast < CallGraph * > ( this ) - > getCallGraphNode ( F ) ; <nl> + } <nl> + <nl> + CallGraphNode * getCallGraphNode ( SILFunction * F ) { <nl> + auto * CGN = tryGetCallGraphNode ( F ) ; <nl> + assert ( CGN & & " Expected call graph node for function ! " ) ; <nl> + return CGN ; <nl> + } <nl> + <nl> + CallGraphEdge * getCallGraphEdge ( FullApplySite AI ) { <nl> + auto Found = ApplyToEdgeMap . find ( AI ) ; <nl> + if ( Found = = ApplyToEdgeMap . end ( ) ) <nl> + return nullptr ; <nl> + <nl> + assert ( Found - > second & & " Unexpected null call graph edge in map ! " ) ; <nl> + return Found - > second ; <nl> + } <nl> + <nl> + CallGraphEdge * getCallGraphEdge ( FullApplySite AI ) const { <nl> + return const_cast < CallGraph * > ( this ) - > getCallGraphEdge ( AI ) ; <nl> + } <nl> + <nl> + CallGraphEdge : : CalleeSetType * <nl> + tryGetCalleeSetForClassMethod ( SILDeclRef Decl ) ; <nl> + <nl> + CallGraphEdge : : CalleeSetType * <nl> + getOrCreateCalleeSetForClassMethod ( SILDeclRef Decl ) ; <nl> + <nl> + <nl> CallGraphNode * tryGetCallGraphNode ( SILFunction * F ) const { <nl> return const_cast < CallGraph * > ( this ) - > tryGetCallGraphNode ( F ) ; <nl> } <nl>
Hide more implementation details of the call graph .
apple/swift
9b7644b0ac250485cf66b5e2826aa6ccf2c6c9bc
2015-10-13T05:56:55Z
mmm a / Telegram / gyp / PrecompiledHeader . cmake <nl> ppp b / Telegram / gyp / PrecompiledHeader . cmake <nl> function ( add_precompiled_header _target _input ) <nl> OUTPUT " $ { _pchfile } " <nl> COMMAND " $ { CMAKE_COMMAND } " - E copy " $ { _pch_header } " " $ { _pchfile } " <nl> DEPENDS " $ { _pch_header } " <nl> + IMPLICIT_DEPENDS CXX " $ { _pch_header } " <nl> + IMPLICIT_DEPENDS C " $ { _pch_header } " <nl> COMMENT " Updating $ { _name } " ) <nl> <nl> if ( _source_for_c_flags ) <nl> function ( add_precompiled_header _target _input ) <nl> OUTPUT " $ { _output_c } " <nl> COMMAND " $ { CMAKE_C_COMPILER } " $ { _compiler_FLAGS } - x c - header - o " $ { _output_c } " - c " $ { _pchfile } " <nl> DEPENDS " $ { _pchfile } " " $ { _pch_c_flags_file } " <nl> + IMPLICIT_DEPENDS C " $ { _pch_header } " <nl> COMMENT " Precompiling $ { _name } for $ { _target } ( C ) " ) <nl> endif ( ) <nl> if ( _source_for_cpp_flags ) <nl> function ( add_precompiled_header _target _input ) <nl> OUTPUT " $ { _output_cxx } " <nl> COMMAND " $ { CMAKE_CXX_COMPILER } " $ { _compiler_FLAGS } - x c + + - header - o " $ { _output_cxx } " - c " $ { _pchfile } " <nl> DEPENDS " $ { _pchfile } " " $ { _pch_cpp_flags_file } " <nl> + IMPLICIT_DEPENDS CXX " $ { _pch_header } " <nl> COMMENT " Precompiling $ { _name } for $ { _target } ( C + + ) " ) <nl> endif ( ) <nl> <nl> mmm a / Telegram / gyp / qt . gypi <nl> ppp b / Telegram / gyp / qt . gypi <nl> <nl> ' fontconfig ' , <nl> ' expat ' , <nl> ' freetype ' , <nl> - ' xcb ' , <nl> ' xcb - shm ' , <nl> ' xcb - xfixes ' , <nl> ' xcb - render ' , <nl> <nl> ] , <nl> ' conditions ' : [ <nl> [ ' build_linux ' , { <nl> - ' library_dirs ' : [ <nl> - ' < ( qt_loc ) / plugins / platforms / xcb / xcb - static ' , <nl> - ] , <nl> ' libraries ' : [ <nl> ' / usr / local / lib / libxkbcommon . a ' , <nl> ' < @ ( qt_libs_release ) ' , <nl> + ' xcb ' , <nl> ' X11 ' , <nl> ' X11 - xcb ' , <nl> ' dbus - 1 ' , <nl>
Stable 0 . 10 . 6 for Linux : dynamic xcb link , cmake dependencies fixed .
telegramdesktop/tdesktop
8660ab555bc759a008658a78981a6e3ea06502d5
2016-09-13T14:07:30Z
mmm a / cmake / modules / AddSwift . cmake <nl> ppp b / cmake / modules / AddSwift . cmake <nl> function ( _add_variant_c_compile_flags ) <nl> list ( APPEND result " \ " $ { CMAKE_INCLUDE_FLAG_C } $ { path } \ " " ) <nl> endforeach ( ) <nl> list ( APPEND result " - D__ANDROID_API__ = $ { SWIFT_ANDROID_API_LEVEL } " ) <nl> + elseif ( CFLAGS_SDK STREQUAL WINDOWS ) <nl> + swift_windows_include_for_arch ( $ { CFLAGS_ARCH } $ { CFLAGS_ARCH } _INCLUDE ) <nl> + foreach ( path $ { $ { CFLAGS_ARCH } _INCLUDE } ) <nl> + list ( APPEND result " \ " $ { CMAKE_INCLUDE_FLAG_C } $ { path } \ " " ) <nl> + endforeach ( ) <nl> endif ( ) <nl> <nl> set ( " $ { CFLAGS_RESULT_VAR_NAME } " " $ { result } " PARENT_SCOPE ) <nl>
build : add Windows includes to build
apple/swift
9624932391fef4415659a7ca3e08e07c734f3eb7
2018-12-17T06:23:41Z
mmm a / src / mongo / db / repl / SConscript <nl> ppp b / src / mongo / db / repl / SConscript <nl> env . CppUnitTest ( ' repl_coordinator_impl_test ' , <nl> ' repl_coordinator_impl_elect_test . cpp ' , <nl> ' repl_coordinator_impl_test . cpp ' , <nl> ' repl_coordinator_impl_heartbeat_test . cpp ' , <nl> + ' repl_coordinator_impl_reconfig_test . cpp ' , <nl> ] , <nl> LIBDEPS = [ ' repl_coordinator_test_fixture ' ] ) <nl> <nl> env . CppUnitTest ( ' repl_coordinator_impl_heartbeat_test ' , <nl> ' repl_coordinator_impl_heartbeat_test . cpp ' , <nl> LIBDEPS = [ ' repl_coordinator_test_fixture ' ] ) <nl> <nl> + env . CppUnitTest ( ' repl_coordinator_impl_reconfig_test ' , <nl> + ' repl_coordinator_impl_reconfig_test . cpp ' , <nl> + LIBDEPS = [ ' repl_coordinator_test_fixture ' ] ) <nl> + <nl> env . Library ( ' repl_coordinator_interface ' , <nl> [ ' repl_coordinator . cpp ' , <nl> ' repl_coordinator_external_state . cpp ' , <nl> mmm a / src / mongo / db / repl / repl_coordinator_external_state_mock . cpp <nl> ppp b / src / mongo / db / repl / repl_coordinator_external_state_mock . cpp <nl> namespace repl { <nl> _lastOpTime ( ErrorCodes : : NoMatchingDocument , " No last oplog entry " ) , <nl> _canAcquireGlobalSharedLock ( true ) , <nl> _storeLocalConfigDocumentStatus ( Status : : OK ( ) ) , <nl> + _storeLocalConfigDocumentShouldHang ( false ) , <nl> _connectionsClosed ( false ) { <nl> } <nl> <nl> namespace repl { <nl> Status ReplicationCoordinatorExternalStateMock : : storeLocalConfigDocument ( <nl> OperationContext * txn , <nl> const BSONObj & config ) { <nl> + { <nl> + boost : : unique_lock < boost : : mutex > lock ( _shouldHangMutex ) ; <nl> + while ( _storeLocalConfigDocumentShouldHang ) { <nl> + _shouldHangCondVar . wait ( lock ) ; <nl> + } <nl> + } <nl> if ( _storeLocalConfigDocumentStatus . isOK ( ) ) { <nl> setLocalConfigDocument ( StatusWith < BSONObj > ( config ) ) ; <nl> return Status : : OK ( ) ; <nl> namespace repl { <nl> _storeLocalConfigDocumentStatus = status ; <nl> } <nl> <nl> + void ReplicationCoordinatorExternalStateMock : : setStoreLocalConfigDocumentToHang ( bool hang ) { <nl> + boost : : unique_lock < boost : : mutex > lock ( _shouldHangMutex ) ; <nl> + _storeLocalConfigDocumentShouldHang = hang ; <nl> + if ( ! hang ) { <nl> + _shouldHangCondVar . notify_all ( ) ; <nl> + } <nl> + } <nl> + <nl> void ReplicationCoordinatorExternalStateMock : : closeConnections ( ) { <nl> _connectionsClosed = true ; <nl> } <nl> mmm a / src / mongo / db / repl / repl_coordinator_external_state_mock . h <nl> ppp b / src / mongo / db / repl / repl_coordinator_external_state_mock . h <nl> namespace repl { <nl> * / <nl> void setStoreLocalConfigDocumentStatus ( Status status ) ; <nl> <nl> + / * * <nl> + * Sets whether or not subsequent calls to storeLocalConfigDocument ( ) should hang <nl> + * indefinitely or not based on the value of " hang " . <nl> + * / <nl> + void setStoreLocalConfigDocumentToHang ( bool hang ) ; <nl> + <nl> private : <nl> StatusWith < BSONObj > _localRsConfigDocument ; <nl> StatusWith < OpTime > _lastOpTime ; <nl> std : : vector < HostAndPort > _selfHosts ; <nl> bool _canAcquireGlobalSharedLock ; <nl> Status _storeLocalConfigDocumentStatus ; <nl> + / / mutex and cond var for controlling stroeLocalConfigDocument ( ) ' s hanging <nl> + boost : : mutex _shouldHangMutex ; <nl> + boost : : condition _shouldHangCondVar ; <nl> + bool _storeLocalConfigDocumentShouldHang ; <nl> bool _connectionsClosed ; <nl> HostAndPort _clientHostAndPort ; <nl> } ; <nl> mmm a / src / mongo / db / repl / repl_coordinator_impl . cpp <nl> ppp b / src / mongo / db / repl / repl_coordinator_impl . cpp <nl> namespace { <nl> return Status ( ErrorCodes : : NotYetInitialized , <nl> " Node not yet initialized ; use the replSetInitiate command " ) ; <nl> case kConfigReplicationDisabled : <nl> - return Status ( ErrorCodes : : NoReplicationEnabled , " Node is not a replica set member " ) ; <nl> + invariant ( false ) ; / / should be unreachable due to ! _settings . usingReplSets ( ) check above <nl> case kConfigInitiating : <nl> case kConfigReconfiguring : <nl> case kConfigHBReconfiguring : <nl> namespace { <nl> if ( ! status . isOK ( ) ) { <nl> error ( ) < < " replSetReconfig got " < < status < < " while parsing " < < newConfigObj < < <nl> rsLog ; <nl> - return status ; <nl> + return Status ( ErrorCodes : : InvalidReplicaSetConfig , status . reason ( ) ) ; ; <nl> } <nl> if ( newConfig . getReplSetName ( ) ! = _settings . ourSetName ( ) ) { <nl> str : : stream errmsg ; <nl> namespace { <nl> newConfig . getReplSetName ( ) < < " , but command line reports " < < <nl> _settings . ourSetName ( ) < < " ; rejecting " ; <nl> error ( ) < < std : : string ( errmsg ) ; <nl> - return Status ( ErrorCodes : : BadValue , errmsg ) ; <nl> + return Status ( ErrorCodes : : InvalidReplicaSetConfig , errmsg ) ; <nl> } <nl> <nl> StatusWith < int > myIndex = validateConfigForReconfig ( <nl> namespace { <nl> if ( ! myIndex . isOK ( ) ) { <nl> error ( ) < < " replSetReconfig got " < < myIndex . getStatus ( ) < < " while validating " < < <nl> newConfigObj < < rsLog ; <nl> - return myIndex . getStatus ( ) ; <nl> + return Status ( ErrorCodes : : NewReplicaSetConfigurationIncompatible , <nl> + myIndex . getStatus ( ) . reason ( ) ) ; <nl> } <nl> <nl> log ( ) < < " replSetReconfig config object with " < < newConfig . getNumMembers ( ) < < <nl> new file mode 100644 <nl> index 000000000000 . . c1bedbd90304 <nl> mmm / dev / null <nl> ppp b / src / mongo / db / repl / repl_coordinator_impl_reconfig_test . cpp <nl> <nl> + / * * <nl> + * Copyright ( C ) 2014 MongoDB Inc . <nl> + * <nl> + * This program is free software : you can redistribute it and / or modify <nl> + * it under the terms of the GNU Affero General Public License , version 3 , <nl> + * as published by the Free Software Foundation . <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 Affero General Public License for more details . <nl> + * <nl> + * You should have received a copy of the GNU Affero General Public License <nl> + * along with this program . If not , see < http : / / www . gnu . org / licenses / > . <nl> + * <nl> + * As a special exception , the copyright holders give permission to link the <nl> + * code of portions of this program with the OpenSSL library under certain <nl> + * conditions as described in each individual source file and distribute <nl> + * linked combinations including the program with the OpenSSL library . You <nl> + * must comply with the GNU Affero General Public License in all respects for <nl> + * all of the code used other than as permitted herein . If you modify file ( s ) <nl> + * with this exception , you may extend this exception to your version of the <nl> + * file ( s ) , but you are not obligated to do so . If you do not wish to do so , <nl> + * delete this exception statement from your version . If you delete this <nl> + * exception statement from all source files in the program , then also delete <nl> + * it in the license file . <nl> + * / <nl> + <nl> + # define MONGO_LOG_DEFAULT_COMPONENT : : mongo : : logger : : LogComponent : : kReplication <nl> + <nl> + # include " mongo / platform / basic . h " <nl> + <nl> + # include " mongo / db / jsobj . h " <nl> + # include " mongo / db / operation_context_noop . h " <nl> + # include " mongo / db / repl / network_interface_mock . h " <nl> + # include " mongo / db / repl / repl_coordinator_external_state_mock . h " <nl> + # include " mongo / db / repl / repl_coordinator_impl . h " <nl> + # include " mongo / db / repl / repl_coordinator_test_fixture . h " <nl> + # include " mongo / db / repl / repl_coordinator . h " / / ReplSetReconfigArgs <nl> + # include " mongo / db / repl / repl_set_heartbeat_args . h " <nl> + # include " mongo / db / repl / repl_set_heartbeat_response . h " <nl> + # include " mongo / db / repl / replica_set_config . h " <nl> + # include " mongo / unittest / unittest . h " <nl> + # include " mongo / util / log . h " <nl> + <nl> + namespace mongo { <nl> + namespace repl { <nl> + namespace { <nl> + <nl> + typedef ReplicationCoordinator : : ReplSetReconfigArgs ReplSetReconfigArgs ; <nl> + typedef ReplicationExecutor : : RemoteCommandRequest RemoteCommandRequest ; <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWhileNotReplSet ) { <nl> + / / start up with settings . replSet empty <nl> + OperationContextNoop txn ; <nl> + init ( " " ) ; <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : NoReplicationEnabled , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigBeforeInitialized ) { <nl> + / / start up but do not initiate <nl> + OperationContextNoop txn ; <nl> + init ( ) ; <nl> + start ( ) ; <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : NotYetInitialized , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWhileNotPrimary ) { <nl> + / / start up , become secondary , receive reconfig <nl> + OperationContextNoop txn ; <nl> + init ( ) ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + ASSERT_EQUALS ( ErrorCodes : : NotMaster , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWithUninitializableConfig ) { <nl> + / / start up , become primary , receive uninitializable config <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " invalidlyNamedField " < < 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " < < <nl> + " arbiterOnly " < < true ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " < < <nl> + " arbiterOnly " < < true ) ) ) ; <nl> + / / ErrorCodes : : BadValue should be propagated from ReplicaSetConfig : : initialize ( ) <nl> + ASSERT_EQUALS ( ErrorCodes : : InvalidReplicaSetConfig , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWithWrongReplSetName ) { <nl> + / / start up , become primary , receive config with incorrect replset name <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " notMySet " < < <nl> + " version " < < 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : InvalidReplicaSetConfig , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigValidateFails ) { <nl> + / / start up , become primary , validate fails <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " mySet " < < <nl> + " version " < < - 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : NewReplicaSetConfigurationIncompatible , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + } <nl> + <nl> + void doReplSetInitiate ( ReplicationCoordinatorImpl * replCoord , Status * status ) { <nl> + OperationContextNoop txn ; <nl> + BSONObjBuilder garbage ; <nl> + * status = replCoord - > processReplSetInitiate ( <nl> + & txn , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 1 < < <nl> + " members " < < BSON_ARRAY ( <nl> + BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + & garbage ) ; <nl> + } <nl> + <nl> + void doReplSetReconfig ( ReplicationCoordinatorImpl * replCoord , Status * status ) { <nl> + OperationContextNoop txn ; <nl> + BSONObjBuilder garbage ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " mySet " < < <nl> + " version " < < 3 < < <nl> + " members " < < BSON_ARRAY ( <nl> + BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " < < <nl> + " priority " < < 3 ) ) ) ; <nl> + * status = replCoord - > processReplSetReconfig ( & txn , args , & garbage ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigQuorumCheckFails ) { <nl> + / / start up , become primary , fail during quorum check due to a heartbeat <nl> + / / containing a higher config version <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + Status status ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + boost : : thread reconfigThread ( stdx : : bind ( doReplSetReconfig , getReplCoord ( ) , & status ) ) ; <nl> + <nl> + NetworkInterfaceMock * net = getNet ( ) ; <nl> + getNet ( ) - > enterNetwork ( ) ; <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi = net - > getNextReadyRequest ( ) ; <nl> + const ReplicationExecutor : : RemoteCommandRequest & request = noi - > getRequest ( ) ; <nl> + repl : : ReplSetHeartbeatArgs hbArgs ; <nl> + ASSERT_OK ( hbArgs . initialize ( request . cmdObj ) ) ; <nl> + repl : : ReplSetHeartbeatResponse hbResp ; <nl> + hbResp . setSetName ( " mySet " ) ; <nl> + hbResp . setState ( MemberState : : RS_SECONDARY ) ; <nl> + hbResp . setVersion ( 5 ) ; <nl> + BSONObjBuilder respObj ; <nl> + respObj < < " ok " < < 1 ; <nl> + hbResp . addToBSON ( & respObj ) ; <nl> + net - > scheduleResponse ( noi , net - > now ( ) , makeResponseStatus ( respObj . obj ( ) ) ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + reconfigThread . join ( ) ; <nl> + ASSERT_EQUALS ( ErrorCodes : : NewReplicaSetConfigurationIncompatible , status ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigStoreLocalConfigDocumentFails ) { <nl> + / / start up , become primary , saving the config fails <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + Status status ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + getExternalState ( ) - > setStoreLocalConfigDocumentStatus ( Status ( ErrorCodes : : OutOfDiskSpace , <nl> + " The test set this " ) ) ; <nl> + boost : : thread reconfigThread ( stdx : : bind ( doReplSetReconfig , getReplCoord ( ) , & status ) ) ; <nl> + <nl> + NetworkInterfaceMock * net = getNet ( ) ; <nl> + getNet ( ) - > enterNetwork ( ) ; <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi = net - > getNextReadyRequest ( ) ; <nl> + const ReplicationExecutor : : RemoteCommandRequest & request = noi - > getRequest ( ) ; <nl> + repl : : ReplSetHeartbeatArgs hbArgs ; <nl> + ASSERT_OK ( hbArgs . initialize ( request . cmdObj ) ) ; <nl> + repl : : ReplSetHeartbeatResponse hbResp ; <nl> + hbResp . setSetName ( " mySet " ) ; <nl> + hbResp . setState ( MemberState : : RS_SECONDARY ) ; <nl> + hbResp . setVersion ( 2 ) ; <nl> + BSONObjBuilder respObj ; <nl> + respObj < < " ok " < < 1 ; <nl> + hbResp . addToBSON ( & respObj ) ; <nl> + net - > scheduleResponse ( noi , net - > now ( ) , makeResponseStatus ( respObj . obj ( ) ) ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + reconfigThread . join ( ) ; <nl> + ASSERT_EQUALS ( ErrorCodes : : OutOfDiskSpace , status ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWhileReconfiggingFails ) { <nl> + / / start up , become primary , reconfig , then before that reconfig concludes , reconfig again <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + Status status ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + / / first reconfig <nl> + boost : : thread reconfigThread ( stdx : : bind ( doReplSetReconfig , getReplCoord ( ) , & status ) ) ; <nl> + getNet ( ) - > enterNetwork ( ) ; <nl> + getNet ( ) - > blackHole ( getNet ( ) - > getNextReadyRequest ( ) ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + <nl> + / / second reconfig <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " mySet " < < <nl> + " version " < < 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : ConfigurationInProgress , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + <nl> + shutdown ( ) ; <nl> + reconfigThread . join ( ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigWhileInitializingFails ) { <nl> + / / start up , initiate , then before that initiate concludes , reconfig <nl> + OperationContextNoop txn ; <nl> + init ( ) ; <nl> + start ( HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + <nl> + / / initiate <nl> + Status status ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + boost : : thread initateThread ( stdx : : bind ( doReplSetInitiate , getReplCoord ( ) , & status ) ) ; <nl> + getNet ( ) - > enterNetwork ( ) ; <nl> + getNet ( ) - > blackHole ( getNet ( ) - > getNextReadyRequest ( ) ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + <nl> + / / reconfig <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = BSON ( " _id " < < " mySet " < < <nl> + " version " < < 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ; <nl> + <nl> + ASSERT_EQUALS ( ErrorCodes : : ConfigurationInProgress , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + ASSERT_TRUE ( result . obj ( ) . isEmpty ( ) ) ; <nl> + <nl> + shutdown ( ) ; <nl> + initateThread . join ( ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigSuccessful ) { <nl> + / / start up , become primary , reconfig successfully <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + <nl> + Status status ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + boost : : thread reconfigThread ( stdx : : bind ( doReplSetReconfig , getReplCoord ( ) , & status ) ) ; <nl> + <nl> + NetworkInterfaceMock * net = getNet ( ) ; <nl> + getNet ( ) - > enterNetwork ( ) ; <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi = net - > getNextReadyRequest ( ) ; <nl> + const ReplicationExecutor : : RemoteCommandRequest & request = noi - > getRequest ( ) ; <nl> + repl : : ReplSetHeartbeatArgs hbArgs ; <nl> + ASSERT_OK ( hbArgs . initialize ( request . cmdObj ) ) ; <nl> + repl : : ReplSetHeartbeatResponse hbResp ; <nl> + hbResp . setSetName ( " mySet " ) ; <nl> + hbResp . setState ( MemberState : : RS_SECONDARY ) ; <nl> + hbResp . setVersion ( 2 ) ; <nl> + BSONObjBuilder respObj ; <nl> + respObj < < " ok " < < 1 ; <nl> + hbResp . addToBSON ( & respObj ) ; <nl> + net - > scheduleResponse ( noi , net - > now ( ) , makeResponseStatus ( respObj . obj ( ) ) ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + reconfigThread . join ( ) ; <nl> + ASSERT_OK ( status ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , ReconfigDuringHBReconfigFails ) { <nl> + / / start up , become primary , receive reconfig via heartbeat , then a second one from reconfig <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + ASSERT_TRUE ( getReplCoord ( ) - > getCurrentMemberState ( ) . primary ( ) ) ; <nl> + <nl> + / / set hbreconfig to hang while in progress <nl> + getExternalState ( ) - > setStoreLocalConfigDocumentToHang ( true ) ; <nl> + <nl> + / / hb reconfig <nl> + NetworkInterfaceMock * net = getNet ( ) ; <nl> + net - > enterNetwork ( ) ; <nl> + ReplSetHeartbeatResponse hbResp2 ; <nl> + ReplicaSetConfig config ; <nl> + config . initialize ( BSON ( " _id " < < " mySet " < < <nl> + " version " < < 3 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ) ; <nl> + hbResp2 . setConfig ( config ) ; <nl> + hbResp2 . setVersion ( 3 ) ; <nl> + hbResp2 . setSetName ( " mySet " ) ; <nl> + hbResp2 . setState ( MemberState : : RS_SECONDARY ) ; <nl> + BSONObjBuilder respObj2 ; <nl> + respObj2 < < " ok " < < 1 ; <nl> + hbResp2 . addToBSON ( & respObj2 ) ; <nl> + net - > runUntil ( net - > now ( ) + 10 * 1000 ) ; / / run until we ' ve sent a heartbeat request <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi2 = net - > getNextReadyRequest ( ) ; <nl> + net - > scheduleResponse ( noi2 , net - > now ( ) , makeResponseStatus ( respObj2 . obj ( ) ) ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + getNet ( ) - > exitNetwork ( ) ; <nl> + <nl> + / / reconfig <nl> + BSONObjBuilder result ; <nl> + ReplSetReconfigArgs args ; <nl> + args . force = false ; <nl> + args . newConfigObj = config . toBSON ( ) ; <nl> + ASSERT_EQUALS ( ErrorCodes : : ConfigurationInProgress , <nl> + getReplCoord ( ) - > processReplSetReconfig ( & txn , args , & result ) ) ; <nl> + <nl> + getExternalState ( ) - > setStoreLocalConfigDocumentToHang ( false ) ; <nl> + } <nl> + <nl> + TEST_F ( ReplCoordTest , HBReconfigDuringReconfigFails ) { <nl> + / / start up , become primary , reconfig , while reconfigging receive reconfig via heartbeat <nl> + OperationContextNoop txn ; <nl> + assertStart ( ReplicationCoordinator : : modeReplSet , <nl> + BSON ( " _id " < < " mySet " < < <nl> + " version " < < 2 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < " host " < < " node2 : 12345 " ) ) ) , <nl> + HostAndPort ( " node1 " , 12345 ) ) ; <nl> + ASSERT ( getReplCoord ( ) - > setFollowerMode ( MemberState : : RS_SECONDARY ) ) ; <nl> + getReplCoord ( ) - > setMyLastOptime ( & txn , OpTime ( 100 , 0 ) ) ; <nl> + simulateSuccessfulElection ( ) ; <nl> + ASSERT_TRUE ( getReplCoord ( ) - > getCurrentMemberState ( ) . primary ( ) ) ; <nl> + <nl> + / / schedule hb reconfig <nl> + NetworkInterfaceMock * net = getNet ( ) ; <nl> + net - > enterNetwork ( ) ; <nl> + net - > runUntil ( net - > now ( ) + 10 * 1000 ) ; / / run until we ' ve sent a heartbeat request <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi = net - > getNextReadyRequest ( ) ; <nl> + ReplSetHeartbeatResponse hbResp ; <nl> + ReplicaSetConfig config ; <nl> + config . initialize ( BSON ( " _id " < < " mySet " < < <nl> + " version " < < 4 < < <nl> + " members " < < BSON_ARRAY ( BSON ( " _id " < < 1 < < <nl> + " host " < < " node1 : 12345 " ) < < <nl> + BSON ( " _id " < < 2 < < <nl> + " host " < < " node2 : 12345 " ) ) ) ) ; <nl> + hbResp . setConfig ( config ) ; <nl> + hbResp . setVersion ( 4 ) ; <nl> + hbResp . setSetName ( " mySet " ) ; <nl> + hbResp . setState ( MemberState : : RS_SECONDARY ) ; <nl> + BSONObjBuilder respObj2 ; <nl> + respObj2 < < " ok " < < 1 ; <nl> + hbResp . addToBSON ( & respObj2 ) ; <nl> + net - > scheduleResponse ( noi , net - > now ( ) , makeResponseStatus ( respObj2 . obj ( ) ) ) ; <nl> + <nl> + / / start reconfig thread <nl> + Status status2 ( ErrorCodes : : InternalError , " Not Set " ) ; <nl> + boost : : thread reconfigThread ( stdx : : bind ( doReplSetReconfig , getReplCoord ( ) , & status2 ) ) ; <nl> + logger : : globalLogDomain ( ) - > setMinimumLoggedSeverity ( logger : : LogSeverity : : Debug ( 1 ) ) ; <nl> + startCapturingLogMessages ( ) ; <nl> + / / execute hb reconfig , which should fail with a log message ; confirmed at end of test <nl> + net - > runUntil ( net - > now ( ) + 500 ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + / / respond to reconfig ' s quorum check so that we can join that thread and exit cleanly <nl> + const NetworkInterfaceMock : : NetworkOperationIterator noi2 = net - > getNextReadyRequest ( ) ; <nl> + const ReplicationExecutor : : RemoteCommandRequest & request = noi2 - > getRequest ( ) ; <nl> + repl : : ReplSetHeartbeatArgs hbArgs ; <nl> + ASSERT_OK ( hbArgs . initialize ( request . cmdObj ) ) ; <nl> + repl : : ReplSetHeartbeatResponse hbResp2 ; <nl> + hbResp2 . setSetName ( " mySet " ) ; <nl> + hbResp2 . setState ( MemberState : : RS_SECONDARY ) ; <nl> + hbResp2 . setVersion ( 5 ) ; <nl> + BSONObjBuilder respObj ; <nl> + respObj < < " ok " < < 1 ; <nl> + hbResp2 . addToBSON ( & respObj ) ; <nl> + net - > scheduleResponse ( noi2 , net - > now ( ) , makeResponseStatus ( respObj . obj ( ) ) ) ; <nl> + net - > runReadyNetworkOperations ( ) ; <nl> + net - > exitNetwork ( ) ; <nl> + stopCapturingLogMessages ( ) ; <nl> + ASSERT_EQUALS ( 1 , <nl> + countLogLinesContaining ( " because already in the midst of a configuration process " ) ) ; <nl> + reconfigThread . join ( ) ; <nl> + logger : : globalLogDomain ( ) - > setMinimumLoggedSeverity ( logger : : LogSeverity : : Log ( ) ) ; <nl> + } <nl> + <nl> + } / / anonymous namespace <nl> + } / / namespace repl <nl> + } / / namespace mongo <nl> mmm a / src / mongo / db / repl / repl_coordinator_test_fixture . cpp <nl> ppp b / src / mongo / db / repl / repl_coordinator_test_fixture . cpp <nl> namespace { <nl> } <nl> <nl> void ReplCoordTest : : tearDown ( ) { <nl> + if ( _externalState ) { <nl> + _externalState - > setStoreLocalConfigDocumentToHang ( false ) ; <nl> + } <nl> if ( _callShutdown ) { <nl> shutdown ( ) ; <nl> } <nl>
SERVER - 15657 test ReplicationCoordinatorImpl reconfigging
mongodb/mongo
f919a33b0d8ca3767e40c0cf9588f1a8d25b7cee
2014-10-14T14:43:34Z
mmm a / src / heap / heap . cc <nl> ppp b / src / heap / heap . cc <nl> bool Heap : : CanExpandOldGeneration ( size_t size ) { <nl> return memory_allocator ( ) - > Size ( ) + size < = MaxReserved ( ) ; <nl> } <nl> <nl> + bool Heap : : CanExpandOldGenerationBackground ( size_t size ) { <nl> + if ( force_oom_ ) return false ; <nl> + return memory_allocator ( ) - > Size ( ) + size < = MaxReserved ( ) ; <nl> + } <nl> + <nl> bool Heap : : HasBeenSetUp ( ) const { <nl> / / We will always have a new space when the heap is set up . <nl> return new_space_ ! = nullptr ; <nl> void Heap : : NotifyBootstrapComplete ( ) { <nl> } <nl> } <nl> <nl> - void Heap : : NotifyOldGenerationExpansion ( ) { <nl> + void Heap : : NotifyOldGenerationExpansion ( AllocationSpace space , <nl> + MemoryChunk * chunk ) { <nl> + / / Pages created during bootstrapping may contain immortal immovable objects . <nl> + if ( ! deserialization_complete ( ) ) { <nl> + chunk - > MarkNeverEvacuate ( ) ; <nl> + } <nl> + if ( space = = CODE_SPACE | | space = = CODE_LO_SPACE ) { <nl> + isolate ( ) - > AddCodeMemoryChunk ( chunk ) ; <nl> + } <nl> const size_t kMemoryReducerActivationThreshold = 1 * MB ; <nl> if ( old_generation_capacity_after_bootstrap_ & & ms_count_ = = 0 & & <nl> OldGenerationCapacity ( ) > = old_generation_capacity_after_bootstrap_ + <nl> mmm a / src / heap / heap . h <nl> ppp b / src / heap / heap . h <nl> class Heap { <nl> <nl> void NotifyBootstrapComplete ( ) ; <nl> <nl> - void NotifyOldGenerationExpansion ( ) ; <nl> + void NotifyOldGenerationExpansion ( AllocationSpace space , MemoryChunk * chunk ) ; <nl> <nl> inline Address * NewSpaceAllocationTopAddress ( ) ; <nl> inline Address * NewSpaceAllocationLimitAddress ( ) ; <nl> class Heap { <nl> bool always_allocate ( ) { return always_allocate_scope_count_ ! = 0 ; } <nl> <nl> V8_EXPORT_PRIVATE bool CanExpandOldGeneration ( size_t size ) ; <nl> + V8_EXPORT_PRIVATE bool CanExpandOldGenerationBackground ( size_t size ) ; <nl> <nl> bool ShouldExpandOldGenerationOnSlowAllocation ( <nl> LocalHeap * local_heap = nullptr ) ; <nl> class Heap { <nl> friend class IncrementalMarking ; <nl> friend class IncrementalMarkingJob ; <nl> friend class OffThreadHeap ; <nl> + friend class OffThreadSpace ; <nl> friend class OldLargeObjectSpace ; <nl> template < typename ConcreteVisitor , typename MarkingState > <nl> friend class MarkingVisitorBase ; <nl> mmm a / src / heap / large - spaces . cc <nl> ppp b / src / heap / large - spaces . cc <nl> AllocationResult OldLargeObjectSpace : : AllocateRaw ( int object_size , <nl> heap ( ) - > incremental_marking ( ) - > black_allocation ( ) , <nl> heap ( ) - > incremental_marking ( ) - > marking_state ( ) - > IsBlack ( object ) ) ; <nl> page - > InitializationMemoryFence ( ) ; <nl> - heap ( ) - > NotifyOldGenerationExpansion ( ) ; <nl> + heap ( ) - > NotifyOldGenerationExpansion ( identity ( ) , page ) ; <nl> AllocationStep ( object_size , object . address ( ) , object_size ) ; <nl> return object ; <nl> } <nl> AllocationResult CodeLargeObjectSpace : : AllocateRaw ( int object_size ) { <nl> void CodeLargeObjectSpace : : AddPage ( LargePage * page , size_t object_size ) { <nl> OldLargeObjectSpace : : AddPage ( page , object_size ) ; <nl> InsertChunkMapEntries ( page ) ; <nl> - heap ( ) - > isolate ( ) - > AddCodeMemoryChunk ( page ) ; <nl> } <nl> <nl> void CodeLargeObjectSpace : : RemovePage ( LargePage * page , size_t object_size ) { <nl> mmm a / src / heap / off - thread - heap . cc <nl> ppp b / src / heap / off - thread - heap . cc <nl> void OffThreadHeap : : Publish ( Heap * heap ) { <nl> heap - > lo_space ( ) - > MergeOffThreadSpace ( & lo_space_ ) ; <nl> <nl> DCHECK ( heap - > CanExpandOldGeneration ( 0 ) ) ; <nl> - heap - > NotifyOldGenerationExpansion ( ) ; <nl> <nl> / / Possibly trigger a GC if we ' re close to exhausting the old generation . <nl> / / TODO ( leszeks ) : Adjust the heuristics here . <nl> mmm a / src / heap / paged - spaces . cc <nl> ppp b / src / heap / paged - spaces . cc <nl> void PagedSpace : : MergeLocalSpace ( LocalSpace * other ) { <nl> / / Relinking requires the category to be unlinked . <nl> other - > RemovePage ( p ) ; <nl> AddPage ( p ) ; <nl> - / / These code pages were allocated by the CompactionSpace . <nl> - if ( identity ( ) = = CODE_SPACE ) heap ( ) - > isolate ( ) - > AddCodeMemoryChunk ( p ) ; <nl> - heap ( ) - > NotifyOldGenerationExpansion ( ) ; <nl> + heap ( ) - > NotifyOldGenerationExpansion ( identity ( ) , p ) ; <nl> DCHECK_IMPLIES ( <nl> ! p - > IsFlagSet ( Page : : NEVER_ALLOCATE_ON_PAGE ) , <nl> p - > AvailableInFreeList ( ) = = p - > AvailableInFreeListFromAllocatedBytes ( ) ) ; <nl> void PagedSpace : : ShrinkImmortalImmovablePages ( ) { <nl> } <nl> } <nl> <nl> - bool PagedSpace : : Expand ( ) { <nl> + Page * PagedSpace : : Expand ( ) { <nl> + / / TODO ( ulan ) : Remove the mutex as it seems redundant : <nl> / / Always lock against the main space as we can only adjust capacity and <nl> / / pages concurrently for the main paged space . <nl> base : : MutexGuard guard ( heap ( ) - > paged_space ( identity ( ) ) - > mutex ( ) ) ; <nl> <nl> - const int size = AreaSize ( ) ; <nl> - <nl> - if ( ! heap ( ) - > CanExpandOldGeneration ( size ) ) return false ; <nl> - <nl> Page * page = <nl> - heap ( ) - > memory_allocator ( ) - > AllocatePage ( size , this , executable ( ) ) ; <nl> - if ( page = = nullptr ) return false ; <nl> - / / Pages created during bootstrapping may contain immortal immovable objects . <nl> - if ( ! heap ( ) - > deserialization_complete ( ) ) page - > MarkNeverEvacuate ( ) ; <nl> + heap ( ) - > memory_allocator ( ) - > AllocatePage ( AreaSize ( ) , this , executable ( ) ) ; <nl> + if ( page = = nullptr ) return nullptr ; <nl> AddPage ( page ) ; <nl> - / / If this is a non - compaction code space , this is a previously unseen page . <nl> - if ( identity ( ) = = CODE_SPACE & & ! is_compaction_space ( ) ) { <nl> - heap ( ) - > isolate ( ) - > AddCodeMemoryChunk ( page ) ; <nl> - } <nl> Free ( page - > area_start ( ) , page - > area_size ( ) , <nl> SpaceAccountingMode : : kSpaceAccounted ) ; <nl> - if ( ! is_off_thread_space ( ) ) { <nl> - heap ( ) - > NotifyOldGenerationExpansion ( ) ; <nl> - } <nl> - return true ; <nl> + return page ; <nl> } <nl> <nl> int PagedSpace : : CountTotalPages ( ) { <nl> PagedSpace : : SlowGetLinearAllocationAreaBackground ( LocalHeap * local_heap , <nl> } <nl> <nl> if ( heap ( ) - > ShouldExpandOldGenerationOnSlowAllocation ( local_heap ) & & <nl> - Expand ( ) ) { <nl> + heap ( ) - > CanExpandOldGenerationBackground ( AreaSize ( ) ) & & Expand ( ) ) { <nl> DCHECK ( ( CountTotalPages ( ) > 1 ) | | <nl> ( min_size_in_bytes < = free_list_ - > Available ( ) ) ) ; <nl> return TryAllocationFromFreeListBackground ( <nl> bool OffThreadSpace : : SlowRefillLinearAllocationArea ( int size_in_bytes , <nl> if ( RefillLinearAllocationAreaFromFreeList ( size_in_bytes , origin ) ) <nl> return true ; <nl> <nl> - if ( Expand ( ) ) { <nl> + if ( heap ( ) - > CanExpandOldGenerationBackground ( size_in_bytes ) & & Expand ( ) ) { <nl> DCHECK ( ( CountTotalPages ( ) > 1 ) | | <nl> ( static_cast < size_t > ( size_in_bytes ) < = free_list_ - > Available ( ) ) ) ; <nl> return RefillLinearAllocationAreaFromFreeList ( <nl> bool PagedSpace : : RawSlowRefillLinearAllocationArea ( int size_in_bytes , <nl> } <nl> } <nl> <nl> - if ( heap ( ) - > ShouldExpandOldGenerationOnSlowAllocation ( ) & & Expand ( ) ) { <nl> - DCHECK ( ( CountTotalPages ( ) > 1 ) | | <nl> - ( static_cast < size_t > ( size_in_bytes ) < = free_list_ - > Available ( ) ) ) ; <nl> - return RefillLinearAllocationAreaFromFreeList ( <nl> - static_cast < size_t > ( size_in_bytes ) , origin ) ; <nl> + if ( heap ( ) - > ShouldExpandOldGenerationOnSlowAllocation ( ) & & <nl> + heap ( ) - > CanExpandOldGeneration ( AreaSize ( ) ) ) { <nl> + Page * page = Expand ( ) ; <nl> + if ( page ) { <nl> + if ( ! is_compaction_space ( ) ) { <nl> + heap ( ) - > NotifyOldGenerationExpansion ( identity ( ) , page ) ; <nl> + } <nl> + DCHECK ( ( CountTotalPages ( ) > 1 ) | | <nl> + ( static_cast < size_t > ( size_in_bytes ) < = free_list_ - > Available ( ) ) ) ; <nl> + return RefillLinearAllocationAreaFromFreeList ( <nl> + static_cast < size_t > ( size_in_bytes ) , origin ) ; <nl> + } <nl> } <nl> <nl> if ( is_compaction_space ( ) ) { <nl> mmm a / src / heap / paged - spaces . h <nl> ppp b / src / heap / paged - spaces . h <nl> class V8_EXPORT_PRIVATE PagedSpace <nl> / / Expands the space by allocating a fixed number of pages . Returns false if <nl> / / it cannot allocate requested number of pages from OS , or if the hard heap <nl> / / size limit has been hit . <nl> - bool Expand ( ) ; <nl> + Page * Expand ( ) ; <nl> <nl> / / Sets up a linear allocation area that fits the given number of bytes . <nl> / / Returns false if there is not enough space and the caller has to retry <nl>
[ heap ] Make PagedSpace : : Expand thread - safe
v8/v8
4f9b30b0145fcdda34e7012c7633cc95f6d3bbdf
2020-05-18T09:23:45Z
mmm a / editor / editor_node . cpp <nl> ppp b / editor / editor_node . cpp <nl> void EditorNode : : _notification ( int p_what ) { <nl> scene_tabs - > set_tab_close_display_policy ( ( bool ( EDITOR_DEF ( " interface / always_show_close_button_in_scene_tabs " , false ) ) ? Tabs : : CLOSE_BUTTON_SHOW_ALWAYS : Tabs : : CLOSE_BUTTON_SHOW_ACTIVE_ONLY ) ) ; <nl> property_editor - > set_enable_capitalize_paths ( bool ( EDITOR_DEF ( " interface / capitalize_properties " , true ) ) ) ; <nl> Ref < Theme > theme = create_editor_theme ( theme_base - > get_theme ( ) ) ; <nl> + <nl> theme_base - > set_theme ( theme ) ; <nl> + <nl> gui_base - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Background " , " EditorStyles " ) ) ; <nl> play_button_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " PlayButtonPanel " , " EditorStyles " ) ) ; <nl> scene_root_parent - > add_style_override ( " panel " , gui_base - > get_stylebox ( " Content " , " EditorStyles " ) ) ; <nl> bottom_panel - > add_style_override ( " panel " , gui_base - > get_stylebox ( " panel " , " TabContainer " ) ) ; <nl> scene_tabs - > add_style_override ( " tab_fg " , gui_base - > get_stylebox ( " SceneTabFG " , " EditorStyles " ) ) ; <nl> scene_tabs - > add_style_override ( " tab_bg " , gui_base - > get_stylebox ( " SceneTabBG " , " EditorStyles " ) ) ; <nl> + <nl> + file_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + project_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + debug_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + settings_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + help_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + <nl> if ( bool ( EDITOR_DEF ( " interface / scene_tabs / resize_if_many_tabs " , true ) ) ) { <nl> scene_tabs - > set_min_width ( int ( EDITOR_DEF ( " interface / scene_tabs / minimum_width " , 50 ) ) * EDSCALE ) ; <nl> } else { <nl> EditorNode : : EditorNode ( ) { <nl> } <nl> <nl> file_menu = memnew ( MenuButton ) ; <nl> + file_menu - > set_flat ( false ) ; <nl> file_menu - > set_text ( TTR ( " Scene " ) ) ; <nl> - left_menu_hb - > add_child ( file_menu ) ; <nl> file_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + left_menu_hb - > add_child ( file_menu ) ; <nl> <nl> prev_scene = memnew ( ToolButton ) ; <nl> prev_scene - > set_icon ( gui_base - > get_icon ( " PrevScene " , " EditorIcons " ) ) ; <nl> EditorNode : : EditorNode ( ) { <nl> p - > add_item ( TTR ( " Quit " ) , FILE_QUIT , KEY_MASK_CMD + KEY_Q ) ; <nl> <nl> project_menu = memnew ( MenuButton ) ; <nl> + project_menu - > set_flat ( false ) ; <nl> project_menu - > set_tooltip ( TTR ( " Miscellaneous project or scene - wide tools . " ) ) ; <nl> project_menu - > set_text ( TTR ( " Project " ) ) ; <nl> project_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> EditorNode : : EditorNode ( ) { <nl> menu_hb - > add_child ( editor_region ) ; <nl> <nl> debug_menu = memnew ( MenuButton ) ; <nl> + debug_menu - > set_flat ( false ) ; <nl> debug_menu - > set_text ( TTR ( " Debug " ) ) ; <nl> debug_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> left_menu_hb - > add_child ( debug_menu ) ; <nl> + <nl> p = debug_menu - > get_popup ( ) ; <nl> p - > set_hide_on_item_selection ( false ) ; <nl> p - > add_check_item ( TTR ( " Deploy with Remote Debug " ) , RUN_DEPLOY_REMOTE_DEBUG ) ; <nl> EditorNode : : EditorNode ( ) { <nl> menu_hb - > add_spacer ( ) ; <nl> <nl> settings_menu = memnew ( MenuButton ) ; <nl> - left_menu_hb - > add_child ( settings_menu ) ; <nl> + settings_menu - > set_flat ( false ) ; <nl> settings_menu - > set_text ( TTR ( " Editor " ) ) ; <nl> settings_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + left_menu_hb - > add_child ( settings_menu ) ; <nl> p = settings_menu - > get_popup ( ) ; <nl> <nl> p - > add_item ( TTR ( " Editor Settings " ) , SETTINGS_PREFERENCES ) ; <nl> EditorNode : : EditorNode ( ) { <nl> p - > add_item ( TTR ( " Manage Export Templates " ) , SETTINGS_MANAGE_EXPORT_TEMPLATES ) ; <nl> <nl> / / Help Menu <nl> - MenuButton * help_menu = memnew ( MenuButton ) ; <nl> - left_menu_hb - > add_child ( help_menu ) ; <nl> + help_menu = memnew ( MenuButton ) ; <nl> + help_menu - > set_flat ( false ) ; <nl> help_menu - > set_text ( TTR ( " Help " ) ) ; <nl> help_menu - > add_style_override ( " hover " , gui_base - > get_stylebox ( " MenuHover " , " EditorStyles " ) ) ; <nl> + left_menu_hb - > add_child ( help_menu ) ; <nl> + <nl> p = help_menu - > get_popup ( ) ; <nl> p - > connect ( " id_pressed " , this , " _menu_option " ) ; <nl> p - > add_icon_item ( gui_base - > get_icon ( " ClassList " , " EditorIcons " ) , TTR ( " Classes " ) , HELP_CLASSES ) ; <nl> mmm a / editor / editor_node . h <nl> ppp b / editor / editor_node . h <nl> class EditorNode : public Node { <nl> MenuButton * file_menu ; <nl> MenuButton * project_menu ; <nl> MenuButton * debug_menu ; <nl> + MenuButton * settings_menu ; <nl> + MenuButton * help_menu ; <nl> PopupMenu * tool_menu ; <nl> ToolButton * export_button ; <nl> ToolButton * prev_scene ; <nl> MenuButton * object_menu ; <nl> - MenuButton * settings_menu ; <nl> ToolButton * play_button ; <nl> MenuButton * native_play_button ; <nl> ToolButton * pause_button ; <nl> mmm a / editor / editor_themes . cpp <nl> ppp b / editor / editor_themes . cpp <nl> Ref < Theme > create_editor_theme ( const Ref < Theme > p_theme ) { <nl> Ref < StyleBoxFlat > style_menu_hover_bg = make_flat_stylebox ( dark_color_2 , 4 , 4 , 4 , 4 ) ; <nl> <nl> style_menu_hover_border - > set_draw_center ( false ) ; <nl> - style_menu_hover_border - > set_border_width ( MARGIN_BOTTOM , border_width ) ; <nl> + style_menu_hover_border - > set_border_width ( MARGIN_BOTTOM , 2 * EDSCALE ) ; <nl> style_menu_hover_border - > set_border_color_all ( highlight_color ) ; <nl> - style_menu_hover_border - > set_expand_margin_size ( MARGIN_BOTTOM , border_width ) ; <nl> <nl> theme - > set_stylebox ( " normal " , " MenuButton " , style_menu ) ; <nl> - theme - > set_stylebox ( " hover " , " MenuButton " , style_menu_hover_border ) ; <nl> + theme - > set_stylebox ( " hover " , " MenuButton " , style_menu ) ; <nl> theme - > set_stylebox ( " pressed " , " MenuButton " , style_menu ) ; <nl> theme - > set_stylebox ( " focus " , " MenuButton " , style_menu ) ; <nl> theme - > set_stylebox ( " disabled " , " MenuButton " , style_menu ) ; <nl>
fixed hover line for menu button
godotengine/godot
45d57ccf288f1957bebdba428adc1090052f5522
2017-09-04T16:06:13Z
mmm a / editor / editor_about . cpp <nl> ppp b / editor / editor_about . cpp <nl> EditorAbout : : EditorAbout ( ) { <nl> <nl> Label * about_text = memnew ( Label ) ; <nl> about_text - > set_v_size_flags ( Control : : SIZE_SHRINK_CENTER ) ; <nl> - about_text - > set_text ( VERSION_FULL_NAME + hash + String : : utf8 ( " \ n \ xc2 \ xa9 2007 - 2018 Juan Linietsky , Ariel Manzur . \ n \ xc2 \ xa9 2014 - 2017 " ) + <nl> + about_text - > set_text ( VERSION_FULL_NAME + hash + <nl> + String : : utf8 ( " \ n \ xc2 \ xa9 2007 - 2018 Juan Linietsky , Ariel Manzur . \ n \ xc2 \ xa9 2014 - 2018 " ) + <nl> TTR ( " Godot Engine contributors " ) + " \ n " ) ; <nl> hbc - > add_child ( about_text ) ; <nl> <nl> mmm a / misc / dist / osx_tools . app / Contents / Info . plist <nl> ppp b / misc / dist / osx_tools . app / Contents / Info . plist <nl> <nl> < key > CFBundleName < / key > <nl> < string > Godot < / string > <nl> < key > CFBundleGetInfoString < / key > <nl> - < string > ( c ) 2007 - 2018 Juan Linietsky , Ariel Manzur . / string > <nl> + < string > ( c ) 2007 - 2018 Juan Linietsky , Ariel Manzur . < / string > <nl> < key > CFBundleIconFile < / key > <nl> < string > Godot . icns < / string > <nl> < key > CFBundleIdentifier < / key > <nl> <nl> < key > CFBundleVersion < / key > <nl> < string > 3 . 0 - dev < / string > <nl> < key > NSHumanReadableCopyright < / key > <nl> - < string > © 2007 - 2018 Juan Linietsky , Ariel Manzur . / string > <nl> + < string > © 2007 - 2018 Juan Linietsky , Ariel Manzur . < / string > <nl> < key > LSMinimumSystemVersion < / key > <nl> < string > 10 . 9 . 0 < / string > <nl> < key > LSMinimumSystemVersionByArchitecture < / key > <nl> mmm a / servers / visual / visual_server_wrap_mt . cpp <nl> ppp b / servers / visual / visual_server_wrap_mt . cpp <nl> <nl> / * https : / / godotengine . org * / <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> / * Copyright ( c ) 2007 - 2018 Juan Linietsky , Ariel Manzur . * / <nl> + / * Copyright ( c ) 2014 - 2018 Godot Engine contributors ( cf . AUTHORS . md ) * / <nl> / * * / <nl> / * Permission is hereby granted , free of charge , to any person obtaining * / <nl> / * a copy of this software and associated documentation files ( the * / <nl> mmm a / servers / visual / visual_server_wrap_mt . h <nl> ppp b / servers / visual / visual_server_wrap_mt . h <nl> <nl> / * https : / / godotengine . org * / <nl> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / <nl> / * Copyright ( c ) 2007 - 2018 Juan Linietsky , Ariel Manzur . * / <nl> + / * Copyright ( c ) 2014 - 2018 Godot Engine contributors ( cf . AUTHORS . md ) * / <nl> / * * / <nl> / * Permission is hereby granted , free of charge , to any person obtaining * / <nl> / * a copy of this software and associated documentation files ( the * / <nl>
Fix broken Info . plist after copyright update
godotengine/godot
e3c9a7ed4f0b07a841e51b8bf2e92c370d21e33c
2018-01-03T16:10:07Z
mmm a / README . md <nl> ppp b / README . md <nl> You can find quick start guides for each language , including installation instru <nl> * [ Go ] ( https : / / github . com / grpc / grpc - common / tree / master / go ) <nl> * [ ruby ] ( https : / / github . com / grpc / grpc - common / tree / master / ruby ) <nl> * [ Node . js ] ( https : / / github . com / grpc / grpc - common / tree / master / node ) <nl> - * Python is coming soon <nl> + * [ Python ] ( https : / / github . com / grpc / grpc - common / tree / master / python / helloworld ) <nl> <nl> # # What ' s in this repository ? <nl> <nl>
Added link to python helloworld
grpc/grpc
b6ab52c2b34e27b060a83b90f4fce6dd04be1d82
2015-02-26T01:48:28Z
mmm a / api / envoy / service / tap / v2alpha / BUILD <nl> ppp b / api / envoy / service / tap / v2alpha / BUILD <nl> api_proto_library_internal ( <nl> " / / envoy / api / v2 / core : base " , <nl> " / / envoy / api / v2 / core : grpc_service " , <nl> " / / envoy / api / v2 / route " , <nl> - " / / envoy / type / matcher : string " , <nl> ] , <nl> ) <nl> <nl> mmm a / api / envoy / service / tap / v2alpha / common . proto <nl> ppp b / api / envoy / service / tap / v2alpha / common . proto <nl> syntax = " proto3 " ; <nl> import " envoy / api / v2 / route / route . proto " ; <nl> import " envoy / api / v2 / core / base . proto " ; <nl> import " envoy / api / v2 / core / grpc_service . proto " ; <nl> - import " envoy / type / matcher / string . proto " ; <nl> <nl> import " google / protobuf / wrappers . proto " ; <nl> <nl>
tap : remove unused dependency . ( )
envoyproxy/envoy
101f8157fe06d78262d0b3c07cf1c2b7c8e72c98
2019-07-15T22:24:37Z
mmm a / arangod / Agency / State . cpp <nl> ppp b / arangod / Agency / State . cpp <nl> bool State : : loadCollection ( std : : string const & name ) { <nl> tmp - > append ( req . startAs < char const > ( ) , req . byteSize ( ) ) ; <nl> _log . push_back ( <nl> log_t ( std : : stoi ( i . get ( TRI_VOC_ATTRIBUTE_KEY ) . copyString ( ) ) , <nl> - i . get ( " term " ) . getUInt ( ) , <nl> - i . get ( " leader " ) . getUInt ( ) , tmp ) ) ; <nl> + static_cast < term_t > ( i . get ( " term " ) . getUInt ( ) ) , <nl> + static_cast < id_t > ( i . get ( " leader " ) . getUInt ( ) ) , tmp ) ) ; <nl> } <nl> } <nl> <nl> mmm a / arangod / Cluster / AgencyCallback . cpp <nl> ppp b / arangod / Cluster / AgencyCallback . cpp <nl> void AgencyCallback : : waitForExecution ( double maxTimeout ) { <nl> <nl> _useCv = true ; <nl> CONDITION_LOCKER ( locker , _cv ) ; <nl> - locker . wait ( maxTimeout * 1000000 ) ; <nl> + locker . wait ( maxTimeout * 1000000 . 0 ) ; <nl> _useCv = false ; <nl> <nl> if ( ! _lastData | | _lastData - > slice ( ) . equals ( compareSlice ) ) { <nl>
fixed MSVC complaints
arangodb/arangodb
4cf847aecdbc0a588bcae135d15d69b3c3b44ba2
2016-04-22T19:04:03Z
mmm a / osquery / config / config . cpp <nl> ppp b / osquery / config / config . cpp <nl> DECLARE_string ( pack_delimiter ) ; <nl> const std : : string kExecutingQuery { " executing_query " } ; <nl> const std : : string kFailedQueries { " failed_queries " } ; <nl> <nl> - / / / The time osquery was started . <nl> - std : : atomic < size_t > kStartTime ; <nl> - <nl> / / The config may be accessed and updated asynchronously ; use mutexes . <nl> Mutex config_hash_mutex_ ; <nl> Mutex config_refresh_mutex_ ; <nl> void Config : : addPack ( const std : : string & name , <nl> } <nl> } <nl> <nl> - size_t Config : : getStartTime ( ) { <nl> - return kStartTime ; <nl> - } <nl> - <nl> - void Config : : setStartTime ( size_t st ) { <nl> - kStartTime = st ; <nl> - } <nl> - <nl> void Config : : removePack ( const std : : string & pack ) { <nl> RecursiveLock wlock ( config_schedule_mutex_ ) ; <nl> return schedule_ - > remove ( pack ) ; <nl> mmm a / osquery / config / config . h <nl> ppp b / osquery / config / config . h <nl> class Config : private boost : : noncopyable { <nl> return valid_ ; <nl> } <nl> <nl> - / / / Get start time of config . <nl> - static size_t getStartTime ( ) ; <nl> - <nl> - / / / Set the start time if the config . <nl> - static void setStartTime ( size_t st ) ; <nl> - <nl> / * * <nl> * @ brief Add a pack to the osquery schedule <nl> * / <nl> mmm a / osquery / core / init . cpp <nl> ppp b / osquery / core / init . cpp <nl> Initializer : : Initializer ( int & argc , <nl> std : : srand ( static_cast < unsigned int > ( <nl> chrono_clock : : now ( ) . time_since_epoch ( ) . count ( ) ) ) ; <nl> / / The config holds the initialization time for easy access . <nl> - Config : : setStartTime ( getUnixTime ( ) ) ; <nl> + setStartTime ( getUnixTime ( ) ) ; <nl> <nl> isWorker_ = hasWorkerVariable ( ) ; <nl> <nl> mmm a / osquery / core / system . cpp <nl> ppp b / osquery / core / system . cpp <nl> FLAG ( string , <nl> <nl> FLAG ( bool , utc , true , " Convert all UNIX times to UTC " ) ; <nl> <nl> + namespace { <nl> + <nl> const std : : vector < std : : string > kPlaceholderHardwareUUIDList { <nl> " 00000000 - 0000 - 0000 - 0000 - 000000000000 " , <nl> " 03000200 - 0400 - 0500 - 0006 - 000700080009 " , <nl> const std : : vector < std : : string > kPlaceholderHardwareUUIDList { <nl> " 10000000 - 0000 - 8000 - 0040 - 000000000000 " , <nl> } ; <nl> <nl> + / / / The time osquery was started . <nl> + std : : atomic < size_t > kStartTime { 0 } ; <nl> + } / / namespace <nl> + <nl> # ifdef WIN32 <nl> struct tm * gmtime_r ( time_t * t , struct tm * result ) { <nl> _gmtime64_s ( result , t ) ; <nl> Status setThreadName ( const std : : string & name ) { <nl> # endif <nl> } <nl> <nl> + void setStartTime ( size_t st ) { <nl> + kStartTime = st ; <nl> + } <nl> + <nl> + size_t getStartTime ( ) { <nl> + return kStartTime ; <nl> + } <nl> + <nl> bool checkPlatform ( const std : : string & platform ) { <nl> if ( platform . empty ( ) | | platform = = " null " ) { <nl> return true ; <nl> mmm a / osquery / core / watcher . cpp <nl> ppp b / osquery / core / watcher . cpp <nl> void WatcherRunner : : watchExtensions ( ) { <nl> } <nl> <nl> size_t WatcherRunner : : delayedTime ( ) const { <nl> - return Config : : getStartTime ( ) + FLAGS_watchdog_delay ; <nl> + return getStartTime ( ) + FLAGS_watchdog_delay ; <nl> } <nl> <nl> bool WatcherRunner : : watch ( const PlatformProcess & child ) const { <nl> mmm a / osquery / include / osquery / system . h <nl> ppp b / osquery / include / osquery / system . h <nl> bool isUserAdmin ( ) ; <nl> * / <nl> Status setThreadName ( const std : : string & name ) ; <nl> <nl> + / / / Get the osquery tool start time . <nl> + size_t getStartTime ( ) ; <nl> + <nl> + / / / Set the osquery tool start time . <nl> + void setStartTime ( size_t st ) ; <nl> + <nl> bool checkPlatform ( const std : : string & platform ) ; <nl> } / / namespace osquery <nl> mmm a / osquery / tables / utility / osquery . cpp <nl> ppp b / osquery / tables / utility / osquery . cpp <nl> QueryData genOsqueryInfo ( QueryContext & context ) { <nl> ( pingExtension ( FLAGS_extensions_socket ) . ok ( ) ) ? " active " : " inactive " ; <nl> r [ " build_platform " ] = STR ( OSQUERY_BUILD_PLATFORM ) ; <nl> r [ " build_distro " ] = STR ( OSQUERY_BUILD_DISTRO ) ; <nl> - r [ " start_time " ] = INTEGER ( Config : : getStartTime ( ) ) ; <nl> + r [ " start_time " ] = INTEGER ( getStartTime ( ) ) ; <nl> if ( Initializer : : isWorker ( ) ) { <nl> r [ " watcher " ] = INTEGER ( PlatformProcess : : getLauncherProcess ( ) - > pid ( ) ) ; <nl> } else { <nl> mmm a / tests / test_util . cpp <nl> ppp b / tests / test_util . cpp <nl> DECLARE_bool ( disable_database ) ; <nl> using chrono_clock = std : : chrono : : high_resolution_clock ; <nl> <nl> void initTesting ( ) { <nl> - Config : : setStartTime ( getUnixTime ( ) ) ; <nl> + setStartTime ( getUnixTime ( ) ) ; <nl> <nl> setToolType ( ToolType : : TEST ) ; <nl> if ( osquery : : isPlatform ( PlatformType : : TYPE_OSX ) ) { <nl>
detangle : Move start time getter and setter out of Config
osquery/osquery
89953d3340ef9a0e3d7d1a287cdecbe5760ecb71
2020-07-09T14:38:53Z
mmm a / tensorflow / contrib / tfprof / python / tools / tfprof / internal / run_metadata_test . py <nl> ppp b / tensorflow / contrib / tfprof / python / tools / tfprof / internal / run_metadata_test . py <nl> def _run_model ( ) : <nl> class RunMetadataTest ( test . TestCase ) : <nl> <nl> def testGPU ( self ) : <nl> - if not test . is_gpu_available ( ) : <nl> + if not test . is_gpu_available ( cuda_only = True ) : <nl> return <nl> <nl> with ops . device ( ' / gpu : 0 ' ) : <nl>
Merge pull request from lukeiwanski / opencl / run_metadata_test
tensorflow/tensorflow
f019f51fc6c71187ac3d0b6ac092b41609a1f6d5
2017-06-22T19:59:33Z
mmm a / configure . ac <nl> ppp b / configure . ac <nl> case $ use_platform in <nl> raspberry - pi ) <nl> target_platform = target_raspberry_pi <nl> use_neon = no <nl> - use_arch = " arm " <nl> use_cpu = arm1176jzf - s <nl> + ; ; <nl> + raspberry - pi2 ) <nl> + target_platform = target_raspberry_pi <nl> + use_neon = yes <nl> + use_cpu = cortex - a7 <nl> + ; ; <nl> + esac <nl> + <nl> + if test " $ target_platform " = " target_raspberry_pi " ; then <nl> + use_arch = " arm " <nl> use_hardcoded_tables = " yes " <nl> use_openmax = no <nl> ARCH = " arm " <nl> case $ use_platform in <nl> USE_MMAL = 1 ; AC_DEFINE ( [ HAS_MMAL ] , [ 1 ] , [ " Define to 1 if MMAL libs is enabled " ] ) <nl> CFLAGS = " $ CFLAGS " <nl> CXXFLAGS = " $ CXXFLAGS " <nl> - ; ; <nl> - esac <nl> + fi <nl> <nl> if test " $ host_vendor " = " apple " ; then <nl> use_avahi = no <nl> mmm a / m4 / xbmc_arch . m4 <nl> ppp b / m4 / xbmc_arch . m4 <nl> if test " $ target_platform " = " target_android " ; then <nl> AC_SUBST ( ARCH_DEFINES , " - DTARGET_POSIX - DTARGET_LINUX - D_LINUX - DTARGET_ANDROID " ) <nl> fi <nl> <nl> - case $ use_platform in <nl> - raspberry - pi ) <nl> - AC_SUBST ( ARCH_DEFINES , " - DTARGET_POSIX - DTARGET_LINUX - D_LINUX - D_ARMEL - DTARGET_RASPBERRY_PI " ) <nl> - ; ; <nl> - esac <nl> + if test " $ target_platform " = " target_raspberry_pi " ; then <nl> + AC_SUBST ( ARCH_DEFINES , " - DTARGET_POSIX - DTARGET_LINUX - D_LINUX - D_ARMEL - DTARGET_RASPBERRY_PI " ) <nl> + fi <nl> ] ) <nl> mmm a / tools / depends / Makefile . include . in <nl> ppp b / tools / depends / Makefile . include . in <nl> NATIVE_OS = @ build_os @ <nl> CROSS_COMPILING = @ cross_compiling @ <nl> ARCH_DEFINES = @ ARCH_DEFINES @ <nl> NATIVE_ARCH_DEFINES = @ NATIVE_ARCH_DEFINES @ <nl> - TARGET_PLATFORM = @ use_platform @ <nl> + TARGET_PLATFORM = @ target_platform @ <nl> XCODE_VERSION = @ use_xcode @ <nl> AAPT = @ AAPT @ <nl> DX = @ DX @ <nl> mmm a / tools / depends / configure . ac <nl> ppp b / tools / depends / configure . ac <nl> AC_ARG_WITH ( [ toolchain ] , <nl> AC_ARG_WITH ( [ platform ] , <nl> [ AS_HELP_STRING ( [ - - with - platform ] , <nl> [ target platform [ auto ] ] ) ] , <nl> - [ use_platform = $ withval ] ) <nl> + [ use_platform = $ withval ] , <nl> + [ target_platform = $ withval ] ) <nl> <nl> AC_ARG_WITH ( [ firmware ] , <nl> [ AS_HELP_STRING ( [ - - with - firmware ] , <nl> case $ host in <nl> AC_MSG_ERROR ( unsupported host ( $ use_host ) ) <nl> esac <nl> <nl> - if test " $ use_platform " = " raspberry - pi " ; then <nl> + case $ use_platform in <nl> + raspberry - pi ) <nl> + target_platform = raspberry_pi <nl> + use_neon = no <nl> + use_cpu = arm1176jzf - s <nl> + platform_cflags = " - mcpu = arm1176jzf - s - mtune = arm1176jzf - s - mfloat - abi = hard - mfpu = vfp " <nl> + platform_cxxflags = " - mcpu = arm1176jzf - s - mtune = arm1176jzf - s - mfloat - abi = hard - mfpu = vfp " <nl> + platform_ldflags = " " <nl> + ; ; <nl> + raspberry - pi2 ) <nl> + target_platform = raspberry_pi <nl> + use_neon = yes <nl> + use_cpu = cortex - a7 <nl> + platform_cflags = " - fPIC - mcpu = cortex - a7 - mfloat - abi = hard - mfpu = neon - vfpv4 " <nl> + platform_cxxflags = " - fPIC - mcpu = cortex - a7 - mfloat - abi = hard - mfpu = neon - vfpv4 " <nl> + platform_ldflags = " - lpthread " <nl> + ; ; <nl> + esac <nl> + <nl> + if test " $ target_platform " = " raspberry_pi " ; then <nl> if test - d " $ { use_firmware } / opt / vc / include " ; then <nl> : <nl> else <nl> AC_MSG_ERROR ( [ Raspberry Pi firmware not found ] ) <nl> fi <nl> - use_neon = no <nl> use_arch = " arm " <nl> - use_cpu = " arm1176jzf - s " <nl> use_hardcoded_tables = " yes " <nl> - use_alsa = " no " <nl> ARCH = " arm " <nl> platform_os = " linux " <nl> cross_compiling = " yes " <nl> use_host = " arm - linux - gnueabihf " <nl> deps_dir = " $ use_host " <nl> - platform_cflags = " - pipe - mcpu = arm1176jzf - s - mtune = arm1176jzf - s - mfloat - abi = hard \ <nl> - - mfpu = vfp - mabi = aapcs - linux - Wno - psabi - Wa , - mno - warn - deprecated \ <nl> - - Wno - deprecated - declarations - isystem $ { use_firmware } / opt / vc / include \ <nl> + platform_cflags + = " - pipe - mabi = aapcs - linux - Wno - psabi \ <nl> + - Wa , - mno - warn - deprecated - Wno - deprecated - declarations \ <nl> + - isystem $ { use_firmware } / opt / vc / include \ <nl> - isystem $ { use_firmware } / opt / vc / include / interface / vcos / pthreads \ <nl> - isystem $ { use_firmware } / opt / vc / include / interface / vmcs_host / linux " <nl> - platform_cxxflags = " - pipe - mcpu = arm1176jzf - s - mtune = arm1176jzf - s \ <nl> - - mfloat - abi = hard - mfpu = vfp - mabi = aapcs - linux - Wno - psabi \ <nl> + platform_cxxflags + = " - pipe - mabi = aapcs - linux - Wno - psabi \ <nl> - Wa , - mno - warn - deprecated - Wno - deprecated - declarations \ <nl> - isystem $ { use_firmware } / opt / vc / include \ <nl> - isystem $ { use_firmware } / opt / vc / include / interface / vcos / pthreads \ <nl> - isystem $ { use_firmware } / opt / vc / include / interface / vmcs_host / linux " <nl> - platform_ldflags = " - L $ { use_firmware } / opt / vc / lib - lEGL - lGLESv2 - lbcm_host - lvcos \ <nl> + platform_ldflags + = " - L $ { use_firmware } / opt / vc / lib - lEGL - lGLESv2 - lbcm_host - lvcos \ <nl> - lvchiq_arm " <nl> fi <nl> <nl> mmm a / tools / depends / target / Toolchain . cmake . in <nl> ppp b / tools / depends / target / Toolchain . cmake . in <nl> <nl> SET ( OS " @ platform_os @ " ) <nl> SET ( CPU " @ use_cpu @ " ) <nl> - SET ( PLATFORM " @ use_platform @ " ) <nl> + SET ( PLATFORM " @ target_platform @ " ) <nl> IF ( " $ { OS } " STREQUAL " linux " OR " $ { OS } " STREQUAL " android " ) <nl> SET ( CMAKE_SYSTEM_NAME Linux ) <nl> ENDIF ( ) <nl> mmm a / tools / depends / target / Toolchain_binaddons . cmake . in <nl> ppp b / tools / depends / target / Toolchain_binaddons . cmake . in <nl> <nl> set ( CMAKE_SYSTEM_VERSION 1 ) <nl> set ( OS " @ platform_os @ " ) <nl> set ( CPU " @ use_cpu @ " ) <nl> - set ( PLATFORM " @ use_platform @ " ) <nl> + set ( PLATFORM " @ target_platform @ " ) <nl> if ( " $ { OS } " STREQUAL " linux " OR " $ { OS } " STREQUAL " android " ) <nl> set ( CMAKE_SYSTEM_NAME Linux ) <nl> endif ( ) <nl>
configure : Add raspberry - pi2 platform
xbmc/xbmc
253ec417519afe9415612add80ff5a1753208b75
2015-12-06T19:33:45Z
mmm a / docs / GPU - Windows . rst <nl> ppp b / docs / GPU - Windows . rst <nl> And open an issue in GitHub ` here ` _ with that log . <nl> <nl> . . _Boost : http : / / www . boost . org / users / history / version_1_63_0 . html <nl> <nl> - . . _link : https : / / git - for - windows . github . io / <nl> + . . _link : https : / / git - scm . com / download / win <nl> <nl> . . _CMake : https : / / cmake . org / download / <nl> <nl> mmm a / src / io / config . cpp <nl> ppp b / src / io / config . cpp <nl> void OverallConfig : : Set ( const std : : unordered_map < std : : string , std : : string > & para <nl> } <nl> } <nl> <nl> + bool CheckMultiClassObjective ( const std : : string & objective_type ) { <nl> + return ( objective_type = = std : : string ( " multiclass " ) <nl> + | | objective_type = = std : : string ( " multiclassova " ) <nl> + | | objective_type = = std : : string ( " softmax " ) <nl> + | | objective_type = = std : : string ( " multiclass_ova " ) <nl> + | | objective_type = = std : : string ( " ova " ) <nl> + | | objective_type = = std : : string ( " ovr " ) ) ; <nl> + } <nl> + <nl> void OverallConfig : : CheckParamConflict ( ) { <nl> / / check if objective_type , metric_type , and num_class match <nl> int num_class_check = boosting_config . num_class ; <nl> - bool objective_type_multiclass = ( objective_type = = std : : string ( " multiclass " ) <nl> - | | objective_type = = std : : string ( " multiclassova " ) <nl> - | | ( objective_type = = std : : string ( " none " ) & & num_class_check > 1 ) ) ; <nl> + bool objective_custom = objective_type = = std : : string ( " none " ) | | objective_type = = std : : string ( " null " ) | | objective_type = = std : : string ( " custom " ) ; <nl> + bool objective_type_multiclass = CheckMultiClassObjective ( objective_type ) | | ( objective_custom & & num_class_check > 1 ) ; <nl> <nl> if ( objective_type_multiclass ) { <nl> if ( num_class_check < = 1 ) { <nl> void OverallConfig : : CheckParamConflict ( ) { <nl> } <nl> if ( boosting_config . is_provide_training_metric | | ! io_config . valid_data_filenames . empty ( ) ) { <nl> for ( std : : string metric_type : metric_types ) { <nl> - bool metric_type_multiclass = ( metric_type = = std : : string ( " multi_logloss " ) <nl> + bool metric_type_multiclass = ( CheckMultiClassObjective ( metric_type ) <nl> + | | metric_type = = std : : string ( " multi_logloss " ) <nl> | | metric_type = = std : : string ( " multi_error " ) ) ; <nl> if ( ( objective_type_multiclass & & ! metric_type_multiclass ) <nl> | | ( ! objective_type_multiclass & & metric_type_multiclass ) ) { <nl> mmm a / src / objective / objective_function . cpp <nl> ppp b / src / objective / objective_function . cpp <nl> ObjectiveFunction * ObjectiveFunction : : CreateObjectiveFunction ( const std : : string & <nl> return new RegressionGammaLoss ( config ) ; <nl> } else if ( type = = std : : string ( " tweedie " ) ) { <nl> return new RegressionTweedieLoss ( config ) ; <nl> + } else if ( type = = std : : string ( " none " ) | | type = = std : : string ( " null " ) | | type = = std : : string ( " custom " ) ) { <nl> + return nullptr ; <nl> } <nl> - return nullptr ; <nl> + Log : : Fatal ( " Unknown objective type name : % s " , type . c_str ( ) ) ; <nl> } <nl> <nl> ObjectiveFunction * ObjectiveFunction : : CreateObjectiveFunction ( const std : : string & str ) { <nl> ObjectiveFunction * ObjectiveFunction : : CreateObjectiveFunction ( const std : : string & <nl> return new RegressionGammaLoss ( strs ) ; <nl> } else if ( type = = std : : string ( " tweedie " ) ) { <nl> return new RegressionTweedieLoss ( strs ) ; <nl> + } else if ( type = = std : : string ( " none " ) | | type = = std : : string ( " null " ) | | type = = std : : string ( " custom " ) ) { <nl> + return nullptr ; <nl> } <nl> - return nullptr ; <nl> + Log : : Fatal ( " Unknown objective type name : % s " , type . c_str ( ) ) ; <nl> } <nl> <nl> } / / namespace LightGBM <nl>
fix the name of custom objective function ( )
microsoft/LightGBM
f2143cf7f164e92a6c67243ae220b5e806eae2a9
2018-02-07T03:01:00Z
mmm a / . ado / windows - vs - pr . yml <nl> ppp b / . ado / windows - vs - pr . yml <nl> jobs : <nl> variables : <nl> # 5059 - Disable failing or intermittent tests ( IntegrationTestHarness , AsyncStorage ) . <nl> # 5265 - WebSocketModuleIntegrationTest : : WebSocketModule_Ping fails for Release <nl> - Desktop . IntegrationTests . Filter : ' ( FullyQualifiedName ! ~ WebSocketJSExecutorIntegrationTest ) & ( FullyQualifiedName ! = RNTesterIntegrationTests : : IntegrationTestHarness ) & ( FullyQualifiedName ! = RNTesterIntegrationTests : : AsyncStorage ) & ( FullyQualifiedName ! ~ WebSocketModule_ ) ' <nl> + Desktop . IntegrationTests . Filter : ' ( FullyQualifiedName ! ~ WebSocketJSExecutorIntegrationTest ) & ( FullyQualifiedName ! = RNTesterIntegrationTests : : IntegrationTestHarness ) & ( FullyQualifiedName ! = RNTesterIntegrationTests : : AsyncStorage ) & ( FullyQualifiedName ! ~ WebSocketModule_ ) & ( FullyQualifiedName ! = WebSocketResourcePerformanceTest : : ProcessThreadsPerResource ) ' <nl> <nl> steps : <nl> - checkout : self <nl> jobs : <nl> filePath : $ ( Build . SourcesDirectory ) \ vnext \ Scripts \ Tfs \ Start - TestServers . ps1 <nl> arguments : - SourcesDirectory $ ( Build . SourcesDirectory ) \ vnext - Preload - SleepSeconds 120 <nl> <nl> + - task : PowerShell @ 2 <nl> + displayName : Check the metro bundle server <nl> + inputs : <nl> + targetType : ' inline ' <nl> + script : Invoke - WebRequest - Uri " http : / / localhost : 8081 / IntegrationTests / IntegrationTestsApp . bundle ? platform = windesktop & dev = true " <nl> + <nl> - task : VSTest @ 2 <nl> displayName : Run Desktop Integration Tests <nl> inputs : <nl> jobs : <nl> collectDumpOn : onAbortOnly <nl> vsTestVersion : latest <nl> otherConsoleOptions : ' / blame - - RunConfiguration . TestSessionTimeout = 300000 ' <nl> + # Suspected debug assert in TestRunner hanging tests randomly . Run only on Release for now . <nl> condition : and ( succeeded ( ) , ne ( variables [ ' BuildConfiguration ' ] , ' Debug ' ) ) <nl> <nl> - - task : PowerShell @ 2 <nl> - displayName : Check the metro bundle server <nl> - inputs : <nl> - targetType : ' inline ' <nl> - script : Invoke - WebRequest - Uri " http : / / localhost : 8081 / IntegrationTests / IntegrationTestsApp . bundle ? platform = windesktop & dev = true " <nl> - condition : failed ( ) <nl> - <nl> - template : templates / stop - packagers . yml <nl> <nl> - template : templates / publish - build - artifacts - for - nuget . yml <nl>
Re - enable Desktop integration tests in Debug ( )
microsoft/react-native-windows
dfeae1324ac71fa62bcbcc8fa38351445fd68aa8
2020-06-19T12:45:09Z
mmm a / xbmc / android / jni / jutils . cpp <nl> ppp b / xbmc / android / jni / jutils . cpp <nl> std : : string jcast_helper < std : : string , jstring > : : cast ( jstring const & v ) <nl> jhstring jcast_helper < jhstring , std : : string > : : cast ( const std : : string & s ) <nl> { <nl> JNIEnv * env = xbmc_jnienv ( ) ; <nl> - jstring obj = env - > NewStringUTF ( s . c_str ( ) ) ; <nl> - return jhstring ( obj ) ; <nl> + jstring ret = NULL ; <nl> + if ( ! s . empty ( ) ) <nl> + { <nl> + ret = env - > NewStringUTF ( s . c_str ( ) ) ; <nl> + } <nl> + return jhstring ( ret ) ; <nl> } <nl> <nl> jhobjectArray jcast_helper < jhobjectArray , std : : vector < std : : string > > : : cast ( const std : : vector < std : : string > & s ) <nl>
jni : pass null strings as null objects , as java expects them
xbmc/xbmc
b7af6b78d3b857c4e93c474aac7c446d9f666bd8
2013-06-07T21:47:51Z
deleted file mode 100644 <nl> index 2e03e7965151 . . 000000000000 <nl> mmm a / aten / src / ATen / core / typeid . h <nl> ppp / dev / null <nl> <nl> - # pragma once <nl> - <nl> - # include < atomic > <nl> - # include < cassert > <nl> - # include < cstdlib > <nl> - # include < iostream > <nl> - # include < memory > <nl> - # include < mutex > <nl> - # include < type_traits > <nl> - # include < unordered_map > <nl> - # include < unordered_set > <nl> - # include < vector > <nl> - # ifdef __GXX_RTTI <nl> - # include < typeinfo > <nl> - # endif <nl> - <nl> - # include < exception > <nl> - <nl> - # include " ATen / core / Backtrace . h " <nl> - # include " ATen / core / Macros . h " <nl> - # include " ATen / core / Half . h " <nl> - # include " ATen / core / IdWrapper . h " <nl> - <nl> - / / TODO : This file is still in the caffe2 namespace , despite living <nl> - / / in the ATen directory . This is because the macro CAFFE_DECLARE_KNOWN_TYPE <nl> - / / defines a template specialization , which relies on the namespace of TypeMeta <nl> - / / matching the namespace where the macro is called . This requires us to <nl> - / / fix all of the call - sites , which I want to do later . So the namespace <nl> - / / is not fixed at the moment . <nl> - <nl> - namespace caffe2 { <nl> - class TypeIdentifier ; <nl> - } <nl> - <nl> - std : : ostream & operator < < ( std : : ostream & stream , caffe2 : : TypeIdentifier typeId ) ; <nl> - <nl> - namespace caffe2 { <nl> - <nl> - class TypeMeta ; <nl> - <nl> - / * * <nl> - * A type id is a unique id for a given C + + type . <nl> - * You need to register your types using CAFFE_KNOWN_TYPE ( MyType ) to be able to <nl> - * use TypeIdentifier with custom types . This is for example used to store the <nl> - * dtype of tensors . <nl> - * / <nl> - class TypeIdentifier final : public at : : IdWrapper < TypeIdentifier , uint16_t > { <nl> - public : <nl> - static TypeIdentifier createTypeId ( ) ; <nl> - <nl> - friend std : : ostream & : : operator < < ( <nl> - std : : ostream & stream , <nl> - TypeIdentifier typeId ) ; <nl> - friend bool operator < ( TypeIdentifier lhs , TypeIdentifier rhs ) ; <nl> - <nl> - / / This is 8 , because 0 is uint8_t ( due to ScalarType BC constraint ) <nl> - static constexpr TypeIdentifier uninitialized ( ) { <nl> - return TypeIdentifier ( 8 ) ; <nl> - } <nl> - <nl> - private : <nl> - constexpr explicit TypeIdentifier ( uint16_t id ) : IdWrapper ( id ) { } <nl> - friend class TypeMeta ; <nl> - } ; <nl> - <nl> - / / Allow usage in std : : map / std : : set <nl> - / / TODO Disallow this and rather use std : : unordered_map / set everywhere <nl> - inline bool operator < ( TypeIdentifier lhs , TypeIdentifier rhs ) { <nl> - return lhs . underlyingId ( ) < rhs . underlyingId ( ) ; <nl> - } <nl> - <nl> - } / / namespace caffe2 <nl> - <nl> - AT_DEFINE_HASH_FOR_IDWRAPPER ( caffe2 : : TypeIdentifier ) <nl> - <nl> - inline std : : ostream & operator < < ( <nl> - std : : ostream & stream , <nl> - caffe2 : : TypeIdentifier typeId ) { <nl> - return stream < < typeId . underlyingId ( ) ; <nl> - } <nl> - <nl> - namespace caffe2 { <nl> - <nl> - std : : unordered_map < TypeIdentifier , std : : string > & gTypeNames ( ) ; <nl> - std : : unordered_set < std : : string > & gRegisteredTypeNames ( ) ; <nl> - <nl> - / / A utility function to return an exception std : : string by prepending its <nl> - / / exception type before its what ( ) content . <nl> - std : : string GetExceptionString ( const std : : exception & e ) ; <nl> - <nl> - std : : mutex & gTypeRegistrationMutex ( ) ; <nl> - <nl> - template < typename T > <nl> - struct TypeNameRegisterer { <nl> - TypeNameRegisterer ( TypeIdentifier id , const std : : string & literal_name ) { <nl> - std : : lock_guard < std : : mutex > guard ( gTypeRegistrationMutex ( ) ) ; <nl> - # ifdef __GXX_RTTI <nl> - ( void ) literal_name ; <nl> - <nl> - std : : string name = at : : demangle ( typeid ( T ) . name ( ) ) ; <nl> - / / If we are in RTTI mode , we will also use this opportunity to do sanity <nl> - / / check if there are duplicated ids registered for the same type . This <nl> - / / usually happens when one does not do RTLD_GLOBAL , which is often the <nl> - / / case in Python . The way we do the check is to make sure that there are <nl> - / / no duplicated names registered - this could be done by checking the <nl> - / / uniqueness of names . <nl> - if ( gRegisteredTypeNames ( ) . count ( name ) ) { <nl> - std : : cerr < < " Type name " < < name <nl> - < < " registered twice . This should " <nl> - " not happen . Do you have duplicated CAFFE_KNOWN_TYPE ? " <nl> - < < std : : endl ; <nl> - throw std : : runtime_error ( " TypeNameRegisterer error with type " + name ) ; <nl> - } <nl> - gRegisteredTypeNames ( ) . insert ( name ) ; <nl> - gTypeNames ( ) [ id ] = name ; <nl> - # else / / __GXX_RTTI <nl> - if ( literal_name . empty ( ) ) { <nl> - gTypeNames ( ) [ id ] = " ( RTTI disabled , cannot show name ) " ; <nl> - } else { <nl> - gTypeNames ( ) [ id ] = literal_name ; <nl> - } <nl> - # endif / / __GXX_RTTI <nl> - } <nl> - } ; <nl> - <nl> - / * * <nl> - * TypeMeta is a thin class that allows us to store the type of a container such <nl> - * as a blob , or the data type of a tensor , with a unique run - time id . It also <nl> - * stores some additional data such as the item size and the name of the type <nl> - * for run - time inspection . <nl> - * / <nl> - class TypeMeta { <nl> - public : <nl> - using PlacementNew = void ( void * , size_t ) ; <nl> - using TypedCopy = void ( const void * , void * , size_t ) ; <nl> - using TypedDestructor = void ( void * , size_t ) ; <nl> - / * * Create a dummy TypeMeta object . To create a TypeMeta object for a specific <nl> - * type , use TypeMeta : : Make < T > ( ) . <nl> - * / <nl> - TypeMeta ( ) noexcept <nl> - : id_ ( TypeIdentifier : : uninitialized ( ) ) , <nl> - itemsize_ ( 0 ) , <nl> - ctor_ ( nullptr ) , <nl> - copy_ ( nullptr ) , <nl> - dtor_ ( nullptr ) { } <nl> - <nl> - / * * <nl> - * Copy constructor . <nl> - * / <nl> - TypeMeta ( const TypeMeta & src ) noexcept = default ; <nl> - <nl> - / * * <nl> - * Assignment operator . <nl> - * / <nl> - TypeMeta & operator = ( const TypeMeta & src ) noexcept = default ; <nl> - <nl> - TypeMeta ( TypeMeta & & rhs ) noexcept = default ; <nl> - <nl> - private : <nl> - / / TypeMeta can only be created by Make , making sure that we do not <nl> - / / create incorrectly mixed up TypeMeta objects . <nl> - TypeMeta ( <nl> - TypeIdentifier i , <nl> - size_t s , <nl> - PlacementNew * ctor , <nl> - TypedCopy * copy , <nl> - TypedDestructor * dtor ) noexcept <nl> - : id_ ( i ) , itemsize_ ( s ) , ctor_ ( ctor ) , copy_ ( copy ) , dtor_ ( dtor ) { } <nl> - <nl> - / / Mechanism for throwing errors which can ' t be prevented at compile time <nl> - / / due to type erasure . E . g . somebody calling TypeMeta : : copy ( ) for <nl> - / / non - copiable type . Right now just throws exception but is implemented <nl> - / / in . cpp to manage dependencies <nl> - static void _ThrowRuntimeTypeLogicError ( const std : : string & msg ) ; <nl> - <nl> - public : <nl> - / * * <nl> - * Returns the type id . <nl> - * / <nl> - const TypeIdentifier & id ( ) const noexcept { <nl> - return id_ ; <nl> - } <nl> - / * * <nl> - * Returns the size of the item . <nl> - * / <nl> - const size_t & itemsize ( ) const noexcept { <nl> - return itemsize_ ; <nl> - } <nl> - / * * <nl> - * Returns the placement new function pointer for individual items . <nl> - * / <nl> - PlacementNew * ctor ( ) const noexcept { <nl> - return ctor_ ; <nl> - } <nl> - / * * <nl> - * Returns the typed copy function pointer for individual iterms . <nl> - * / <nl> - TypedCopy * copy ( ) const noexcept { <nl> - return copy_ ; <nl> - } <nl> - / * * <nl> - * Returns the destructor function pointer for individual items . <nl> - * / <nl> - TypedDestructor * dtor ( ) const noexcept { <nl> - return dtor_ ; <nl> - } <nl> - / * * <nl> - * Returns a printable name for the type . <nl> - * / <nl> - const char * name ( ) const noexcept { <nl> - auto it = gTypeNames ( ) . find ( id_ ) ; <nl> - assert ( it ! = gTypeNames ( ) . end ( ) ) ; <nl> - return it - > second . c_str ( ) ; <nl> - } <nl> - <nl> - friend bool operator = = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept ; <nl> - <nl> - template < typename T > <nl> - bool Match ( ) const { <nl> - return ( id_ = = Id < T > ( ) ) ; <nl> - } <nl> - <nl> - / / Below are static functions that can be called by passing a specific type . <nl> - <nl> - / * * <nl> - * Returns the unique id for the given type T . The id is unique for the type T <nl> - * in the sense that for any two different types , their id are different ; for <nl> - * the same type T , the id remains the same over different calls of the <nl> - * function . However , this is not guaranteed over different runs , as the id <nl> - * is generated during run - time . Do NOT serialize the id for storage . <nl> - * / <nl> - template < typename T > <nl> - AT_CORE_API static TypeIdentifier Id ( ) ; <nl> - <nl> - / * * <nl> - * Returns the item size of the type . This is equivalent to sizeof ( T ) . <nl> - * / <nl> - template < typename T > <nl> - static size_t ItemSize ( ) { <nl> - return sizeof ( T ) ; <nl> - } <nl> - <nl> - / * * <nl> - * Returns the registered printable name of the type . <nl> - * <nl> - * Works for only the ones registered with CAFFE_KNOWN_TYPE <nl> - * / <nl> - template < typename T > <nl> - static const char * TypeName ( ) { <nl> - auto it = gTypeNames ( ) . find ( Id < T > ( ) ) ; <nl> - assert ( it ! = gTypeNames ( ) . end ( ) ) ; <nl> - return it - > second . c_str ( ) ; <nl> - } <nl> - <nl> - / * * <nl> - * Placement new function for the type . <nl> - * / <nl> - template < typename T > <nl> - static void _Ctor ( void * ptr , size_t n ) { <nl> - T * typed_ptr = static_cast < T * > ( ptr ) ; <nl> - for ( size_t i = 0 ; i < n ; + + i ) { <nl> - new ( typed_ptr + i ) T ; <nl> - } <nl> - } <nl> - <nl> - template < typename T > <nl> - static void _CtorNotDefault ( void * / * ptr * / , size_t / * n * / ) { <nl> - _ThrowRuntimeTypeLogicError ( <nl> - " Type " + std : : string ( at : : demangle_type < T > ( ) ) + <nl> - " is not default - constructible . " ) ; <nl> - } <nl> - <nl> - template < <nl> - typename T , <nl> - typename std : : enable_if < std : : is_default_constructible < T > : : value > : : type * = <nl> - nullptr > <nl> - static inline PlacementNew * _PickCtor ( ) { <nl> - return _Ctor < T > ; <nl> - } <nl> - <nl> - template < <nl> - typename T , <nl> - typename std : : enable_if < ! std : : is_default_constructible < T > : : value > : : type * = <nl> - nullptr > <nl> - static inline PlacementNew * _PickCtor ( ) { <nl> - return _CtorNotDefault < T > ; <nl> - } <nl> - <nl> - / * * <nl> - * Typed copy function for classes . <nl> - * / <nl> - template < typename T > <nl> - static void _Copy ( const void * src , void * dst , size_t n ) { <nl> - const T * typed_src = static_cast < const T * > ( src ) ; <nl> - T * typed_dst = static_cast < T * > ( dst ) ; <nl> - for ( size_t i = 0 ; i < n ; + + i ) { <nl> - typed_dst [ i ] = typed_src [ i ] ; <nl> - } <nl> - } <nl> - <nl> - / * * <nl> - * A placeholder function for types that do not allow assignment . <nl> - * / <nl> - template < typename T > <nl> - static void _CopyNotAllowed ( <nl> - const void * / * src * / , <nl> - void * / * dst * / , <nl> - size_t / * n * / ) { <nl> - _ThrowRuntimeTypeLogicError ( <nl> - " Type " + std : : string ( at : : demangle_type < T > ( ) ) + <nl> - " does not allow assignment . " ) ; <nl> - } <nl> - <nl> - template < <nl> - typename T , <nl> - typename std : : enable_if < std : : is_copy_assignable < T > : : value > : : type * = <nl> - nullptr > <nl> - static inline TypedCopy * _PickCopy ( ) { <nl> - return _Copy < T > ; <nl> - } <nl> - <nl> - template < <nl> - typename T , <nl> - typename std : : enable_if < ! std : : is_copy_assignable < T > : : value > : : type * = <nl> - nullptr > <nl> - static inline TypedCopy * _PickCopy ( ) { <nl> - return _CopyNotAllowed < T > ; <nl> - } <nl> - <nl> - / * * <nl> - * Destructor for non - fundamental types . <nl> - * / <nl> - template < typename T > <nl> - static void _Dtor ( void * ptr , size_t n ) { <nl> - T * typed_ptr = static_cast < T * > ( ptr ) ; <nl> - for ( size_t i = 0 ; i < n ; + + i ) { <nl> - typed_ptr [ i ] . ~ T ( ) ; <nl> - } <nl> - } <nl> - <nl> - / * * <nl> - * Returns a TypeMeta object that corresponds to the typename T . <nl> - * / <nl> - template < typename T > <nl> - static typename std : : enable_if < <nl> - std : : is_fundamental < T > : : value | | std : : is_pointer < T > : : value , <nl> - TypeMeta > : : type <nl> - Make ( ) { <nl> - return TypeMeta ( Id < T > ( ) , ItemSize < T > ( ) , nullptr , nullptr , nullptr ) ; <nl> - } <nl> - <nl> - template < typename T > <nl> - static typename std : : enable_if < <nl> - ! ( std : : is_fundamental < T > : : value | | std : : is_pointer < T > : : value ) , <nl> - TypeMeta > : : type <nl> - Make ( ) { <nl> - return TypeMeta ( <nl> - Id < T > ( ) , ItemSize < T > ( ) , _PickCtor < T > ( ) , _PickCopy < T > ( ) , _Dtor < T > ) ; <nl> - } <nl> - <nl> - private : <nl> - TypeIdentifier id_ ; <nl> - size_t itemsize_ ; <nl> - PlacementNew * ctor_ ; <nl> - TypedCopy * copy_ ; <nl> - TypedDestructor * dtor_ ; <nl> - } ; <nl> - <nl> - inline bool operator = = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept { <nl> - return ( lhs . id_ = = rhs . id_ ) ; <nl> - } <nl> - inline bool operator ! = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept { <nl> - return ! operator = = ( lhs , rhs ) ; <nl> - } <nl> - <nl> - / * * <nl> - * Register unique id for a type so it can be used in TypeMeta context , e . g . be <nl> - * used as a type for Blob or for Tensor elements . <nl> - * <nl> - * CAFFE_KNOWN_TYPE does explicit instantiation of TypeMeta : : Id < T > template <nl> - * function and thus needs to be put in a single translation unit ( . cpp file ) <nl> - * for a given type T . Other translation units that use type T as a type of the <nl> - * caffe2 : : Blob or element type of caffe2 : : Tensor need to depend on the <nl> - * translation unit that contains CAFFE_KNOWN_TYPE declaration via regular <nl> - * linkage dependencies . <nl> - * <nl> - * NOTE : the macro needs to be invoked in : : caffe2 namespace <nl> - * / <nl> - / / Implementation note : in MSVC , we will need to prepend the AT_CORE_API <nl> - / / keyword in order to get things compiled properly . in Linux , gcc seems to <nl> - / / create attribute ignored error for explicit template instantiations , see <nl> - / / http : / / www . open - std . org / jtc1 / sc22 / wg21 / docs / papers / 2017 / p0537r0 . html <nl> - / / https : / / gcc . gnu . org / bugzilla / show_bug . cgi ? id = 51930 <nl> - / / and as a result , we define these two macros slightly differently . <nl> - <nl> - # ifdef _MSC_VER <nl> - # define CAFFE_KNOWN_TYPE ( T ) \ <nl> - template < > \ <nl> - AT_CORE_API TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> - static const TypeIdentifier type_id = TypeIdentifier : : createTypeId ( ) ; \ <nl> - static TypeNameRegisterer < T > registerer ( type_id , # T ) ; \ <nl> - return type_id ; \ <nl> - } <nl> - # else / / _MSC_VER <nl> - # define CAFFE_KNOWN_TYPE ( T ) \ <nl> - template < > \ <nl> - TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> - static const TypeIdentifier type_id = TypeIdentifier : : createTypeId ( ) ; \ <nl> - static TypeNameRegisterer < T > registerer ( type_id , # T ) ; \ <nl> - return type_id ; \ <nl> - } <nl> - # endif <nl> - <nl> - / * * <nl> - * CAFFE_DECLARE_KNOWN_TYPE and CAFFE_DEFINE_KNOWN_TYPE are used <nl> - * to preallocate ids for types that are queried very often so that they <nl> - * can be resolved at compile time . Please use CAFFE_KNOWN_TYPE ( ) instead <nl> - * for your own types to allocate dynamic ids for them . <nl> - * / <nl> - # ifdef _MSC_VER <nl> - # define CAFFE_DECLARE_KNOWN_TYPE ( PreallocatedId , T ) \ <nl> - template < > \ <nl> - inline AT_CORE_API TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> - return TypeIdentifier ( PreallocatedId ) ; \ <nl> - } <nl> - # else / / _MSC_VER <nl> - # define CAFFE_DECLARE_KNOWN_TYPE ( PreallocatedId , T ) \ <nl> - template < > \ <nl> - inline TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> - return TypeIdentifier ( PreallocatedId ) ; \ <nl> - } <nl> - # endif <nl> - <nl> - # define CONCAT_IMPL ( x , y ) x # # y <nl> - # define MACRO_CONCAT ( x , y ) CONCAT_IMPL ( x , y ) <nl> - <nl> - # define CAFFE_DEFINE_KNOWN_TYPE ( T ) \ <nl> - namespace { \ <nl> - TypeNameRegisterer < T > MACRO_CONCAT ( registerer , __COUNTER__ ) ( \ <nl> - TypeMeta : : Id < T > ( ) , \ <nl> - # T ) ; \ <nl> - } <nl> - <nl> - class Tensor ; <nl> - <nl> - / / Note : we have preallocated the numbers 0 - 8 so they line up exactly <nl> - / / with at : : ScalarType ' s numbering . All other numbers do not matter . <nl> - / / <nl> - / / Notably , the " uninitialized " type id is 8 , not 0 , for hysterical raisins . <nl> - <nl> - struct _CaffeHighestPreallocatedTypeId final { } ; <nl> - <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 0 , uint8_t ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 1 , int8_t ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 2 , int16_t ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 3 , int ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 4 , int64_t ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 5 , at : : Half ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 6 , float ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 7 , double ) ; <nl> - / / 8 = undefined type id <nl> - <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 9 , Tensor ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 10 , std : : string ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 11 , bool ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 12 , uint16_t ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 13 , char ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 14 , std : : unique_ptr < std : : mutex > ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 15 , std : : unique_ptr < std : : atomic < bool > > ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 16 , std : : vector < int32_t > ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 17 , std : : vector < int64_t > ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 18 , std : : vector < unsigned long > ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 19 , bool * ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 20 , char * ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 21 , int * ) ; <nl> - <nl> - # ifdef CAFFE2_UNIQUE_LONG_TYPEMETA <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 22 , long ) ; <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 23 , std : : vector < long > ) ; <nl> - # endif / / CAFFE2_UNIQUE_LONG_TYPEMETA <nl> - <nl> - CAFFE_DECLARE_KNOWN_TYPE ( 24 , _CaffeHighestPreallocatedTypeId ) ; <nl> - } / / namespace caffe2 <nl> mmm a / caffe2 / CMakeLists . txt <nl> ppp b / caffe2 / CMakeLists . txt <nl> if ( USE_CUDA ) <nl> target_link_libraries ( <nl> caffe2_gpu PUBLIC caffe2 $ { Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS } ) <nl> <nl> - # See Note [ Supporting both static and dynamic libraries on Window ] <nl> - # TODO : I ' m actually not sure why this is necessary , because caffe2_gpu <nl> - # should depend on caffe2 ( which itself would give us the necessary <nl> - # macro definition ) . <nl> - if ( MSVC AND NOT BUILD_SHARED_LIBS ) <nl> - target_compile_options ( caffe2_gpu PUBLIC " - DAT_CORE_STATIC_WINDOWS = 1 " ) <nl> - endif ( ) <nl> - <nl> # Set standard properties on the target <nl> aten_set_target_props ( caffe2_gpu ) <nl> <nl> mmm a / caffe2 / core / registry . h <nl> ppp b / caffe2 / core / registry . h <nl> class Registerer { <nl> key , \ <nl> RegistryName ( ) , \ <nl> Registerer # # RegistryName : : DefaultCreator < __VA_ARGS__ > , \ <nl> - at : : demangle_type < __VA_ARGS__ > ( ) ) ; \ <nl> + DemangleType < __VA_ARGS__ > ( ) ) ; \ <nl> } <nl> <nl> / / CAFFE_DECLARE_REGISTRY and CAFFE_DEFINE_REGISTRY are hard - wired to use string <nl> mmm a / caffe2 / core / tensor . cc <nl> ppp b / caffe2 / core / tensor . cc <nl> CAFFE2_DEFINE_int64 ( <nl> <nl> namespace caffe2 { <nl> <nl> - CAFFE_DEFINE_KNOWN_TYPE ( Tensor ) ; <nl> - <nl> TensorPrinter : : TensorPrinter ( <nl> const std : : string & tensor_name , <nl> const std : : string & file_name , <nl> similarity index 69 % <nl> rename from aten / src / ATen / core / typeid . cpp <nl> rename to caffe2 / core / typeid . cc <nl> mmm a / aten / src / ATen / core / typeid . cpp <nl> ppp b / caffe2 / core / typeid . cc <nl> <nl> - # include < ATen / core / typeid . h > <nl> - # include < ATen / core / Error . h > <nl> + # include " caffe2 / core / typeid . h " <nl> + # include " caffe2 / core / logging . h " <nl> + # include " caffe2 / core / scope_guard . h " <nl> + # include " caffe2 / core / tensor . h " <nl> <nl> # include < atomic > <nl> <nl> std : : mutex & gTypeRegistrationMutex ( ) { <nl> return g_type_registration_mutex ; <nl> } <nl> <nl> + # if defined ( _MSC_VER ) <nl> + / / Windows does not have cxxabi . h , so we will simply return the original . <nl> + string Demangle ( const char * name ) { <nl> + return string ( name ) ; <nl> + } <nl> + # else <nl> + string Demangle ( const char * name ) { <nl> + int status = 0 ; <nl> + auto demangled = : : abi : : __cxa_demangle ( name , nullptr , nullptr , & status ) ; <nl> + if ( demangled ) { <nl> + auto guard = caffe2 : : MakeGuard ( [ demangled ] ( ) { free ( demangled ) ; } ) ; <nl> + return string ( demangled ) ; <nl> + } <nl> + return name ; <nl> + } <nl> + # endif <nl> + <nl> string GetExceptionString ( const std : : exception & e ) { <nl> # ifdef __GXX_RTTI <nl> - return at : : demangle ( typeid ( e ) . name ( ) ) + " : " + e . what ( ) ; <nl> + return Demangle ( typeid ( e ) . name ( ) ) + " : " + e . what ( ) ; <nl> # else <nl> return string ( " Exception ( no RTTI available ) : " ) + e . what ( ) ; <nl> # endif / / __GXX_RTTI <nl> string GetExceptionString ( const std : : exception & e ) { <nl> void TypeMeta : : _ThrowRuntimeTypeLogicError ( const std : : string & msg ) { <nl> / / In earlier versions it used to be std : : abort ( ) but it ' s a bit hard - core <nl> / / for a library <nl> - AT_ERROR ( msg ) ; <nl> + CAFFE_THROW ( msg ) ; <nl> } <nl> <nl> TypeIdentifier TypeIdentifier : : createTypeId ( ) { <nl> static std : : atomic < TypeIdentifier : : underlying_type > counter ( <nl> TypeMeta : : Id < _CaffeHighestPreallocatedTypeId > ( ) . underlyingId ( ) ) ; <nl> const TypeIdentifier : : underlying_type new_value = + + counter ; <nl> - if ( new_value = = <nl> - std : : numeric_limits < TypeIdentifier : : underlying_type > : : max ( ) ) { <nl> - throw std : : logic_error ( <nl> - " Ran out of available type ids . If you need more than 2 ^ 16 CAFFE_KNOWN_TYPEs , we need to increase TypeIdentifier to use more than 16 bit . " ) ; <nl> + if ( new_value = = std : : numeric_limits < TypeIdentifier : : underlying_type > : : max ( ) ) { <nl> + throw std : : logic_error ( " Ran out of available type ids . If you need more than 2 ^ 16 CAFFE_KNOWN_TYPEs , we need to increase TypeIdentifier to use more than 16 bit . " ) ; <nl> } <nl> return TypeIdentifier ( new_value ) ; <nl> } <nl> <nl> + CAFFE_DEFINE_KNOWN_TYPE ( Tensor ) ; <nl> CAFFE_DEFINE_KNOWN_TYPE ( float ) ; <nl> CAFFE_DEFINE_KNOWN_TYPE ( int ) ; <nl> CAFFE_DEFINE_KNOWN_TYPE ( std : : string ) ; <nl> namespace { <nl> / / for unintializied blob . You should not use this struct yourself - it is <nl> / / intended to be only instantiated once here . <nl> struct UninitializedTypeNameRegisterer { <nl> - UninitializedTypeNameRegisterer ( ) { <nl> - gTypeNames ( ) [ TypeIdentifier : : uninitialized ( ) ] = " nullptr ( uninitialized ) " ; <nl> - } <nl> + UninitializedTypeNameRegisterer ( ) { <nl> + gTypeNames ( ) [ TypeIdentifier : : uninitialized ( ) ] = " nullptr ( uninitialized ) " ; <nl> + } <nl> } ; <nl> static UninitializedTypeNameRegisterer g_uninitialized_type_name_registerer ; <nl> <nl> mmm a / caffe2 / core / typeid . h <nl> ppp b / caffe2 / core / typeid . h <nl> <nl> # pragma once <nl> <nl> - / / If I omit this header , the Windows build fails . The error message <nl> - / / was sufficiently bad that I couldn ' t figure out which downstream file <nl> - / / was missing the include of common . h . So keep it here for BC . <nl> - # include < caffe2 / core / common . h > <nl> - # include < ATen / core / typeid . h > <nl> + # include < atomic > <nl> + # include < cassert > <nl> + # include < cstdlib > <nl> + # include < iostream > <nl> + # include < mutex > <nl> + # include < type_traits > <nl> + # include < unordered_map > <nl> + # include < unordered_set > <nl> + # ifdef __GXX_RTTI <nl> + # include < typeinfo > <nl> + # endif <nl> + <nl> + # include < exception > <nl> + <nl> + # include " ATen / core / Half . h " <nl> + # include " caffe2 / core / common . h " <nl> + # include " ATen / core / IdWrapper . h " <nl> + <nl> + namespace caffe2 { <nl> + class TypeIdentifier ; <nl> + } <nl> + <nl> + std : : ostream & operator < < ( std : : ostream & stream , caffe2 : : TypeIdentifier typeId ) ; <nl> + <nl> + namespace caffe2 { <nl> + <nl> + class TypeMeta ; <nl> + <nl> + / * * <nl> + * A type id is a unique id for a given C + + type . <nl> + * You need to register your types using CAFFE_KNOWN_TYPE ( MyType ) to be able to use TypeIdentifier with custom types . <nl> + * This is for example used to store the dtype of tensors . <nl> + * / <nl> + class TypeIdentifier final : public at : : IdWrapper < TypeIdentifier , uint16_t > { <nl> + public : <nl> + static TypeIdentifier createTypeId ( ) ; <nl> + <nl> + friend std : : ostream & : : operator < < ( std : : ostream & stream , TypeIdentifier typeId ) ; <nl> + friend bool operator < ( TypeIdentifier lhs , TypeIdentifier rhs ) ; <nl> + <nl> + / / This is 8 , because 0 is uint8_t ( due to ScalarType BC constraint ) <nl> + static constexpr TypeIdentifier uninitialized ( ) { <nl> + return TypeIdentifier ( 8 ) ; <nl> + } <nl> + <nl> + private : <nl> + constexpr explicit TypeIdentifier ( uint16_t id ) : IdWrapper ( id ) { } <nl> + friend class TypeMeta ; <nl> + } ; <nl> + <nl> + / / Allow usage in std : : map / std : : set <nl> + / / TODO Disallow this and rather use std : : unordered_map / set everywhere <nl> + inline bool operator < ( TypeIdentifier lhs , TypeIdentifier rhs ) { <nl> + return lhs . underlyingId ( ) < rhs . underlyingId ( ) ; <nl> + } <nl> + <nl> + } <nl> + <nl> + AT_DEFINE_HASH_FOR_IDWRAPPER ( caffe2 : : TypeIdentifier ) <nl> + <nl> + inline std : : ostream & operator < < ( std : : ostream & stream , caffe2 : : TypeIdentifier typeId ) { <nl> + return stream < < typeId . underlyingId ( ) ; <nl> + } <nl> + <nl> + namespace caffe2 { <nl> + <nl> + std : : unordered_map < TypeIdentifier , std : : string > & gTypeNames ( ) ; <nl> + std : : unordered_set < std : : string > & gRegisteredTypeNames ( ) ; <nl> + <nl> + / / A utility function to demangle a function name . <nl> + std : : string Demangle ( const char * name ) ; <nl> + <nl> + / * * <nl> + * Returns the printable name of the type . <nl> + * <nl> + * Works for all types , not only the ones registered with CAFFE_KNOWN_TYPE <nl> + * / <nl> + template < typename T > <nl> + static const char * DemangleType ( ) { <nl> + # ifdef __GXX_RTTI <nl> + static const std : : string name = Demangle ( typeid ( T ) . name ( ) ) ; <nl> + return name . c_str ( ) ; <nl> + # else / / __GXX_RTTI <nl> + return " ( RTTI disabled , cannot show name ) " ; <nl> + # endif / / __GXX_RTTI <nl> + } <nl> + <nl> + / / A utility function to return an exception std : : string by prepending its exception <nl> + / / type before its what ( ) content . <nl> + std : : string GetExceptionString ( const std : : exception & e ) ; <nl> + <nl> + std : : mutex & gTypeRegistrationMutex ( ) ; <nl> + <nl> + template < typename T > <nl> + struct TypeNameRegisterer { <nl> + TypeNameRegisterer ( TypeIdentifier id , const std : : string & literal_name ) { <nl> + std : : lock_guard < std : : mutex > guard ( gTypeRegistrationMutex ( ) ) ; <nl> + # ifdef __GXX_RTTI <nl> + ( void ) literal_name ; <nl> + <nl> + std : : string name = Demangle ( typeid ( T ) . name ( ) ) ; <nl> + / / If we are in RTTI mode , we will also use this opportunity to do sanity <nl> + / / check if there are duplicated ids registered for the same type . This <nl> + / / usually happens when one does not do RTLD_GLOBAL , which is often the <nl> + / / case in Python . The way we do the check is to make sure that there are <nl> + / / no duplicated names registered - this could be done by checking the <nl> + / / uniqueness of names . <nl> + if ( gRegisteredTypeNames ( ) . count ( name ) ) { <nl> + std : : cerr < < " Type name " < < name <nl> + < < " registered twice . This should " <nl> + " not happen . Do you have duplicated CAFFE_KNOWN_TYPE ? " <nl> + < < std : : endl ; <nl> + throw std : : runtime_error ( " TypeNameRegisterer error with type " + name ) ; <nl> + } <nl> + gRegisteredTypeNames ( ) . insert ( name ) ; <nl> + gTypeNames ( ) [ id ] = name ; <nl> + # else / / __GXX_RTTI <nl> + if ( literal_name . empty ( ) ) { <nl> + gTypeNames ( ) [ id ] = " ( RTTI disabled , cannot show name ) " ; <nl> + } else { <nl> + gTypeNames ( ) [ id ] = literal_name ; <nl> + } <nl> + # endif / / __GXX_RTTI <nl> + } <nl> + } ; <nl> + <nl> + / * * <nl> + * TypeMeta is a thin class that allows us to store the type of a container such <nl> + * as a blob , or the data type of a tensor , with a unique run - time id . It also <nl> + * stores some additional data such as the item size and the name of the type <nl> + * for run - time inspection . <nl> + * / <nl> + class TypeMeta { <nl> + public : <nl> + using PlacementNew = void ( void * , size_t ) ; <nl> + using TypedCopy = void ( const void * , void * , size_t ) ; <nl> + using TypedDestructor = void ( void * , size_t ) ; <nl> + / * * Create a dummy TypeMeta object . To create a TypeMeta object for a specific <nl> + * type , use TypeMeta : : Make < T > ( ) . <nl> + * / <nl> + TypeMeta ( ) noexcept <nl> + : id_ ( TypeIdentifier : : uninitialized ( ) ) , itemsize_ ( 0 ) , ctor_ ( nullptr ) , copy_ ( nullptr ) , dtor_ ( nullptr ) { } <nl> + <nl> + / * * <nl> + * Copy constructor . <nl> + * / <nl> + TypeMeta ( const TypeMeta & src ) noexcept = default ; <nl> + <nl> + / * * <nl> + * Assignment operator . <nl> + * / <nl> + TypeMeta & operator = ( const TypeMeta & src ) noexcept = default ; <nl> + <nl> + TypeMeta ( TypeMeta & & rhs ) noexcept = default ; <nl> + <nl> + private : <nl> + / / TypeMeta can only be created by Make , making sure that we do not <nl> + / / create incorrectly mixed up TypeMeta objects . <nl> + TypeMeta ( <nl> + TypeIdentifier i , <nl> + size_t s , <nl> + PlacementNew * ctor , <nl> + TypedCopy * copy , <nl> + TypedDestructor * dtor ) noexcept <nl> + : id_ ( i ) , itemsize_ ( s ) , ctor_ ( ctor ) , copy_ ( copy ) , dtor_ ( dtor ) { } <nl> + <nl> + / / Mechanism for throwing errors which can ' t be prevented at compile time <nl> + / / due to type erasure . E . g . somebody calling TypeMeta : : copy ( ) for <nl> + / / non - copiable type . Right now just throws exception but is implemented <nl> + / / in . cpp to manage dependencies <nl> + static void _ThrowRuntimeTypeLogicError ( const std : : string & msg ) ; <nl> + <nl> + public : <nl> + / * * <nl> + * Returns the type id . <nl> + * / <nl> + const TypeIdentifier & id ( ) const noexcept { <nl> + return id_ ; <nl> + } <nl> + / * * <nl> + * Returns the size of the item . <nl> + * / <nl> + const size_t & itemsize ( ) const noexcept { <nl> + return itemsize_ ; <nl> + } <nl> + / * * <nl> + * Returns the placement new function pointer for individual items . <nl> + * / <nl> + PlacementNew * ctor ( ) const noexcept { <nl> + return ctor_ ; <nl> + } <nl> + / * * <nl> + * Returns the typed copy function pointer for individual iterms . <nl> + * / <nl> + TypedCopy * copy ( ) const noexcept { <nl> + return copy_ ; <nl> + } <nl> + / * * <nl> + * Returns the destructor function pointer for individual items . <nl> + * / <nl> + TypedDestructor * dtor ( ) const noexcept { <nl> + return dtor_ ; <nl> + } <nl> + / * * <nl> + * Returns a printable name for the type . <nl> + * / <nl> + const char * name ( ) const noexcept { <nl> + auto it = gTypeNames ( ) . find ( id_ ) ; <nl> + assert ( it ! = gTypeNames ( ) . end ( ) ) ; <nl> + return it - > second . c_str ( ) ; <nl> + } <nl> + <nl> + friend bool operator = = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept ; <nl> + <nl> + template < typename T > <nl> + bool Match ( ) const { <nl> + return ( id_ = = Id < T > ( ) ) ; <nl> + } <nl> + <nl> + / / Below are static functions that can be called by passing a specific type . <nl> + <nl> + / * * <nl> + * Returns the unique id for the given type T . The id is unique for the type T <nl> + * in the sense that for any two different types , their id are different ; for <nl> + * the same type T , the id remains the same over different calls of the <nl> + * function . However , this is not guaranteed over different runs , as the id <nl> + * is generated during run - time . Do NOT serialize the id for storage . <nl> + * / <nl> + template < typename T > <nl> + CAFFE2_API static TypeIdentifier Id ( ) ; <nl> + <nl> + / * * <nl> + * Returns the item size of the type . This is equivalent to sizeof ( T ) . <nl> + * / <nl> + template < typename T > <nl> + static size_t ItemSize ( ) { <nl> + return sizeof ( T ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Returns the registered printable name of the type . <nl> + * <nl> + * Works for only the ones registered with CAFFE_KNOWN_TYPE <nl> + * / <nl> + template < typename T > <nl> + static const char * TypeName ( ) { <nl> + auto it = gTypeNames ( ) . find ( Id < T > ( ) ) ; <nl> + assert ( it ! = gTypeNames ( ) . end ( ) ) ; <nl> + return it - > second . c_str ( ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Placement new function for the type . <nl> + * / <nl> + template < typename T > <nl> + static void _Ctor ( void * ptr , size_t n ) { <nl> + T * typed_ptr = static_cast < T * > ( ptr ) ; <nl> + for ( size_t i = 0 ; i < n ; + + i ) { <nl> + new ( typed_ptr + i ) T ; <nl> + } <nl> + } <nl> + <nl> + template < typename T > <nl> + static void _CtorNotDefault ( void * / * ptr * / , size_t / * n * / ) { <nl> + _ThrowRuntimeTypeLogicError ( <nl> + " Type " + std : : string ( DemangleType < T > ( ) ) + <nl> + " is not default - constructible . " ) ; <nl> + } <nl> + <nl> + template < <nl> + typename T , <nl> + typename std : : enable_if < std : : is_default_constructible < T > : : value > : : type * = <nl> + nullptr > <nl> + static inline PlacementNew * _PickCtor ( ) { <nl> + return _Ctor < T > ; <nl> + } <nl> + <nl> + template < <nl> + typename T , <nl> + typename std : : enable_if < ! std : : is_default_constructible < T > : : value > : : type * = <nl> + nullptr > <nl> + static inline PlacementNew * _PickCtor ( ) { <nl> + return _CtorNotDefault < T > ; <nl> + } <nl> + <nl> + / * * <nl> + * Typed copy function for classes . <nl> + * / <nl> + template < typename T > <nl> + static void _Copy ( const void * src , void * dst , size_t n ) { <nl> + const T * typed_src = static_cast < const T * > ( src ) ; <nl> + T * typed_dst = static_cast < T * > ( dst ) ; <nl> + for ( size_t i = 0 ; i < n ; + + i ) { <nl> + typed_dst [ i ] = typed_src [ i ] ; <nl> + } <nl> + } <nl> + <nl> + / * * <nl> + * A placeholder function for types that do not allow assignment . <nl> + * / <nl> + template < typename T > <nl> + static void <nl> + _CopyNotAllowed ( const void * / * src * / , void * / * dst * / , size_t / * n * / ) { <nl> + _ThrowRuntimeTypeLogicError ( <nl> + " Type " + std : : string ( DemangleType < T > ( ) ) + <nl> + " does not allow assignment . " ) ; <nl> + } <nl> + <nl> + template < <nl> + typename T , <nl> + typename std : : enable_if < std : : is_copy_assignable < T > : : value > : : type * = <nl> + nullptr > <nl> + static inline TypedCopy * _PickCopy ( ) { <nl> + return _Copy < T > ; <nl> + } <nl> + <nl> + template < <nl> + typename T , <nl> + typename std : : enable_if < ! std : : is_copy_assignable < T > : : value > : : type * = <nl> + nullptr > <nl> + static inline TypedCopy * _PickCopy ( ) { <nl> + return _CopyNotAllowed < T > ; <nl> + } <nl> + <nl> + / * * <nl> + * Destructor for non - fundamental types . <nl> + * / <nl> + template < typename T > <nl> + static void _Dtor ( void * ptr , size_t n ) { <nl> + T * typed_ptr = static_cast < T * > ( ptr ) ; <nl> + for ( size_t i = 0 ; i < n ; + + i ) { <nl> + typed_ptr [ i ] . ~ T ( ) ; <nl> + } <nl> + } <nl> + <nl> + / * * <nl> + * Returns a TypeMeta object that corresponds to the typename T . <nl> + * / <nl> + template < typename T > <nl> + static typename std : : enable_if < <nl> + std : : is_fundamental < T > : : value | | std : : is_pointer < T > : : value , <nl> + TypeMeta > : : type <nl> + Make ( ) { <nl> + return TypeMeta ( Id < T > ( ) , ItemSize < T > ( ) , nullptr , nullptr , nullptr ) ; <nl> + } <nl> + <nl> + template < typename T > <nl> + static typename std : : enable_if < <nl> + ! ( std : : is_fundamental < T > : : value | | std : : is_pointer < T > : : value ) , <nl> + TypeMeta > : : type <nl> + Make ( ) { <nl> + return TypeMeta ( <nl> + Id < T > ( ) , ItemSize < T > ( ) , _PickCtor < T > ( ) , _PickCopy < T > ( ) , _Dtor < T > ) ; <nl> + } <nl> + <nl> + private : <nl> + TypeIdentifier id_ ; <nl> + size_t itemsize_ ; <nl> + PlacementNew * ctor_ ; <nl> + TypedCopy * copy_ ; <nl> + TypedDestructor * dtor_ ; <nl> + } ; <nl> + <nl> + inline bool operator = = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept { <nl> + return ( lhs . id_ = = rhs . id_ ) ; <nl> + } <nl> + inline bool operator ! = ( const TypeMeta & lhs , const TypeMeta & rhs ) noexcept { <nl> + return ! operator = = ( lhs , rhs ) ; <nl> + } <nl> + <nl> + / * * <nl> + * Register unique id for a type so it can be used in TypeMeta context , e . g . be <nl> + * used as a type for Blob or for Tensor elements . <nl> + * <nl> + * CAFFE_KNOWN_TYPE does explicit instantiation of TypeMeta : : Id < T > template <nl> + * function and thus needs to be put in a single translation unit ( . cpp file ) <nl> + * for a given type T . Other translation units that use type T as a type of the <nl> + * caffe2 : : Blob or element type of caffe2 : : Tensor need to depend on the <nl> + * translation unit that contains CAFFE_KNOWN_TYPE declaration via regular <nl> + * linkage dependencies . <nl> + * <nl> + * NOTE : the macro needs to be invoked in : : caffe2 namespace <nl> + * / <nl> + / / Implementation note : in MSVC , we will need to prepend the CAFFE2_EXPORT <nl> + / / keyword in order to get things compiled properly . in Linux , gcc seems to <nl> + / / create attribute ignored error for explicit template instantiations , see <nl> + / / http : / / www . open - std . org / jtc1 / sc22 / wg21 / docs / papers / 2017 / p0537r0 . html <nl> + / / https : / / gcc . gnu . org / bugzilla / show_bug . cgi ? id = 51930 <nl> + / / and as a result , we define these two macros slightly differently . <nl> + <nl> + # ifdef _MSC_VER <nl> + # define CAFFE_KNOWN_TYPE ( T ) \ <nl> + template < > \ <nl> + CAFFE2_EXPORT TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> + static const TypeIdentifier type_id = TypeIdentifier : : createTypeId ( ) ; \ <nl> + static TypeNameRegisterer < T > registerer ( type_id , # T ) ; \ <nl> + return type_id ; \ <nl> + } <nl> + # else / / _MSC_VER <nl> + # define CAFFE_KNOWN_TYPE ( T ) \ <nl> + template < > \ <nl> + TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> + static const TypeIdentifier type_id = TypeIdentifier : : createTypeId ( ) ; \ <nl> + static TypeNameRegisterer < T > registerer ( type_id , # T ) ; \ <nl> + return type_id ; \ <nl> + } <nl> + # endif <nl> + <nl> + / * * <nl> + * CAFFE_DECLARE_KNOWN_TYPE and CAFFE_DEFINE_KNOWN_TYPE are used <nl> + * to preallocate ids for types that are queried very often so that they <nl> + * can be resolved at compile time . Please use CAFFE_KNOWN_TYPE ( ) instead <nl> + * for your own types to allocate dynamic ids for them . <nl> + * / <nl> + # ifdef _MSC_VER <nl> + # define CAFFE_DECLARE_KNOWN_TYPE ( PreallocatedId , T ) \ <nl> + template < > \ <nl> + inline CAFFE2_EXPORT TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> + return TypeIdentifier ( PreallocatedId ) ; \ <nl> + } <nl> + # else / / _MSC_VER <nl> + # define CAFFE_DECLARE_KNOWN_TYPE ( PreallocatedId , T ) \ <nl> + template < > \ <nl> + inline TypeIdentifier TypeMeta : : Id < T > ( ) { \ <nl> + return TypeIdentifier ( PreallocatedId ) ; \ <nl> + } <nl> + # endif <nl> + <nl> + # define CONCAT_IMPL ( x , y ) x # # y <nl> + # define MACRO_CONCAT ( x , y ) CONCAT_IMPL ( x , y ) <nl> + <nl> + # define CAFFE_DEFINE_KNOWN_TYPE ( T ) \ <nl> + namespace { \ <nl> + TypeNameRegisterer < T > MACRO_CONCAT ( registerer , __COUNTER__ ) ( \ <nl> + TypeMeta : : Id < T > ( ) , \ <nl> + # T ) ; \ <nl> + } <nl> + <nl> + class Tensor ; <nl> + <nl> + / / Note : we have preallocated the numbers 0 - 8 so they line up exactly <nl> + / / with at : : ScalarType ' s numbering . All other numbers do not matter . <nl> + / / <nl> + / / Notably , the " uninitialized " type id is 8 , not 0 , for hysterical raisins . <nl> + <nl> + struct _CaffeHighestPreallocatedTypeId final { } ; <nl> + <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 0 , uint8_t ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 1 , int8_t ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 2 , int16_t ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 3 , int ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 4 , int64_t ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 5 , at : : Half ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 6 , float ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 7 , double ) ; <nl> + / / 8 = undefined type id <nl> + <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 9 , Tensor ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 10 , std : : string ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 11 , bool ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 12 , uint16_t ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 13 , char ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 14 , std : : unique_ptr < std : : mutex > ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 15 , std : : unique_ptr < std : : atomic < bool > > ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 16 , std : : vector < int32_t > ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 17 , std : : vector < int64_t > ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 18 , std : : vector < unsigned long > ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 19 , bool * ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 20 , char * ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 21 , int * ) ; <nl> + <nl> + # ifdef CAFFE2_UNIQUE_LONG_TYPEMETA <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 22 , long ) ; <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 23 , std : : vector < long > ) ; <nl> + # endif / / CAFFE2_UNIQUE_LONG_TYPEMETA <nl> + <nl> + CAFFE_DECLARE_KNOWN_TYPE ( 24 , _CaffeHighestPreallocatedTypeId ) ; <nl> + } <nl> mmm a / caffe2 / core / typeid_test . cc <nl> ppp b / caffe2 / core / typeid_test . cc <nl> TEST ( TypeMetaTest , Names ) { <nl> EXPECT_TRUE ( <nl> string ( string_meta . name ( ) ) ! = typeid ( string ) . name ( ) ) ; <nl> EXPECT_TRUE ( <nl> - string ( string_meta . name ( ) ) = = at : : demangle ( typeid ( string ) . name ( ) ) ) ; <nl> + string ( string_meta . name ( ) ) = = Demangle ( typeid ( string ) . name ( ) ) ) ; <nl> # endif / / __GXX_RTTI <nl> } <nl> <nl>
Back out " Move typeid . h to move to ATen / core "
pytorch/pytorch
1dbdc5a93da074ab3b928c23f6b377395a27bcbe
2018-08-11T04:39:25Z
mmm a / Telegram / SourceFiles / platform / win / main_window_win . cpp <nl> ppp b / Telegram / SourceFiles / platform / win / main_window_win . cpp <nl> class _PsShadowWindows { <nl> max_w = avail . width ( ) ; <nl> accumulate_max ( max_w , st : : windowMinWidth ) ; <nl> max_h = avail . height ( ) ; <nl> - accumulate_max ( max_h , st : : titleHeight + st : : windowMinHeight ) ; <nl> + accumulate_max ( max_h , st : : defaultWindowTitle . height + st : : windowMinHeight ) ; <nl> <nl> HINSTANCE appinst = ( HINSTANCE ) GetModuleHandle ( 0 ) ; <nl> HWND hwnd = _window ? _window - > psHwnd ( ) : nullptr ; <nl> mmm a / Telegram / SourceFiles / platform / win / window_title_win . cpp <nl> ppp b / Telegram / SourceFiles / platform / win / window_title_win . cpp <nl> For license and copyright information please follow this link : <nl> <nl> namespace Platform { <nl> <nl> - TitleWidget : : TitleWidget ( QWidget * parent ) : Window : : TitleWidget ( parent ) <nl> - , _minimize ( this , st : : titleButtonMinimize ) <nl> - , _maximizeRestore ( this , st : : titleButtonMaximize ) <nl> - , _close ( this , st : : titleButtonClose ) <nl> + TitleWidget : : TitleWidget ( QWidget * parent ) <nl> + : Window : : TitleWidget ( parent ) <nl> + , _st ( st : : defaultWindowTitle ) <nl> + , _minimize ( this , _st . minimize ) <nl> + , _maximizeRestore ( this , _st . maximize ) <nl> + , _close ( this , _st . close ) <nl> , _shadow ( this , st : : titleShadow ) <nl> , _maximizedState ( parent - > window ( ) - > windowState ( ) & Qt : : WindowMaximized ) { <nl> _minimize - > setClickedCallback ( [ this ] ( ) { <nl> TitleWidget : : TitleWidget ( QWidget * parent ) : Window : : TitleWidget ( parent ) <nl> _close - > setPointerCursor ( false ) ; <nl> <nl> setAttribute ( Qt : : WA_OpaquePaintEvent ) ; <nl> - resize ( width ( ) , st : : titleHeight ) ; <nl> + resize ( width ( ) , _st . height ) ; <nl> } <nl> <nl> void TitleWidget : : init ( ) { <nl> void TitleWidget : : paintEvent ( QPaintEvent * e ) { <nl> _activeState = active ; <nl> updateButtonsState ( ) ; <nl> } <nl> - Painter ( this ) . fillRect ( rect ( ) , active ? st : : titleBgActive : st : : titleBg ) ; <nl> + Painter ( this ) . fillRect ( rect ( ) , active ? _st . bgActive : _st . bg ) ; <nl> } <nl> <nl> void TitleWidget : : updateControlsPosition ( ) { <nl> void TitleWidget : : onWindowStateChanged ( Qt : : WindowState state ) { <nl> } <nl> <nl> void TitleWidget : : updateButtonsState ( ) { <nl> - _minimize - > setIconOverride ( _activeState ? & st : : titleButtonMinimizeIconActive : nullptr , _activeState ? & st : : titleButtonMinimizeIconActiveOver : nullptr ) ; <nl> + _minimize - > setIconOverride ( _activeState <nl> + ? & _st . minimizeIconActive <nl> + : nullptr , <nl> + _activeState <nl> + ? & _st . minimizeIconActiveOver <nl> + : nullptr ) ; <nl> if ( _maximizedState ) { <nl> - _maximizeRestore - > setIconOverride ( _activeState ? & st : : titleButtonRestoreIconActive : & st : : titleButtonRestoreIcon , _activeState ? & st : : titleButtonRestoreIconActiveOver : & st : : titleButtonRestoreIconOver ) ; <nl> + _maximizeRestore - > setIconOverride ( <nl> + _activeState <nl> + ? & _st . restoreIconActive : & _st . restoreIcon , <nl> + _activeState <nl> + ? & _st . restoreIconActiveOver <nl> + : & _st . restoreIconOver ) ; <nl> } else { <nl> - _maximizeRestore - > setIconOverride ( _activeState ? & st : : titleButtonMaximizeIconActive : nullptr , _activeState ? & st : : titleButtonMaximizeIconActiveOver : nullptr ) ; <nl> + _maximizeRestore - > setIconOverride ( _activeState <nl> + ? & _st . maximizeIconActive <nl> + : nullptr , <nl> + _activeState <nl> + ? & _st . maximizeIconActiveOver <nl> + : nullptr ) ; <nl> } <nl> - _close - > setIconOverride ( _activeState ? & st : : titleButtonCloseIconActive : nullptr , _activeState ? & st : : titleButtonCloseIconActiveOver : nullptr ) ; <nl> + _close - > setIconOverride ( _activeState <nl> + ? & _st . closeIconActive <nl> + : nullptr , <nl> + _activeState <nl> + ? & _st . closeIconActiveOver <nl> + : nullptr ) ; <nl> } <nl> <nl> Window : : HitTestResult TitleWidget : : hitTest ( const QPoint & p ) const { <nl> mmm a / Telegram / SourceFiles / platform / win / window_title_win . h <nl> ppp b / Telegram / SourceFiles / platform / win / window_title_win . h <nl> For license and copyright information please follow this link : <nl> # include " platform / platform_window_title . h " <nl> # include " base / object_ptr . h " <nl> <nl> + namespace style { <nl> + struct WindowTitle ; <nl> + } / / namespace style <nl> + <nl> namespace Ui { <nl> class IconButton ; <nl> class PlainShadow ; <nl> public slots : <nl> void updateButtonsState ( ) ; <nl> void updateControlsPosition ( ) ; <nl> <nl> + const style : : WindowTitle & _st ; <nl> object_ptr < Ui : : IconButton > _minimize ; <nl> object_ptr < Ui : : IconButton > _maximizeRestore ; <nl> object_ptr < Ui : : IconButton > _close ; <nl>
Fix build on Windows .
telegramdesktop/tdesktop
92d48a7846d306d8f8e5dff3bad306eafeb5baa6
2019-10-20T11:32:44Z
mmm a / src / compiler / ast - graph - builder . cc <nl> ppp b / src / compiler / ast - graph - builder . cc <nl> void AstGraphBuilder : : Visit ( Expression * expr ) { <nl> <nl> void AstGraphBuilder : : VisitVariableDeclaration ( VariableDeclaration * decl ) { <nl> Variable * variable = decl - > proxy ( ) - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals ( ) - > push_back ( variable - > name ( ) ) ; <nl> FeedbackVectorSlot slot = decl - > proxy ( ) - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void AstGraphBuilder : : VisitVariableDeclaration ( VariableDeclaration * decl ) { <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Node * value = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> - environment ( ) - > Bind ( variable , value ) ; <nl> - } <nl> - break ; <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Node * value = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> - const Operator * op = javascript ( ) - > StoreContext ( 0 , variable - > index ( ) ) ; <nl> - NewNode ( op , value ) ; <nl> - } <nl> break ; <nl> case VariableLocation : : LOOKUP : <nl> case VariableLocation : : MODULE : <nl> Node * AstGraphBuilder : : BuildArgumentsObject ( Variable * arguments ) { <nl> return object ; <nl> } <nl> <nl> - Node * AstGraphBuilder : : BuildHoleCheckThenThrow ( Node * value , Variable * variable , <nl> - Node * not_hole , <nl> - BailoutId bailout_id ) { <nl> - IfBuilder hole_check ( this ) ; <nl> - Node * the_hole = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> - Node * check = NewNode ( javascript ( ) - > StrictEqual ( CompareOperationHint : : kAny ) , <nl> - value , the_hole ) ; <nl> - hole_check . If ( check ) ; <nl> - hole_check . Then ( ) ; <nl> - Node * error = BuildThrowReferenceError ( variable , bailout_id ) ; <nl> - environment ( ) - > Push ( error ) ; <nl> - hole_check . Else ( ) ; <nl> - environment ( ) - > Push ( not_hole ) ; <nl> - hole_check . End ( ) ; <nl> - return environment ( ) - > Pop ( ) ; <nl> - } <nl> - <nl> - <nl> - Node * AstGraphBuilder : : BuildHoleCheckElseThrow ( Node * value , Variable * variable , <nl> - Node * for_hole , <nl> - BailoutId bailout_id ) { <nl> - IfBuilder hole_check ( this ) ; <nl> - Node * the_hole = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> - Node * check = NewNode ( javascript ( ) - > StrictEqual ( CompareOperationHint : : kAny ) , <nl> - value , the_hole ) ; <nl> - hole_check . If ( check ) ; <nl> - hole_check . Then ( ) ; <nl> - environment ( ) - > Push ( for_hole ) ; <nl> - hole_check . Else ( ) ; <nl> - Node * error = BuildThrowReferenceError ( variable , bailout_id ) ; <nl> - environment ( ) - > Push ( error ) ; <nl> - hole_check . End ( ) ; <nl> - return environment ( ) - > Pop ( ) ; <nl> - } <nl> - <nl> Node * AstGraphBuilder : : BuildVariableLoad ( Variable * variable , <nl> BailoutId bailout_id , <nl> const VectorSlotPair & feedback , <nl> OutputFrameStateCombine combine , <nl> TypeofMode typeof_mode ) { <nl> - Node * the_hole = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> / / Global var , const , or let variable . <nl> Node * AstGraphBuilder : : BuildVariableLoad ( Variable * variable , <nl> return value ; <nl> } <nl> case VariableLocation : : PARAMETER : <nl> - case VariableLocation : : LOCAL : { <nl> - / / Local var , const , or let variable . <nl> - Node * value = environment ( ) - > Lookup ( variable ) ; <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - / / Perform check for uninitialized let / const variables . <nl> - if ( value - > op ( ) = = the_hole - > op ( ) ) { <nl> - value = BuildThrowReferenceError ( variable , bailout_id ) ; <nl> - } else if ( value - > opcode ( ) = = IrOpcode : : kPhi ) { <nl> - value = BuildHoleCheckThenThrow ( value , variable , value , bailout_id ) ; <nl> - } <nl> - } <nl> - return value ; <nl> - } <nl> + case VariableLocation : : LOCAL : <nl> + / / Local variable . <nl> + return environment ( ) - > Lookup ( variable ) ; <nl> case VariableLocation : : CONTEXT : { <nl> / / Context variable ( potentially up the context chain ) . <nl> int depth = current_scope ( ) - > ContextChainLength ( variable - > scope ( ) ) ; <nl> Node * AstGraphBuilder : : BuildVariableLoad ( Variable * variable , <nl> info ( ) - > is_function_context_specializing ( ) ; <nl> const Operator * op = <nl> javascript ( ) - > LoadContext ( depth , variable - > index ( ) , immutable ) ; <nl> - Node * value = NewNode ( op ) ; <nl> - / / TODO ( titzer ) : initialization checks are redundant for already <nl> - / / initialized immutable context loads , but only specialization knows . <nl> - / / Maybe specializer should be a parameter to the graph builder ? <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - / / Perform check for uninitialized let / const variables . <nl> - value = BuildHoleCheckThenThrow ( value , variable , value , bailout_id ) ; <nl> - } <nl> - return value ; <nl> + return NewNode ( op ) ; <nl> } <nl> case VariableLocation : : LOOKUP : <nl> case VariableLocation : : MODULE : <nl> Node * AstGraphBuilder : : BuildVariableAssignment ( <nl> Variable * variable , Node * value , Token : : Value op , <nl> const VectorSlotPair & feedback , BailoutId bailout_id , <nl> OutputFrameStateCombine combine ) { <nl> - Node * the_hole = jsgraph ( ) - > TheHoleConstant ( ) ; <nl> - VariableMode mode = variable - > mode ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> / / Global var , const , or let variable . <nl> Node * AstGraphBuilder : : BuildVariableAssignment ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - / / Local var , const , or let variable . <nl> - if ( mode = = LET & & op = = Token : : INIT ) { <nl> - / / No initialization check needed because scoping guarantees it . Note <nl> - / / that we still perform a lookup to keep the variable live , because <nl> - / / baseline code might contain debug code that inspects the variable . <nl> - Node * current = environment ( ) - > Lookup ( variable ) ; <nl> - CHECK_NOT_NULL ( current ) ; <nl> - } else if ( mode = = LET & & op ! = Token : : INIT & & <nl> - variable - > binding_needs_init ( ) ) { <nl> - / / Perform an initialization check for let declared variables . <nl> - Node * current = environment ( ) - > Lookup ( variable ) ; <nl> - if ( current - > op ( ) = = the_hole - > op ( ) ) { <nl> - return BuildThrowReferenceError ( variable , bailout_id ) ; <nl> - } else if ( current - > opcode ( ) = = IrOpcode : : kPhi ) { <nl> - BuildHoleCheckThenThrow ( current , variable , value , bailout_id ) ; <nl> - } <nl> - } else if ( mode = = CONST & & op = = Token : : INIT ) { <nl> - / / Perform an initialization check for const { this } variables . <nl> - / / Note that the { this } variable is the only const variable being able <nl> - / / to trigger bind operations outside the TDZ , via { super } calls . <nl> - Node * current = environment ( ) - > Lookup ( variable ) ; <nl> - if ( current - > op ( ) ! = the_hole - > op ( ) & & variable - > is_this ( ) ) { <nl> - value = BuildHoleCheckElseThrow ( current , variable , value , bailout_id ) ; <nl> - } <nl> - } else if ( mode = = CONST & & op ! = Token : : INIT & & <nl> - variable - > is_sloppy_function_name ( ) ) { <nl> + DCHECK ( ! variable - > is_this ( ) ) ; <nl> + if ( variable - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> / / Non - initializing assignment to sloppy function names is <nl> / / - exception in strict mode . <nl> / / - ignored in sloppy mode . <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> + DCHECK ( variable - > is_sloppy_function_name ( ) ) ; <nl> if ( variable - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> return BuildThrowConstAssignError ( bailout_id ) ; <nl> } <nl> return value ; <nl> - } else if ( mode = = CONST & & op ! = Token : : INIT ) { <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Node * current = environment ( ) - > Lookup ( variable ) ; <nl> - if ( current - > op ( ) = = the_hole - > op ( ) ) { <nl> - return BuildThrowReferenceError ( variable , bailout_id ) ; <nl> - } else if ( current - > opcode ( ) = = IrOpcode : : kPhi ) { <nl> - BuildHoleCheckThenThrow ( current , variable , value , bailout_id ) ; <nl> - } <nl> - } <nl> - / / Assignment to const is exception in all modes . <nl> - return BuildThrowConstAssignError ( bailout_id ) ; <nl> } <nl> environment ( ) - > Bind ( variable , value ) ; <nl> return value ; <nl> case VariableLocation : : CONTEXT : { <nl> + DCHECK ( ! variable - > is_this ( ) ) ; <nl> / / Context variable ( potentially up the context chain ) . <nl> - int depth = current_scope ( ) - > ContextChainLength ( variable - > scope ( ) ) ; <nl> - if ( mode = = LET & & op ! = Token : : INIT & & variable - > binding_needs_init ( ) ) { <nl> - / / Perform an initialization check for let declared variables . <nl> - const Operator * op = <nl> - javascript ( ) - > LoadContext ( depth , variable - > index ( ) , false ) ; <nl> - Node * current = NewNode ( op ) ; <nl> - value = BuildHoleCheckThenThrow ( current , variable , value , bailout_id ) ; <nl> - } else if ( mode = = CONST & & op = = Token : : INIT ) { <nl> - / / Perform an initialization check for const { this } variables . <nl> - / / Note that the { this } variable is the only const variable being able <nl> - / / to trigger bind operations outside the TDZ , via { super } calls . <nl> - if ( variable - > is_this ( ) ) { <nl> - const Operator * op = <nl> - javascript ( ) - > LoadContext ( depth , variable - > index ( ) , false ) ; <nl> - Node * current = NewNode ( op ) ; <nl> - value = BuildHoleCheckElseThrow ( current , variable , value , bailout_id ) ; <nl> - } <nl> - } else if ( mode = = CONST & & op ! = Token : : INIT & & <nl> - variable - > is_sloppy_function_name ( ) ) { <nl> + if ( variable - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> / / Non - initializing assignment to sloppy function names is <nl> / / - exception in strict mode . <nl> / / - ignored in sloppy mode . <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> + DCHECK ( variable - > is_sloppy_function_name ( ) ) ; <nl> if ( variable - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> return BuildThrowConstAssignError ( bailout_id ) ; <nl> } <nl> return value ; <nl> - } else if ( mode = = CONST & & op ! = Token : : INIT ) { <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - const Operator * op = <nl> - javascript ( ) - > LoadContext ( depth , variable - > index ( ) , false ) ; <nl> - Node * current = NewNode ( op ) ; <nl> - BuildHoleCheckThenThrow ( current , variable , value , bailout_id ) ; <nl> - } <nl> - / / Assignment to const is exception in all modes . <nl> - return BuildThrowConstAssignError ( bailout_id ) ; <nl> } <nl> + int depth = current_scope ( ) - > ContextChainLength ( variable - > scope ( ) ) ; <nl> const Operator * op = javascript ( ) - > StoreContext ( depth , variable - > index ( ) ) ; <nl> return NewNode ( op , value ) ; <nl> } <nl> Node * AstGraphBuilder : : BuildThrowError ( Node * exception , BailoutId bailout_id ) { <nl> } <nl> <nl> <nl> - Node * AstGraphBuilder : : BuildThrowReferenceError ( Variable * variable , <nl> - BailoutId bailout_id ) { <nl> - Node * variable_name = jsgraph ( ) - > Constant ( variable - > name ( ) ) ; <nl> - const Operator * op = javascript ( ) - > CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - Node * call = NewNode ( op , variable_name ) ; <nl> - PrepareFrameState ( call , bailout_id ) ; <nl> - Node * control = NewNode ( common ( ) - > Throw ( ) , call ) ; <nl> - UpdateControlDependencyToLeaveFunction ( control ) ; <nl> - return call ; <nl> - } <nl> - <nl> - <nl> Node * AstGraphBuilder : : BuildThrowConstAssignError ( BailoutId bailout_id ) { <nl> const Operator * op = <nl> javascript ( ) - > CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> mmm a / src / compiler / ast - graph - builder . h <nl> ppp b / src / compiler / ast - graph - builder . h <nl> class AstGraphBuilder : public AstVisitor < AstGraphBuilder > { <nl> <nl> / / Builders for error reporting at runtime . <nl> Node * BuildThrowError ( Node * exception , BailoutId bailout_id ) ; <nl> - Node * BuildThrowReferenceError ( Variable * var , BailoutId bailout_id ) ; <nl> Node * BuildThrowConstAssignError ( BailoutId bailout_id ) ; <nl> <nl> - / / Builders for dynamic hole - checks at runtime . <nl> - Node * BuildHoleCheckThenThrow ( Node * value , Variable * var , Node * not_hole , <nl> - BailoutId bailout_id ) ; <nl> - Node * BuildHoleCheckElseThrow ( Node * value , Variable * var , Node * for_hole , <nl> - BailoutId bailout_id ) ; <nl> - <nl> / / Builders for non - local control flow . <nl> Node * BuildReturn ( Node * return_value ) ; <nl> Node * BuildThrow ( Node * exception_value ) ; <nl> mmm a / src / full - codegen / arm / full - codegen - arm . cc <nl> ppp b / src / full - codegen / arm / full - codegen - arm . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( r0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ str ( r0 , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( r0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ str ( r0 , ContextMemOperand ( cp , variable - > index ( ) ) ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( r0 , var ) ; <nl> - __ CompareRoot ( r0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ b ( ne , & done ) ; <nl> - __ mov ( r0 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( r0 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r0 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , r1 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ ldr ( r3 , location ) ; <nl> - __ CompareRoot ( r3 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ b ( ne , & assign ) ; <nl> - __ mov ( r3 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r3 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , r1 ) ; <nl> - __ ldr ( r3 , location ) ; <nl> - __ CompareRoot ( r3 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ b ( eq , & uninitialized_this ) ; <nl> - __ mov ( r0 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( r0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , r1 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ ldr ( r2 , location ) ; <nl> - __ CompareRoot ( r2 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> VariableProxy * proxy = expr - > expression ( ) - > AsVariableProxy ( ) ; <nl> if ( expr - > is_postfix ( ) ) { <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( r0 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r0 ) ; <nl> mmm a / src / full - codegen / arm64 / full - codegen - arm64 . cc <nl> ppp b / src / full - codegen / arm64 / full - codegen - arm64 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( x10 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Str ( x10 , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( x10 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Str ( x10 , ContextMemOperand ( cp , variable - > index ( ) ) ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) <nl> ? " Context variable " <nl> : " Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( x0 , var ) ; <nl> - __ JumpIfNotRoot ( x0 , Heap : : kTheHoleValueRootIndex , & done ) ; <nl> - __ Mov ( x0 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( x0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ Bind ( & done ) ; <nl> - context ( ) - > Plug ( x0 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( x0 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> ASM_LOCATION ( " FullCodeGenerator : : EmitVariableAssignment " ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , x1 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( var - > binding_needs_init ( ) ) { <nl> - Label assign ; <nl> - __ Ldr ( x10 , location ) ; <nl> - __ JumpIfNotRoot ( x10 , Heap : : kTheHoleValueRootIndex , & assign ) ; <nl> - __ Mov ( x10 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( x10 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ Bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , x1 ) ; <nl> - __ Ldr ( x10 , location ) ; <nl> - __ JumpIfRoot ( x10 , Heap : : kTheHoleValueRootIndex , & uninitialized_this ) ; <nl> - __ Mov ( x0 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( x0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , x1 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - __ Ldr ( x10 , location ) ; <nl> - __ CompareRoot ( x10 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> VariableProxy * proxy = expr - > expression ( ) - > AsVariableProxy ( ) ; <nl> if ( expr - > is_postfix ( ) ) { <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( x0 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( x0 ) ; <nl> mmm a / src / full - codegen / full - codegen . h <nl> ppp b / src / full - codegen / full - codegen . h <nl> class FullCodeGenerator final : public AstVisitor < FullCodeGenerator > { <nl> / / Complete a variable assignment . The right - hand - side value is expected <nl> / / in the accumulator . <nl> void EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) ; <nl> + FeedbackVectorSlot slot ) ; <nl> <nl> / / Helper functions to EmitVariableAssignment <nl> void EmitStoreToStackLocalOrContextSlot ( Variable * var , <nl> mmm a / src / full - codegen / ia32 / full - codegen - ia32 . cc <nl> ppp b / src / full - codegen / ia32 / full - codegen - ia32 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ mov ( StackOperand ( variable ) , <nl> - Immediate ( isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ mov ( ContextOperand ( esi , variable - > index ( ) ) , <nl> - Immediate ( isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ) ; <nl> - / / No write barrier since the hole value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( eax , var ) ; <nl> - __ cmp ( eax , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( not_equal , & done , Label : : kNear ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( eax ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( eax ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ mov ( StoreDescriptor : : ReceiverRegister ( ) , NativeContextOperand ( ) ) ; <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> Context : : EXTENSION_INDEX ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , ecx ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( not_equal , & assign , Label : : kNear ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , ecx ) ; <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( equal , & uninitialized_this ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , ecx ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ Check ( equal , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> if ( expr - > is_postfix ( ) ) { <nl> / / Perform the assignment as if via ' = ' . <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( eax ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> } <nl> } else { <nl> / / Perform the assignment as if via ' = ' . <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( eax ) ; <nl> mmm a / src / full - codegen / mips / full - codegen - mips . cc <nl> ppp b / src / full - codegen / mips / full - codegen - mips . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( t0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ sw ( t0 , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ sw ( at , ContextMemOperand ( cp , variable - > index ( ) ) ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( v0 , var ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ subu ( at , v0 , at ) ; / / Sub as compare : at = = 0 on eq . <nl> - __ Branch ( & done , ne , at , Operand ( zero_reg ) ) ; <nl> - __ li ( a0 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( a0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( v0 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( v0 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ mov ( StoreDescriptor : : ValueRegister ( ) , result_register ( ) ) ; <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , a1 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ lw ( a3 , location ) ; <nl> - __ LoadRoot ( t0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Branch ( & assign , ne , a3 , Operand ( t0 ) ) ; <nl> - __ li ( a3 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( a3 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , a1 ) ; <nl> - __ lw ( a3 , location ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Branch ( & uninitialized_this , eq , a3 , Operand ( at ) ) ; <nl> - __ li ( a0 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( a0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , a1 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ lw ( a2 , location ) ; <nl> - __ LoadRoot ( t0 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization , a2 , Operand ( t0 ) ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> VariableProxy * proxy = expr - > expression ( ) - > AsVariableProxy ( ) ; <nl> if ( expr - > is_postfix ( ) ) { <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( v0 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( v0 ) ; <nl> mmm a / src / full - codegen / mips64 / full - codegen - mips64 . cc <nl> ppp b / src / full - codegen / mips64 / full - codegen - mips64 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( a4 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ sd ( a4 , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ sd ( at , ContextMemOperand ( cp , variable - > index ( ) ) ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( v0 , var ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ dsubu ( at , v0 , at ) ; / / Sub as compare : at = = 0 on eq . <nl> - __ Branch ( & done , ne , at , Operand ( zero_reg ) ) ; <nl> - __ li ( a0 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( a0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( v0 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( v0 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ mov ( StoreDescriptor : : ValueRegister ( ) , result_register ( ) ) ; <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , a1 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ ld ( a3 , location ) ; <nl> - __ LoadRoot ( a4 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Branch ( & assign , ne , a3 , Operand ( a4 ) ) ; <nl> - __ li ( a3 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( a3 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , a1 ) ; <nl> - __ ld ( a3 , location ) ; <nl> - __ LoadRoot ( at , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Branch ( & uninitialized_this , eq , a3 , Operand ( at ) ) ; <nl> - __ li ( a0 , Operand ( var - > name ( ) ) ) ; <nl> - __ Push ( a0 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , a1 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ ld ( a2 , location ) ; <nl> - __ LoadRoot ( a4 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization , a2 , Operand ( a4 ) ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> VariableProxy * proxy = expr - > expression ( ) - > AsVariableProxy ( ) ; <nl> if ( expr - > is_postfix ( ) ) { <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( v0 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( v0 ) ; <nl> mmm a / src / full - codegen / ppc / full - codegen - ppc . cc <nl> ppp b / src / full - codegen / ppc / full - codegen - ppc . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( ip , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ StoreP ( ip , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( ip , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ StoreP ( ip , ContextMemOperand ( cp , variable - > index ( ) ) , r0 ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( r3 , var ) ; <nl> - __ CompareRoot ( r3 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ bne ( & done ) ; <nl> - __ mov ( r3 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r3 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( r3 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r3 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , r4 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ LoadP ( r6 , location ) ; <nl> - __ CompareRoot ( r6 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ bne ( & assign ) ; <nl> - __ mov ( r6 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r6 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , r4 ) ; <nl> - __ LoadP ( r6 , location ) ; <nl> - __ CompareRoot ( r6 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ beq ( & uninitialized_this ) ; <nl> - __ mov ( r4 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r4 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , r4 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ LoadP ( r5 , location ) ; <nl> - __ CompareRoot ( r5 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> if ( expr - > is_postfix ( ) ) { <nl> { <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( r3 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r3 ) ; <nl> mmm a / src / full - codegen / s390 / full - codegen - s390 . cc <nl> ppp b / src / full - codegen / s390 / full - codegen - s390 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( ip , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ StoreP ( ip , StackOperand ( variable ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( ip , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ StoreP ( ip , ContextMemOperand ( cp , variable - > index ( ) ) ) ; <nl> - / / No write barrier since the_hole_value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( r2 , var ) ; <nl> - __ CompareRoot ( r2 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ bne ( & done ) ; <nl> - __ mov ( r2 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r2 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( r2 ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r2 ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - / / Non - initializing assignment to let variable needs a write barrier . <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , r3 ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ LoadP ( r5 , location ) ; <nl> - __ CompareRoot ( r5 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ bne ( & assign ) ; <nl> - __ mov ( r5 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r5 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , r3 ) ; <nl> - __ LoadP ( r5 , location ) ; <nl> - __ CompareRoot ( r5 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ beq ( & uninitialized_this ) ; <nl> - __ mov ( r3 , Operand ( var - > name ( ) ) ) ; <nl> - __ push ( r3 ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , r3 ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ LoadP ( r4 , location ) ; <nl> - __ CompareRoot ( r4 , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( eq , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> if ( expr - > is_postfix ( ) ) { <nl> { <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( r2 ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> context ( ) - > PlugTOS ( ) ; <nl> } <nl> } else { <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( r2 ) ; <nl> mmm a / src / full - codegen / x64 / full - codegen - x64 . cc <nl> ppp b / src / full - codegen / x64 / full - codegen - x64 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ LoadRoot ( kScratchRegister , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ movp ( StackOperand ( variable ) , kScratchRegister ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ LoadRoot ( kScratchRegister , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ movp ( ContextOperand ( rsi , variable - > index ( ) ) , kScratchRegister ) ; <nl> - / / No write barrier since the hole value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variable , and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context slot " <nl> : " [ Stack slot " ) ; <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - DCHECK ( IsLexicalVariableMode ( var - > mode ( ) ) ) ; <nl> - Label done ; <nl> - GetVar ( rax , var ) ; <nl> - __ CompareRoot ( rax , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ j ( not_equal , & done , Label : : kNear ) ; <nl> - __ Push ( var - > name ( ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( rax ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( rax ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ LoadGlobalObject ( StoreDescriptor : : ReceiverRegister ( ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , rcx ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ movp ( rdx , location ) ; <nl> - __ CompareRoot ( rdx , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ j ( not_equal , & assign , Label : : kNear ) ; <nl> - __ Push ( var - > name ( ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , rcx ) ; <nl> - __ movp ( rdx , location ) ; <nl> - __ CompareRoot ( rdx , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ j ( equal , & uninitialized_this ) ; <nl> - __ Push ( var - > name ( ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , rcx ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ movp ( rdx , location ) ; <nl> - __ CompareRoot ( rdx , Heap : : kTheHoleValueRootIndex ) ; <nl> - __ Check ( equal , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> if ( expr - > is_postfix ( ) ) { <nl> / / Perform the assignment as if via ' = ' . <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( rax ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> } <nl> } else { <nl> / / Perform the assignment as if via ' = ' . <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( rax ) ; <nl> mmm a / src / full - codegen / x87 / full - codegen - x87 . cc <nl> ppp b / src / full - codegen / x87 / full - codegen - x87 . cc <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> VariableDeclaration * declaration ) { <nl> VariableProxy * proxy = declaration - > proxy ( ) ; <nl> Variable * variable = proxy - > var ( ) ; <nl> + DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> switch ( variable - > location ( ) ) { <nl> case VariableLocation : : UNALLOCATED : { <nl> - DCHECK ( ! variable - > binding_needs_init ( ) ) ; <nl> globals_ - > Add ( variable - > name ( ) , zone ( ) ) ; <nl> FeedbackVectorSlot slot = proxy - > VariableFeedbackSlot ( ) ; <nl> DCHECK ( ! slot . IsInvalid ( ) ) ; <nl> void FullCodeGenerator : : VisitVariableDeclaration ( <nl> } <nl> case VariableLocation : : PARAMETER : <nl> case VariableLocation : : LOCAL : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - __ mov ( StackOperand ( variable ) , <nl> - Immediate ( isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ) ; <nl> - } <nl> - break ; <nl> - <nl> case VariableLocation : : CONTEXT : <nl> - if ( variable - > binding_needs_init ( ) ) { <nl> - Comment cmnt ( masm_ , " [ VariableDeclaration " ) ; <nl> - EmitDebugCheckDeclarationContext ( variable ) ; <nl> - __ mov ( ContextOperand ( esi , variable - > index ( ) ) , <nl> - Immediate ( isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ) ; <nl> - / / No write barrier since the hole value is in old space . <nl> - PrepareForBailoutForId ( proxy - > id ( ) , BailoutState : : NO_REGISTERS ) ; <nl> - } <nl> break ; <nl> <nl> case VariableLocation : : LOOKUP : <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> SetExpressionPosition ( proxy ) ; <nl> PrepareForBailoutForId ( proxy - > BeforeId ( ) , BailoutState : : NO_REGISTERS ) ; <nl> Variable * var = proxy - > var ( ) ; <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> <nl> / / Two cases : global variables and all other types of variables . <nl> switch ( var - > location ( ) ) { <nl> void FullCodeGenerator : : EmitVariableLoad ( VariableProxy * proxy , <nl> DCHECK_EQ ( NOT_INSIDE_TYPEOF , typeof_mode ) ; <nl> Comment cmnt ( masm_ , var - > IsContextSlot ( ) ? " [ Context variable " <nl> : " [ Stack variable " ) ; <nl> - <nl> - if ( proxy - > hole_check_mode ( ) = = HoleCheckMode : : kRequired ) { <nl> - / / Throw a reference error when using an uninitialized let / const <nl> - / / binding in harmony mode . <nl> - Label done ; <nl> - GetVar ( eax , var ) ; <nl> - __ cmp ( eax , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( not_equal , & done , Label : : kNear ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & done ) ; <nl> - context ( ) - > Plug ( eax ) ; <nl> - break ; <nl> - } <nl> context ( ) - > Plug ( var ) ; <nl> break ; <nl> } <nl> void FullCodeGenerator : : VisitAssignment ( Assignment * expr ) { <nl> switch ( assign_type ) { <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > target ( ) - > AsVariableProxy ( ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , expr - > op ( ) , expr - > AssignmentSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( eax ) ; <nl> break ; <nl> void FullCodeGenerator : : EmitAssignment ( Expression * expr , <nl> case VARIABLE : { <nl> VariableProxy * proxy = expr - > AsVariableProxy ( ) ; <nl> EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , slot ) ; <nl> break ; <nl> } <nl> case NAMED_PROPERTY : { <nl> void FullCodeGenerator : : EmitStoreToStackLocalOrContextSlot ( <nl> } <nl> <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> - FeedbackVectorSlot slot , <nl> - HoleCheckMode hole_check_mode ) { <nl> + FeedbackVectorSlot slot ) { <nl> + DCHECK ( ! var - > binding_needs_init ( ) ) ; <nl> if ( var - > IsUnallocated ( ) ) { <nl> / / Global var , const , or let . <nl> __ mov ( StoreDescriptor : : ReceiverRegister ( ) , NativeContextOperand ( ) ) ; <nl> void FullCodeGenerator : : EmitVariableAssignment ( Variable * var , Token : : Value op , <nl> Context : : EXTENSION_INDEX ) ) ; <nl> CallStoreIC ( slot , var - > name ( ) ) ; <nl> <nl> - } else if ( IsLexicalVariableMode ( var - > mode ( ) ) & & op ! = Token : : INIT ) { <nl> - DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - MemOperand location = VarOperand ( var , ecx ) ; <nl> - / / Perform an initialization check for lexically declared variables . <nl> - if ( hole_check_mode = = HoleCheckMode : : kRequired ) { <nl> - Label assign ; <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( not_equal , & assign , Label : : kNear ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & assign ) ; <nl> - } <nl> - if ( var - > mode ( ) ! = CONST ) { <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - } else if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> + } else if ( var - > mode ( ) = = CONST & & op ! = Token : : INIT ) { <nl> + if ( var - > throw_on_const_assignment ( language_mode ( ) ) ) { <nl> __ CallRuntime ( Runtime : : kThrowConstAssignError ) ; <nl> } <nl> - } else if ( var - > is_this ( ) & & var - > mode ( ) = = CONST & & op = = Token : : INIT ) { <nl> - / / Initializing assignment to const { this } needs a write barrier . <nl> - DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> - Label uninitialized_this ; <nl> - MemOperand location = VarOperand ( var , ecx ) ; <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ j ( equal , & uninitialized_this ) ; <nl> - __ push ( Immediate ( var - > name ( ) ) ) ; <nl> - __ CallRuntime ( Runtime : : kThrowReferenceError ) ; <nl> - __ bind ( & uninitialized_this ) ; <nl> - EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> - <nl> } else { <nl> - DCHECK ( var - > mode ( ) ! = CONST | | op = = Token : : INIT ) ; <nl> + DCHECK ( ! var - > is_this ( ) ) ; <nl> DCHECK ( var - > IsStackAllocated ( ) | | var - > IsContextSlot ( ) ) ; <nl> DCHECK ( ! var - > IsLookupSlot ( ) ) ; <nl> - / / Assignment to var or initializing assignment to let / const in harmony <nl> - / / mode . <nl> MemOperand location = VarOperand ( var , ecx ) ; <nl> - if ( FLAG_debug_code & & var - > mode ( ) = = LET & & op = = Token : : INIT ) { <nl> - / / Check for an uninitialized let binding . <nl> - __ mov ( edx , location ) ; <nl> - __ cmp ( edx , isolate ( ) - > factory ( ) - > the_hole_value ( ) ) ; <nl> - __ Check ( equal , kLetBindingReInitialization ) ; <nl> - } <nl> EmitStoreToStackLocalOrContextSlot ( var , location ) ; <nl> } <nl> } <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> if ( expr - > is_postfix ( ) ) { <nl> / / Perform the assignment as if via ' = ' . <nl> { EffectContext context ( this ) ; <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , <nl> + expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context . Plug ( eax ) ; <nl> void FullCodeGenerator : : VisitCountOperation ( CountOperation * expr ) { <nl> } <nl> } else { <nl> / / Perform the assignment as if via ' = ' . <nl> - EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) , <nl> - proxy - > hole_check_mode ( ) ) ; <nl> + EmitVariableAssignment ( proxy - > var ( ) , Token : : ASSIGN , expr - > CountSlot ( ) ) ; <nl> PrepareForBailoutForId ( expr - > AssignmentId ( ) , <nl> BailoutState : : TOS_REGISTER ) ; <nl> context ( ) - > Plug ( eax ) ; <nl>
[ fullcodegen ] Remove dead hole check logic
v8/v8
45c11887929c1f0fbc54849d2627cd8bb90bcc37
2017-01-06T19:45:05Z
mmm a / AirLib / src / rpc / RpcLibServer . cpp <nl> ppp b / AirLib / src / rpc / RpcLibServer . cpp <nl> struct RpcLibServer : : impl { <nl> : server ( server_address , port ) <nl> { } <nl> <nl> - ~ impl ( ) { <nl> - } <nl> + ~ impl ( ) { <nl> + } <nl> <nl> rpc : : server server ; <nl> } ; <nl> RpcLibServer : : RpcLibServer ( DroneControllerCancelable * drone , string server_addre <nl> / / required for pimpl <nl> RpcLibServer : : ~ RpcLibServer ( ) <nl> { <nl> - stop ( ) ; <nl> - drone_ = nullptr ; <nl> + stop ( ) ; <nl> + drone_ = nullptr ; <nl> } <nl> <nl> void RpcLibServer : : start ( bool block ) <nl> mmm a / AirSim . sln <nl> ppp b / AirSim . sln <nl> Project ( " { 2150E333 - 8FDC - 42A3 - 9474 - 1A3956D46DE8 } " ) = " AirSim " , " AirSim " , " { 6B6941 <nl> Unreal \ Plugins \ AirSim \ Source \ RecordingThread . h = Unreal \ Plugins \ AirSim \ Source \ RecordingThread . h <nl> Unreal \ Plugins \ AirSim \ Source \ RenderRequest . cpp = Unreal \ Plugins \ AirSim \ Source \ RenderRequest . cpp <nl> Unreal \ Plugins \ AirSim \ Source \ RenderRequest . h = Unreal \ Plugins \ AirSim \ Source \ RenderRequest . h <nl> + Unreal \ Plugins \ AirSim \ Source \ VehicleCameraConnector . cpp = Unreal \ Plugins \ AirSim \ Source \ VehicleCameraConnector . cpp <nl> Unreal \ Plugins \ AirSim \ Source \ VehicleCameraConnector . h = Unreal \ Plugins \ AirSim \ Source \ VehicleCameraConnector . h <nl> Unreal \ Plugins \ AirSim \ Source \ VehicleConnectorBase . cpp = Unreal \ Plugins \ AirSim \ Source \ VehicleConnectorBase . cpp <nl> Unreal \ Plugins \ AirSim \ Source \ VehicleConnectorBase . h = Unreal \ Plugins \ AirSim \ Source \ VehicleConnectorBase . h <nl> new file mode 100644 <nl> index 000000000 . . b253ff885 <nl> mmm / dev / null <nl> ppp b / Unreal / Plugins / AirSim / Source / VehicleCameraConnector . cpp <nl> <nl> + # include " AirSim . h " <nl> + # include " RenderRequest . h " <nl> + # include " SimHUD / SimHUD . h " <nl> + # include " ImageUtils . h " <nl> + # include < chrono > <nl> + <nl> + <nl> + VehicleCameraConnector : : VehicleCameraConnector ( APIPCamera * camera , int id ) <nl> + { <nl> + this - > camera = camera ; <nl> + this - > id = id ; <nl> + <nl> + addScreenCaptureHandler ( camera - > GetWorld ( ) ) ; <nl> + } <nl> + <nl> + int VehicleCameraConnector : : getId ( ) <nl> + { <nl> + return id ; <nl> + } <nl> + <nl> + void VehicleCameraConnector : : addScreenCaptureHandler ( UWorld * world ) <nl> + { <nl> + static bool is_installed = false ; <nl> + <nl> + if ( ! is_installed ) { <nl> + UGameViewportClient * ViewportClient = world - > GetGameViewport ( ) ; <nl> + ViewportClient - > OnScreenshotCaptured ( ) . Clear ( ) ; <nl> + ViewportClient - > OnScreenshotCaptured ( ) . AddLambda ( <nl> + [ this ] ( int32 SizeX , int32 SizeY , const TArray < FColor > & Bitmap ) <nl> + { <nl> + / / Make sure that all alpha values are opaque . <nl> + TArray < FColor > & RefBitmap = const_cast < TArray < FColor > & > ( Bitmap ) ; <nl> + for ( auto & Color : RefBitmap ) <nl> + Color . A = 255 ; <nl> + <nl> + TArray < uint8_t > last_compressed_png ; <nl> + FImageUtils : : CompressImageArray ( SizeX , SizeY , RefBitmap , last_compressed_png ) ; <nl> + last_compressed_png_ = std : : vector < uint8_t > ( last_compressed_png . GetData ( ) , last_compressed_png . GetData ( ) + last_compressed_png . Num ( ) ) ; <nl> + } ) ; <nl> + <nl> + is_installed = true ; <nl> + } <nl> + } <nl> + <nl> + <nl> + bool VehicleCameraConnector : : getScreenShot ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) <nl> + { <nl> + <nl> + if ( this - > camera = = nullptr ) { <nl> + return false ; <nl> + } <nl> + if ( imageType = = DroneControllerBase : : ImageType : : None ) { <nl> + return false ; <nl> + } <nl> + <nl> + return getScreenshotSceneCapture ( imageType , compressedPng ) ; <nl> + } <nl> + <nl> + bool VehicleCameraConnector : : getScreenshotScreen ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) <nl> + { <nl> + FScreenshotRequest : : RequestScreenshot ( false ) ; / / This is an async operation <nl> + return true ; <nl> + } <nl> + <nl> + bool VehicleCameraConnector : : getScreenshotSceneCapture ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) <nl> + { <nl> + ASimHUD * hud = ASimHUD : : GetInstance ( ) ; <nl> + EPIPCameraType pip_type ; <nl> + bool visibilityChanged = false ; <nl> + / / TODO : merge these two different types ? <nl> + switch ( imageType ) { <nl> + case DroneControllerBase : : ImageType : : Scene : <nl> + pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_SCENE ; <nl> + if ( ! hud - > isPIPSceneVisible ( ) ) { <nl> + hud - > inputEventTogglePIPScene ( ) ; <nl> + visibilityChanged = true ; <nl> + } <nl> + break ; <nl> + case DroneControllerBase : : ImageType : : Depth : <nl> + pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_DEPTH ; <nl> + if ( ! hud - > isPIPDepthVisible ( ) ) { <nl> + hud - > inputEventTogglePIPDepth ( ) ; <nl> + visibilityChanged = true ; <nl> + } <nl> + break ; <nl> + case DroneControllerBase : : ImageType : : Segmentation : <nl> + pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_SEG ; <nl> + if ( ! hud - > isPIPSegVisible ( ) ) { <nl> + hud - > inputEventTogglePIPSeg ( ) ; <nl> + visibilityChanged = true ; <nl> + } <nl> + break ; <nl> + default : <nl> + pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_NONE ; <nl> + } <nl> + <nl> + if ( visibilityChanged ) { <nl> + / / Wait for render so that view is ready for capture <nl> + std : : this_thread : : sleep_for ( std : : chrono : : duration < double > ( 0 . 2 ) ) ; <nl> + / / not sure why this doesn ' t work . <nl> + / / DECLARE_CYCLE_STAT ( TEXT ( " FNullGraphTask . CheckRenderStatus " ) , STAT_FNullGraphTask_CheckRenderStatus , STATGROUP_TaskGraphTasks ) ; <nl> + / / auto renderStatus = TGraphTask < FNullGraphTask > : : CreateTask ( NULL ) . ConstructAndDispatchWhenReady ( GET_STATID ( STAT_FNullGraphTask_CheckRenderStatus ) , ENamedThreads : : RenderThread ) ; <nl> + / / FTaskGraphInterface : : Get ( ) . WaitUntilTaskCompletes ( renderStatus ) ; <nl> + } <nl> + <nl> + using namespace msr : : airlib ; <nl> + USceneCaptureComponent2D * capture = camera - > getCaptureComponent ( pip_type , true ) ; <nl> + if ( capture = = nullptr ) { <nl> + UAirBlueprintLib : : LogMessage ( TEXT ( " Can ' t take screenshot because eithercamera type is not active " ) , TEXT ( " " ) , LogDebugLevel : : Failure ) ; <nl> + return false ; <nl> + } <nl> + <nl> + if ( capture - > TextureTarget = = nullptr ) { <nl> + UAirBlueprintLib : : LogMessage ( TEXT ( " Can ' t take screenshot because texture target is null " ) , TEXT ( " " ) , LogDebugLevel : : Failure ) ; <nl> + return false ; <nl> + } <nl> + <nl> + UTextureRenderTarget2D * textureTarget = capture - > TextureTarget ; <nl> + <nl> + TArray < uint8 > image ; <nl> + RenderRequest request ; <nl> + request . getScreenshot ( textureTarget , image ) ; <nl> + <nl> + / / copy data across to std : : vector . <nl> + compressedPng = std : : vector < uint8_t > ( image . GetData ( ) , image . GetData ( ) + image . Num ( ) ) ; <nl> + <nl> + return true ; <nl> + } <nl> mmm a / Unreal / Plugins / AirSim / Source / VehicleCameraConnector . h <nl> ppp b / Unreal / Plugins / AirSim / Source / VehicleCameraConnector . h <nl> <nl> - # include " AirSim . h " <nl> - # include " PIPCamera . h " <nl> + # pragma once <nl> + <nl> # include " controllers / VehicleCamera . hpp " <nl> - # include " RenderRequest . h " <nl> - # include " SimHUD / SimHUD . h " <nl> - # include < chrono > <nl> + # include " PIPCamera . h " <nl> + <nl> <nl> class VehicleCameraConnector : public VehicleCamera <nl> { <nl> - APIPCamera * camera ; <nl> - int id ; <nl> public : <nl> - VehicleCameraConnector ( APIPCamera * camera , int id ) { <nl> - this - > camera = camera ; <nl> - this - > id = id ; <nl> - } <nl> - <nl> - int getId ( ) override { <nl> - return id ; <nl> - } <nl> + VehicleCameraConnector ( APIPCamera * camera , int id ) ; <nl> + int getId ( ) override ; <nl> + bool getScreenShot ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) override ; <nl> <nl> - bool getScreenShot ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) override <nl> - { <nl> <nl> - if ( this - > camera = = nullptr ) { <nl> - return false ; <nl> - } <nl> - if ( imageType = = DroneControllerBase : : ImageType : : None ) { <nl> - return false ; <nl> - } <nl> - ASimHUD * hud = ASimHUD : : GetInstance ( ) ; <nl> - EPIPCameraType pip_type ; <nl> - bool visibilityChanged = false ; <nl> - / / TODO : merge these two different types ? <nl> - switch ( imageType ) { <nl> - case DroneControllerBase : : ImageType : : Scene : <nl> - pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_SCENE ; <nl> - if ( ! hud - > isPIPSceneVisible ( ) ) { <nl> - hud - > inputEventTogglePIPScene ( ) ; <nl> - visibilityChanged = true ; <nl> - } <nl> - break ; <nl> - case DroneControllerBase : : ImageType : : Depth : <nl> - pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_DEPTH ; <nl> - if ( ! hud - > isPIPDepthVisible ( ) ) { <nl> - hud - > inputEventTogglePIPDepth ( ) ; <nl> - visibilityChanged = true ; <nl> - } <nl> - break ; <nl> - case DroneControllerBase : : ImageType : : Segmentation : <nl> - pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_SEG ; <nl> - if ( ! hud - > isPIPSegVisible ( ) ) { <nl> - hud - > inputEventTogglePIPSeg ( ) ; <nl> - visibilityChanged = true ; <nl> - } <nl> - break ; <nl> - default : <nl> - pip_type = EPIPCameraType : : PIP_CAMERA_TYPE_NONE ; <nl> - } <nl> + private : <nl> + bool getScreenshotScreen ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) ; <nl> + bool getScreenshotSceneCapture ( DroneControllerBase : : ImageType imageType , std : : vector < uint8_t > & compressedPng ) ; <nl> + void addScreenCaptureHandler ( UWorld * world ) ; <nl> <nl> - if ( visibilityChanged ) { <nl> - / / Wait for render so that view is ready for capture <nl> - std : : this_thread : : sleep_for ( std : : chrono : : duration < double > ( 0 . 2 ) ) ; <nl> - / / not sure why this doesn ' t work . <nl> - / / DECLARE_CYCLE_STAT ( TEXT ( " FNullGraphTask . CheckRenderStatus " ) , STAT_FNullGraphTask_CheckRenderStatus , STATGROUP_TaskGraphTasks ) ; <nl> - / / auto renderStatus = TGraphTask < FNullGraphTask > : : CreateTask ( NULL ) . ConstructAndDispatchWhenReady ( GET_STATID ( STAT_FNullGraphTask_CheckRenderStatus ) , ENamedThreads : : RenderThread ) ; <nl> - / / FTaskGraphInterface : : Get ( ) . WaitUntilTaskCompletes ( renderStatus ) ; <nl> - } <nl> - <nl> - using namespace msr : : airlib ; <nl> - USceneCaptureComponent2D * capture = camera - > getCaptureComponent ( pip_type , true ) ; <nl> - if ( capture = = nullptr ) { <nl> - UAirBlueprintLib : : LogMessage ( TEXT ( " Can ' t take screenshot because eithercamera type is not active " ) , TEXT ( " " ) , LogDebugLevel : : Failure ) ; <nl> - return false ; <nl> - } <nl> - <nl> - if ( capture - > TextureTarget = = nullptr ) { <nl> - UAirBlueprintLib : : LogMessage ( TEXT ( " Can ' t take screenshot because texture target is null " ) , TEXT ( " " ) , LogDebugLevel : : Failure ) ; <nl> - return false ; <nl> - } <nl> - <nl> - UTextureRenderTarget2D * textureTarget = capture - > TextureTarget ; <nl> - <nl> - TArray < uint8 > image ; <nl> - RenderRequest request ; <nl> - request . getScreenshot ( textureTarget , image ) ; <nl> - <nl> - / / copy data across to std : : vector . <nl> - compressedPng = std : : vector < uint8_t > ( image . GetData ( ) , image . GetData ( ) + image . Num ( ) ) ; <nl> - return true ; <nl> - } <nl> + private : <nl> + APIPCamera * camera ; <nl> + int id ; <nl> + std : : vector < uint8_t > last_compressed_png_ ; <nl> } ; <nl> \ No newline at end of file <nl>
added screenshot ability ( untested )
microsoft/AirSim
48416922b8978bc0b226cee6c5e4832a5c5aa8aa
2017-06-27T07:50:37Z
mmm a / docker / test / integration / Dockerfile <nl> ppp b / docker / test / integration / Dockerfile <nl> <nl> # docker build - t yandex / clickhouse - integration - test . <nl> - FROM ubuntu : 18 . 04 <nl> - <nl> - RUN echo " deb [ trusted = yes ] http : / / apt . llvm . org / bionic / llvm - toolchain - bionic - 8 main " > > / etc / apt / sources . list <nl> + FROM ubuntu : 19 . 10 <nl> <nl> RUN apt - get update \ <nl> & & env DEBIAN_FRONTEND = noninteractive apt - get - y install \ <nl> RUN apt - get update \ <nl> libreadline - dev \ <nl> libicu - dev \ <nl> bsdutils \ <nl> - llvm - 8 \ <nl> + llvm - 9 \ <nl> gdb \ <nl> unixodbc \ <nl> odbcinst \ <nl> RUN ln - snf / usr / share / zoneinfo / $ TZ / etc / localtime & & echo $ TZ > / etc / timezone <nl> RUN echo " TSAN_OPTIONS = ' verbosity = 1000 halt_on_error = 1 history_size = 7 ' " > > / etc / environment ; \ <nl> echo " UBSAN_OPTIONS = ' print_stacktrace = 1 ' " > > / etc / environment ; \ <nl> echo " MSAN_OPTIONS = ' abort_on_error = 1 ' " > > / etc / environment ; \ <nl> - ln - s / usr / lib / llvm - 8 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; <nl> + ln - s / usr / lib / llvm - 9 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; <nl> mmm a / docker / test / stateful / Dockerfile <nl> ppp b / docker / test / stateful / Dockerfile <nl> RUN apt - get update - y \ <nl> & & env DEBIAN_FRONTEND = noninteractive \ <nl> apt - get install - - yes - - no - install - recommends \ <nl> python - requests \ <nl> - llvm - 8 <nl> + llvm - 9 <nl> <nl> COPY s3downloader / s3downloader <nl> <nl> CMD dpkg - i package_folder / clickhouse - common - static_ * . deb ; \ <nl> ln - s / usr / share / clickhouse - test / config / strings_dictionary . xml / etc / clickhouse - server / ; \ <nl> ln - s / usr / share / clickhouse - test / config / decimals_dictionary . xml / etc / clickhouse - server / ; \ <nl> ln - s / usr / share / clickhouse - test / config / macros . xml / etc / clickhouse - server / config . d / ; \ <nl> - ln - s / usr / lib / llvm - 8 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; \ <nl> + ln - s / usr / lib / llvm - 9 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; \ <nl> echo " TSAN_OPTIONS = ' verbosity = 1000 halt_on_error = 1 history_size = 7 ' " > > / etc / environment ; \ <nl> echo " TSAN_SYMBOLIZER_PATH = / usr / lib / llvm - 8 / bin / llvm - symbolizer " > > / etc / environment ; \ <nl> echo " UBSAN_OPTIONS = ' print_stacktrace = 1 ' " > > / etc / environment ; \ <nl> mmm a / docker / test / stateless / Dockerfile <nl> ppp b / docker / test / stateless / Dockerfile <nl> RUN apt - get update - y \ <nl> brotli \ <nl> gdb \ <nl> lsof \ <nl> - llvm - 8 \ <nl> + llvm - 9 \ <nl> unixodbc \ <nl> wget <nl> <nl> RUN ln - snf / usr / share / zoneinfo / $ TZ / etc / localtime & & echo $ TZ > / etc / timezone <nl> RUN echo " TSAN_OPTIONS = ' verbosity = 1000 halt_on_error = 1 history_size = 7 ' " > > / etc / environment ; \ <nl> echo " UBSAN_OPTIONS = ' print_stacktrace = 1 ' " > > / etc / environment ; \ <nl> echo " MSAN_OPTIONS = ' abort_on_error = 1 ' " > > / etc / environment ; \ <nl> - ln - s / usr / lib / llvm - 8 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; <nl> + ln - s / usr / lib / llvm - 9 / bin / llvm - symbolizer / usr / bin / llvm - symbolizer ; <nl> <nl> CMD dpkg - i package_folder / clickhouse - common - static_ * . deb ; \ <nl> dpkg - i package_folder / clickhouse - common - static - dbg_ * . deb ; \ <nl>
Bump llvm tools to 9
ClickHouse/ClickHouse
049b86ff7d419af5ba2eccb3aa849a81322f042d
2020-03-25T12:12:03Z
mmm a / include / swift / AST / Expr . h <nl> ppp b / include / swift / AST / Expr . h <nl> class alignas ( 8 ) Expr { <nl> NumConformances : 32 <nl> ) ; <nl> <nl> + SWIFT_INLINE_BITFIELD_FULL ( UnresolvedSpecializeExpr , Expr , 32 , <nl> + : NumPadBits , <nl> + NumUnresolvedParams : 32 <nl> + ) ; <nl> + <nl> SWIFT_INLINE_BITFIELD ( ApplyExpr , Expr , 1 + 1 , <nl> ThrowsIsSet : 1 , <nl> Throws : 1 <nl> class alignas ( 8 ) Expr { <nl> SWIFT_INLINE_BITS ( SequenceExpr ) ; <nl> SWIFT_INLINE_BITS ( CollectionExpr ) ; <nl> SWIFT_INLINE_BITS ( ErasureExpr ) ; <nl> + SWIFT_INLINE_BITS ( UnresolvedSpecializeExpr ) ; <nl> } Bits ; <nl> <nl> private : <nl> class BridgeToObjCExpr : public ImplicitConversionExpr { <nl> <nl> / / / UnresolvedSpecializeExpr - Represents an explicit specialization using <nl> / / / a type parameter list ( e . g . " Vector < Int > " ) that has not been resolved . <nl> - class UnresolvedSpecializeExpr : public Expr { <nl> + class UnresolvedSpecializeExpr final : public Expr , <nl> + private llvm : : TrailingObjects < UnresolvedSpecializeExpr , TypeLoc > { <nl> + friend TrailingObjects ; <nl> + <nl> Expr * SubExpr ; <nl> SourceLoc LAngleLoc ; <nl> SourceLoc RAngleLoc ; <nl> - MutableArrayRef < TypeLoc > UnresolvedParams ; <nl> - public : <nl> + <nl> UnresolvedSpecializeExpr ( Expr * SubExpr , <nl> SourceLoc LAngleLoc , <nl> - MutableArrayRef < TypeLoc > UnresolvedParams , <nl> + ArrayRef < TypeLoc > UnresolvedParams , <nl> SourceLoc RAngleLoc ) <nl> : Expr ( ExprKind : : UnresolvedSpecialize , / * Implicit = * / false ) , <nl> - SubExpr ( SubExpr ) , <nl> - LAngleLoc ( LAngleLoc ) , RAngleLoc ( RAngleLoc ) , <nl> - UnresolvedParams ( UnresolvedParams ) { } <nl> + SubExpr ( SubExpr ) , LAngleLoc ( LAngleLoc ) , RAngleLoc ( RAngleLoc ) { <nl> + Bits . UnresolvedSpecializeExpr . NumUnresolvedParams = UnresolvedParams . size ( ) ; <nl> + std : : uninitialized_copy ( UnresolvedParams . begin ( ) , UnresolvedParams . end ( ) , <nl> + getTrailingObjects < TypeLoc > ( ) ) ; <nl> + } <nl> + <nl> + public : <nl> + static UnresolvedSpecializeExpr * <nl> + create ( ASTContext & ctx , Expr * SubExpr , SourceLoc LAngleLoc , <nl> + ArrayRef < TypeLoc > UnresolvedParams , SourceLoc RAngleLoc ) ; <nl> <nl> Expr * getSubExpr ( ) const { return SubExpr ; } <nl> void setSubExpr ( Expr * e ) { SubExpr = e ; } <nl> <nl> / / / \ brief Retrieve the list of type parameters . These parameters have not yet <nl> / / / been bound to archetypes of the entity to be specialized . <nl> - ArrayRef < TypeLoc > getUnresolvedParams ( ) const { return UnresolvedParams ; } <nl> - MutableArrayRef < TypeLoc > getUnresolvedParams ( ) { return UnresolvedParams ; } <nl> + ArrayRef < TypeLoc > getUnresolvedParams ( ) const { <nl> + return { getTrailingObjects < TypeLoc > ( ) , <nl> + Bits . UnresolvedSpecializeExpr . NumUnresolvedParams } ; <nl> + } <nl> + MutableArrayRef < TypeLoc > getUnresolvedParams ( ) { <nl> + return { getTrailingObjects < TypeLoc > ( ) , <nl> + Bits . UnresolvedSpecializeExpr . NumUnresolvedParams } ; <nl> + } <nl> <nl> SourceLoc getLoc ( ) const { return LAngleLoc ; } <nl> SourceLoc getLAngleLoc ( ) const { return LAngleLoc ; } <nl> mmm a / lib / AST / Expr . cpp <nl> ppp b / lib / AST / Expr . cpp <nl> ErasureExpr * ErasureExpr : : create ( ASTContext & ctx , Expr * subExpr , Type type , <nl> return : : new ( mem ) ErasureExpr ( subExpr , type , conformances ) ; <nl> } <nl> <nl> + UnresolvedSpecializeExpr * UnresolvedSpecializeExpr : : create ( ASTContext & ctx , <nl> + Expr * SubExpr , SourceLoc LAngleLoc , <nl> + ArrayRef < TypeLoc > UnresolvedParams , <nl> + SourceLoc RAngleLoc ) { <nl> + auto size = totalSizeToAlloc < TypeLoc > ( UnresolvedParams . size ( ) ) ; <nl> + auto mem = ctx . Allocate ( size , alignof ( UnresolvedSpecializeExpr ) ) ; <nl> + return : : new ( mem ) UnresolvedSpecializeExpr ( SubExpr , LAngleLoc , <nl> + UnresolvedParams , RAngleLoc ) ; <nl> + } <nl> + <nl> SourceRange TupleExpr : : getSourceRange ( ) const { <nl> SourceLoc start = SourceLoc ( ) ; <nl> SourceLoc end = SourceLoc ( ) ; <nl> mmm a / lib / Parse / ParseExpr . cpp <nl> ppp b / lib / Parse / ParseExpr . cpp <nl> Parser : : parseExprPostfixSuffix ( ParserResult < Expr > Result , bool isExprBasic , <nl> SmallVector < TypeLoc , 8 > locArgs ; <nl> for ( auto ty : args ) <nl> locArgs . push_back ( ty ) ; <nl> - Result = makeParserResult ( new ( Context ) UnresolvedSpecializeExpr ( <nl> - Result . get ( ) , LAngleLoc , Context . AllocateCopy ( locArgs ) , RAngleLoc ) ) ; <nl> + Result = makeParserResult ( UnresolvedSpecializeExpr : : create ( Context , <nl> + Result . get ( ) , LAngleLoc , locArgs , RAngleLoc ) ) ; <nl> } <nl> <nl> continue ; <nl> Expr * Parser : : parseExprIdentifier ( ) { <nl> SmallVector < TypeLoc , 8 > locArgs ; <nl> for ( auto ty : args ) <nl> locArgs . push_back ( ty ) ; <nl> - E = new ( Context ) UnresolvedSpecializeExpr ( E , LAngleLoc , <nl> - Context . AllocateCopy ( locArgs ) , <nl> - RAngleLoc ) ; <nl> + E = UnresolvedSpecializeExpr : : create ( Context , E , LAngleLoc , locArgs , <nl> + RAngleLoc ) ; <nl> } <nl> return E ; <nl> } <nl>
[ AST ] NFC : Tail allocate UnresolvedSpecializeExpr TypeLocs
apple/swift
5a4e96fcc23691319e7abbdfc522f7046fa7e4bf
2017-12-20T14:35:15Z
mmm a / test / test_jit . py <nl> ppp b / test / test_jit . py <nl> def foo ( ) : <nl> <nl> self . checkScript ( foo , ( ) ) <nl> <nl> + def test_string_sort ( self ) : <nl> + @ torch . jit . script <nl> + def foo ( strs : List [ str ] ) : <nl> + return sorted ( strs ) <nl> + <nl> + inputs = [ " str3 " , " str2 " , " str1 " ] <nl> + self . assertEqual ( foo ( inputs ) , sorted ( inputs ) ) <nl> + <nl> def test_string_new_line ( self ) : <nl> with self . assertRaisesRegex ( RuntimeError , " expected a valid token * " ) : <nl> torch . jit . CompilationUnit ( ' ' ' <nl> mmm a / torch / csrc / jit / runtime / register_prim_ops_fulljit . cpp <nl> ppp b / torch / csrc / jit / runtime / register_prim_ops_fulljit . cpp <nl> RegisterOperators reg2 ( { <nl> " aten : : sort . bool ( bool [ ] ( a ! ) self , bool reverse = False ) - > ( ) " , <nl> listSort < bool > , <nl> aliasAnalysisFromSchema ( ) ) , <nl> + Operator ( <nl> + " aten : : sort . str ( str [ ] ( a ! ) self , bool reverse = False ) - > ( ) " , <nl> + listSort < std : : string > , <nl> + aliasAnalysisFromSchema ( ) ) , <nl> Operator ( <nl> " aten : : sorted . int ( int [ ] ( a ) input ) - > ( int [ ] ) " , <nl> listCopyAndSort < int64_t > , <nl> RegisterOperators reg2 ( { <nl> " aten : : sorted . bool ( bool [ ] ( a ) input ) - > ( bool [ ] ) " , <nl> listCopyAndSort < bool > , <nl> aliasAnalysisFromSchema ( ) ) , <nl> + Operator ( <nl> + " aten : : sorted . str ( str [ ] ( a ) input ) - > ( bool [ ] ) " , <nl> + listCopyAndSort < std : : string > , <nl> + aliasAnalysisFromSchema ( ) ) , <nl> + <nl> Operator ( <nl> " aten : : eq . float_list ( float [ ] a , float [ ] b ) - > bool " , <nl> listEq < double > , <nl> Function * checkSortSchema ( const c10 : : TypePtr & list_element_type ) { <nl> < < " returns a bool " ; <nl> } else { <nl> error_str < < " To sort a list of " < < list_element_type - > repr_str ( ) <nl> - < < " must be of Tensors , ints , floats , bools or " <nl> + < < " must be of Tensors , ints , floats , bools , strs or " <nl> < < " a User Defined Class that defines the __lt__ compare method " <nl> < < " , got list of " < < list_element_type - > repr_str ( ) < < " \ n " ; <nl> } <nl>
Implement sort for string in aten ( )
pytorch/pytorch
317b9d3bfcd87113386bf7e3d4db588d2a548544
2020-08-04T22:25:35Z
mmm a / scripts / eosio_build_amazon . sh <nl> ppp b / scripts / eosio_build_amazon . sh <nl> <nl> bzip2 - devel . x86_64 openssl - devel . x86_64 gmp - devel . x86_64 libstdc + + 72 . x86_64 \ <nl> python27 . x86_64 python36 - devel . x86_64 libedit - devel . x86_64 doxygen . x86_64 graphviz . x86_64 ) <nl> else <nl> - DEP_ARRAY = ( git gcc . x86_64 gcc - c + + . x86_64 autoconf automake libtool make bzip2 \ <nl> - bzip2 - devel . x86_64 openssl - devel . x86_64 gmp - devel . x86_64 libstdc + + . x86_64 \ <nl> - python3 . x86_64 python3 - devel . x86_64 libedit - devel . x86_64 doxygen . x86_64 graphviz . x86_64 ) <nl> + DEP_ARRAY = ( git gcc gcc - c + + autoconf automake libtool make bzip2 \ <nl> + bzip2 - devel openssl - devel gmp - devel libstdc + + \ <nl> + python3 python3 - devel libedit - devel doxygen graphviz ) <nl> fi <nl> COUNT = 1 <nl> DISPLAY = " " <nl>
remove x86_64 arch dep specification on AMI2 build script
EOSIO/eos
bdebb506021454c157269ab95f6e581cecf49408
2018-12-05T15:31:21Z
mmm a / dbms / src / Storages / MergeTree / MergeList . cpp <nl> ppp b / dbms / src / Storages / MergeTree / MergeList . cpp <nl> MergeListElement : : MergeListElement ( const std : : string & database , const std : : stri <nl> if ( ! source_parts . empty ( ) ) <nl> partition_id = source_parts [ 0 ] - > info . partition_id ; <nl> <nl> + num_parts = source_parts . size ( ) ; <nl> + <nl> + for ( const MergeTreeData : : DataPartPtr & part : source_parts ) <nl> + { <nl> + std : : shared_lock < std : : shared_mutex > part_lock ( part - > columns_lock ) ; <nl> + <nl> + total_size_bytes_compressed + = part - > bytes_on_disk ; <nl> + total_size_marks + = part - > marks_count ; <nl> + } <nl> + <nl> / / / Each merge is executed into separate background processing pool thread <nl> background_thread_memory_tracker = & CurrentThread : : getMemoryTracker ( ) ; <nl> if ( background_thread_memory_tracker ) <nl> mmm a / dbms / src / Storages / MergeTree / MergeTreeDataMergerMutator . cpp <nl> ppp b / dbms / src / Storages / MergeTree / MergeTreeDataMergerMutator . cpp <nl> class ColumnSizeEstimator <nl> sum_total = std : : max ( static_cast < decltype ( sum_index_columns ) > ( 1 ) , sum_index_columns + sum_ordinary_columns ) ; <nl> } <nl> <nl> - / / / Approximate size of num_rows column elements if column contains num_total_rows elements <nl> - Float64 columnSize ( const String & column , size_t num_rows , size_t num_total_rows ) const <nl> + Float64 columnWeight ( const String & column ) const <nl> { <nl> - return static_cast < Float64 > ( map . at ( column ) ) / num_total_rows * num_rows ; <nl> + return static_cast < Float64 > ( map . at ( column ) ) / sum_total ; <nl> } <nl> <nl> - / / / Relative size of num_rows column elements ( in comparison with overall size of all columns ) if column contains num_total_rows elements <nl> - Float64 columnProgress ( const String & column , size_t num_rows , size_t num_total_rows ) const <nl> + Float64 keyColumnsWeight ( ) const <nl> { <nl> - return columnSize ( column , num_rows , num_total_rows ) / sum_total ; <nl> + return static_cast < Float64 > ( sum_index_columns ) / sum_total ; <nl> } <nl> + } ; <nl> <nl> - / / / Like columnSize , but takes into account only PK columns <nl> - Float64 keyColumnsSize ( size_t num_rows , size_t num_total_rows ) const <nl> + / * * Progress callback . <nl> + * What it should update : <nl> + * - approximate progress <nl> + * - amount of read rows <nl> + * - various metrics <nl> + * - time elapsed for current merge . <nl> + * / <nl> + <nl> + / / / Auxilliary struct that for each merge stage stores its current progress . <nl> + / / / A stage is : the horizontal stage + a stage for each gathered column ( if we are doing a <nl> + / / / Vertical merge ) or a mutation of a single part . During a single stage all rows are read . <nl> + struct MergeStageProgress <nl> + { <nl> + MergeStageProgress ( Float64 weight_ ) <nl> + : is_first ( true ) , weight ( weight_ ) <nl> { <nl> - return static_cast < Float64 > ( sum_index_columns ) / num_total_rows * num_rows ; <nl> } <nl> <nl> - / / / Like columnProgress , but takes into account only PK columns <nl> - Float64 keyColumnsProgress ( size_t num_rows , size_t num_total_rows ) const <nl> + MergeStageProgress ( Float64 initial_progress_ , Float64 weight_ ) <nl> + : initial_progress ( initial_progress_ ) , is_first ( false ) , weight ( weight_ ) <nl> { <nl> - return keyColumnsSize ( num_rows , num_total_rows ) / sum_total ; <nl> } <nl> + <nl> + Float64 initial_progress = 0 . 0 ; <nl> + bool is_first ; <nl> + Float64 weight ; <nl> + <nl> + UInt64 total_rows = 0 ; <nl> + UInt64 rows_read = 0 ; <nl> } ; <nl> <nl> - / * * Progress callback . Is used by Horizontal merger and first step of Vertical merger . <nl> - * What it should update : <nl> - * - approximate progress <nl> - * - amount of merged rows and their size ( PK columns subset is used in case of Vertical merge ) <nl> - * - time elapsed for current merge . <nl> - * / <nl> class MergeProgressCallback <nl> { <nl> public : <nl> - MergeProgressCallback ( MergeList : : Entry & merge_entry_ , UInt64 & watch_prev_elapsed_ ) <nl> - : merge_entry ( merge_entry_ ) , watch_prev_elapsed ( watch_prev_elapsed_ ) { } <nl> - <nl> - MergeProgressCallback ( MergeList : : Entry & merge_entry_ , size_t num_total_rows , const ColumnSizeEstimator & column_sizes , <nl> - UInt64 & watch_prev_elapsed_ , MergeTreeDataMergerMutator : : MergeAlgorithm merge_alg_ = MergeAlgorithm : : Vertical ) <nl> - : merge_entry ( merge_entry_ ) , watch_prev_elapsed ( watch_prev_elapsed_ ) , merge_alg ( merge_alg_ ) <nl> + MergeProgressCallback ( <nl> + MergeList : : Entry & merge_entry_ , UInt64 & watch_prev_elapsed_ , MergeStageProgress & stage_ ) <nl> + : merge_entry ( merge_entry_ ) <nl> + , watch_prev_elapsed ( watch_prev_elapsed_ ) <nl> + , stage ( stage_ ) <nl> { <nl> - if ( num_total_rows ) <nl> - { <nl> - average_elem_progress = ( merge_alg = = MergeAlgorithm : : Horizontal ) <nl> - ? 1 . 0 / num_total_rows <nl> - : column_sizes . keyColumnsProgress ( 1 , num_total_rows ) ; <nl> - } <nl> - <nl> updateWatch ( ) ; <nl> } <nl> <nl> MergeList : : Entry & merge_entry ; <nl> UInt64 & watch_prev_elapsed ; <nl> - Float64 average_elem_progress = 0 ; <nl> - const MergeAlgorithm merge_alg { MergeAlgorithm : : Vertical } ; <nl> + MergeStageProgress & stage ; <nl> <nl> void updateWatch ( ) <nl> { <nl> class MergeProgressCallback <nl> void operator ( ) ( const Progress & value ) <nl> { <nl> ProfileEvents : : increment ( ProfileEvents : : MergedUncompressedBytes , value . bytes ) ; <nl> - ProfileEvents : : increment ( ProfileEvents : : MergedRows , value . rows ) ; <nl> + if ( stage . is_first ) <nl> + ProfileEvents : : increment ( ProfileEvents : : MergedRows , value . rows ) ; <nl> updateWatch ( ) ; <nl> <nl> merge_entry - > bytes_read_uncompressed + = value . bytes ; <nl> - merge_entry - > rows_read + = value . rows ; <nl> - merge_entry - > progress . store ( average_elem_progress * merge_entry - > rows_read , std : : memory_order_relaxed ) ; <nl> - } <nl> - } ; <nl> - <nl> - / * * Progress callback for gathering step of Vertical merge . <nl> - * Updates : approximate progress , amount of merged bytes ( TODO : two column case should be fixed ) , elapsed time . <nl> - * / <nl> - class MergeProgressCallbackVerticalStep : public MergeProgressCallback <nl> - { <nl> - public : <nl> - MergeProgressCallbackVerticalStep ( MergeList : : Entry & merge_entry_ , size_t num_total_rows_exact , <nl> - const ColumnSizeEstimator & column_sizes , const String & column_name , UInt64 & watch_prev_elapsed_ ) <nl> - : MergeProgressCallback ( merge_entry_ , watch_prev_elapsed_ ) , initial_progress ( merge_entry - > progress . load ( std : : memory_order_relaxed ) ) <nl> - { <nl> - average_elem_progress = column_sizes . columnProgress ( column_name , 1 , num_total_rows_exact ) ; <nl> - updateWatch ( ) ; <nl> - } <nl> + if ( stage . is_first ) <nl> + merge_entry - > rows_read + = value . rows ; <nl> <nl> - Float64 initial_progress ; <nl> - size_t rows_read_internal { 0 } ; / / NOTE : not thread safe ( to be copyable ) . It is OK in current single thread use case <nl> - <nl> - void operator ( ) ( const Progress & value ) <nl> - { <nl> - merge_entry - > bytes_read_uncompressed + = value . bytes ; <nl> - ProfileEvents : : increment ( ProfileEvents : : MergedUncompressedBytes , value . bytes ) ; <nl> - updateWatch ( ) ; <nl> - <nl> - rows_read_internal + = value . rows ; <nl> - Float64 local_progress = average_elem_progress * rows_read_internal ; <nl> - <nl> - / / / NOTE : ' progress ' is modified by single thread , but it may be concurrently read from MergeListElement : : getInfo ( ) ( StorageSystemMerges ) . <nl> - merge_entry - > progress . store ( initial_progress + local_progress , std : : memory_order_relaxed ) ; <nl> + stage . total_rows + = value . total_rows ; <nl> + stage . rows_read + = value . rows ; <nl> + if ( stage . total_rows > 0 ) <nl> + { <nl> + merge_entry - > progress . store ( <nl> + stage . initial_progress + stage . weight * stage . rows_read / stage . total_rows , <nl> + std : : memory_order_relaxed ) ; <nl> + } <nl> } <nl> } ; <nl> <nl> - <nl> / / / parts should be sorted . <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTemporaryPart ( <nl> const FuturePart & future_part , MergeList : : Entry & merge_entry , <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> if ( Poco : : File ( new_part_tmp_path ) . exists ( ) ) <nl> throw Exception ( " Directory " + new_part_tmp_path + " already exists " , ErrorCodes : : DIRECTORY_ALREADY_EXISTS ) ; <nl> <nl> - merge_entry - > num_parts = parts . size ( ) ; <nl> - <nl> - for ( const MergeTreeData : : DataPartPtr & part : parts ) <nl> - { <nl> - std : : shared_lock < std : : shared_mutex > part_lock ( part - > columns_lock ) ; <nl> - <nl> - merge_entry - > total_size_bytes_compressed + = part - > bytes_on_disk ; <nl> - merge_entry - > total_size_marks + = part - > marks_count ; <nl> - } <nl> - <nl> MergeTreeData : : DataPart : : ColumnToSize merged_column_to_size ; <nl> for ( const MergeTreeData : : DataPartPtr & part : parts ) <nl> part - > accumulateColumnSizes ( merged_column_to_size ) ; <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> } <nl> } <nl> <nl> - <nl> + MergeStageProgress horizontal_stage_progress ( <nl> + merge_alg = = MergeAlgorithm : : Horizontal ? 1 . 0 : column_sizes . keyColumnsWeight ( ) ) ; <nl> for ( const auto & part : parts ) <nl> { <nl> auto input = std : : make_unique < MergeTreeSequentialBlockInputStream > ( <nl> data , part , merging_column_names , read_with_direct_io , true ) ; <nl> <nl> - input - > setProgressCallback ( MergeProgressCallback ( <nl> - merge_entry , sum_input_rows_upper_bound , column_sizes , watch_prev_elapsed , merge_alg ) ) ; <nl> + input - > setProgressCallback ( <nl> + MergeProgressCallback ( merge_entry , watch_prev_elapsed , horizontal_stage_progress ) ) ; <nl> <nl> if ( data . hasPrimaryKey ( ) ) <nl> src_streams . emplace_back ( std : : make_shared < MaterializingBlockInputStream > ( <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> { <nl> size_t sum_input_rows_exact = merge_entry - > rows_read ; <nl> merge_entry - > columns_written = merging_column_names . size ( ) ; <nl> - merge_entry - > progress . store ( column_sizes . keyColumnsProgress ( sum_input_rows_exact , sum_input_rows_exact ) , std : : memory_order_relaxed ) ; <nl> + merge_entry - > progress . store ( column_sizes . keyColumnsWeight ( ) , std : : memory_order_relaxed ) ; <nl> <nl> BlockInputStreams column_part_streams ( parts . size ( ) ) ; <nl> <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> Names column_names { column_name } ; <nl> Float64 progress_before = merge_entry - > progress . load ( std : : memory_order_relaxed ) ; <nl> <nl> + MergeStageProgress column_progress ( progress_before , column_sizes . columnWeight ( column_name ) ) ; <nl> for ( size_t part_num = 0 ; part_num < parts . size ( ) ; + + part_num ) <nl> { <nl> auto column_part_stream = std : : make_shared < MergeTreeSequentialBlockInputStream > ( <nl> data , parts [ part_num ] , column_names , read_with_direct_io , true ) ; <nl> <nl> - column_part_stream - > setProgressCallback ( MergeProgressCallbackVerticalStep ( <nl> - merge_entry , sum_input_rows_exact , column_sizes , column_name , watch_prev_elapsed ) ) ; <nl> + column_part_stream - > setProgressCallback ( <nl> + MergeProgressCallback ( merge_entry , watch_prev_elapsed , column_progress ) ) ; <nl> <nl> column_part_streams [ part_num ] = std : : move ( column_part_stream ) ; <nl> } <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> <nl> / / / NOTE : ' progress ' is modified by single thread , but it may be concurrently read from MergeListElement : : getInfo ( ) ( StorageSystemMerges ) . <nl> <nl> - merge_entry - > columns_written = merging_column_names . size ( ) + column_num ; <nl> + merge_entry - > columns_written + = 1 ; <nl> merge_entry - > bytes_written_uncompressed + = column_gathered_stream . getProfileInfo ( ) . bytes ; <nl> - merge_entry - > progress . store ( progress_before + column_sizes . columnProgress ( column_name , sum_input_rows_exact , sum_input_rows_exact ) , std : : memory_order_relaxed ) ; <nl> + merge_entry - > progress . store ( progress_before + column_sizes . columnWeight ( column_name ) , std : : memory_order_relaxed ) ; <nl> <nl> if ( actions_blocker . isCancelled ( ) ) <nl> throw Exception ( " Cancelled merging parts " , ErrorCodes : : ABORTED ) ; <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mergePartsToTempor <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTemporaryPart ( <nl> const FuturePart & future_part , <nl> const std : : vector < MutationCommand > & commands , <nl> + MergeListEntry & merge_entry , <nl> const Context & context ) <nl> { <nl> auto check_not_cancelled = [ & ] ( ) <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTempor <nl> <nl> Block in_header = in - > getHeader ( ) ; <nl> <nl> + UInt64 watch_prev_elapsed = 0 ; <nl> + MergeStageProgress stage_progress ( 1 . 0 ) ; <nl> + in - > setProgressCallback ( MergeProgressCallback ( merge_entry , watch_prev_elapsed , stage_progress ) ) ; <nl> + <nl> if ( in_header . columns ( ) = = all_columns . size ( ) ) <nl> { <nl> / / / All columns are modified , proceed to write a new part from scratch . <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTempor <nl> { <nl> minmax_idx . update ( block , data . minmax_idx_columns ) ; <nl> out . write ( block ) ; <nl> + <nl> + merge_entry - > rows_written + = block . rows ( ) ; <nl> + merge_entry - > bytes_written_uncompressed + = block . bytes ( ) ; <nl> } <nl> <nl> new_data_part - > partition . assign ( source_part - > partition ) ; <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTempor <nl> createHardLink ( dir_it . path ( ) . toString ( ) , destination . toString ( ) ) ; <nl> } <nl> <nl> + merge_entry - > columns_written = all_columns . size ( ) - in_header . columns ( ) ; <nl> + <nl> IMergedBlockOutputStream : : WrittenOffsetColumns unused_written_offsets ; <nl> MergedColumnOnlyOutputStream out ( <nl> data , in_header , new_part_tmp_path , / * sync = * / false , compression_codec , / * skip_offsets = * / false , unused_written_offsets ) ; <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTempor <nl> <nl> Block block ; <nl> while ( check_not_cancelled ( ) & & ( block = in - > read ( ) ) ) <nl> + { <nl> out . write ( block ) ; <nl> <nl> + merge_entry - > rows_written + = block . rows ( ) ; <nl> + merge_entry - > bytes_written_uncompressed + = block . bytes ( ) ; <nl> + } <nl> + <nl> in - > readSuffix ( ) ; <nl> auto changed_checksums = out . writeSuffixAndGetChecksums ( ) ; <nl> <nl> mmm a / dbms / src / Storages / MergeTree / MergeTreeDataMergerMutator . h <nl> ppp b / dbms / src / Storages / MergeTree / MergeTreeDataMergerMutator . h <nl> class MergeTreeDataMergerMutator <nl> MergeTreeData : : MutableDataPartPtr mutatePartToTemporaryPart ( <nl> const FuturePart & future_part , <nl> const std : : vector < MutationCommand > & commands , <nl> - const Context & context ) ; <nl> + MergeListEntry & merge_entry , const Context & context ) ; <nl> <nl> MergeTreeData : : DataPartPtr renameMergedTemporaryPart ( <nl> MergeTreeData : : MutableDataPartPtr & new_data_part , <nl> mmm a / dbms / src / Storages / StorageMergeTree . cpp <nl> ppp b / dbms / src / Storages / StorageMergeTree . cpp <nl> bool StorageMergeTree : : tryMutatePart ( ) <nl> if ( ! tagger ) <nl> return false ; <nl> <nl> + MergeList : : EntryPtr merge_entry = global_context . getMergeList ( ) . insert ( database_name , table_name , future_part . name , future_part . parts ) ; <nl> + <nl> Stopwatch stopwatch ; <nl> MergeTreeData : : MutableDataPartPtr new_part ; <nl> <nl> bool StorageMergeTree : : tryMutatePart ( ) <nl> part_log_elem . table_name = table_name ; <nl> part_log_elem . part_name = future_part . name ; <nl> <nl> + part_log_elem . rows_read = ( * merge_entry ) - > rows_read ; <nl> + part_log_elem . bytes_read_uncompressed = ( * merge_entry ) - > bytes_read_uncompressed ; <nl> + <nl> + part_log_elem . rows = ( * merge_entry ) - > rows_written ; <nl> + part_log_elem . bytes_uncompressed = ( * merge_entry ) - > bytes_written_uncompressed ; <nl> + <nl> if ( new_part ) <nl> - { <nl> part_log_elem . bytes_compressed_on_disk = new_part - > bytes_on_disk ; <nl> - part_log_elem . rows = new_part - > rows_count ; <nl> - } <nl> <nl> part_log_elem . source_part_names . reserve ( future_part . parts . size ( ) ) ; <nl> for ( const auto & source_part : future_part . parts ) <nl> bool StorageMergeTree : : tryMutatePart ( ) <nl> <nl> try <nl> { <nl> - new_part = merger_mutator . mutatePartToTemporaryPart ( future_part , commands , global_context ) ; <nl> + new_part = merger_mutator . mutatePartToTemporaryPart ( future_part , commands , * merge_entry , global_context ) ; <nl> data . renameTempPartAndReplace ( new_part ) ; <nl> tagger - > is_successful = true ; <nl> write_part_log ( { } ) ; <nl> mmm a / dbms / src / Storages / StorageReplicatedMergeTree . cpp <nl> ppp b / dbms / src / Storages / StorageReplicatedMergeTree . cpp <nl> bool StorageReplicatedMergeTree : : tryExecutePartMutation ( const StorageReplicatedM <nl> future_mutated_part . part_info = new_part_info ; <nl> future_mutated_part . name = entry . new_part_name ; <nl> <nl> + MergeList : : EntryPtr merge_entry = global_context . getMergeList ( ) . insert ( <nl> + database_name , table_name , future_mutated_part . name , future_mutated_part . parts ) ; <nl> + <nl> Stopwatch stopwatch ; <nl> <nl> auto write_part_log = [ & ] ( const ExecutionStatus & execution_status ) <nl> { <nl> writePartLog ( <nl> PartLogElement : : MUTATE_PART , execution_status , stopwatch . elapsed ( ) , <nl> - entry . new_part_name , new_part , future_mutated_part . parts , nullptr ) ; <nl> + entry . new_part_name , new_part , future_mutated_part . parts , merge_entry . get ( ) ) ; <nl> } ; <nl> <nl> try <nl> { <nl> - new_part = merger_mutator . mutatePartToTemporaryPart ( future_mutated_part , commands , global_context ) ; <nl> + new_part = merger_mutator . mutatePartToTemporaryPart ( future_mutated_part , commands , * merge_entry , global_context ) ; <nl> data . renameTempPartAndReplace ( new_part , nullptr , & transaction ) ; <nl> <nl> try <nl>
system . merges element for mutations [ # CLICKHOUSE - 3912 ]
ClickHouse/ClickHouse
92a4342c31cd30f14b38f45763f444d84075a50b
2019-02-05T18:09:00Z
mmm a / src / Storages / MergeTree / MergeTreeBlockOutputStream . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeBlockOutputStream . cpp <nl> <nl> # include < Storages / MergeTree / MergeTreeBlockOutputStream . h > <nl> + # include < Storages / MergeTree / MergeTreeDataPartInMemory . h > <nl> # include < Storages / StorageMergeTree . h > <nl> # include < Interpreters / PartLog . h > <nl> <nl> void MergeTreeBlockOutputStream : : write ( const Block & block ) <nl> <nl> PartLog : : addNewPart ( storage . global_context , part , watch . elapsed ( ) ) ; <nl> <nl> - if ( isInMemoryPart ( part ) & & storage . getSettings ( ) - > in_memory_parts_insert_sync ) <nl> + if ( auto * part_in_memory = dynamic_cast < MergeTreeDataPartInMemory * > ( part . get ( ) ) ) <nl> { <nl> - if ( ! part - > waitUntilMerged ( in_memory_parts_timeout ) ) <nl> - throw Exception ( " Timeout exceeded while waiting to write part " <nl> - + part - > name + " on disk " , ErrorCodes : : TIMEOUT_EXCEEDED ) ; <nl> + storage . in_memory_merges_throttler . add ( part_in_memory - > block . bytes ( ) , part_in_memory - > rows_count ) ; <nl> + <nl> + auto settings = storage . getSettings ( ) ; <nl> + if ( settings - > in_memory_parts_insert_sync ) <nl> + { <nl> + if ( ! part - > waitUntilMerged ( in_memory_parts_timeout ) ) <nl> + throw Exception ( " Timeout exceeded while waiting to write part " <nl> + + part - > name + " on disk " , ErrorCodes : : TIMEOUT_EXCEEDED ) ; <nl> + } <nl> + else if ( storage . merging_mutating_task_handle & & ! storage . in_memory_merges_throttler . needDelayMerge ( ) ) <nl> + { <nl> + storage . in_memory_merges_throttler . reset ( ) ; <nl> + storage . merging_mutating_task_handle - > wake ( ) ; <nl> + } <nl> + <nl> + return ; <nl> } <nl> <nl> / / / Initiate async merge - it will be done if it ' s good time for merge and if there are space in ' background_pool ' . <nl> mmm a / src / Storages / MergeTree / MergeTreeData . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeData . cpp <nl> MergeTreeData : : MergeTreeData ( <nl> , data_parts_by_info ( data_parts_indexes . get < TagByInfo > ( ) ) <nl> , data_parts_by_state_and_info ( data_parts_indexes . get < TagByStateAndInfo > ( ) ) <nl> , parts_mover ( this ) <nl> + , in_memory_merges_throttler ( storage_settings . get ( ) - > min_bytes_for_compact_part , storage_settings . get ( ) - > min_rows_for_compact_part ) <nl> { <nl> if ( relative_data_path . empty ( ) ) <nl> throw Exception ( " MergeTree storages require data path " , ErrorCodes : : INCORRECT_FILE_NAME ) ; <nl> NamesAndTypesList MergeTreeData : : getVirtuals ( ) const <nl> NameAndTypePair ( " _sample_factor " , std : : make_shared < DataTypeFloat64 > ( ) ) , <nl> } ; <nl> } <nl> + <nl> + bool MergeTreeData : : MergesThrottler : : needDelayMerge ( ) const <nl> + { <nl> + std : : lock_guard lock ( mutex ) ; <nl> + return ( ! max_bytes | | have_bytes < max_bytes ) & & ( ! max_rows | | have_rows < max_rows ) ; <nl> + } <nl> + <nl> + void MergeTreeData : : MergesThrottler : : add ( size_t bytes , size_t rows ) <nl> + { <nl> + std : : lock_guard lock ( mutex ) ; <nl> + have_bytes + = bytes ; <nl> + have_rows + = rows ; <nl> + } <nl> + <nl> + void MergeTreeData : : MergesThrottler : : reset ( ) <nl> + { <nl> + have_bytes = 0 ; <nl> + have_rows = 0 ; <nl> + } <nl> + <nl> } <nl> mmm a / src / Storages / MergeTree / MergeTreeData . h <nl> ppp b / src / Storages / MergeTree / MergeTreeData . h <nl> class MergeTreeData : public IStorage <nl> <nl> bool areBackgroundMovesNeeded ( ) const ; <nl> <nl> + struct MergesThrottler <nl> + { <nl> + mutable std : : mutex mutex ; <nl> + size_t have_bytes = 0 ; <nl> + size_t have_rows = 0 ; <nl> + <nl> + size_t max_bytes ; <nl> + size_t max_rows ; <nl> + <nl> + MergesThrottler ( size_t max_bytes_ , size_t max_rows_ ) <nl> + : max_bytes ( max_bytes_ ) , max_rows ( max_rows_ ) { } <nl> + <nl> + bool needDelayMerge ( ) const ; <nl> + void add ( size_t bytes , size_t rows ) ; <nl> + void reset ( ) ; <nl> + } ; <nl> + <nl> + MergesThrottler in_memory_merges_throttler ; <nl> + <nl> private : <nl> / / / RAII Wrapper for atomic work with currently moving parts <nl> / / / Acuire them in constructor and remove them in destructor <nl> mmm a / src / Storages / MergeTree / MergeTreeDataMergerMutator . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeDataMergerMutator . cpp <nl> MergeTreeData : : MutableDataPartPtr MergeTreeDataMergerMutator : : mutatePartToTempor <nl> commands_for_part . emplace_back ( command ) ; <nl> } <nl> <nl> - if ( ! isStorageTouchedByMutations ( storage_from_source_part , commands_for_part , context_for_reading ) ) <nl> + if ( source_part - > isStoredOnDisk ( ) & & ! isStorageTouchedByMutations ( storage_from_source_part , commands_for_part , context_for_reading ) ) <nl> { <nl> LOG_TRACE ( log , " Part " < < source_part - > name < < " doesn ' t change up to mutation version " < < future_part . part_info . mutation ) ; <nl> return data . cloneAndLoadDataPartOnSameDisk ( source_part , " tmp_clone_ " , future_part . part_info ) ; <nl> mmm a / src / Storages / MergeTree / MergeTreeDataPartWriterInMemory . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeDataPartWriterInMemory . cpp <nl> void MergeTreeDataPartWriterInMemory : : write ( <nl> result_block . insert ( block . getByName ( col . name ) ) ; <nl> } <nl> <nl> + index_granularity . appendMark ( result_block . rows ( ) ) ; <nl> + if ( with_final_mark ) <nl> + index_granularity . appendMark ( 0 ) ; <nl> part - > block = std : : move ( result_block ) ; <nl> block_written = true ; <nl> } <nl> void MergeTreeDataPartWriterInMemory : : calculateAndSerializePrimaryIndex ( const Bl <nl> if ( ! rows ) <nl> return ; <nl> <nl> - index_granularity . appendMark ( rows ) ; <nl> - if ( with_final_mark ) <nl> - index_granularity . appendMark ( 0 ) ; <nl> - <nl> size_t primary_columns_num = primary_index_block . columns ( ) ; <nl> index_columns . resize ( primary_columns_num ) ; <nl> for ( size_t i = 0 ; i < primary_columns_num ; + + i ) <nl> mmm a / src / Storages / MergeTree / MergeTreeWriteAheadLog . cpp <nl> ppp b / src / Storages / MergeTree / MergeTreeWriteAheadLog . cpp <nl> namespace ErrorCodes <nl> { <nl> extern const int UNKNOWN_FORMAT_VERSION ; <nl> extern const int CANNOT_READ_ALL_DATA ; <nl> + extern const int BAD_DATA_PART_NAME ; <nl> } <nl> <nl> <nl> MergeTreeData : : MutableDataPartsVector MergeTreeWriteAheadLog : : restore ( ) <nl> } <nl> catch ( const Exception & e ) <nl> { <nl> - if ( e . code ( ) = = ErrorCodes : : CANNOT_READ_ALL_DATA | | e . code ( ) = = ErrorCodes : : UNKNOWN_FORMAT_VERSION ) <nl> + if ( e . code ( ) = = ErrorCodes : : CANNOT_READ_ALL_DATA <nl> + | | e . code ( ) = = ErrorCodes : : UNKNOWN_FORMAT_VERSION <nl> + | | e . code ( ) = = ErrorCodes : : BAD_DATA_PART_NAME ) <nl> { <nl> LOG_WARNING ( & Logger : : get ( storage . getLogName ( ) + " ( WriteAheadLog ) " ) , <nl> " WAL file ' " < < path < < " ' is broken . " < < e . displayText ( ) ) ; <nl> mmm a / src / Storages / StorageMergeTree . cpp <nl> ppp b / src / Storages / StorageMergeTree . cpp <nl> BackgroundProcessingPoolTaskResult StorageMergeTree : : mergeMutateTask ( ) <nl> <nl> / / / TODO : read deduplicate option from table config <nl> if ( merge ( false / * aggressive * / , { } / * partition_id * / , false / * final * / , false / * deduplicate * / ) ) <nl> - return BackgroundProcessingPoolTaskResult : : SUCCESS ; <nl> - <nl> + { <nl> + return in_memory_merges_throttler . needDelayMerge ( ) <nl> + ? BackgroundProcessingPoolTaskResult : : NOTHING_TO_DO <nl> + : BackgroundProcessingPoolTaskResult : : SUCCESS ; <nl> + } <nl> <nl> if ( tryMutatePart ( ) ) <nl> return BackgroundProcessingPoolTaskResult : : SUCCESS ; <nl>
in - memory parts : delay merges
ClickHouse/ClickHouse
4fb6492b08538d42089eca6b2b3322c843869b92
2020-05-20T12:02:02Z
mmm a / tensorflow / contrib / makefile / tf_op_files . txt <nl> ppp b / tensorflow / contrib / makefile / tf_op_files . txt <nl> tensorflow / core / kernels / split_op . cc <nl> tensorflow / core / kernels / split_v_op . cc <nl> tensorflow / core / kernels / split_lib_cpu . cc <nl> tensorflow / core / kernels / sparse_to_dense_op . cc <nl> + tensorflow / core / kernels / sparse_matmul_op . cc <nl> tensorflow / core / kernels / softsign_op . cc <nl> tensorflow / core / kernels / softplus_op . cc <nl> tensorflow / core / kernels / softmax_op . cc <nl> mmm a / tensorflow / core / kernels / BUILD <nl> ppp b / tensorflow / core / kernels / BUILD <nl> filegroup ( <nl> " ctc_loss_op . * " , <nl> # Excluded due to experimental status : <nl> " debug_ops . * " , <nl> - # Ops excluded because they do not build correctly for Android . <nl> - # See b / 29213790 <nl> " scatter_nd_op * " , <nl> - " sparse_matmul_op . * " , <nl> # Lib CURL is not supported on Android . <nl> " bigquery * " , <nl> ] , <nl>
Reenable sparse_matmul_op for Android builds
tensorflow/tensorflow
da28a6eb0521061ef1c87b2b13228485161905ce
2017-01-18T22:25:20Z
Binary files a / frontend / img / icon_arango . png and b / frontend / img / icon_arango . png differ <nl>
new icon for arangodb collections
arangodb/arangodb
3492fc0aca40fc860e4e6b1a736452923597d9a5
2013-02-28T15:50:17Z
mmm a / AUTHORS <nl> ppp b / AUTHORS <nl> a license to everyone to use it as detailed in LICENSE . ) <nl> * Braden MacDonald < braden @ bradenmacdonald . com > <nl> * Kevin Cheung < kevin . cheung @ autodesk . com > ( copyright owned by Autodesk , Inc . ) <nl> * Josh Peterson < petersonjm1 @ gmail . com > <nl> + * eska < eska @ eska . me > <nl> mmm a / site / source / docs / api_reference / html5 . h . rst <nl> ppp b / site / source / docs / api_reference / html5 . h . rst <nl> The ` ` userData ` ` parameter is a user - defined value that is passed ( unchanged ) to <nl> <nl> The ` ` useCapture ` ` parameter maps to ` ` useCapture ` ` in ` EventTarget . addEventListener < https : / / developer . mozilla . org / en - US / docs / Web / API / EventTarget . addEventListener > ` _ . It indicates whether or not to initiate * capture * : if ` ` true ` ` the callback will be invoked only for the DOM capture and target phases ; if ` ` false ` ` the callback will be triggered during the target and bubbling phases . See ` DOM Level 3 Events < http : / / www . w3 . org / TR / 2003 / NOTE - DOM - Level - 3 - Events - 20031107 / events . html # Events - phases > ` _ for a more detailed explanation . <nl> <nl> - Most functions return the result using the type : c : data : ` EMSCRIPTEN_RESULT ` . Non - zero and positive values denote success . Negative values signal failure . None of the functions fail or abort by throwing a JavaScript or C + + exception . If a particular browser does not support the given feature , the value : c : data : ` EMSCRIPTEN_RESULT_NOT_SUPPORTED ` will be returned at the time the callback is registered . <nl> + Most functions return the result using the type : c : data : ` EMSCRIPTEN_RESULT ` . Zero and positive values denote success . Negative values signal failure . None of the functions fail or abort by throwing a JavaScript or C + + exception . If a particular browser does not support the given feature , the value : c : data : ` EMSCRIPTEN_RESULT_NOT_SUPPORTED ` will be returned at the time the callback is registered . <nl> <nl> <nl> Callback functions <nl> Most functions in this API return a result of type : c : data : ` EMSCRIPTEN_RESULT ` . <nl> <nl> . . c : macro : : EMSCRIPTEN_RESULT <nl> <nl> - This type is used to return the result of most functions in this API . Positive values denote success , while zero and negative values signal failure . Possible values are listed below . <nl> + This type is used to return the result of most functions in this API . Zero and positive values denote success , while negative values signal failure . Possible values are listed below . <nl> <nl> <nl> . . c : macro : : EMSCRIPTEN_RESULT_SUCCESS <nl>
Merge pull request from eska014 / fix - emscripten - result - documentation
emscripten-core/emscripten
ddf64b263eb31c17c7c2f3e1e3d459754771a744
2015-12-28T20:27:52Z
mmm a / js / common / bootstrap / module - internal . js <nl> ppp b / js / common / bootstrap / module - internal . js <nl> <nl> / / - - SECTION - - public printing functions <nl> / / mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm - - <nl> <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + / / / @ brief flatten <nl> + / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> + <nl> + var hasOwnProperty = Function . prototype . call . bind ( Object . prototype . hasOwnProperty ) ; <nl> + <nl> + exports . flatten = function ( obj , seen ) { <nl> + ' use strict ' ; <nl> + <nl> + if ( ! obj | | ( typeof obj ! = = ' object ' & & typeof obj ! = = ' function ' ) ) { <nl> + return obj ; <nl> + } <nl> + <nl> + if ( obj instanceof Date ) { <nl> + return obj . toJSON ( ) ; <nl> + } <nl> + <nl> + if ( ! seen ) { <nl> + seen = [ ] ; <nl> + } <nl> + <nl> + var result = Object . create ( null ) , <nl> + src = obj , <nl> + keys , <nl> + i , <nl> + key , <nl> + val ; <nl> + <nl> + if ( typeof obj = = = ' function ' ) { <nl> + result . __exec = String ( obj ) ; <nl> + } <nl> + <nl> + while ( src ) { <nl> + if ( <nl> + seen . indexOf ( src ) ! = = - 1 <nl> + | | ( obj . constructor & & src = = = obj . constructor . prototype ) <nl> + ) { <nl> + break ; <nl> + } <nl> + seen . push ( src ) ; <nl> + keys = Object . getOwnPropertyNames ( src ) ; <nl> + for ( i = 0 ; i < keys . length ; i + + ) { <nl> + key = keys [ i ] ; <nl> + if ( typeof src ! = = ' function ' | | ( <nl> + key ! = = ' arguments ' & & key ! = = ' caller ' & & key ! = = ' callee ' <nl> + ) ) { <nl> + if ( key . charAt ( 0 ) ! = = ' _ ' & & ! hasOwnProperty ( result , key ) ) { <nl> + val = obj [ key ] ; <nl> + if ( seen . indexOf ( val ) ! = = - 1 & & ( <nl> + typeof val = = = ' object ' | | typeof val = = = ' function ' <nl> + ) ) { <nl> + result [ key ] = ' [ Circular ] ' ; <nl> + } else { <nl> + result [ key ] = exports . flatten ( val , seen ) ; <nl> + } <nl> + } <nl> + } <nl> + } <nl> + src = Object . getPrototypeOf ( src ) ; <nl> + } <nl> + <nl> + if ( obj . constructor & & obj . constructor . name ) { <nl> + if ( obj instanceof Error & & obj . name = = = Error . name ) { <nl> + result . name = obj . constructor . name ; <nl> + } else if ( ! hasOwnProperty ( result , ' constructor ' ) ) { <nl> + result . constructor = { name : obj . constructor . name } ; <nl> + } <nl> + } <nl> + <nl> + return result ; <nl> + } ; <nl> + <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl> / / / @ brief inspect <nl> / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / <nl>
Added flatten method .
arangodb/arangodb
069644a2e4b45c1127da7e4ffbe56a27680a826b
2014-08-01T18:02:54Z
mmm a / src / app / commands / cmd_preview . cpp <nl> ppp b / src / app / commands / cmd_preview . cpp <nl> class PreviewWindow : public Window { <nl> m_editor - > layer ( ) , <nl> m_editor - > frame ( ) ) ; <nl> <nl> + ImageBufferPtr buf = Editor : : getRenderImageBuffer ( ) ; <nl> m_render . reset ( <nl> renderEngine . renderSprite ( <nl> 0 , 0 , m_sprite - > width ( ) , m_sprite - > height ( ) , <nl> - m_editor - > frame ( ) , 0 , false , false , <nl> - Editor : : getRenderImageBuffer ( ) ) ) ; <nl> + m_editor - > frame ( ) , 0 , false , false , buf ) ) ; <nl> } <nl> <nl> int x , y , w , h , u , v ; <nl>
Fix compilation error in clang
aseprite/aseprite
d92a5d08ebce9e1bb01f98920447929267af5a4c
2014-11-30T15:06:31Z
mmm a / DEPS <nl> ppp b / DEPS <nl> vars = { <nl> <nl> deps = { <nl> " v8 / build " : <nl> - Var ( " git_url " ) + " / chromium / src / build . git " + " @ " + " a34a5233778556481dfa869bff735fad2157f196 " , <nl> + Var ( " git_url " ) + " / chromium / src / build . git " + " @ " + " 3f47a5e106127ae4e2567d64c615dc706054c819 " , <nl> " v8 / tools / gyp " : <nl> Var ( " git_url " ) + " / external / gyp . git " + " @ " + " 702ac58e477214c635d9b541932e75a95d349352 " , <nl> " v8 / third_party / icu " : <nl> deps = { <nl> " v8 / test / test262 / harness " : <nl> Var ( " git_url " ) + " / external / github . com / test262 - utils / test262 - harness - py . git " + " @ " + " cbd968f54f7a95c6556d53ba852292a4c49d11d8 " , <nl> " v8 / tools / clang " : <nl> - Var ( " git_url " ) + " / chromium / src / tools / clang . git " + " @ " + " 23638ab6411fb9e25ea7f1837835b67a793b5499 " , <nl> + Var ( " git_url " ) + " / chromium / src / tools / clang . git " + " @ " + " bd7e80b254a93d0a5cd8ecb994e47b1c827e253c " , <nl> } <nl> <nl> deps_os = { <nl>
Update V8 DEPS .
v8/v8
e0c98799c018c4a0dae5fe16285f070d1f5220af
2016-09-16T03:30:57Z
mmm a / Jenkinsfile <nl> ppp b / Jenkinsfile <nl> void build_taichi ( ) { <nl> nvidia - smi <nl> fi <nl> cd $ TAICHI_REPO_DIR <nl> + git submodule update - - init - - recursive <nl> [ - e build ] & & rm - rf build <nl> mkdir build & & cd build <nl> export CUDA_BIN_PATH = / usr / local / cuda - $ { CUDA_VERSION } <nl>
git submodule for jenkins
taichi-dev/taichi
30b59c28568a51e8fa5e0fab6ef0aaaf95ebc01d
2020-03-05T19:24:03Z
mmm a / osquery / filesystem / file_compression . cpp <nl> ppp b / osquery / filesystem / file_compression . cpp <nl> Status archive ( const std : : set < boost : : filesystem : : path > & paths , <nl> for ( size_t i = 0 ; i < blkCount ; i + + ) { <nl> std : : vector < char > block ( block_size , 0 ) ; <nl> auto r = pFile . read ( block . data ( ) , block_size ) ; <nl> - if ( r ! = block_size & & r > 0 ) { <nl> + if ( r > 0 & & static_cast < std : : size_t > ( r ) ! = block_size ) { <nl> / / resize the buffer to size we read as last block is likely smaller <nl> - block . resize ( r ) ; <nl> + block . resize ( static_cast < std : : size_t > ( r ) ) ; <nl> } <nl> archive_write_data ( arch , block . data ( ) , block . size ( ) ) ; <nl> } <nl>
Fix sign compare warning in file_compression . cpp
osquery/osquery
b93069b3f488c8b9389000538f8865dafedf23b8
2019-03-25T16:28:26Z
mmm a / lib / SILGen / SILGenApply . cpp <nl> ppp b / lib / SILGen / SILGenApply . cpp <nl> SILGenFunction : : emitApplyOfLibraryIntrinsic ( SILLocation loc , <nl> finalArgs , calleeTypeInfo , ApplyOptions : : None , ctx ) ; <nl> } <nl> <nl> - static StringRef <nl> - getMagicFunctionString ( SILGenFunction & SGF ) { <nl> - assert ( SGF . MagicFunctionName <nl> + StringRef SILGenFunction : : getMagicFunctionString ( ) { <nl> + assert ( MagicFunctionName <nl> & & " asking for # function but we don ' t have a function name ? ! " ) ; <nl> - if ( SGF . MagicFunctionString . empty ( ) ) { <nl> - llvm : : raw_string_ostream os ( SGF . MagicFunctionString ) ; <nl> - SGF . MagicFunctionName . print ( os ) ; <nl> + if ( MagicFunctionString . empty ( ) ) { <nl> + llvm : : raw_string_ostream os ( MagicFunctionString ) ; <nl> + MagicFunctionName . print ( os ) ; <nl> } <nl> - return SGF . MagicFunctionString ; <nl> + return MagicFunctionString ; <nl> } <nl> <nl> - static StringRef <nl> - getMagicFilePathString ( SILGenFunction & SGF , SourceLoc loc ) { <nl> - if ( ! loc . isValid ( ) ) <nl> - return " " ; <nl> - <nl> - return SGF . getASTContext ( ) . SourceMgr . getDisplayNameForLoc ( loc ) ; <nl> + StringRef SILGenFunction : : getMagicFilePathString ( SourceLoc loc ) { <nl> + assert ( loc . isValid ( ) ) ; <nl> + return getSourceManager ( ) . getDisplayNameForLoc ( loc ) ; <nl> } <nl> <nl> - static std : : string <nl> - getConciseMagicFileString ( SILGenFunction & SGF , SourceLoc loc ) { <nl> - if ( ! loc . isValid ( ) ) <nl> - return " " ; <nl> + std : : string SILGenFunction : : getMagicFileString ( SourceLoc loc ) { <nl> + auto path = getMagicFilePathString ( loc ) ; <nl> + <nl> + if ( ! getASTContext ( ) . LangOpts . EnableConcisePoundFile ) <nl> + return path ; <nl> <nl> - auto path = getMagicFilePathString ( SGF , loc ) ; <nl> auto value = llvm : : sys : : path : : filename ( path ) . str ( ) ; <nl> value + = " ( " ; <nl> - value + = SGF . getModule ( ) . getSwiftModule ( ) - > getNameStr ( ) ; <nl> + value + = getModule ( ) . getSwiftModule ( ) - > getNameStr ( ) ; <nl> value + = " ) " ; <nl> return value ; <nl> } <nl> RValue SILGenFunction : : emitLiteral ( LiteralExpr * literal , SGFContext C ) { <nl> auto magicLiteral = cast < MagicIdentifierLiteralExpr > ( literal ) ; <nl> switch ( magicLiteral - > getKind ( ) ) { <nl> case MagicIdentifierLiteralExpr : : File : { <nl> - std : : string value = getASTContext ( ) . LangOpts . EnableConcisePoundFile <nl> - ? getConciseMagicFileString ( * this , loc ) <nl> - : getMagicFilePathString ( * this , loc ) . str ( ) ; <nl> + std : : string value = loc . isValid ( ) ? getMagicFileString ( loc ) : " " ; <nl> builtinLiteralArgs = emitStringLiteral ( * this , literal , value , C , <nl> magicLiteral - > getStringEncoding ( ) ) ; <nl> builtinInit = magicLiteral - > getBuiltinInitializer ( ) ; <nl> RValue SILGenFunction : : emitLiteral ( LiteralExpr * literal , SGFContext C ) { <nl> } <nl> <nl> case MagicIdentifierLiteralExpr : : FilePath : { <nl> - StringRef value = getMagicFilePathString ( * this , loc ) ; <nl> + StringRef value = loc . isValid ( ) ? getMagicFilePathString ( loc ) : " " ; <nl> builtinLiteralArgs = emitStringLiteral ( * this , literal , value , C , <nl> magicLiteral - > getStringEncoding ( ) ) ; <nl> builtinInit = magicLiteral - > getBuiltinInitializer ( ) ; <nl> RValue SILGenFunction : : emitLiteral ( LiteralExpr * literal , SGFContext C ) { <nl> } <nl> <nl> case MagicIdentifierLiteralExpr : : Function : { <nl> - StringRef value = " " ; <nl> - if ( loc . isValid ( ) ) <nl> - value = getMagicFunctionString ( * this ) ; <nl> + StringRef value = loc . isValid ( ) ? getMagicFunctionString ( ) : " " ; <nl> builtinLiteralArgs = emitStringLiteral ( * this , literal , value , C , <nl> magicLiteral - > getStringEncoding ( ) ) ; <nl> builtinInit = magicLiteral - > getBuiltinInitializer ( ) ; <nl> mmm a / lib / SILGen / SILGenConvert . cpp <nl> ppp b / lib / SILGen / SILGenConvert . cpp <nl> auto SILGenFunction : : emitSourceLocationArgs ( SourceLoc sourceLoc , <nl> - > SourceLocArgs { <nl> auto & ctx = getASTContext ( ) ; <nl> <nl> - StringRef filename = " " ; <nl> + std : : string filename = " " ; <nl> unsigned line = 0 ; <nl> unsigned column = 0 ; <nl> if ( sourceLoc . isValid ( ) ) { <nl> - filename = ctx . SourceMgr . getDisplayNameForLoc ( sourceLoc ) ; <nl> + filename = getMagicFileString ( sourceLoc ) ; <nl> std : : tie ( line , column ) = ctx . SourceMgr . getLineAndColumn ( sourceLoc ) ; <nl> } <nl> <nl> auto SILGenFunction : : emitSourceLocationArgs ( SourceLoc sourceLoc , <nl> auto i1Ty = SILType : : getBuiltinIntegerType ( 1 , ctx ) ; <nl> <nl> SourceLocArgs result ; <nl> - SILValue literal = B . createStringLiteral ( emitLoc , filename , <nl> + SILValue literal = B . createStringLiteral ( emitLoc , StringRef ( filename ) , <nl> StringLiteralInst : : Encoding : : UTF8 ) ; <nl> result . filenameStartPointer = ManagedValue : : forUnmanaged ( literal ) ; <nl> / / File length <nl> mmm a / lib / SILGen / SILGenFunction . h <nl> ppp b / lib / SILGen / SILGenFunction . h <nl> class LLVM_LIBRARY_VISIBILITY SILGenFunction <nl> Optional < SILAccessEnforcement > getUnknownEnforcement ( VarDecl * var = nullptr ) ; <nl> <nl> SourceManager & getSourceManager ( ) { return SGM . M . getASTContext ( ) . SourceMgr ; } <nl> + std : : string getMagicFileString ( SourceLoc loc ) ; <nl> + StringRef getMagicFilePathString ( SourceLoc loc ) ; <nl> + StringRef getMagicFunctionString ( ) ; <nl> <nl> / / / Push a new debug scope and set its parent pointer . <nl> void enterDebugScope ( SILLocation Loc ) { <nl> mmm a / test / SILGen / magic_identifier_file . swift <nl> ppp b / test / SILGen / magic_identifier_file . swift <nl> func indirectUse ( ) { <nl> / / ABSOLUTE : string_literal utf8 " SOURCE_DIR / test / SILGen / magic_identifier_file . swift " <nl> / / CONCISE : string_literal utf8 " magic_identifier_file . swift ( Foo ) " <nl> } <nl> + <nl> + func forceUnwrap ( _ x : ( ) ? ) { <nl> + / / BOTH - LABEL : sil { { . * } } @ $ s3Foo11forceUnwrapyyytSgF <nl> + _ = x ! <nl> + / / ABSOLUTE : string_literal utf8 " SOURCE_DIR / test / SILGen / magic_identifier_file . swift " <nl> + / / CONCISE : string_literal utf8 " magic_identifier_file . swift ( Foo ) " <nl> + } <nl> + <nl> + func forceTry ( _ fn : ( ) throws - > ( ) ) { <nl> + / / BOTH - LABEL : sil { { . * } } @ $ s3Foo8forceTryyyyyKXEF <nl> + try ! fn ( ) <nl> + / / ABSOLUTE : string_literal utf8 " SOURCE_DIR / test / SILGen / magic_identifier_file . swift " <nl> + / / CONCISE : string_literal utf8 " magic_identifier_file . swift ( Foo ) " <nl> + } <nl>
Use # file string for force - unwrap and force - try
apple/swift
0f476284d1536b37eb6d959b026348aa4af20be8
2020-01-10T21:48:45Z
mmm a / ios / sdk / WeexSDK / Sources / Utility / WXDefine . h <nl> ppp b / ios / sdk / WeexSDK / Sources / Utility / WXDefine . h <nl> <nl> # ifndef __WX_DEFINE_H__ <nl> # define __WX_DEFINE_H__ <nl> <nl> - # define WX_SDK_VERSION @ " 0 . 7 . 0 " <nl> + # define WX_SDK_VERSION @ " 0 . 8 . 0 " <nl> <nl> # if defined ( __cplusplus ) <nl> # define WX_EXTERN extern " C " __attribute__ ( ( visibility ( " default " ) ) ) <nl>
* [ ios ] upgrade sdk version
apache/incubator-weex
35b6366656b6aef5fbd5fbec3b32e297078139e7
2016-09-12T02:22:55Z
mmm a / docker / test / fuzzer / run - fuzzer . sh <nl> ppp b / docker / test / fuzzer / run - fuzzer . sh <nl> case " $ stage " in <nl> # Lost connection to the server . This probably means that the server died <nl> # with abort . <nl> echo " failure " > status . txt <nl> - if ! grep - a " Received signal \ | Logical error " server . log > description . txt <nl> + if ! grep - ao " Received signal . * \ | Logical error . * \ | Assertion . * failed " server . log > description . txt <nl> then <nl> echo " Lost connection to server . See the logs " > description . txt <nl> fi <nl>
query fuzzer
ClickHouse/ClickHouse
6f861294f45ae2177e28e7feb7cce569d22d5a0d
2020-07-31T15:57:01Z
mmm a / tensorflow / go / operation . go <nl> ppp b / tensorflow / go / operation . go <nl> import " C " <nl> <nl> import ( <nl> " errors " <nl> + " unsafe " <nl> ) <nl> <nl> / / Operation that has been added to the graph . <nl> func ( op * Operation ) NumOutputs ( ) int { <nl> return int ( C . TF_OperationNumOutputs ( op . c ) ) <nl> } <nl> <nl> + / / OutputListSize returns the size of the list of Outputs that is produced by a <nl> + / / named output of op . <nl> + / / <nl> + / / An Operation has multiple named outputs , each of which produces either <nl> + / / a single tensor or a list of tensors . This method returns the size of <nl> + / / the list of tensors for a specific output of the operation , identified <nl> + / / by its name . <nl> + func ( op * Operation ) OutputListSize ( output string ) ( int , error ) { <nl> + cname : = C . CString ( output ) <nl> + defer C . free ( unsafe . Pointer ( cname ) ) <nl> + status : = newStatus ( ) <nl> + n : = C . TF_OperationOutputListLength ( op . c , cname , status . c ) <nl> + return int ( n ) , status . Err ( ) <nl> + } <nl> + <nl> / / Output returns the i - th output of op . <nl> func ( op * Operation ) Output ( i int ) Output { <nl> return Output { op , i } <nl> mmm a / tensorflow / go / operation_test . go <nl> ppp b / tensorflow / go / operation_test . go <nl> func TestOperationLifetime ( t * testing . T ) { <nl> } <nl> } <nl> <nl> + func TestOperationOutputListSize ( t * testing . T ) { <nl> + graph : = NewGraph ( ) <nl> + c1 , err : = Const ( graph , " c1 " , int64 ( 1 ) ) <nl> + if err ! = nil { <nl> + t . Fatal ( err ) <nl> + } <nl> + c2 , err : = Const ( graph , " c2 " , [ ] [ ] int64 { { 1 , 2 } , { 3 , 4 } } ) <nl> + if err ! = nil { <nl> + t . Fatal ( err ) <nl> + } <nl> + / / The ShapeN op takes a list of tensors as input and a list as output . <nl> + op , err : = graph . AddOperation ( OpSpec { <nl> + Type : " ShapeN " , <nl> + Input : [ ] Input { OutputList { c1 , c2 } } , <nl> + } ) <nl> + if err ! = nil { <nl> + t . Fatal ( err ) <nl> + } <nl> + n , err : = op . OutputListSize ( " output " ) <nl> + if err ! = nil { <nl> + t . Fatal ( err ) <nl> + } <nl> + if got , want : = n , 2 ; got ! = want { <nl> + t . Errorf ( " Got % d , want % d " , got , want ) <nl> + } <nl> + if got , want : = op . NumOutputs ( ) , 2 ; got ! = want { <nl> + t . Errorf ( " Got % d , want % d " , got , want ) <nl> + } <nl> + } <nl> + <nl> func TestOutputShape ( t * testing . T ) { <nl> graph : = NewGraph ( ) <nl> testdata : = [ ] struct { <nl>
go : Add Operation . OutputListSize
tensorflow/tensorflow
47318618b24d493877668750f84d114179120ca5
2016-10-14T20:47:09Z
mmm a / scripting / engine_spidermonkey . cpp <nl> ppp b / scripting / engine_spidermonkey . cpp <nl> namespace mongo { <nl> <nl> if ( val ! = JSVAL_NULL & & val ! = JSVAL_VOID & & JSVAL_IS_OBJECT ( val ) ) { <nl> / / TODO : this is a hack to get around sub objects being modified <nl> + / / basically right now whenever a sub object is read we mark whole obj as possibly modified <nl> JSObject * oo = JSVAL_TO_OBJECT ( val ) ; <nl> if ( JS_InstanceOf ( cx , oo , & bson_class , 0 ) | | <nl> JS_IsArrayObject ( cx , oo ) ) { <nl> mmm a / scripting / engine_v8 . cpp <nl> ppp b / scripting / engine_v8 . cpp <nl> namespace mongo { <nl> V8Scope * scope = ( V8Scope * ) ( scp - > Value ( ) ) ; <nl> val = scope - > mongoToV8Element ( elmt , false ) ; <nl> info . This ( ) - > ForceSet ( name , val ) ; <nl> + <nl> + if ( elmt . type ( ) = = mongo : : Object | | elmt . type ( ) = = mongo : : Array ) { <nl> + / / if accessing a subobject , it may get modified and base obj would not know <nl> + / / have to set base as modified , which means some optim is lost <nl> + info . This ( ) - > SetHiddenValue ( scope - > V8STR_MODIFIED , v8 : : Boolean : : New ( true ) ) ; <nl> + } <nl> return val ; <nl> } <nl> <nl> namespace mongo { <nl> return Handle < Value > ( ) ; <nl> Handle < Value > val = scope - > mongoToV8Element ( elmt , false ) ; <nl> / / info . This ( ) - > ForceSet ( name , val ) ; <nl> + <nl> + if ( elmt . type ( ) = = mongo : : Object | | elmt . type ( ) = = mongo : : Array ) { <nl> + / / if accessing a subobject , it may get modified and base obj would not know <nl> + / / have to set base as modified , which means some optim is lost <nl> + info . This ( ) - > SetHiddenValue ( scope - > V8STR_MODIFIED , v8 : : Boolean : : New ( true ) ) ; <nl> + } <nl> return val ; <nl> } <nl> <nl>
- fix basica . js with v8 , need to mark base obj as modified when subobj is accessed
mongodb/mongo
0ed5ef7b067abe8fde6a695f9d488586119c9d69
2011-07-15T21:17:31Z