vera++-1.2.1/cmake/CMakeLists.txt000644 000765 000024 00000000771 12154326666 017372 0ustar00glehmannstaff000000 000000 include(WriteBasicConfigVersionFile) write_basic_config_version_file( ${CMAKE_CURRENT_BINARY_DIR}/vera++-config-version.cmake VERSION ${VERA_VERSION} COMPATIBILITY AnyNewerVersion) if(WIN) set(destdir cmake/) else() set(destdir lib/vera++/) endif() install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vera++-config-version.cmake ${CMAKE_CURRENT_SOURCE_DIR}/vera++-config.cmake ${CMAKE_CURRENT_SOURCE_DIR}/use_vera++.cmake ${CMAKE_CURRENT_SOURCE_DIR}/test_wrapper.cmake.in DESTINATION ${destdir}) vera++-1.2.1/cmake/test_wrapper.cmake.in000644 000765 000024 00000001462 12154326666 020756 0ustar00glehmannstaff000000 000000 message("Running: \"${VERA_PROGRAM}\" @protected_args@") execute_process(COMMAND "${VERA_PROGRAM}" @args@ RESULT_VARIABLE ret OUTPUT_VARIABLE output ERROR_VARIABLE error @input_option@) message("return value: ${ret}") message("---output---\n${output}---error----\n${error}------------") set(fail OFF) if(NOT ${ret} EQUAL @retcode@) message("Invalid return code. Expected return code was @retcode@.") set(fail ON) endif() if(NOT "${output}" STREQUAL "@protected_output@") message("Output mismatch. Expected content was:") message("@protected_output@---") set(fail ON) endif() if(NOT "${error}" STREQUAL "@protected_error@") message("Output mismatch. Expected content was:") message("@protected_error@---") set(fail ON) endif() if(fail) message(FATAL_ERROR "some errors occurred.") endif() vera++-1.2.1/cmake/use_vera++.cmake000644 000765 000024 00000014257 12154326666 017577 0ustar00glehmannstaff000000 000000 # remember where test_wrapper.cmake.in is get_filename_component(VERA_TEST_WRAPPER_CMAKE ${CMAKE_CURRENT_LIST_FILE}/../test_wrapper.cmake.in ABSOLUTE) function(vera_add_test_stdin_file name input output error retcode) if(NOT "${input}" STREQUAL "") set(input_option "INPUT_FILE \"${input}\"") else() set(input_option) endif() string(REPLACE ";" "\" \"" args "${ARGN}") set(args "\"${args}\"") string(REPLACE "\"" "\\\"" protected_args "${args}") string(REPLACE "\\" "\\\\" protected_output "${output}") string(REPLACE "\"" "\\\"" protected_output "${protected_output}") string(REPLACE "\\" "\\\\" protected_error "${error}") string(REPLACE "\"" "\\\"" protected_error "${protected_error}") configure_file(${VERA_TEST_WRAPPER_CMAKE} ${CMAKE_CURRENT_BINARY_DIR}/${name}.cmake @ONLY) if(NOT VERA++_EXECUTABLE AND TARGET vera) set(vera_program "$") else() set(vera_program "${VERA++_EXECUTABLE}") endif() add_test(NAME ${name} COMMAND ${CMAKE_COMMAND} -D VERA_PROGRAM:FILEPATH=${vera_program} -P ${CMAKE_CURRENT_BINARY_DIR}/${name}.cmake) endfunction() function(vera_add_test name input output error retcode) if(NOT "${input}" STREQUAL "") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${name}-input.txt" "${input}") set(input_file "${CMAKE_CURRENT_BINARY_DIR}/${name}-input.txt") else() set(input_file) endif() vera_add_test_stdin_file("${name}" "${input_file}" "${output}" "${error}" "${retcode}" ${ARGN}) endfunction() function(vera_add_rule_test name output) if(VERA_TEST_RULE_ROOT) set(root ${VERA_TEST_RULE_ROOT}) else() set(root ${CMAKE_CURRENT_SOURCE_DIR}) endif() set(full_input "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp") string(REPLACE "\n" "\n${full_input}:" formated_output "${output}") set(formated_output "${full_input}:${formated_output}\n") vera_add_test(Rule${name} "" "${formated_output}" "" 0 --root ${root} --rule ${name} ${full_input} ) endfunction() macro(vera_incr var_name) math(EXPR ${var_name} "${${var_name}} + 1") endmacro() function(add_vera_targets) # default values set(target "style") set(target_all "style_reports") set(profile "default") set(root "${CMAKE_CURRENT_BINARY_DIR}") set(exclusions) set(recurse OFF) set(globs) # parse the options math(EXPR lastIdx "${ARGC} - 1") set(i 0) while(i LESS ${ARGC}) set(arg "${ARGV${i}}") if("${arg}" STREQUAL "NAME") vera_incr(i) set(target "${ARGV${i}}") elseif("${arg}" STREQUAL "NAME_ALL") vera_incr(i) set(target_all "${ARGV${i}}") elseif("${arg}" STREQUAL "ROOT") vera_incr(i) set(root "${ARGV${i}}") elseif("${arg}" STREQUAL "PROFILE") vera_incr(i) set(profile "${ARGV${i}}") elseif("${arg}" STREQUAL "EXCLUSION") vera_incr(i) list(APPEND exclusions --exclusions "${ARGV${i}}") elseif("${arg}" STREQUAL "RECURSE") set(recurse ON) else() list(APPEND globs ${arg}) endif() vera_incr(i) endwhile() if(recurse) file(GLOB_RECURSE srcs ${globs}) else() file(GLOB srcs ${globs}) endif() list(SORT srcs) if(NOT VERA++_EXECUTABLE AND TARGET vera) set(vera_program "$") else() set(vera_program "${VERA++_EXECUTABLE}") endif() # Two custom targets will be created: # * style_reports is run as part of the build, and is not rerun unless one of # the file checked is modified; # * style must be explicitely called (make style) and is rerun even if the files # to check have not been modified. To achieve this behavior, the commands used # in this target pretend to produce a file without actually producing it. # Because the output file is not there after the run, the command will be rerun # again at the next target build. # The report style is selected based on the build environment, so the style # problems are properly reported in the IDEs if(MSVC) set(style vc) else() set(style std) endif() set(xmlreports) set(noreports) set(reportNb 0) set(reportsrcs) list(GET srcs 0 first) get_filename_component(currentDir ${first} PATH) # add a fake src file in a fake dir to trigger the creation of the last # custom command list(APPEND srcs "#12345678900987654321#/0987654321#1234567890") foreach(s ${srcs}) get_filename_component(d ${s} PATH) if(NOT "${d}" STREQUAL "${currentDir}") # this is a new dir - lets generate everything needed for the previous dir string(LENGTH "${CMAKE_SOURCE_DIR}" len) string(SUBSTRING "${currentDir}" 0 ${len} pre) if("${pre}" STREQUAL "${CMAKE_SOURCE_DIR}") string(SUBSTRING "${currentDir}" ${len} -1 currentDir) string(REGEX REPLACE "^/" "" currentDir "${currentDir}") endif() if("${currentDir}" STREQUAL "") set(currentDir ".") endif() set(xmlreport ${CMAKE_CURRENT_BINARY_DIR}/vera_report_${reportNb}.xml) add_custom_command( OUTPUT ${xmlreport} COMMAND ${vera_program} --root ${root} --profile ${profile} --${style}-report=- --show-rule --warning --xml-report=${xmlreport} ${exclusions} ${reportsrcs} DEPENDS ${reportsrcs} COMMENT "Checking style with vera++ in ${currentDir}" ) set(noreport ${CMAKE_CURRENT_BINARY_DIR}/vera_noreport_${reportNb}.xml) add_custom_command( OUTPUT ${noreport} COMMAND ${vera_program} --root ${root} --profile ${profile} --${style}-report=- --show-rule --warning # --xml-report=${noreport} ${exclusions} ${reportsrcs} DEPENDS ${reportsrcs} COMMENT "Checking style with vera++ in ${currentDir}" ) list(APPEND xmlreports ${xmlreport}) list(APPEND noreports ${noreport}) vera_incr(reportNb) # clear the list for the next dir set(reportsrcs) set(currentDir ${d}) endif() list(APPEND reportsrcs ${s}) endforeach() # Create the custom targets that will trigger the custom command created # previously add_custom_target(${target_all} ALL DEPENDS ${xmlreports}) add_custom_target(${target} DEPENDS ${noreports}) endfunction() vera++-1.2.1/cmake/vera++-config.cmake000644 000765 000024 00000000500 12154326666 020150 0ustar00glehmannstaff000000 000000 if(WIN) get_filename_component(VERA++_EXECUTABLE ${CMAKE_CURRENT_LIST_FILE}/../../bin/vera++.exe ABSOLUTE) else() get_filename_component(VERA++_EXECUTABLE ${CMAKE_CURRENT_LIST_FILE}/../../../bin/vera++ ABSOLUTE) endif() get_filename_component(VERA++_USE_FILE ${CMAKE_CURRENT_LIST_FILE}/../use_vera++.cmake ABSOLUTE) vera++-1.2.1/CMakeLists.txt000644 000765 000024 00000000547 12154705401 016277 0ustar00glehmannstaff000000 000000 project(vera++) cmake_minimum_required(VERSION 2.8) set(VERA_MAJOR 1) set(VERA_MINOR 2) set(VERA_BUILD 1) set(VERA_VERSION "${VERA_MAJOR}.${VERA_MINOR}.${VERA_BUILD}") add_subdirectory(src) add_subdirectory(doc) add_subdirectory(scripts) add_subdirectory(profiles) include(CTest) add_subdirectory(tests) add_subdirectory(packages) add_subdirectory(cmake) vera++-1.2.1/CTestConfig.cmake000644 000765 000024 00000001026 12130151521 016672 0ustar00glehmannstaff000000 000000 ## This file should be placed in the root directory of your project. ## Then modify the CMakeLists.txt file in the root directory of your ## project to incorporate the testing dashboard. ## ## # The following are required to submit to the CDash dashboard: ## ENABLE_TESTING() ## INCLUDE(CTest) set(CTEST_PROJECT_NAME "vera++") set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=vera%2B%2B") set(CTEST_DROP_SITE_CDASH TRUE) vera++-1.2.1/doc/CMakeLists.txt000644 000765 000024 00000003461 12136216271 017044 0ustar00glehmannstaff000000 000000 find_program(PANDOC pandoc) if(NOT PANDOC) message(WARNING "The documentation won't be built because pandoc was not found.") return() endif() set(wiki "${CMAKE_SOURCE_DIR}/wiki") if(NOT EXISTS "${wiki}/Introduction.md") message(WARNING "The documentation won't be built because the wiki directory is empty.") message(WARNING "Run 'git submodule update --init' to fix that.") return() endif() # don't put the full path in this list because it breaks the doc generation # on windows. Instead we run the command in the wiki directory set(inputs Introduction.md # no need for the build page in the final doc # ${wiki}/Building.md Running.md Rules.md Transformations.md ScriptAPI.md Changes.md ) # generate the list of inputs with the full path to deal properly with # dependencies in add_custom_command set(inputs_full_path) foreach(i ${inputs}) list(APPEND inputs_full_path "${wiki}/${i}") endforeach() add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vera++.1 COMMAND ${PANDOC} -s ${CMAKE_CURRENT_SOURCE_DIR}/manpage.md ${inputs} -o ${CMAKE_CURRENT_BINARY_DIR}/vera++.1 DEPENDS ${PANDOC} ${CMAKE_CURRENT_SOURCE_DIR}/manpage.md ${inputs_full_path} WORKING_DIRECTORY "${wiki}" ) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vera++.html COMMAND ${PANDOC} -s # --toc --toc-depth=1 -H ${CMAKE_CURRENT_SOURCE_DIR}/style.css ${inputs} -o ${CMAKE_CURRENT_BINARY_DIR}/vera++.html DEPENDS ${PANDOC} ${CMAKE_CURRENT_SOURCE_DIR}/style.css ${inputs_full_path} WORKING_DIRECTORY "${wiki}" ) add_custom_target(doc ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/vera++.1 ${CMAKE_CURRENT_BINARY_DIR}/vera++.html) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vera++.1 DESTINATION share/man/man1) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vera++.html DESTINATION share/vera++/doc) vera++-1.2.1/doc/manpage.md000644 000765 000024 00000000342 12133152114 016221 0ustar00glehmannstaff000000 000000 % VERA++(1) Vera++ User Manuals % Maciej Sobczak; Vincent Hobeïka; Gaëtan Lehmann % April 10, 2013 NAME ==== vera++ - Programmable verification and analysis tool for C++ SYNOPSIS ======== vera++ *[options] [file ...]* vera++-1.2.1/doc/style.css000644 000765 000024 00000000552 12133152114 016144 0ustar00glehmannstaff000000 000000 vera++-1.2.1/LICENSE_1_0.txt000644 000765 000024 00000002472 12125131507 016016 0ustar00glehmannstaff000000 000000 Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vera++-1.2.1/packages/CMakeLists.txt000644 000765 000024 00000005216 12154326666 020067 0ustar00glehmannstaff000000 000000 # binary package set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") set(CPACK_PACKAGE_VENDOR "The vera++ team") set(CPACK_PACKAGE_CONTACT "none") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Programmable verification and analysis tool for C++") set(CPACK_PACKAGE_VERSION_MAJOR "${VERA_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${VERA_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${VERA_BUILD}") set(CPACK_PACKAGE_VERSION "${VERA_VERSION}") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.txt") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE_1_0.txt") # set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/vera++.bmp") # set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/vera++.ico") # set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/vera++.ico") if(TARGET doc) set(CPACK_NSIS_MENU_LINKS "share\\\\vera++\\\\doc\\\\vera++.html" "documentation") endif() set(CPACK_NSIS_MODIFY_PATH "ON") set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}") # source package set(CPACK_SOURCE_GENERATOR "TGZ") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERA_VERSION}") set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git" "/\\\\.mailmap$" "/\\\\.gitignore$" ".*~$" "\\\\.bak$" "\\\\.orig$" "/\\\\.DS_Store$" "/Thumbs\\\\.db" "/CMakeLists.txt.user$" "/wiki/images/.*png$" ${CPACK_SOURCE_IGNORE_FILES}) # also ignore the build directories that may be in the source tree file(GLOB_RECURSE caches "${CMAKE_SOURCE_DIR}/CMakeCache.txt") foreach(c ${caches}) get_filename_component(d "${c}" PATH) list(APPEND CPACK_SOURCE_IGNORE_FILES "^${d}/") endforeach() # if git is there, we also use it to exclude the files not in the repository macro(ignore_git_others dir) if(GITCOMMAND AND EXISTS "${dir}/.git") execute_process(COMMAND "${GITCOMMAND}" ls-files --others --directory RESULT_VARIABLE ret OUTPUT_VARIABLE output ERROR_VARIABLE error WORKING_DIRECTORY "${dir}") string(REGEX REPLACE "\r?\n" ";" output "${output}") foreach(f ${output}) set(df "${dir}/${f}") # escape regex special character that may be in the paths string(REGEX REPLACE "([.[{()\\*+?|^$])" "\\\\\\\\\\1" df "${df}") list(APPEND CPACK_SOURCE_IGNORE_FILES "^${df}") endforeach() endif() endmacro() ignore_git_others("${CMAKE_SOURCE_DIR}") ignore_git_others("${CMAKE_SOURCE_DIR}/wiki") include(CPack) find_program(TAR_EXECUTABLE tar) if(TARGET doc AND TAR_EXECUTABLE) set(output ${CMAKE_BINARY_DIR}/vera++-${VERA_VERSION}-doc.tar.gz) add_custom_command( OUTPUT ${output} COMMAND ${TAR_EXECUTABLE} czf ${output} vera++.1 vera++.html WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/doc) add_custom_target(package_doc DEPENDS doc ${output}) endif() vera++-1.2.1/profiles/boost000644 000765 000024 00000000442 12125131507 016423 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # This file defines the set of scripts (rules) that should be executed # to verify whether the code complies with the Boost conventions, # as defined in the original Boost inspect tool. set rules { F001 F002 L002 T013 T014 T015 T016 T017 } vera++-1.2.1/profiles/CMakeLists.txt000644 000765 000024 00000000234 12124625635 020122 0ustar00glehmannstaff000000 000000 file(GLOB_RECURSE srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) list(REMOVE_ITEM srcs CMakeLists.txt) install(FILES ${srcs} DESTINATION lib/vera++/profiles) vera++-1.2.1/profiles/default000644 000765 000024 00000000622 12135774264 016737 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # This file defines the set of scripts (rules) that should be executed # by default (if no specific profile is named when vera++ is launched). set rules { F001 L001 L002 L003 L004 L005 L006 T001 T002 T003 T004 T005 T006 T007 T008 T009 T010 T011 T012 T013 T015 T016 T017 T018 T019 } vera++-1.2.1/profiles/full000644 000765 000024 00000000426 12144542562 016251 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # This profile includes all the rules provided by vera++ set rules { F001 F002 L001 L002 L003 L004 L005 L006 T001 T002 T003 T004 T005 T006 T007 T008 T009 T010 T011 T012 T013 T014 T015 T016 T017 T018 T019 } vera++-1.2.1/README.txt000644 000765 000024 00000000672 12135764012 015236 0ustar00glehmannstaff000000 000000 Description ----------- Vera++ is a programmable tool for verification, analysis and transformation of C++ source code. Vera++ is mainly an engine that parses C++ source files and presents the result of this parsing to scripts in the form of various collections - the scripts are actually performing the requested tasks. License ------- Boost Software License Origins ------- Vera++ was initially hosted at: http://www.inspirel.com/vera vera++-1.2.1/scripts/CMakeLists.txt000644 000765 000024 00000000072 12124625462 017764 0ustar00glehmannstaff000000 000000 add_subdirectory(rules) add_subdirectory(transformations) vera++-1.2.1/scripts/rules/CMakeLists.txt000644 000765 000024 00000000241 12124625627 021117 0ustar00glehmannstaff000000 000000 file(GLOB_RECURSE srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) list(REMOVE_ITEM srcs CMakeLists.txt) install(FILES ${srcs} DESTINATION lib/vera++/scripts/rules) vera++-1.2.1/scripts/rules/DUMP.tcl000755 000765 000024 00000000506 12137427462 017640 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh foreach f [getSourceFileNames] { puts "Tokens in file ${f}:" foreach t [getTokens $f 1 0 -1 -1 {}] { set value [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set name [lindex $t 3] puts "${line}/${column}\t${name}\t${value}" } puts "" } vera++-1.2.1/scripts/rules/F001.tcl000755 000765 000024 00000001207 12136754174 017502 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Source files should not use the '\r' (CR) character foreach fileName [getSourceFileNames] { if { $fileName == "-" } { # can't check the content from stdin continue } set file [open $fileName "r"] fconfigure $file -translation lf set line [gets $file] set lineCounter 1 while {![eof $file]} { set pos [string first "\r" $line] if {$pos != -1 && $pos != [expr [string length $line] - 1]} { report $fileName $lineCounter "\\r (CR) detected in isolation at position ${pos}" } set line [gets $file] incr lineCounter } close $file } vera++-1.2.1/scripts/rules/F002.tcl000755 000765 000024 00000003333 12125131074 017467 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # File names should be well-formed set maxDirectoryDepth [getParameter "max-directory-depth" 8] set maxDirnameLength [getParameter "max-dirname-length" 31] set maxFilenameLength [getParameter "max-filename-length" 31] set maxPathLength [getParameter "max-path-length" 100] foreach fileName [getSourceFileNames] { if {[string length $fileName] > $maxPathLength} { report $fileName 1 "path name too long" } set dirDepth 0 foreach dir [file split [file dirname $fileName]] { if {$dir == "/" || $dir == "." || $dir == ".."} { continue } incr dirDepth if {[string length $dir] > $maxDirnameLength} { report $fileName 1 "directory name component too long" break } set first [string index $dir 0] if {[string is alpha $first] == 0 && $first != "_"} { report $fileName 1 "directory name should start with alphabetic character or underscore" break } if {[string first "." $dir] != -1} { report $fileName 1 "directory name should not contain the dot" break } } if {$dirDepth >= $maxDirectoryDepth} { report $fileName 1 "directory structure too deep" } set leafName [file tail $fileName] if {[string length $leafName] > $maxFilenameLength} { report $fileName 1 "file name too long" } set first [string index $leafName 0] if {[string is alpha $first] == 0 && $first != "_"} { report $fileName 1 "file name should start with alphabetic character or underscore" } if {[llength [split $leafName .]] > 2} { report $fileName 1 "file name should not contain more than one dot" } } vera++-1.2.1/scripts/rules/L001.tcl000755 000765 000024 00000001024 12125131074 017467 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # No trailing whitespace set strictMode [getParameter "strict-trailing-space" 0] foreach f [getSourceFileNames] { set lineNumber 1 set previousIndent "" foreach line [getAllLines $f] { if [regexp {^.*[[:space:]]+$} $line] { if {$strictMode || [string trim $line] != "" || $line != $previousIndent} { report $f $lineNumber "trailing whitespace" } } regexp {^([[:space:]]*).*$} $line dummy previousIndent incr lineNumber } } vera++-1.2.1/scripts/rules/L002.tcl000755 000765 000024 00000000414 12125131074 017472 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Don't use tab characters foreach f [getSourceFileNames] { set lineNumber 1 foreach line [getAllLines $f] { if [regexp {\t} $line] { report $f $lineNumber "horizontal tab used" } incr lineNumber } } vera++-1.2.1/scripts/rules/L003.tcl000755 000765 000024 00000000716 12125131074 017500 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # No leading and no trailing empty lines foreach f [getSourceFileNames] { set lineCount [getLineCount $f] if {$lineCount > 0} { set firstLine [getLine $f 1] if {[string trim $firstLine] == ""} { report $f 1 "leading empty line(s)" } set lastLine [getLine $f $lineCount] if {[string trim $lastLine] == ""} { report $f $lineCount "trailing empty line(s)" } } } vera++-1.2.1/scripts/rules/L004.tcl000755 000765 000024 00000000546 12143053062 017502 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Line cannot be too long set maxLength [getParameter "max-line-length" 100] foreach f [getSourceFileNames] { set lineNumber 1 foreach line [getAllLines $f] { if {[string length $line] > $maxLength} { report $f $lineNumber "line is longer than ${maxLength} characters" } incr lineNumber } } vera++-1.2.1/scripts/rules/L005.tcl000755 000765 000024 00000001216 12125131074 017476 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # There should not be too many consecutive empty lines set maxEmptyLines [getParameter "max-consecutive-empty-lines" 2] foreach f [getSourceFileNames] { set lineNumber 1 set emptyCount 0 set reported false foreach line [getAllLines $f] { if {[string trim $line] == ""} { incr emptyCount if {$emptyCount > $maxEmptyLines && $reported == "false"} { report $f $lineNumber "too many consecutive empty lines" set reported true } } else { set emptyCount 0 set reported false } incr lineNumber } } vera++-1.2.1/scripts/rules/L006.tcl000755 000765 000024 00000000410 12125131074 017472 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Source file should not be too long set maxLines [getParameter "max-file-length" 2000] foreach f [getSourceFileNames] { set length [getLineCount $f] if {$length > $maxLines} { report $f $length "source file is too long" } } vera++-1.2.1/scripts/rules/T001.tcl000755 000765 000024 00000000607 12125131074 017505 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # One-line comments should not have forced continuation foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {cppcomment}] { set lineNumber [lindex $t 1] set wholeLine [getLine $f $lineNumber] if {[string index $wholeLine end] == "\\"} { report $f $lineNumber "line-continuation in one-line comment" } } } vera++-1.2.1/scripts/rules/T002.tcl000755 000765 000024 00000003276 12125131074 017513 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Reserved names should not be used for preprocessor macros set keywords { asm auto bool break case catch char class const const_cast continue default delete goto do double dynamic_cast else enum explicit export extern false float for friend if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq } foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {pp_define}] { set lineNumber [lindex $t 1] set line [getLine $f $lineNumber] set rest [string trimleft [string range $line \ [expr [lindex $t 2] + [string length [lindex $t 0]]] end]] set macroName [string range $rest 0 [expr [string wordend $rest 0] - 1]] if {([regexp {^_} $macroName] && [string is upper -strict [string index $macroName 1]]) || [string first "__" $macroName] != -1} { report $f $lineNumber "reserved name used for macro (incorrect use of underscore)" } if {[lsearch $keywords $macroName] != -1} { report $f $lineNumber "reserved name used for macro (keyword or alternative token redefined)" } } } vera++-1.2.1/scripts/rules/T003.tcl000755 000765 000024 00000002261 12125131074 017505 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Some keywords should be followed by a single space set keywords { case class delete enum explicit extern goto new struct union using } proc isKeyword {s} { global keywords return [expr [lsearch $keywords $s] != -1] } set state "other" foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {}] { set tokenValue [lindex $t 0] set tokenName [lindex $t 3] if {$state == "keyword"} { if {$tokenName == "space" && $tokenValue == " "} { set state "space" } else { report $f $lineNumber "keyword \'${keywordValue}\' not followed by a single space" set state "other" } } elseif {$state == "space"} { if {$tokenName == "newline"} { report $f $lineNumber "keyword \'${keywordValue}\' not followed by a single space" } set state "other" } else { if [isKeyword $tokenName] { set state "keyword" set lineNumber [lindex $t 1] set keywordValue [lindex $t 0] } } } } vera++-1.2.1/scripts/rules/T004.tcl000755 000765 000024 00000003254 12125131074 017511 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Some keywords should be immediately followed by a colon set keywords { default private protected public } proc isKeyword {s} { global keywords return [expr [lsearch $keywords $s] != -1] } foreach f [getSourceFileNames] { set lastKeywordLine 0 set lastKeywordColumn 0 set lastKeywordValue "" set last "" foreach t [getTokens $f 1 0 -1 -1 [concat $keywords colon]] { set tokenValue [lindex $t 0] set tokenName [lindex $t 3] if {$tokenName == "colon"} { if {$last == "keyword" && $lastKeywordLine != 0} { set line [lindex $t 1] set column [lindex $t 2] if {$line != $lastKeywordLine || $column != [expr $lastKeywordColumn + [string length $lastKeywordValue]]} { set nonWhiteFound "false" foreach tb [getTokens $f $lastKeywordLine [expr $lastKeywordColumn + 1] $line $column {}] { set tbName [lindex $tb 3] if {[lsearch {space newline ccomment cppcomment} $tbName] == -1} { set nonWhiteFound "true" break } } if {$nonWhiteFound == "false"} { report $f $line "colon not immediately after the \'$lastKeywordValue\' keyword" } } } set last "colon" } else { set lastKeywordLine [lindex $t 1] set lastKeywordColumn [lindex $t 2] set lastKeywordValue $tokenValue set last "keyword" } } } vera++-1.2.1/scripts/rules/T005.tcl000755 000765 000024 00000001434 12125131074 017510 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Keywords break and continue should be immediately followed by a semicolon foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {break continue}] { set keyword [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set semicolons [getTokens $f $line [expr $column + [string length $keyword]] [expr $line + 1] 0 {semicolon}] if {$semicolons == {}} { report $f $line "keyword '${keyword}' not immediately followed by a semicolon" } else { set semColumn [lindex [lindex $semicolons 0] 2] if {$semColumn != $column + [string length $keyword]} { report $f $line "keyword '${keyword}' not immediately followed by a semicolon" } } } } vera++-1.2.1/scripts/rules/T006.tcl000755 000765 000024 00000001747 12137405371 017527 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Keywords return and throw should be immediately followed by a semicolon or a single space foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {return throw}] { set keyword [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set followingTokens [getTokens $f $line [expr $column + [string length $keyword]] [expr $line + 1] 0 {}] if {$followingTokens == {}} { report $f $line "keyword '${keyword}' not immediately followed by a semicolon or a single space" } else { set first [lindex [lindex $followingTokens 0] 0] if {$first != ";" && $first != " "} { if {!([llength $followingTokens] >= 2 && $keyword == "throw" && $first == "(" && [lindex [lindex $followingTokens 1] 0] == ")")} { report $f $line "keyword '${keyword}' not immediately followed by a semicolon or a single space" } } } } } vera++-1.2.1/scripts/rules/T007.tcl000755 000765 000024 00000001645 12125131074 017516 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Semicolons should not be isolated by spaces or comments from the rest of the code foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {semicolon}] { set line [lindex $t 1] set column [lindex $t 2] set previousTokens [getTokens $f $line 0 $line $column {}] if {$previousTokens == {}} { report $f $line "semicolon is isolated from other tokens" } else { set lastToken [lindex $previousTokens end] set lastName [lindex $lastToken 3] if {[lsearch {space ccomment} $lastName] != -1} { set forTokens [getTokens $f $line 0 $line $column {for leftparen}] if {[list [lindex [lindex $forTokens 0] 3] [lindex [lindex $forTokens 1] 3]] != {for leftparen}} { report $f $line "semicolon is isolated from other tokens" } } } } } vera++-1.2.1/scripts/rules/T008.tcl000755 000765 000024 00000001426 12125131074 017514 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Keywords catch, for, if and while should be followed by a single space foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {catch for if switch while}] { set keyword [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set followingTokens [getTokens $f $line [expr $column + [string length $keyword]] [expr $line + 1] -1 {}] if {[llength $followingTokens] < 2} { report $f $line "keyword '${keyword}' not followed by a single space" } else { if {[list [lindex [lindex $followingTokens 0] 0] [lindex [lindex $followingTokens 1] 0]] != [list " " "("]} { report $f $line "keyword '${keyword}' not followed by a single space" } } } } vera++-1.2.1/scripts/rules/T009.tcl000755 000765 000024 00000002074 12125131074 017515 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Comma should not be preceded by whitespace, but should be followed by one foreach f [getSourceFileNames] { foreach t [getTokens $f 1 0 -1 -1 {comma}] { set line [lindex $t 1] set column [lindex $t 2] set preceding [getTokens $f $line 0 $line $column {}] if {$preceding == {}} { report $f $line "comma should not be preceded by whitespace" } else { set lastPreceding [lindex [lindex $preceding end] 3] if {$lastPreceding == "space"} { report $f $line "comma should not be preceded by whitespace" } } set following [getTokens $f $line [expr $column + 1] [expr $line + 1] -1 {}] if {$following != {}} { set firstFollowing [lindex [lindex $following 0] 3] if {$firstFollowing != "space" && $firstFollowing != "newline" && !($lastPreceding == "operator" && $firstFollowing == "leftparen")} { report $f $line "comma should be followed by whitespace" } } } } vera++-1.2.1/scripts/rules/T010.tcl000755 000765 000024 00000000554 12125131074 017506 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Identifiers should not be composed of 'l' and 'O' characters only foreach file [getSourceFileNames] { foreach t [getTokens $file 1 0 -1 -1 {identifier}] { set value [lindex $t 0] if [regexp {^(l|O)+$} $value] { report $file [lindex $t 1] "identifier should not be composed of only 'l' and 'O'" } } } vera++-1.2.1/scripts/rules/T011.tcl000755 000765 000024 00000003263 12125131074 017507 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Curly brackets from the same pair should be either in the same line or in the same column proc acceptPairs {} { global file parens index end while {$index != $end} { set nextToken [lindex $parens $index] set tokenValue [lindex $nextToken 0] if {$tokenValue == "\{"} { incr index set leftParenLine [lindex $nextToken 1] set leftParenColumn [lindex $nextToken 2] acceptPairs if {$index == $end} { report $file $leftParenLine "opening curly bracket is not closed" return } set nextToken [lindex $parens $index] incr index set tokenValue [lindex $nextToken 0] set rightParenLine [lindex $nextToken 1] set rightParenColumn [lindex $nextToken 2] if {($leftParenLine != $rightParenLine) && ($leftParenColumn != $rightParenColumn)} { # make an exception for line continuation set leftLine [getLine $file $leftParenLine] set rightLine [getLine $file $rightParenLine] if {[string index $leftLine end] != "\\" && [string index $rightLine end] != "\\"} { report $file $rightParenLine "closing curly bracket not in the same line or column" } } } else { return } } } foreach file [getSourceFileNames] { set parens [getTokens $file 1 0 -1 -1 {leftbrace rightbrace}] set index 0 set end [llength $parens] acceptPairs if {$index != $end} { report $file [lindex [lindex $parens $index] 1] "excessive closing bracket?" } } vera++-1.2.1/scripts/rules/T012.tcl000755 000765 000024 00000000576 12125131074 017514 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Negation operator should not be used in its short form foreach file [getSourceFileNames] { foreach negation [getTokens $file 1 0 -1 -1 {not}] { set value [lindex $negation 0] if {$value == "!"} { set lineNumber [lindex $negation 1] report $file $lineNumber "negation operator used in its short form" } } } vera++-1.2.1/scripts/rules/T013.tcl000755 000765 000024 00000000706 12135761511 017516 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Source files should contain the copyright notice foreach file [getSourceFileNames] { set found false foreach comment [getTokens $file 1 0 -1 -1 {ccomment cppcomment}] { set value [lindex $comment 0] if {[string first "copyright" [string tolower $value]] != -1} { set found true break } } if {$found == false} { report $file 1 "no copyright notice found" } } vera++-1.2.1/scripts/rules/T014.tcl000755 000765 000024 00000000735 12125131074 017513 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Source files should refer the Boost Software License foreach file [getSourceFileNames] { set found false foreach comment [getTokens $file 1 0 -1 -1 {ccomment cppcomment}] { set value [lindex $comment 0] if {[string first "Boost Software License" $value] != -1} { set found true break } } if {$found == false} { report $file 1 "no reference to the Boost Software License found" } } vera++-1.2.1/scripts/rules/T015.tcl000755 000765 000024 00000003413 12125131074 017510 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # HTML links in comments and string literals should be correct set urlRe {<[[:space:]]*[^>]*[[:space:]]+(?:HREF|SRC)[[:space:]]*=[[:space:]]*\"([^\"]*)\"} foreach file [getSourceFileNames] { foreach token [getTokens $file 1 0 -1 -1 {ccomment cppcomment stringlit}] { set tokenValue [lindex $token 0] if {[regexp -nocase $urlRe $tokenValue dummy link] == 1} { if {[string index $link 0] == "\#" || [string first "mailto:" $link] == 0 || [string first "http:" $link] == 0 || [string first "https:" $link] == 0 || [string first "ftp:" $link] == 0 || [string first "news:" $link] == 0 || [string first "javascript:" $link] == 0} { continue } set lineNumber [lindex $token 1] if {[string first "file:" $link] == 0} { report $file $lineNumber "URL links to files are not allowed" continue } if {[regexp {[ \<\>\'\{\}\|\\\^\[\]]} $link] == 1} { report $file $lineNumber "URL link contains illegal character(s)" continue } set plainLink $link set pos [string first "\#" $link] if {$pos != -1} { set plainLink [string range $link 0 [expr $pos - 1]] } if {[string first "\#" $link [expr $pos + 1]] != -1} { report $file $lineNumber "URL link contains invalid bookmark" } set completeLink [file join [file dirname $file] $plainLink] if {[file isfile $completeLink] == 0} { report $file $lineNumber "URL points to non-existing file" } } } } vera++-1.2.1/scripts/rules/T016.tcl000755 000765 000024 00000001266 12125131074 017515 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Calls to min/max should be protected against accidental macro substitution foreach file [getSourceFileNames] { foreach identifier [getTokens $file 1 0 -1 -1 {identifier}] { set value [lindex $identifier 0] if {$value == "min" || $value == "max"} { set lineNumber [lindex $identifier 1] set columnNumber [expr [lindex $identifier 2] + [string length $value]] set restOfLine [string range [getLine $file $lineNumber] $columnNumber end] if {[regexp {^[[:space:]]*\(} $restOfLine] == 1} { report $file $lineNumber "min/max potential macro substitution problem" } } } } vera++-1.2.1/scripts/rules/T017.tcl000755 000765 000024 00000001276 12125131074 017517 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # Unnamed namespaces are not allowed in header files foreach fileName [getSourceFileNames] { set extension [file extension $fileName] if {[lsearch {.h .hh .hpp .hxx .ipp} $extension] != -1} { set state "start" foreach token [getTokens $fileName 1 0 -1 -1 {namespace identifier leftbrace}] { set type [lindex $token 3] if {$state == "namespace" && $type == "leftbrace"} { report $fileName $namespaceLine "unnamed namespace not allowed in header file" } if {$type == "namespace"} { set namespaceLine [lindex $token 1] } set state $type } } } vera++-1.2.1/scripts/rules/T018.tcl000755 000765 000024 00000001245 12125131074 017514 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # using namespace are not allowed in header files foreach fileName [getSourceFileNames] { set extension [file extension $fileName] if {[lsearch {.h .hh .hpp .hxx .ipp} $extension] != -1} { set state "start" foreach token [getTokens $fileName 1 0 -1 -1 {using namespace identifier}] { set type [lindex $token 3] if {$state == "using" && $type == "namespace"} { report $fileName $usingLine "using namespace not allowed in header file" } if {$type == "using"} { set usingLine [lindex $token 1] } set state $type } } } vera++-1.2.1/scripts/rules/T019.tcl000755 000765 000024 00000002343 12154326666 017534 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # control structures should have complete curly-braced block of code foreach fileName [getSourceFileNames] { set state "start" set prev "" foreach token [getTokens $fileName 1 0 -1 -1 {for if while do leftparen rightparen leftbrace rightbrace semicolon}] { set type [lindex $token 3] if {$state == "control"} { if {$type == "leftparen"} { incr parenCount } elseif {$type == "rightparen"} { incr parenCount -1 if {$parenCount == 0} { set state "expectedblock" } } } elseif {$state == "expectedblock"} { if {$type != "leftbrace"} { set line [lindex $token 1] report $fileName $line "full block {} expected in the control structure" } set state "block" } if {$type == "for" || $type == "if"} { set parenCount 0 set state "control" } elseif {$type == "do"} { set state "expectedblock" } elseif {$type == "while" && $prev != "rightbrace"} { set parenCount 0 set state "control" } set prev $type } } vera++-1.2.1/scripts/transformations/CMakeLists.txt000644 000765 000024 00000000253 12124625614 023215 0ustar00glehmannstaff000000 000000 file(GLOB_RECURSE srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *) list(REMOVE_ITEM srcs CMakeLists.txt) install(FILES ${srcs} DESTINATION lib/vera++/scripts/transformations) vera++-1.2.1/scripts/transformations/move_includes.tcl000755 000765 000024 00000001333 12125131074 024011 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # change prefix of #include paths set oldPrefix "\"boost/" set newPrefix "\"boom/" set oldPrefixLength [string length $oldPrefix] foreach fileName [getSourceFileNames] { set tokens [getTokens $fileName 1 0 -1 -1 {}] set newFile [open $fileName "w"] foreach token $tokens { set tokenValue [lindex $token 0] set tokenType [lindex $token 3] if {$tokenType == "pp_qheader"} { set index [string first $oldPrefix $tokenValue] if {$index != -1} { set tokenValue [string replace $tokenValue $index [expr $index + $oldPrefixLength - 1] $newPrefix] } } puts -nonewline $newFile $tokenValue } close $newFile } vera++-1.2.1/scripts/transformations/move_macros.tcl000755 000765 000024 00000001264 12125131074 023472 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # change the prefix in all macros set oldPrefix "BOOST" set newPrefix "BOOM" set oldPrefixLength [string length $oldPrefix] foreach fileName [getSourceFileNames] { set tokens [getTokens $fileName 1 0 -1 -1 {}] set newFile [open $fileName "w"] foreach token $tokens { set tokenValue [lindex $token 0] set tokenType [lindex $token 3] if {$tokenType == "identifier" && \ [string compare -length $oldPrefixLength $oldPrefix $tokenValue] == 0} { set tokenValue [string replace $tokenValue 0 [expr $oldPrefixLength - 1] $newPrefix] } puts -nonewline $newFile $tokenValue } close $newFile } vera++-1.2.1/scripts/transformations/move_namespace.tcl000755 000765 000024 00000001040 12125131074 024132 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # change the namespace of all source files set oldNamespace "boost" set newNamespace "boom" foreach fileName [getSourceFileNames] { set tokens [getTokens $fileName 1 0 -1 -1 {}] set newFile [open $fileName "w"] foreach token $tokens { set tokenValue [lindex $token 0] set tokenType [lindex $token 3] if {$tokenType == "identifier" && $tokenValue == $oldNamespace} { set tokenValue $newNamespace } puts -nonewline $newFile $tokenValue } close $newFile } vera++-1.2.1/scripts/transformations/to_lower.tcl000755 000765 000024 00000003047 12125131074 023013 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # transform indentifier names from CamelCase to standard_lower_case # this list contains exceptional mappings as pairs ?original new? set exceptions {SOMESpecialName some_special_name SOMEOTHER some_other} proc transformIdentifier {old} { global exceptions if [string is lower $old] { set new $old } else { set e [lsearch $exceptions $old] if {$e != -1} { set new [lindex $exceptions [expr $e + 1]] } else { set state "upper" set new "" for {set i 0} {$i != [string length $old]} {incr i} { set c [string index $old $i] if [string is upper $c] { if {$state == "upper"} { set new ${new}[string tolower $c] } else { set new ${new}_[string tolower $c] set state "upper" } } else { set new ${new}${c} set state "lower" } } } } return $new } foreach fileName [getSourceFileNames] { set tokens [getTokens $fileName 1 0 -1 -1 {}] set newFile [open $fileName "w"] foreach t $tokens { set tokenValue [lindex $t 0] set tokenType [lindex $t 3] if {$tokenType == "identifier"} { set newToken [transformIdentifier $tokenValue] } else { set newToken $tokenValue } puts -nonewline $newFile $newToken } close $newFile } vera++-1.2.1/scripts/transformations/to_xml.tcl000755 000765 000024 00000001567 12125131074 022470 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # transform the source file into XML file foreach f [getSourceFileNames] { set outFileName "${f}.xml" set outFile [open $outFileName "w"] puts $outFile "" puts $outFile "" foreach t [getTokens $f 1 0 -1 -1 {}] { set value [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set name [lindex $t 3] if {$value == "\n"} { set value "!\[CDATA\[\n\]]" } else { set value [regsub -all "&" $value {\&}] set value [regsub -all "<" $value {\<}] set value [regsub -all ">" $value {\>}] } puts $outFile " ${value}" } puts $outFile "" close $outFile } vera++-1.2.1/scripts/transformations/to_xml2.tcl000755 000765 000024 00000001574 12125131074 022550 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # transform the source file into XML file (another variant) foreach f [getSourceFileNames] { set outFileName "${f}.xml" set outFile [open $outFileName "w"] puts $outFile "" puts $outFile "" foreach t [getTokens $f 1 0 -1 -1 {}] { set value [lindex $t 0] set line [lindex $t 1] set column [lindex $t 2] set name [lindex $t 3] if {$value == "\n"} { set value "!\[CDATA\[\n\]]" } else { set value [regsub -all "&" $value {\&}] set value [regsub -all "<" $value {\<}] set value [regsub -all ">" $value {\>}] } puts $outFile " <${name} line=\"${line}\" column=\"${column}\">${value}" } puts $outFile "" close $outFile } vera++-1.2.1/scripts/transformations/trim_right.tcl000755 000765 000024 00000000467 12125131074 023334 0ustar00glehmannstaff000000 000000 #!/usr/bin/tclsh # trim each line by removing trailing whitespace foreach fileName [getSourceFileNames] { set lines [getAllLines $fileName] set newFile [open $fileName "w"] foreach line $lines { set newLine [string trimright $line] puts $newFile $newLine } close $newFile } vera++-1.2.1/src/boost_main.cpp000644 000765 000024 00000030042 12154705401 017155 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "config.h" #include "structures/SourceFiles.h" #include "plugins/Profiles.h" #include "plugins/Rules.h" #include "plugins/Exclusions.h" #include "plugins/Transformations.h" #include "plugins/Parameters.h" #include "plugins/Reports.h" #include "plugins/RootDirectory.h" #include #include #include #include #include #include #include #include #define foreach BOOST_FOREACH #ifdef _MSC_VER // vm.count() used as a bool #pragma warning(disable:4800) #endif template void doReports(Files & reports, Options & vm, Reporter * reporter) { foreach (const std::string & fn, reports) { if (fn == "-") { if (vm.count("warning") || vm.count("error")) { (*reporter)(std::cerr, vm.count("no-duplicate")); } else { (*reporter)(std::cout, vm.count("no-duplicate")); } } else { std::ofstream file; file.open(fn.c_str()); if (file.fail()) { throw std::ios::failure("Can't open " + fn); } (*reporter)(file, vm.count("no-duplicate")); if (file.bad() || file.fail()) { throw std::ios::failure( "Can't write to " + fn); } file.close(); } } } int boost_main(int argc, char * argv[]) { // the directory containing the profile and rule definitions // by default it is (in this order, first has highest precedence): // - VERA_ROOT (if VERA_ROOT is defined) // - HOME/.vera++ (if HOME is defined) // - current directory (if scripts and profile are present) // - /usr/lib/vera++/ default debian directory Vera::Plugins::RootDirectory::DirectoryName veraRoot(VERA_INSTALL_DIR "/lib/vera++/"); struct stat St; bool isInCurrent = ( stat( "./scripts", &St ) == 0 && stat( "./profiles", &St ) == 0 ); // scripts and profiles folders are inside current directory if (isInCurrent) { // we can override /usr/lib/vera++ veraRoot = "."; } char * veraRootEnv = getenv("HOME"); if (veraRootEnv != NULL) { Vera::Plugins::RootDirectory::DirectoryName veraRootTmp(veraRootEnv); veraRootTmp += "/.vera++"; bool isInHome = ( stat( veraRootTmp.c_str(), &St ) == 0 ); if (isInHome) { // We assume that if the user has a .vera++ folder in // their home then we can override the current // directory // We don't want to override the current directory // only because $HOME is defined. veraRoot = veraRootEnv; veraRoot += "/.vera++"; } } veraRootEnv = getenv("VERA_ROOT"); if (veraRootEnv != NULL) { veraRoot = veraRootEnv; } std::string profile = "default"; std::string transform; std::vector rules; std::vector parameters; std::vector parameterFiles; std::vector inputs; std::vector inputFiles; std::vector exclusionFiles; // outputs std::vector stdreports; std::vector vcreports; std::vector xmlreports; std::vector checkstylereports; /** Define and parse the program options */ namespace po = boost::program_options; po::options_description visibleOptions("Options"); visibleOptions.add_options() ("profile,p", po::value(&profile), "execute all rules from the given profile") ("rule,R", po::value(&rules), "execute the given rule (note: the .tcl extension is added" " automatically. can be used many times.)") ("transform", po::value(&transform), "execute the given transformation") ("std-report,o", po::value(&stdreports), "write the standard (gcc-like) report to this" "file. Default is standard or error output depending on the options." " (note: may be used many times.)") ("vc-report,v", po::value(&vcreports), "write the Visual C report to this file." " Not used by default. (note: may be used many times.)") ("xml-report,x", po::value(&xmlreports), "write the XML report to this file." " Not used by default. (note: may be used many times.)") ("checkstyle-report,c", po::value(&checkstylereports), "write the checkstyle report to this file." " Not used by default. (note: may be used many times.)") ("show-rule,s", "include rule name in each report") ("no-duplicate,d", "do not duplicate messages if a single rule is violated many times in a" " single line of code") ("warning,w", "reports are marked as warning and generated on error output") ("error,e", "reports are marked as error and generated on error output." " An non zero exit code is used when one or more reports are generated.") ("quiet,q", "don't display the reports") ("summary,S", "display the number of reports and the number of processed files") ("parameters", po::value(¶meterFiles), "read parameters from file" " (note: can be used many times)") ("parameter,P", po::value(¶meters), "provide parameters to the scripts as name=value" " (note: can be used many times)") ("exclusions", po::value(&exclusionFiles), "read exclusions from file" " (note: can be used many times)") ("inputs,i", po::value(&inputFiles), "the inputs are read from that file (note: one file" " per line. can be used many times.)") ("root,r", po::value(&veraRoot), "use the given directory as the vera root directory") ("help,h", "show this help message and exit") ("version", "show vera++'s version and exit"); // don't call it "input", as is may seems more logical, in order to get an error when // --inputs is used without the "s" at the end po::options_description allOptions; allOptions.add(visibleOptions).add_options() ("__input__", po::value(&inputs), "input files from command line"); po::positional_options_description positionalOptions; positionalOptions.add("__input__", -1); po::variables_map vm; try { po::store(po::command_line_parser(argc, argv).options(allOptions) .positional(positionalOptions).run(), vm); if ( vm.count("help") ) { std::cout << "vera++ [options] [list-of-files]" << std::endl << visibleOptions << std::endl; return EXIT_SUCCESS; } po::notify(vm); // throws on error, so do after help in case // there are any problems } catch (po::error& e) { std::cerr << "ERROR: " << e.what() << std::endl << std::endl; std::cerr << visibleOptions << std::endl; return EXIT_FAILURE; } if (vm.count("version")) { std::cout << VERA_VERSION << '\n'; return EXIT_SUCCESS; } try { Vera::Plugins::RootDirectory::setRootDirectory(veraRoot); Vera::Plugins::Reports::setShowRules(vm.count("show-rule")); if (vm.count("warning")) { if (vm.count("error")) { std::cerr << "ERROR: --warning and --error can't be used at the same time." << std::endl; std::cerr << visibleOptions << std::endl; return EXIT_FAILURE; } Vera::Plugins::Reports::setPrefix("warning"); } if (vm.count("error")) { Vera::Plugins::Reports::setPrefix("error"); } foreach (const std::string & f, exclusionFiles) { Vera::Plugins::Exclusions::setExclusions(f); } foreach (const std::string & f, parameterFiles) { Vera::Plugins::Parameters::readFromFile(f); } foreach (const std::string & p, parameters) { Vera::Plugins::Parameters::ParamAssoc assoc(p); Vera::Plugins::Parameters::set(assoc); } if (vm.count("__input__")) { foreach (const std::string & i, inputs) { Vera::Structures::SourceFiles::addFileName(i); } } if (vm.count("__input__") == 0 && vm.count("inputs") == 0) { // list of source files is provided on stdin inputFiles.push_back("-"); } foreach (const std::string & f, inputFiles) { if (f == "-") { Vera::Structures::SourceFiles::FileName name; while (std::getline(std::cin, name)) { Vera::Structures::SourceFiles::addFileName(name); } } else { std::ifstream file; std::string name; file.open(f.c_str()); if (file.fail()) { throw std::ios::failure("Can't open " + f); } while (std::getline(file, name)) { Vera::Structures::SourceFiles::addFileName(name); } if (file.bad()) { throw std::ios::failure( "Can't read from " + f); } file.close(); } } if (vm.count("std-report") == 0 && vm.count("vc-report") == 0 && vm.count("xml-report") == 0 && vm.count("checkstyle-report") == 0 && vm.count("quiet") == 0) { // no report set - use std report on std out/err stdreports.push_back("-"); } if (rules.empty() == false) { if (vm.count("profile")) { std::cerr << "ERROR: --profile and --rule can't be used at the same time." << std::endl; std::cerr << visibleOptions << std::endl; return EXIT_FAILURE; } if (vm.count("transform")) { std::cerr << "ERROR: --transform and --rule can't be used at the same time." << std::endl; std::cerr << visibleOptions << std::endl; return EXIT_FAILURE; } foreach (const std::string & r, rules) { Vera::Plugins::Rules::executeRule(r); } } else if (vm.count("transform")) { if (vm.count("profile")) { std::cerr << "ERROR: --profile and --transform can't be used at the same time." << std::endl; std::cerr << visibleOptions << std::endl; return EXIT_FAILURE; } Vera::Plugins::Transformations::executeTransformation(transform); } else { Vera::Plugins::Profiles::executeProfile(profile); } doReports(stdreports, vm, Vera::Plugins::Reports::writeStd); doReports(vcreports, vm, Vera::Plugins::Reports::writeVc); doReports(xmlreports, vm, Vera::Plugins::Reports::writeXml); doReports(checkstylereports, vm, Vera::Plugins::Reports::writeCheckStyle); if (vm.count("summary")) { std::cerr << Vera::Plugins::Reports::count() << " reports in " << Vera::Structures::SourceFiles::count() << " files." << std::endl; } } catch (const std::exception & e) { std::cerr << "error: " << e.what() << '\n'; return EXIT_FAILURE; } if (vm.count("error") && Vera::Plugins::Reports::count() !=0) { return EXIT_FAILURE; } return EXIT_SUCCESS; } vera++-1.2.1/src/CMakeLists.txt000644 000765 000024 00000004454 12154350323 017066 0ustar00glehmannstaff000000 000000 find_package(TCL) # REQUIRED) # don't use find_package's REQUIRED parameter to avoid requiring tk if(NOT TCL_FOUND) message(FATAL_ERROR "TCL was not found.") endif() include_directories(SYSTEM ${TCL_INCLUDE_PATH}) link_directories(${TCL_LIBRARY_DIRS}) if(WIN32) # use boost static libs to avoid LNK2019 errors # feel free to contribute a better fix! set(Boost_USE_STATIC_LIBS ON) else() # expose the Boost_USE_STATIC_LIBS option to ease the manual creation of # packages with cpack option(Boost_USE_STATIC_LIBS "Use Boost static libraries" OFF) endif() find_package(Boost COMPONENTS program_options system wave REQUIRED) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) # hide Boost_DIR option that doesn't seem to be set by FindBoost mark_as_advanced(Boost_DIR) if(MSVC) # hide the warning generated by the usage of getenv() add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_SCL_SECURE_NO_WARNINGS) endif(MSVC) configure_file(config.h.in config.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR}) file(GLOB_RECURSE srcs *.cpp) add_executable(vera ${srcs}) set_target_properties(vera PROPERTIES OUTPUT_NAME vera++) target_link_libraries(vera ${TCL_LIBRARY} ${Boost_LIBRARIES}) if(WIN32) # install the tcl lib, if we can find it get_filename_component(tcldir "${TCL_LIBRARY}" PATH) get_filename_component(tclname "${TCL_LIBRARY}" NAME_WE) set(tcldll "${tcldir}/../bin/${tclname}.dll") if(EXISTS "${tcldll}") set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS "${tcldll}") endif() endif() # runtime libs will be copied by hand in the package - there is no need # for these warnings set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) include(InstallRequiredSystemLibraries) install(TARGETS vera DESTINATION bin) # install the runtime libraries if(MSVC10) if(NOT MSVC10_REDIST_DIR) # the libs where not found by InstallRequiredSystemLibraries, so we get # them from System32 set(msvc_redist_libs "C:/Windows/System32/msvcp100.dll" "C:/Windows/System32/msvcr100.dll") foreach(lib ${msvc_redist_libs}) if(EXISTS ${lib}) install(PROGRAMS ${lib} DESTINATION bin) endif() endforeach() endif() endif() include(../cmake/use_vera++.cmake) add_vera_targets(*.h *.cpp RECURSE ROOT "${CMAKE_SOURCE_DIR}") vera++-1.2.1/src/config.h.in000644 000765 000024 00000000445 12127744304 016353 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #define VERA_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@" #define VERA_VERSION "@VERA_VERSION@" vera++-1.2.1/src/legacy_main.cpp000644 000765 000024 00000026202 12136141440 017273 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "config.h" #include "structures/SourceFiles.h" #include "plugins/Profiles.h" #include "plugins/Rules.h" #include "plugins/Exclusions.h" #include "plugins/Transformations.h" #include "plugins/Parameters.h" #include "plugins/Reports.h" #include "plugins/RootDirectory.h" #include #include #include #include #include #include namespace // unnamed { // helper function that checks whether the given file name names the C or C++ source file bool isSourceFileName(const Vera::Structures::SourceFiles::FileName & name) { const std::string suffixes[] = { ".cpp", ".cxx", ".cc", ".c", ".C", ".h", ".hh", ".hpp", ".hxx", ".ipp" }; const int numOfSuffixes = sizeof(suffixes) / sizeof(std::string); for (int i = 0; i != numOfSuffixes; ++i) { const std::string suf = suffixes[i]; const Vera::Structures::SourceFiles::FileName::size_type pos = name.rfind(suf); if (pos != Vera::Structures::SourceFiles::FileName::npos && pos == name.size() - suf.size()) { return true; } } return false; } } // unnamed namespace int legacy_main(int argc, char * argv[], bool silent = false) { int exitCodeOnFailure = EXIT_FAILURE; try { Vera::Plugins::Profiles::ProfileName profile("default"); // the directory containing the profile and rule definitions // by default it is (in this order, first has highest precedence): // - VERA_ROOT (if VERA_ROOT is defined) // - HOME/.vera++ (if HOME is defined) // - current directory (if scripts and profile are present) // - /usr/lib/vera++/ default debian directory Vera::Plugins::RootDirectory::DirectoryName veraRoot(VERA_INSTALL_DIR "/lib/vera++/"); struct stat St; bool isInCurrent = ( stat( "./scripts", &St ) == 0 && stat( "./profiles", &St ) == 0 ); // scripts and profiles folders are inside current directory if (isInCurrent) { // we can override /usr/lib/vera++ veraRoot = "."; } char * veraRootEnv = getenv("HOME"); if (veraRootEnv != NULL) { Vera::Plugins::RootDirectory::DirectoryName veraRootTmp(veraRootEnv); veraRootTmp += "/.vera++"; bool isInHome = ( stat( veraRootTmp.c_str(), &St ) == 0 ); if (isInHome) { // We assume that if the user has a .vera++ folder in // their home then we can override the current // directory // We don't want to override the current directory // only because $HOME is defined. veraRoot = veraRootEnv; veraRoot += "/.vera++"; } } veraRootEnv = getenv("VERA_ROOT"); if (veraRootEnv != NULL) { veraRoot = veraRootEnv; } Vera::Plugins::RootDirectory::setRootDirectory(veraRoot); // collect all source file names and interpret options Vera::Plugins::Rules::RuleName singleRule; Vera::Plugins::Transformations::TransformationName singleTransformation; bool omitDuplicates = false; int i = 1; while (i != argc) { const std::string arg(argv[i]); if (arg == "-help") { std::cout << "vera++ [options] [list-of-files]\n\n" "This command line interface is deprecated and is planned to be removed.\n\n" "Recognized options:\n\n" "- (a single minus sign) indicates that the list of\n" " source file names will be provided on the stdin.\n\n" "-exclusions file read exclusions from file\n\n" "-help print this message\n\n" "-nofail do not fail even when finding rule violations\n\n" "-nodup do not duplicate messages if a single rule is violated\n" " many times in a single line of code\n\n" "-profile name execute all rules from the given profile\n\n" "-param name=value provide parameters to scripts (can be used many times)\n\n" "-paramfile file read parameters from file\n\n" "-rule name execute the given rule\n" " (note: the .tcl extension is added automatically)\n\n" "-showrules include rule name in each report\n\n" "-vcformat report in Visual C++ format\n\n" "-xmlreport produce report in the XML format\n\n" "-transform name execute the given transformation\n\n" "-version print version number\n\n"; exit(EXIT_SUCCESS); } else if (arg == "-version") { std::cout << VERA_VERSION << '\n'; exit(EXIT_SUCCESS); } else if (arg == "-nofail") { exitCodeOnFailure = EXIT_SUCCESS; } else if (arg == "-nodup") { omitDuplicates = true; } else if (arg == "-") { // list of source files is provided on stdin Vera::Structures::SourceFiles::FileName name; while (std::cin >> name) { Vera::Structures::SourceFiles::addFileName(name); } } else if (arg == "-showrules") { Vera::Plugins::Reports::setShowRules(true); } else if (arg == "-xmlreport") { Vera::Plugins::Reports::setXMLReport(true); } else if (arg == "-vcformat") { Vera::Plugins::Reports::setVCFormat(true); } else if (arg == "-rule") { ++i; if (argv[i] != NULL) { singleRule = argv[i]; } else { if (silent == false) { std::cerr << "error: option -rule provided with no rule name\n"; } return exitCodeOnFailure; } } else if (arg == "-profile") { ++i; if (argv[i] != NULL) { profile = argv[i]; } else { if (silent == false) { std::cerr << "error: option -profile provided with no profile name\n"; } return exitCodeOnFailure; } } else if (arg == "-exclusions") { ++i; if (argv[i] != NULL) { Vera::Plugins::Exclusions::ExclusionFileName file(argv[i]); Vera::Plugins::Exclusions::setExclusions(file); } else { if (silent == false) { std::cerr << "error: option -exclusions provided without name of file\n"; } return exitCodeOnFailure; } } else if (arg == "-param") { ++i; if (argv[i] != NULL) { Vera::Plugins::Parameters::ParamAssoc assoc(argv[i]); Vera::Plugins::Parameters::set(assoc); } else { if (silent == false) { std::cerr << "error: option -param provided without name and value\n"; } return exitCodeOnFailure; } } else if (arg == "-paramfile") { ++i; if (argv[i] != NULL) { Vera::Plugins::Parameters::FileName file(argv[i]); Vera::Plugins::Parameters::readFromFile(file); } else { if (silent == false) { std::cerr << "error: option -paramfile provided without name of file\n"; } return exitCodeOnFailure; } } else if (arg == "-transform") { ++i; if (argv[i] != NULL) { singleTransformation = argv[i]; } else { if (silent == false) { std::cerr << "error: option -transform provided without name of transformation\n"; } return exitCodeOnFailure; } } else if (isSourceFileName(arg)) { Vera::Structures::SourceFiles::addFileName(arg); } else { // the option was not recognized as a name of the source file // or a vera-specific option if (silent == false) { std::cerr << "error: option " << arg << " not recognized\n"; } return EXIT_FAILURE; } ++i; } if (Vera::Structures::SourceFiles::empty()) { if (silent == false) { std::cerr << "vera++: no input files\n"; } return exitCodeOnFailure; } if (singleTransformation.empty() == false) { if (singleRule.empty() == false || profile != "default") { if (silent == false) { std::cerr << "error: " "transformation cannot be specified together with rules or profiles\n"; } return exitCodeOnFailure; } Vera::Plugins::Transformations::executeTransformation(singleTransformation); } else if (singleRule.empty() == false) { // single rule requested Vera::Plugins::Rules::executeRule(singleRule); } else { Vera::Plugins::Profiles::executeProfile(profile); } Vera::Plugins::Reports::dumpAll(std::cerr, omitDuplicates); } catch (const std::exception & e) { std::cerr << "error: " << e.what() << '\n'; exit(exitCodeOnFailure); } return 0; } vera++-1.2.1/src/main.cpp000644 000765 000024 00000003447 12136117203 015755 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include #include #include int legacy_main(int argc, char * argv[], bool silent = false); int boost_main(int argc, char * argv[]); int main(int argc, char * argv[]) { char * veraLegacyEnv = getenv("VERA_LEGACY"); if (veraLegacyEnv != NULL) { std::string legacy = veraLegacyEnv; boost::to_lower(legacy); if (legacy == "yes" || legacy == "on" || legacy == "1") { // use the legacy main, and nothing else return legacy_main(argc, argv); } // use the boost main and nothing else return boost_main(argc, argv); } // look at the arg if we can find some options that looks like legacy // options int i = 1; bool useLegacy = false; while (i != argc) { const std::string arg(argv[i]); if (arg == "-version" || arg == "-help" || arg == "-nofail" || arg == "-nodup" || arg == "-showrules" || arg == "-xmlreport" || arg == "-vcformat" || arg == "-rule" || arg == "-profile" || arg == "-exclusions" || arg == "-param" || arg == "-paramfile" || arg == "-transform") { useLegacy = true; break; } ++i; } // if legacy main fail, we silently pass to boost main in order to display // the new usage message if (useLegacy && legacy_main(argc, argv, true) == EXIT_SUCCESS) { return EXIT_SUCCESS; } return boost_main(argc, argv); } vera++-1.2.1/src/plugins/cpptcl-1.1.4/cpptcl.cpp000644 000765 000024 00000060516 12137563427 021741 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // #include "cpptcl.h" #include #include #include namespace Tcl { namespace details { result::result(Tcl_Interp *interp) : interp_(interp) {} result::operator bool() const { Tcl_Obj *obj = Tcl_GetObjResult(interp_); int val, cc; cc = Tcl_GetBooleanFromObj(interp_, obj, &val); if (cc != TCL_OK) { throw tcl_error(interp_); } return val != 0; } result::operator double() const { Tcl_Obj *obj = Tcl_GetObjResult(interp_); double val; int cc = Tcl_GetDoubleFromObj(interp_, obj, &val); if (cc != TCL_OK) { throw tcl_error(interp_); } return val; } result::operator int() const { Tcl_Obj *obj = Tcl_GetObjResult(interp_); int val, cc; cc = Tcl_GetIntFromObj(interp_, obj, &val); if (cc != TCL_OK) { throw tcl_error(interp_); } return val; } result::operator long() const { Tcl_Obj *obj = Tcl_GetObjResult(interp_); long val; int cc; cc = Tcl_GetLongFromObj(interp_, obj, &val); if (cc != TCL_OK) { throw tcl_error(interp_); } return val; } result::operator std::string() const { Tcl_Obj *obj = Tcl_GetObjResult(interp_); return Tcl_GetString(obj); } result::operator Tcl::object() const { return object(Tcl_GetObjResult(interp_)); } void set_result(Tcl_Interp *interp, bool b) { Tcl_SetObjResult(interp, Tcl_NewBooleanObj(b)); } void set_result(Tcl_Interp *interp, int i) { Tcl_SetObjResult(interp, Tcl_NewIntObj(i)); } void set_result(Tcl_Interp *interp, long i) { Tcl_SetObjResult(interp, Tcl_NewLongObj(i)); } void set_result(Tcl_Interp *interp, double d) { Tcl_SetObjResult(interp, Tcl_NewDoubleObj(d)); } void set_result(Tcl_Interp *interp, std::string const &s) { Tcl_SetObjResult(interp, Tcl_NewStringObj(s.data(), static_cast(s.size()))); } void set_result(Tcl_Interp *interp, void *p) { std::ostringstream ss; ss << 'p' << p; std::string s(ss.str()); Tcl_SetObjResult(interp, Tcl_NewStringObj(s.data(), static_cast(s.size()))); } void set_result(Tcl_Interp *interp, object const &o) { Tcl_SetObjResult(interp, o.get_object()); } void check_params_no(int objc, int required) { if (objc < required) { throw tcl_error("Too few arguments."); } } object get_var_params(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], int from, policies const &pol) { object o; if (pol.variadic_) { check_params_no(objc, from); o.assign(objv + from, objv + objc); } else { check_params_no(objc, from + 1); o.assign(objv[from]); } o.set_interp(interp); return o; } } namespace // unnamed { // map of polymorphic callbacks typedef std::map > callback_interp_map; typedef std::map callback_map; callback_map callbacks; callback_map constructors; // map of call policies typedef std::map policies_interp_map; typedef std::map policies_map; policies_map call_policies; // map of object handlers typedef std::map > class_interp_map; typedef std::map class_handlers_map; class_handlers_map class_handlers; // helper for finding call policies - returns true when found bool find_policies(Tcl_Interp *interp, std::string const &cmdName, policies_interp_map::iterator &piti) { policies_map::iterator pit = call_policies.find(interp); if (pit == call_policies.end()) { return false; } piti = pit->second.find(cmdName); return piti != pit->second.end(); } extern "C" int object_handler(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]); // helper function for post-processing call policies // for both free functions (isMethod == false) // and class methods (isMethod == true) void post_process_policies(Tcl_Interp *interp, policies &pol, Tcl_Obj * CONST objv[], bool isMethod) { // check if it is a factory if (pol.factory_.empty() == false) { class_handlers_map::iterator it = class_handlers.find(interp); if (it == class_handlers.end()) { throw tcl_error( "Factory was registered for unknown class."); } class_interp_map::iterator oit = it->second.find(pol.factory_); if (oit == it->second.end()) { throw tcl_error( "Factory was registered for unknown class."); } Tcl::details::class_handler_base *chb = oit->second.get(); // register a new command for the object returned // by this factory function // if everything went OK, the result is the address of the // new object in the 'pXXX' form // - the new command will be created with this name Tcl_CreateObjCommand(interp, Tcl_GetString(Tcl_GetObjResult(interp)), object_handler, static_cast(chb), 0); } // process all declared sinks // - unregister all object commands that envelopes the pointers for (std::vector::iterator s = pol.sinks_.begin(); s != pol.sinks_.end(); ++s) { if (isMethod == false) { // example: if there is a declared sink at parameter 3, // and the Tcl command was: // % fun par1 par2 PAR3 par4 // then the index 3 correctly points into the objv array int index = *s; Tcl_DeleteCommand(interp, Tcl_GetString(objv[index])); } else { // example: if there is a declared sink at parameter 3, // and the Tcl command was: // % $p method par1 par2 PAR3 par4 // then the index 3 needs to be incremented // in order correctly point into the 4th index of objv array int index = *s + 1; Tcl_DeleteCommand(interp, Tcl_GetString(objv[index])); } } } // actual functions handling various callbacks // generic callback handler extern "C" int callback_handler(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { callback_map::iterator it = callbacks.find(interp); if (it == callbacks.end()) { char msg[] = "Trying to invoke non-existent callback (wrong interpreter?)"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } std::string cmdName(Tcl_GetString(objv[0])); callback_interp_map::iterator iti = it->second.find(cmdName); if (iti == it->second.end()) { char msg[] = "Trying to invoke non-existent callback (wrong cmd name?)"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } policies_map::iterator pit = call_policies.find(interp); if (pit == call_policies.end()) { char msg[] = "Trying to invoke callback with no known policies"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } policies_interp_map::iterator piti; if (find_policies(interp, cmdName, piti) == false) { char msg[] = "Trying to invoke callback with no known policies"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } policies &pol = piti->second; try { iti->second->invoke(interp, objc, objv, pol); post_process_policies(interp, pol, objv, false); } catch (std::exception const &e) { Tcl_SetResult(interp, const_cast(e.what()), TCL_VOLATILE); return TCL_ERROR; } catch (...) { char msg[] = "Unknown error."; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } return TCL_OK; } // generic "object" command handler extern "C" int object_handler(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { // here, client data points to the singleton object // which is responsible for managing commands for // objects of a given type Tcl::details::class_handler_base *chb = reinterpret_cast(cd); // the command name has the form 'pXXX' where XXX is the address // of the "this" object std::string const str(Tcl_GetString(objv[0])); std::istringstream ss(str); char dummy; void *p; ss >> dummy >> p; try { std::string methodName(Tcl_GetString(objv[1])); policies &pol = chb->get_policies(methodName); chb->invoke(p, interp, objc, objv, pol); post_process_policies(interp, pol, objv, true); } catch (std::exception const &e) { Tcl_SetResult(interp, const_cast(e.what()), TCL_VOLATILE); return TCL_ERROR; } catch (...) { char msg[] = "Unknown error."; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } return TCL_OK; } // generic "constructor" command extern "C" int constructor_handler(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { // here, client data points to the singleton object // which is responsible for managing commands for // objects of a given type Tcl::details::class_handler_base *chb = reinterpret_cast(cd); callback_map::iterator it = constructors.find(interp); if (it == constructors.end()) { char msg[] = "Trying to invoke non-existent callback (wrong interpreter?)"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } std::string className(Tcl_GetString(objv[0])); callback_interp_map::iterator iti = it->second.find(className); if (iti == it->second.end()) { char msg[] = "Trying to invoke non-existent callback (wrong class name?)"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } policies_interp_map::iterator piti; if (find_policies(interp, className, piti) == false) { char msg[] = "Trying to invoke callback with no known policies"; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } policies &pol = piti->second; try { iti->second->invoke(interp, objc, objv, pol); // if everything went OK, the result is the address of the // new object in the 'pXXX' form // - we can create a new command with this name Tcl_CreateObjCommand(interp, Tcl_GetString(Tcl_GetObjResult(interp)), object_handler, static_cast(chb), 0); } catch (std::exception const &e) { Tcl_SetResult(interp, const_cast(e.what()), TCL_VOLATILE); return TCL_ERROR; } catch (...) { char msg[] = "Unknown error."; Tcl_SetResult(interp, msg, TCL_STATIC); return TCL_ERROR; } return TCL_OK; } } // unnamed namespace Tcl::details::no_init_type no_init; policies & policies::factory(std::string const &name) { factory_ = name; return *this; } policies & policies::sink(int index) { sinks_.push_back(index); return *this; } policies & policies::variadic() { variadic_ = true; return *this; } policies factory(std::string const &name) { return policies().factory(name); } policies sink(int index) { return policies().sink(index); } policies variadic() { return policies().variadic(); } namespace details { class_handler_base::class_handler_base() { // default policies for the -delete command policies_["-delete"] = policies(); } void class_handler_base::register_method(std::string const &name, boost::shared_ptr ocb, policies const &p) { methods_[name] = ocb; policies_[name] = p; } policies & class_handler_base::get_policies(std::string const &name) { policies_map_type::iterator it = policies_.find(name); if (it == policies_.end()) { throw tcl_error("Trying to use non-existent policy: " + name); } return it->second; } } object::object() : interp_(0) { obj_ = Tcl_NewObj(); Tcl_IncrRefCount(obj_); } object::object(bool b) : interp_(0) { obj_ = Tcl_NewBooleanObj(b); Tcl_IncrRefCount(obj_); } object::object(char const *buf, size_t size) : interp_(0) { obj_ = Tcl_NewByteArrayObj( reinterpret_cast(buf), static_cast(size)); Tcl_IncrRefCount(obj_); } object::object(double d) : interp_(0) { obj_ = Tcl_NewDoubleObj(d); Tcl_IncrRefCount(obj_); } object::object(int i) : interp_(0) { obj_ = Tcl_NewIntObj(i); Tcl_IncrRefCount(obj_); } object::object(long ln) : interp_(0) { obj_ = Tcl_NewLongObj(ln); Tcl_IncrRefCount(obj_); } object::object(char const *s) : interp_(0) { obj_ = Tcl_NewStringObj(s, -1); Tcl_IncrRefCount(obj_); } object::object(std::string const &s) : interp_(0) { obj_ = Tcl_NewStringObj(s.data(), static_cast(s.size())); Tcl_IncrRefCount(obj_); } object::object(Tcl_Obj *o, bool shared) : interp_(0) { init(o, shared); } object::object(object const &other, bool shared) : interp_(other.get_interp()) { init(other.obj_, shared); } void object::init(Tcl_Obj *o, bool shared) { if (shared) { obj_ = o; } else { obj_ = Tcl_DuplicateObj(o); } Tcl_IncrRefCount(obj_); } object::~object() { Tcl_DecrRefCount(obj_); } object & object::assign(bool b) { Tcl_SetBooleanObj(obj_, b); return *this; } object & object::resize(size_t size) { Tcl_SetByteArrayLength(obj_, static_cast(size)); return *this; } object & object::assign(char const *buf, size_t size) { Tcl_SetByteArrayObj(obj_, reinterpret_cast(buf), static_cast(size)); return *this; } object & object::assign(double d) { Tcl_SetDoubleObj(obj_, d); return *this; } object & object::assign(int i) { Tcl_SetIntObj(obj_, i); return *this; } object & object::assign(long ln) { Tcl_SetLongObj(obj_, ln); return *this; } object & object::assign(char const *s) { Tcl_SetStringObj(obj_, s, -1); return *this; } object & object::assign(std::string const &s) { Tcl_SetStringObj(obj_, s.data(), static_cast(s.size())); return *this; } object & object::assign(object const &other) { object(other).swap(*this); return *this; } object & object::assign(Tcl_Obj *o) { object(o).swap(*this); return *this; } object & object::swap(object &other) { std::swap(obj_, other.obj_); std::swap(interp_, other.interp_); return *this; } template <> bool object::get(interpreter &i) const { int retVal; int res = Tcl_GetBooleanFromObj(i.get(), obj_, &retVal); if (res != TCL_OK) { throw tcl_error(i.get()); } return retVal != 0; } template <> std::vector object::get >(interpreter &) const { size_t size; char const *buf = get(size); return std::vector(buf, buf + size); } template <> double object::get(interpreter &i) const { double retVal; int res = Tcl_GetDoubleFromObj(i.get(), obj_, &retVal); if (res != TCL_OK) { throw tcl_error(i.get()); } return retVal; } template <> int object::get(interpreter &i) const { int retVal; int res = Tcl_GetIntFromObj(i.get(), obj_, &retVal); if (res != TCL_OK) { throw tcl_error(i.get()); } return retVal; } template <> long object::get(interpreter &i) const { long retVal; int res = Tcl_GetLongFromObj(i.get(), obj_, &retVal); if (res != TCL_OK) { throw tcl_error(i.get()); } return retVal; } template <> char const * object::get(interpreter &) const { return get(); } template <> std::string object::get(interpreter &) const { int len; char const *buf = Tcl_GetStringFromObj(obj_, &len); return std::string(buf, buf + len); } char const * object::get() const { return Tcl_GetString(obj_); } char const * object::get(size_t &size) const { int len; unsigned char *buf = Tcl_GetByteArrayFromObj(obj_, &len); size = len; return const_cast(reinterpret_cast(buf)); } size_t object::length(interpreter &i) const { int len; int res = Tcl_ListObjLength(i.get(), obj_, &len); if (res != TCL_OK) { throw tcl_error(i.get()); } return static_cast(len); } object object::at(interpreter &i, size_t index) const { Tcl_Obj *o; int res = Tcl_ListObjIndex(i.get(), obj_, static_cast(index), &o); if (res != TCL_OK) { throw tcl_error(i.get()); } if (o == NULL) { throw tcl_error("Index out of range."); } return object(o); } object & object::append(interpreter &i, object const &o) { int res = Tcl_ListObjAppendElement(i.get(), obj_, o.obj_); if (res != TCL_OK) { throw tcl_error(i.get()); } return *this; } object & object::append_list(interpreter &i, object const &o) { int res = Tcl_ListObjAppendList(i.get(), obj_, o.obj_); if (res != TCL_OK) { throw tcl_error(i.get()); } return *this; } object & object::replace(interpreter &i, size_t index, size_t count, object const &o) { int res = Tcl_ListObjReplace(i.get(), obj_, static_cast(index), static_cast(count), 1, &(o.obj_)); if (res != TCL_OK) { throw tcl_error(i.get()); } return *this; } object & object::replace_list(interpreter &i, size_t index, size_t count, object const &o) { int objc; Tcl_Obj **objv; int res = Tcl_ListObjGetElements(i.get(), o.obj_, &objc, &objv); if (res != TCL_OK) { throw tcl_error(i.get()); } res = Tcl_ListObjReplace(i.get(), obj_, static_cast(index), static_cast(count), objc, objv); if (res != TCL_OK) { throw tcl_error(i.get()); } return *this; } void object::set_interp(Tcl_Interp *interp) { interp_ = interp; } Tcl_Interp * object::get_interp() const { return interp_; } interpreter::interpreter() { interp_ = Tcl_CreateInterp(); owner_ = true; } interpreter::interpreter(Tcl_Interp *interp, bool owner) { interp_ = interp; owner_ = owner; } interpreter::~interpreter() { if (owner_) { // clear all callback info belonging to this interpreter clear_definitions(interp_); Tcl_DeleteInterp(interp_); } } void interpreter::make_safe() { int cc = Tcl_MakeSafe(interp_); if (cc != TCL_OK) { throw tcl_error(interp_); } } details::result interpreter::eval(std::string const &script) { int cc = Tcl_Eval(interp_, script.c_str()); if (cc != TCL_OK) { throw tcl_error(interp_); } return details::result(interp_); } details::result interpreter::eval(std::istream &s) { std::string str( std::istreambuf_iterator(s.rdbuf()), std::istreambuf_iterator() ); return eval(str); } details::result interpreter::eval(object const &o) { int cc = Tcl_EvalObjEx(interp_, o.get_object(), 0); if (cc != TCL_OK) { throw tcl_error(interp_); } return details::result(interp_); } void interpreter::pkg_provide(std::string const &name, std::string const &version) { int cc = Tcl_PkgProvide(interp_, name.c_str(), version.c_str()); if (cc != TCL_OK) { throw tcl_error(interp_); } } void interpreter::create_alias(std::string const &cmd, interpreter &targetInterp, std::string const &targetCmd) { int cc = Tcl_CreateAlias(interp_, cmd.c_str(), targetInterp.interp_, targetCmd.c_str(), 0, 0); if (cc != TCL_OK) { throw tcl_error(interp_); } } void interpreter::clear_definitions(Tcl_Interp *interp) { // delete all callbacks that were registered for given interpreter { callback_map::iterator it = callbacks.find(interp); if (it == callbacks.end()) { // no callbacks defined for this interpreter return; } callback_interp_map &imap = it->second; for (callback_interp_map::iterator it2 = imap.begin(); it2 != imap.end(); ++it2) { Tcl_DeleteCommand(interp, it2->first.c_str()); } callbacks.erase(interp); } // delete all constructors { callback_map::iterator it = constructors.find(interp); if (it == constructors.end()) { // no callbacks defined for this interpreter return; } callback_interp_map &imap = it->second; for (callback_interp_map::iterator it2 = imap.begin(); it2 != imap.end(); ++it2) { Tcl_DeleteCommand(interp, it2->first.c_str()); } callbacks.erase(interp); } // delete all call policies call_policies.erase(interp); // delete all object handlers // (we have to assume that all living objects were destroyed, // otherwise Bad Things will happen) class_handlers.erase(interp); } void interpreter::add_function(std::string const &name, boost::shared_ptr cb, policies const &p) { Tcl_CreateObjCommand(interp_, name.c_str(), callback_handler, 0, 0); callbacks[interp_][name] = cb; call_policies[interp_][name] = p; } void interpreter::add_class(std::string const &name, boost::shared_ptr chb) { class_handlers[interp_][name] = chb; } void interpreter::add_constructor(std::string const &name, boost::shared_ptr chb, boost::shared_ptr cb, policies const &p) { Tcl_CreateObjCommand(interp_, name.c_str(), constructor_handler, static_cast(chb.get()), 0); constructors[interp_][name] = cb; call_policies[interp_][name] = p; } namespace details { int tcl_cast::from(Tcl_Interp *interp, Tcl_Obj *obj) { int res; int cc = Tcl_GetIntFromObj(interp, obj, &res); if (cc != TCL_OK) { throw tcl_error(interp); } return res; } long tcl_cast::from(Tcl_Interp *interp, Tcl_Obj *obj) { long res; int cc = Tcl_GetLongFromObj(interp, obj, &res); if (cc != TCL_OK) { throw tcl_error(interp); } return res; } bool tcl_cast::from(Tcl_Interp *interp, Tcl_Obj *obj) { int res; int cc = Tcl_GetBooleanFromObj(interp, obj, &res); if (cc != TCL_OK) { throw tcl_error(interp); } return res != 0; } double tcl_cast::from(Tcl_Interp *interp, Tcl_Obj *obj) { double res; int cc = Tcl_GetDoubleFromObj(interp, obj, &res); if (cc != TCL_OK) { throw tcl_error(interp); } return res; } std::string tcl_cast::from(Tcl_Interp *, Tcl_Obj *obj) { return Tcl_GetString(obj); } char const * tcl_cast::from(Tcl_Interp *, Tcl_Obj *obj) { return Tcl_GetString(obj); } object tcl_cast::from(Tcl_Interp *interp, Tcl_Obj *obj) { object o(obj); o.set_interp(interp); return o; } } } vera++-1.2.1/src/plugins/cpptcl-1.1.4/cpptcl.h000644 000765 000024 00000066673 12137563545 021421 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // #ifndef CPPTCL_INCLUDED #define CPPTCL_INCLUDED #include #include #include #include #include #include #include #include namespace Tcl { // exception class used for reporting all Tcl errors class tcl_error : public std::runtime_error { public: explicit tcl_error(std::string const &msg) : std::runtime_error(msg) {} explicit tcl_error(Tcl_Interp *interp) : std::runtime_error( Tcl_GetString(Tcl_GetVar2Ex(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY))){} }; // call policies struct policies { policies() : variadic_(false) {} policies & factory(std::string const &name); // note: this is additive policies & sink(int index); policies & variadic(); std::string factory_; std::vector sinks_; bool variadic_; }; // syntax short-cuts policies factory(std::string const &name); policies sink(int index); policies variadic(); class interpreter; class object; namespace details { // wrapper for the evaluation result class result { public: result(Tcl_Interp *interp); operator bool() const; operator double() const; operator int() const; operator long() const; operator std::string() const; operator object() const; private: Tcl_Interp *interp_; }; // helper functions used to set the result value void set_result(Tcl_Interp *interp, bool b); void set_result(Tcl_Interp *interp, int i); void set_result(Tcl_Interp *interp, long i); void set_result(Tcl_Interp *interp, double d); void set_result(Tcl_Interp *interp, std::string const &s); void set_result(Tcl_Interp *interp, void *p); void set_result(Tcl_Interp *interp, object const &o); // helper functor for converting Tcl objects to the given type #include "details/conversions.h" // dispatchers able to capture (or ignore) the result #include "details/dispatchers.h" // helper for checking for required number of parameters // (throws tcl_error when not met) void check_params_no(int objc, int required); // helper for gathering optional params in variadic functions object get_var_params(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], int from, policies const &pol); // the callback_base is used to store callback handlers in a polynorphic map class callback_base { public: virtual ~callback_base() {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) = 0; }; // base class for object command handlers // and for class handlers class object_cmd_base { public: // destructor not needed, but exists to shut up the compiler warnings virtual ~object_cmd_base() {} virtual void invoke(void *p, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) = 0; }; // base class for all class handlers, still abstract class class_handler_base : public object_cmd_base { public: typedef std::map policies_map_type; class_handler_base(); void register_method(std::string const &name, boost::shared_ptr ocb, policies const &p); policies & get_policies(std::string const &name); protected: typedef std::map< std::string, boost::shared_ptr > method_map_type; // a map of methods for the given class method_map_type methods_; policies_map_type policies_; }; // class handler - responsible for executing class methods template class class_handler : public class_handler_base { public: virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C * p = static_cast(pv); if (objc < 2) { throw tcl_error("Too few arguments."); } std::string methodName(Tcl_GetString(objv[1])); if (methodName == "-delete") { Tcl_DeleteCommand(interp, Tcl_GetString(objv[0])); delete p; return; } // dispatch on the method name method_map_type::iterator it = methods_.find(methodName); if (it == methods_.end()) { throw tcl_error("Method " + methodName + " not found."); } it->second->invoke(pv, interp, objc, objv, pol); } }; // factory functions for creating class objects #include "details/constructors.h" // actual callback envelopes #include "details/callbacks.h" // actual method envelopes #include "details/methods.h" // helper meta function for figuring appropriate constructor callback #include "details/metahelpers.h" // this class is used to provide the "def" interface for defining // class member functions template class class_definer { public: class_definer(boost::shared_ptr > ch) : ch_(ch) {} template class_definer & def(std::string const &name, R (C::*f)(), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method0(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)() const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method0(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method1(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method1(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method2(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method2(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method3(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method3(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method4(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method4(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method5(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method5(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method6(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method6(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method7(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method7(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7, T8), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method8(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7, T8) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method8(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method9(f)), p); return *this; } template class_definer & def(std::string const &name, R (C::*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9) const, policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr( new details::method9(f)), p); return *this; } private: boost::shared_ptr > ch_; }; } // namespace details // init type for defining class constructors template class init {}; // no_init type and object - to define classes without constructors namespace details { struct no_init_type {}; } // namespace details extern details::no_init_type no_init; // interpreter wrapper class interpreter { public: interpreter(); interpreter(Tcl_Interp *, bool owner = true); ~interpreter(); void make_safe(); Tcl_Interp * get() const { return interp_; } // free function definitions template void def(std::string const &name, R (*f)(), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback0(f)), p); } template void def(std::string const &name, R (*f)(T1), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback1(f)), p); } template void def(std::string const &name, R (*f)(T1, T2), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback2(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback3(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback4(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4, T5), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback5(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4, T5, T6), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback6(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4, T5, T6, T7), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback7(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4, T5, T6, T7, T8), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback8(f)), p); } template void def(std::string const &name, R (*f)(T1, T2, T3, T4, T5, T6, T7, T8, T9), policies const &p = policies()) { add_function(name, boost::shared_ptr( new details::callback9(f)), p); } // class definitions template details::class_definer class_(std::string const &name) { boost::shared_ptr > ch( new details::class_handler()); add_class(name, ch); add_constructor(name, ch, boost::shared_ptr( new details::callback0(&details::construct< C, void, void, void, void, void, void, void, void, void>::doit))); return details::class_definer(ch); } template details::class_definer class_(std::string const &name, init const &, policies const &p = policies()) { typedef typename details::get_callback_type_for_construct< C, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type callback_type; boost::shared_ptr > ch( new details::class_handler()); add_class(name, ch); add_constructor(name, ch, boost::shared_ptr( new callback_type(&details::construct< C, T1, T2, T3, T4, T5, T6, T7, T8, T9>::doit)), p); return details::class_definer(ch); } template details::class_definer class_( std::string const &name, details::no_init_type const &) { boost::shared_ptr > ch( new details::class_handler()); add_class(name, ch); return details::class_definer(ch); } // free script evaluation details::result eval(std::string const &script); details::result eval(std::istream &s); details::result eval(object const &o); // the InputIterator should give object& or Tcl_Obj* when dereferenced template details::result eval(InputIterator first, InputIterator last); // create alias from the *this interpreter to the target interpreter void create_alias(std::string const &cmd, interpreter &targetInterp, std::string const &targetCmd); // register a package info (useful when defining packages) void pkg_provide(std::string const &name, std::string const &version); // helper for cleaning up callbacks in non-managed interpreters static void clear_definitions(Tcl_Interp *); private: // copy not supported interpreter(const interpreter &); void operator=(const interpreter &); void add_function(std::string const &name, boost::shared_ptr cb, policies const &p = policies()); void add_class(std::string const &name, boost::shared_ptr chb); void add_constructor(std::string const &name, boost::shared_ptr chb, boost::shared_ptr cb, policies const &p = policies()); Tcl_Interp *interp_; bool owner_; }; // object wrapper class object { public: // constructors object(); explicit object(bool b); object(char const *buf, size_t size); // byte array explicit object(double b); explicit object(int i); // list creation // the InputIterator should give object& or Tcl_Obj* when dereferenced template object(InputIterator first, InputIterator last) : interp_(0) { std::vector v; fill_vector(v, first, last); obj_ = Tcl_NewListObj(static_cast(v.size()), v.empty() ? NULL : &v[0]); Tcl_IncrRefCount(obj_); } explicit object(long i); explicit object(char const *s); // string construction explicit object(std::string const &s); // string construction explicit object(Tcl_Obj *o, bool shared = false); object(object const &other, bool shared = false); ~object(); // assignment object & assign(bool b); object & resize(size_t size); // byte array resize object & assign(char const *buf, size_t size); // byte array assignment object & assign(double d); object & assign(int i); // list assignment // the InputIterator should give Tcl_Obj* or object& when dereferenced template object & assign(InputIterator first, InputIterator last) { std::vector v; fill_vector(v, first, last); Tcl_SetListObj(obj_, static_cast(v.size()), v.empty() ? NULL : &v[0]); return *this; } object & assign(long ln); object & assign(char const *s); // string assignment object & assign(std::string const &s); // string assignment object & assign(object const &o); object & assign(Tcl_Obj *o); object & operator=(bool b) { return assign(b); } object & operator=(double d) { return assign(d); } object & operator=(int i) { return assign(i); } object & operator=(long ln) { return assign(ln); } object & operator=(char const *s) { return assign(s); } object & operator=(std::string const &s) { return assign(s); } object & operator=(object const &o) { return assign(o); } object & swap(object &other); // (logically) non-modifying members template T get(interpreter &i) const; char const * get() const; // string get char const * get(size_t &size) const; // byte array get size_t length(interpreter &i) const; // returns list length object at(interpreter &i, size_t index) const; Tcl_Obj * get_object() const { return obj_; } // modifying members object & append(interpreter &i, object const &o); object & append_list(interpreter &i, object const &o); // list replace // the InputIterator should give Tcl_Obj* or object& when dereferenced template object & replace(interpreter &i, size_t index, size_t count, InputIterator first, InputIterator last) { std::vector v; fill_vector(v, first, last); int res = Tcl_ListObjReplace(i.get(), obj_, static_cast(index), static_cast(count), static_cast(v.size()), v.empty() ? NULL : &v[0]); if (res != TCL_OK) { throw tcl_error(i.get()); } return *this; } object & replace(interpreter &i, size_t index, size_t count, object const &o); object & replace_list(interpreter &i, size_t index, size_t count, object const &o); // helper functions for piggy-backing interpreter info void set_interp(Tcl_Interp *interp); Tcl_Interp * get_interp() const; // helper function, also used from interpreter::eval template static void fill_vector(std::vector &v, InputIterator first, InputIterator last) { for (; first != last; ++first) { object o(*first, true); v.push_back(o.obj_); } } private: // helper function used from copy constructors void init(Tcl_Obj *o, bool shared); Tcl_Obj *obj_; Tcl_Interp *interp_; }; // available specializations for object::get template <> bool object::get(interpreter &i) const; template <> double object::get(interpreter &i) const; template <> int object::get(interpreter &i) const; template <> long object::get(interpreter &i) const; template <> char const * object::get(interpreter &i) const; template <> std::string object::get(interpreter &i) const; template <> std::vector object::get >(interpreter &i) const; // the InputIterator should give object& or Tcl_Obj* when dereferenced template details::result interpreter::eval(InputIterator first, InputIterator last) { std::vector v; object::fill_vector(v, first, last); int cc = Tcl_EvalObjv(interp_, static_cast(v.size()), v.empty() ? NULL : &v[0], 0); if (cc != TCL_OK) { throw tcl_error(interp_); } return details::result(interp_); } namespace details { // additional callback envelopes for variadic functions #include "details/callbacks_v.h" // additional method envelopes for variadic methods #include "details/methods_v.h" } // namespace details } // namespace Tcl // macro for defining loadable module entry point // - used for extending Tcl interpreter #define CPPTCL_MODULE(name, i) void name##_cpptcl_Init(Tcl::interpreter &i); \ extern "C" int name##_Init(Tcl_Interp *interp) \ { \ Tcl::interpreter i(interp, false); \ name##_cpptcl_Init(i); \ return TCL_OK; \ } \ void name##_cpptcl_Init(Tcl::interpreter &i) #endif // CPPTCL_INCLUDED vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/callbacks.h000644 000765 000024 00000017454 12125131507 023453 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template class callback0 : public callback_base { typedef R (*functor_type)(); public: callback0(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int, Tcl_Obj * CONST [], policies const &) { dispatch::do_dispatch(interp, f_); } private: functor_type f_; }; template class callback1 : public callback_base { typedef R (*functor_type)(T1); public: callback1(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 2); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1])); } private: functor_type f_; }; template class callback2 : public callback_base { typedef R (*functor_type)(T1, T2); public: callback2(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 3); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2])); } private: functor_type f_; }; template class callback3 : public callback_base { typedef R (*functor_type)(T1, T2, T3); public: callback3(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 4); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3])); } private: functor_type f_; }; template class callback4 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4); public: callback4(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 5); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4])); } private: functor_type f_; }; template class callback5 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4, T5); public: callback5(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 6); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5])); } private: functor_type f_; }; template class callback6 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4, T5, T6); public: callback6(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 7); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6])); } private: functor_type f_; }; template class callback7 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7); public: callback7(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 8); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7])); } private: functor_type f_; }; template class callback8 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8); public: callback8(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 9); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8])); } private: functor_type f_; }; template class callback9 : public callback_base { typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9); public: callback9(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 10); dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9])); } private: functor_type f_; }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/callbacks_v.h000644 000765 000024 00000020270 12125131507 023766 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template class callback1 : public callback_base { typedef object const & T1; typedef R (*functor_type)(T1); enum { var_start = 1 }; public: callback1(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t1 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch(interp, f_, t1); } private: functor_type f_; }; template class callback2 : public callback_base { typedef object const & T2; typedef R (*functor_type)(T1, T2); enum { var_start = 2 }; public: callback2(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t2 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), t2); } private: functor_type f_; }; template class callback3 : public callback_base { typedef object const & T3; typedef R (*functor_type)(T1, T2, T3); enum { var_start = 3 }; public: callback3(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t3 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), t3); } private: functor_type f_; }; template class callback4 : public callback_base { typedef object const & T4; typedef R (*functor_type)(T1, T2, T3, T4); enum { var_start = 4 }; public: callback4(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t4 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch(interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), t4); } private: functor_type f_; }; template class callback5 : public callback_base { typedef object const & T5; typedef R (*functor_type)(T1, T2, T3, T4, T5); enum { var_start = 5 }; public: callback5(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t5 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), t5); } private: functor_type f_; }; template class callback6 : public callback_base { typedef object const & T6; typedef R (*functor_type)(T1, T2, T3, T4, T5, T6); enum { var_start = 6 }; public: callback6(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t6 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), t6); } private: functor_type f_; }; template class callback7 : public callback_base { typedef object const & T7; typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7); enum { var_start = 7 }; public: callback7(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t7 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), t7); } private: functor_type f_; }; template class callback8 : public callback_base { typedef object const & T8; typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8); enum { var_start = 8 }; public: callback8(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t8 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), t8); } private: functor_type f_; }; template class callback9 : public callback_base { typedef object const & T9; typedef R (*functor_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9); enum { var_start = 9 }; public: callback9(functor_type f) : f_(f) {} virtual void invoke(Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { object t9 = get_var_params(interp, objc, objv, var_start, pol); dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>( interp, f_, tcl_cast::from(interp, objv[1]), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), t9); } private: functor_type f_; }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/constructors.h000644 000765 000024 00000005442 12125131507 024276 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { return new C(t1, t2, t3, t4, t5, t6, t7, t8, t9); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { return new C(t1, t2, t3, t4, t5, t6, t7, t8); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { return new C(t1, t2, t3, t4, t5, t6, t7); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { return new C(t1, t2, t3, t4, t5, t6); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { return new C(t1, t2, t3, t4, t5); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3, T4 t4) { return new C(t1, t2, t3, t4); } }; template struct construct { static C * doit(T1 t1, T2 t2, T3 t3) { return new C(t1, t2, t3); } }; template struct construct { static C * doit(T1 t1, T2 t2) { return new C(t1, t2); } }; template struct construct { static C * doit(T1 t1) { return new C(t1); } }; template struct construct { static C * doit() { return new C(); } }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/conversions.h000644 000765 000024 00000004213 12125131507 024071 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header // helper functor for converting Tcl objects to the given type // (it is a struct instead of function, // because I need to partially specialize it) template struct tcl_cast; template struct tcl_cast { static T * from(Tcl_Interp *, Tcl_Obj *obj) { std::string s(Tcl_GetString(obj)); if (s.size() == 0) { throw tcl_error("Expected pointer value, got empty string."); } if (s[0] != 'p') { throw tcl_error("Expected pointer value."); } std::istringstream ss(s); char dummy; void *p; ss >> dummy >> p; return static_cast(p); } }; // the following partial specialization is to strip reference // (it returns a temporary object of the underlying type, which // can be bound to the const-ref parameter of the actual function) template struct tcl_cast { static T from(Tcl_Interp *interp, Tcl_Obj *obj) { return tcl_cast::from(interp, obj); } }; // the following specializations are implemented template <> struct tcl_cast { static int from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static long from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static bool from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static double from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static std::string from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static char const * from(Tcl_Interp *, Tcl_Obj *); }; template <> struct tcl_cast { static object from(Tcl_Interp *, Tcl_Obj *); }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/dispatchers.h000644 000765 000024 00000013247 12125131507 024041 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header // the dispatch class is used to execute the callback functor and to // capture its return value // further dispatch specialization ignores the res template struct dispatch { template static void do_dispatch(Tcl_Interp *interp, Functor f) { R res = f(); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1) { R res = f(t1); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2) { R res = f(t1, t2); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3) { R res = f(t1, t2, t3); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4) { R res = f(t1, t2, t3, t4); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { R res = f(t1, t2, t3, t4, t5); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { R res = f(t1, t2, t3, t4, t5, t6); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { R res = f(t1, t2, t3, t4, t5, t6, t7); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { R res = f(t1, t2, t3, t4, t5, t6, t7, t8); set_result(interp, res); } template static void do_dispatch(Tcl_Interp *interp, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { R res = f(t1, t2, t3, t4, t5, t6, t7, t8, t9); set_result(interp, res); } }; template <> struct dispatch { template static void do_dispatch(Tcl_Interp *, Functor f) { f(); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1) { f(t1); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2) { f(t1, t2); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3) { f(t1, t2, t3); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4) { f(t1, t2, t3, t4); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { f(t1, t2, t3, t4, t5); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { f(t1, t2, t3, t4, t5, t6); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { f(t1, t2, t3, t4, t5, t6, t7); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { f(t1, t2, t3, t4, t5, t6, t7, t8); } template static void do_dispatch(Tcl_Interp *, Functor f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { f(t1, t2, t3, t4, t5, t6, t7, t8, t9); } }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/metahelpers.h000644 000765 000024 00000005166 12125131507 024042 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template struct get_callback_type_for_construct { typedef callback9 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, T4, T5, T6, T7, T8, void> { typedef callback8 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, T4, T5, T6, T7, void, void> { typedef callback7 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, T4, T5, T6, void, void, void> { typedef callback6 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, T4, T5, void, void, void, void> { typedef callback5 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, T4, void, void, void, void, void> { typedef callback4 type; }; template struct get_callback_type_for_construct< C, T1, T2, T3, void, void, void, void, void, void> { typedef callback3 type; }; template struct get_callback_type_for_construct< C, T1, T2, void, void, void, void, void, void, void> { typedef callback2 type; }; template struct get_callback_type_for_construct< C, T1, void, void, void, void, void, void, void, void> { typedef callback1 type; }; template struct get_callback_type_for_construct< C, void, void, void, void, void, void, void, void, void> { typedef callback0 type; }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/methods.h000644 000765 000024 00000036352 12125131507 023175 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template class method0 : public object_cmd_base { typedef R (C::*mem_type)(); typedef R (C::*cmem_type)() const; public: method0(mem_type f) : f_(f), cmem_(false) {} method0(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int, Tcl_Obj * CONST [], policies const &) { C *p = static_cast(pv); if (cmem_) { dispatch::do_dispatch(interp, boost::bind(cf_, p)); } else { dispatch::do_dispatch(interp, boost::bind(f_, p)); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method1 : public object_cmd_base { typedef R (C::*mem_type)(T1); typedef R (C::*cmem_type)(T1) const; public: method1(mem_type f) : f_(f), cmem_(false) {} method1(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 3); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1), tcl_cast::from(interp, objv[2])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1), tcl_cast::from(interp, objv[2])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method2 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2); typedef R (C::*cmem_type)(T1, T2) const; public: method2(mem_type f) : f_(f), cmem_(false) {} method2(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 4); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method3 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3); typedef R (C::*cmem_type)(T1, T2, T3) const; public: method3(mem_type f) : f_(f), cmem_(false) {} method3(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 5); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method4 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4); typedef R (C::*cmem_type)(T1, T2, T3, T4) const; public: method4(mem_type f) : f_(f), cmem_(false) {} method4(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 6); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method5 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4, T5); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5) const; public: method5(mem_type f) : f_(f), cmem_(false) {} method5(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 7); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method6 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6) const; public: method6(mem_type f) : f_(f), cmem_(false) {} method6(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 8); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method7 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7) const; public: method7(mem_type f) : f_(f), cmem_(false) {} method7(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 9); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8])); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method8 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7, T8); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7, T8) const; public: method8(mem_type f) : f_(f), cmem_(false) {} method8(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 10); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8>( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7, _8), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9])); } else { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8>( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7, _8), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method9 : public object_cmd_base { typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9) const; public: method9(mem_type f) : f_(f), cmem_(false) {} method9(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &) { check_params_no(objc, 11); C *p = static_cast(pv); if (cmem_) { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7, _8, _9), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9]), tcl_cast::from(interp, objv[10])); } else { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7, _8, _9), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9]), tcl_cast::from(interp, objv[10])); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; vera++-1.2.1/src/plugins/cpptcl-1.1.4/details/methods_v.h000644 000765 000024 00000036013 12125131507 023514 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2004-2006, Maciej Sobczak // // Permission to copy, use, modify, sell and distribute this software // is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // // Note: this file is not supposed to be a stand-alone header template class method1 : public object_cmd_base { typedef object const & T1; typedef R (C::*mem_type)(T1); typedef R (C::*cmem_type)(T1) const; enum { var_start = 2 }; public: method1(mem_type f) : f_(f), cmem_(false) {} method1(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t1 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1), t1); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1), t1); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method2 : public object_cmd_base { typedef object const & T2; typedef R (C::*mem_type)(T1, T2); typedef R (C::*cmem_type)(T1, T2) const; enum { var_start = 3 }; public: method2(mem_type f) : f_(f), cmem_(false) {} method2(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t2 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2), tcl_cast::from(interp, objv[2]), t2); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2), tcl_cast::from(interp, objv[2]), t2); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method3 : public object_cmd_base { typedef object const & T3; typedef R (C::*mem_type)(T1, T2, T3); typedef R (C::*cmem_type)(T1, T2, T3) const; enum { var_start = 4 }; public: method3(mem_type f) : f_(f), cmem_(false) {} method3(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t3 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), t3); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), t3); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method4 : public object_cmd_base { typedef object const & T4; typedef R (C::*mem_type)(T1, T2, T3, T4); typedef R (C::*cmem_type)(T1, T2, T3, T4) const; enum { var_start = 5 }; public: method4(mem_type f) : f_(f), cmem_(false) {} method4(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t4 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), t4); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), t4); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method5 : public object_cmd_base { typedef object const & T5; typedef R (C::*mem_type)(T1, T2, T3, T4, T5); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5) const; enum { var_start = 6 }; public: method5(mem_type f) : f_(f), cmem_(false) {} method5(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t5 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), t5); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), t5); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method6 : public object_cmd_base { typedef object const & T6; typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6) const; enum { var_start = 7 }; public: method6(mem_type f) : f_(f), cmem_(false) {} method6(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t6 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), t6); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), t6); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method7 : public object_cmd_base { typedef object const & T7; typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7) const; enum { var_start = 8 }; public: method7(mem_type f) : f_(f), cmem_(false) {} method7(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t7 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), t7); } else { dispatch::template do_dispatch( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), t7); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method8 : public object_cmd_base { typedef object const & T8; typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7, T8); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7, T8) const; enum { var_start = 9 }; public: method8(mem_type f) : f_(f), cmem_(false) {} method8(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t8 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8>( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7, _8), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), t8); } else { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8>( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7, _8), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), t8); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; template class method9 : public object_cmd_base { typedef object const & T9; typedef R (C::*mem_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9); typedef R (C::*cmem_type)(T1, T2, T3, T4, T5, T6, T7, T8, T9) const; enum { var_start = 10 }; public: method9(mem_type f) : f_(f), cmem_(false) {} method9(cmem_type f) : cf_(f), cmem_(true) {} virtual void invoke(void *pv, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[], policies const &pol) { C *p = static_cast(pv); object t9 = get_var_params(interp, objc, objv, var_start, pol); if (cmem_) { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>( interp, boost::bind(cf_, p, _1, _2, _3, _4, _5, _6, _7, _8, _9), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9]), t9); } else { dispatch::template do_dispatch< T1, T2, T3, T4, T5, T6, T7, T8, T9>( interp, boost::bind(f_, p, _1, _2, _3, _4, _5, _6, _7, _8, _9), tcl_cast::from(interp, objv[2]), tcl_cast::from(interp, objv[3]), tcl_cast::from(interp, objv[4]), tcl_cast::from(interp, objv[5]), tcl_cast::from(interp, objv[6]), tcl_cast::from(interp, objv[7]), tcl_cast::from(interp, objv[8]), tcl_cast::from(interp, objv[9]), t9); } } private: mem_type f_; cmem_type cf_; bool cmem_; }; vera++-1.2.1/src/plugins/CurrentRule.h000644 000765 000024 00000001064 12125131507 020423 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef CURRENTRULE_H_INCLUDED #define CURRENTRULE_H_INCLUDED #include namespace Vera { namespace Plugins { class CurrentRule { public: typedef std::string RuleName; static void setCurrentRule(const RuleName & name); static RuleName getCurrentRule(); }; } // namespace Plugins } // namespace Vera #endif // CURRENTRULE_H_INCLUDED vera++-1.2.1/src/plugins/Exclusions.cpp000644 000765 000024 00000004246 12154705401 020647 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Exclusions.h" #include "Rules.h" #include "../structures/SourceFiles.h" #include "cpptcl-1.1.4/cpptcl.h" #include #include namespace // unnamed { typedef std::set FileNameSet; typedef std::map ExclusionMap; ExclusionMap exclusions; } // unnamed namespace namespace Vera { namespace Plugins { void Exclusions::setExclusions(const ExclusionFileName & fileName) { std::ifstream exclusionsFile(fileName.c_str()); if (exclusionsFile.is_open() == false) { std::ostringstream ss; ss << "cannot open exclusions file " << fileName; throw ExclusionError(ss.str()); } Tcl::interpreter interp; interp.eval(exclusionsFile); const Tcl::object ruleNames = interp.eval("array names ruleExclusions"); const size_t ruleNamesLength = ruleNames.length(interp); for (size_t i = 0; i != ruleNamesLength; ++i) { const std::string ruleName = ruleNames.at(interp, i).get(); const Tcl::object exceptionList = interp.eval("set ruleExclusions(" + ruleName + ")"); const size_t exceptionListLength = exceptionList.length(interp); FileNameSet files; for (size_t j = 0; j != exceptionListLength; ++j) { const Structures::SourceFiles::FileName file = exceptionList.at(interp, j).get(); files.insert(file); } exclusions[ruleName] = files; } } bool Exclusions::isExcluded(const Structures::SourceFiles::FileName & name) { const Rules::RuleName currentRule = Rules::getCurrentRule(); const ExclusionMap::const_iterator eit = exclusions.find(currentRule); if (eit != exclusions.end()) { const FileNameSet & files = eit->second; const FileNameSet::const_iterator fit = files.find(name.substr(name.find_last_of("\\/") + 1)); return fit != files.end(); } else { return false; } } } } vera++-1.2.1/src/plugins/Exclusions.h000644 000765 000024 00000001454 12125131507 020310 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef EXCLUSIONS_H_INCLUDED #define EXCLUSIONS_H_INCLUDED #include #include "../structures/SourceFiles.h" #include namespace Vera { namespace Plugins { class ExclusionError : public std::runtime_error { public: ExclusionError(const std::string & msg) : std::runtime_error(msg) {} }; class Exclusions { public: typedef std::string ExclusionFileName; static void setExclusions(const ExclusionFileName & name); static bool isExcluded(const Structures::SourceFiles::FileName & name); }; } // namespace Plugins } // namespace Vera #endif // EXCLUSIONS_H_INCLUDED vera++-1.2.1/src/plugins/Interpreter.cpp000644 000765 000024 00000012125 12154705401 021011 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Interpreter.h" #include "Exclusions.h" #include "Reports.h" #include "Parameters.h" #include "../structures/SourceFiles.h" #include "../structures/SourceLines.h" #include "../structures/Tokens.h" #include "cpptcl-1.1.4/cpptcl.h" #include #include #include namespace // unnamed { // helper global pointer // - for those functions that might modify the interpreter's state Tcl::interpreter *pInter; void report(const std::string & fileName, int lineNumber, const std::string & message) { Vera::Plugins::Reports::add(fileName, lineNumber, message); } std::string getParameter(const std::string & name, const std::string & defaultValue) { return Vera::Plugins::Parameters::get(name, defaultValue); } Tcl::object getSourceFileNames() { Tcl::object obj; const Vera::Structures::SourceFiles::FileNameSet & files = Vera::Structures::SourceFiles::getAllFileNames(); typedef Vera::Structures::SourceFiles::FileNameSet::const_iterator iterator; const iterator end = files.end(); for (iterator it = files.begin(); it != end; ++it) { const Vera::Structures::SourceFiles::FileName & name = *it; if (Vera::Plugins::Exclusions::isExcluded(name) == false) { obj.append(*pInter, Tcl::object(name)); } } return obj; } int getLineCount(const std::string & sourceName) { return Vera::Structures::SourceLines::getLineCount(sourceName); } std::string getLine(const std::string & sourceName, int lineNumber) { return Vera::Structures::SourceLines::getLine(sourceName, lineNumber); } Tcl::object getAllLines(const std::string & sourceName) { Tcl::object obj; const Vera::Structures::SourceLines::LineCollection & lines = Vera::Structures::SourceLines::getAllLines(sourceName); typedef Vera::Structures::SourceLines::LineCollection::const_iterator iterator; const iterator end = lines.end(); for (iterator it = lines.begin(); it != end; ++it) { obj.append(*pInter, Tcl::object(*it)); } return obj; } Tcl::object getTokens(const std::string & sourceName, int fromLine, int fromColumn, int toLine, int toColumn, const Tcl::object & filter) { Vera::Structures::Tokens::FilterSequence filterSeq; size_t filterLength = filter.length(*pInter); for (size_t i = 0; i != filterLength; ++i) { filterSeq.push_back(filter.at(*pInter, i).get()); } Vera::Structures::Tokens::TokenSequence tokenSeq = Vera::Structures::Tokens::getTokens(sourceName, fromLine, fromColumn, toLine, toColumn, filterSeq); Tcl::object ret; Vera::Structures::Tokens::TokenSequence::iterator it = tokenSeq.begin(); Vera::Structures::Tokens::TokenSequence::iterator end = tokenSeq.end(); for ( ; it != end; ++it) { Tcl::object singleToken; singleToken.append(*pInter, Tcl::object(it->value_)); singleToken.append(*pInter, Tcl::object(it->line_)); singleToken.append(*pInter, Tcl::object(it->column_)); singleToken.append(*pInter, Tcl::object(it->name_)); ret.append(*pInter, singleToken); } return ret; } void registerCommands(Tcl::interpreter & inter) { pInter = &inter; // commands related to source files and plain source code inter.def("report", report); inter.def("getParameter", getParameter); inter.def("getSourceFileNames", getSourceFileNames); inter.def("getLineCount", getLineCount); inter.def("getLine", getLine); inter.def("getAllLines", getAllLines); inter.def("getTokens", getTokens); } } // unnamed namespace namespace Vera { namespace Plugins { void Interpreter::execute(const DirectoryName & root, ScriptType type, const ScriptName & name) { std::string fileName = root + "/scripts/"; switch (type) { case rule: fileName += "rules/"; break; case transformation: fileName += "transformations/"; break; } fileName += name; fileName += ".tcl"; std::ifstream scriptFile(fileName.c_str()); if (scriptFile.is_open() == false) { std::ostringstream ss; ss << "cannot open script " << fileName; throw ScriptError(ss.str()); } std::string scriptBody; scriptBody.assign(std::istreambuf_iterator(scriptFile), std::istreambuf_iterator()); Tcl::interpreter inter; registerCommands(inter); try { inter.eval(scriptBody); } catch (Tcl::tcl_error & e) { // rethrow the exception with the name of the rule #if (TCL_MAJOR_VERSION < 8) || (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION < 6) int errorLine = inter.get()->errorLine; #else int errorLine = Tcl_GetErrorLine(inter.get()); #endif throw Tcl::tcl_error(std::string(e.what()) + "\n (file \"" + fileName + "\" line " + boost::lexical_cast(errorLine) + ")"); } } } } vera++-1.2.1/src/plugins/Interpreter.h000644 000765 000024 00000001435 12154350323 020457 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef INTERPRETER_H_INCLUDED #define INTERPRETER_H_INCLUDED #include namespace Vera { namespace Plugins { class ScriptError : public std::runtime_error { public: ScriptError(const std::string & msg) : std::runtime_error(msg) {} }; class Interpreter { public: enum ScriptType { rule, transformation }; typedef std::string DirectoryName; typedef std::string ScriptName; static void execute(const DirectoryName & root, ScriptType type, const ScriptName & name); }; } // namespace Plugins } // namespace Vera #endif // INTERPRETER_H_INCLUDED vera++-1.2.1/src/plugins/Parameters.cpp000644 000765 000024 00000003354 12154705401 020615 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Parameters.h" #include #include #include namespace // unnamed { typedef std::map ParametersCollection; ParametersCollection parameters_; } // unnamed namespace namespace Vera { namespace Plugins { void Parameters::set(const ParamAssoc & assoc) { std::string::size_type pos = assoc.find("="); if (pos != std::string::npos) { ParamName name = assoc.substr(0, pos); ParamValue value = assoc.substr(pos + 1); parameters_[name] = value; } else { std::ostringstream ss; ss << "Invalid parameter association: " << assoc; throw ParametersError(ss.str()); } } Parameters::ParamValue Parameters::get(const ParamName & name, const ParamValue & defaultValue) { ParametersCollection::iterator it = parameters_.find(name); if (it != parameters_.end()) { return it->second; } else { return defaultValue; } } void Parameters::readFromFile(const FileName & name) { std::ifstream file(name.c_str()); if (file.is_open() == false) { std::ostringstream ss; ss << "cannot open parameters file " << name; throw ParametersError(ss.str()); } std::string line; int lineNumber = 0; while (getline(file, line)) { ++lineNumber; if (line.empty()) { continue; } if (line[0] != '#') { set(line); } } } } } vera++-1.2.1/src/plugins/Parameters.h000644 000765 000024 00000001630 12125131507 020253 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef PARAMETERS_H_INCLUDED #define PARAMETERS_H_INCLUDED #include #include namespace Vera { namespace Plugins { class ParametersError : public std::runtime_error { public: ParametersError(const std::string & msg) : std::runtime_error(msg) {} }; class Parameters { public: typedef std::string ParamName; typedef std::string ParamValue; typedef std::string ParamAssoc; typedef std::string FileName; static void set(const ParamAssoc & assoc); static void readFromFile(const FileName & name); static ParamValue get(const ParamName & name, const ParamValue & defaultValue); }; } // namespace Plugins } // namespace Vera #endif // PARAMETERS_H_INCLUDED vera++-1.2.1/src/plugins/Profiles.cpp000644 000765 000024 00000003643 12154705401 020276 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Profiles.h" #include "Rules.h" #include "RootDirectory.h" #include "cpptcl-1.1.4/cpptcl.h" #include #include #include #include #include #include namespace // unnamed { typedef std::vector RuleNameCollection; RuleNameCollection getListOfScriptNames(const Vera::Plugins::Profiles::ProfileName & profile) { RuleNameCollection allRules; // name of the profile is also the name of the profile file const Vera::Plugins::RootDirectory::DirectoryName veraRoot = Vera::Plugins::RootDirectory::getRootDirectory(); std::string fileName(veraRoot + "/profiles/"); fileName += profile; std::ifstream profileFile(fileName.c_str()); if (profileFile.is_open() == false) { std::ostringstream ss; ss << "cannot open profile description for profile " << profile; throw Vera::Plugins::ProfileError(ss.str()); } Tcl::interpreter interp; interp.eval(profileFile); const Tcl::object ruleList = interp.eval("set rules"); const size_t ruleListLength = ruleList.length(interp); for (size_t i = 0; i != ruleListLength; ++i) { const Vera::Plugins::Rules::RuleName rName = ruleList.at(interp, i).get(); allRules.push_back(rName); } return allRules; } } // unnamed namespace namespace Vera { namespace Plugins { void Profiles::executeProfile(const ProfileName & profile) { const RuleNameCollection scripts = getListOfScriptNames(profile); typedef RuleNameCollection::const_iterator iterator; const iterator end = scripts.end(); for (iterator it = scripts.begin(); it != end; ++it) { Rules::executeRule(*it); } } } } vera++-1.2.1/src/plugins/Profiles.h000644 000765 000024 00000001242 12125131507 017732 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef PROFILES_H_INCLUDED #define PROFILES_H_INCLUDED #include #include namespace Vera { namespace Plugins { class ProfileError : public std::runtime_error { public: ProfileError(const std::string & msg) : std::runtime_error(msg) {} }; class Profiles { public: typedef std::string ProfileName; static void executeProfile(const ProfileName & name); }; } // namespace Plugins } // namespace Vera #endif // PROFILES_H_INCLUDED vera++-1.2.1/src/plugins/Reports.cpp000644 000765 000024 00000023606 12144542562 020160 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Reports.h" #include "Rules.h" #include #include #include namespace // unnamed { // for a single report typedef std::pair SingleReport; // for a single file (line number -> single report) typedef std::multimap FileMessagesCollection; // for all reports typedef std::map MessagesCollection; MessagesCollection messages_; bool showRules_; bool vcFormat_; bool xmlReport_; std::string prefix_; } // unnamed namespace namespace Vera { namespace Plugins { void Reports::setShowRules(bool show) { showRules_ = show; } void Reports::setXMLReport(bool xmlReport) { xmlReport_ = xmlReport; } void Reports::setVCFormat(bool vc) { vcFormat_ = vc; } void Reports::setPrefix(std::string prefix) { prefix_ = prefix; } int Reports::count() { return messages_.size(); } void Reports::add(const FileName & name, int lineNumber, const Message & msg) { const Rules::RuleName currentRule = Rules::getCurrentRule(); messages_[name].insert(make_pair(lineNumber, make_pair(currentRule, msg))); } void Reports::dumpAll(std::ostream & os, bool omitDuplicates) { if (xmlReport_) { dumpAllXML(os, omitDuplicates); } else { dumpAllNormal(os, omitDuplicates); } } void Reports::dumpAllNormal(std::ostream & os, bool omitDuplicates) { for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end(); it != end; ++it) { const FileName & name = it->first; FileMessagesCollection & fileMessages = it->second; FileMessagesCollection::iterator fit = fileMessages.begin(); FileMessagesCollection::iterator fend = fileMessages.end(); int lastLineNumber = 0; SingleReport lastReport; for ( ; fit != fend; ++fit) { int lineNumber = fit->first; const SingleReport & report = fit->second; const Rules::RuleName & rule = report.first; const Message & msg = report.second; if (omitDuplicates == false || lineNumber != lastLineNumber || report != lastReport) { if (showRules_) { if (vcFormat_) { os << name << '(' << lineNumber << ") : " << '(' << rule << ") " << msg << '\n'; } else { os << name << ':' << lineNumber << ": " << '(' << rule << ") " << msg << '\n'; } } else { if (vcFormat_) { os << name << '(' << lineNumber << ") : " << msg << '\n'; } else { os << name << ':' << lineNumber << ": " << msg << '\n'; } } lastLineNumber = lineNumber; lastReport = report; } } } } void Reports::dumpAllXML(std::ostream & os, bool omitDuplicates) { writeXml(os, omitDuplicates); } void Reports::writeStd(std::ostream & os, bool omitDuplicates) { for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end(); it != end; ++it) { const FileName & name = it->first; FileMessagesCollection & fileMessages = it->second; FileMessagesCollection::iterator fit = fileMessages.begin(); FileMessagesCollection::iterator fend = fileMessages.end(); int lastLineNumber = 0; SingleReport lastReport; for ( ; fit != fend; ++fit) { int lineNumber = fit->first; const SingleReport & report = fit->second; const Rules::RuleName & rule = report.first; const Message & msg = report.second; if (omitDuplicates == false || lineNumber != lastLineNumber || report != lastReport) { os << name; os << ':' << lineNumber << ":"; if (prefix_ != "") { os << " " << prefix_; } if (showRules_) { os << " " << rule; } if (showRules_ || prefix_ != "") { os << ":"; } os << " " << msg << std::endl; lastLineNumber = lineNumber; lastReport = report; } } } } void Reports::writeVc(std::ostream & os, bool omitDuplicates) { for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end(); it != end; ++it) { const FileName & name = it->first; FileMessagesCollection & fileMessages = it->second; FileMessagesCollection::iterator fit = fileMessages.begin(); FileMessagesCollection::iterator fend = fileMessages.end(); int lastLineNumber = 0; SingleReport lastReport; for ( ; fit != fend; ++fit) { int lineNumber = fit->first; const SingleReport & report = fit->second; const Rules::RuleName & rule = report.first; const Message & msg = report.second; if (omitDuplicates == false || lineNumber != lastLineNumber || report != lastReport) { os << name; os << '(' << lineNumber << "):"; if (prefix_ != "") { os << " " << prefix_; } if (showRules_) { os << " " << rule; } if (showRules_ || prefix_ != "") { os << ":"; } os << " " << msg << std::endl; lastLineNumber = lineNumber; lastReport = report; } } } } void Reports::writeXml(std::ostream & os, bool omitDuplicates) { os<< "" << std::endl; os << "\n"; for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end(); it != end; ++it) { const FileName & name = it->first; os << " \n"; FileMessagesCollection & fileMessages = it->second; FileMessagesCollection::iterator fit = fileMessages.begin(); FileMessagesCollection::iterator fend = fileMessages.end(); int lastLineNumber = 0; SingleReport lastReport; for ( ; fit != fend; ++fit) { int lineNumber = fit->first; const SingleReport & report = fit->second; const Rules::RuleName & rule = report.first; const Message & msg = report.second; if (omitDuplicates == false || lineNumber != lastLineNumber || report != lastReport) { if (showRules_) { os << " ![CDATA[" << msg << "]]\n"; } else { os << " ![CDATA[" << msg << "]]\n"; } lastLineNumber = lineNumber; lastReport = report; } } os << " \n"; } os << "\n"; } void Reports::writeCheckStyle(std::ostream & os, bool omitDuplicates) { std::string severity = prefix_; if (severity == "") { severity = "info"; } os<< "" << std::endl; os << "\n"; for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end(); it != end; ++it) { const FileName & name = it->first; os << " \n"; FileMessagesCollection & fileMessages = it->second; FileMessagesCollection::iterator fit = fileMessages.begin(); FileMessagesCollection::iterator fend = fileMessages.end(); int lastLineNumber = 0; SingleReport lastReport; for ( ; fit != fend; ++fit) { int lineNumber = fit->first; const SingleReport & report = fit->second; const Rules::RuleName & rule = report.first; const Message & msg = report.second; if (omitDuplicates == false || lineNumber != lastLineNumber || report != lastReport) { os << " \n"; lastLineNumber = lineNumber; lastReport = report; } } os << " \n"; } os << "\n"; } std::string Reports::xmlEscape(const std::string & msg) { std::string res = msg; boost::algorithm::replace_all(res, "&", "&"); boost::algorithm::replace_all(res, "\"", """); boost::algorithm::replace_all(res, "\'", "'"); boost::algorithm::replace_all(res, "<", "<"); boost::algorithm::replace_all(res, ">", ">"); return res; } } } vera++-1.2.1/src/plugins/Reports.h000644 000765 000024 00000002511 12144542562 017615 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef REPORTS_H_INCLUDED #define REPORTS_H_INCLUDED #include "Reports.h" #include #include namespace Vera { namespace Plugins { class Reports { public: typedef std::string FileName; typedef std::string Message; static void setShowRules(bool show); static void setVCFormat(bool vc); static void setXMLReport(bool xmlReport); static void setPrefix(std::string prefix); static int count(); static void add(const FileName & name, int lineNumber, const Message & msg); static void dumpAll(std::ostream & os, bool omitDuplicates); static void writeStd(std::ostream & os, bool omitDuplicates); static void writeVc(std::ostream & os, bool omitDuplicates); static void writeXml(std::ostream & os, bool omitDuplicates); static void writeCheckStyle(std::ostream & os, bool omitDuplicates); private: static void dumpAllNormal(std::ostream & os, bool omitDuplicates); static void dumpAllXML(std::ostream & os, bool omitDuplicates); static std::string xmlEscape(const std::string & msg); }; } // namespace Plugins } // namespace Vera #endif // REPORTS_H_INCLUDED vera++-1.2.1/src/plugins/RootDirectory.cpp000644 000765 000024 00000001046 12135262772 021326 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "RootDirectory.h" namespace // unnamed { Vera::Plugins::RootDirectory::DirectoryName root_; } // unnamed namespace namespace Vera { namespace Plugins { void RootDirectory::setRootDirectory(const DirectoryName & name) { root_ = name; } RootDirectory::DirectoryName RootDirectory::getRootDirectory() { return root_; } } } vera++-1.2.1/src/plugins/RootDirectory.h000644 000765 000024 00000001121 12125131507 020753 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef ROOTDIRECTORY_H_INCLUDED #define ROOTDIRECTORY_H_INCLUDED #include namespace Vera { namespace Plugins { class RootDirectory { public: typedef std::string DirectoryName; static void setRootDirectory(const DirectoryName & name); static DirectoryName getRootDirectory(); }; } // namespace Plugins } // namespace Vera #endif // ROOTDIRECTORY_H_INCLUDED vera++-1.2.1/src/plugins/Rules.cpp000644 000765 000024 00000001356 12135763242 017612 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Rules.h" #include "RootDirectory.h" #include "Interpreter.h" namespace // unnamed { Vera::Plugins::Rules::RuleName currentRule_; } // unnamed namespace namespace Vera { namespace Plugins { void Rules::executeRule(const RuleName & name) { currentRule_ = name; const Vera::Plugins::RootDirectory::DirectoryName veraRoot = Vera::Plugins::RootDirectory::getRootDirectory(); Interpreter::execute(veraRoot, Interpreter::rule, name); } Rules::RuleName Rules::getCurrentRule() { return currentRule_; } } } vera++-1.2.1/src/plugins/Rules.h000644 000765 000024 00000001032 12125131507 017236 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef RULES_H_INCLUDED #define RULES_H_INCLUDED #include namespace Vera { namespace Plugins { class Rules { public: typedef std::string RuleName; static void executeRule(const RuleName & name); static RuleName getCurrentRule(); }; } // namespace Plugins } // namespace Vera #endif // RULES_H_INCLUDED vera++-1.2.1/src/plugins/Transformations.cpp000644 000765 000024 00000001067 12135263246 021707 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Transformations.h" #include "RootDirectory.h" #include "Interpreter.h" namespace Vera { namespace Plugins { void Transformations::executeTransformation(const TransformationName & name) { const RootDirectory::DirectoryName veraRoot = RootDirectory::getRootDirectory(); Interpreter::execute(veraRoot, Interpreter::transformation, name); } } } vera++-1.2.1/src/plugins/Transformations.h000644 000765 000024 00000001072 12125131507 021341 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef TRANSFORMATIONS_H_INCLUDED #define TRANSFORMATIONS_H_INCLUDED #include namespace Vera { namespace Plugins { class Transformations { public: typedef std::string TransformationName; static void executeTransformation(const TransformationName & name); }; } // namespace Plugins } // namespace Vera #endif // TRANSFORMATIONS_H_INCLUDED vera++-1.2.1/src/structures/SourceFiles.cpp000644 000765 000024 00000001226 12135263342 021475 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "SourceFiles.h" namespace // unnamed { Vera::Structures::SourceFiles::FileNameSet files_; } // unnamed namespace namespace Vera { namespace Structures { int SourceFiles::count() { return files_.size(); } void SourceFiles::addFileName(const FileName & name) { files_.insert(name); } bool SourceFiles::empty() { return files_.empty(); } const SourceFiles::FileNameSet & SourceFiles::getAllFileNames() { return files_; } } } vera++-1.2.1/src/structures/SourceFiles.h000644 000765 000024 00000001603 12135761564 021152 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef SOURCEFILES_H_INCLUDED #define SOURCEFILES_H_INCLUDED #include #include #include namespace Vera { namespace Structures { class SourceFileError : public std::runtime_error { public: SourceFileError(const std::string & msg) : std::runtime_error(msg) {} }; class SourceFiles { public: typedef std::string FileName; typedef std::set FileNameSet; typedef FileNameSet::const_iterator iterator; static void addFileName(const FileName & name); static bool empty(); static int count(); static const FileNameSet & getAllFileNames(); }; } // namespace Structures } // namespace Vera #endif // SOURCEFILES_H_INCLUDED vera++-1.2.1/src/structures/SourceLines.cpp000644 000765 000024 00000005130 12154705401 021501 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "SourceLines.h" #include "Tokens.h" #include "../plugins/Reports.h" #include #include #include #include namespace // unnamed { typedef std::map SourceFileCollection; SourceFileCollection sources_; } // unnamed namespace namespace Vera { namespace Structures { const SourceLines::LineCollection & SourceLines::getAllLines(const SourceFiles::FileName & name) { const SourceFileCollection::const_iterator it = sources_.find(name); if (it != sources_.end()) { return it->second; } else { // lazy load of the source file loadFile(name); return sources_[name]; } } void SourceLines::loadFile(const SourceFiles::FileName & name) { if (name == "-") { SourceLines::loadFile(std::cin, name); } else { std::ifstream file(name.c_str()); if (file.is_open() == false) { std::ostringstream ss; ss << "cannot open source file " << name; throw SourceFileError(ss.str()); } SourceLines::loadFile(file, name); } } void SourceLines::loadFile(std::istream & file, const SourceFiles::FileName & name) { LineCollection & lines = sources_[name]; std::string line; Tokens::FileContent fullSource; while (getline(file, line)) { lines.push_back(line); fullSource += line; // built-in rule if (file.eof()) { Plugins::Reports::add(name, static_cast(lines.size()), "no newline at end of file"); } else { fullSource += '\n'; } } Tokens::parse(name, fullSource); } int SourceLines::getLineCount(const SourceFiles::FileName & name) { return static_cast(getAllLines(name).size()); } const std::string & SourceLines::getLine(const SourceFiles::FileName & name, int lineNumber) { const LineCollection & lines = getAllLines(name); if (lineNumber < 1 || lineNumber > static_cast(lines.size())) { std::cerr << "Requested wrong line number: " << lineNumber << '\n'; std::cerr << "lines.size in " << name << " is " << static_cast(lines.size()) << '\n'; throw SourceFileError("requested line number is out of range"); } return lines[lineNumber - 1]; } } } vera++-1.2.1/src/structures/SourceLines.h000644 000765 000024 00000001637 12140232137 021152 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef SOURCELINES_H_INCLUDED #define SOURCELINES_H_INCLUDED #include "SourceFiles.h" #include #include namespace Vera { namespace Structures { class SourceLines { public: typedef std::vector LineCollection; static const LineCollection & getAllLines(const SourceFiles::FileName & name); static int getLineCount(const SourceFiles::FileName & name); static const std::string & getLine(const SourceFiles::FileName & name, int lineNumber); static void loadFile(const SourceFiles::FileName & name); static void loadFile(std::istream & file, const SourceFiles::FileName & name); }; } // namespace Structures } // namespace Vera #endif // SOURCELINES_H_INCLUDED vera++-1.2.1/src/structures/Tokens.cpp000644 000765 000024 00000052632 12154350323 020521 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include "Tokens.h" #include "SourceLines.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace // unnamed { typedef std::vector PhysicalTokenCollection; PhysicalTokenCollection physicalTokens; struct TokenRef { TokenRef(boost::wave::token_id id, int line, int column, int length) : id_(id), line_(line), column_(column), length_(length), index_(-1) {} TokenRef(boost::wave::token_id id, int line, int column, int length, const std::string & value) : id_(id), line_(line), column_(column), length_(length) { // newline is optimized as the most common case if (id_ != boost::wave::T_NEWLINE) { // value of the token is stored in physicalTokens collection // (because it has no physical representation in the source code) index_ = static_cast(physicalTokens.size()); physicalTokens.push_back(value); } } std::string getTokenValue(const Vera::Structures::SourceFiles::FileName & fileName) const { if (id_ == boost::wave::T_NEWLINE) { return "\n"; } else if (index_ >= 0) { // token value stored in the physicalTokens structure // (this is used with line continuation and other cases // where the token has no representation in physical lines) return physicalTokens[static_cast(index_)]; } else { // token value has to be retrieved from the physical line collection return Vera::Structures::SourceLines::getLine(fileName, line_).substr(column_, length_); } } boost::wave::token_id id_; int line_; int column_; int length_; // if >= 0, it is the index into the physicalTokens collection, // used only for line continuation // and when line_ and column_ do not reflect the physical layout: int index_; }; typedef std::vector TokenCollection; typedef std::map FileTokenCollection; FileTokenCollection fileTokens_; typedef std::vector > CompiledFilterSequence; boost::wave::token_id tokenIdFromTokenFilter(const Vera::Structures::Tokens::TokenFilter & filter) { typedef std::map TokenFilterToIdMap; static TokenFilterToIdMap tokenMap; if (tokenMap.empty()) { tokenMap["and"] = static_cast(256); tokenMap["andand"] = static_cast(257); tokenMap["assign"] = static_cast(258); tokenMap["andassign"] = static_cast(259); tokenMap["or"] = static_cast(260); tokenMap["orassign"] = static_cast(261); tokenMap["xor"] = static_cast(262); tokenMap["xorassign"] = static_cast(263); tokenMap["comma"] = static_cast(264); tokenMap["colon"] = static_cast(265); tokenMap["divide"] = static_cast(266); tokenMap["divideassign"] = static_cast(267); tokenMap["dot"] = static_cast(268); tokenMap["dotstar"] = static_cast(269); tokenMap["ellipsis"] = static_cast(270); tokenMap["equal"] = static_cast(271); tokenMap["greater"] = static_cast(272); tokenMap["greaterequal"] = static_cast(273); tokenMap["leftbrace"] = static_cast(274); tokenMap["less"] = static_cast(275); tokenMap["lessequal"] = static_cast(276); tokenMap["leftparen"] = static_cast(277); tokenMap["leftbracket"] = static_cast(278); tokenMap["minus"] = static_cast(279); tokenMap["minusassign"] = static_cast(280); tokenMap["minusminus"] = static_cast(281); tokenMap["percent"] = static_cast(282); tokenMap["percentassign"] = static_cast(283); tokenMap["not"] = static_cast(284); tokenMap["notequal"] = static_cast(285); tokenMap["oror"] = static_cast(286); tokenMap["plus"] = static_cast(287); tokenMap["plusassign"] = static_cast(288); tokenMap["plusplus"] = static_cast(289); tokenMap["arrow"] = static_cast(290); tokenMap["arrowstar"] = static_cast(291); tokenMap["question_mark"] = static_cast(292); tokenMap["rightbrace"] = static_cast(293); tokenMap["rightparen"] = static_cast(294); tokenMap["rightbracket"] = static_cast(295); tokenMap["colon_colon"] = static_cast(296); tokenMap["semicolon"] = static_cast(297); tokenMap["shiftleft"] = static_cast(298); tokenMap["shiftleftassign"] = static_cast(299); tokenMap["shiftright"] = static_cast(300); tokenMap["shiftrightassign"] = static_cast(301); tokenMap["star"] = static_cast(302); tokenMap["compl"] = static_cast(303); tokenMap["starassign"] = static_cast(304); tokenMap["asm"] = static_cast(305); tokenMap["auto"] = static_cast(306); tokenMap["bool"] = static_cast(307); tokenMap["false"] = static_cast(308); tokenMap["true"] = static_cast(309); tokenMap["break"] = static_cast(310); tokenMap["case"] = static_cast(311); tokenMap["catch"] = static_cast(312); tokenMap["char"] = static_cast(313); tokenMap["class"] = static_cast(314); tokenMap["const"] = static_cast(315); tokenMap["constcast"] = static_cast(316); tokenMap["continue"] = static_cast(317); tokenMap["default"] = static_cast(318); tokenMap["delete"] = static_cast(319); tokenMap["do"] = static_cast(320); tokenMap["double"] = static_cast(321); tokenMap["dynamiccast"] = static_cast(322); tokenMap["else"] = static_cast(323); tokenMap["enum"] = static_cast(324); tokenMap["explicit"] = static_cast(325); tokenMap["export"] = static_cast(326); tokenMap["extern"] = static_cast(327); tokenMap["float"] = static_cast(328); tokenMap["for"] = static_cast(329); tokenMap["friend"] = static_cast(330); tokenMap["goto"] = static_cast(331); tokenMap["if"] = static_cast(332); tokenMap["inline"] = static_cast(333); tokenMap["int"] = static_cast(334); tokenMap["long"] = static_cast(335); tokenMap["mutable"] = static_cast(336); tokenMap["namespace"] = static_cast(337); tokenMap["new"] = static_cast(338); tokenMap["operator"] = static_cast(339); tokenMap["private"] = static_cast(340); tokenMap["protected"] = static_cast(341); tokenMap["public"] = static_cast(342); tokenMap["register"] = static_cast(343); tokenMap["reinterpretcast"] = static_cast(344); tokenMap["return"] = static_cast(345); tokenMap["short"] = static_cast(346); tokenMap["signed"] = static_cast(347); tokenMap["sizeof"] = static_cast(348); tokenMap["static"] = static_cast(349); tokenMap["staticcast"] = static_cast(350); tokenMap["struct"] = static_cast(351); tokenMap["switch"] = static_cast(352); tokenMap["template"] = static_cast(353); tokenMap["this"] = static_cast(354); tokenMap["throw"] = static_cast(355); tokenMap["try"] = static_cast(356); tokenMap["typedef"] = static_cast(357); tokenMap["typeid"] = static_cast(358); tokenMap["typename"] = static_cast(359); tokenMap["union"] = static_cast(360); tokenMap["unsigned"] = static_cast(361); tokenMap["using"] = static_cast(362); tokenMap["virtual"] = static_cast(363); tokenMap["void"] = static_cast(364); tokenMap["volatile"] = static_cast(365); tokenMap["wchart"] = static_cast(366); tokenMap["while"] = static_cast(367); tokenMap["pp_define"] = static_cast(368); tokenMap["pp_if"] = static_cast(369); tokenMap["pp_ifdef"] = static_cast(370); tokenMap["pp_ifndef"] = static_cast(371); tokenMap["pp_else"] = static_cast(372); tokenMap["pp_elif"] = static_cast(373); tokenMap["pp_endif"] = static_cast(374); tokenMap["pp_error"] = static_cast(375); tokenMap["pp_line"] = static_cast(376); tokenMap["pp_pragma"] = static_cast(377); tokenMap["pp_undef"] = static_cast(378); tokenMap["pp_warning"] = static_cast(379); tokenMap["identifier"] = static_cast(380); tokenMap["octalint"] = static_cast(381); tokenMap["decimalint"] = static_cast(382); tokenMap["hexaint"] = static_cast(383); tokenMap["intlit"] = static_cast(384); tokenMap["longintlit"] = static_cast(385); tokenMap["floatlit"] = static_cast(386); tokenMap["ccomment"] = static_cast(387); tokenMap["cppcomment"] = static_cast(388); tokenMap["charlit"] = static_cast(389); tokenMap["stringlit"] = static_cast(390); tokenMap["contline"] = static_cast(391); tokenMap["space"] = static_cast(392); tokenMap["space2"] = static_cast(393); tokenMap["newline"] = static_cast(394); tokenMap["pound_pound"] = static_cast(395); tokenMap["pound"] = static_cast(396); tokenMap["any"] = static_cast(397); tokenMap["pp_include"] = static_cast(398); tokenMap["pp_qheader"] = static_cast(399); tokenMap["pp_hheader"] = static_cast(400); tokenMap["eof"] = static_cast(401); tokenMap["eoi"] = static_cast(402); tokenMap["pp_number"] = static_cast(403); tokenMap["msext_int8"] = static_cast(404); tokenMap["msext_int16"] = static_cast(405); tokenMap["msext_int32"] = static_cast(406); tokenMap["msext_int64"] = static_cast(407); tokenMap["msext_based"] = static_cast(408); tokenMap["msext_declspec"] = static_cast(409); tokenMap["msext_cdecl"] = static_cast(410); tokenMap["msext_fastcall"] = static_cast(411); tokenMap["msext_stdcall"] = static_cast(412); tokenMap["msext_try"] = static_cast(413); tokenMap["msext_except"] = static_cast(414); tokenMap["msext_finally"] = static_cast(415); tokenMap["msext_leave"] = static_cast(416); tokenMap["msext_inline"] = static_cast(417); tokenMap["msext_asm"] = static_cast(418); tokenMap["msext_region"] = static_cast(419); tokenMap["msext_endregion"] = static_cast(420); tokenMap["import"] = static_cast(421); } const TokenFilterToIdMap::const_iterator it = tokenMap.find(filter); if (it != tokenMap.end()) { return it->second; } else { throw Vera::Structures::TokensError("unknown token filter requested"); } } bool matchAll(boost::wave::token_id) { return true; } bool matchTokenBaseId(boost::wave::token_id id, boost::wave::token_id ref) { return BASEID_FROM_TOKEN(id) == ref; } CompiledFilterSequence prepareCompiledFilter( const Vera::Structures::Tokens::FilterSequence & filterSeq) { CompiledFilterSequence ret; if (filterSeq.empty()) { // with empty filter all tokens should be accepted ret.push_back(matchAll); } else { Vera::Structures::Tokens::FilterSequence::const_iterator it = filterSeq.begin(); const Vera::Structures::Tokens::FilterSequence::const_iterator end = filterSeq.end(); for ( ; it != end; ++it) { ret.push_back(bind(matchTokenBaseId, _1, tokenIdFromTokenFilter(*it))); } } return ret; } bool match(const CompiledFilterSequence & compiledFilter, boost::wave::token_id id) { CompiledFilterSequence::const_iterator it = compiledFilter.begin(); const CompiledFilterSequence::const_iterator end = compiledFilter.end(); for ( ; it != end; ++it) { if ((*it)(id)) { return true; } } return false; } struct LineNumberComparator { bool operator()(const TokenRef & left, const TokenRef & right) const { return left.line_ < right.line_; } }; void findRange(const TokenCollection & tokens, int fromLine, int toLine, TokenCollection::const_iterator & beg, TokenCollection::const_iterator & end) { const TokenRef tokenToCompareFrom(boost::wave::token_id(), fromLine, 0, 0); beg = lower_bound(tokens.begin(), tokens.end(), tokenToCompareFrom, LineNumberComparator()); if (toLine < 0) { end = tokens.end(); } else { const TokenRef tokenToCompareTo(boost::wave::token_id(), toLine, 0, 0); end = upper_bound(tokens.begin(), tokens.end(), tokenToCompareTo, LineNumberComparator()); } } } // unnamed namespace namespace Vera { namespace Structures { void Tokens::parse(const SourceFiles::FileName & name, const FileContent & src) { TokenCollection & tokensInFile = fileTokens_[name]; // wave throws exceptions when given an empty file if (src.empty() == false) { try { typedef boost::wave::cpplexer::lex_token<> token_type; typedef boost::wave::cpplexer::lex_iterator lexer_type; typedef token_type::position_type position_type; const position_type pos(name.c_str()); lexer_type it = lexer_type(src.begin(), src.end(), pos, boost::wave::language_support( boost::wave::support_cpp | boost::wave::support_option_long_long)); const lexer_type end = lexer_type(); const int lineCount = SourceLines::getLineCount(name); for ( ; it != end; ++it) { const boost::wave::token_id id(*it); const token_type::position_type pos = it->get_position(); const std::string value = it->get_value().c_str(); const int line = pos.get_line(); const int column = pos.get_column() - 1; const int length = static_cast(value.size()); bool useReference = true; if (id == boost::wave::T_NEWLINE || id == boost::wave::T_EOF || line > lineCount) { useReference = false; } else { const std::string & sourceLine = SourceLines::getLine(name, line); if (column > static_cast(sourceLine.size()) || value != sourceLine.substr(column, length)) { useReference = false; } } if (useReference) { // the reference representation of the token is stored tokensInFile.push_back(TokenRef(id, line, column, length)); } else { // value of the token has no representation in the physical line // so the real token value is stored in physicalTokens tokensInFile.push_back(TokenRef(id, line, column, length, value)); } } } catch (const boost::wave::cpplexer::cpplexer_exception & e) { std::ostringstream ss; ss << name << ':' << e.line_no() << ": illegal token in column " << e.column_no() << ", giving up (hint: fix the file or remove it from the working set)"; throw TokensError(ss.str()); } } } Tokens::TokenSequence Tokens::getTokens(const SourceFiles::FileName & fileName, int fromLine, int fromColumn, int toLine, int toColumn, const FilterSequence & filter) { if ((fromLine < 1) || (fromColumn < 0) || (toLine > 0 && fromLine > toLine) || (fromLine == toLine && toColumn >= 0 && fromColumn > toColumn)) { throw TokensError("illegal range of tokens requested by the script"); } { // lazy load and parse const FileTokenCollection::const_iterator fit = fileTokens_.find(fileName); if (fit == fileTokens_.end()) { SourceLines::loadFile(fileName); } } // here we know that the file is already loaded and parsed // (or the exception was thrown in the above) const CompiledFilterSequence compiledFilter = prepareCompiledFilter(filter); const TokenCollection & tokensInFile = fileTokens_[fileName]; TokenSequence ret; TokenCollection::const_iterator begin; TokenCollection::const_iterator end; findRange(tokensInFile, fromLine, toLine, begin, end); for (TokenCollection::const_iterator it = begin; it != end; ++it) { const TokenRef & token = *it; const int line = token.line_; const int column = token.column_; if ((line > fromLine || (line == fromLine && column >= fromColumn)) && (toLine <= 0 || (line < toLine || (line == toLine && column < toColumn)))) { if (match(compiledFilter, token.id_)) { std::string tokenName = boost::wave::get_token_name(token.id_).c_str(); boost::algorithm::to_lower(tokenName); std::string value; if (tokenName != "eof") { value = token.getTokenValue(fileName); } ret.push_back(SingleToken(value, line, column, tokenName)); } } } return ret; } } } vera++-1.2.1/src/structures/Tokens.h000644 000765 000024 00000002442 12154350323 020160 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef TOKENS_H_INCLUDED #define TOKENS_H_INCLUDED #include "SourceFiles.h" #include #include namespace Vera { namespace Structures { class TokensError : public std::runtime_error { public: TokensError(const std::string & msg) : std::runtime_error(msg) {} }; class Tokens { public: typedef std::string FileContent; struct SingleToken { SingleToken(const std::string & v, int ln, int cl, const std::string & n) : value_(v), line_(ln), column_(cl), name_(n) {} std::string value_; int line_; int column_; std::string name_; }; typedef std::vector TokenSequence; typedef std::string TokenFilter; typedef std::vector FilterSequence; static void parse(const SourceFiles::FileName & name, const FileContent & src); static TokenSequence getTokens(const SourceFiles::FileName & name, int fromLine, int fromColumn, int toLine, int toColumn, const FilterSequence & filter); }; } // namespace Structures } // namespace Vera #endif // TOKENS_H_INCLUDED vera++-1.2.1/tests/CMakeLists.txt000644 000765 000024 00000041114 12154705401 017434 0ustar00glehmannstaff000000 000000 # just to show a way to use vera++ file(GLOB_RECURSE srcs ${CMAKE_SOURCE_DIR}/src/*.cpp ${CMAKE_SOURCE_DIR}/src/*.h) add_test(NAME VeraStyle COMMAND vera --error --root "${CMAKE_SOURCE_DIR}" ${srcs} ) # now the real tests include(${CMAKE_SOURCE_DIR}/cmake/use_vera++.cmake) ####### command line iterface tests ####### # this test is supposed to not found the vera root dir and fail because of that, # but it will found one if vera has already been installed, so we don't run # it in that case. if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/lib/vera++/") vera_add_test(NoRoot "" "" "error: cannot open profile description for profile default\n" 1 "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp" ) endif() vera_add_test(VeraRootEnvironment "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) set_tests_properties(VeraRootEnvironment PROPERTIES ENVIRONMENT "VERA_ROOT=${CMAKE_SOURCE_DIR}") vera_add_test(VeraRootCurrentDirectory "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) set_tests_properties(VeraRootCurrentDirectory PROPERTIES WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") vera_add_test(VeraLegacy "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" 0 ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) set_tests_properties(VeraLegacy PROPERTIES ENVIRONMENT "VERA_LEGACY=ON;VERA_ROOT=${CMAKE_SOURCE_DIR}") vera_add_test(StdInNoArgs "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp\n" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" ) vera_add_test(InputsDash "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp\n" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --inputs=- ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/inputs "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp\n") vera_add_test(InputsFile "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --inputs=${CMAKE_CURRENT_BINARY_DIR}/inputs ) vera_add_test(ShortInputs "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp\n" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" -i - ) vera_add_test_stdin_file(StdInDash "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp" "-:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" - ) vera_add_test(StandardReport "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --std-report=- ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortStandardReport "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" -o - ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(VCReport "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp(1): no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --vc-report=- ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortVCReport "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp(1): no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" -v - ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(XMLReport "" " ![CDATA[no copyright notice found]] \n" "" 0 --root "${CMAKE_SOURCE_DIR}" --xml-report=- ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortXMLReport "" " ![CDATA[no copyright notice found]] \n" "" 0 --root "${CMAKE_SOURCE_DIR}" -x - ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(CheckStyleReport "" " \n" "" 0 --root "${CMAKE_SOURCE_DIR}" --checkstyle-report=- ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortCheckStyleReport "" " \n" "" 0 --root "${CMAKE_SOURCE_DIR}" -c - ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShowRule "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: T013: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --show-rule ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortShowRule "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: T013: no copyright notice found\n" "" 0 --root "${CMAKE_SOURCE_DIR}" -s ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(Warning "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: warning: no copyright notice found\n" 0 --root "${CMAKE_SOURCE_DIR}" --warning ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortWarning "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: warning: no copyright notice found\n" 0 --root "${CMAKE_SOURCE_DIR}" -w ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(WarningShowRule "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: warning T013: no copyright notice found\n" 0 --root "${CMAKE_SOURCE_DIR}" --warning --show-rule ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(Error "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: error: no copyright notice found\n" 1 --root "${CMAKE_SOURCE_DIR}" --error ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ErrorShowRule "" "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: error T013: no copyright notice found\n" 1 --root "${CMAKE_SOURCE_DIR}" --error --show-rule ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(Quiet "" "" "" 0 --root "${CMAKE_SOURCE_DIR}" --quiet ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortQuiet "" "" "" 0 --root "${CMAKE_SOURCE_DIR}" -q ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(Summary "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "1 reports in 1 files.\n" 0 --root "${CMAKE_SOURCE_DIR}" --summary ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(ShortSummary "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "1 reports in 1 files.\n" 0 --root "${CMAKE_SOURCE_DIR}" -S ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(Version "" "${VERA_VERSION}\n" "" 0 --version ) vera_add_test(VersionLegacy "" "${VERA_VERSION}\n" "" 0 -version ) vera_add_test(AggregatedShortOptions "" "" "1 reports in 1 files.\n" 1 -eSqpdefault -r "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera_add_test(NoDuplicate "" "${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:10: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:12: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:13: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:14: comma should not be preceded by whitespace\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --rule T009 --no-duplicate ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp ) vera_add_test(ShortNoDuplicate "" "${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:10: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:12: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:13: comma should not be preceded by whitespace ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp:14: comma should not be preceded by whitespace\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --rule T009 -d ${CMAKE_CURRENT_SOURCE_DIR}/T009.cpp ) vera_add_test(Parameter "" "${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: line is longer than 99 characters ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:2: line is longer than 99 characters\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --rule L004 --parameter max-line-length=99 ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp ) vera_add_test(ShortParameter "" "${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: line is longer than 99 characters ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:2: line is longer than 99 characters\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --rule L004 -P max-line-length=99 ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp ) vera_add_test(Parameters "" "${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: line is longer than 99 characters ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:2: line is longer than 99 characters\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --rule L004 --parameters ${CMAKE_CURRENT_SOURCE_DIR}/parameters.txt ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp ) vera_add_test(Profile "" "${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: L004: line is longer than 100 characters ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: T013: no copyright notice found ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: T014: no reference to the Boost Software License found ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:2: L004: line is longer than 100 characters\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --show-rule --profile full --parameter max-directory-depth=20 ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp ) vera_add_test(ShortProfile "" "${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: L004: line is longer than 100 characters ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: T013: no copyright notice found ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:1: T014: no reference to the Boost Software License found ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp:2: L004: line is longer than 100 characters\n" "" 0 --root "${CMAKE_SOURCE_DIR}" --show-rule -p full --parameter max-directory-depth=20 ${CMAKE_CURRENT_SOURCE_DIR}/L004.cpp ) # just make sure the help test does not fail add_test(NAME Help COMMAND vera --help foo bar) add_test(NAME ShortHelp COMMAND vera -h foo bar) # options to test # --transform arg ####### rule tests ####### set(VERA_TEST_RULE_ROOT ${CMAKE_SOURCE_DIR}) vera_add_rule_test(F001 "4: \\r (CR) detected in isolation at position 7") # F002 vera_add_rule_test(L001 "4: trailing whitespace 6: trailing whitespace") vera_add_rule_test(L002 "2: horizontal tab used 4: horizontal tab used 6: horizontal tab used") vera_add_test(RuleL003 "" "${CMAKE_CURRENT_SOURCE_DIR}/L003-1.cpp:1: leading empty line(s) ${CMAKE_CURRENT_SOURCE_DIR}/L003-2.cpp:4: trailing empty line(s)\n" "" 0 --rule L003 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/L003-1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/L003-2.cpp ) vera_add_rule_test(L004 "1: line is longer than 100 characters 2: line is longer than 100 characters") vera_add_rule_test(L005 "6: too many consecutive empty lines") vera_add_test(RuleL006 "" "${CMAKE_CURRENT_SOURCE_DIR}/L006-2.cpp:2001: source file is too long\n" "" 0 --rule L006 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/L006-1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/L006-2.cpp ) vera_add_rule_test(T001 "6: line-continuation in one-line comment") set(output "4: reserved name used for macro (incorrect use of underscore) 5: reserved name used for macro (incorrect use of underscore)") foreach(i RANGE 7 80) set(output "${output}\n${i}: reserved name used for macro (keyword or alternative token redefined)") endforeach() vera_add_rule_test(T002 "${output}") vera_add_rule_test(T003 "1: keyword 'case' not followed by a single space 2: keyword 'class' not followed by a single space 3: keyword 'delete' not followed by a single space 4: keyword 'enum' not followed by a single space 5: keyword 'explicit' not followed by a single space 6: keyword 'extern' not followed by a single space 7: keyword 'goto' not followed by a single space 8: keyword 'new' not followed by a single space 9: keyword 'struct' not followed by a single space 10: keyword 'union' not followed by a single space 11: keyword 'using' not followed by a single space 13: keyword 'case' not followed by a single space 14: keyword 'class' not followed by a single space 15: keyword 'delete' not followed by a single space 16: keyword 'enum' not followed by a single space 17: keyword 'explicit' not followed by a single space 18: keyword 'extern' not followed by a single space 19: keyword 'goto' not followed by a single space 20: keyword 'new' not followed by a single space 21: keyword 'struct' not followed by a single space 22: keyword 'union' not followed by a single space 23: keyword 'using' not followed by a single space") vera_add_rule_test(T004 "25: colon not immediately after the 'public' keyword 28: colon not immediately after the 'protected' keyword 30: colon not immediately after the 'private' keyword 39: colon not immediately after the 'default' keyword") vera_add_rule_test(T005 "19: keyword 'break' not immediately followed by a semicolon 23: keyword 'continue' not immediately followed by a semicolon") vera_add_rule_test(T006 "24: keyword 'throw' not immediately followed by a semicolon or a single space 25: keyword 'return' not immediately followed by a semicolon or a single space 29: keyword 'return' not immediately followed by a semicolon or a single space") vera_add_rule_test(T007 "6: semicolon is isolated from other tokens 7: semicolon is isolated from other tokens 9: semicolon is isolated from other tokens") vera_add_rule_test(T008 "22: keyword 'catch' not followed by a single space 24: keyword 'for' not followed by a single space 26: keyword 'if' not followed by a single space 28: keyword 'while' not followed by a single space") vera_add_rule_test(T009 "10: comma should not be preceded by whitespace 12: comma should not be preceded by whitespace 12: comma should not be preceded by whitespace 13: comma should not be preceded by whitespace 13: comma should not be preceded by whitespace 14: comma should not be preceded by whitespace") vera_add_rule_test(T010 "5: identifier should not be composed of only 'l' and 'O' 6: identifier should not be composed of only 'l' and 'O'") vera_add_rule_test(T011 "22: closing curly bracket not in the same line or column 27: closing curly bracket not in the same line or column 30: closing curly bracket not in the same line or column 39: closing curly bracket not in the same line or column") vera_add_rule_test(T012 "1: negation operator used in its short form") vera_add_test(RuleT013 "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no copyright notice found\n" "" 0 --rule T013 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/T013.cpp ) vera_add_test(RuleT014 "" "${CMAKE_CURRENT_SOURCE_DIR}/test.cpp:1: no reference to the Boost Software License found\n" "" 0 --rule T014 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/T013.cpp ) vera_add_rule_test(T015 "8: URL points to non-existing file 9: URL points to non-existing file") vera_add_rule_test(T016 "1: min/max potential macro substitution problem") vera_add_test(RuleT017 "" "${CMAKE_CURRENT_SOURCE_DIR}/T017.h:1: unnamed namespace not allowed in header file\n" "" 0 --rule T017 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/T017.h ${CMAKE_CURRENT_SOURCE_DIR}/T017.cpp ) vera_add_test(RuleT018 "" "${CMAKE_CURRENT_SOURCE_DIR}/T018.h:1: using namespace not allowed in header file\n" "" 0 --rule T018 --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/T018.h ${CMAKE_CURRENT_SOURCE_DIR}/T018.cpp ) vera_add_rule_test(T019 "1: full block {} expected in the control structure 5: full block {} expected in the control structure 13: full block {} expected in the control structure 14: full block {} expected in the control structure 24: full block {} expected in the control structure 33: full block {} expected in the control structure 34: full block {} expected in the control structure") vera_add_test(RuleDUMP "" "Tokens in file ${CMAKE_CURRENT_SOURCE_DIR}/T017.cpp: 1/0\tnamespace\tnamespace 1/9\tnewline\t 2/0\tleftbrace\t{ 2/1\tnewline\t 3/0\tcppcomment\t// some stuff here 4/0\trightbrace\t} 4/1\tnewline\t 5/0\teof\t " "" 0 --rule DUMP --root "${CMAKE_SOURCE_DIR}" ${CMAKE_CURRENT_SOURCE_DIR}/T017.cpp ) vera_add_test(ErrorReport "" "" "error: can't read \"auie\": no such variable while executing \"lindex $auie\" (procedure \"Foo\" line 2) invoked from within \"Foo\" (procedure \"Bar\" line 2) invoked from within \"Bar\" invoked from within \"puts [Bar]\" (file \"${CMAKE_CURRENT_SOURCE_DIR}/errorReport/scripts/rules/Broken.tcl\" line 9)\n" 1 --rule Broken --root "${CMAKE_CURRENT_SOURCE_DIR}/errorReport" ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp ) vera++-1.2.1/tests/errorReport/scripts/rules/Broken.tcl000644 000765 000024 00000000126 12137562246 023775 0ustar00glehmannstaff000000 000000 proc Foo {} { return [lindex $auie] } proc Bar {} { return [Foo] } puts [Bar] vera++-1.2.1/tests/exclusions.txt000644 000765 000024 00000000050 12144542562 017631 0ustar00glehmannstaff000000 000000 set ruleExclusions(T013) { test.cpp } vera++-1.2.1/tests/F001.cpp000644 000765 000024 00000000217 12136755400 016011 0ustar00glehmannstaff000000 000000 // this file uses CRLF int i = 0; // a CR char is inserted in this line int j = 1; //and the next line is ended by a LF alone int k = 0; vera++-1.2.1/tests/L001.cpp000644 000765 000024 00000000176 12136752377 016035 0ustar00glehmannstaff000000 000000 // no trailing white space int i = 0; // one trailing white space int j = 1; // many trailing white spaces int j = 1; vera++-1.2.1/tests/L002.cpp000644 000765 000024 00000000231 12136757374 016030 0ustar00glehmannstaff000000 000000 // one tab at the beginning of the next line int i = 1; // two tabs and a tab in the middle int j = 0; // a tab in the middle of the line int k = 1; vera++-1.2.1/tests/L003-1.cpp000644 000765 000024 00000000052 12137013622 016146 0ustar00glehmannstaff000000 000000 // some empty lines above int i = 2; vera++-1.2.1/tests/L003-2.cpp000644 000765 000024 00000000054 12137014061 016147 0ustar00glehmannstaff000000 000000 // some empty lines at the end int j = 2; vera++-1.2.1/tests/L004.cpp000644 000765 000024 00000000723 12137150632 016021 0ustar00glehmannstaff000000 000000 // this comment is waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too long int thisStatementIsAlsowaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayTooLong = 1; // this comment 100 characters long --------------------------------------------------------------> // and this one is shorter int thisStatementIsOk = 1; int asIsThisOne = 2; vera++-1.2.1/tests/L005.cpp000644 000765 000024 00000000053 12137157306 016023 0ustar00glehmannstaff000000 000000 // 2 empty lines are ok // 3 are not vera++-1.2.1/tests/L006-1.cpp000644 000765 000024 00000021275 12137157374 016200 0ustar00glehmannstaff000000 000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 vera++-1.2.1/tests/L006-2.cpp000644 000765 000024 00000021302 12137157510 016160 0ustar00glehmannstaff000000 000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 vera++-1.2.1/tests/parameters.txt000644 000765 000024 00000000023 12144542562 017600 0ustar00glehmannstaff000000 000000 max-line-length=99 vera++-1.2.1/tests/T001.cpp000644 000765 000024 00000000225 12137247735 016036 0ustar00glehmannstaff000000 000000 void foo() { // this comment is ok as is the next line int i = \ 3; // this comment is continued in the next line \ exit(0); } vera++-1.2.1/tests/T002.cpp000644 000765 000024 00000002346 12137250636 016037 0ustar00glehmannstaff000000 000000 // this one is OK #define MY_MACRO something // these ones are not #define _MY_MACRO something #define MY__MACRO something // reserved keywords can't be redefined #define asm #define auto #define bool #define break #define case #define catch #define char #define class #define const #define const_cast #define continue #define default #define delete #define goto #define do #define double #define dynamic_cast #define else #define enum #define explicit #define export #define extern #define false #define float #define for #define friend #define if #define inline #define int #define long #define mutable #define namespace #define new #define operator #define private #define protected #define public #define register #define reinterpret_cast #define return #define short #define signed #define sizeof #define static #define static_cast #define struct #define switch #define template #define this #define throw #define true #define try #define typedef #define typeid #define typename #define union #define unsigned #define using #define virtual #define void #define volatile #define wchar_t #define while #define and #define and_eq #define bitand #define bitor #define compl #define not #define not_eq #define or #define or_eq #define xor #define xor_eq vera++-1.2.1/tests/T003.cpp000644 000765 000024 00000000540 12137402173 016025 0ustar00glehmannstaff000000 000000 case(); class(); delete(); enum(); explicit(); extern(); goto(); new(); struct(); union(); using(); // a space followed by a new line case class delete enum explicit extern goto new struct union using // normal cases case Foo: class Foo; delete foo; enum Foo; explicit foo; extern foo; goto foo; new foo(); struct Foo; union Foo; using foo; vera++-1.2.1/tests/T004.cpp000644 000765 000024 00000000654 12137402603 016032 0ustar00glehmannstaff000000 000000 // OK class A : public B, private C { public: A(); ~A(); protected: // ... private: // ... }; void fun(int a) { switch (a) { // ... default: exit(0); } } // not OK class A : public B, private C { public : A(); ~A(); protected : // ... private : // ... }; void fun(int a) { switch (a) { // ... default : exit(0); } } vera++-1.2.1/tests/T005.cpp000644 000765 000024 00000000405 12137403034 016024 0ustar00glehmannstaff000000 000000 // OK while (...) { if (...) { break; } if (...) { continue; } // ... } // not OK while (...) { if (...) { break ; } if (...) { continue ; } // ... } vera++-1.2.1/tests/T006.cpp000644 000765 000024 00000000526 12137403431 016032 0ustar00glehmannstaff000000 000000 // OK void fun() { if (...) { return; } // ... throw e; return (x == y); } int add(int a, int b) throw() { return a + b; } // not OK void fun() { if (...) { return ; } // ... throw(e); return(x == y); } int add(int a, int b) throw() { return(a + b); } vera++-1.2.1/tests/T007.cpp000644 000765 000024 00000000133 12137405701 016027 0ustar00glehmannstaff000000 000000 // OK int a; int b; // a variable int /*const*/ c; // not OK int a ; int b/*[3]*/; int c ; vera++-1.2.1/tests/T008.cpp000644 000765 000024 00000001426 12137411465 016042 0ustar00glehmannstaff000000 000000 // OK catch (...) { for (int i = 0; i != 10; ++i) { if (foo(i)) { while (getline(cin, line)) { switch (i % 3) { case 0: bar(line); break; // ... } } } } } // not OK catch(...) { for(int i = 0; i != 10; ++i) { if(foo(i)) { while(getline(cin, line)) { switch (i % 3) { case 0: bar(line); break; // ... } } } } } vera++-1.2.1/tests/T009.cpp000644 000765 000024 00000000515 12137414603 016036 0ustar00glehmannstaff000000 000000 // OK void fun(int x, int y, int z); int a[] = {5, 6, 7}; class A : public B, public C { // ... }; void operator,(const A &left, const A &right); void operator , (const A &left, const A &right); // not OK void fun(int x , int y , int z); int a[] = {5 , 6 , 7}; class A : public B , public C { // ... }; vera++-1.2.1/tests/T010.cpp000644 000765 000024 00000000075 12137415605 016032 0ustar00glehmannstaff000000 000000 // OK int l1 = 0; int O0 = 1 // not OK int l = 0; int O = 1; vera++-1.2.1/tests/T011.cpp000644 000765 000024 00000000531 12137416066 016032 0ustar00glehmannstaff000000 000000 // OK class MyException {}; struct MyPair { int a; int b; }; enum state { close, open }; enum colors { black, red, green, blue, white }; // not OK class MyException { }; struct MyPair { int a; int b; }; enum state { close, open }; enum colors { black, red, green, blue, white }; vera++-1.2.1/tests/T012.cpp000644 000765 000024 00000000162 12137416314 016027 0ustar00glehmannstaff000000 000000 if (!cond) // error-prone if (cond == false) // better if (not cond) // better (alternative keyword) vera++-1.2.1/tests/T013.cpp000644 000765 000024 00000000330 12137416571 016032 0ustar00glehmannstaff000000 000000 // // Copyright (C) 2006-2007 Maciej Sobczak // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // int i = 0; vera++-1.2.1/tests/T015.cpp000644 000765 000024 00000000350 12137417641 016035 0ustar00glehmannstaff000000 000000 // OK // inspirel /* inspirel */ // T015 /* T015 */ // not OK // T015 /* T015 */ vera++-1.2.1/tests/T016.cpp000644 000765 000024 00000000223 12137424670 016035 0ustar00glehmannstaff000000 000000 x = max(y, z); // wrong, vulnerable to accidental macro substitution x = (max)(y, z); // OK x = max BOOST_PREVENT_MACRO_SUBSTITUTION (y, z); // OK vera++-1.2.1/tests/T017.cpp000644 000765 000024 00000000041 12137425064 016032 0ustar00glehmannstaff000000 000000 namespace { // some stuff here } vera++-1.2.1/tests/T017.h000644 000765 000024 00000000041 12137425073 015477 0ustar00glehmannstaff000000 000000 namespace { // some stuff here } vera++-1.2.1/tests/T018.cpp000644 000765 000024 00000000076 12137425350 016041 0ustar00glehmannstaff000000 000000 using namespace std; class Foo: private Bar { using blah; } vera++-1.2.1/tests/T018.h000644 000765 000024 00000000076 12137425303 015504 0ustar00glehmannstaff000000 000000 using namespace std; class Foo: private Bar { using blah; } vera++-1.2.1/tests/T019.cpp000644 000765 000024 00000001103 12154326666 016043 0ustar00glehmannstaff000000 000000 if (x) foo(); // bad style if (x) { foo(); } // OK if (x) foo(); // again bad style if (x) { // OK foo(); } if (x) while (y) // bad style foo(); // bad style if (x) { // OK while (y) { // OK foo(); } } for (int i = 0; i = 10; ++i); // oops! cout << "Hello\n"; for (int i = 0; i = 10; ++i) // OK { cout << "Hello\n"; } do cout << "Hello\n"; while (int i = 0; i = 10; ++i); // not OK do { cout << "Hello\n"; } while (int i = 0; i = 10; ++i); // OK vera++-1.2.1/tests/test.cpp000644 000765 000024 00000000000 12125265375 016355 0ustar00glehmannstaff000000 000000 vera++-1.2.1/vera.ctest000644 000765 000024 00000026752 12145130274 015546 0ustar00glehmannstaff000000 000000 # vera++ Dashboard Script # # This script contains basic dashboard driver code common to all # clients. # # Put this script in a directory such as "~/Dashboards/Scripts" or # "c:/Dashboards/Scripts". Create a file next to this script, say # 'my_dashboard.cmake', with code of the following form: # # # Client maintainer: me@mydomain.net # set(CTEST_SITE "machine.site") # set(CTEST_BUILD_NAME "Platform-Compiler") # set(CTEST_BUILD_CONFIGURATION Debug) # set(CTEST_CMAKE_GENERATOR "Unix Makefiles") # include(${CTEST_SCRIPT_DIRECTORY}/vera.ctest) # # Then run a scheduled task (cron job) with a command line such as # # ctest -S ~/Dashboards/Scripts/my_dashboard.cmake -V # # By default the source and build trees will be placed in the path # "../My Tests/" relative to your script location. # # The following variables may be set before including this script # to configure it: # # dashboard_model = Nightly | Experimental | Continuous # dashboard_loop = Repeat until N seconds have elapsed # dashboard_root_name = Change name of "My Tests" directory # dashboard_source_name = Name of source directory (vera) # dashboard_binary_name = Name of binary directory (vera-build) # dashboard_cache = Initial CMakeCache.txt file content # dashboard_do_coverage = True to enable coverage (ex: gcov) # dashboard_do_memcheck = True to enable memcheck (ex: valgrind) # dashboard_no_clean = True to skip build tree wipeout # CTEST_UPDATE_COMMAND = path to svn command-line client # CTEST_BUILD_FLAGS = build tool arguments (ex: -j2) # CTEST_DASHBOARD_ROOT = Where to put source and build trees # CTEST_TEST_CTEST = Whether to run long CTestTest* tests # CTEST_TEST_TIMEOUT = Per-test timeout length # CTEST_TEST_ARGS = ctest_test args (ex: PARALLEL_LEVEL 4) # CMAKE_MAKE_PROGRAM = Path to "make" tool to use # # Options to configure builds from experimental git repository: # dashboard_git_url = Custom git clone url # dashboard_git_branch = Custom remote branch to track # dashboard_git_crlf = Value of core.autocrlf for repository # # The following macros will be invoked before the corresponding # step if they are defined: # # dashboard_hook_init = End of initialization, before loop # dashboard_hook_start = Start of loop body, before ctest_start # dashboard_hook_build = Before ctest_build # dashboard_hook_test = Before ctest_test # dashboard_hook_coverage = Before ctest_coverage # dashboard_hook_memcheck = Before ctest_memcheck # dashboard_hook_submit = Before ctest_submit # dashboard_hook_end = End of loop body, after ctest_submit # # For Makefile generators the script may be executed from an # environment already configured to use the desired compilers. # Alternatively the environment may be set at the top of the script: # # set(ENV{CC} /path/to/cc) # C compiler # set(ENV{CXX} /path/to/cxx) # C++ compiler # set(ENV{FC} /path/to/fc) # Fortran compiler (optional) # set(ENV{LD_LIBRARY_PATH} /path/to/vendor/lib) # (if necessary) #========================================================================== # # Copyright Insight Software Consortium # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #==========================================================================*/ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) set(dashboard_user_home "$ENV{HOME}") get_filename_component(dashboard_self_dir ${CMAKE_CURRENT_LIST_FILE} PATH) # Select the top dashboard directory. if(NOT DEFINED dashboard_root_name) set(dashboard_root_name "My Tests") endif() if(NOT DEFINED CTEST_DASHBOARD_ROOT) get_filename_component(CTEST_DASHBOARD_ROOT "${CTEST_SCRIPT_DIRECTORY}/${dashboard_root_name}" ABSOLUTE) endif() # Select the model (Nightly, Experimental, Continuous). if(NOT DEFINED dashboard_model) set(dashboard_model Nightly) endif() if(NOT "${dashboard_model}" MATCHES "^(Nightly|Experimental|Continuous)$") message(FATAL_ERROR "dashboard_model must be Nightly, Experimental, or Continuous") endif() # Default to a Debug build. if(NOT DEFINED CTEST_CONFIGURATION_TYPE AND DEFINED CTEST_BUILD_CONFIGURATION) set(CTEST_CONFIGURATION_TYPE ${CTEST_BUILD_CONFIGURATION}) endif() if(NOT DEFINED CTEST_CONFIGURATION_TYPE) set(CTEST_CONFIGURATION_TYPE Debug) endif() # Choose CTest reporting mode. if(NOT DEFINED CTEST_USE_LAUNCHERS) if(NOT "${CTEST_CMAKE_GENERATOR}" MATCHES "Make") # Launchers work only with Makefile generators. set(CTEST_USE_LAUNCHERS 0) elseif(NOT DEFINED CTEST_USE_LAUNCHERS) # The setting is ignored by CTest < 2.8 so we need no version test. set(CTEST_USE_LAUNCHERS 1) endif() endif() # Configure testing. if(NOT DEFINED CTEST_TEST_CTEST) set(CTEST_TEST_CTEST 1) endif() if(NOT CTEST_TEST_TIMEOUT) set(CTEST_TEST_TIMEOUT 1500) endif() # Select Git source to use. if(NOT DEFINED dashboard_git_url) set(dashboard_git_url "https://bitbucket.org/verateam/vera.git") endif() if(NOT DEFINED dashboard_git_branch) # if("${dashboard_model}" STREQUAL "Nightly") # set(dashboard_git_branch nightly-master) # else() set(dashboard_git_branch master) # endif() endif() if(NOT DEFINED dashboard_git_crlf) if(UNIX) set(dashboard_git_crlf false) else(UNIX) set(dashboard_git_crlf true) endif(UNIX) endif() # Look for a GIT command-line client. if(NOT DEFINED CTEST_GIT_COMMAND) find_program(CTEST_GIT_COMMAND NAMES git git.cmd) endif() if(NOT DEFINED CTEST_GIT_COMMAND) message(FATAL_ERROR "No Git Found.") endif() # Select a source directory name. if(NOT DEFINED CTEST_SOURCE_DIRECTORY) if(DEFINED dashboard_source_name) set(CTEST_SOURCE_DIRECTORY ${CTEST_DASHBOARD_ROOT}/${dashboard_source_name}) else() set(CTEST_SOURCE_DIRECTORY ${CTEST_DASHBOARD_ROOT}/vera) endif() endif() # Select a build directory name. if(NOT DEFINED CTEST_BINARY_DIRECTORY) if(DEFINED dashboard_binary_name) set(CTEST_BINARY_DIRECTORY ${CTEST_DASHBOARD_ROOT}/${dashboard_binary_name}) else() set(CTEST_BINARY_DIRECTORY ${CTEST_SOURCE_DIRECTORY}-build) endif() endif() # Support initial checkout if necessary. if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}" AND NOT DEFINED CTEST_CHECKOUT_COMMAND) execute_process( COMMAND "${CTEST_GIT_COMMAND}" clone -b ${dashboard_git_branch} -- "${dashboard_git_url}" "${CTEST_SOURCE_DIRECTORY}" ) if(EXISTS "${CTEST_SOURCE_DIRECTORY}/.git") execute_process( COMMAND "${CTEST_GIT_COMMAND}" config core.autocrlf ${dashboard_git_crlf} WORKING_DIRECTORY "${CTEST_SOURCE_DIRECTORY}" ) execute_process( COMMAND "${CTEST_GIT_COMMAND}" submodule update --init WORKING_DIRECTORY "${CTEST_SOURCE_DIRECTORY}" ) endif() endif() #----------------------------------------------------------------------------- # Send the main script as a note. list(APPEND CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}" "${CMAKE_CURRENT_LIST_FILE}" ) # Check for required variables. foreach(req CTEST_CMAKE_GENERATOR CTEST_SITE CTEST_BUILD_NAME ) if(NOT DEFINED ${req}) message(FATAL_ERROR "The containing script must set ${req}") endif() endforeach(req) # Print summary information. foreach(v CTEST_SITE CTEST_BUILD_NAME CTEST_SOURCE_DIRECTORY CTEST_BINARY_DIRECTORY CTEST_CMAKE_GENERATOR CTEST_BUILD_CONFIGURATION CTEST_GIT_COMMAND CTEST_CHECKOUT_COMMAND CTEST_SCRIPT_DIRECTORY CTEST_USE_LAUNCHERS ) set(vars "${vars} ${v}=[${${v}}]\n") endforeach(v) message("Dashboard script configuration:\n${vars}\n") # Avoid non-ascii characters in tool output. set(ENV{LC_ALL} "en_US.UTF-8") # Helper macro to write the initial cache. macro(write_cache) set(cache_build_type "") set(cache_make_program "") if(CTEST_CMAKE_GENERATOR MATCHES "Make") set(cache_build_type CMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION}) if(CMAKE_MAKE_PROGRAM) set(cache_make_program CMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}) endif() endif() file(WRITE ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt " SITE:STRING=${CTEST_SITE} BUILDNAME:STRING=${CTEST_BUILD_NAME} CTEST_USE_LAUNCHERS:BOOL=${CTEST_USE_LAUNCHERS} DART_TESTING_TIMEOUT:STRING=${CTEST_TEST_TIMEOUT} ${cache_build_type} ${cache_make_program} ${dashboard_cache} ") endmacro(write_cache) # Start with a fresh build tree. file(MAKE_DIRECTORY "${CTEST_BINARY_DIRECTORY}") if(NOT "${CTEST_SOURCE_DIRECTORY}" STREQUAL "${CTEST_BINARY_DIRECTORY}" AND NOT dashboard_no_clean) message("Clearing build tree...") ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) endif() set(dashboard_continuous 0) if("${dashboard_model}" STREQUAL "Continuous") set(dashboard_continuous 1) endif() if(NOT DEFINED dashboard_loop) if(dashboard_continuous) set(dashboard_loop 43200) else() set(dashboard_loop 0) endif() endif() # CTest 2.6 crashes with message() after ctest_test. macro(safe_message) if(NOT "${CMAKE_VERSION}" VERSION_LESS 2.8 OR NOT safe_message_skip) message(${ARGN}) endif() endmacro() if(COMMAND dashboard_hook_init) dashboard_hook_init() endif() set(dashboard_done 0) while(NOT dashboard_done) if(dashboard_loop) set(START_TIME ${CTEST_ELAPSED_TIME}) endif() set(ENV{HOME} "${dashboard_user_home}") # Start a new submission. if(COMMAND dashboard_hook_start) dashboard_hook_start() endif() ctest_start(${dashboard_model}) # Always build if the tree is fresh. set(dashboard_fresh 0) if(NOT EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt") set(dashboard_fresh 1) safe_message("Starting fresh build...") write_cache() endif() # Look for updates. ctest_update(RETURN_VALUE count) set(CTEST_CHECKOUT_COMMAND) # checkout on first iteration only safe_message("Found ${count} changed files") if(dashboard_fresh OR NOT dashboard_continuous OR count GREATER 0) ctest_configure() ctest_read_custom_files(${CTEST_BINARY_DIRECTORY}) if(COMMAND dashboard_hook_build) dashboard_hook_build() endif() ctest_build() if(COMMAND dashboard_hook_test) dashboard_hook_test() endif() ctest_test(${CTEST_TEST_ARGS}) set(safe_message_skip 1) # Block furhter messages if(dashboard_do_coverage) if(COMMAND dashboard_hook_coverage) dashboard_hook_coverage() endif() ctest_coverage() endif() if(dashboard_do_memcheck) if(COMMAND dashboard_hook_memcheck) dashboard_hook_memcheck() endif() ctest_memcheck() endif() if(COMMAND dashboard_hook_submit) dashboard_hook_submit() endif() if(NOT dashboard_no_submit) ctest_submit() endif() if(COMMAND dashboard_hook_end) dashboard_hook_end() endif() endif() if(dashboard_loop) # Delay until at least 5 minutes past START_TIME ctest_sleep(${START_TIME} 300 ${CTEST_ELAPSED_TIME}) if(${CTEST_ELAPSED_TIME} GREATER ${dashboard_loop}) set(dashboard_done 1) endif() else() # Not continuous, so we are done. set(dashboard_done 1) endif() endwhile() vera++-1.2.1/wiki/Building.md000644 000765 000024 00000007555 12154705411 016570 0ustar00glehmannstaff000000 000000 Compiling Vera++ ================ Getting the sources ------------------- ### From the download section Just download [this archive](https://bitbucket.org/verateam/vera/downloads/vera++-1.2.0.tar.gz) and extract it. ### With git To get a copy of Vera++'s repository, run: git clone https://bitbucket.org/verateam/vera.git cd vera git submodule update --init To update that repository, run: git pull git submodule update Note that the submodule is only needed to build the documentation. If it is not there, a warning is displayed and the documentation is not generated. Dependencies ------------ Vera++ is implemented in C++ and depends on the [Boost](http://www.boost.org/) and [Tcl](http://www.tcl.tk/) libraries. It uses [CMake](http://cmake.org/ CMake) as build system. The documentation is generated with [pandoc](http://johnmacfarlane.net/pandoc/). Note that pandoc is only needed to build the documentation. If it is not found, a warning is displayed and the documentation is not generated. Configuring and building ------------------------ To build vera++, as with any CMake project, run either, `cmake`, `ccmake` or `cmake-gui`, configure and generate the project, and build the project with your build environment. You can then install vera++ by building the `install` target, or generate a package by building the `package` target. On unix compatible systems (Linux, *BSD, Mac OS X, ...), this is done this way: cd vera mkdir build cd build cmake .. make -j make install See [Running CMake](http://www.cmake.org/cmake/help/runningcmake.html) for more information. Testing ------- Vera++ uses CTest, the testing tool that comes with CMake. To run the tests, simply type ctest in your build directory. The test results can be submitted to the [vera++'s dashboard](http://my.cdash.org/index.php?project=vera%2B%2B) with the command ctest -D Experimental To submit nightly tests, it is easier to create a test directory, copy `vera.ctest` from [vera++'s sources](https://bitbucket.org/ThArGos/vera/src) to that directory and create a new file `vera.cmake` like this one: set(CTEST_SITE "host.site") set(CTEST_BUILD_NAME "compiler name") set(CTEST_BUILD_CONFIGURATION Debug) set(CTEST_CMAKE_GENERATOR "Unix Makefiles") include(${CTEST_SCRIPT_DIRECTORY}/vera.ctest) adjust the values, and run every nights: ctest -S /path/to/vera.cmake The test results will appear on [vera++'s dashboard](http://my.cdash.org/index.php?project=vera%2B%2B). See [CMake Scripting Of CTest](http://www.cmake.org/Wiki/CMake_Scripting_Of_CTest) for more details. Packages -------- Vera++ uses `CPack` to generate the binary and source packages. ### Source package ### Just build the `package_source` target to generate the source archive as a `tar.gz` file. Make sure your repository is clean with `git status` before generating the package. ### Documentation package ### Build the `package_doc` target to generate the documentation archive as a `tar.gz` file. ### Mac OS X package ### `CPack` depends on [PackageMaker](https://developer.apple.com/downloads/index.action) to generate this package. Set the CMake option `Boost_USE_STATIC_LIBS` to `ON` and `CMAKE_BUILD_TYPE` to `Release` and build the target `package`. A few options can be turned off to speed up the package build if only the package built with `PackageMaker` is needed: * `CPACK_BINARY_STGZ` * `CPACK_BINARY_TGZ` ### Microsoft Windows ### `CPack` depends on [NSIS](http://nsis.sourceforge.net/Main_Page) to generate this package. Set the CMake option `CMAKE_BUILD_TYPE` to `Release` and build the target `package`. ### Linux Debian ### Set the CMake option `CMAKE_BUILD_TYPE` to `Release` and build the target `package`. ### Linux RPM ### Set the CMake option `CMAKE_BUILD_TYPE` to `Release` and build the target `package`. Note: this package generation has not yet been tested.vera++-1.2.1/wiki/Changes.md000644 000765 000024 00000010554 12154705411 016374 0ustar00glehmannstaff000000 000000 Changes ======= Vera++ 1.2.1 ------------ Vera++ 1.2.1 differs from 1.2.0 in the following ways: - BUGFIX: fix `--inputs` in order to be able to read the inputs from a file Vera++ 1.2.0 ------------ Vera++ 1.2.0 differs from 1.1.2 in the following ways: - Full Tcl stack printed when a rule fail. - New command line interface that support long and short options. The old style command line is still usable for backward compatibility. - Produce output to standard output by default so the output can easily be piped to another program. The options `--warning` and `--error` make vera++ produce its output on the error output. - CMake macros to easily run vera++ in any CMake project. - Easier integration in a test chain by return an error code when at least one report is produced and the `--error` option is used. `--quiet` and `--summary` can also help to better integrate vera++ in the test chain. - The standard output format match gcc's output format for a better integration in a build chain. - Can read the list of files to check from one or more files. - Can read the source code to check from the standard input. - Can write the several reports in differents formats and in different places. - Added `--root` option to point the the vera root directory from the command line and ease the usage of custom rules. - Reports can be produced in [checkstyle](http://checkstyle.sourceforge.net/) XML format. - Vera++ no more impose the extension of the source files to check. - Several exclusion files can be used. - Several parameter files can be used. - Build system now uses CMake. - Builds with TCL 8.6. - Don't require Boost sources to build. - New documentation generation process to unify the wiki, the html doc and the manpage. - Binary packages for MS Windows and Mac OS X (and others). - Nightly tests to avoid regressions. - New website. - BUGFIX: the rule T019 now works properly with `do ... while` blocks. Vera++ 1.1.2 ------------ Vera++ 1.1.2 differs from 1.1.1 in the following ways: - Added `-xmlreport` option. Vera++ 1.1.1 ------------ Vera++ 1.1.1 differs from 1.1.0 in the following ways: - Added `-help` option. - Updated code for compatibility with newer versions of Boost. The reference version of the Boost library is now 1.35 or 1.36. - BUGFIX: Corrected handling of current directory when neither `HOME` nor `VERA_ROOT` is specified (this affects Windows users only). Vera++ 1.1.0 ------------ Vera++ 1.1.0 differs from 1.0.0 in the following ways: - Updated rules: - T002: additionally recognizes redefinition (`#define`) of keywords - T009: recognizes comment adjacent to colon as an exception to the rule - Added rules: - F001: Source files should not use the `\r` (CR) character - F002: File names should be well-formed Note: F002 is not part of the default profile. - T012: Negation operator should not be used in its short form - T013: Source files should contain the copyright notice - T014: Source files should refer the Boost Software License Note: T014 is not part of the default profile. - T015: HTML links in comments and string literals should be correct - T016: Calls to `min`/`max` should be protected against accidental macro substitution - T017: Unnamed namespaces are not allowed in header files - T018: Using namespace is not allowed in header files - T019: Control structures should have complete curly-braced block of code - Added predefined boost profile to emulate the original Boost inspect tool. - Added transformations: - move_namespace: Changes the given identifier, useful for moving the whole project from one namespace to another. - move_macros: Changes the given prefix in all identifiers, useful for moving the whole set of macros that have common prefix. - move_includes: Changes the given part of `#include "..."` directives, useful for moving libraries and whole sets of header files. - Added documentation for all available transformations. - Makefiles modified to better support Windows make users. - Extension `.ipp` added to the list of recognized source file extensions. - New option `-showrules` includes name of rules in each report line. - Changed the profile definition to be an active Tcl script instead of passive text file. - Added the possibility to define exclusions to rule checks. - BUGFIX: Corrected handling of newline tokens.vera++-1.2.1/wiki/Home.md000644 000765 000024 00000001777 12154705411 015723 0ustar00glehmannstaff000000 000000 [Introduction](Introduction) [Compiling](Building) [Running](Running) [Index of available rules](Rules) [Index of available transformations](Transformations) [Script API](ScriptAPI) [Changes](Changes) [Screenshots](Screenshots) * * * * * Welcome ======= Welcome to the Vera++ homepage. This is the new official home for Vera++. I would like to thank Maciej Sobczak who had written the original Vera++ program and had supported it for so long. Thank you for your contributions and thank you for letting the community an opportunity to take Vera++ even further. Description ----------- Vera++ is a programmable tool for verification, analysis and transformation of C++ source code. Vera++ is mainly an engine that parses C++ source files and presents the result of this parsing to scripts in the form of various collections - the scripts are actually performing the requested tasks. License ------- Boost Software License Origins ------- Vera++ was initially hosted at: http://www.inspirel.com/vera vera++-1.2.1/wiki/Introduction.md000644 000765 000024 00000004634 12135504715 017512 0ustar00glehmannstaff000000 000000 Introduction ============ Vera++ is a programmable tool for verification, analysis and transformation of C++ source code. The main usage scenarios that are foreseen for Vera++ are: * Ensure that the source code complies with the given _coding standards and conventions_. * Provide source code _metrics and statistics_. * Perform automated _transformations_ of the source code, which can range from _pretty-printing_ to _diagnostics_ to _fault injection_ and advanced testing. The main design idea of Vera++ is to create a generic engine that will be able to parse the C++ code and present it in the form of collections of various objects to user provided _scripts_ that will define the concrete actions to be executed. Currently the following object collections are provided: * Collection of source _file names_. * Collection of _source lines_ for each file. * Collection of identified _tokens_ in each file. __Note:__ It is foreseen that future versions of Vera++ will provide also the semantic view on the code. The most important feature of Vera++ is that all activities other than code parsing are defined by scripts. This means that Vera++ is _flexible_ and _extensible_. For example, compliance with coding standards can be expressed in terms of _rules_, each being defined by a separate script. The scripts can access all collections listed above and perform actions related to the given rule. The user can ask to run any given script or some defined set of scripts in a single program execution. As a simple example, a coding convention that limits the length of the source line can be implemented as a script that traverses the collection of files and the collection of source lines and checks whether each source line fits within the given limits. A report can be generated for each non-conforming line of code so that the user gets a clear information about where the problem is located. All existing rules present their reports in the format that is compatible with regular compiler's output, so that it is easy to integrate Vera++ with the existing build framework. Similarly, automated transformation procedures are implemented as separate scripts that scan the above collections and produce another source files according to their algorithms. A simple example of such transformation might be a script that removes empty lines from source code. The Tcl programming language is currently supported for scripts that run within Vera++. vera++-1.2.1/wiki/Rules.md000644 000765 000024 00000035020 12131444241 016105 0ustar00glehmannstaff000000 000000 Rules ===== F001 Source files should not use the '\\r' (CR) character --------------------------------------------------------- As a commonly accepted practice, line breaks are denoted by a single '\\n' (LF) character or by two characters "\\r\\n" (CRLF). A single appearance of '\\r' (CR) is discouraged. **Compliance:** Boost F002 File names should be well-formed ------------------------------------- The source file names should be well-formed in the sense of their allowed maximum length and directory depth. Directory and file names should start with alphabetic character or underscore. In addition, directory names should not contain dots and file names can have only one dot. **Recognized parameters:** Name Default Description ----------------------- --------- ------------------------------------------------- max-directory-depth 8 Maximum depth of the directory structure. max-dirname-length 31 Maximum length of the directory path component. max-filename-length 31 Maximum length of the leaf file name. max-path-length 100 Maximum length of the full path. **Compliance:** Boost L001 No trailing whitespace --------------------------- *Trailing whitespace* is any whitespace character (space or tab) that is placed at the end of the source line, after other characters or alone. The presence of *trailing whitespace* artificially influences some source code metrics and is therefore discouraged. As a special case, the trailing whitespace in the otherwise empty lines is allowed provided that the amount of whitespace is identical to the indent in the previous line - this exception is more friendly with less smart editors, but can be switched off by setting non-zero value for the `strict-trailing-space` parameter. **Recognized parameters:** Name Default Description ------------------------- --------- -------------------------------------- strict-trailing-space 0 Strict mode for trailing whitespace. **Compliance:** Inspirel L002 Don't use tab characters ----------------------------- *Horizontal tabs* are not consistently handled by editors and tools. Avoiding them ensures that the intended formatting of the code is preserved. **Compliance:** HICPP, JSF L003 No leading and no trailing empty lines ------------------------------------------- *Leading and trailing empty lines* confuse users of various tools (like `head` and `tail`) and artificially influence some source code metrics. **Compliance:** Inspirel L004 Line cannot be too long ---------------------------- The source code line should not exceed some *reasonable* length. **Recognized parameters:** Name Default Description ------------------- --------- ------------------------------------- max-line-length 100 Maximum length of source code line. **Compliance:** Inspirel L005 There should not be too many consecutive empty lines --------------------------------------------------------- The empty lines (if any) help to introduce more "light" in the source code, but they should not be overdosed in the sense that too many consecutive empty lines make the code harder to follow. Lines containing only whitespace are considered to be empty in this context. **Recognized parameters:** Name Default Description ------------------------------- --------- -------------------------------------------- max-consecutive-empty-lines 2 Maximum number of consecutive empty lines. **Compliance:** Inspirel L006 Source file should not be too long --------------------------------------- The source file should not exceed a *reasonable* length. Long source files can indicate an opportunity for refactoring. **Recognized parameters:** Name Default Description ------------------- --------- ------------------------------------ max-file-length 2000 Maximum number of lines in a file. **Compliance:** Inspirel T001 One-line comments should not have forced continuation ---------------------------------------------------------- The one-line comment is a comment that starts with `//`. The usual intent is to let the comment continue till the end of the line, but the preprocessing rules of the language allow to actually continue the comment in the next line if *line-splicing* is forced with the backslash at the end of the line: ~~~~ void foo() { // this comment is continued in the next line \ exit(0); } ~~~~ It is not immediately obvious what happens in this example. Moreover, the line-splicing works only if the backslash is really the last character in the line - which is error prone because any white characters that might appear after the backslash will change the meaning of the program without being visible in the code. **Compliance:** Inspirel T002 Reserved names should not be used for preprocessor macros -------------------------------------------------------------- The C++ Standard reserves some forms of names for language implementations. One of the most frequent violations is a definition of preprocessor macro that begins with underscore followed by a capital letter or containing two consecutive underscores: ~~~~ #define _MY_MACRO something #define MY__MACRO something ~~~~ Even though the majority of known compilers use more obscure names for internal purposes and the above code is not likely to cause any significant problems, all such names are *formally reserved* and therefore should not be used. Apart from the use of underscore in macro names, preprocessor macros should not be used to redefine language keywords: ~~~~ #define private public #define const ~~~~ **Compliance:** ISO T003 Some keywords should be followed by a single space ------------------------------------------------------- Keywords from the following list: - `case` - `class` - `delete` - `enum` - `explicit` - `extern` - `goto` - `new` - `struct` - `union` - `using` should be followed by a single space for better readability. **Compliance:** Inspirel T004 Some keywords should be immediately followed by a colon ------------------------------------------------------------ Keywords from the following list: - `default` - `private` - `protected` - `public` should be immediately followed by a colon, unless used in the list of base classes: ~~~~ class A : public B, private C { public: A(); ~A(); protected: // ... private: // ... }; void fun(int a) { switch (a) { // ... default: exit(0); } } ~~~~ **Compliance:** Inspirel T005 Keywords break and continue should be immediately followed by a semicolon ------------------------------------------------------------------------------ The `break` and `continue` keywords should be immediately followed by a semicolon, with no other tokens in between: ~~~~ {.example} while (...) { if (...) { break; } if (...) { continue; } // ... } ~~~~ **Compliance:** Inspirel T006 Keywords return and throw should be immediately followed by a semicolon or a single space ---------------------------------------------------------------------------------------------- The `return` and `throw` keywords should be immediately followed by a semicolon or a single space: ~~~~ {.example} void fun() { if (...) { return; } // ... } int add(int a, int b) { return a + b; } ~~~~ An exception to this rule is allowed for exeption specifications: ~~~~ {.example} void fun() throw(); ~~~~ **Compliance:** Inspirel T007 Semicolons should not be isolated by spaces or comments from the rest of the code -------------------------------------------------------------------------------------- The semicolon should not stand isolated by whitespace or comments from the rest of the code. ~~~~ {.example} int a ; // bad int b ; // bad int c; // OK ~~~~ As an exception from this rule, semicolons surrounded by spaces are allowed in `for` loops: ~~~~ {.example} for ( ; ; ) // OK as an exception { // ... } ~~~~ **Compliance:** Inspirel T008 Keywords catch, for, if, switch and while should be followed by a single space ----------------------------------------------------------------------------------- Keywords `catch`, `for`, `if`, `switch` and `while` should be followed by a single space and then an opening left parenthesis: ~~~~ {.example} catch (...) { for (int i = 0; i != 10; ++i) { if (foo(i)) { while (getline(cin, line)) { switch (i % 3) { case 0: bar(line); break; // ... } } } } } ~~~~ **Compliance:** Inspirel T009 Comma should not be preceded by whitespace, but should be followed by one ------------------------------------------------------------------------------ A comma, whether used as operator or in various lists, should not be preceded by whitespace on its left side, but should be followed by whitespace on its right side: ~~~~ {.example} void fun(int x, int y, int z); int a[] = {5, 6, 7}; class A : public B, public C { // ... }; ~~~~ An exception to this rule is allowed for `operator,`: ~~~~ {.example} struct A {}; void operator,(const A &left, const A &right); ~~~~ **Compliance:** Inspirel T010 Identifiers should not be composed of 'l' and 'O' characters only ---------------------------------------------------------------------- The characters 'l' (which is lowercase 'L') and 'O' (which is uppercase 'o') should not be the only characters used in the identifier, because this would make them visually similar to numeric literals. **Compliance:** Inspirel T011 Curly brackets from the same pair should be either in the same line or in the same column ---------------------------------------------------------------------------------------------- Corresponding curly brackets should be either in the same line or in the same column. This promotes clarity by emphasising scopes, but allows concise style of one-line definitions and empty blocks: ~~~~ {.example} class MyException {}; struct MyPair { int a; int b; }; enum state { close, open }; enum colors { black, red, green, blue, white }; ~~~~ **Compliance:** Inspirel T012 Negation operator should not be used in its short form ----------------------------------------------------------- The negation operator (exclamation mark) reduces readability of the code due to its terseness. Prefer explicit logical comparisons or alternative tokens for increased readability: ~~~~ {.example} if (!cond) // error-prone if (cond == false) // better if (not cond) // better (alternative keyword) ~~~~ **Compliance:** Inspirel T013 Source files should contain the copyright notice ----------------------------------------------------- The copyright notice is required by man coding standards and guidelines. In some countries every written artwork has some copyright, even if implicit. Prefer explicit notice to avoid any later confusion. This rule verifies that at least one comment in the source file contains the "copyright" word. **Compliance:** Boost T014 Source files should refer the Boost Software License --------------------------------------------------------- The Boost Software License should be referenced in the source code. This rule verifies that at least one comment in the source file contains the "Boost Software License" phrase. Note that this rule is very specific to the Boost libraries and those project that choose to use the Boost license. It is therefore not part of the default profile. **Compliance:** Boost T015 HTML links in comments and string literals should be correct ----------------------------------------------------------------- The links embedded in comments and string literals should have correct form and should reference existing files. **Compliance:** Boost T016 Calls to min/max should be protected against accidental macro substitution ------------------------------------------------------------------------------- The calls to min and max functions should be protected against accidental macro substitution. ~~~~ {.example} x = max(y, z); // wrong, vulnerable to accidental macro substitution x = (max)(y, z); // OK x = max BOOST_PREVENT_MACRO_SUBSTITUTION (y, z); // OK ~~~~ **Compliance:** Boost T017 Unnamed namespaces are not allowed in header files ------------------------------------------------------- Unnamed namespaces are not allowed in header files. The typical use of unnamed namespace is to hide module-internal names from the outside world. Header files are physically concatenated in a single translation unit, which logically merges all namespaces with the same name. Unnamed namespaces are also merged in this process, which effectively undermines their initial purpose. Use named namespaces in header files. Unnamed namespaces are allowed in implementation files only. **Compliance:** Boost T018 Using namespace is not allowed in header files --------------------------------------------------- Using namespace directives are not allowed in header files. The using namespace directive imports names from the given namespace and when used in a header file influences the global namespace of all the files that directly or indirectly include this header file. It is imaginable to use the using namespace directive in a limited scope in a header file (for example in a template or inline function definition), but for the sake of consistency this is also discouraged. **Compliance:** C++ Coding Standards T019 Control structures should have complete curly-braced block of code ----------------------------------------------------------------------- Control structures managed by for, if and while constructs can be associated with a single instruction or with a complex block of code. Standardizing on the curly-braced blocks in all cases allows to avoid common pitfalls and makes the code visually more uniform. ~~~~ {.example} if (x) foo(); // bad style if (x) { foo(); } // OK if (x) foo(); // again bad style if (x) { // OK foo(); } if (x) while (y) // bad style foo(); // bad style if (x) { // OK while (y) { // OK foo(); } } for (int i = 0; i = 10; ++i); // oops! cout << "Hello\n"; for (int i = 0; i = 10; ++i) // OK { cout << "Hello\n"; } ~~~~ **Compliance:** Inspirel vera++-1.2.1/wiki/Running.md000644 000765 000024 00000026660 12151366432 016454 0ustar00glehmannstaff000000 000000 Running Vera++ ============= Vera++ needs to know where the rules and transformation scripts are located. The following rules are applied: * If the `--root` option is used, its argument is used as the name of the directory where the `scripts` subdirectory with scripts should be located, otherwise * If the `VERA_ROOT` environment variable is defined, it is used as the name of the directory where the `scripts` subdirectory with scripts should be located, otherwise * If the `HOME` environment variable is defined, then the `~/.vera++` directory is used (and it should contain the `scripts` subdirectory with scripts), otherwise * The current directory should contain the `scripts` subdirectory. Options ------- Vera++ recognizes the following parameters: `-` : (a single minus) indicates that the source code to check will be provided on the stdin. `-p` `--profile` _profilename_ : instructs the program to execute all rules defined in the given profile; the profile name is just a name of the file that will be found under the `profiles` directory, the content of this file is a Tcl script that must set a `rules` variable to be the list of all rules that are part of the profile. An example profile definition that groups three rules (L001, L002 and L003) might look like: set rules { L001 L002 L003 } There is always a `default` profile that lists all existing rules - it is used when no profile is named explicitly. `-R` `--rule` _rulename_ : instructs the program to execute the given rule; note that the name of the rule should not contain the file extension of the script implementing the rule - this is added automatically, so that for example `--rule my_rule` means that Vera++ will find the `my_rule.tcl` script and will run it. `--transform` _transformationname_ : instructs the program to execute a single named transformation; the naming scheme is the same as for the `--rule` option. `-o` `--std-report` _filename_ : writes the standard (gcc-like) report to this file. A single dash `-` means that the standard output or the error output will be used, depending on the usage of the `--warning` or `--error` option. This option may be used several times in order to produce the reports in several locations - for example on the standard output and in a file. Default value is `-`. `-v` `--vc-report` _filename_ : writes the Visual C report to this file. A single dash `-` means that the standard output or the error output will be used, depending on the usage of the `--warning` or `--error` option. This option may be used several times in order to produce the reports in several locations - for example on the standard output and in a file. This report is not produced by default. `-x` `--xml-report` _filename_ : writes the XML report to this file. Not used by default. A single dash `-` means that the standard output or the error output will be used, depending on the usage of the `--warning` or `--error` option. This option may be used several times in order to produce the reports in several locations - for example on the standard output and in a file. This report is not produced by default. `-c` `--checkstyle-report` _filename_ : writes the checkstyle report to this file. Not used by default. A single dash `-` means that the standard output or the error output will be used, depending on the usage of the `--warning` or `--error` option. This option may be used several times in order to produce the reports in several locations - for example on the standard output and in a file. This report is not produced by default. `-s` `--show-rule` : includes the name of the rule in each report line. `-d` `--no-duplicate` : instructs the program to omit duplicated messages in the final report (the duplicates can be a result of violating the same rule many times in the same line of source code). `-w` `--warning` : reports are marked as warning and generated on the error output. `-e` `--error` : reports are marked as error and generated on the error output. An non zero exit code is used when one or more reports are generated. `-q` `--quiet` : don't display the reports. This option is best used with `--summary` and/or with `--error`. `-S` `--summary` : displays the number of reports and the number of processed files. `--parameters` _filename_ : instructs the program to read parameter values from the given file; each parameter association should be placed in a separate line of this file. This option may be used several times. `-P` `--parameter` _parameterassociation_ : provides the value of the named parameter to the scripts (see the documentation of each script to see whether it recognizes any parameters); the parameter association has the form `name=value`. `--exclusions` _exclusionsfilename_ : instructs the program to exclude some source files from rule checks, as described in the given file; the content of this file is a Tcl script that must set a `ruleExclusions` array, where keys are rule names and values are lists of files to omit for the given rule. For example: set ruleExclusions(L002) { some_file.cpp } set ruleExclusions(T005) { some_file.cpp some_other_file.cpp } Note that the given file names are compared for exact match with the source file names that are provided as parameters to Vera++. This means that links in paths are not resolved for comparison purposes. This option may be used several times. `-i` `--inputs` _filename_ : the inputs are read from that file. A single dash `-` means that the files to check will be read from the standard input. This option may be used several times. `-r` `--root` _path_ : uses the given path as the vera++ root directory `--version` : prints the program version information and exits. `-h` `--help` : prints the list of recognized options and exits. `--` : (a double dash) do not interpret any more arguments as options. Arguments that are not starting with a dash `-` are treated as source files to check. Files starting with a dash can be checked by prefixing them with the current directory shortcut `./`. When no input file is provided either as an argument or with the `--input` option, the list of source file names is read from the standard input. Examples of executing Vera++ with rules --------------------------------------- To execute all default verification rules against the file `file.cpp`, run: vera++ file.cpp To execute only rule `L001` (this rule ensures that there is no trailing whitespace in each source line) against the same file, run: vera++ -R L001 file.cpp To execute rule `L004` (this rule checks for too long source lines) with the parameter value providing 78 as the maximum line length, run: vera++ -R L004 -P max-line-length=78 file.cpp To execute all rules from your favorite profile (assuming that the `my_favorite` profile definition is stored in the `profiles` directory) against all header files in the current filesystem subtree, run: find . -name '*.h' | vera++ --profile my_favorite __Note:__ Vera++ collects the reports generated by each rule and prints them out sorted and after all rules were executed. If there were no problem reports, the output of the program is empty. __Note:__ Vera++ reports are generated on the standard output by default, making them easy to use with a pipe. The `--warning` and `--error` options are changing the output to the standard error. The options `--std-report`, `--vc-report`, `--xml-report` and `--quiet` may be used to disable the output to the standard or error output. Examples of executing Vera++ with transformations ------------------------------------------------- To execute the `trim_right` source code transformation (it removes the trailing whitespace that the rule `L001` above complained about) on all `.cpp` files in the current directory run: vera++ --transform trim_right *.cpp As a result, each `.cpp` file will be backed up with the additional extension `.bak` and the files will be trimmed by removing trailing whitespace. The exact behavior is defined by the script named `trim_right.tcl` in the `scripts/transformations` directory. Running Vera++ as a test with CMake ----------------------------------- CMake offers the possibility to run tests that are considered to pass when they return a 0 value and to fail otherwise. Fortunately, vera++, when used with the `--error` option, has exactly this behavior. Creating the test is just a matter of listing the sources to check: file(GLOB_RECURSE srcs ${CMAKE_SOURCE_DIR}/src/*.cpp ${CMAKE_SOURCE_DIR}/src/*.h) add_test(NAME VeraStyle COMMAND vera++ --error ${srcs}) Running Vera++ during the build with CMake ------------------------------------------ Running vera++ in a test integrates quite badly with the IDEs or with [CDash](http://cdash.org): the reports are hidden in the test log, and it is not easy to look at the problematic code. Moreover, a failure in the coding style is not the same as a failure in a unit or functional test, and shouldn't appear in the same way. Another option is to run vera++ during the build and make it generate warnings that are well interpreted by the IDEs and CDash. In QtCreator for instance, it is then possible to click on the warning to go to the problematic code. Running vera++ during the build can be done in a similar way to the previous section, by replacing the `add_test()` call with a `add_custom_target()` that will run the style check every time the custom target is built. file(GLOB_RECURSE srcs ${CMAKE_SOURCE_DIR}/src/*.cpp ${CMAKE_SOURCE_DIR}/src/*.h) add_custom_target(VeraStyle ALL vera++ --warning ${srcs}) For large projects, running the style check every time can be quite time consuming and uncomfortable for the developer. It is then more convenient to split the style check in several parts that can be run in parallel, and to avoid rerunning the check if the files to check have not been modified. A vera++ macro is available to do that very easily: find_package(vera++) include(${VERA++_USE_FILE}) add_vera_targets(*.h *.cpp RECURSE ROOT "${CMAKE_SOURCE_DIR}") This macro adds a new `style_reports` target that is run every time a source file is modified. A `style` target is still available to force the style check. The target names can be configured with the parameters `NAME` and `NAME_ALL`. This macro is the recommended way to use vera++ with CMake. Backward compatibility with vera++ 1.1 -------------------------------------- Vera++ is still mostly compatible with the vera++ 1.1 command line interface, but this feature is planned for removal and its usage is not recommended. Vera++ tries to detect if the old command line style is used by searching for the old options in the arguments. If no old style option is found, vera++ uses the new command line parser. The command line style can be forced to the old style by setting the environment variable `VERA_LEGACY` to `on`, `true` or `1`. Any other value will force vera++ to use the new command line style. Note: the behavior of vera++ is not backward compatible with vera++ 1.1 when no option is passed to vera++ and `VERA_LEGACY` is not set: * the reports are generated on the standard output instead of the error output; * a single dash `-` means that the source code to check is read from the standard input instead of reading the list of files to check; * the lack of input files makes vera++ read the standard input instead of generating an error. vera++-1.2.1/wiki/Screenshots.md000644 000765 000024 00000001170 12151440347 017317 0ustar00glehmannstaff000000 000000 Screenshots =========== Everybody loves screenshots! Vera++ is a text only tool with no GUI, but it works smoothly with many graphical tools. QtCreator --------- [![Vera++ in QtCreator](images/qtcreator.png)](images/qtcreator.png) Microsoft Visual C++ 2010 ------------------------- [![Vera++ in Microsoft Visual C++ 2010](images/msvc10.png)](images/msvc10.png) XCode ----- [![Vera++ in Xcode](images/xcode.png)](images/xcode.png) CDash ----- [![Vera++ in CDash](images/cdash.png)](images/cdash.png) More screenshots ---------------- Feel free to add more screenshots showing how well vera++ integrates with your tools!vera++-1.2.1/wiki/ScriptAPI.md000644 000765 000024 00000015710 12136220216 016614 0ustar00glehmannstaff000000 000000 Script API ========== The scripts (rules and transformations) are written in Tcl and are executed by the embedded interpreter that has access to relevant state of the program. A set of commands is provided to enable easy read-only operation on the information that was gathered by parsing given source files. The following Tcl commands are provided: - **`getSourceFileNames`** - returns the list of file names that were provided to Vera++ as program parameters. - **`getLineCount fileName`** - returns the number of lines in the given source file. - **`getAllLines fileName`** - returns the list of lines, in their natural order, that form a give source file. - **`getLine fileName lineNumber`** - returns the selected line; line numbers are counted from 1. - **`getTokens fileName fromLine fromColumn toLine toColumn filter`** - returns the list of tokens, in their natural order, from the given source file and that match the given selection criteria. The meaning of arguments for selecting tokens is: - **`fromLine`** - the lowest line number (counted from 1), inclusive - **`fromColumn`** - the lowest column number (counted from 0), inclusive - **`toLine`** - the highest line number, inclusive; -1 means that the selected range spans to the end of the file - **`toColumn`** - the highest column number, exclusive; -1 means that the selected range spans to the end of the line defined by `toLine`. - **`filter`** - the list of selected token types, the recognized token types are listed below; if this list is empty, then all token types are allowed. The `getTokens` command returns a list of lists - the nested lists have the following elements: - *value* - the literal text of the token - *lineNumber* - the line number (from 1) where the token appears - *columnNumber* - the column number (from 0) where the token appears - *name* - the name or type of the token; see below for the list of recognized token types - **`getParameter name defaultValue`** - returns the value of the given parameter or the provided default value if no such parameter is defined. - **`report fileName lineNumber message`** - registers a report for the given file and line; this report is printed at the end of the program execution, sorted by file and line number. Use this command to generate output that is compatible with the warning/error output format of popular compilers. Examples: --------- To process all lines from all source files, use the following code pattern: foreach fileName [getSourceFileNames] { foreach line [getAllLines $fileName] { # ... } } To process all tokens from all source files, use: foreach fileName [getSourceFileNames] { foreach token [getTokens $fileName 1 0 -1 -1 {}] { set tokenValue [lindex $token 0] set lineNumber [lindex $token 1] set columnNumber [lindex $token 2] set tokenType [lindex $token 3] # ... } } To process only curly braces from the given source file, use: foreach token [getTokens $fileName 1 0 -1 -1 {leftbrace rightbrace}] { # ... } The complete rule script for verifying that the lines are no longer than some limit (the limit can be provided as a parameter, but the default value is defined in by the script itself): # Line cannot be too long set maxLength [getParameter "max-line-length" 100] foreach f [getSourceFileNames] { set lineNumber 1 foreach line [getAllLines $f] { if {[string length $line] > $maxLength} { report $f $lineNumber "line is longer than ${maxLength} characters" } incr lineNumber } } The above script is actually the implementation of rule L004. Notes about line splicing ------------------------- As required by the C++ ISO standard, the line splicing (with the backslash at the end of the line) is performed before tokenizing. This means that the lists of tokens might not strictly fit the list of lines. Due to the internal mechanisms of the parser, the line splicing freezes the line counter and forces the column counter to continue until the last line in the spliced block. This means that there might be physical non-empty lines that apparently don't have any tokens, as well as tokens that have column numbers not matching the physical source line lengths. Recognized token types ---------------------- The following token types are recognized by the parser and can be used for filter selection in the `getTokens` command (some of these token types are related to compiler extensions): and andand andassign any arrow arrowstar asm assign auto bool break case catch ccomment char charlit class colon colon_colon comma compl const constcast continue contline cppcomment decimalint default delete divide divideassign do dot dotstar double dynamiccast ellipsis else enum eof eoi equal explicit export extern false float floatlit for friend goto greater greaterequal hexaint identifier if inline int intlit leftbrace leftbracket leftparen less lessequal long longintlit minus minusassign minusminus msext_asm msext_based msext_cdecl msext_declspec msext_endregion msext_except msext_fastcall msext_finally msext_inline msext_int16 msext_int32 msext_int64 msext_int8 msext_leave msext_region msext_stdcall msext_try mutable namespace new newline not notequal octalint operator or orassign oror percent percentassign plus plusassign plusplus pound pound_pound pp_define pp_elif pp_else pp_endif pp_error pp_hheader pp_if pp_ifdef pp_ifndef pp_include pp_line pp_number pp_pragma pp_qheader pp_undef pp_warning private protected public question_mark register reinterpretcast return rightbrace rightbracket rightparen semicolon shiftleft shiftleftassign shiftright shiftrightassign short signed sizeof space space2 star starassign static staticcast stringlit struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchart while xor xorassign Note ---- There is a predefined rule named `DUMP` that prints on the screen all tokens with their types and position. This rule can be helpful as a guideline for creating custom filtering criteria: vera++ --rule DUMP myfile.cpp vera++-1.2.1/wiki/Transformations.md000644 000765 000024 00000017047 12131557275 020231 0ustar00glehmannstaff000000 000000 Transformations =============== move\_includes Change prefix of \#include paths ----------------------------------------------- This transformation allows to modify the prefix of file paths in \#include directives. The motivation for this transformation is to help move whole libraries from one file tree to another. Please use this transformation as a boilerplate for your own customized version. For example, the following file: ~~~~ #include "boost/shared_ptr.hpp" #include "boost/bind.hpp" ~~~~ will be transformed into: ~~~~ #include "boom/shared_ptr.hpp" #include "boom/bind.hpp" ~~~~ Note: The transformation is performed in place, which means that the source files are modified. move\_macros Change prefix in macros ------------------------------------ This transformation allows to modify the prefix of macros. The motivation for this transformation is to help move whole libraries or source sets from one naming conventioin to another. Please use this transformation as a boilerplate for your own customized version. For example, the following file: ~~~~ #define BOOST_SOME_MACRO 1 // ... #ifdef BOOST_SOME_MACRO // ... #endif ~~~~ will be transformed into: ~~~~ #define BOOM_SOME_MACRO 1 // ... #ifdef BOOM_SOME_MACRO // ... #endif ~~~~ Note: This transformation actually does not check whether the given identifier is indeed a macro name and the prefix replacement is performed systematically on all identifiers that match. Note: The transformation is performed in place, which means that the source files are modified. move\_namespace Change namespace name ------------------------------------- This transformation allows to consistently change the namespace name. The motivation for this transformation is to help move whole libraries or source sets from one namespace to another, for example to allow the coexistence of two different version of the same library. Please use this transformation as a boilerplate for your own customized version. For example, the following file: ~~~~ namespace boost { void foo(); } void boost::foo() {/* ... */} ~~~~ will be transformed into: ~~~~ namespace boom { void foo(); } void boom::foo() {/* ... */} ~~~~ Note: This transformation actually does not check whether the given identifier is indeed a namespace name and the replacement is performed systematically on all identifiers that match. Do not use it on code that overloads namespace names for other purposes. Note: The transformation is performed in place, which means that the source files are modified. to\_lower Change identifier naming convention from CamelCase to standard\_lowercase ----------------------------------------------------------------------------------- This transformation allows to modify the naming convention of all identifiers from CamelCase to standard\_lowercase, as used by the standard library or Boost. For example, the following code: ~~~~ namespace MyTools { class MyClass { public: void myFunction(); }; } ~~~~ will be transformed into this: ~~~~ namespace my_tools { class my_class { public: void my_function(); }; } ~~~~ Note: The transformation is performed in place, which means that the source files are modified. Note: This transformation does not modify comments and string literals. to\_xml Transform C++ code into XML ----------------------------------- This transformation generates a XML tree where nodes relate to C++ source code tokens. For example, the following file (file.cpp): ~~~~ #include int main() { std::cout << "Hello World\n"; } ~~~~ will be transformed into new file named file.cpp.xml: ~~~~ #include <iostream> ![CDATA[ ]] ![CDATA[ ]] int main ( ) ![CDATA[ ]] { ![CDATA[ ]] std :: cout << "Hello World\n" ; ![CDATA[ ]] } ![CDATA[ ]] ~~~~ Note: If the source code does not use line splicing, then concatenation of all XML node values is equivalent to the original C++ code. to\_xml2 Transform C++ code into XML (another variant) ------------------------------------------------------ This transformation generates a XML tree where nodes relate to C++ source code tokens. The difference between this version and the one named to\_xml is that here nodes have names related to token types, which can make it easier for some further XML transformations. For example, the following file (file.cpp): ~~~~ #include int main() { std::cout << "Hello World\n"; } ~~~~ will be transformed into new file named file.cpp.xml: ~~~~ #include <iostream> ![CDATA[ ]] ![CDATA[ ]] int main ( ) ![CDATA[ ]] { ![CDATA[ ]] std :: cout << "Hello World\n" ; ![CDATA[ ]] } ![CDATA[ ]] ~~~~ Note: If the source code does not use line splicing, then concatenation of all XML node values is equivalent to the original C++ code. trim\_right Remove trailing white space --------------------------------------- This transformation removes the trailing whitespace from each line of code. It can be treated as a quick remedy for problems reported by rule L001. Note: The transformation is performed in place, which means that the source files are modified.