private void positionForIfDef(IfDef ifdef) { if (ifdef == IfDef.If) { _locationHierarchyActivity = new List <LocationHierarchyActivity>(); } else if (ifdef == IfDef.Else) { revertLocationHierarchy(); } }
private void positionForIfDef(IfDef ifdef) { if (ifdef == IfDef.If) _locationHierarchyActivity = new List<LocationHierarchyActivity>(); else if (ifdef == IfDef.Else) revertLocationHierarchy(); }
List<object> GetDefs(string unitText) { var defs = new List<object>(); IfDef currentIf = null; var dirEnd = 0; while (true) { var dirStart = unitText.IndexOf("{$", dirEnd); if (dirStart == -1) break; dirEnd = unitText.IndexOf("}", dirStart); if (dirEnd == -1) throw new Exception("Diretiva incompleta"); dirEnd++; var dirCode = unitText.Substring(dirStart + 2, dirEnd - 1 - (dirStart + 2)).Trim().ToLower(); var dirPair = dirCode.Split(' '); if (dirPair[0] == "ifdef" || dirPair[0] == "ifndef") { var newIf = new IfDef(); newIf.IfStart = dirStart; newIf.IfEnd = dirEnd; newIf.Logic = dirPair[0] == "ifdef"; newIf.Symbol = dirPair[1]; if (currentIf != null) { if (currentIf.ReadingElse) currentIf.ElseChildren.Add(newIf); else currentIf.ThenChildren.Add(newIf); newIf.Parent = currentIf; } else defs.Add(newIf); currentIf = newIf; } else if (dirPair[0] == "else") { if (currentIf == null) throw new Exception("'Else' sem if"); currentIf.ElseStart = dirStart; currentIf.ElseEnd = dirEnd; currentIf.ReadingElse = true; } else if (dirPair[0] == "endif") { if (currentIf == null) throw new Exception("'EndIf' sem if"); currentIf.EndStart = dirStart; currentIf.EndEnd = dirEnd; currentIf = currentIf.Parent; } else if (dirPair[0] == "define") { var newDef = new SetDef(); newDef.DefStart = dirStart; newDef.DefEnd = dirEnd; newDef.Symbol = dirPair[1]; newDef.Parent = currentIf; if (currentIf != null) if (currentIf.ReadingElse) currentIf.ElseChildren.Add(newDef); else currentIf.ThenChildren.Add(newDef); else defs.Add(newDef); } else throw new Exception("Diretiva desconhecida: " + dirCode); } return defs; }