public void LiftReferenceExpression() { var referenceExpression = new ReferenceExpression("foo"); var parameter = ParameterDeclaration.Lift(referenceExpression); Assert.AreEqual(referenceExpression.Name, parameter.Name); Assert.IsNull(parameter.Type); }
public GeneratorExpressionTrees(string parameter, ReferenceExpression parameterRef, NameResolutionService nameResolutionService, BooCodeBuilder codeBuilder) { _parameter = parameter; _parameterRef = parameterRef; _nameResolutionService = nameResolutionService; _codeBuilder = codeBuilder; }
public static Expression my(ReferenceExpression typeReference) { var myReference = new GenericReferenceExpression(typeReference.LexicalInfo); myReference.Target = AstUtil.CreateReferenceExpression(typeReference.LexicalInfo, "Boo.Lang.Environments.My"); myReference.GenericArguments.Add(TypeReference.Lift(typeReference)); return new MemberReferenceExpression(typeReference.LexicalInfo, myReference, "Instance"); }
public override void OnReferenceExpression(ReferenceExpression node) { if (LookingFor(node)) { Found(node); } }
/// <summary> /// This turn a call to TryGetParemeter('item') where item is a local variable /// into a WrapIfNull(item) method call. /// </summary> /// <param name="node">The node.</param> public override void OnMethodInvocationExpression(MethodInvocationExpression node) { var expression = node.Target as ReferenceExpression; if (expression == null || expression.Name != "TryGetParameter") { base.OnMethodInvocationExpression(node); return; } var name = ((StringLiteralExpression)node.Arguments[0]).Value; var entity = NameResolutionService.Resolve(name); if (entity == null) { base.OnMethodInvocationExpression(node); return; } var parentNode = node.ParentNode; var mie = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateSelfReference(_currentMethod.DeclaringType), wrapNullValue); var item = new ReferenceExpression(node.LexicalInfo, name); TypeSystemServices.Bind(item, entity); mie.Arguments.Add(item); parentNode.Replace(node, mie); }
public static ReferenceExpression CreateReferenceExpression(LexicalInfo li, string fullname) { ReferenceExpression e = CreateReferenceExpression(fullname); e.LexicalInfo = li; return(e); }
public override void OnReferenceExpression(ReferenceExpression node) { var entity = NameResolutionService.Resolve(node.Name); if (entity != null) { base.OnReferenceExpression(node); return; } if (node.Name.StartsWith("@")) { ReplaceWithComponentReference(node, node.Name); return; } else if (node.ParentNode is ExpressionPair) { var pair = (ExpressionPair) node.ParentNode; var literal = CodeBuilder.CreateStringLiteral(node.Name); pair.Replace(node, literal); return; } else if ( //search for the left side of a key in a hash literal expression node.ParentNode is ExpressionPair && ((ExpressionPair) node.ParentNode).First == node && node.ParentNode.ParentNode is HashLiteralExpression) { var parent = (ExpressionPair) node.ParentNode; var literal = CodeBuilder.CreateStringLiteral(node.Name); parent.First = literal; parent.Replace(node, literal); return; } base.OnReferenceExpression(node); }
/// <summary> /// Sets the node name to pascal case. /// </summary> /// <param name="node">The node.</param> protected virtual void TransformNodeName(ReferenceExpression node) { var nameCharacters = node.Name.ToCharArray(); nameCharacters[0] = char.ToUpperInvariant(nameCharacters[0]); node.Name = new string(nameCharacters); }
public static TypeReference Lift(ReferenceExpression e) { if (e == null) { return(null); } return(new SimpleTypeReference(e.LexicalInfo, e.ToString())); }
B.ReferenceExpression MakeReferenceExpression(string fullName) { string[] parts = fullName.Split('.'); B.ReferenceExpression r = new B.ReferenceExpression(lastLexicalInfo, parts[0]); for (int i = 1; i < parts.Length; i++) r = new B.MemberReferenceExpression(lastLexicalInfo, r, parts[i]); return r; }
public override void OnReferenceExpression(ReferenceExpression node) { IAccessibleMember member = node.Entity as IAccessibleMember; if (null == member) return; if (_checker.IsAccessible(member)) return; Error(CompilerErrorFactory.UnaccessibleMember(node, member.FullName)); }
public static CompilerError AmbiguousReference(ReferenceExpression reference, System.Reflection.MemberInfo[] members) { return new CompilerError("BCE0004", SafeLexicalInfo(reference), reference.Name, ToNameList(members) ); }
public override void OnMethodInvocationExpression(MethodInvocationExpression node) { if (node is MethodInvocationExpression && node.Target is GenericReferenceExpression) { var genericReferenceExpression = (GenericReferenceExpression)node.Target; if (genericReferenceExpression.Target is MemberReferenceExpression) { var memberReferenceExpression = (MemberReferenceExpression)genericReferenceExpression.Target; if (memberReferenceExpression.Target is MemberReferenceExpression) { var memberReferenceExpression2 = (MemberReferenceExpression)memberReferenceExpression.Target; if (memberReferenceExpression2.Target is MemberReferenceExpression) { var memberReferenceExpression3 = (MemberReferenceExpression)memberReferenceExpression2.Target; if (memberReferenceExpression3.Target is ReferenceExpression) { var referenceExpression = (ReferenceExpression)memberReferenceExpression3.Target; if (referenceExpression.Name == "Boo" && memberReferenceExpression3.Name == "Lang" && memberReferenceExpression2.Name == "Builtins" && memberReferenceExpression.Name == "array" && 1 == ((ICollection)genericReferenceExpression.GenericArguments).Count) { TypeReference node2 = genericReferenceExpression.GenericArguments[0]; if (1 == ((ICollection)node.Arguments).Count && node.Arguments[0] is CastExpression) { var castExpression = (CastExpression)node.Arguments[0]; Expression target = castExpression.Target; if (castExpression.Type is SimpleTypeReference) { var simpleTypeReference = (SimpleTypeReference)castExpression.Type; if (simpleTypeReference.Name == "int") { var methodInvocationExpression = new MethodInvocationExpression(LexicalInfo.Empty); var arg_255_0 = methodInvocationExpression; var genericReferenceExpression2 = new GenericReferenceExpression(LexicalInfo.Empty); GenericReferenceExpression arg_226_0 = genericReferenceExpression2; var referenceExpression2 = new ReferenceExpression(LexicalInfo.Empty); string text = referenceExpression2.Name = "array"; Expression expression = arg_226_0.Target = referenceExpression2; TypeReferenceCollection typeReferenceCollection = genericReferenceExpression2.GenericArguments = TypeReferenceCollection.FromArray(new TypeReference[] { TypeReference.Lift(node2) }); Expression expression2 = arg_255_0.Target = genericReferenceExpression2; ExpressionCollection expressionCollection = methodInvocationExpression.Arguments = ExpressionCollection.FromArray(new Expression[] { Expression.Lift(target) }); ReplaceCurrentNode(methodInvocationExpression); } } } } } } } } } }
/// <summary> /// Called when we encounter a reference expression /// </summary> /// <param name="node">The node.</param> public override void OnReferenceExpression(ReferenceExpression node) { if (this.ShouldTransformNodeName(node)) { this.TransformNodeName(node); } base.OnReferenceExpression(node); }
public WithExpander(ReferenceExpression instance) { this.instance = instance; /* foreach (var method in members.Where(m => m.EntityType == EntityType.Method)) { keywords.Add(method.Name); }*/ }
/// <summary> /// Called when visting a reference expression. /// Will turn reference expressions with initial @ to string literals /// </summary> /// <param name="node">The node.</param> public override void OnReferenceExpression(Boo.Lang.Compiler.Ast.ReferenceExpression node) { if (node.Name.StartsWith("@") == false) { return; } ReplaceCurrentNode(new StringLiteralExpression(node.Name.Substring(1))); }
public override void OnReferenceExpression(ReferenceExpression node) { if (node.Name[0] == '_') { var result = new MemberReferenceExpression(node.LexicalInfo); result.Name = node.Name.Substring(1); result.Target = instance.CloneNode(); ReplaceCurrentNode(result); } }
public override void OnReferenceExpression(ReferenceExpression node) { if (TypeInference.IsTypeLiteral(node)) { TypeofExpression typeofExpression = new TypeofExpression(LexicalInfo.Empty); TypeReference typeReference = typeofExpression.Type = TypeReference.Lift(node); this.ReplaceCurrentNode(typeofExpression); } }
public object VisitReDimStatement(ReDimStatement reDimStatement, object data) { // Redim [Preserve] a(newBounds) // without preserve: // a = array(Type, newBounds) // with preserve: // ??1 = array(Type, newBounds) // Array.Copy(a, ??1, System.Math.Min(a.Length, ??1.Length)) // a = ??1 if (reDimStatement.IsPreserve) { AddError(reDimStatement, "Redim Preserve is not supported."); } ArrayList list = new ArrayList(); foreach (InvocationExpression o in reDimStatement.ReDimClauses) { IdentifierExpression identifier = o.TargetObject as IdentifierExpression; if (identifier == null) { AddError(o, "Sorry, that expression is too complex to be resolved by the converter."); } else { if (identifier.TypeArguments != null && identifier.TypeArguments.Count > 0) { AddError(o, "Type parameters are not allowed here."); } // first we need to find out the array type VariableResolver resolver = new VariableResolver(nameComparer); TypeReference r = resolver.FindType(identifier.Identifier, reDimStatement); if (r == null) { AddError(o, "The name '" + identifier.Identifier + "' could not be resolved by the converter."); } else if (!r.IsArrayType) { AddError(o, identifier.Identifier + " is not an array."); } else { ArrayCreateExpression ace = new ArrayCreateExpression(r); foreach (Expression boundExpr in o.Arguments) { ace.Arguments.Add(Expression.AddInteger((Expression)boundExpr, 1)); } ace.StartLocation = o.StartLocation; B.Expression expr = new B.ReferenceExpression(GetLexicalInfo(identifier), identifier.Identifier); expr = new B.BinaryExpression(GetLexicalInfo(reDimStatement), B.BinaryOperatorType.Assign, expr, ConvertExpression(ace)); list.Add(new B.ExpressionStatement(expr)); } } } return(list); }
public void LiftCastExpression() { var referenceExpression = new ReferenceExpression("foo"); var typeReference = new SimpleTypeReference("T"); Expression cast = new TryCastExpression(referenceExpression, typeReference); var parameter = ParameterDeclaration.Lift(cast); Assert.AreEqual(referenceExpression.Name, parameter.Name); Assert.IsTrue(typeReference.Matches(parameter.Type)); Assert.AreNotSame(typeReference, parameter.Type); }
B.ReferenceExpression MakeReferenceExpression(string fullName) { string[] parts = fullName.Split('.'); B.ReferenceExpression r = new B.ReferenceExpression(lastLexicalInfo, parts[0]); for (int i = 1; i < parts.Length; i++) { r = new B.MemberReferenceExpression(lastLexicalInfo, r, parts[i]); } return(r); }
public static Expression build_with(ReferenceExpression builder, MethodInvocationExpression build, ReferenceExpression frameWorkVersion) { var targetName = builder.Name; return new MethodInvocationExpression( new ReferenceExpression(targetName), build.Arguments[0], new StringLiteralExpression(frameWorkVersion.Name) ); }
/// <summary> /// Sets the node name to pascal case. /// </summary> /// <param name="node">The node.</param> protected virtual void TransformNodeName(ReferenceExpression node) { string[] parts = node.Name.Split(new char[] { '_' },StringSplitOptions.RemoveEmptyEntries); StringBuilder name = new StringBuilder(); foreach (string part in parts) { name.Append(char.ToUpperInvariant(part[0])) .Append(part.Substring(1)); } node.Name = name.ToString(); }
public static ReferenceExpression CreateReferenceExpression(string fullname) { string[] parts = fullname.Split('.'); ReferenceExpression expression = new ReferenceExpression(parts[0]); expression.IsSynthetic = true; for (int i=1; i<parts.Length; ++i) { expression = new MemberReferenceExpression(expression, parts[i]); expression.IsSynthetic = true; } return expression; }
public static ReferenceExpression CreateReferenceExpression(string fullname) { string[] parts = fullname.Split('.'); ReferenceExpression expression = new ReferenceExpression(parts[0]); expression.IsSynthetic = true; for (int i = 1; i < parts.Length; ++i) { expression = new MemberReferenceExpression(expression, parts[i]); expression.IsSynthetic = true; } return(expression); }
public override void OnReferenceExpression(ReferenceExpression node){ if(checkAll(node)){ return; } if(checkSubstitution(node)){ return; } //else{ base.OnReferenceExpression(node); //} }
private ICompileUnit ResolveAssemblyReference(ReferenceExpression reference) { ICompileUnit existing = Parameters.FindAssembly(reference.Name); if (null != existing) return existing; ICompileUnit newAssembly = Parameters.LoadAssembly(reference.Name); if (null != newAssembly) { Parameters.References.Add(newAssembly); return newAssembly; } return null; }
public override void OnReferenceExpression(ReferenceExpression node) { Console.WriteLine("ConvertReferenceToStringLiteralCompilerStep: {0}", node.Name); var macro = node.GetAncestor(NodeType.MacroStatement) as MacroStatement; if (macro != null) { if (Array.Exists(macros, value => macro.Name == value)) { Console.WriteLine("ConvertReferenceToStringLiteralCompilerStep: replacing {0} at line {1}", node.Name, node.LexicalInfo.Line); ReplaceCurrentNode(new StringLiteralExpression(node.Name)); } } }
public override void OnReferenceExpression(ReferenceExpression node) { base.OnReferenceExpression(node); EvaluationContextEntity entity = node.get_Entity() as EvaluationContextEntity; if (entity != null) { if (!this.ValidateContext(entity)) { IMember member = entity.Delegate; this.get_Errors().Add(CompilerErrorFactory.InstanceRequired(node, member)); } node.get_ParentNode().Replace(node, this.MapToContextReference(entity)); } }
public override void OnReferenceExpression(ReferenceExpression node) { var entity = NameResolutionService.Resolve(node.Name); if (entity != null) { base.OnReferenceExpression(node); return; } var mie = CodeBuilder.CreateMethodInvocation( CodeBuilder.CreateSelfReference(_currentMethod.DeclaringType), GetMethod(node.Name)); mie.Arguments.Add(GetNameLiteral(node.Name)); node.ParentNode.Replace(node, mie); }
Expression ConvertExpressionToTemporaryVariable(Expression methodInvocation, Block block) { var temporaryVariable = new ReferenceExpression(Context.GetUniqueName("with")); var assignment = new WithBinaryExpression { Operator = BinaryOperatorType.Assign, Left = Expression.Lift(temporaryVariable), Right = methodInvocation }; block.Insert(0, assignment); return temporaryVariable; }
protected override Statement ExpandImpl(MacroStatement macro){ if (macro.Arguments.Count == 0) { Context.Errors.Add(new CompilerError(macro.LexicalInfo, "call macro requires at least one reference or string attribute for action name")); } var basis = new ReferenceExpression("Html"); var method = new MemberReferenceExpression(basis, "RenderAction"); var call = new MethodInvocationExpression(method); int i = 0; var result = new Block(); foreach (Expression argument in macro.Arguments){ i++; Expression exp = argument; if (!(exp is HashLiteralExpression)){ //action and contrller parameters if (!(exp is NullLiteralExpression)){ exp = new StringLiteralExpression(argument.ToCodeString()); } call.Arguments.Add(exp); } else{ string name = "__rd"; result.Add( new DeclarationStatement( new Declaration(name, null), new MethodInvocationExpression(AstUtil.CreateReferenceExpression("RouteValueDictionary")) ) ); var dict = argument as HashLiteralExpression; foreach (ExpressionPair item in dict.Items){ result.Add( new MethodInvocationExpression( AstUtil.CreateReferenceExpression(name + ".Add"), item.First, item.Second ) ); } if (i == 2){ call.Arguments.Add(new NullLiteralExpression()); } call.Arguments.Add(AstUtil.CreateReferenceExpression(name)); } } result.Add(call); return result; }
public override void OnReferenceExpression(ReferenceExpression node) { IEntity entity = NameResolutionService.Resolve(node.Name); //search for the left side of a key in a hash literal expression if (node.ParentNode is ExpressionPair && ((ExpressionPair)node.ParentNode).First == node && node.ParentNode.ParentNode is HashLiteralExpression) { ExpressionPair parent = (ExpressionPair)node.ParentNode; StringLiteralExpression literal = CodeBuilder.CreateStringLiteral(node.Name); parent.First = literal; parent.Replace(node, literal); return; } base.OnReferenceExpression(node); }
private static Expression[] GetExpressionsFromBlock(Block block) { List<Expression> expressions = new List<Expression>(block.Statements.Count); foreach (Statement statement in block.Statements) { if (statement is ExpressionStatement) expressions.Add((statement as ExpressionStatement).Expression); else if (statement is MacroStatement) { MacroStatement macroStatement = statement as MacroStatement; if (macroStatement.Arguments.Count == 0 && macroStatement.Body.IsEmpty) { // Assume it is a reference expression ReferenceExpression refExp = new ReferenceExpression(macroStatement.LexicalInfo); refExp.Name = macroStatement.Name; expressions.Add(refExp); } else { // Assume it is a MethodInvocation MethodInvocationExpression mie = new MethodInvocationExpression(macroStatement.LexicalInfo); mie.Target = new ReferenceExpression(macroStatement.LexicalInfo, macroStatement.Name); mie.Arguments = macroStatement.Arguments; if (macroStatement.Body.IsEmpty == false) { // If the macro statement has a block, // transform it into a block expression and pass that as the last argument // to the method invocation. BlockExpression be = new BlockExpression(macroStatement.LexicalInfo); be.Body = macroStatement.Body.CloneNode(); mie.Arguments.Add(be); } expressions.Add(mie); } } else { throw new InvalidOperationException(string.Format("Can not transform block with {0} into argument.", statement.GetType())); } } return expressions.ToArray(); }
override public object Clone() { ReferenceExpression clone = new ReferenceExpression(); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._isSynthetic = _isSynthetic; clone._entity = _entity; if (_annotations != null) { clone._annotations = (Hashtable)_annotations.Clone(); } clone._expressionType = _expressionType; clone._name = _name; return(clone); }
override public object Clone() { ReferenceExpression clone = (ReferenceExpression)FormatterServices.GetUninitializedObject(typeof(ReferenceExpression)); clone._lexicalInfo = _lexicalInfo; clone._endSourceLocation = _endSourceLocation; clone._documentation = _documentation; clone._entity = _entity; if (_annotations != null) { clone._annotations = (Hashtable)_annotations.Clone(); } clone._expressionType = _expressionType; clone._name = _name; return(clone); }
public static ReferenceExpression CreateReferenceExpression(string fullname) { var parts = fullname.Split('.'); var expression = new ReferenceExpression(parts[0]) { IsSynthetic = true }; for (var i = 1; i < parts.Length; ++i) { expression = new MemberReferenceExpression(expression, parts[i]) { IsSynthetic = true } } ; return(expression); }
public override void Apply(Node targetNode) { var cls = targetNode as ClassDefinition; if(cls==null) { this.Context.Errors.Add(new CompilerError(this.LexicalInfo, "ControllerAttribute is applyable only to classes")); return; } targetNode.GetEnclosingModule().Imports.Add(new Import(this.LexicalInfo,"Comdiv.Controllers")); cls.BaseTypes.Clear(); cls.BaseTypes.Insert(0, new SimpleTypeReference("Comdiv.Controllers.ExtensionBaseController")); if(!cls.Name.EndsWith("Controller")) { cls.Name = cls.Name + "Controller"; } var body = targetNode.GetEnclosingModule()["regmethod"] as Block; var registrycall = new SlicingExpression(new ReferenceExpression("registry"), new StringLiteralExpression(cls.Name.ToLower())); var assign = new ReferenceExpression(cls.Name); var aexpr = new BinaryExpression(BinaryOperatorType.Assign, registrycall, assign); body.Add(aexpr); }
protected override void AddResolvedNamedArgumentToEval(MethodInvocationExpression eval, ExpressionPair pair, ReferenceExpression instance) { if (!TypeSystemServices.IsQuackBuiltin(pair.First)) { base.AddResolvedNamedArgumentToEval(eval, pair, instance); return; } MemberReferenceExpression memberRef = new MemberReferenceExpression( pair.First.LexicalInfo, instance.CloneNode(), ((ReferenceExpression)pair.First).Name); BindQuack(memberRef); eval.Arguments.Add( CodeBuilder.CreateAssignment( pair.First.LexicalInfo, memberRef, pair.Second)); }
B.Expression MakeReferenceExpression(TypeReference typeRef) { if (typeRef.IsArrayType) { return(new B.TypeofExpression(GetLexicalInfo(typeRef), ConvertTypeReference(typeRef))); } B.SimpleTypeReference t = (B.SimpleTypeReference)ConvertTypeReference(typeRef); B.ReferenceExpression r = MakeReferenceExpression(t.Name); if (t is B.GenericTypeReference) { B.GenericReferenceExpression gr = new B.GenericReferenceExpression(GetLexicalInfo(typeRef)); gr.Target = r; foreach (B.TypeReference tr in ((B.GenericTypeReference)t).GenericArguments) { gr.GenericArguments.Add(tr); } return(gr); } else { return(r); } }
public GotoStatement(LexicalInfo lexicalInfo, ReferenceExpression label) : base(lexicalInfo) { this.Label = label; }
public static ParameterDeclaration Lift(ReferenceExpression referenceExpression) { return(new ParameterDeclaration(referenceExpression.Name, null)); }
public Local(ReferenceExpression reference, bool privateScope) { _name = reference.Name; LexicalInfo = reference.LexicalInfo; _privateScope = privateScope; }
public static string LiftName(ReferenceExpression node) { return(node.Name); }
public GotoStatement(LexicalInfo lexicalInfo, ReferenceExpression label) : base(lexicalInfo, label) { }
public static GenericParameterDeclaration Lift(ReferenceExpression referenceExpression) { return(new GenericParameterDeclaration(referenceExpression.Name)); }
private static ReferenceExpression ReferenceExpressionFor(Type type) { return(ReferenceExpression.Lift(TypeUtilities.GetFullName(type))); }
public Import(string namespace_, ReferenceExpression assemblyReference, ReferenceExpression alias) { this.Namespace = namespace_; this.AssemblyReference = assemblyReference; this.Alias = alias; }
public Import(string namespace_, ReferenceExpression assemblyReference, ReferenceExpression alias) : base(namespace_, assemblyReference, alias) { }
public Import(Expression namespace_, ReferenceExpression assemblyReference, ReferenceExpression alias) { Expression = namespace_; AssemblyReference = assemblyReference; Alias = alias; }