/// <returns>-1 if c is not matching, 1 if matching, 0 if unknown (won't invalidate else-case)</returns> int CheckCondition(DeclarationCondition c) { if (c == null || handledConditions.Contains(c) || c is StaticIfCondition || (c is NegatedDeclarationCondition && (c as NegatedDeclarationCondition).FirstCondition is NegatedDeclarationCondition)) { return(0); } handledConditions.Add(c); bool ret = false; var backupStack = new Stack <CustomConditionFlagSet> (); INode n = null; CustomConditionFlagSet cc; while (conditionStack.Count != 0 && (n == null || conditionStack.Peek().Block == n.Parent)) { cc = conditionStack.Pop(); n = cc.Block; backupStack.Push(cc); if (!(ret = cc.IsMatching(c, null))) { break; } } while (backupStack.Count != 0) { conditionStack.Push(backupStack.Pop()); } return((ret || (!(c is NegatedDeclarationCondition) && ctxt.CompilationEnvironment.IsMatching(c, null))) ? 1 : -1); }
public bool IsMatching(DeclarationCondition dc, ResolutionContext ctxt) { if (ctxt.CancelOperation) { return(true); } var r = true; if (dc is NegatedDeclarationCondition) { var ng = (NegatedDeclarationCondition)dc; if (ng.FirstCondition is StaticIfCondition) { if (!conditionsBeingChecked.Contains(ng.FirstCondition)) { conditionsBeingChecked.Add(ng.FirstCondition); } else { return(false); } r = !GlobalFlags.IsMatching((StaticIfCondition)ng.FirstCondition, ctxt); conditionsBeingChecked.Remove(ng.FirstCondition); } else { r = ((GlobalFlags == null || GlobalFlags.IsMatching(dc, ctxt)) && (LocalFlags == null || LocalFlags.IsMatching(dc, ctxt))); } } else { if (dc is StaticIfCondition) { if (!conditionsBeingChecked.Contains(dc)) { conditionsBeingChecked.Add(dc); } else { return(false); } r = GlobalFlags.IsMatching((StaticIfCondition)dc, ctxt); conditionsBeingChecked.Remove(dc); } else { r = (GlobalFlags.IsMatching(dc, ctxt) || LocalFlags.IsMatching(dc, ctxt)); } } return(r); }
public bool IsMatching(DeclarationCondition cond, ResolutionContext ctxt) { if (cond is VersionCondition) { var vc = (VersionCondition)cond; return(vc.VersionId == null ? vc.VersionNumber >= versionNumber : setVersions.Contains(vc.VersionId)); } else if (cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.HasNoExplicitSpecification) { return(IsDebug); } return(dc.DebugId == null ? debugLevel >= dc.DebugLevel : setDebugVersions.Contains(dc.DebugId)); } else if (cond is StaticIfCondition) { return(IsMatching((StaticIfCondition)cond, ctxt)); } else if (cond is NegatedDeclarationCondition) { cond = ((NegatedDeclarationCondition)cond).FirstCondition; //TODO: Ensure that there's no double negation if (cond is VersionCondition) { var vc = (VersionCondition)cond; return(vc.VersionId == null ? vc.VersionNumber < versionNumber : (!setVersions.Contains(vc.VersionId) || setVersions.Contains("!" + vc.VersionId))); } else if (cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.HasNoExplicitSpecification) { return(!IsDebug); } return(dc.DebugId == null ? debugLevel < dc.DebugLevel : (!setDebugVersions.Contains(dc.DebugId) || setDebugVersions.Contains("!" + dc.DebugId))); } else if (cond is StaticIfCondition) { return(!IsMatching((StaticIfCondition)cond, ctxt)); } } // True on default -- static if's etc. will be filtered later on return(true); }
public void Add(DeclarationCondition cond) { if (cond is VersionCondition) { var vc = (VersionCondition)cond; if (vc.VersionId == null) { AddVersionCondition(vc.VersionNumber); } else { AddVersionCondition(vc.VersionId); } } else if (cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.DebugId == null) { AddDebugCondition(dc.DebugLevel); } else { AddDebugCondition(dc.DebugId); } } else if (cond is NegatedDeclarationCondition) { cond = ((NegatedDeclarationCondition)cond).FirstCondition; if (cond is VersionCondition) { var vc = (VersionCondition)cond; if (vc.VersionId != null) { /*AddVersionCondition(vc.VersionNumber); -- TODO How are "negated" version numbers handled? * else*/ AddVersionCondition("!" + vc.VersionId); } } else if (cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.DebugId != null) { /*AddDebugCondition(dc.DebugLevel); * else*/ AddDebugCondition("!" + dc.DebugId); } } } }
public bool IsMatching(DeclarationCondition cond, ResolutionContext ctxt) { if(cond is VersionCondition) { var vc = (VersionCondition)cond; return vc.VersionId == null ? vc.VersionNumber >= versionNumber : setVersions.Contains(vc.VersionId); } else if(cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.HasNoExplicitSpecification) return IsDebug; return dc.DebugId == null ? debugLevel >= dc.DebugLevel : setDebugVersions.Contains(dc.DebugId); } else if(cond is StaticIfCondition) return IsMatching((StaticIfCondition)cond,ctxt); else if(cond is NegatedDeclarationCondition) { cond = ((NegatedDeclarationCondition)cond).FirstCondition; //TODO: Ensure that there's no double negation if(cond is VersionCondition) { var vc = (VersionCondition)cond; return vc.VersionId == null ? vc.VersionNumber < versionNumber : (!setVersions.Contains(vc.VersionId) || setVersions.Contains("!"+vc.VersionId)); } else if(cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.HasNoExplicitSpecification) return !IsDebug; return dc.DebugId == null ? debugLevel < dc.DebugLevel : (!setDebugVersions.Contains(dc.DebugId) || setDebugVersions.Contains("!" + dc.DebugId)); } else if(cond is StaticIfCondition) return !IsMatching((StaticIfCondition)cond,ctxt); } // True on default -- static if's etc. will be filtered later on return true; }
IConditionFunction DeclarationCondition(ref CssToken token) { var property = Factory.Properties.Create(token.Data) ?? new CssUnknownProperty(token.Data); var declaration = default(DeclarationCondition); token = NextToken(); CollectTrivia(ref token); if (token.Type == CssTokenType.Colon) { var important = false; var result = CreateValue(CssTokenType.RoundBracketClose, ref token, out important); property.IsImportant = important; if (result != null) { declaration = new DeclarationCondition(property, result); } } return(declaration); }
public bool IsMatching(DeclarationCondition dc, ResolutionContext ctxt) { var r = true; if(dc is NegatedDeclarationCondition) { var ng = (NegatedDeclarationCondition)dc; if(ng.FirstCondition is StaticIfCondition){ if(!conditionsBeingChecked.Contains(ng.FirstCondition)) conditionsBeingChecked.Add(ng.FirstCondition); else return false; r = !GlobalFlags.IsMatching((StaticIfCondition)ng.FirstCondition, ctxt); conditionsBeingChecked.Remove(ng.FirstCondition); } else r = (GlobalFlags.IsMatching(dc,ctxt) && LocalFlags.IsMatching(dc,ctxt)); } else { if(dc is StaticIfCondition){ if(!conditionsBeingChecked.Contains(dc)) conditionsBeingChecked.Add(dc); else return false; r = GlobalFlags.IsMatching((StaticIfCondition)dc, ctxt); conditionsBeingChecked.Remove(dc); } else r = (GlobalFlags.IsMatching(dc,ctxt) || LocalFlags.IsMatching(dc,ctxt)); } return r; }
public bool MatchesDeclarationEnvironment(DeclarationCondition dc) { return(declarationCondititons.IsMatching(dc, ctxt)); }
public bool MatchesDeclarationEnvironment(DeclarationCondition dc) { return declarationCondititons.IsMatching(dc,ctxt); }
public void Add(DeclarationCondition cond) { if(cond is VersionCondition) { var vc = (VersionCondition)cond; if (vc.VersionId == null) AddVersionCondition(vc.VersionNumber); else AddVersionCondition(vc.VersionId); } else if(cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.DebugId == null) AddDebugCondition(dc.DebugLevel); else AddDebugCondition(dc.DebugId); } else if(cond is NegatedDeclarationCondition) { cond = ((NegatedDeclarationCondition)cond).FirstCondition; if (cond is VersionCondition) { var vc = (VersionCondition)cond; if (vc.VersionId != null) /*AddVersionCondition(vc.VersionNumber); -- TODO How are "negated" version numbers handled? else*/ AddVersionCondition("!"+vc.VersionId); } else if (cond is DebugCondition) { var dc = (DebugCondition)cond; if (dc.DebugId != null) /*AddDebugCondition(dc.DebugLevel); else*/ AddDebugCondition("!"+dc.DebugId); } } }