private void addCodeFileIfNeccesary(FileInfo aFileInfo) { if (isExistCodeFile(aFileInfo)) {// 既にある return; } CodeFile codeFile = new CodeFile(aFileInfo, Regex.IsMatch(aFileInfo.Name, sourceRegexString)); codeFiles.AddCodeFileRef(codeFile); // コールバック onAnalyzerStartFunc(aFileInfo); // 解析 Regex regex = new Regex(@"^(#include)( )+([""<])(?<1>([a-zA-Z0-9_/.]+))(["">])"); string[] lines = File.ReadAllLines(aFileInfo.FullName); foreach (string line in lines) { Match match = regex.Match(line); if (match.Success) { // 該当するヘッダファイルを探す bool isFound = false; string headerPath = match.Groups[1].ToString(); foreach (DirectoryInfo dirInfo in includeDirs) { if (!dirInfo.Exists) {// ディレクトリがない continue; } FileInfo headerFile = new FileInfo(dirInfo.FullName + @"\" + headerPath); if (!headerFile.Exists) {// ファイル見つからず continue; } isFound = true; // まだなければ作成 addCodeFileIfNeccesary(headerFile); // インクルードの登録 codeFile.includeCodeFiles.AddCodeFileRef(getCodeFile(headerFile)); // 参照の登録 getCodeFile(headerFile).referencedCodeFiles.AddCodeFileRef(codeFile); } if (!isFound) { //System.Console.WriteLine("[警告] " + codeFile.fileInfo.FullName + "がインクルードするファイル" + headerPath + "が見つかりませんでした。"); } } } }
// calculateTotalIncludeCountとは逆の方向で計算。 private uint calculateTotalIncludeCountRev(CodeFile aCodeFile, CodeFileTable aGuardTable) { if (aGuardTable.IsExistCodeFile(aCodeFile.fileInfo)) {// 既に計算済み return(0); } aGuardTable.AddCodeFileRef(aCodeFile); uint cnt = 0; if (aCodeFile.IsSource()) {// ソースファイルを数に含める ++cnt; } foreach (CodeFile subCodeFile in aCodeFile.includeCodeFiles.GetCodeFiles()) { cnt += calculateTotalIncludeCountRev(subCodeFile, aGuardTable); } return(cnt); }