Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 89fec47

Browse files
committed
Added partial sketch prototype resolving
It detects which prototypes need to be generated, based on the def-dec matching ability previously added
1 parent 2522892 commit 89fec47

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

cmake/Platform/Sketches/SketchManager.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function(add_sketch_to_target _target_name _sketch_file)
3131
if (CONVERT_SKETCHES_IF_CONVERTED_SOURCES_EXISTS OR NOT EXISTS ${sketch_converted_source_path})
3232

3333
resolve_sketch_headers(${_target_name} ${_sketch_file} sketch_headers)
34-
3534
resolve_sketch_libraries(${_target_name} ${_sketch_file} "${sketch_headers}")
35+
resolve_sketch_prototypes(${_sketch_file} "${sketch_headers}" sketch_prototypes)
3636

3737
convert_sketch_to_source(${_sketch_file} ${sketch_converted_source_path})
3838

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function(resolve_sketch_prototypes _sketch_file _resolved_sketch_headers _return_var)
2+
3+
get_source_function_definitions(${_sketch_file} sketch_func_defines)
4+
if (NOT sketch_func_defines) # Source has no function definitions at all
5+
return()
6+
endif ()
7+
8+
list(APPEND _resolved_sketch_headers "${_sketch_file}")
9+
10+
foreach (func_def ${sketch_func_defines})
11+
12+
match_function_declaration("${func_def}" "${_resolved_sketch_headers}" match)
13+
14+
if (${match} MATCHES "NOTFOUND")
15+
# ToDo: Append signature to list of prototypes to create
16+
message("Coludn't find a matching declaration for `${func_def}`")
17+
endif ()
18+
19+
endforeach ()
20+
21+
endfunction()

cmake/Platform/Sketches/SketchSourceConverter.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function(convert_sketch_to_source _sketch_file _converted_source_path)
9595

9696
file(STRINGS "${_sketch_file}" sketch_loc)
9797

98-
set(header_insert_pattern "${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN}|${ARDUINO_CMAKE_FUNCTION_REGEX_PATTERN}")
98+
set(header_insert_pattern
99+
"${ARDUINO_CMAKE_HEADER_INCLUDE_REGEX_PATTERN}|${ARDUINO_CMAKE_FUNCTION_DEFINITION_REGEX_PATTERN}")
99100
set(header_inserted FALSE)
100101

101102
list(LENGTH sketch_loc num_of_loc)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include(SketchHeadersResolver)
22
include(SketchLibrariesResolver)
3+
include(SketchPrototypesResolver)
34
include(SketchSourceConverter)
45
include(SketchManager)

examples/sketch/sketch2.pde

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
int x = 5;
44

5+
int bar(short, int b);
6+
57
void foo()
68
{
79
Serial.print(x);
10+
bar(5, 6);
811
}

0 commit comments

Comments
 (0)