mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Don't generate prototypes for function that already have them. (Lars J. Nielsen)
This searches for prototypes by using the same regular expression used to search for functions definitions, but with "{}" replaced by ";". Note that it requires the prototype to be formatted identically to the function definition (e.g. matching white-space). http://code.google.com/p/arduino/issues/detail?id=973
This commit is contained in:
parent
a01657b312
commit
d30bd83660
@ -316,13 +316,31 @@ public class PdePreprocessor {
|
||||
|
||||
// XXX: doesn't handle ... varargs
|
||||
// XXX: doesn't handle function pointers
|
||||
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||
Pattern prototypePattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*;)");
|
||||
Pattern functionPattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||
|
||||
ArrayList<String> matches = new ArrayList<String>();
|
||||
Matcher matcher = pattern.matcher(in);
|
||||
while (matcher.find())
|
||||
matches.add(matcher.group(0) + ";");
|
||||
// Find already declared prototypes
|
||||
ArrayList<String> prototypeMatches = new ArrayList<String>();
|
||||
Matcher prototypeMatcher = prototypePattern.matcher(in);
|
||||
while (prototypeMatcher.find())
|
||||
prototypeMatches.add(prototypeMatcher.group(0) + ";");
|
||||
|
||||
return matches;
|
||||
// Find all functions and generate prototypes for them
|
||||
ArrayList<String> functionMatches = new ArrayList<String>();
|
||||
Matcher functionMatcher = functionPattern.matcher(in);
|
||||
while (functionMatcher.find())
|
||||
functionMatches.add(functionMatcher.group(0) + ";");
|
||||
|
||||
// Remove generated prototypes that exactly match ones found in the source file
|
||||
for (int functionIndex=functionMatches.size() - 1; functionIndex >= 0; functionIndex--) {
|
||||
for (int prototypeIndex=0; prototypeIndex < prototypeMatches.size(); prototypeIndex++) {
|
||||
if ((functionMatches.get(functionIndex)).equals(prototypeMatches.get(prototypeIndex))) {
|
||||
functionMatches.remove(functionIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return functionMatches;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user