std::vector<char> NppInterface::GetCurrentLine(ViewType view) const { int curLine = GetCurrentLineNumber(view); int bufSize = sendMsgToScintilla(view, SCI_LINELENGTH, curLine) + 1; std::vector<char> buf(bufSize); int ret = sendMsgToScintilla(view, SCI_GETLINE, curLine, reinterpret_cast<LPARAM>(buf.data())); FIX_UNUSED(ret); assert(ret == bufSize - 1); return buf; }
void CSAX2ParserBase::HandleError(int errNo) { CXMLException xmlExc(CXMLException::EBase + errNo, string()); XMLString systemId; XMLString publicId; if (m_pInputSource) { systemId = m_pInputSource->GetSystemId(); publicId = m_pInputSource->GetPublicId(); } CSAXParseException saxExc("", publicId, systemId, GetCurrentLineNumber(), GetCurrentColumnNumber(), xmlExc); if (m_pErrorHandler) m_pErrorHandler->Error(saxExc); else throw saxExc; }
void XmlParser::OnParseError () { ex::fprintf( stderr, "%s Parse error at line %d: %s\n", m_ParsingFileName, GetCurrentLineNumber(), GetErrorString() ); ex_error( "%s Parse error at line %d: %s\n", m_ParsingFileName, GetCurrentLineNumber(), GetErrorString() ); }
int CSAX2ParserBase::GetLineNumber() const { return GetCurrentLineNumber(); }
bool Parser::SM_Run() { FILE *out_fp = included_files.top()->ofile; const char *pos; TRI_STATE result = TSV_0; const char *output = pline.from.c_str(); sym_t preprocessor; CC_STRING expanded_line; do { pos = pline.parsed.c_str(); preprocessor = GetPreprocessor(pos, &pos); if(preprocessor != pline.pp_id || (pline.content != -1 && pline.content + pline.parsed.c_str() != pos) ) { fprintf(stderr, "%s:%zu\n", dv_current_file, dv_current_line); fprintf(stderr, " (%d) %s\n", pline.content, pline.parsed.c_str()); fprintf(stderr, " %d vs %d\n", preprocessor, pline.pp_id); exit(1); } } while(0); pos = pline.parsed.c_str() + pline.content; dv_current_file = GetCurrentFileName().c_str(); dv_current_line = GetCurrentLineNumber(); // GDB_TRAP2(strstr(dv_current_file,"makeint.h"), (dv_current_line==30)); // GDB_TRAP2(strstr(dv_current_file,"/usr/include/features.h"), dv_current_line==131); switch(pline.pp_id) { case SSID_SHARP_IF: if( superior_conditional_value(true) != TSV_0 ) result = (TRI_STATE) Compute(pos); goto handle_if_branch; case SSID_SHARP_IFNDEF: if( superior_conditional_value(true) != TSV_0 ) result = (TRI_STATE) CheckSymbolDefined(pos, true, NULL); goto handle_if_branch; case SSID_SHARP_IFDEF: if( superior_conditional_value(true) != TSV_0 ) result = (TRI_STATE) CheckSymbolDefined(pos, false, NULL); handle_if_branch: if( result == TSV_X ) { if( gvar_preprocess_mode ) { if(errmsg.isnull()) errmsg = "Error on processing conditional"; goto done; } } conditionals.push(new CConditionalChain()); upper_chain()->enter_if(result); upper_chain()->filename = dv_current_file; upper_chain()->line = dv_current_line; if(eval_current_conditional() != TSV_X) output = NULL; included_files.top()->add_if(result); break; case SSID_SHARP_ELIF: if( superior_conditional_value(false) == TSV_0 ) { included_files.top()->add_elif(false); goto done; } if( upper_chain()->has_true() ) { upper_chain()->enter_elif(TSV_0); included_files.top()->add_elif(false); goto done; } result = (TRI_STATE) Compute(pos); if( gvar_preprocess_mode && result == TSV_X) goto done; /* * Transformation on the condition of: * * 1) #if 0 * #elif X --> #if X * * 2) #elif X * #elif 1 --> #else */ if( eval_current_conditional() == TSV_0 ) { if(result == TSV_X) { pline.to = do_elif(1); output = pline.to.c_str(); } else output = NULL; } else { if(result == TSV_1) { pline.to = do_elif(2); output = pline.to.c_str(); } else if(result == TSV_0) output = NULL; } upper_chain()->enter_elif(result); included_files.top()->add_elif(result); break; case SSID_SHARP_ELSE: if( superior_conditional_value(false) == TSV_0 ) { included_files.top()->add_else(false); goto done; } result = upper_chain()->enter_else(); included_files.top()->add_else(result); if( eval_current_conditional() != TSV_X ) output = NULL; break; case SSID_SHARP_ENDIF: included_files.top()->add_endif(); CConditionalChain *c; if( ! upper_chain()->keep_endif() ) output = NULL; if( conditionals.size() == 0 ) { errmsg = "Unmatched #endif"; goto done; } conditionals.pop(c); delete c; break; default: if(eval_current_conditional() == TSV_0) goto done; if(eval_current_conditional() == TSV_X) goto print_and_exit; switch(pline.pp_id) { case SSID_SHARP_DEFINE: if(!do_define(pos)) goto error_out; break; case SSID_SHARP_UNDEF: handle_undef(intab, pos); break; case SSID_SHARP_INCLUDE: case SSID_SHARP_INCLUDE_NEXT: if( gvar_preprocess_mode ) do_include(pline.pp_id, pos, &output); break; default: if(gvar_expand_macros) { pos = pline.parsed.c_str(); expanded_line = ExpandLine(intab, false, pos, errmsg); if(!errmsg.isnull()) goto error_out; if(included_files.size() == 1) { expanded_line += '\n'; output = expanded_line.c_str(); } } } } print_and_exit: if( out_fp != NULL && output != NULL ) fprintf(out_fp, "%s", output); done: pline.comment_start = -1; if(gvar_preprocess_mode && GetError()) { IncludedFile *tmp; CC_STRING pmsg, ts; while(included_files.size() > 0) { included_files.pop(tmp); ts.Format(" %s:%u\n", tmp->ifile->name.c_str(), tmp->ifile->line); pmsg += ts; } if( !pmsg.isnull() ) { errmsg = pmsg + errmsg; } } return gvar_preprocess_mode ? (GetError() == NULL) : true; error_out: return false; }
/* Parse the input file and update the global symbol table and macro table, * output the stripped file contents to devices if OUTFILE is not nil. * * Returns a pointer to the error messages on failure, or nil on success. */ bool Parser::DoFile(InternalTables *intab, size_t num_preprocessors, File *infile, ParserContext *ctx) { bool ignored; FILE *out_fp; bool retval = false; CC_STRING bak_fname, out_fname; struct stat stb; struct utimbuf utb; if(ctx) { ignored = ctx->check_ignore(infile->name); if( ignored && ! has_dep_file() ) return true; } else ignored = false; if( stat(infile->name, &stb) == 0 ) { utb.actime = stb.st_atime; utb.modtime = stb.st_mtime; } if( ! infile->Open() ) { errmsg.Format("Cannot open \"%s\" for reading\n"); return false; } out_fp = NULL; if(ctx != NULL && ctx->outfile != ParserContext::OF_NULL ) { if( ctx->outfile == ParserContext::OF_STDOUT ) out_fp = stdout; else { #if SANITY_CHECK assert( ! ctx->baksuffix.isnull() ); #endif if( ctx->baksuffix[0] != ParserContext::MAGIC_CHAR ) bak_fname = infile->name + ctx->baksuffix; else out_fname = infile->name; int fd; char tmp_outfile[32]; strcpy(tmp_outfile, "@cl@-XXXXXX"); fd = mkstemp(tmp_outfile); if( fd < 0 ) { errmsg.Format("Cannot open \"%s\" for writing\n", tmp_outfile); infile->Close(); return false; } out_fp = fdopen(fd, "wb"); out_fname = tmp_outfile; } } if(ctx == NULL) memset(writers, 0, sizeof(writers)); else { writers[VCH_CL] = NULL; if(!ctx->of_array[VCH_DEP].isnull()) writers[VCH_DEP] = gvar_file_writers[VCH_DEP]; if(!ctx->of_array[VCH_CV].isnull()) writers[VCH_CV] = gvar_file_writers[VCH_CV]; } if( num_preprocessors >= COUNT_OF(Parser::preprocessors) ) num_preprocessors = COUNT_OF(Parser::preprocessors); Reset(intab, num_preprocessors, ctx); if(has_dep_file()) AddDependency("", infile->name); PushIncludedFile(infile, out_fp, COUNT_OF(Parser::preprocessors), false, conditionals.size()); if(ctx != NULL) { GetCmdLineIncludeFiles(ctx->imacro_files, 2); GetCmdLineIncludeFiles(ctx->include_files, COUNT_OF(preprocessors)); } if( ! RunEngine(0) ) goto error; SaveDepInfo(deptext); if( conditionals.size() != 0 ) errmsg = "Unmatched #if"; else retval = true; error: if(!retval) { if(included_files.size() > 0) { CC_STRING tmp; tmp.Format("%s:%u: %s\n%s\n", GetCurrentFileName().c_str(), GetCurrentLineNumber(), pline.from.c_str(), GetError()); errmsg = tmp; } #if 0 IncludedFile *ilevel; while(included_files.size() > 0) { ilevel = PopIncludedFile(); if(infile != ilevel->ifile) delete ilevel; } #endif } if(out_fp != NULL && out_fp != stdout) fclose(out_fp); if( retval && ctx != NULL && ! ignored ) { CC_STRING semname; sem_t *sem; semname = MakeSemaName(infile->name); sem = sem_open(semname.c_str(), O_CREAT, 0666, 1); sem_wait(sem); if( ! bak_fname.isnull() ) rename(infile->name, bak_fname); if( ! out_fname.isnull() ) { rename(out_fname, infile->name); utime(infile->name.c_str(), &utb); } sem_post(sem); sem_unlink(semname.c_str()); } else if( ! out_fname.isnull() ) unlink(out_fname.c_str()); return retval; }