Mercurial > hg > CbC > CbC_llvm
comparison tools/clang/lib/Parse/ParseCbC.cpp @ 48:4b59af982ef3
create return function for continuation with the environment automatically, but it can return only int value and it's name is not unique now
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 12 Jan 2014 19:15:16 +0900 (2014-01-12) |
parents | 5b813d18f000 |
children | c22698ecb2a9 |
comparison
equal
deleted
inserted
replaced
47:5b813d18f000 | 48:4b59af982ef3 |
---|---|
23 #include "llvm/Support/TargetRegistry.h" | 23 #include "llvm/Support/TargetRegistry.h" |
24 #include "llvm/Support/TargetSelect.h" | 24 #include "llvm/Support/TargetSelect.h" |
25 #include "llvm/ADT/SmallString.h" | 25 #include "llvm/ADT/SmallString.h" |
26 #include "clang/Sema/Lookup.h" | 26 #include "clang/Sema/Lookup.h" |
27 #include "clang/Lex/LiteralSupport.h" | 27 #include "clang/Lex/LiteralSupport.h" |
28 #include "clang/AST/ASTConsumer.h" | |
28 | 29 |
29 #include <cmath> | 30 #include <cmath> |
30 #include <sstream> | 31 #include <sstream> |
31 | 32 |
32 #include "CbCHelper.h" | 33 #include "CbCHelper.h" |
113 | 114 |
114 void Parser::PrepareForGotoWithTheEnv(){ | 115 void Parser::PrepareForGotoWithTheEnv(){ |
115 StmtResult Res; | 116 StmtResult Res; |
116 SourceLocation Loc = Tok.getLocation(); | 117 SourceLocation Loc = Tok.getLocation(); |
117 | 118 |
119 CreateRetFunction(); | |
118 Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc), CbCSpace::FunctionType, DeclSpec::TST___code); | 120 Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc), CbCSpace::FunctionType, DeclSpec::TST___code); |
119 if (Res.isUsable()) | 121 if (Res.isUsable()) |
120 Stmtsp->push_back(Res.release()); | 122 Stmtsp->push_back(Res.release()); |
121 | 123 |
122 Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc), 0, DeclSpec::TST_struct, | 124 Res = CreateDeclStmt(CreateIdentifierInfo(__CBC_ENVIRONMENT_NAME, __CBC_ENVIRONMENT_LENGTH, Loc), 0, DeclSpec::TST_struct, |
213 DeclGroupPtrTy DeclGPT; | 215 DeclGroupPtrTy DeclGPT; |
214 ParsingDeclSpec DS(*this); | 216 ParsingDeclSpec DS(*this); |
215 DeclSpec *DSp; | 217 DeclSpec *DSp; |
216 DSp = &DS; | 218 DSp = &DS; |
217 | 219 |
218 DS.SetRangeStart(Loc); | 220 setTST(&DS, valueType, Name); |
219 DS.SetRangeEnd(Loc); | |
220 | |
221 bool isInvalid = false; | |
222 const char *PrevSpec = 0; | |
223 unsigned DiagID = 0; | |
224 | |
225 if (valueType == DeclSpec::TST_struct) { | |
226 ParsedAttributesWithRange attrs(AttrFactory); | |
227 CXXScopeSpec &SS = DS.getTypeSpecScope(); | |
228 DeclResult TagOrTempResult = true; | |
229 bool Owned = false; | |
230 bool IsDependent = false; | |
231 MultiTemplateParamsArg TParams; | |
232 TagOrTempResult = Actions.ActOnTag(getCurScope(), valueType, Sema::TUK_Reference, Loc, | |
233 SS, Name, Loc, attrs.getList(), AS_none, | |
234 DS.getModulePrivateSpecLoc(), | |
235 TParams, Owned, IsDependent, | |
236 SourceLocation(), false, | |
237 clang::TypeResult()); | |
238 isInvalid = DS.SetTypeSpecType(valueType, Loc, Loc, PrevSpec, DiagID, TagOrTempResult.get(), Owned); | |
239 if (isInvalid) | |
240 Diag(Loc, DiagID) << PrevSpec; | |
241 } | |
242 | |
243 else | |
244 isInvalid = DS.SetTypeSpecType(valueType, Loc, PrevSpec, DiagID); | |
245 | |
246 DS.SetRangeEnd(Loc); | |
247 DS.Finish(Diags, PP); | |
248 ParsingDeclarator D(*this, DS, static_cast<Declarator::TheContext>(Declarator::BlockContext)); | 221 ParsingDeclarator D(*this, DS, static_cast<Declarator::TheContext>(Declarator::BlockContext)); |
249 D.SetIdentifier(II, Loc); | 222 D.SetIdentifier(II, Loc); |
250 | 223 |
251 if (CbCSpace::isFunction(DeclFlags)) { | 224 if (CbCSpace::isFunction(DeclFlags)) { |
252 D.setEllipsisLoc(SourceLocation()); | 225 D.setEllipsisLoc(SourceLocation()); |
350 StmtVector innerStmts; | 323 StmtVector innerStmts; |
351 StmtResult innerStmtRes; | 324 StmtResult innerStmtRes; |
352 ExprResult innerExprRes; | 325 ExprResult innerExprRes; |
353 DeclSpec CastDS(AttrFactory); | 326 DeclSpec CastDS(AttrFactory); |
354 | 327 |
355 if (CastDS.getSourceRange().isInvalid()) { | 328 setTST(&CastDS, DeclSpec::TST_int); |
356 CastDS.SetRangeStart(Loc); | |
357 CastDS.SetRangeEnd(Loc); | |
358 } | |
359 ParsedAttributesWithRange attrs(AttrFactory); | |
360 bool isInvalid = false; | |
361 const char *PrevSpec = 0; | |
362 unsigned DiagID = 0; | |
363 isInvalid = CastDS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID); | |
364 CastDS.SetRangeEnd(Loc); | |
365 isInvalid = false; | |
366 DiagID = 0; | |
367 ProhibitAttributes(attrs); | |
368 CastDS.Finish(Diags, PP); | |
369 | |
370 Declarator CastDeclaratorInfo(CastDS, Declarator::TypeNameContext); | 329 Declarator CastDeclaratorInfo(CastDS, Declarator::TypeNameContext); |
371 CastDeclaratorInfo.SetRangeEnd(Loc); | 330 CastDeclaratorInfo.SetRangeEnd(Loc); |
372 DeclSpec pointerDS(AttrFactory); | 331 DeclSpec pointerDS(AttrFactory); |
373 pointerDS.Finish(Diags, PP); | 332 pointerDS.Finish(Diags, PP); |
374 DeclaratorScopeObj DeclScopeObj(*this, CastDeclaratorInfo.getCXXScopeSpec()); | 333 DeclaratorScopeObj DeclScopeObj(*this, CastDeclaratorInfo.getCXXScopeSpec()); |
479 PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, Loc, "parsing struct/union body"); | 438 PrettyDeclStackTraceEntry CrashInfo(Actions, TagDecl, Loc, "parsing struct/union body"); |
480 ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope); | 439 ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope); |
481 Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); | 440 Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
482 SmallVector<Decl *, 32> FieldDecls; | 441 SmallVector<Decl *, 32> FieldDecls; |
483 | 442 |
484 bool isInvalid = false; | |
485 const char *PrevSpec = 0; | 443 const char *PrevSpec = 0; |
486 unsigned DiagID = 0; | 444 unsigned DiagID = 0; |
487 | 445 |
488 FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_void, Loc, __CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH)); | 446 FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_void, Loc, __CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH)); |
489 FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_int, Loc, __CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH)); | 447 FieldDecls.push_back(Create__CbC_envBody(TagDecl, DeclSpec::TST_int, Loc, __CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH)); |
499 | 457 |
500 SDS.Finish(Diags,PP); | 458 SDS.Finish(Diags,PP); |
501 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, SDS); | 459 Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, SDS); |
502 SDS.complete(TheDecl); | 460 SDS.complete(TheDecl); |
503 Actions.ConvertDeclToDeclGroup(TheDecl); | 461 Actions.ConvertDeclToDeclGroup(TheDecl); |
504 if (isInvalid) { | |
505 assert(PrevSpec && "Method did not return previous specifier!"); | |
506 assert(DiagID); | |
507 | |
508 if (DiagID == diag::ext_duplicate_declspec) | |
509 Diag(Tok, DiagID) | |
510 << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation()); | |
511 else | |
512 Diag(Tok, DiagID) << PrevSpec; | |
513 } | |
514 } | 462 } |
515 | 463 |
516 Decl* Parser::Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name, int NameLen){ | 464 Decl* Parser::Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name, int NameLen){ |
517 const char *PrevSpec = 0; | |
518 unsigned DiagID = 0; | |
519 ParsingDeclSpec PDS(*this); | 465 ParsingDeclSpec PDS(*this); |
520 if (PDS.getSourceRange().isInvalid()) { | 466 setTST(&PDS, T); |
521 PDS.SetRangeStart(Loc); | |
522 PDS.SetRangeEnd(Loc); | |
523 } | |
524 PDS.SetTypeSpecType(T, Loc, PrevSpec, DiagID); | |
525 PDS.SetRangeEnd(Loc); | |
526 | |
527 | |
528 PDS.Finish(Diags, PP); | |
529 SourceLocation CommaLoc; | 467 SourceLocation CommaLoc; |
530 ParsingFieldDeclarator DeclaratorInfo(*this, PDS); | 468 ParsingFieldDeclarator DeclaratorInfo(*this, PDS); |
531 DeclaratorInfo.D.setCommaLoc(CommaLoc); | 469 DeclaratorInfo.D.setCommaLoc(CommaLoc); |
532 DeclaratorInfo.D.SetRangeEnd(Loc); | 470 DeclaratorInfo.D.SetRangeEnd(Loc); |
533 DeclSpec DS(AttrFactory); | 471 DeclSpec DS(AttrFactory); |
534 DS.Finish(Diags,PP); | 472 DS.Finish(Diags,PP); |
535 DeclaratorInfo.D.SetIdentifier(CreateIdentifierInfo(Name, NameLen,Loc),Loc); | 473 DeclaratorInfo.D.SetIdentifier(CreateIdentifierInfo(Name, NameLen,Loc),Loc); |
536 | |
537 | 474 |
538 DeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,DS.getConstSpecLoc(), | 475 DeclaratorInfo.D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,DS.getConstSpecLoc(), |
539 DS.getVolatileSpecLoc(),DS.getRestrictSpecLoc()), | 476 DS.getVolatileSpecLoc(),DS.getRestrictSpecLoc()), |
540 DS.getAttributes(),SourceLocation()); | 477 DS.getAttributes(),SourceLocation()); |
541 Decl *Field = Actions.ActOnField(getCurScope(), TagDecl, | 478 Decl *Field = Actions.ActOnField(getCurScope(), TagDecl, |
543 DeclaratorInfo.D, DeclaratorInfo.BitfieldSize); | 480 DeclaratorInfo.D, DeclaratorInfo.BitfieldSize); |
544 DeclaratorInfo.complete(Field); | 481 DeclaratorInfo.complete(Field); |
545 return Field; | 482 return Field; |
546 } | 483 } |
547 | 484 |
548 IdentifierInfo* Parser::CreateIdentifierInfo(const char* Name, int NameLen, SourceLocation Loc) { | 485 IdentifierInfo* Parser::CreateIdentifierInfo(const char* Name, int NameLen, SourceLocation Loc) { |
549 Token TokenForII; | 486 Token TokenForII; |
550 TokenForII.startToken(); | 487 TokenForII.startToken(); |
551 TokenForII.setLocation(Loc); | 488 TokenForII.setLocation(Loc); |
552 TokenForII.setLength(NameLen); | 489 TokenForII.setLength(NameLen); |
553 TokenForII.setKind(tok::raw_identifier); | 490 TokenForII.setKind(tok::raw_identifier); |
557 TokenForII.setIdentifierInfo(II); | 494 TokenForII.setIdentifierInfo(II); |
558 TokenForII.setKind(II->getTokenID()); | 495 TokenForII.setKind(II->getTokenID()); |
559 return II; | 496 return II; |
560 } | 497 } |
561 | 498 |
499 void Parser::CreateRetFunction(){ | |
500 Scope *SavedScope = getCurScope(); | |
501 DeclContext *SavedContext = Actions.CurContext; | |
502 sema::FunctionScopeInfo *SavedFSI = Actions.FunctionScopes.pop_back_val(); | |
503 DeclSpec::TST retvalType = DeclSpec::TST_int; | |
504 | |
505 Actions.CurContext = static_cast<DeclContext *>(Actions.Context.getTranslationUnitDecl()); | |
506 Scope *TopScope = getCurScope(); | |
507 while(TopScope->getParent() != NULL) | |
508 TopScope = TopScope->getParent(); | |
509 Actions.CurScope = TopScope; | |
510 DeclGroupPtrTy returnDecl = DeclGroupPtrTy(); | |
511 SourceLocation Loc = Tok.getLocation(); | |
512 ParsingDeclSpec PDS(*this); | |
513 setTST(&PDS, DeclSpec::TST___code); | |
514 ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::FileContext)); | |
515 D.SetIdentifier(CreateIdentifierInfo("return1", 7, Loc),Loc); | |
516 ParseScope PrototypeScope(this,Scope::FunctionPrototypeScope|Scope::DeclScope|Scope::FunctionDeclarationScope); | |
517 bool IsAmbiguous = false; | |
518 bool HasProto = true; | |
519 SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; | |
520 SourceLocation EllipsisLoc, RefQualifierLoc, ConstQualifierLoc, VolatileQualifierLoc; | |
521 DeclSpec FDS(AttrFactory); | |
522 bool RefQualifierIsLValueRef = true; | |
523 ExceptionSpecificationType ESpecType = EST_None; | |
524 SourceRange ESpecRange; | |
525 SmallVector<ParsedType, 2> DynamicExceptions; | |
526 SmallVector<SourceRange, 2> DynamicExceptionRanges; | |
527 ExprResult NoexceptExpr; | |
528 ParsedAttributes FnAttrs(AttrFactory); | |
529 TypeResult TrailingReturnType; | |
530 | |
531 | |
532 IdentifierInfo *retvalII = CreateIdentifierInfo(__CBC_RETVAL_NAME, __CBC_RETVAL_LENGTH, Loc); | |
533 // TODO : We should change retval type to a destination function's return type. | |
534 CreateParam(retvalType, retvalII, 0, &ParamInfo); | |
535 IdentifierInfo *envII = CreateIdentifierInfo(__CBC_STRUCT_ENV_NAME, __CBC_STRUCT_ENV_LENGTH, Loc); | |
536 CreateParam(DeclSpec::TST_void, envII, 1, &ParamInfo); | |
537 | |
538 D.AddTypeInfo(DeclaratorChunk::getFunction(HasProto, IsAmbiguous, Loc, ParamInfo.data(), ParamInfo.size(), EllipsisLoc, Loc, | |
539 FDS.getTypeQualifiers(), RefQualifierIsLValueRef, RefQualifierLoc, ConstQualifierLoc, | |
540 VolatileQualifierLoc, SourceLocation(), ESpecType, ESpecRange.getBegin(), | |
541 DynamicExceptions.data(), DynamicExceptionRanges.data(), DynamicExceptions.size(), | |
542 NoexceptExpr.isUsable() ? NoexceptExpr.get() : 0, | |
543 Loc, Loc, D, TrailingReturnType), FnAttrs, Loc); | |
544 PrototypeScope.Exit(); | |
545 | |
546 Decl *TheDecl; | |
547 ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); | |
548 Decl *BodyRes = Actions.ActOnStartOfFunctionDef(getCurScope(), D); | |
549 | |
550 D.complete(BodyRes); | |
551 D.getMutableDeclSpec().abort(); | |
552 Actions.ActOnDefaultCtorInitializers(BodyRes); | |
553 StmtResult FnBody; | |
554 StmtVector FnStmts; | |
555 StmtResult innerR; | |
556 ExprResult retvalAssginmentExpr,LHS; | |
557 DeclSpec retvalTypeDS(AttrFactory); | |
558 setTST(&retvalTypeDS, retvalType); | |
559 | |
560 Declarator retvalTypeDInfo(retvalTypeDS, Declarator::TypeNameContext); | |
561 retvalTypeDInfo.SetRangeEnd(Loc); | |
562 DeclSpec starDS(AttrFactory); | |
563 starDS.Finish(Diags, PP); | |
564 retvalTypeDInfo.SetIdentifier(0, Loc); | |
565 retvalTypeDInfo.AddTypeInfo(DeclaratorChunk::getPointer(starDS.getTypeQualifiers(), Loc, | |
566 starDS.getConstSpecLoc(), | |
567 starDS.getVolatileSpecLoc(), | |
568 starDS.getRestrictSpecLoc()), | |
569 starDS.getAttributes(), | |
570 SourceLocation()); | |
571 | |
572 ExprVector ArgExprs; | |
573 CommaLocsTy CommaLocs; | |
574 DeclSpec envDS(AttrFactory); | |
575 IdentifierInfo *structName = CreateIdentifierInfo(__CBC_STRUCT_NAME, __CBC_STRUCT_LENGTH, Loc); | |
576 setTST(&envDS, DeclSpec::TST_struct, structName); | |
577 | |
578 Declarator envDInfo(envDS, Declarator::TypeNameContext); | |
579 envDInfo.SetRangeEnd(Loc); | |
580 DeclSpec starDS2(AttrFactory); | |
581 starDS2.Finish(Diags, PP); | |
582 envDInfo.SetIdentifier(0,Loc); | |
583 envDInfo.AddTypeInfo(DeclaratorChunk::getPointer(starDS2.getTypeQualifiers(), Loc, | |
584 starDS2.getConstSpecLoc(), | |
585 starDS2.getVolatileSpecLoc(), | |
586 starDS2.getRestrictSpecLoc()), | |
587 starDS2.getAttributes(), | |
588 SourceLocation()); | |
589 ExprVector ArgExprs2; | |
590 LHS = LookupAndDeclareName(envII); | |
591 ArgExprs2.push_back(LHS.release()); | |
592 LHS = Actions.ActOnParenListExpr(Loc, Loc, ArgExprs2); | |
593 Expr *envCastExpr = LHS.take(); | |
594 TypeSourceInfo *castTInfo = Actions.GetTypeForDeclaratorCast(envDInfo, envCastExpr->getType()); | |
595 LHS = Actions.MaybeConvertParenListExprToParenExpr(getCurScope(), envCastExpr); | |
596 envCastExpr = LHS.take(); | |
597 LHS = Actions.BuildCStyleCastExpr(Loc, castTInfo, Loc, envCastExpr); | |
598 ArgExprs.push_back(LHS.release()); | |
599 LHS = Actions.ActOnParenListExpr(Loc, Loc, ArgExprs); | |
600 LHS = LookupMemberAndBuildExpr(CreateIdentifierInfo(__CBC_STRUCT_POINTER_NAME, __CBC_STRUCT_POINTER_LENGTH, Loc), | |
601 LHS.take(), true); | |
602 Expr *ret_pCastExpr = LHS.take(); | |
603 TypeSourceInfo *castTInfo2 = Actions.GetTypeForDeclaratorCast(retvalTypeDInfo, ret_pCastExpr->getType()); | |
604 LHS = Actions.BuildCStyleCastExpr(Loc, castTInfo2, Loc, ret_pCastExpr); | |
605 LHS = Actions.ActOnUnaryOp(getCurScope(), Loc, tok::star, LHS.get()); | |
606 ExprResult RHS; | |
607 RHS = LookupAndDeclareName(retvalII); | |
608 | |
609 retvalAssginmentExpr = Actions.ActOnBinOp(getCurScope(), Loc, tok::equal, LHS.take(), RHS.take()); | |
610 innerR = Actions.ActOnExprStmt(retvalAssginmentExpr); | |
611 if(innerR.isUsable()) | |
612 FnStmts.push_back(innerR.release()); | |
613 | |
614 Token Next,ljTok; | |
615 Next.setKind(tok::l_paren); | |
616 ExternalSpace::StatementFilterCCC CCCValidator(Next); | |
617 CXXScopeSpec SS; | |
618 IdentifierInfo *ljName = CreateIdentifierInfo("longjmp", 7, Loc); | |
619 Sema::NameClassification Classification = Actions.ClassifyName(getCurScope(), SS, ljName, Loc, Next, false, &CCCValidator); | |
620 ljTok.startToken(); | |
621 ljTok.setLocation(Loc); | |
622 ljTok.setIdentifierInfo(ljName); | |
623 ljTok.setKind(tok::annot_primary_expr); | |
624 setExprAnnotation(ljTok, Classification.getExpression()); | |
625 ljTok.setAnnotationEndLoc(Loc); | |
626 PP.AnnotateCachedTokens(ljTok); | |
627 ExprResult ljExpr,ljLHS; | |
628 ljExpr = getExprAnnotation(ljTok); | |
629 ExprVector ljArgExprs; | |
630 DeclSpec ljDS(AttrFactory); | |
631 setTST(&ljDS, DeclSpec::TST_struct, structName); | |
632 | |
633 Declarator ljD(ljDS, Declarator::TypeNameContext); | |
634 ljD.SetRangeEnd(Loc); | |
635 DeclSpec starDS3(AttrFactory); | |
636 starDS3.Finish(Diags, PP); | |
637 ljD.ExtendWithDeclSpec(starDS3); | |
638 ljD.SetIdentifier(0, Loc); | |
639 ljD.AddTypeInfo(DeclaratorChunk::getPointer(ljDS.getTypeQualifiers(), Loc, | |
640 ljDS.getConstSpecLoc(), | |
641 ljDS.getVolatileSpecLoc(), | |
642 ljDS.getRestrictSpecLoc()), | |
643 ljDS.getAttributes(), | |
644 SourceLocation()); | |
645 ljLHS = LookupAndDeclareName(envII); | |
646 Expr *ljCastExpr = ljLHS.take(); | |
647 TypeSourceInfo *ljCastTInfo = Actions.GetTypeForDeclaratorCast(ljD, ljCastExpr->getType()); | |
648 ljLHS = Actions.BuildCStyleCastExpr(Loc, ljCastTInfo, Loc, ljCastExpr); | |
649 ljLHS = Actions.ActOnParenExpr(Loc, Loc, ljLHS.take()); | |
650 ljLHS = LookupMemberAndBuildExpr(envII, ljLHS.take(), true); | |
651 ljLHS = Actions.ActOnParenExpr(Loc, Loc, ljLHS.take()); | |
652 ljArgExprs.push_back(ljLHS.release()); | |
653 CommaLocs.push_back(Loc); | |
654 ljLHS = Actions.ActOnIntegerConstant(Loc, 1 /* return value for setjmp */); | |
655 ljArgExprs.push_back(ljLHS.release()); | |
656 ljExpr = Actions.ActOnCallExpr(getCurScope(), ljExpr.take(), Loc, ljArgExprs, Loc, 0); | |
657 innerR = Actions.ActOnExprStmt(ljExpr); | |
658 if(innerR.isUsable()) | |
659 FnStmts.push_back(innerR.release()); | |
660 FnBody = Actions.ActOnCompoundStmt(Loc, Loc, FnStmts, false); | |
661 BodyScope.Exit(); | |
662 TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.take()); | |
663 returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); | |
664 (&Actions.getASTConsumer())->HandleTopLevelDecl(returnDecl.get()); | |
665 Actions.CurScope = SavedScope; | |
666 Actions.CurContext = SavedContext; | |
667 Actions.FunctionScopes.push_back(SavedFSI); | |
668 } | |
669 | |
670 void Parser::CreateParam(DeclSpec::TST T, IdentifierInfo *II, int pointerNum, SmallVector<DeclaratorChunk::ParamInfo, 16> *ParamInfo){ | |
671 SourceLocation Loc = Tok.getLocation(); | |
672 DeclSpec DS(AttrFactory); | |
673 setTST(&DS, T); | |
674 Declarator ParamDeclarator(DS, Declarator::PrototypeContext); | |
675 ParamDeclarator.SetIdentifier(II, Loc); | |
676 for(int i = 0;i<pointerNum; i++){ | |
677 DeclSpec pointerDS(AttrFactory); | |
678 pointerDS.Finish(Diags, PP); | |
679 ParamDeclarator.AddTypeInfo(DeclaratorChunk::getPointer(pointerDS.getTypeQualifiers(), Loc, | |
680 pointerDS.getConstSpecLoc(), | |
681 pointerDS.getVolatileSpecLoc(), | |
682 pointerDS.getRestrictSpecLoc()), | |
683 pointerDS.getAttributes(),SourceLocation()); | |
684 } | |
685 Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParamDeclarator); | |
686 ParamInfo->push_back(DeclaratorChunk::ParamInfo(II, ParamDeclarator.getIdentifierLoc(), Param, 0)); | |
687 | |
688 } | |
689 | |
690 void Parser::setTST(DeclSpec *DS, DeclSpec::TST T, IdentifierInfo* Name){ | |
691 SourceLocation Loc = Tok.getLocation(); | |
692 bool isInvalid = false; | |
693 const char *PrevSpec = 0; | |
694 unsigned DiagID = 0; | |
695 DS->SetRangeStart(Loc); | |
696 DS->SetRangeEnd(Loc); | |
697 if (T == DeclSpec::TST_struct) { | |
698 ParsedAttributesWithRange attrs(AttrFactory); | |
699 CXXScopeSpec &SS = DS->getTypeSpecScope(); | |
700 DeclResult TagOrTempResult = true; | |
701 bool Owned = false; | |
702 bool IsDependent = false; | |
703 MultiTemplateParamsArg TParams; | |
704 TagOrTempResult = Actions.ActOnTag(getCurScope(), T, Sema::TUK_Reference, Loc, | |
705 SS, Name, Loc, attrs.getList(), AS_none, | |
706 DS->getModulePrivateSpecLoc(), | |
707 TParams, Owned, IsDependent, | |
708 SourceLocation(), false, | |
709 clang::TypeResult()); | |
710 isInvalid = DS->SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, TagOrTempResult.get(), Owned); | |
711 } | |
712 else | |
713 isInvalid = DS->SetTypeSpecType(T, Loc, PrevSpec, DiagID); | |
714 | |
715 DS->Finish(Diags, PP); | |
716 if (isInvalid) { | |
717 assert(PrevSpec && "Method did not return previous specifier!"); | |
718 assert(DiagID); | |
719 if (DiagID == diag::ext_duplicate_declspec) | |
720 Diag(Tok, DiagID) | |
721 << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation()); | |
722 else | |
723 Diag(Tok, DiagID) << PrevSpec; | |
724 } | |
725 } | |
562 | 726 |
563 #endif | 727 #endif |