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); } } } } }
public ReferenceExpression CreateReference(LexicalInfo info, IType type) { ReferenceExpression expression = CreateReference(type); expression.LexicalInfo = info; return(expression); }
public override void OnReferenceExpression(ReferenceExpression node) { if (LookingFor(node)) { Found(node); } }
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); }
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); }
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 }
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); }
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)); }
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); }
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()))); //</##> }
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)); }
public override void OnReferenceExpression(ReferenceExpression node) { if (PhantomDslEngine.IsCleanupMethod(node.ParentNode)) { ReplaceCurrentNode(new StringLiteralExpression(node.Name)); } }
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); }
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; } }
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)); }
public override void OnReferenceExpression(ReferenceExpression node) { if (node.Name.Contains("$switch$")) { node.ParentNode.Replace(node, _tbc); } }
public override void OnMethodInvocationExpression(MethodInvocationExpression child) { ReferenceExpression target = (ReferenceExpression)child.Target; _name = NormalizeName(target.Name); _node = CreateBuilderIfNeeded(child, _name); }
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); }
public GotoStatement NewGoto(Node sourceNode) { ReferenceExpression reference = new ReferenceExpression(sourceNode.LexicalInfo, _label.Name); reference.Entity = _label.Entity; return(new GotoStatement(sourceNode.LexicalInfo, reference)); }
public override void OnReferenceExpression(ReferenceExpression node) { if (nameComparer.Equals(node.Name, oldName)) { node.Name = newName; } }
public ReferenceExpression CreateReference(IType type) { ReferenceExpression reference = new ReferenceExpression(type.FullName); reference.Entity = type; return(reference); }
public Expression CreateInitValueType(LexicalInfo li, ReferenceExpression target) { var mie = CreateBuiltinInvocation(li, BuiltinFunction.InitValueType); mie.Arguments.Add(target); return(mie); }
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 }); }
/// <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); }
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; } }
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); }
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); }
public ReferenceExpression CreateLabelReference(LabelStatement label) { ReferenceExpression reference = new ReferenceExpression(label.LexicalInfo, label.Name); reference.Entity = label.Entity; return(reference); }
public void LiftReferenceExpression() { var referenceExpression = new ReferenceExpression("foo"); var parameter = GenericParameterDeclaration.Lift(referenceExpression); Assert.AreEqual(referenceExpression.Name, parameter.Name); }
public static ReferenceExpression CreateBuiltinReference(BuiltinFunction builtin) { ReferenceExpression target = new ReferenceExpression(builtin.Name); target.Entity = builtin; return(target); }
public static EnumMember Lift(ReferenceExpression node) { return new EnumMember(node.LexicalInfo, node.Name); }