1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 04:15:35 +02:00

Fix the parser

This commit is contained in:
Alain Magloire 2003-09-10 03:10:10 +00:00
parent 9c9ed44482
commit 79a8a117d0

View file

@ -67,7 +67,7 @@ public class PosixMakefile extends AbstractMakefile {
void parse(MakefileReader reader) throws IOException { void parse(MakefileReader reader) throws IOException {
String line; String line;
Rule rule = null; Rule[] rules = null;
int startLine = 0; int startLine = 0;
int endLine = 0; int endLine = 0;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -77,10 +77,13 @@ public class PosixMakefile extends AbstractMakefile {
// 1- Try command first, since we do not strip '#' in commands // 1- Try command first, since we do not strip '#' in commands
if (MakefileUtil.isCommand(line)) { if (MakefileUtil.isCommand(line)) {
Command cmd = new Command(line); Command cmd = new Command(line);
cmd.setLines(startLine, endLine);
// The commands are added to a Rule // The commands are added to a Rule
if (rule != null) { if (rules != null) {
rule.addCommand(cmd); for (int i = 0; i < rules.length; i++) {
rule.setEndLine(endLine); rules[i].addCommand(cmd);
rules[i].setEndLine(endLine);
}
continue; continue;
} }
// If it is not a command give the other rules a chance a fallthrough // If it is not a command give the other rules a chance a fallthrough
@ -119,13 +122,23 @@ public class PosixMakefile extends AbstractMakefile {
} else { } else {
tgt = line; tgt = line;
} }
rule = new InferenceRule(new Target(tgt)); InferenceRule irule = new InferenceRule(new Target(tgt));
rule.setLines(startLine, endLine); irule.setLines(startLine, endLine);
addStatement(rule); addStatement(irule);
rules = new Rule[]{irule};
continue; continue;
} }
// 5- Target Rule ? // 5- Macro Definiton ?
if (MakefileUtil.isMacroDefinition(line)) {
// MacroDefinition
Statement stmt = new MacroDefinition(line);
stmt.setLines(startLine, endLine);
addStatement(stmt);
continue;
}
// 6- Target Rule ?
if (MakefileUtil.isTargetRule(line)) { if (MakefileUtil.isTargetRule(line)) {
String[] targets; String[] targets;
String[] reqs = new String[0]; String[] reqs = new String[0];
@ -154,26 +167,20 @@ public class PosixMakefile extends AbstractMakefile {
for (int i = 0; i < reqs.length; i++) { for (int i = 0; i < reqs.length; i++) {
preqs[i] = new Target(reqs[i]); preqs[i] = new Target(reqs[i]);
} }
rules = new Rule[targets.length];
for (int i = 0; i < targets.length; i++) { for (int i = 0; i < targets.length; i++) {
rule = new TargetRule(new Target(targets[i]), preqs); Rule rule = new TargetRule(new Target(targets[i]), preqs);
rule.setLines(startLine, endLine); rule.setLines(startLine, endLine);
addStatement(rule); addStatement(rule);
if (cmd != null) { if (cmd != null) {
rule.addCommand(new Command(cmd)); rule.addCommand(new Command(cmd));
} }
rules[i] = rule;
} }
continue; continue;
} }
// 6- Macro Definiton ?
if (MakefileUtil.isMacroDefinition(line)) {
// MacroDefinition
Statement stmt = new MacroDefinition(line);
stmt.setLines(startLine, endLine);
addStatement(stmt);
continue;
}
// Other type of processing ? // Other type of processing ?
Statement stmt = processLine(line); Statement stmt = processLine(line);
if (stmt == null) { if (stmt == null) {