public override Node Transform(ParseScope Scope) { Object = Object.Transform(Scope); Index = Index.Transform(Scope); if (IsAssignmentTarget) { //Try to find an indexer macro for this type. var setterArguments = DummyArguments(Keyword("SET"), Keyword("AT"), Term(Index.ResultType), Keyword("IN"), Term(Object.ResultType), Keyword("TO"), TermOfAnyType()); var matchingSetter = Scope.FindAllPossibleMacroMatches(setterArguments).Where(d => ExactDummyMatch(d.Terms, setterArguments)).FirstOrDefault(); if (matchingSetter != null) return new ExplicitIndexSetter(Source, matchingSetter, Object, Index).Transform(Scope); else throw new CompileError("No macro of the form SET AT " + Index.ResultType.Name + " IN " + Object.ResultType.Name + " TO VALUE found.", Source); } else { //Try to find an access macro for this type. var getterArguments = DummyArguments(Keyword("GET"), Keyword("AT"), Term(Index.ResultType), Keyword("FROM"), Term(Object.ResultType)); var matchingGetter = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d => ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault(); if (matchingGetter != null) return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingGetter, new List<Node>(new Node[] { Index, Object })).Transform(Scope); else throw new CompileError("No macro of the form GET AT " + Index.ResultType.Name + " FROM " + Object.ResultType.Name + " found.", Source); } }
public override Ast.Node Transform(ParseScope Scope) { //Look for a control macro. var control = Scope.EnvironmentContext.FindControl(Arguments); if (control != null && control.BlockType == ControlBlockType.NoBlock) return control.TransformationFunction( Declaration.GenerateParameterListSyntaxTree(Arguments, control.DeclarationTerms).Members, null).Transform(Scope); var possibleMatches = Scope.FindAllPossibleMacroMatches(Arguments); var match = FindTypeMatch(possibleMatches, Arguments, Scope); if (match == null) { var errorMessage = "Could not find match for static invokation. Arguments: "; foreach (var argument in Arguments) { errorMessage += "("; if (argument is Identifier) errorMessage += (argument as Identifier).Name.Value; if (argument.ResultType != null) errorMessage += argument.ResultType.Name + ") "; else errorMessage += "NULL)"; } throw new CompileError(errorMessage, Source); } return CreateCorrectInvokationNode(Source, Scope, match.Item1, match.Item2).Transform(Scope); }
public override Node Transform(ParseScope Scope) { LHS = LHS.Transform(Scope); RHS = RHS.Transform(Scope); //Generics behave dynamically with operators. if (Object.ReferenceEquals(LHS.ResultType, Type.Generic) || Object.ReferenceEquals(RHS.ResultType, Type.Generic)) return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Type.Generic); //Equality works with everything. if (Operator.token == "==" || Operator.token == "!=") return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Scope.FindType("BOOLEAN")); if (Object.ReferenceEquals(LHS.ResultType, RHS.ResultType)) { PopulateRawOperators(); if (RawOperators.ContainsKey(LHS.ResultType.Name)) if (RawOperators[LHS.ResultType.Name].Contains(Operator.token)) { //Return type is always boolean for raw comparisons. if (Operator.token == ">" || Operator.token == ">=" || Operator.token == "<" || Operator.token == "<=") return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, Scope.FindType("BOOLEAN")); return new RawBinaryOperator(Source, Operator.instruction, LHS, RHS, LHS.ResultType); } } //Try to find an operator macro for these types. var operatorArguments = DummyArguments(Term(LHS.ResultType), Keyword(Operator.token), Term(RHS.ResultType)); var matchingOperator = Scope.FindAllPossibleMacroMatches(operatorArguments).Where(d => ExactDummyMatch(d.Terms, operatorArguments)).FirstOrDefault(); if (matchingOperator != null) { return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingOperator, new List<Node>(new Node[] { LHS, RHS })).Transform(Scope); } else throw new CompileError("No operator macro of the form " + LHS.ResultType.Name + " " + Operator.token + " " + RHS.ResultType.Name + " found.", Source); }
public override Node Transform(ParseScope Scope) { this.Scope = Scope; ResultType = Scope.FindType(Typename); if (ResultType == null) throw new CompileError("Unable to find type with name '" + Typename + "'", Source); if (ResultType.Origin != TypeOrigin.Script) throw new CompileError("New cannot be used with primitive or system types", Source); var constructorArguments = DummyArguments(Keyword("CONSTRUCT"), Term(ResultType)); Constructor = Scope.FindAllPossibleMacroMatches(constructorArguments).Where(d => ExactDummyMatch(d.Terms, constructorArguments)).FirstOrDefault(); if (Initializers != null) { foreach (var initializer in Initializers) { initializer.ObjectType = ResultType; initializer.Transform(Scope); } } return this; }
public override Node Transform(ParseScope Scope) { Object = Object.Transform(Scope); if (IsAssignmentTarget) { if (Object.ResultType.Origin == TypeOrigin.System) { //Try to find an access macro for this type. var setterArguments = DummyArguments(Keyword("SET"), Keyword(Name), Keyword("ON"), Term(Object.ResultType), Keyword("TO"), TermOfAnyType()); var matchingSetter = Scope.FindAllPossibleMacroMatches(setterArguments).Where(d => ExactDummyMatch(d.Terms, setterArguments)).FirstOrDefault(); if (matchingSetter != null) return new ExplicitSetter(Source, matchingSetter, Object).Transform(Scope); else { setterArguments = DummyArguments(Keyword("SET"), Term(Scope.FindType("STRING")), Keyword("ON"), Term(Object.ResultType), Keyword("TO"), TermOfAnyType()); matchingSetter = Scope.FindAllPossibleMacroMatches(setterArguments).Where(d => ExactDummyMatch(d.Terms, setterArguments)).FirstOrDefault(); if (matchingSetter != null) return new GenericSetter(Source, matchingSetter, Name, Object).Transform(Scope); else throw new CompileError("No macro of the form SET " + Name + " ON " + Object.ResultType.Name + " TO VALUE found.", Source); } } else if (Object.ResultType.Origin == TypeOrigin.Script) return new StaticMemberAccess(Source) { MemberName = Name, Object = Object }.Transform(Scope); else throw new CompileError("Can't assign to this target", Source); } else { if (Object.ResultType.Origin == TypeOrigin.System) { //Try to find an access macro for this type. var getterArguments = DummyArguments(Keyword("GET"), Keyword(Name), Keyword("FROM"), Term(Object.ResultType)); var matchingGetter = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d => ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault(); if (matchingGetter != null) return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingGetter, new List<Node>(new Node[] { Object })).Transform(Scope); else { getterArguments = DummyArguments(Keyword("GET"), Term(Scope.FindType("STRING")), Keyword("FROM"), Term(Object.ResultType)); matchingGetter = Scope.FindAllPossibleMacroMatches(getterArguments).Where(d => ExactDummyMatch(d.Terms, getterArguments)).FirstOrDefault(); if (matchingGetter != null) return StaticInvokation.CreateCorrectInvokationNode(Source, Scope, matchingGetter, new List<Node>(new Node[] { new Ast.StringLiteral(Source, Name), Object })).Transform(Scope); else throw new CompileError("No macro of the form GET " + Name + " FROM " + Object.ResultType.Name + " found.", Source); } } else if (Object.ResultType.Origin == TypeOrigin.Script) return new StaticMemberAccess(Source) { MemberName = Name, Object = Object }.Transform(Scope); else if (Object.ResultType.Origin == TypeOrigin.Primitive) throw new CompileError("Can't access members of primitives.", Source); else throw new CompileError("Impossible.", Source); } }