From 45f9d6e13be537dc65e3badf1e2f2bcce17fcedf Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 20 Mar 2013 22:50:48 +0000 Subject: [PATCH] [UPDATE] Build-in FunctionList in progress. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1031 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../FunctionList/functionListPanel.cpp | 2 + .../FunctionList/functionParser.cpp | 318 ++++++++++++------ .../WinControls/FunctionList/functionParser.h | 28 +- PowerEditor/src/functionList.xml | 97 ++++-- 4 files changed, 305 insertions(+), 140 deletions(-) diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 835fdf63..1a2e1efb 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -237,6 +237,8 @@ void FunctionListPanel::reload() } } } + + void FunctionListPanel::init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { DockingDlgInterface::init(hInst, hPere); diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp index 5aad3d04..0d492988 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.cpp @@ -30,6 +30,14 @@ #include "functionParser.h" #include "boostregexsearch.h" +FunctionParsersManager::~FunctionParsersManager() +{ + for (size_t i = 0; i < _parsers.size(); i++) + { + delete _parsers[i]; + } +} + bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** ppEditView) { _ppEditView = ppEditView; @@ -48,6 +56,118 @@ bool FunctionParsersManager::init(generic_string xmlPath, ScintillaEditView ** p return loadOkay; } +bool FunctionParsersManager::getZonePaserParameters(TiXmlNode *classRangeParser, generic_string &commentExprStr, generic_string &mainExprStr, generic_string &openSymboleStr, generic_string &closeSymboleStr, std::vector &classNameExprArray, generic_string &functionExprStr, std::vector &functionNameExprArray) +{ + const TCHAR *mainExpr = NULL; + const TCHAR *openSymbole = NULL; + const TCHAR *closeSymbole = NULL; + const TCHAR *commentExpr = NULL; + const TCHAR *functionExpr = NULL; + + mainExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr")); + if (!mainExpr || !mainExpr[0]) + return false; + mainExprStr = mainExpr; + + openSymbole = (classRangeParser->ToElement())->Attribute(TEXT("openSymbole")); + if (openSymbole && openSymbole[0]) + openSymboleStr = openSymbole; + + closeSymbole = (classRangeParser->ToElement())->Attribute(TEXT("closeSymbole")); + if (closeSymbole && closeSymbole[0]) + closeSymboleStr = closeSymbole; + + TiXmlNode *commentSymbols = classRangeParser->FirstChild(TEXT("comment")); + if (commentSymbols) + { + commentExpr = (commentSymbols->ToElement())->Attribute(TEXT("expr")); + if (commentExpr) + commentExprStr = commentExpr; + } + + TiXmlNode *classNameParser = classRangeParser->FirstChild(TEXT("className")); + if (classNameParser) + { + for (TiXmlNode *childNode2 = classNameParser->FirstChildElement(TEXT("nameExpr")); + childNode2; + childNode2 = childNode2->NextSibling(TEXT("nameExpr")) ) + { + const TCHAR *expr = (childNode2->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + classNameExprArray.push_back(expr); + } + } + + TiXmlNode *functionParser = classRangeParser->FirstChild(TEXT("function")); + if (!functionParser) + return false; + + functionExpr = (functionParser->ToElement())->Attribute(TEXT("mainExpr")); + if (!functionExpr || !functionExpr[0]) + return false; + functionExprStr = functionExpr; + + TiXmlNode *functionNameParser = functionParser->FirstChild(TEXT("functionName")); + if (functionNameParser) + { + for (TiXmlNode *childNode3 = functionNameParser->FirstChildElement(TEXT("funcNameExpr")); + childNode3; + childNode3 = childNode3->NextSibling(TEXT("funcNameExpr")) ) + { + const TCHAR *expr = (childNode3->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + functionNameExprArray.push_back(expr); + } + + } + return true; +} + +bool FunctionParsersManager::getUnitPaserParameters(TiXmlNode *functionParser, generic_string &commentExprStr, generic_string &mainExprStr, std::vector &functionNameExprArray, std::vector &classNameExprArray) +{ + const TCHAR *commentExpr = NULL; + const TCHAR *mainExpr = (functionParser->ToElement())->Attribute(TEXT("mainExpr")); + if (!mainExpr || !mainExpr[0]) + return false; + mainExprStr = mainExpr; + + TiXmlNode *commentSymbols = functionParser->FirstChild(TEXT("comment")); + if (commentSymbols) + { + commentExpr = (commentSymbols->ToElement())->Attribute(TEXT("expr")); + if (commentExpr && commentExpr[0]) + commentExprStr = commentExpr; + } + + TiXmlNode *functionNameParser = functionParser->FirstChild(TEXT("functionName")); + if (functionNameParser) + { + for (TiXmlNode *childNode = functionNameParser->FirstChildElement(TEXT("nameExpr")); + childNode; + childNode = childNode->NextSibling(TEXT("nameExpr")) ) + { + const TCHAR *expr = (childNode->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + functionNameExprArray.push_back(expr); + } + } + + TiXmlNode *classNameParser = functionParser->FirstChild(TEXT("className")); + if (functionNameParser) + { + for (TiXmlNode *childNode = classNameParser->FirstChildElement(TEXT("nameExpr")); + childNode; + childNode = childNode->NextSibling(TEXT("nameExpr")) ) + { + const TCHAR *expr = (childNode->ToElement())->Attribute(TEXT("expr")); + if (expr && expr[0]) + classNameExprArray.push_back(expr); + } + } + return true; +} + + bool FunctionParsersManager::getFuncListFromXmlTree() { if (!_pXmlFuncListDoc) @@ -74,117 +194,39 @@ bool FunctionParsersManager::getFuncListFromXmlTree() if (!id || !id[0]) continue; - std::vector classNameExprArray; - const TCHAR *functionExpr = NULL; std::vector functionNameExprArray; const TCHAR *displayName = (childNode->ToElement())->Attribute(TEXT("displayName")); if (!displayName || !displayName[0]) displayName = id; - const TCHAR *commentExpr = NULL; - TiXmlNode *classRangeParser = childNode->FirstChild(TEXT("classRange")); - if (classRangeParser) + TiXmlNode *functionParser = childNode->FirstChild(TEXT("function")); + if (classRangeParser && functionParser) { - const TCHAR *mainExpr = NULL; - const TCHAR *openSymbole = NULL; - const TCHAR *closeSymbole = NULL; + generic_string commentExpr, mainExpr, openSymbole, closeSymbole, functionExpr; + getZonePaserParameters(classRangeParser, commentExpr, mainExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray); + + generic_string commentExpr2, mainExpr2; + std::vector classNameExprArray2; + std::vector functionNameExprArray2; + getUnitPaserParameters(functionParser, commentExpr2, mainExpr2, functionNameExprArray2, classNameExprArray2); + FunctionUnitParser *funcUnitPaser = new FunctionUnitParser(id, displayName, commentExpr2.c_str(), mainExpr2.c_str(), functionNameExprArray2, classNameExprArray2); - mainExpr = (classRangeParser->ToElement())->Attribute(TEXT("mainExpr")); - if (!mainExpr) - continue; - - openSymbole = (classRangeParser->ToElement())->Attribute(TEXT("openSymbole")); - closeSymbole = (classRangeParser->ToElement())->Attribute(TEXT("closeSymbole")); - TiXmlNode *commentSymbols = classRangeParser->FirstChild(TEXT("comment")); - if (commentSymbols) - { - commentExpr = (commentSymbols->ToElement())->Attribute(TEXT("expr")); - } - - TiXmlNode *classNameParser = classRangeParser->FirstChild(TEXT("className")); - if (classNameParser) - { - for (TiXmlNode *childNode2 = classNameParser->FirstChildElement(TEXT("nameExpr")); - childNode2; - childNode2 = childNode2->NextSibling(TEXT("nameExpr")) ) - { - const TCHAR *expr = (childNode2->ToElement())->Attribute(TEXT("expr")); - if (expr && expr[0]) - classNameExprArray.push_back(expr); - } - } - - TiXmlNode *functionParser = classRangeParser->FirstChild(TEXT("function")); - if (!functionParser) - continue; - - functionExpr = (functionParser->ToElement())->Attribute(TEXT("mainExpr")); - if (!functionExpr) - continue; - - TiXmlNode *functionNameParser = functionParser->FirstChild(TEXT("functionName")); - if (functionNameParser) - { - for (TiXmlNode *childNode3 = functionNameParser->FirstChildElement(TEXT("funcNameExpr")); - childNode3; - childNode3 = childNode3->NextSibling(TEXT("funcNameExpr")) ) - { - const TCHAR *expr = (childNode3->ToElement())->Attribute(TEXT("expr")); - if (expr && expr[0]) - functionNameExprArray.push_back(expr); - } - - } - - _parsers.push_back(new FunctionZoneParser(id, displayName, commentExpr, mainExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray)); + _parsers.push_back(new FunctionMixParser(id, displayName, commentExpr.c_str(), mainExpr.c_str(), openSymbole.c_str(), closeSymbole.c_str(), classNameExprArray, functionExpr.c_str(), functionNameExprArray, funcUnitPaser)); } - else + else if (classRangeParser) { - TiXmlNode *functionParser = childNode->FirstChild(TEXT("function")); - if (!functionParser) - { - continue; - } - - const TCHAR *mainExpr = (functionParser->ToElement())->Attribute(TEXT("mainExpr")); - if (!mainExpr) - continue; - - TiXmlNode *commentSymbols = functionParser->FirstChild(TEXT("comment")); - if (commentSymbols) - { - commentExpr = (commentSymbols->ToElement())->Attribute(TEXT("expr")); - } - - TiXmlNode *functionNameParser = functionParser->FirstChild(TEXT("functionName")); - if (functionNameParser) - { - for (TiXmlNode *childNode = functionNameParser->FirstChildElement(TEXT("nameExpr")); - childNode; - childNode = childNode->NextSibling(TEXT("nameExpr")) ) - { - const TCHAR *expr = (childNode->ToElement())->Attribute(TEXT("expr")); - if (expr && expr[0]) - functionNameExprArray.push_back(expr); - } - } - - TiXmlNode *classNameParser = functionParser->FirstChild(TEXT("className")); - if (functionNameParser) - { - for (TiXmlNode *childNode = classNameParser->FirstChildElement(TEXT("nameExpr")); - childNode; - childNode = childNode->NextSibling(TEXT("nameExpr")) ) - { - const TCHAR *expr = (childNode->ToElement())->Attribute(TEXT("expr")); - if (expr && expr[0]) - classNameExprArray.push_back(expr); - } - } - _parsers.push_back(new FunctionUnitParser(id, displayName, commentExpr, mainExpr, functionNameExprArray, classNameExprArray)); + generic_string commentExpr, mainExpr, openSymbole, closeSymbole, functionExpr; + getZonePaserParameters(classRangeParser, commentExpr, mainExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray); + _parsers.push_back(new FunctionZoneParser(id, displayName, commentExpr.c_str(), mainExpr.c_str(), openSymbole.c_str(), closeSymbole.c_str(), classNameExprArray, functionExpr.c_str(), functionNameExprArray)); + } + else if (functionParser) + { + generic_string commentExpr, mainExpr; + getUnitPaserParameters(functionParser, commentExpr, mainExpr, functionNameExprArray, classNameExprArray); + _parsers.push_back(new FunctionUnitParser(id, displayName, commentExpr.c_str(), mainExpr.c_str(), functionNameExprArray, classNameExprArray)); } } @@ -228,6 +270,9 @@ FunctionParser * FunctionParsersManager::getParser(int langID) FunctionParser * FunctionParsersManager::getParser(generic_string ext) { + if (ext == TEXT("")) + return NULL; + for (size_t i = 0; i < _associationMap.size(); i++) { if (ext == _associationMap[i]._ext) @@ -241,6 +286,9 @@ void FunctionParser::funcParse(std::vector & foundInfos, size_t begi if (begin >= end) return; + if (_functionExpr.length() == 0) + return; + int flags = SCFIND_REGEXP | SCFIND_POSIX | SCFIND_REGEXP_DOTMATCHESNL; (*ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); @@ -281,16 +329,16 @@ void FunctionParser::funcParse(std::vector & foundInfos, size_t begi fi._pos = foundPos; } - if (_classNameExprArray.size()) - { - fi._data2 = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); - fi._pos2 = foundPos; - } - else if (classStructName != TEXT("")) + if (classStructName != TEXT("")) { fi._data2 = classStructName; fi._pos2 = 0; // change -1 valeur for validated data2 } + else if (_classNameExprArray.size()) + { + fi._data2 = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); + fi._pos2 = foundPos; + } } if (fi._pos != -1 || fi._pos2 != -1) // at least one should be found @@ -430,7 +478,7 @@ size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSy return targetEnd; } -void FunctionZoneParser::classParse(vector & foundInfos, vector< pair > &scannedZone, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) +void FunctionZoneParser::classParse(vector & foundInfos, vector< pair > &scannedZones, const std::vector< std::pair > & commentZones, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) { if (begin >= end) return; @@ -439,12 +487,12 @@ void FunctionZoneParser::classParse(vector & foundInfos, vector< pair (*ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); int targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end); + int targetEnd = 0; while (targetStart != -1 && targetStart != -2) { targetEnd = int((*ppEditView)->execute(SCI_GETTARGETEND)); - scannedZone.push_back(pair(targetStart, targetEnd)); // Get class name int foundPos = 0; @@ -460,14 +508,19 @@ void FunctionZoneParser::classParse(vector & foundInfos, vector< pair { break; } + + scannedZones.push_back(pair(targetStart, targetEnd)); + int foundTextLen = targetEnd - targetStart; if (targetStart + foundTextLen == int(end)) break; // Begin to search all method inside - vector< generic_string > emptyArray; - funcParse(foundInfos, targetStart, targetEnd, ppEditView, classStructName); - + //vector< generic_string > emptyArray; + if (!isInZones(targetStart, commentZones)) + { + funcParse(foundInfos, targetStart, targetEnd, ppEditView, classStructName); + } begin = targetStart + (targetEnd - targetStart); targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end); } @@ -506,6 +559,18 @@ void FunctionParser::getCommentZones(vector< pair > & commentZone, siz } } +bool FunctionParser::isInZones(int pos2Test, const std::vector< std::pair > & zones) +{ + for (size_t i = 0; i < zones.size(); i++) + { + if (pos2Test >= zones[i].first && pos2Test < zones[i].second) + { + return true; + } + } + return false; +} + void FunctionParser::getInvertZones(vector< pair > & destZones, vector< pair > & sourceZones, size_t begin, size_t end) { if (sourceZones.size() == 0) @@ -536,12 +601,12 @@ void FunctionParser::getInvertZones(vector< pair > & destZones, vecto void FunctionZoneParser::parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) { - vector< pair > commentZones, nonCommentZones; + vector< pair > classZones, commentZones, nonCommentZones; getCommentZones(commentZones, begin, end, ppEditView); getInvertZones(nonCommentZones, commentZones, begin, end); for (size_t i = 0; i < nonCommentZones.size(); i++) { - classParse(foundInfos, commentZones, nonCommentZones[i].first, nonCommentZones[i].second, ppEditView, classStructName); + classParse(foundInfos, classZones, commentZones, nonCommentZones[i].first, nonCommentZones[i].second, ppEditView, classStructName); } } @@ -554,4 +619,33 @@ void FunctionUnitParser::parse(std::vector & foundInfos, size_t begin { funcParse(foundInfos, nonCommentZones[i].first, nonCommentZones[i].second, ppEditView, classStructName); } +} + +// +// SortClass for vector> +// sort in _selLpos : increased order +struct SortZones { + bool operator() (pair & l, pair & r) { + return (l.first < r.first); + } +}; + +void FunctionMixParser::parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) +{ + vector< pair > commentZones, scannedZones, nonCommentZones, nonScannedZones; + getCommentZones(commentZones, begin, end, ppEditView); + + classParse(foundInfos, scannedZones, commentZones, begin, end, ppEditView, classStructName); + + // invert scannedZones + getInvertZones(nonScannedZones, scannedZones, begin, end); + + // for each nonScannedZones, search functions + if (_funcUnitPaser) + { + for (size_t i = 0; i < nonScannedZones.size(); i++) + { + _funcUnitPaser->funcParse(foundInfos, nonScannedZones[i].first, nonScannedZones[i].second, ppEditView, classStructName); + } + } } \ No newline at end of file diff --git a/PowerEditor/src/WinControls/FunctionList/functionParser.h b/PowerEditor/src/WinControls/FunctionList/functionParser.h index 9afb2421..4f21fbe8 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionParser.h +++ b/PowerEditor/src/WinControls/FunctionList/functionParser.h @@ -30,6 +30,7 @@ class ScintillaEditView; class TiXmlDocument; +class TiXmlNode; struct foundInfo { generic_string _data; @@ -47,6 +48,7 @@ public: virtual void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")) = 0; void funcParse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); + bool isInZones(int pos2Test, const std::vector< std::pair > & zones); protected: generic_string _id; generic_string _displayName; @@ -68,19 +70,20 @@ public: void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); +protected: + void classParse(std::vector & foundInfos, std::vector< std::pair > & scannedZones, const std::vector< std::pair > & commentZones, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); private: generic_string _rangeExpr; generic_string _openSymbole; generic_string _closeSymbole; - //std::vector _classNameExprArray; generic_string _functionExpr; - //std::vector _functionNameExprArray; - void classParse(std::vector & foundInfos, std::vector< std::pair > & scannedZone, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); size_t getBodyClosePos(size_t begin, const TCHAR *bodyOpenSymbol, const TCHAR *bodyCloseSymbol, ScintillaEditView **ppEditView); }; + + class FunctionUnitParser : public FunctionParser { public: FunctionUnitParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, @@ -91,6 +94,22 @@ public: }; +class FunctionMixParser : public FunctionZoneParser { +public: + FunctionMixParser(const TCHAR *id, const TCHAR *displayName, const TCHAR *commentExpr, generic_string rangeExpr, generic_string openSymbole, generic_string closeSymbole, + std::vector classNameExprArray, generic_string functionExpr, std::vector functionNameExprArray, FunctionUnitParser *funcUnitPaser): + FunctionZoneParser(id, displayName, commentExpr, rangeExpr, openSymbole, closeSymbole, classNameExprArray, functionExpr, functionNameExprArray), _funcUnitPaser(funcUnitPaser){}; + + ~FunctionMixParser() { + if (_funcUnitPaser) + delete _funcUnitPaser; + } + void parse(std::vector & foundInfos, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName = TEXT("")); + +private: + FunctionUnitParser *_funcUnitPaser; +}; + struct AssociationInfo { int _id; int _langID; @@ -102,6 +121,7 @@ struct AssociationInfo { class FunctionParsersManager { public: FunctionParsersManager() : _ppEditView(NULL), _pXmlFuncListDoc(NULL){}; + ~FunctionParsersManager(); bool init(generic_string xmlPath, ScintillaEditView ** ppEditView); bool parse(std::vector & foundInfos, int langID); bool parse(std::vector & foundInfos, generic_string ext); @@ -113,6 +133,8 @@ private: TiXmlDocument *_pXmlFuncListDoc; bool getFuncListFromXmlTree(); + bool getZonePaserParameters(TiXmlNode *classRangeParser, generic_string &commentExprStr, generic_string &mainExprStr, generic_string &openSymboleStr, generic_string &closeSymboleStr, std::vector &classNameExprArray, generic_string &functionExprStr, std::vector &functionNameExprArray); + bool getUnitPaserParameters(TiXmlNode *functionParser, generic_string &commentExprStr, generic_string &mainExprStr, std::vector &functionNameExprArray, std::vector &classNameExprArray); FunctionParser * getParser(generic_string ext); FunctionParser * getParser(int langID); }; diff --git a/PowerEditor/src/functionList.xml b/PowerEditor/src/functionList.xml index de907e17..6ad619ca 100644 --- a/PowerEditor/src/functionList.xml +++ b/PowerEditor/src/functionList.xml @@ -2,12 +2,26 @@ - - - - - - + + + + + @@ -23,19 +37,17 @@ + mainExpr="^[\t ]*((static|const|virtual)[\s]+)?[\w]+([\s]+|\*[\s]+|[\s]+\*|[\s]+\*[\s]+)([\w_]+[\s]*::)?(?!(if|whil|for))[\w_]+[\s]*\([\n\w_,*&\s]*\)([\s]*const[\s]*)?[\n\s]*\{"> - - + @@ -49,20 +61,55 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +