Esempio n. 1
0
		protected override void TranslateFunctionCall(List<string> output, FunctionCall functionCall)
		{
			TranslateExpression(output, functionCall.Root);
			output.Add("(");
			for (int i = 0; i < functionCall.Args.Length; ++i)
			{
				if (i > 0) output.Add(", ");
				TranslateExpression(output, functionCall.Args[i]);
			}
			output.Add(")");
		}
Esempio n. 2
0
		private static Expression ParseEntity(TokenStream tokens, Executable owner)
		{
			Expression root;
			if (tokens.PopIfPresent("("))
			{
				root = Parse(tokens, owner);
				tokens.PopExpected(")");
			}
			else
			{
				root = ParseEntityWithoutSuffixChain(tokens, owner);
			}
			bool anySuffixes = true;
			while (anySuffixes)
			{
				if (tokens.IsNext("."))
				{
					Token dotToken = tokens.Pop();
					Token stepToken = tokens.Pop();
					Parser.VerifyIdentifier(stepToken);
					root = new DotStep(root, dotToken, stepToken, owner);
				}
				else if (tokens.IsNext("["))
				{
					Token openBracket = tokens.Pop();
					List<Expression> sliceComponents = new List<Expression>();
					if (tokens.IsNext(":"))
					{
						sliceComponents.Add(null);
					}
					else
					{
						sliceComponents.Add(Parse(tokens, owner));
					}

					for (int i = 0; i < 2; ++i)
					{
						if (tokens.PopIfPresent(":"))
						{
							if (tokens.IsNext(":") || tokens.IsNext("]"))
							{
								sliceComponents.Add(null);
							}
							else
							{
								sliceComponents.Add(Parse(tokens, owner));
							}
						}
					}

					tokens.PopExpected("]");

					if (sliceComponents.Count == 1)
					{
						Expression index = sliceComponents[0];
						root = new BracketIndex(root, openBracket, index, owner);
					}
					else
					{
						root = new ListSlice(root, sliceComponents, openBracket, owner);
					}
				}
				else if (tokens.IsNext("("))
				{
					Token openParen = tokens.Pop();
					List<Expression> args = new List<Expression>();
					while (!tokens.PopIfPresent(")"))
					{
						if (args.Count > 0)
						{
							tokens.PopExpected(",");
						}

						args.Add(Parse(tokens, owner));
					}
					root = new FunctionCall(root, openParen, args, owner);
				}
				else
				{
					anySuffixes = false;
				}
			}
			return root;
		}
Esempio n. 3
0
		private void CompileFunctionCall(Parser parser, ByteBuffer buffer, FunctionCall funCall, bool outputUsed)
		{
			Expression root = funCall.Root;
			if (root is FunctionReference)
			{
				FunctionReference verifiedFunction = (FunctionReference)root;
				FunctionDefinition fd = verifiedFunction.FunctionDefinition;
				this.CompileExpressionList(parser, buffer, funCall.Args, true);
				if (fd.FunctionOrClassOwner is ClassDefinition)
				{
					ClassDefinition cd = (ClassDefinition)fd.FunctionOrClassOwner;
					if (fd.IsStaticMethod)
					{
						buffer.Add(
							funCall.ParenToken,
							OpCode.CALL_FUNCTION,
							(int)FunctionInvocationType.STATIC_METHOD,
							funCall.Args.Length,
							fd.FunctionID,
							outputUsed ? 1 : 0,
							cd.ClassID);
					}
					else
					{
						buffer.Add(
							funCall.ParenToken,
							OpCode.CALL_FUNCTION,
							(int)FunctionInvocationType.LOCAL_METHOD,
							funCall.Args.Length,
							fd.FunctionID,
							outputUsed ? 1 : 0,
							cd.ClassID);
					}
				}
				else
				{
					// vanilla function
					buffer.Add(
						funCall.ParenToken,
						OpCode.CALL_FUNCTION,
						(int) FunctionInvocationType.NORMAL_FUNCTION,
						funCall.Args.Length,
						fd.FunctionID,
						outputUsed ? 1 : 0,
						0);
				}
			}
			else if (root is DotStep)
			{
				DotStep ds = (DotStep)root;
				Expression dotRoot = ds.Root;
				int globalNameId = parser.GetId(ds.StepToken.Value);
				this.CompileExpression(parser, buffer, dotRoot, true);
				this.CompileExpressionList(parser, buffer, funCall.Args, true);
				buffer.Add(
					funCall.ParenToken,
					OpCode.CALL_FUNCTION,
					(int)FunctionInvocationType.FIELD_INVOCATION,
					funCall.Args.Length,
					0,
					outputUsed ? 1 : 0,
					globalNameId);
			}
			else if (root is BaseMethodReference)
			{
				BaseMethodReference bmr = (BaseMethodReference)root;
				FunctionDefinition fd = bmr.ClassToWhichThisMethodRefers.GetMethod(bmr.StepToken.Value, true);
				if (fd == null)
				{
					throw new ParserException(bmr.DotToken, "This method does not exist on any base class.");
				}

				this.CompileExpressionList(parser, buffer, funCall.Args, true);
				buffer.Add(
					funCall.ParenToken,
					OpCode.CALL_FUNCTION,
					(int)FunctionInvocationType.LOCAL_METHOD,
					funCall.Args.Length,
					fd.FunctionID,
					outputUsed ? 1 : 0,
					bmr.ClassToWhichThisMethodRefers.ClassID);
			}
			else
			{
				this.CompileExpression(parser, buffer, root, true);
				this.CompileExpressionList(parser, buffer, funCall.Args, true);
				buffer.Add(
					funCall.ParenToken,
					OpCode.CALL_FUNCTION,
					(int)FunctionInvocationType.POINTER_PROVIDED,
					funCall.Args.Length,
					0,
					outputUsed ? 1 : 0,
					0);
			}
		}
Esempio n. 4
0
		protected abstract void TranslateFunctionCall(List<string> output, FunctionCall functionCall);