Example #1
0
        public bool IsMatching(StaticIfCondition sc, ResolutionContext ctxt)
        {
            if (conditionsBeingChecked.Contains(sc) || ctxt == null)
            {
                return(false);
            }

            conditionsBeingChecked.Add(sc);
            ISymbolValue v = null;

            /*if (System.Threading.Interlocked.Increment(ref stk) > 5)
             * {
             * }*/
            try
            {
                v = Evaluation.EvaluateValue(sc.Expression, ctxt);

                if (v is VariableValue)
                {
                    v = Evaluation.EvaluateValue(((VariableValue)v).Variable.Initializer, ctxt);
                }
            }
            finally
            {
                conditionsBeingChecked.Remove(sc);
            }
            //System.Threading.Interlocked.Decrement(ref stk);
            return(!Evaluation.IsFalseZeroOrNull(v));            //TODO: Just because the expression evaluation isn't working properly currently, let it return true to have it e.g. in the completion list
        }
Example #2
0
        public bool IsMatching(StaticIfCondition sc, ResolutionContext ctxt)
        {
            ISymbolValue v;

            try{
                v = Evaluation.EvaluateValue(sc.Expression, ctxt);
                if (v is VariableValue)
                {
                    v = Evaluation.EvaluateValue(((VariableValue)v).Variable.Initializer, ctxt);
                }
            }
            catch
            {
                return(false);                        //TODO: Remove the try / Notify the user on an exception case -- when the evaluation is considered stable only!!
            }
            return(!Evaluation.IsFalseZeroOrNull(v)); //TODO: Just because the expression evaluation isn't working properly currently, let it return true to have it e.g. in the completion list
        }
		public virtual void VisitAttribute(StaticIfCondition a)
		{
			if(a.Expression!=null)
				a.Expression.Accept(this);
		}
Example #4
0
 public string VisitAttribute(StaticIfCondition a)
 {
     throw new NotImplementedException();
 }
			public override void VisitAttribute(StaticIfCondition a)
			{
				
			}
Example #6
0
        DeclarationCondition Condition(IBlockNode parent)
        {
            DeclarationCondition c = null;

            switch (laKind) {
            case Version:
                /*
                 * http://www.dlang.org/version.html#VersionSpecification
                 * VersionCondition:
                 *		version ( IntegerLiteral )
                 *		version ( Identifier )
                 *		version ( unittest )
                 *		version ( assert )
                 */
                Step ();
                if (Expect (OpenParenthesis)) {
                    switch (laKind) {
                    case Unittest:
                        Step ();
                        c = new VersionCondition ("unittest") { IdLocation = t.Location };
                        break;
                    case Assert:
                        Step ();
                        c = new VersionCondition ("assert") { IdLocation = t.Location };
                        break;
                    case Literal:
                        Step ();
                        if (t.LiteralFormat != LiteralFormat.Scalar)
                            SynErr (t.Kind, "Version number must be an integer");
                        else
                            c = new VersionCondition (Convert.ToInt32 (t.LiteralValue)) { IdLocation = t.Location };
                        break;
                    default:
                        if (Expect (Identifier))
                            c = new VersionCondition (t.Value) { IdLocation = t.Location };
                        else if (IsEOF) {
                            c = new VersionCondition (DTokens.IncompleteId);
                            parent.Add (new DVariable{ Attributes = new List<DAttribute>{ c } });
                        }
                        break;
                    }

                    Expect (CloseParenthesis);
                }

                if (c == null)
                    c = new VersionCondition ("");
                break;

            case Debug:
                /*
                 * DebugCondition:
                 *		debug
                 *		debug ( IntegerLiteral )
                 *		debug ( Identifier )
                 */
                Step ();
                if (laKind == OpenParenthesis) {
                    Step ();

                    if (laKind == Literal) {
                        Step ();
                        if (t.LiteralFormat != LiteralFormat.Scalar)
                            SynErr (t.Kind, "Debug level must be an integer");
                        else
                            c = new DebugCondition (Convert.ToInt32 (t.LiteralValue)) { IdLocation = t.Location };
                    } else if (Expect (Identifier))
                        c = new DebugCondition ((string)t.LiteralValue) { IdLocation = t.Location };
                    else if (IsEOF) {
                        c = new DebugCondition (DTokens.IncompleteId);
                        parent.Add (new DVariable{ Attributes = new List<DAttribute>{ c } });
                    }

                    Expect (CloseParenthesis);
                }

                if (c == null)
                    c = new DebugCondition ();
                break;

            case Static:
                /*
                 * StaticIfCondition:
                 *		static if ( AssignExpression )
                 */
                Step ();
                if (Expect (If) && Expect (OpenParenthesis)) {
                    var x = AssignExpression (parent);
                    c = new StaticIfCondition (x);

                    if (!Expect (CloseParenthesis) && IsEOF)
                        parent.Add (new DVariable{ Attributes = new List<DAttribute>{ c } });
                } else
                    c = new StaticIfCondition (null);
                break;

            default:
                throw new Exception("Condition() should only be called if Version/Debug/If is the next token!");
            }

            return c;
        }
Example #7
0
 public AbstractType VisitAttribute(StaticIfCondition a)
 {
     throw new NotImplementedException();
 }
Example #8
0
        DeclarationCondition Condition(IBlockNode parent)
        {
            DeclarationCondition c = null;

            /*
             * http://www.dlang.org/version.html#VersionSpecification
             * VersionCondition:
             *		version ( IntegerLiteral )
             *		version ( Identifier )
             *		version ( unittest )
             *		version ( assert )
             */
            if (laKind == Version)
            {
                Step();
                if (Expect(OpenParenthesis))
                {
                    TrackerVariables.ExpectingIdentifier = true;
                    if (laKind == Unittest)
                    {
                        Step();
                        c = new VersionCondition("unittest") { IdLocation = t.Location };
                    }
                    else if (laKind == Assert)
                    {
                        Step();
                        c = new VersionCondition("assert") { IdLocation = t.Location };
                    }
                    else if (laKind == Literal)
                    {
                        Step();
                        if (t.LiteralFormat != LiteralFormat.Scalar)
                            SynErr(t.Kind, "Version number must be an integer");
                        else
                            c = new VersionCondition(Convert.ToInt32(t.LiteralValue)) { IdLocation = t.Location };
                    }
                    else if (Expect(Identifier))
                        c = new VersionCondition(t.Value) { IdLocation = t.Location };

                    if (Expect(CloseParenthesis))
                        TrackerVariables.ExpectingIdentifier = false;
                }

                if(c==null)
                    c = new VersionCondition("");
            }

            /*
             * DebugCondition:
             *		debug
             *		debug ( IntegerLiteral )
             *		debug ( Identifier )
             */
            else if (laKind == Debug)
            {
                Step();
                if (laKind == OpenParenthesis)
                {
                    Step();
                    TrackerVariables.ExpectingIdentifier = true;

                    if (laKind == Literal)
                    {
                        Step();
                        if (t.LiteralFormat != LiteralFormat.Scalar)
                            SynErr(t.Kind, "Debug level must be an integer");
                        else
                            c = new DebugCondition(Convert.ToInt32(t.LiteralValue)) { IdLocation = t.Location };
                    }
                    else if (Expect(Identifier))
                        c = new DebugCondition((string)t.LiteralValue) { IdLocation = t.Location };
                    else
                        c = new DebugCondition();

                    if (Expect(CloseParenthesis))
                        TrackerVariables.ExpectingIdentifier = false;
                }
                else
                    c = new DebugCondition();
            }

            /*
             * StaticIfCondition:
             *		static if ( AssignExpression )
             */
            else if (laKind == Static)
            {
                Step ();
                if (Expect (If) && Expect(OpenParenthesis))
                {
                    var x = AssignExpression(parent);
                    c = new StaticIfCondition(x);

                    Expect(CloseParenthesis);
                }
                else
                    c = new StaticIfCondition(null);
            }
            else
                throw new Exception("Condition() should only be called if Version/Debug/If is the next token!");

            LastParsedObject = c;

            return c;
        }
 public override void VisitAttribute(StaticIfCondition a)
 {
     handlesInitializer = true;
     base.VisitAttribute(a);
     handlesInitializer = false;
 }
 public override void VisitAttribute(StaticIfCondition a)
 {
     handlesInitializer = true;
     base.VisitAttribute (a);
     handlesInitializer = false;
 }
Example #11
0
 public override void VisitAttribute(StaticIfCondition a)
 {
 }
 public ulong VisitAttribute(StaticIfCondition a)
 {
     return(1000211 + (a.Expression != null ? Accept(a.Expression) << 8 : 0));
 }
 public bool IsMatching(StaticIfCondition sc, ResolutionContext ctxt)
 {
     ISymbolValue v;
     try{
         v = Evaluation.EvaluateValue(sc.Expression, ctxt);
         if(v is VariableValue)
             v = Evaluation.EvaluateValue(((VariableValue)v).Variable.Initializer, ctxt);
     }
     catch
     {
         return false; //TODO: Remove the try / Notify the user on an exception case -- when the evaluation is considered stable only!!
     }
     return !Evaluation.IsFalseZeroOrNull(v); //TODO: Just because the expression evaluation isn't working properly currently, let it return true to have it e.g. in the completion list
 }
        public bool IsMatching(StaticIfCondition sc, ResolutionContext ctxt)
        {
            if (conditionsBeingChecked.Contains(sc))
                return false;

            conditionsBeingChecked.Add(sc);
            ISymbolValue v = null;

            /*if (System.Threading.Interlocked.Increment(ref stk) > 5)
            {
            }*/
            try
            {
                v = Evaluation.EvaluateValue(sc.Expression, ctxt);

                if (v is VariableValue)
                    v = Evaluation.EvaluateValue(((VariableValue)v).Variable.Initializer, ctxt);
            }
            finally
            {
                conditionsBeingChecked.Remove(sc);
            }
            //System.Threading.Interlocked.Decrement(ref stk);
            return !Evaluation.IsFalseZeroOrNull(v); //TODO: Just because the expression evaluation isn't working properly currently, let it return true to have it e.g. in the completion list
        }
Example #15
0
 public CompletionItemKind VisitAttribute(StaticIfCondition a)
 {
     throw new NotImplementedException();
 }