On Tue, May 6, 2014 at 4:47 PM, Nico Weber <[email protected]> wrote:
> Having libFormat know about "goog.scope" seems pretty icky. Maybe this > should be handled like the for loop macros instead? > I don't disagree, we should eventually move this out again. On Tue, May 6, 2014 at 6:54 AM, Daniel Jasper <[email protected]> wrote: > > Author: djasper > > Date: Tue May 6 08:54:10 2014 > > New Revision: 208088 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=208088&view=rev > > Log: > > clang-format: [JS] Don't indent in goog.scope blocks. > > > > Before: > > goog.scope(function() { > > var x = a.b; > > var y = c.d; > > }); // goog.scope > > > > After: > > goog.scope(function() { > > var x = a.b; > > var y = c.d; > > }); // goog.scope > > > > Modified: > > cfe/trunk/lib/Format/UnwrappedLineParser.cpp > > cfe/trunk/unittests/Format/FormatTestJS.cpp > > > > Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=208088&r1=208087&r2=208088&view=diff > > > ============================================================================== > > --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) > > +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue May 6 08:54:10 2014 > > @@ -415,16 +415,34 @@ void UnwrappedLineParser::parseBlock(boo > > Line->Level = InitialLevel; > > } > > > > +static bool IsGoogScope(const UnwrappedLine &Line) { > > + if (Line.Tokens.size() < 4) > > + return false; > > + auto I = Line.Tokens.begin(); > > + if (I->Tok->TokenText != "goog") > > + return false; > > + ++I; > > + if (I->Tok->isNot(tok::period)) > > + return false; > > + ++I; > > + if (I->Tok->TokenText != "scope") > > + return false; > > + ++I; > > + return I->Tok->is(tok::l_paren); > > +} > > + > > void UnwrappedLineParser::parseChildBlock() { > > FormatTok->BlockKind = BK_Block; > > nextToken(); > > { > > + bool GoogScope = > > + Style.Language == FormatStyle::LK_JavaScript && > IsGoogScope(*Line); > > ScopedLineState LineState(*this); > > ScopedDeclarationState DeclarationState(*Line, > DeclarationScopeStack, > > > /*MustBeDeclaration=*/false); > > - Line->Level += 1; > > + Line->Level += GoogScope ? 0 : 1; > > parseLevel(/*HasOpeningBrace=*/true); > > - Line->Level -= 1; > > + Line->Level -= GoogScope ? 0 : 1; > > } > > nextToken(); > > } > > > > Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp > > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=208088&r1=208087&r2=208088&view=diff > > > ============================================================================== > > --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) > > +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue May 6 08:54:10 2014 > > @@ -91,5 +91,12 @@ TEST_F(FormatTestJS, SingleQuoteStrings) > > verifyFormat("this.function('', true);"); > > } > > > > +TEST_F(FormatTestJS, GoogScopes) { > > + verifyFormat("goog.scope(function() {\n" > > + "var x = a.b;\n" > > + "var y = c.d;\n" > > + "}); // goog.scope"); > > +} > > + > > } // end namespace tooling > > } // end namespace clang > > > > > > _______________________________________________ > > cfe-commits mailing list > > [email protected] > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
