void PPIncludeCallback::InclusionDirective(
  clang::SourceLocation hashLoc_,
  const clang::Token&,
  clang::StringRef fileName_,
  bool,
  clang::CharSourceRange filenameRange_,
  const clang::FileEntry*,
  clang::StringRef searchPath_,
  clang::StringRef,
  const clang::Module*,
  clang::SrcMgr::CharacteristicKind)
{
  if (searchPath_.empty())
    return;

  clang::SourceLocation expLoc = _clangSrcMgr.getExpansionLoc(hashLoc_);
  clang::PresumedLoc presLoc = _clangSrcMgr.getPresumedLoc(expLoc);

  //--- Included file ---//

  std::string includedPath = searchPath_.str() + '/' + fileName_.str();
  model::FilePtr included = _ctx.srcMgr.getFile(includedPath);
  included->parseStatus = model::File::PSFullyParsed;
  if (included->type != model::File::DIRECTORY_TYPE &&
      included->type != _cppSourceType)
  {
    included->type = _cppSourceType;
    _ctx.srcMgr.updateFile(*included);
  }

  //--- Includer file ---//

  std::string includerPath = presLoc.getFilename();
  model::FilePtr includer = _ctx.srcMgr.getFile(includerPath);
  includer->parseStatus = model::File::PSFullyParsed;
  if (includer->type != model::File::DIRECTORY_TYPE &&
      includer->type != _cppSourceType)
  {
    includer->type = _cppSourceType;
    _ctx.srcMgr.updateFile(*includer);
  }

  //--- CppAstNode ---//

  model::CppAstNodePtr fileNode =
    createFileAstNode(included, filenameRange_.getAsRange());

  if (_mangledNameCache.insert(*fileNode))
    _astNodes.push_back(fileNode);

  model::CppHeaderInclusionPtr inclusion(new model::CppHeaderInclusion);
  inclusion->includer = includer;
  inclusion->included = included;

  _headerIncs.push_back(inclusion);
}
示例#2
0
文件: yylex.c 项目: LordJagged/plucid
yylex()
{
	int k;
	STRING synfind(),strsave(),getident(),getword2(),getstring(),getword();
	float getnum();
	while(iswhite(c=lexgetc()));
	startoflex = curr_index;
	if((isalpha(c)||c=='@' )&& c != EOF) {
		s = getident(c);
		if(strcmp("include",s)==0){
			inclusion();
			return(yylex());
		}else if((k=keyfind(synfind(s)))!=NKEYWORDS && const_list == 0){
			   yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->strg =  keywords[k].keyname;
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  = startoflex;
				return(keywords[k].keyret);
		}else{ if (const_list != 0)
			{
			  yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			  yylval.resptr->strg = s;
			  yylval.resptr->line = in_files[in_index].in_line;
			  yylval.resptr->len  =
			  startoflex;
			  return(WORD);
			}
			else
			{
			  yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			  yylval.resptr->strg = s;
			  yylval.resptr->line = in_files[in_index].in_line;
			  yylval.resptr->len  =
			  startoflex;
			  return(IDENT);
			}
		     }
       }else if((isdigit(c) || c == '~') && c !=EOF) {
		yylval.numb = (float) getnum(c);
		return(CONST);
	}else{
		switch(c){
		case '+':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg = "plus";
			yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(ADDOP);
		case '-':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg =  "minus";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(ADDOP);
		case '*':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
			yylval.resptr->line = in_files[in_index].in_line;
			if (c=='*') { yylval.resptr->strg =  "exp";
				      yylval.resptr->len  = startoflex;
				      return(EXP); }
			peekc = c;
			yylval.resptr->strg =  "times";
			yylval.resptr->len  = startoflex;
			return(MULOP);
		case '/': c = lexgetc();
			if (const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->strg=getword2('/');
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			if (c=='/'){
			while((c=lexgetc())!='\n');
			peekc = c;
			return(yylex()); }
			peekc = c;
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			yylval.resptr->strg =  "fdiv";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(MULOP);
		case '^':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			yylval.resptr->strg ="strconc";
			   yylval.resptr->line = in_files[in_index].in_line;
			yylval.resptr->len  =
			  startoflex;
			return(STRCONC);
		case '#':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->strg=getword2(c);
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			return(c);
		case '"':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c = lexgetc() ;
			yylval.resptr->strg = getword(c);
			yylval.resptr->len  =
			  startoflex;
			return(WORD);
		case '`':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			c = lexgetc();
			yylval.resptr->strg =  getstring(c);
			yylval.resptr->len  =
			  startoflex;
			return(STRING_QUOTED);
		case ':':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			   yylval.resptr->len  = startoflex;
			if (const_list!=0) {
			     yylval.resptr->strg = getword(c);
			     return(WORD); }
			c = lexgetc();
			if (c==':') { yylval.resptr->strg = "cons";
					return(CONS); } else {
					peekc=c;
					return(COLON);}
		case '[': c = lexgetc();
			if (c=='%' && const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2('[');
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			if (c == '%') { return(CLSTART);
				      }
				      else
				      { peekc = c;
					const_list++;
					return(LSTART);
				      }
		case '%':c = lexgetc();
			if ((c==']' || c==')') && const_list!=0) {
			     peekc = c;
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2('%');
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			  if (c == ']')
				       {  return(CLEND);
				       }
				       else
				       {
				       my_yyerror("incorrect use of %","cannot continue compliation ");
					 my_exit(1);
				       }
		case ']':
				       { const_list--;
					 return(LEND);
				       }
		case '.':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			return(DOT);
		case '<':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
					if (c=='=') {
						   yylval.resptr->strg =  "le";
						   yylval.resptr->len  =
			  startoflex;
						     return(RELOP); } else
					if (c =='>') {
						 yylval.resptr->strg = "append";
						 yylval.resptr->len  =
			  startoflex;
						   return(APPEND); } else {
						     peekc=c;
						     yylval.resptr->strg = "lt";
						     yylval.resptr->len  =
			  startoflex;
						     return(RELOP);  }
		case '>':
			yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			if (const_list!=0) {
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			c=lexgetc();
			if (c=='=') { yylval.resptr->strg =  "ge";
				      yylval.resptr->len  =
			  startoflex;
					return(RELOP); } else {
						 yylval.resptr->strg = "gt";
						 yylval.resptr->len  =
			  startoflex;
						 peekc=c;
						 return(RELOP); }
		case '&':
		case ',':
		case ';':
		case '=':
		case '$':
		case '(':
		case ')':
			if (const_list!=0) {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			   yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->strg=getword2(c);
			     yylval.resptr->len  =
			  startoflex;
			     return(WORD); }
			 if (c==',') {
			     yylval.resptr = (RESPTR) calloc(1,sizeof(RES));
			     yylval.resptr->line = in_files[in_index].in_line;
			     yylval.resptr->len  = startoflex;
			     return(COMMA); }
		default:
			return(c);
		}
	}
}