private ExpressionContainer AddIfDefExpressionContainer(IfDefReference ifdef) { var expr = new FlatExpression(new Operands(ifdef.Node.Value), new FlatExpressionLine(ifdef.Defined ? 1ul : 0ul)); if (ifdef.Node.Extra.Define.IfDefs?.Count > 0) { var parentIfDefs = ifdef.Node.Extra.Define.IfDefs; var listContainers = new List <ExpressionContainer>(parentIfDefs.Count); foreach (var ifDef in parentIfDefs) { listContainers.Add(GetOrAddExpressionContainer(new IfDefSet(ifDef))); } var operands = new Operands(listContainers .Select(_ => _.FlatExpression.Operands.Concat(expr.Operands)) .SelectMany(_ => _) .Distinct() .OrderBy(_ => _) .ToArray()); var flatExpr = new FlatExpression(operands); foreach (var c in listContainers) { flatExpr = flatExpr.Or(c.FlatExpression); } expr = flatExpr.And(expr); } if (ifdef.Defined) { ifdef.Node.Extra.Define.IfDefExpression = expr.AsTreeExpression().ToString(); } else { ifdef.Node.Extra.Define.IfNotDefExpression = expr.AsTreeExpression().ToString(); } var container = new ExpressionContainer { FlatExpression = expr }; _knownReferences.Add(new IfDefSet(ifdef), container); return(container); }