Skip to content

Commit ad394cf

Browse files
authored
Merge pull request #34 from Knaldgas/Ada-support
Added support for Ada code.
2 parents ceb182a + 00cb407 commit ad394cf

File tree

11 files changed

+147
-5
lines changed

11 files changed

+147
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15.5)
22
project(duplo)
33
file(GLOB SOURCES src/*.cpp)
44

5-
SET(DUPLO_VERSION "\"v1.0.0\"" CACHE STRING "Duplo version")
5+
SET(DUPLO_VERSION "\"v1.0.1\"" CACHE STRING "Duplo version")
66

77
if(MSVC)
88
else()

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM alpine:3.11 AS build
2-
ARG DUPLO_VERSION=v1.0.0
2+
ARG DUPLO_VERSION=v1.0.1
33

44
RUN apk --no-cache add \
55
alpine-sdk cmake

compile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# to run this, first set the DUPLO_VERSION environment variable. Otherwise
33
# some of the tests might fail. So, do this:
4-
# > export DUPLO_VERSION=v1.0.0
4+
# > export DUPLO_VERSION=v1.0.1
55
p() {
66
now="$(date +'%r')"
77
printf "$(tput setaf 1)%s$(tput sgr0) | $(tput bold)$1$(tput sgr0)\n" "$now";

src/FileTypeFactory.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "FileType_S.h"
55
#include "FileType_Unknown.h"
66
#include "FileType_VB.h"
7+
#include "FileType_Ada.h"
78
#include "StringUtil.h"
89

910
#include <algorithm>
@@ -23,6 +24,8 @@ IFileTypePtr FileTypeFactory::CreateFileType(
2324
fileType.reset(new FileType_S(ignorePrepStuff, minChars));
2425
else if (ext == "vb")
2526
fileType.reset(new FileType_VB(ignorePrepStuff, minChars));
27+
else if (ext == "ads" || ext == "adb")
28+
fileType.reset(new FileType_Ada(ignorePrepStuff, minChars));
2629
else
2730
fileType.reset(new FileType_Unknown(minChars));
2831
return fileType;

src/FileType_Ada.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "FileType_Ada.h"
2+
#include "CstyleUtils.h"
3+
#include "NoopLineFilter.h"
4+
#include "SourceLine.h"
5+
6+
#include <cstring>
7+
8+
FileType_Ada::FileType_Ada(bool ignorePrepStuff, unsigned minChars)
9+
: FileTypeBase(ignorePrepStuff, minChars) {
10+
}
11+
12+
ILineFilterPtr FileType_Ada::CreateLineFilter() const {
13+
return std::make_shared<NoopLineFilter>();
14+
}
15+
16+
std::string FileType_Ada::GetCleanLine(const std::string& line) const {
17+
std::string cleanedLine(line.substr(0, line.find("--")));
18+
return cleanedLine;
19+
}
20+
21+
bool FileType_Ada::IsPreprocessorDirective(const std::string& line) const {
22+
// look for other markers to avoid
23+
const char* markers[] = { "pragma", "with", "use" };
24+
25+
size_t first = line.find_first_not_of(" \t\r\n");
26+
if (first != std::string::npos)
27+
first = 0;
28+
29+
for (auto v : markers) {
30+
if (line.find(v, first, std::strlen(v)) != std::string::npos)
31+
return true;
32+
}
33+
34+
return false;
35+
}

src/FileType_Ada.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef _FILETYPE_ADA_H_
2+
#define _FILETYPE_ADA_H_
3+
4+
#include "FileTypeBase.h"
5+
6+
struct FileType_Ada : public FileTypeBase {
7+
FileType_Ada(bool ignorePrepStuff, unsigned minChars);
8+
9+
ILineFilterPtr CreateLineFilter() const override;
10+
11+
std::string GetCleanLine(const std::string& line) const override;
12+
13+
bool IsPreprocessorDirective(const std::string& line) const override;
14+
};
15+
16+
#endif

src/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace {
5151

5252
std::cout << "\nDESCRIPTION\n";
5353
std::cout << " Duplo is a tool to find duplicated code blocks in large\n";
54-
std::cout << " C/C++/Java/C#/VB.Net software systems.\n\n";
54+
std::cout << " C/C++/Java/C#/VB.Net/Ada software systems.\n\n";
5555

5656
std::cout << " -ml minimal block size in lines (default is " << MIN_BLOCK_SIZE << ")\n";
5757
std::cout << " -pt percentage of lines of duplication threshold to override -ml\n";

tests/Simple_Ada/simple_log.adb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
with Ada.Text_IO;
2+
3+
package body Simple_Log is
4+
5+
use Ada.Text_IO;
6+
7+
--
8+
Current_Output_Level : Output_Level_Type := Info;
9+
10+
--
11+
procedure Set_Output (New_Output_Level : in Output_Level_Type) is
12+
begin
13+
Current_Output_Level := New_Output_Level;
14+
end Set_Output;
15+
16+
--
17+
procedure Error (Message : in String) is
18+
begin
19+
if Current_Output_Level >= Error then
20+
Put_Line (Standard_Error, Message); -- For errors
21+
-- Comments should be ignored, also as lines in between
22+
end if;
23+
end Error;
24+
25+
--
26+
procedure Warning (Message : in String) is
27+
begin
28+
if Current_Output_Level >= Warning then
29+
Put_Line (Standard_Error, Message); -- For warnings
30+
end if;
31+
end Warning;
32+
33+
--
34+
procedure Info (Message : in String) is
35+
begin
36+
if Current_Output_Level >= Info then
37+
Put_Line (Standard_Error, Message); -- For info
38+
end if;
39+
end Info;
40+
41+
--
42+
procedure Debug (Message : in String) is
43+
begin
44+
if Current_Output_Level >= Debug then
45+
Put_Line (Standard_Error, Message); -- For debug
46+
end if;
47+
end Debug;
48+
49+
end Simple_Log;

tests/Simple_Ada/simple_log.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/Simple_Ada/simple_log.adb

tests/Simple_Ada/tests.bats

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
setup() {
2+
run ./build/duplo -ml 2 tests/Simple_Ada/simple_log.lst out.txt
3+
}
4+
5+
@test "simple_log.adb" {
6+
[ "$status" -eq 0 ]
7+
[ "${lines[0]}" = "Loading and hashing files ... 2 done." ]
8+
[ "${lines[1]}" = "tests/Simple_Ada/simple_log.adb found: 6 block(s)" ]
9+
}
10+
11+
@test "simple_log.adb out.txt" {
12+
run cat out.txt
13+
printf 'Lines:\n'
14+
printf 'lines %s\n' "${lines[@]}" >&2
15+
printf 'output %s\n' "${output[@]}" >&2
16+
[ "${lines[0]}" = "tests/Simple_Ada/simple_log.adb(29)" ]
17+
[ "${lines[1]}" = "tests/Simple_Ada/simple_log.adb(20)" ]
18+
[ "${lines[4]}" = "tests/Simple_Ada/simple_log.adb(37)" ]
19+
[ "${lines[5]}" = "tests/Simple_Ada/simple_log.adb(29)" ]
20+
[ "${lines[8]}" = "tests/Simple_Ada/simple_log.adb(45)" ]
21+
[ "${lines[9]}" = "tests/Simple_Ada/simple_log.adb(37)" ]
22+
[ "${lines[12]}" = "tests/Simple_Ada/simple_log.adb(37)" ]
23+
[ "${lines[13]}" = "tests/Simple_Ada/simple_log.adb(20)" ]
24+
[ "${lines[16]}" = "tests/Simple_Ada/simple_log.adb(45)" ]
25+
[ "${lines[17]}" = "tests/Simple_Ada/simple_log.adb(29)" ]
26+
[ "${lines[20]}" = "tests/Simple_Ada/simple_log.adb(45)" ]
27+
[ "${lines[21]}" = "tests/Simple_Ada/simple_log.adb(20)" ]
28+
[ "${lines[24]}" = "Configuration:" ]
29+
[ "${lines[25]}" = " Number of files: 1" ]
30+
[ "${lines[26]}" = " Minimal block size: 2" ]
31+
[ "${lines[27]}" = " Minimal characters in line: 3" ]
32+
[ "${lines[28]}" = " Ignore preprocessor directives: 0" ]
33+
[ "${lines[29]}" = " Ignore same filenames: 0" ]
34+
[ "${lines[30]}" = "Results:" ]
35+
[ "${lines[31]}" = " Lines of code: 33" ]
36+
[ "${lines[32]}" = " Duplicate lines of code: 12" ]
37+
[ "${lines[33]}" = " Total 6 duplicate block(s) found." ]
38+
}

0 commit comments

Comments
 (0)