int ParseParameter(const char* parameter) { unsigned char flags = 0; unsigned int i = 0; if(parameter == NULL) { fprintf(stderr, "Null string parse attempt\n"); return 0; } for(i = 0; parameter[i] != '\0'; i++) { if(parameter[i] == '|') { flags |= TOKENS; flags |= NOT_NUMBER; } else if(parameter[i] < '0' || parameter[i] > '9') { flags |= NOT_NUMBER; } } if((flags & NOT_NUMBER) == 0) return atoi(parameter); if((flags & TOKENS) == 0) return TranslateDefines(parameter); return ParseTokens("0", parameter); }
/// Bind a mouse action to the python io map /// @param action a string version of the action to bind to the map /// @param pyAction the python action to take when the state is correct void PyIOMap::BindMouseAction( const std::string& action, PythonIOMapping::Action pyAction ) { // convert the strings into values InputCode inputCode = GetInputCode( ParseTokens(action, "+" ) ); IOMapping::InputType eInputType = GetInputType( IOMapping::kInputSource_Mouse, action ); // bind the button BindIO( IOMapping::kInputSource_Mouse, eInputType, inputCode, pyAction ); }
/// Bind a key to the python io map /// @param key a string version of the key to bind to the map /// @param inputType a string version of the input type to bind /// @param pyAction the python action to take when the state is correct void PyIOMap::BindKey( const std::string& key, const std::string& inputType, PythonIOMapping::Action pyAction ) { // convert the parameters into values InputCode inputCode = GetInputCode( ParseTokens( key, "+" ) ); IOMapping::InputType eInputType = GetInputType( IOMapping::kInputSource_Keyboard, inputType); // bind the key BindIO( IOMapping::kInputSource_Keyboard, eInputType, inputCode, pyAction ); }
int ParseTokens(const char* left, const char* right) { int left_int = StringToInt(left); char* tmp = strchr(right, '|'); if(tmp == NULL) return (left_int | StringToInt(right)); tmp[0] = '\0'; tmp++; return (left_int | ParseTokens(right, tmp)); }
BOOL CDocMgr::InitConfigInfo(void) { CString sCfgInfo(m_ConfigInfo); CString sCfgtok(L","); CStringArray resultCfgInfo; try{ int iNum = ParseTokens( resultCfgInfo, sCfgInfo, sCfgtok); if(iNum > 0) { m_WebSvrAddr = resultCfgInfo.GetAt(0); m_TmpPath = resultCfgInfo.GetAt(1); m_MossSiteURL = resultCfgInfo.GetAt(2); m_Comment = resultCfgInfo.GetAt(3); //m_UploadURL = resultCfgInfo.GetAt(2); m_List.m_DefaultURLAddr = m_UploadURL; } m_WebServicesRef.m_TmpPath = m_MossSiteURL;//m_UploadURL; if(!CreateDirectory(m_TmpPath, NULL)) { /*MessageBox(L"创建临时目录失败"); return 1;*/ } } catch(...) { CString str("初始化失败"); MessageBox(str); return FALSE; // 目录无效 } int iRet = -1; BSTR sMessage = L""; //m_WebServicesRef.TestWebSvrRefAddr(m_WebSvrAddr); //TODO: 验证WEBSERVICES是否正确 if(!m_WebServicesRef.TestWebSvrRefAddr(m_WebSvrAddr)) { MessageBox(L"WebServices引用地址无效"); return FALSE; } /*CString sWSDLFile(m_WebSvrAddr); sWSDLFile.Append(L"?wsdl"); m_WebServicesRef.Init(sWSDLFile);*/ // 初始化SOAP CLIENT帐户、口令、超时参数 return TRUE; }
void FSyntaxHighlighterTextLayoutMarshaller::SetText(const FString& SourceString, FTextLayout& TargetTextLayout) { if(bSyntaxHighlightingEnabled) { TArray<FSyntaxTokenizer::FTokenizedLine> TokenizedLines; Tokenizer->Process(TokenizedLines, SourceString); ParseTokens(SourceString, TargetTextLayout, TokenizedLines); } else { FPlainTextLayoutMarshaller::SetText(SourceString, TargetTextLayout); } }
void LoadXMLDoc(XMLDocument& doc, string fileName){ ifstream file; string fileContents; file.open(fileName.c_str()); if(!file.good()){ cout << "Error opening file: " << fileName << endl; return; } while(!file.eof()){ string line; std::getline(file,line,'\n'); fileContents = fileContents + line + "\n"; } vector<Token> tokens = Tokenize(fileContents); for(auto iter = tokens.begin(); iter != tokens.end(); iter++){ //printf("Token: |%.*s|\n", iter->length, iter->start); } ParseTokens(tokens, doc); }
flag CReport::DoExcelReports() { ASSERT(gs_pPrj); CSVColArray c; char Buff[8192]; const int ReportKeyLen = strlen(ReportKey); int i,j,Pos1; char* p; DWORD dwSize = 0; void* pData = NULL; char* pDat; i = 0; flag found = 0; flag DoMore = 1; flag FoundOne = 0; flag DoReportErr = 1; int jStart = 0; CDdeReportInfo& d = gs_pPrj->ReportInfo; while (DoMore && i<d.iVSearchLen) { sprintf(Buff, "R%dC1:R%dC%d", i+1, i+1, d.iHSearchLen+1); pConv->Request(Buff, &pData, &dwSize); //request for a row if (dwSize) {//got row... pDat = (char*)pData; int nToks = ParseTokens(pDat, c, '\t'); XStrRTrim(c[nToks-1], "\r\t\n "); found = False; j = jStart; while (!found && j<nToks) { if (_strnicmp(c[j], ReportKey, ReportKeyLen)==0) { if (ParseFn(c[j])) found = (bAll || sReportName==sName); else { DoReportErr = 0; ReportError(13L, "Illegal syntax for %s....) R%dC%d", ReportKey, i+1, j+1); found = False; } } j++; } delete pData; jStart = 0; if (found) {//found, now get tags... iStartRow = i+1; iStartCol = j; //get the primary tags... if (bVert) sprintf(Buff, "R%dC%d:R%dC%d", iStartRow+1, iStartCol, iStartRow+lALen, iStartCol); else sprintf(Buff, "R%dC%d:R%dC%d", iStartRow, iStartCol+1, iStartRow, iStartCol+lALen); char c = (bVert ? '\r' : '\t'); pConv->Request(Buff, &pData, &dwSize); if (dwSize) { pDat = (char*)pData; Pos1 = 0; int index = 0; p = strchr(pDat, c); while (p) { p[0] = 0; SetATag(index, &pDat[Pos1]); Pos1 = p - pDat + 1; if (bVert) Pos1++; index++; p = strchr(&pDat[Pos1], c); } if (index<lALen) SetATag(index, &pDat[Pos1]); delete pData; } else { pConv->Release(); // and it should get deleted ReportError(14L, "Unable to get primary tags %s from excel", Buff); return False; } //get the secondary tags... if (bVert) sprintf(Buff, "R%dC%d:R%dC%d", iStartRow, iStartCol+1, iStartRow, iStartCol+lBLen); else sprintf(Buff, "R%dC%d:R%dC%d", iStartRow+1, iStartCol, iStartRow+lBLen, iStartCol); c = (bVert ? '\t' : '\r'); pConv->Request(Buff, &pData, &dwSize); if (dwSize) { pDat = (char*)pData; Pos1 = 0; int index = 0; p = strchr(pDat, c); while (p) { p[0] = 0; SetBTag(index, &pDat[Pos1]); Pos1 = p - pDat + 1; if (!bVert) Pos1++; index++; p = strchr(&pDat[Pos1], c); } if (index<lBLen) SetBTag(index, &pDat[Pos1]); delete pData; } else { pConv->Release(); // and it should get deleted ReportError(15L, "Unable to get secondary tags %s from excel", Buff); return False; } //have the primary and secondry tags, do the report... DoReport(); FoundOne = 1; DoMore = bAll; i--; jStart = j; } } else { pConv->Release(); // and it should get deleted ReportError(11L, "Unable to get request %s from excel", Buff); return False; } i++; } if (!FoundOne) { pConv->Release(); // and it should get deleted if (DoReportErr) ReportError(12L, "Unable to find %s....)", ReportKey); return False; } return True; }
void UseOverride::check(const MatchFinder::MatchResult &Result) { const FunctionDecl *Method = Result.Nodes.getStmtAs<FunctionDecl>("method"); const SourceManager &Sources = *Result.SourceManager; assert(Method != nullptr); if (Method->getInstantiatedFromMemberFunction() != nullptr) Method = Method->getInstantiatedFromMemberFunction(); if (Method->isImplicit() || Method->getLocation().isMacroID() || Method->isOutOfLine()) return; bool HasVirtual = Method->isVirtualAsWritten(); bool HasOverride = Method->getAttr<OverrideAttr>(); bool HasFinal = Method->getAttr<FinalAttr>(); bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal; unsigned KeywordCount = HasVirtual + HasOverride + HasFinal; if (!OnlyVirtualSpecified && KeywordCount == 1) return; // Nothing to do. DiagnosticBuilder Diag = diag( Method->getLocation(), OnlyVirtualSpecified ? "Prefer using 'override' or (rarely) 'final' instead of 'virtual'" : "Annotate this function with 'override' or (rarely) 'final'"); CharSourceRange FileRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(Method->getSourceRange()), Sources, Result.Context->getLangOpts()); if (!FileRange.isValid()) return; // FIXME: Instead of re-lexing and looking for specific macros such as // 'ABSTRACT', properly store the location of 'virtual' and '= 0' in each // FunctionDecl. SmallVector<Token, 16> Tokens = ParseTokens(FileRange, Result); // Add 'override' on inline declarations that don't already have it. if (!HasFinal && !HasOverride) { SourceLocation InsertLoc; StringRef ReplacementText = "override "; for (Token T : Tokens) { if (T.is(tok::kw___attribute)) { InsertLoc = T.getLocation(); break; } } if (Method->hasAttrs()) { for (const clang::Attr *A : Method->getAttrs()) { if (!A->isImplicit()) { SourceLocation Loc = Sources.getExpansionLoc(A->getRange().getBegin()); if (!InsertLoc.isValid() || Sources.isBeforeInTranslationUnit(Loc, InsertLoc)) InsertLoc = Loc; } } } if (InsertLoc.isInvalid() && Method->doesThisDeclarationHaveABody() && Method->getBody() && !Method->isDefaulted()) InsertLoc = Method->getBody()->getLocStart(); if (!InsertLoc.isValid()) { if (Tokens.size() > 2 && GetText(Tokens.back(), Sources) == "0" && GetText(Tokens[Tokens.size() - 2], Sources) == "=") { InsertLoc = Tokens[Tokens.size() - 2].getLocation(); } else if (GetText(Tokens.back(), Sources) == "ABSTRACT") { InsertLoc = Tokens.back().getLocation(); } } if (!InsertLoc.isValid()) { InsertLoc = FileRange.getEnd(); ReplacementText = " override"; } Diag << FixItHint::CreateInsertion(InsertLoc, ReplacementText); } if (HasFinal && HasOverride) { SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation(); Diag << FixItHint::CreateRemoval( CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc)); } if (Method->isVirtualAsWritten()) { for (Token Tok : Tokens) { if (Tok.is(tok::kw_virtual)) { Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( Tok.getLocation(), Tok.getLocation())); break; } } } }
void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { const auto *Method = Result.Nodes.getNodeAs<FunctionDecl>("method"); const SourceManager &Sources = *Result.SourceManager; assert(Method != nullptr); if (Method->getInstantiatedFromMemberFunction() != nullptr) Method = Method->getInstantiatedFromMemberFunction(); if (Method->isImplicit() || Method->getLocation().isMacroID() || Method->isOutOfLine()) return; bool HasVirtual = Method->isVirtualAsWritten(); bool HasOverride = Method->getAttr<OverrideAttr>(); bool HasFinal = Method->getAttr<FinalAttr>(); bool OnlyVirtualSpecified = HasVirtual && !HasOverride && !HasFinal; unsigned KeywordCount = HasVirtual + HasOverride + HasFinal; if (!OnlyVirtualSpecified && KeywordCount == 1) return; // Nothing to do. std::string Message; if (OnlyVirtualSpecified) { Message = "prefer using 'override' or (rarely) 'final' instead of 'virtual'"; } else if (KeywordCount == 0) { Message = "annotate this function with 'override' or (rarely) 'final'"; } else { StringRef Redundant = HasVirtual ? (HasOverride && HasFinal ? "'virtual' and 'override' are" : "'virtual' is") : "'override' is"; StringRef Correct = HasFinal ? "'final'" : "'override'"; Message = (llvm::Twine(Redundant) + " redundant since the function is already declared " + Correct) .str(); } DiagnosticBuilder Diag = diag(Method->getLocation(), Message); CharSourceRange FileRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(Method->getSourceRange()), Sources, getLangOpts()); if (!FileRange.isValid()) return; // FIXME: Instead of re-lexing and looking for specific macros such as // 'ABSTRACT', properly store the location of 'virtual' and '= 0' in each // FunctionDecl. SmallVector<Token, 16> Tokens = ParseTokens(FileRange, Result); // Add 'override' on inline declarations that don't already have it. if (!HasFinal && !HasOverride) { SourceLocation InsertLoc; StringRef ReplacementText = "override "; SourceLocation MethodLoc = Method->getLocation(); for (Token T : Tokens) { if (T.is(tok::kw___attribute) && !Sources.isBeforeInTranslationUnit(T.getLocation(), MethodLoc)) { InsertLoc = T.getLocation(); break; } } if (Method->hasAttrs()) { for (const clang::Attr *A : Method->getAttrs()) { if (!A->isImplicit() && !A->isInherited()) { SourceLocation Loc = Sources.getExpansionLoc(A->getRange().getBegin()); if ((!InsertLoc.isValid() || Sources.isBeforeInTranslationUnit(Loc, InsertLoc)) && !Sources.isBeforeInTranslationUnit(Loc, MethodLoc)) InsertLoc = Loc; } } } if (InsertLoc.isInvalid() && Method->doesThisDeclarationHaveABody() && Method->getBody() && !Method->isDefaulted()) { // For methods with inline definition, add the override keyword at the // end of the declaration of the function, but prefer to put it on the // same line as the declaration if the beginning brace for the start of // the body falls on the next line. Token LastNonCommentToken; for (Token T : Tokens) { if (!T.is(tok::comment)) { LastNonCommentToken = T; } } InsertLoc = LastNonCommentToken.getEndLoc(); ReplacementText = " override"; } if (!InsertLoc.isValid()) { // For declarations marked with "= 0" or "= [default|delete]", the end // location will point until after those markings. Therefore, the override // keyword shouldn't be inserted at the end, but before the '='. if (Tokens.size() > 2 && (GetText(Tokens.back(), Sources) == "0" || Tokens.back().is(tok::kw_default) || Tokens.back().is(tok::kw_delete)) && GetText(Tokens[Tokens.size() - 2], Sources) == "=") { InsertLoc = Tokens[Tokens.size() - 2].getLocation(); // Check if we need to insert a space. if ((Tokens[Tokens.size() - 2].getFlags() & Token::LeadingSpace) == 0) ReplacementText = " override "; } else if (GetText(Tokens.back(), Sources) == "ABSTRACT") { InsertLoc = Tokens.back().getLocation(); } } if (!InsertLoc.isValid()) { InsertLoc = FileRange.getEnd(); ReplacementText = " override"; } Diag << FixItHint::CreateInsertion(InsertLoc, ReplacementText); } if (HasFinal && HasOverride) { SourceLocation OverrideLoc = Method->getAttr<OverrideAttr>()->getLocation(); Diag << FixItHint::CreateRemoval( CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc)); } if (HasVirtual) { for (Token Tok : Tokens) { if (Tok.is(tok::kw_virtual)) { Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( Tok.getLocation(), Tok.getLocation())); break; } } } }