changeset 42:3e178477409f

made some submethods for the methods which emit CbC statements.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Fri, 27 Dec 2013 00:08:21 +0900
parents 1d6c745cd57d
children 7116d17d6428
files tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Parse/ParseCbC.cpp
diffstat 2 files changed, 66 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/include/clang/Parse/Parser.h	Thu Dec 26 22:29:30 2013 +0900
+++ b/tools/clang/include/clang/Parse/Parser.h	Fri Dec 27 00:08:21 2013 +0900
@@ -1709,6 +1709,8 @@
   IdentifierInfo* CreateIdentifierInfo(const char* Name, int NameLen, SourceLocation Loc);
   Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, bool* isInvalid,
 			    const char* PrevSpec, unsigned* DiagID, const char* Name, int NameLen);
+  ExprResult LookupAndDeclareName(IdentifierInfo *II);
+  ExprResult LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow);
 #endif
 
   bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Thu Dec 26 22:29:30 2013 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Fri Dec 27 00:08:21 2013 +0900
@@ -24,7 +24,7 @@
 #include "clang/Sema/Lookup.h"
 using namespace clang;
 
-namespace ExternalSpace {
+namespace ExternalSpace { // from ParseExpr.cpp , ParseStmt.cpp
 class CastExpressionIdValidator : public CorrectionCandidateCallback {
  public:
   CastExpressionIdValidator(bool AllowTypes, bool AllowNonTypes)
@@ -79,7 +79,6 @@
 
 StmtResult Parser::Create__returnStmt(){
   SourceLocation Loc = Tok.getLocation();
-  unsigned Context = Declarator::BlockContext;
   ParsedAttributesWithRange __retAttrs(AttrFactory);
   SourceLocation DeclStart = Loc, DeclEnd = Loc;
   ParsingDeclSpec PDS(*this);
@@ -103,19 +102,19 @@
   }
   __retDS.SetRangeEnd(Loc);
   __retDS.Finish(Diags, PP);
-  ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Context));
+  ParsingDeclarator D(*this, PDS, static_cast<Declarator::TheContext>(Declarator::BlockContext));
   D.setEllipsisLoc(SourceLocation());
   bool hadGroupingParens = D.hasGroupingParens();
   D.setGroupingParens(true);
   IdentifierInfo* II = CreateIdentifierInfo("__CbC_return",12, Loc); // CreateIdentifierInfo(name,length of the name, SourceLocation);
   D.SetRangeEnd(Loc);
-  DeclSpec DS_(AttrFactory);
+  DeclSpec DS(AttrFactory);
 
-  DS_.Finish(Diags, PP);
+  DS.Finish(Diags, PP);
   D.SetIdentifier(II, Loc);
   
-  D.AddTypeInfo(DeclaratorChunk::getPointer(DS_.getTypeQualifiers(), Loc,DS_.getConstSpecLoc(),DS_.getVolatileSpecLoc(),
-					    DS_.getRestrictSpecLoc()),DS_.getAttributes(),SourceLocation());
+  D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,DS.getConstSpecLoc(),DS.getVolatileSpecLoc(),
+					    DS.getRestrictSpecLoc()),DS.getAttributes(),SourceLocation());
   D.setGroupingParens(hadGroupingParens);
 
   
@@ -124,7 +123,7 @@
   bool HasProto = false;
   SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
   SourceLocation EllipsisLoc, RefQualifierLoc, ConstQualifierLoc, VolatileQualifierLoc;
-  DeclSpec DS__(AttrFactory);
+  DeclSpec FDS(AttrFactory);
   bool RefQualifierIsLValueRef = true;
   ExceptionSpecificationType ESpecType = EST_None;
   SourceRange ESpecRange;
@@ -134,7 +133,7 @@
   ParsedAttributes FnAttrs(AttrFactory);
   TypeResult TrailingReturnType;
   D.AddTypeInfo(DeclaratorChunk::getFunction(HasProto,false,Loc,ParamInfo.data(),
-					     ParamInfo.size(),EllipsisLoc, Loc,DS__.getTypeQualifiers(),
+					     ParamInfo.size(),EllipsisLoc, Loc,FDS.getTypeQualifiers(),
 					     RefQualifierIsLValueRef,RefQualifierLoc, ConstQualifierLoc,
 					     VolatileQualifierLoc,SourceLocation(),ESpecType, ESpecRange.getBegin(),
 					     DynamicExceptions.data(),DynamicExceptionRanges.data(),
@@ -148,7 +147,7 @@
   D.complete(FirstDecl);
   DeclsInGroup.push_back(FirstDecl);
   
-  DeclGroupPtrTy __retDecl = Actions.FinalizeDeclaratorGroup(getCurScope(), DS_, DeclsInGroup);
+  DeclGroupPtrTy __retDecl = Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup);
   return Actions.ActOnDeclStmt(__retDecl, DeclStart, DeclEnd);
 }
 
@@ -176,21 +175,7 @@
   LHSToken.setAnnotationEndLoc(Loc);
   PP.AnnotateCachedTokens(LHSToken);
   LHS = getExprAnnotation(LHSToken);
-  IdentifierInfo &return1II = *CreateIdentifierInfo("return1", 7, Loc);
-  UnqualifiedId Name;
-  Name.setIdentifier(&return1II, Loc);
-  
-  DeclarationNameInfo NameInfo;
-  const TemplateArgumentListInfo *TemplateArgs;
-  TemplateArgumentListInfo TemplateArgsBuffer;
-  Actions.DecomposeUnqualifiedId(Name, TemplateArgsBuffer, NameInfo, TemplateArgs);
-  DeclarationName DName = NameInfo.getName();
-  IdentifierInfo *IIFromName = DName.getAsIdentifierInfo();
-  LookupResult LR(Actions, NameInfo, Actions.LookupOrdinaryName);
-  bool IvarLookupFollowUp = IIFromName && !SS.isSet() && Actions.getCurMethodDecl();
-  Actions.LookupParsedName(LR, getCurScope(), &SS, !IvarLookupFollowUp);
-  RHS = Actions.BuildDeclarationNameExpr(SS, LR, /* ADL = */ false);
-  
+  RHS = LookupAndDeclareName(CreateIdentifierInfo("return1", 7, Loc));
   Res = Actions.CreateBuiltinBinOp(Loc, BO_Assign, LHS.take(), RHS.take());
   return Actions.ActOnExprStmt(Res);
 }
@@ -202,66 +187,16 @@
   ParseScope IfScope(this, Scope::DeclScope | Scope::ControlScope, true/* C99 or CXX */);
   ExprResult CondExp;
   Decl *CondVar = 0;
-  IdentifierInfo &setjmpII = *CreateIdentifierInfo("setjmp",6,Loc);
-  UnqualifiedId setjmpName;
-  CXXScopeSpec SS;
-  SourceLocation TemplateKWLoc;
-  ExternalSpace::CastExpressionIdValidator Validator(false,true);
-  setjmpName.setIdentifier(&setjmpII, Loc);
-  TemplateArgumentListInfo TemplateArgsBuffer;
-  DeclarationNameInfo setjmpNameInfo;
-  const TemplateArgumentListInfo *TemplateArgs;
-  Actions.DecomposeUnqualifiedId(setjmpName, TemplateArgsBuffer, setjmpNameInfo, TemplateArgs);
-  DeclarationName DName = setjmpNameInfo.getName();
-  IdentifierInfo *setjmpII_ = DName.getAsIdentifierInfo();
-  SourceLocation NameLoc = setjmpNameInfo.getLoc();
-  LookupResult setjmpR(Actions, setjmpNameInfo,Actions.LookupOrdinaryName);
-  Actions.LookupParsedName(setjmpR, getCurScope(), &SS, true);
 
-  if (setjmpII_ && setjmpR.empty()) {
-    NamedDecl *sjljD = Actions.ImplicitlyDefineFunction(NameLoc, *setjmpII_, getCurScope());
-    if (sjljD) setjmpR.addDecl(sjljD);
-  }
-
-  CondExp = Actions.BuildDeclarationNameExpr(SS, setjmpR, false);
-  Expr *ExecConfig = 0;
+  CondExp = LookupAndDeclareName(CreateIdentifierInfo("setjmp",6,Loc));
   ExprVector ArgExprs;
   ExprResult __envExprRes = CondExp.get();
-  IdentifierInfo &__envII = *CreateIdentifierInfo("__CbC_environment",17,Loc);
-  UnqualifiedId __envName;
 
-  __envName.setIdentifier(&__envII,Loc);
-  TemplateArgumentListInfo __envTemplateArgsBuffer;
-  DeclarationNameInfo __envNameInfo;
-  const TemplateArgumentListInfo *__envTemplateArgs;
-  Actions.DecomposeUnqualifiedId(__envName, __envTemplateArgsBuffer, __envNameInfo, __envTemplateArgs);
-  LookupResult __envR(Actions, __envNameInfo,Actions.LookupOrdinaryName);
-  Actions.LookupParsedName(__envR, getCurScope(), &SS, true);
-  __envExprRes = Actions.BuildDeclarationNameExpr(SS, __envR, false);
-  UnqualifiedId envName;
-  IdentifierInfo *envId = CreateIdentifierInfo("env",3,Loc);
-  envName.setIdentifier(envId,Loc);
-
-  Expr *envBase = __envExprRes.take();
-  TemplateArgumentListInfo envTemplateArgsBuffer;
-  DeclarationNameInfo envNameInfo;
-  const TemplateArgumentListInfo *envTemplateArgs;
-  Actions.DecomposeUnqualifiedId(envName, envTemplateArgsBuffer, envNameInfo, envTemplateArgs);
-  bool IsArrow = false;
-
-  __envExprRes = Actions.MaybeConvertParenListExprToParenExpr(getCurScope(), envBase);
-  envBase = __envExprRes.take();
-  LookupResult envR(Actions, envNameInfo, Actions.LookupMemberName);
-  ExprResult envBaseResult = Actions.Owned(envBase);
-  __envExprRes = Actions.LookupMemberExpr(envR, envBaseResult, IsArrow, Loc, SS, 0, envTemplateArgs != 0);
-  envBase = envBaseResult.take();
-			    
-  Sema::ActOnMemberAccessExtraArgs envExtraArgs = {getCurScope(), envName, 0, false};
-  __envExprRes = Actions.BuildMemberReferenceExpr(envBase, envBase->getType(), Loc, IsArrow, SS, TemplateKWLoc, 0, envR, envTemplateArgs,false, &envExtraArgs);
+  __envExprRes = LookupAndDeclareName(CreateIdentifierInfo("__CbC_environment", 17, Loc));
+  __envExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo("env", 3, Loc), __envExprRes.take(), false);
 
   ArgExprs.push_back(__envExprRes.release());
-  CondExp = Actions.ActOnCallExpr(getCurScope(), CondExp.take(), Loc, ArgExprs, Loc, ExecConfig);
-
+  CondExp = Actions.ActOnCallExpr(getCurScope(), CondExp.take(), Loc, ArgExprs, Loc, 0);
   CondExp = Actions.ActOnBooleanCondition(getCurScope(), Loc, CondExp.get());
 
   FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp.get(), Loc));
@@ -274,7 +209,6 @@
   StmtVector innerStmts;
   StmtResult innerStmtRes;
   ExprResult innerExprRes;
-  ExprResult CastResult(true);
   DeclSpec CastDS(AttrFactory);
 						      
   if (CastDS.getSourceRange().isInvalid()) {
@@ -303,40 +237,14 @@
 							     pointerDS.getVolatileSpecLoc(),
 							     pointerDS.getRestrictSpecLoc()),
 				 pointerDS.getAttributes(),SourceLocation());
-  IdentifierInfo &__envII__ = *CreateIdentifierInfo("__CbC_environment",17,Loc);
-  UnqualifiedId __envName_;
-  ExternalSpace::CastExpressionIdValidator Validator2(true,false);
-  __envName_.setIdentifier(&__envII__, Loc);
-  TemplateArgumentListInfo __envTemplateArgsBuffer_;
-  DeclarationNameInfo __envNameInfo_;
-  const TemplateArgumentListInfo *__envTemplateArgs_;
-  Actions.DecomposeUnqualifiedId(__envName_, __envTemplateArgsBuffer_, __envNameInfo_, __envTemplateArgs_);
-  LookupResult __envR_(Actions, __envNameInfo_,Actions.LookupOrdinaryName);
-  Actions.LookupParsedName(__envR_, getCurScope(), &SS, true);
-  CastResult = Actions.BuildDeclarationNameExpr(SS,__envR_, false);
-  UnqualifiedId ret_pName;
-  IdentifierInfo *ret_pId = CreateIdentifierInfo("ret_p",5,Loc);
-  ret_pName.setIdentifier(ret_pId,Loc);
-  Expr *ret_pBase = CastResult.take();
-  TemplateArgumentListInfo ret_pTemplateArgsBuffer;
-  DeclarationNameInfo ret_pNameInfo;
-  const TemplateArgumentListInfo *ret_pTemplateArgs;
-  Actions.DecomposeUnqualifiedId(ret_pName, ret_pTemplateArgsBuffer, ret_pNameInfo, ret_pTemplateArgs);
-  CastResult = Actions.MaybeConvertParenListExprToParenExpr(getCurScope(), ret_pBase);
-  ret_pBase = CastResult.take();
-  LookupResult ret_pR(Actions, ret_pNameInfo, Actions.LookupMemberName);
-  ExprResult ret_pBaseResult = Actions.Owned(ret_pBase);
-  CastResult = Actions.LookupMemberExpr(ret_pR, ret_pBaseResult, IsArrow, Loc, SS, 0, ret_pTemplateArgs != 0);
-  ret_pBase = ret_pBaseResult.take();
-  Sema::ActOnMemberAccessExtraArgs ret_pExtraArgs = {getCurScope(), ret_pName, 0,  false};
-  CastResult = Actions.BuildMemberReferenceExpr(ret_pBase, ret_pBase->getType(), Loc, IsArrow, SS, TemplateKWLoc, 0, ret_pR, ret_pTemplateArgs,false, &ret_pExtraArgs);
 
-  Expr *CastExpr = CastResult.take();
+  innerExprRes = LookupAndDeclareName(CreateIdentifierInfo("__CbC_environment", 17, Loc));
+  innerExprRes = LookupMemberAndBuildExpr(CreateIdentifierInfo("ret_p",5,Loc), innerExprRes.take(), false);
+  Expr *CastExpr = innerExprRes.take();
   TypeSourceInfo *castTInfo = Actions.GetTypeForDeclaratorCast(CastDeclaratorInfo, CastExpr->getType());
   Actions.checkUnusedDeclAttributes(CastDeclaratorInfo);
 
-  CastResult = Actions.BuildCStyleCastExpr(Loc, castTInfo, Loc, CastExpr);
-  innerExprRes = CastResult;
+  innerExprRes = Actions.BuildCStyleCastExpr(Loc, castTInfo, Loc, CastExpr);
   innerExprRes = Actions.ActOnParenExpr(Loc, Loc, innerExprRes.take());
   innerExprRes = Actions.ActOnUnaryOp(getCurScope(), Loc, tok::star, innerExprRes.get());
   innerStmtRes = Actions.ActOnReturnStmt(Loc, innerExprRes.take());
@@ -350,3 +258,49 @@
   IfRes = Actions.ActOnIfStmt(Loc, FullCondExp, CondVar, ThenStmt.get(),Loc, ElseStmt.get());
   return IfRes;
 }
+
+ExprResult Parser::LookupAndDeclareName(IdentifierInfo *II){
+  SourceLocation Loc = Tok.getLocation();
+  UnqualifiedId Name;
+  CXXScopeSpec SS;
+  SourceLocation TemplateKWLoc;
+  ExternalSpace::CastExpressionIdValidator Validator(false,true);
+  Name.setIdentifier(II, Loc);
+  TemplateArgumentListInfo TemplateArgsBuffer;
+  DeclarationNameInfo NameInfo;
+  const TemplateArgumentListInfo *TemplateArgs;
+  Actions.DecomposeUnqualifiedId(Name, TemplateArgsBuffer, NameInfo, TemplateArgs);
+  DeclarationName DName = NameInfo.getName();
+  II = DName.getAsIdentifierInfo();
+  SourceLocation NameLoc = NameInfo.getLoc();
+  LookupResult R(Actions, NameInfo,Actions.LookupOrdinaryName);
+  Actions.LookupParsedName(R, getCurScope(), &SS, true);
+
+  if (II && R.empty()) {
+    NamedDecl *D = Actions.ImplicitlyDefineFunction(NameLoc, *II, getCurScope());
+    if (D) R.addDecl(D);
+  }
+  return Actions.BuildDeclarationNameExpr(SS, R, false);
+}
+
+ExprResult Parser::LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow){
+  SourceLocation Loc = Tok.getLocation();
+  ExprResult Res;
+  CXXScopeSpec SS;
+  UnqualifiedId Name;
+  SourceLocation TemplateKWLoc;
+  Name.setIdentifier(II,Loc);
+  TemplateArgumentListInfo TemplateArgsBuffer;
+  DeclarationNameInfo NameInfo;
+  const TemplateArgumentListInfo *TemplateArgs;
+  Actions.DecomposeUnqualifiedId(Name, TemplateArgsBuffer, NameInfo, TemplateArgs);
+  Res = Actions.MaybeConvertParenListExprToParenExpr(getCurScope(), Base);
+  Base = Res.take();
+  LookupResult R(Actions, NameInfo, Actions.LookupMemberName);
+  ExprResult BaseResult = Actions.Owned(Base);
+  Actions.LookupMemberExpr(R, BaseResult, IsArrow, Loc, SS, 0, TemplateArgs != 0);
+  Base = BaseResult.take();
+  Sema::ActOnMemberAccessExtraArgs ExtraArgs = {getCurScope(), Name, 0,  false};
+  return Actions.BuildMemberReferenceExpr(Base, Base->getType(), Loc, IsArrow, SS, TemplateKWLoc, 0, R, TemplateArgs,false, &ExtraArgs);
+
+}