コード例 #1
0
 void ResolveImportAssemblyReferences()
 {
     foreach (Boo.Lang.Compiler.Ast.Module module in CompileUnit.Modules)
     {
         ImportCollection imports     = module.Imports;
         Import[]         importArray = imports.ToArray();
         for (int i = 0; i < importArray.Length; ++i)
         {
             Import u = importArray[i];
             ReferenceExpression reference = u.AssemblyReference;
             if (null != reference)
             {
                 try
                 {
                     Assembly asm = Parameters.FindAssembly(reference.Name);
                     if (null == asm)
                     {
                         asm = Parameters.LoadAssembly(reference.Name);
                         if (null != asm)
                         {
                             Parameters.AddAssembly(asm);
                         }
                     }
                     reference.Entity = new TypeSystem.AssemblyReference(asm);
                 }
                 catch (Exception x)
                 {
                     Errors.Add(CompilerErrorFactory.UnableToLoadAssembly(reference, reference.Name, x));
                     imports.RemoveAt(i);
                 }
             }
         }
     }
 }
コード例 #2
0
        public ReferenceExpression CreateReference(LexicalInfo info, IType type)
        {
            ReferenceExpression expression = CreateReference(type);

            expression.LexicalInfo = info;
            return(expression);
        }
コード例 #3
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (LookingFor(node))
     {
         Found(node);
     }
 }
コード例 #4
0
        public void IfStatementComplexExpression()
        {
            var left = new ExpressionNode(nameof(Operator.Multiply), new ReferenceExpression("x"),
                                          new ReferenceExpression("y"));
            var right     = new ReferenceExpression("z");
            var condition = new ExpressionNode(nameof(Operator.Eq), left, right);

            var statement = new IfStatement(condition,
                                            new Block(new AssignmentStatement(new Reference("a"), new ReferenceExpression("b"))));

            var actual = Generate(statement);

            var label = new Label("label1");

            var expected = new List <IntermediateCode>
            {
                IntermediateCode.Emit.Mult(new Reference("T1"), new Reference("x"), new Reference("y")),
                IntermediateCode.Emit.IsEqual(new Reference("T2"), new Reference("T1"), new Reference("z")),
                IntermediateCode.Emit.JumpIfFalse(new Reference("T2"), label),
                IntermediateCode.Emit.Set(new Reference("a"), new Reference("b")),
                IntermediateCode.Emit.Label(label)
            };

            actual.ShouldDeepEqual(expected);
        }
コード例 #5
0
        protected static Expression state(Expression expression)
        {
            var args = new List <Expression>();

            if (expression is StringLiteralExpression)
            {
                args.Add(expression);
                if (!String.IsNullOrEmpty(_state_identifier_target))
                {
                    args.Add(ExpandStateIdentifier((StringLiteralExpression)expression));
                }
            }
            else if (expression is BinaryExpression)
            {
                var original = (BinaryExpression)expression;
                args.Add(original.Left);
                args.Add(original.Right);
            }

            var method = new ReferenceExpression("add_state");

            var invoker = new MethodInvocationExpression(method, args.ToArray());

            return(invoker);
        }
コード例 #6
0
        private MemberInfo[] FindMembers(ReferenceExpression name)
        {
#if DNXCORE50
            MemberFilter filter = delegate(MemberInfo m, object filterCriteria)
            {
                if (filterCriteria == null || !(filterCriteria is string))
                {
                    throw new System.Reflection.InvalidFilterCriteriaException("RFLCT.FltCritString");
                }
                string text = (string)filterCriteria;
                text = text.Trim();
                string text2 = m.Name;
                if (m.MemberType == MemberTypes.NestedType)
                {
                    text2 = text2.Substring(text2.LastIndexOf('+') + 1);
                }
                if (text.Length > 0 && text[text.Length - 1] == '*')
                {
                    text = text.Substring(0, text.Length - 1);
                    return(text2.StartsWith(text, StringComparison.Ordinal));
                }
                return(text2.Equals(text));
            };

            return(_type.GetTypeInfo()
                   .FindMembers(MemberTypes.Property | MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public, filter,
                                name.Name));
#else
            return(_type.FindMembers(MemberTypes.Property | MemberTypes.Field, BindingFlags.Instance | BindingFlags.Public, System.Type.FilterName, name.Name));
#endif
        }
コード例 #7
0
        private HashLiteralExpression ObtainListeners(MacroStatement macro)
        {
            HashLiteralExpression  listeners       = new HashLiteralExpression();
            ComponentMethodVisitor componentMethod = new ComponentMethodVisitor();

            foreach (Statement statement in macro.Block.Statements)
            {
                ExpressionStatement expression = statement as ExpressionStatement;
                if (expression == null || !(expression.Expression is MethodInvocationExpression))
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                MethodInvocationExpression mie = (MethodInvocationExpression)expression.Expression;
                ReferenceExpression        to  = mie.Target as ReferenceExpression;
                if (to == null || mie.Arguments.Count != 1 ||
                    !"to".Equals(to.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                MemberReferenceExpression listener = mie.Arguments[0] as MemberReferenceExpression;
                if (listener == null || !componentMethod.ExtractMethod(listener))
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                listeners.Items.Add(new ExpressionPair(componentMethod.Component, componentMethod.Method));
            }

            return(listeners);
        }
コード例 #8
0
        protected override bool ExpandExtension(ref MethodInvocationExpression extension,
                                                MacroStatement macro, MacroStatement parent,
                                                ref Statement expansion)
        {
            if (macro.Arguments.Count < 1)
            {
                AddMissingLifestyleTypeError(macro);
                return(false);
            }

            ReferenceExpression lifestyle = macro.Arguments[0] as ReferenceExpression;

            if (lifestyle == null)
            {
                AddMissingLifestyleTypeError(macro);
                return(false);
            }

            macro.Arguments.RemoveAt(0);
            IEntity entity = NameResolutionService.Resolve(lifestyle.Name);

            if (entity == null || entity.EntityType != EntityType.Type)
            {
                AddMissingLifestyleTypeError(macro);
                return(false);
            }

            Type lifestyleType = ((ExternalType)entity).ActualType;

            return(InitializeLifestyleExtension(ref extension, lifestyle, lifestyleType) &&
                   ArgumentsToCreateNamedArguments(macro.Arguments, extension));
        }
コード例 #9
0
        private Expression ParseReferenceExpression(Expression hint)
        {
            var references = new List <Expression>();

            references.Add(hint);

            do
            {
                Take(TokenKind.Dot);
                if (current == TokenKind.Identifier)
                {
                    var expr = ParseIdentiferExpression();
                    references.Add(expr);
                }

                if (current == TokenKind.LeftParenthesis)
                {
                    var expr = new ReferenceExpression(CreateSpan(hint), references);
                    return(ParseFuncCallExpression(expr));
                }
            } while (current == TokenKind.Dot);

            ReferenceExpression r = new ReferenceExpression(CreateSpan(hint), references);

            statm.Add(r);
            return(r);
        }
コード例 #10
0
ファイル: SnLucCompiler.cs プロジェクト: kimduquan/DMIS
        private Query CompileReferenceExpressionNode(ReferenceExpression expression)
        {
            if (expression.Expression != null)
            {
                throw new NotImplementedException();
            }

            var leftName = CompileLeftValue(expression.ReferrerProperty);

            if (expression.ExistenceOnly)
            {
                // not null --> not empty --> -(name:)
                var boolQuery = new BooleanQuery();
                boolQuery.Add(new BooleanClause(new TermQuery(new Term(leftName)), BooleanClause.Occur.MUST_NOT));
                return(boolQuery);
            }
            //if (!expression.ReferrerProperty.IsSlot)
            //{
            //    // simple nodeid
            //    return new TermQuery(new Term(leftName, ValueFormatter.Format(DataType.Int, expression.ReferencedNode.Id)[0]));
            //}
            //// reference slot
            //return new TermQuery(new Term(leftName, ValueFormatter.Format(DataType.Reference, new int[] { expression.ReferencedNode.Id })));
            //<##>
            //return new TermQuery(new Term(leftName, ValueFormatter.Format(DataType.Int, expression.ReferencedNode.Id)[0]));
            return(new TermQuery(new Term(leftName, expression.ReferencedNode.Id.ToString())));
            //</##>
        }
コード例 #11
0
        private Expression ParseReferenceExpression(Expression hint)
        {
            var references = new List <Expression>();

            references.Add(hint);

            do
            {
                Take(TokenKind.Dot);
                if (_current == TokenKind.Identifier)
                {
                    var expr = ParseIdentiferExpression();
                    references.Add(expr);
                }

                if (_current == TokenKind.LeftParenthesis)
                {
                    var expr = new ReferenceExpression(CreateSpan(hint), references);
                    return(ParseMethodCallExpression(expr));
                }
                else if (_current == TokenKind.LeftBrace)
                {
                    var expr = new ReferenceExpression(CreateSpan(hint), references);
                    return(ParseArrayAccessExpression(expr));
                }
            } while (_current == TokenKind.Dot);

            return(new ReferenceExpression(CreateSpan(hint), references));
        }
コード例 #12
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (PhantomDslEngine.IsCleanupMethod(node.ParentNode))
     {
         ReplaceCurrentNode(new StringLiteralExpression(node.Name));
     }
 }
コード例 #13
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            ReferenceExpression.SetName(NewName);

            if (!Name.StartsWith(nameof(AbstractValidator <object> .Validate)))
            {
                // adapt lambda expression
                var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(ReferenceExpression);
                if (invocationExpression != null)
                {
                    foreach (var argument in invocationExpression.Arguments)
                    {
                        var lambdaExpression = argument.Expression as ILambdaExpression;
                        if (lambdaExpression == null)
                        {
                            continue;
                        }

                        lambdaExpression.SetAsync(!IsCurrentlyAsync);
                        // foreach (var awaitExpression in lambdaExpression.BodyBlock.Descendants<IAwaitExpression>())
                        // {
                        //     EcmaDesc.Mod
                        // }
                    }
                }
            }

            return(null);
        }
コード例 #14
0
ファイル: GenericTypeMapper.cs プロジェクト: weimingtom/boo
        public override void OnReferenceExpression(ReferenceExpression node)
        {
            var local = node.Entity as InternalLocal;

            if (local != null)
            {
                var type       = local.Type;
                var mappedType = _replacer.MapType(type);
                if (mappedType != type)
                {
                    node.Entity = UpdateLocal(local.Local, mappedType);
                }
            }
            var te = node.Entity as ITypedEntity;

            if (te != null)
            {
                if (node.Entity is IGenericMappedMember)
                {
                    ReplaceMappedEntity(node, te.Type);
                }
                else if (node.Entity.EntityType == EntityType.Type)
                {
                    var type = (IType)node.Entity;
                    node.Entity = _replacer.MapType(type);
                }
                node.ExpressionType = ((ITypedEntity)node.Entity).Type;
            }
        }
コード例 #15
0
        private Expression CreateBuilderIfNeeded(MethodInvocationExpression child, string name)
        {
            int argsCount = child.Arguments.Count;

            if (argsCount >= 1)
            {
                ReferenceExpression builder = child.Arguments[0] as ReferenceExpression;
                if (builder != null)
                {
                    Block block;
                    if (argsCount > 2 || (argsCount == 2 && !MacroHelper.IsNewBlock(child, out block)))
                    {
                        _compileErrors.Add(CompilerErrorFactory.CustomError(
                                               child.Arguments[0].LexicalInfo,
                                               "Builder syntax must be in the format builder, prop: value,..."));
                        return(null);
                    }

                    MethodInvocationExpression builderCtor = new MethodInvocationExpression(builder);
                    builderCtor.Arguments.Add(new StringLiteralExpression(name));
                    builderCtor.NamedArguments.Extend(child.NamedArguments);
                    return(builderCtor);
                }
            }

            return(new StringLiteralExpression(name));
        }
コード例 #16
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (node.Name.Contains("$switch$"))
     {
         node.ParentNode.Replace(node, _tbc);
     }
 }
コード例 #17
0
        public override void OnMethodInvocationExpression(MethodInvocationExpression child)
        {
            ReferenceExpression target = (ReferenceExpression)child.Target;

            _name = NormalizeName(target.Name);
            _node = CreateBuilderIfNeeded(child, _name);
        }
コード例 #18
0
        private bool InitializeLifestyleExtension(ref MethodInvocationExpression extension,
                                                  ReferenceExpression lifestyle, Type lifestyleType)
        {
            if (typeof(LifestyleExtension).IsAssignableFrom(lifestyleType))
            {
                extension = new MethodInvocationExpression(lifestyle);
            }
            else
            {
                if (!typeof(ILifestyleManager).IsAssignableFrom(lifestyleType))
                {
                    AddCompilerError(lifestyle.LexicalInfo,
                                     "A custom lifestyle statement must specify a type that implements " +
                                     typeof(ILifestyleManager).FullName);
                    return(false);
                }

                extension = new MethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(Custom).FullName)
                    );
                extension.Arguments.Add(AstUtil.CreateReferenceExpression(lifestyleType.FullName));
            }

            return(true);
        }
コード例 #19
0
        public GotoStatement NewGoto(Node sourceNode)
        {
            ReferenceExpression reference = new ReferenceExpression(sourceNode.LexicalInfo, _label.Name);

            reference.Entity = _label.Entity;
            return(new GotoStatement(sourceNode.LexicalInfo, reference));
        }
コード例 #20
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (nameComparer.Equals(node.Name, oldName))
     {
         node.Name = newName;
     }
 }
コード例 #21
0
        public ReferenceExpression CreateReference(IType type)
        {
            ReferenceExpression reference = new ReferenceExpression(type.FullName);

            reference.Entity = type;
            return(reference);
        }
コード例 #22
0
        public Expression CreateInitValueType(LexicalInfo li, ReferenceExpression target)
        {
            var mie = CreateBuiltinInvocation(li, BuiltinFunction.InitValueType);

            mie.Arguments.Add(target);
            return(mie);
        }
コード例 #23
0
ファイル: Parser.cs プロジェクト: alistair-singh/tsqlc
        private FunctionCallExpression FunctionCall(ReferenceExpression reference)
        {
            var token = Current;

            Match(TokenType.OpenBracket);
            var parameters = new List <IExpression>();

            if (Consume(TokenType.CloseBracket))
            {
                return new FunctionCallExpression {
                           Token = token, Function = reference, Parameters = parameters
                }
            }
            ;

            do
            {
                parameters.Add(Expression());
            }while (Consume(TokenType.Comma));

            Match(TokenType.CloseBracket);
            return(new FunctionCallExpression {
                Function = reference, Parameters = parameters
            });
        }
コード例 #24
0
ファイル: GroupByMacro.cs プロジェクト: xliang/rhino-etl
        /// <summary>
        /// Perform the actual expansion of the macro
        /// </summary>
        /// <param name="macro">The macro.</param>
        /// <returns></returns>
        protected override Statement DoExpand(MacroStatement macro)
        {
            List <string> columns = new List <string>();

            if (!macro.Body.IsEmpty)
            {
                Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "GroupBy cannot contain statements"));
                return(null);
            }
            foreach (Expression argument in macro.Arguments)
            {
                ReferenceExpression expr = argument as ReferenceExpression;
                if (expr == null)
                {
                    Errors.Add(CompilerErrorFactory.CustomError(macro.LexicalInfo, "GroupBy arguments must be refernce expressions. Example: groupBy name, surname"));
                    return(null);
                }
                columns.Add(expr.Name);
            }

            Method method = CreateGetColumnsToGroupByMethod(macro, columns);

            ParentMethods.Add(method);

            return(null);
        }
コード例 #25
0
 public override void OnMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (!this.HandleConstructorInvocation(node))
     {
         CodeMethodReferenceExpression codeMethodReferenceExpression = new CodeMethodReferenceExpression();
         if (node.Target is SuperLiteralExpression)
         {
             codeMethodReferenceExpression.TargetObject = new CodeBaseReferenceExpression();
         }
         else
         {
             ReferenceExpression referenceExpression = (ReferenceExpression)node.Target;
             codeMethodReferenceExpression.MethodName = referenceExpression.Name;
             MemberReferenceExpression memberReferenceExpression = node.Target as MemberReferenceExpression;
             if (memberReferenceExpression != null)
             {
                 codeMethodReferenceExpression.TargetObject = this.VisitExpr(memberReferenceExpression.Target);
             }
             else
             {
                 codeMethodReferenceExpression.TargetObject = new CodeThisReferenceExpression();
             }
         }
         CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(codeMethodReferenceExpression, node.Arguments.Select(this.VisitExpr).ToArray());
         this._currentStatement.Expression = expression;
     }
 }
コード例 #26
0
            public override bool EnterMethodInvocationExpression(MethodInvocationExpression node)
            {
                if (this.model == CodeDomLocalizationModel.PropertyReflection)
                {
                    return(false);
                }

                MemberReferenceExpression member = node.Target as MemberReferenceExpression;

                if (member != null)
                {
                    ReferenceExpression refex = member.Target as ReferenceExpression;
                    if (refex != null && refex.Name.Equals("resources", StringComparison.InvariantCulture))
                    {
                        if (member.Name.Equals("ApplyResources", StringComparison.InvariantCulture))
                        {
                            this.model = CodeDomLocalizationModel.PropertyReflection;
                        }
                        else if (member.Name.Equals("GetString", StringComparison.InvariantCulture))
                        {
                            this.model = CodeDomLocalizationModel.PropertyAssignment;
                        }
                    }
                }
                return(false);
            }
コード例 #27
0
        public override void OnReferenceExpression(ReferenceExpression node)
        {
            IEntity entity = NameResolutionService.Resolve(node.Name);

            if (entity != null)
            {
                base.OnReferenceExpression(node);
                return;
            }
            if (node.Name.StartsWith("@"))
            {
                string refComponentName             = node.Name.Substring(1);
                StringLiteralExpression literal     = CodeBuilder.CreateStringLiteral(refComponentName);
                ExternalConstructor     constructor =
                    new ExternalConstructor(TypeSystemServices, _componentReferenceConstructor);
                MethodInvocationExpression invocation = CodeBuilder.CreateConstructorInvocation(constructor, literal);
                node.ParentNode.Replace(node, invocation);
                return;
            }
            else if (node.ParentNode is MethodInvocationExpression)
            {
                MethodInvocationExpression mie = (MethodInvocationExpression)node.ParentNode;
                //Transform the first parameter of Component ctor to string.
                if (mie.Target.ToString() == "Component")
                {
                    StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name);
                    mie.Replace(node, literal);
                    return;
                }
            }
            base.OnReferenceExpression(node);
        }
コード例 #28
0
        public ReferenceExpression CreateLabelReference(LabelStatement label)
        {
            ReferenceExpression reference = new ReferenceExpression(label.LexicalInfo, label.Name);

            reference.Entity = label.Entity;
            return(reference);
        }
コード例 #29
0
        public void LiftReferenceExpression()
        {
            var referenceExpression = new ReferenceExpression("foo");
            var parameter           = GenericParameterDeclaration.Lift(referenceExpression);

            Assert.AreEqual(referenceExpression.Name, parameter.Name);
        }
コード例 #30
0
        public static ReferenceExpression CreateBuiltinReference(BuiltinFunction builtin)
        {
            ReferenceExpression target = new ReferenceExpression(builtin.Name);

            target.Entity = builtin;
            return(target);
        }
コード例 #31
0
ファイル: EnumMember.cs プロジェクト: 0xb1dd1e/boo
		public static EnumMember Lift(ReferenceExpression node)
		{	
			return new EnumMember(node.LexicalInfo, node.Name);
		}