public static Statement CreateModifiedStatement(StatementModifier modifier, Statement node)
 {
     Block block;
     Statement stmt = MapStatementModifier(modifier, out block);
     block.Add(node);
     return stmt;
 }
示例#2
0
		//this method returns -1 if it doesn't detect unreachable code
		//else it returns the index of the first unreachable in block.Statements 
		private int DetectUnreachableCode(Block block, Statement limit)
		{
			var unreachable = false;
			var idx = 0;
			foreach (var stmt in block.Statements)
			{
				//HACK: __switch__ builtin function is hard to detect/handle
				//		within this context, let's ignore whatever is after __switch__
				if (IsSwitchBuiltin(stmt))
					return -1;//ignore followings

				if (unreachable && stmt is LabelStatement)
					return -1;

				if (stmt == limit)
					unreachable = true;
				else if (unreachable)
				{
					if (!stmt.IsSynthetic)
						Warnings.Add(CompilerWarningFactory.UnreachableCodeDetected(stmt));
					return idx;
				}

				idx++;
			}
			return -1;
		}
示例#3
0
		//this method returns -1 if it doesn't detect unreachable code
		//else it returns the index of the first unreachable in block.Statements 
		private int DetectUnreachableCode(Block block, Statement limit)
		{
			bool unreachable = false;
			int idx = 0;
			foreach (Statement stmt in block.Statements)
			{
				//HACK: __switch__ builtin function is hard to detect/handle
				//		within this context, let's ignore whatever is after __switch__
				ExpressionStatement est = stmt as ExpressionStatement;
				if (null != est)
				{
					MethodInvocationExpression mie = est.Expression as MethodInvocationExpression;
					if (null != mie && TypeSystem.BuiltinFunction.Switch == mie.Target.Entity)
						return -1;//ignore followings
				}

				if (unreachable && stmt is LabelStatement)
					return -1;

				if (stmt == limit)
				{
					unreachable = true;
				}
				else if (unreachable)
				{
					Warnings.Add(
						CompilerWarningFactory.UnreachableCodeDetected(stmt) );
					return idx;
				}
				idx++;
			}
			return -1;
		}
示例#4
0
		private void RemoveUnreachableCode(Statement node)
		{
			Block block = node.ParentNode as Block;			
			if (null == block) return;

			int from = DetectUnreachableCode(block, node);
			if (-1 != from) RemoveStatements(block, from);
		}
示例#5
0
        public void ReplaceBy(Statement other)
        {
            Block block = (Block)ParentNode;
            if (null == block)
            {
                throw new InvalidOperationException();
            }

            block.Statements.Replace(this, other);
        }
 private bool IsSwitchCondition(Statement candidateBlock, Statement parentStmt)
 {
     Block block = candidateBlock as Block;
     if (block == null)
     {
         return false;
     }
     Block block2 = block.get_ParentNode() as Block;
     return ((block2 != null) && (block2.get_ParentNode().get_NodeType() == 0x16));
 }
 private bool IsExpandedDefaultSwitchCase(Statement candidateBlock, Statement parentStatement)
 {
     Block block = candidateBlock as Block;
     if (block == null)
     {
         return false;
     }
     int index = block.get_Statements().IndexOf(parentStatement);
     if (index <= 0)
     {
         return false;
     }
     LabelStatement statement = block.get_Statements().get_Item(index - 1) as LabelStatement;
     return ((statement != null) && statement.get_Name().Contains("$switch$"));
 }
 public Statement Reify(Statement node)
 {
     var result = node;
     if (node is MacroStatement)
     {
         // macro statements are replaced
         // so we need to wrap it in a Block
         // otherwise we would lose the result
         var parentNode = node.ParentNode;
         result = new Block(node);
         parentNode.Replace(node, result);
     }
     ApplyAttributesAndExpandMacros();
     return result;
 }
示例#9
0
		public static TypeMember Lift(Statement stmt)
		{
			var typeMemberStatement = stmt as TypeMemberStatement;
			if (null != typeMemberStatement)
				return TypeMember.Lift(typeMemberStatement);

			var declaration = stmt as DeclarationStatement;
			if (null != declaration)
				return TypeMember.Lift(declaration);

			var expressionStatement = stmt as ExpressionStatement;
			if (null != expressionStatement)
				return TypeMember.Lift(expressionStatement);

			throw new NotImplementedException(stmt.ToCodeString());
		}
示例#10
0
        public Statement Reify(Statement node)
        {
            var result = node;
            if (ShouldReify())
            {
                if (node is MacroStatement)
                {
                    // macro statements are replaced
                    // so we need to wrap it in a Block
                    // otherwise we would lose the result
                    var parentNode = node.ParentNode;
                    result = new Block(node);
                    parentNode.Replace(node, result);
                }
                RunExpansionIterations();
            }

            return result;
        }
示例#11
0
        void AddToBlock(Statement n, B.Block b)
        {
            object result = ConvertStatementInternal(n);

            if (result is ArrayList)
            {
                foreach (B.Statement stmt in (ArrayList)result)
                {
                    b.Add(stmt);
                }
            }
            else
            {
                B.Statement stmt = (B.Statement)result;
                if (stmt != null)
                {
                    b.Add(stmt);
                }
            }
        }
示例#12
0
 private void CheckInLoop(Statement node)
 {
     if (!_state.InLoop)
     {
         Error(CompilerErrorFactory.NoEnclosingLoop(node));
     }
 }
示例#13
0
        private Statement ExpandMacroExpansion(MacroStatement node, Statement expansion)
        {
            if (null == expansion)
                return null;

            Statement modifiedExpansion = ApplyMacroModifierToExpansion(node, expansion);
            modifiedExpansion.InitializeParent(node.ParentNode);
            return Visit(modifiedExpansion);
        }
示例#14
0
 public void Insert(int index, Statement stmt)
 {
     this.Statements.Insert(index, stmt);
 }
 public TemplateBindVisitor(IEnumerable<Expression> templatesource, IDictionary<string, Expression> namedsubsts,  Statement block)
 {
     args = templatesource.ToList();
     this.namedargs = namedsubsts;
     this.block = block;
 }
示例#16
0
 private static Statement ApplyMacroModifierToExpansion(MacroStatement node, Statement expansion)
 {
     if (node.Modifier == null)
         return expansion;
     return NormalizeStatementModifiers.CreateModifiedStatement(node.Modifier, expansion);
 }
示例#17
0
		public Statement Reify(Statement node)
		{
			return Visit(node);
		}
示例#18
0
 public static Statement Lift(Statement node)
 {
     return node;
 }
示例#19
0
		private static bool IsSwitchBuiltin(Statement stmt)
		{	
			var est = stmt as ExpressionStatement;
			if (est != null)
			{
				MethodInvocationExpression mie = est.Expression as MethodInvocationExpression;
				if (mie != null && TypeSystem.BuiltinFunction.Switch == mie.Target.Entity)
					return true;
			}
			return false;
		}
 public ClassDefinition GetContextFieldDeclaration()
 {
     Field field;
     Field field2;
     ParameterDeclaration declaration;
     MemberReferenceExpression expression;
     ReferenceExpression expression2;
     BinaryExpression expression3;
     ReferenceExpression expression4;
     ReferenceExpression expression5;
     MemberReferenceExpression expression6;
     BinaryExpression expression7;
     Block block;
     Constructor constructor;
     ClassDefinition definition;
     Type type = this._evaluationContext.GetType();
     Type type2 = this._evaluationContext.ScriptContainer.GetType();
     ClassDefinition definition1 = definition = new ClassDefinition(LexicalInfo.Empty);
     definition.set_Name("_");
     TypeMember[] memberArray1 = new TypeMember[3];
     Field field1 = field = new Field(LexicalInfo.Empty);
     field.set_Modifiers(40);
     field.set_Name("ScriptContainer");
     field.set_Type(TypeReference.Lift(type2));
     field.set_IsVolatile(false);
     memberArray1[0] = field;
     Field field3 = field2 = new Field(LexicalInfo.Empty);
     field2.set_Name("EvaluationContext");
     field2.set_Type(TypeReference.Lift(type));
     field2.set_IsVolatile(false);
     memberArray1[1] = field2;
     Constructor constructor1 = constructor = new Constructor(LexicalInfo.Empty);
     constructor.set_Name("constructor");
     ParameterDeclaration[] declarationArray1 = new ParameterDeclaration[1];
     ParameterDeclaration declaration1 = declaration = new ParameterDeclaration(LexicalInfo.Empty);
     declaration.set_Name("context");
     declaration.set_Type(TypeReference.Lift(type));
     declarationArray1[0] = declaration;
     constructor.set_Parameters(ParameterDeclarationCollection.FromArray(false, declarationArray1));
     Block block1 = block = new Block(LexicalInfo.Empty);
     Statement[] statementArray1 = new Statement[2];
     BinaryExpression expression1 = expression3 = new BinaryExpression(LexicalInfo.Empty);
     expression3.set_Operator(15);
     MemberReferenceExpression expression14 = expression = new MemberReferenceExpression(LexicalInfo.Empty);
     expression.set_Name("EvaluationContext");
     expression.set_Target(new SelfLiteralExpression(LexicalInfo.Empty));
     expression3.set_Left(expression);
     ReferenceExpression expression15 = expression2 = new ReferenceExpression(LexicalInfo.Empty);
     expression2.set_Name("context");
     expression3.set_Right(expression2);
     statementArray1[0] = Statement.Lift(expression3);
     BinaryExpression expression16 = expression7 = new BinaryExpression(LexicalInfo.Empty);
     expression7.set_Operator(15);
     ReferenceExpression expression17 = expression4 = new ReferenceExpression(LexicalInfo.Empty);
     expression4.set_Name("ScriptContainer");
     expression7.set_Left(expression4);
     MemberReferenceExpression expression18 = expression6 = new MemberReferenceExpression(LexicalInfo.Empty);
     expression6.set_Name("ScriptContainer");
     ReferenceExpression expression19 = expression5 = new ReferenceExpression(LexicalInfo.Empty);
     expression5.set_Name("context");
     expression6.set_Target(expression5);
     expression7.set_Right(expression6);
     statementArray1[1] = Statement.Lift(expression7);
     block.set_Statements(StatementCollection.FromArray(statementArray1));
     constructor.set_Body(block);
     memberArray1[2] = constructor;
     definition.set_Members(TypeMemberCollection.FromArray(memberArray1));
     return definition;
 }
示例#21
0
		public StatementTypeMember(Statement macro) : base(macro.LexicalInfo)
		{
			this.Statement = macro;
		}
示例#22
0
 public void Add(Statement stmt)
 {
     this.Statements.Add(stmt);
 }
示例#23
0
 public override bool Replace(Node existing, Node newNode)
 {
     if (base.Replace(existing, newNode))
     {
         return true;
     }
     if (_attributes != null)
     {
         Attribute item = existing as Attribute;
         if (null != item)
         {
             Attribute newItem = (Attribute)newNode;
             if (_attributes.Replace(item, newItem))
             {
                 return true;
             }
         }
     }
     if (_statement == existing)
     {
         this.Statement = (Statement)newNode;
         return true;
     }
     return false;
 }
示例#24
0
 public void LeaveStatement(Statement node)
 {
     StatementModifier modifier = node.Modifier;
     if (null != modifier)
     {
         node.Modifier = null;
         ReplaceCurrentNode(CreateModifiedStatement(modifier, node));
     }
 }
示例#25
0
 public static Statement Lift(Statement node)
 {
     return(node);
 }