public BinaryOpChain(Expression left, Token op, Expression right, TopLevelConstruct owner) : base(left.FirstToken, owner) { this.Left = left; this.Right = right; this.Op = op; }
internal static ClassDefinition DoClassLookup(TopLevelConstruct currentContainer, Token nameToken, string name, bool failSilently) { TopLevelConstruct ex = currentContainer.FileScope.FileScopeEntityLookup.DoLookup(name, currentContainer); if (ex == null) { if (failSilently) { return(null); } string message = "No class named '" + name + "' was found."; if (name.Contains(".")) { message += " Did you forget to import a library?"; } throw new ParserException(nameToken, message); } if (ex is ClassDefinition) { return((ClassDefinition)ex); } // Still throw an exception if the found item is not a class. This is used by code to check if // something is a valid variable name or a class name. Colliding with something else is bad. throw new ParserException(nameToken, "This is not a class."); }
public ClassDefinition( Token classToken, Token nameToken, IList <Token> subclassTokens, IList <string> subclassNames, string ns, TopLevelConstruct owner, Library library, Token staticToken, Token finalToken, FileScope fileScope) : base(classToken, owner, fileScope) { this.Library = library; this.ClassID = ClassDefinition.classIdAlloc++; this.Namespace = ns; this.NameToken = nameToken; this.BaseClassTokens = subclassTokens.ToArray(); this.BaseClassDeclarations = subclassNames.ToArray(); this.StaticToken = staticToken; this.FinalToken = finalToken; if (staticToken != null && this.BaseClassTokens.Length > 0) { throw new ParserException(staticToken, "Class cannot be static and have base classes or interfaces."); } }
public ConstructorDefinition( Token constructorToken, IList <Token> args, IList <Expression> defaultValues, IList <Expression> baseArgs, IList <Executable> code, Token baseToken, TopLevelConstruct owner) : base(constructorToken, owner, owner.FileScope) { this.IsDefault = false; this.ArgNames = args.ToArray(); this.DefaultValues = defaultValues.ToArray(); this.BaseArgs = baseArgs.ToArray(); this.Code = code.ToArray(); this.BaseToken = baseToken; TODO.VerifyDefaultArgumentsAreAtTheEnd(); this.MaxArgCount = this.ArgNames.Length; int minArgCount = 0; for (int i = 0; i < this.ArgNames.Length; ++i) { if (this.DefaultValues[i] == null) { minArgCount++; } else { break; } } this.MinArgCount = minArgCount; }
public DotStep(Expression root, Token dotToken, Token stepToken, TopLevelConstruct owner) : base(root.FirstToken, owner) { this.Root = root; this.DotToken = dotToken; this.StepToken = stepToken; }
public BracketIndex(Expression root, Token bracketToken, Expression index, TopLevelConstruct owner) : base(root.FirstToken, owner) { this.Root = root; this.BracketToken = bracketToken; this.Index = index; }
public EnumDefinition(Token enumToken, Token nameToken, string ns, TopLevelConstruct owner, Library library, FileScope fileScope) : base(enumToken, owner, fileScope) { this.Library = library; this.NameToken = nameToken; this.Name = nameToken.Value; this.Namespace = ns; }
public ConstStatement(Token constToken, Token nameToken, string ns, TopLevelConstruct owner, Library library, FileScope fileScope) : base(constToken, owner, fileScope) { this.Library = library; this.NameToken = nameToken; this.Name = nameToken.Value; this.Namespace = ns; }
public Executable(Token firstToken, TopLevelConstruct owner) : base(firstToken, owner) { if (owner == null) { throw new Exception(); // This should never happen. } }
public ConstructorDefinition(TopLevelConstruct owner) : base(null, owner, owner.FileScope) { this.IsDefault = true; this.Code = new Executable[0]; this.ArgNames = new Token[0]; this.DefaultValues = new Expression[0]; this.BaseArgs = new Expression[0]; this.MaxArgCount = 0; this.MinArgCount = 0; }
public CoreFunctionInvocation(Token firstToken, Expression[] originalArgs, TopLevelConstruct owner) : base(firstToken, owner) { if (originalArgs.Length == 0 || !(originalArgs[0] is StringConstant)) { throw new ParserException(firstToken, "$$$ invocations must include a string constant containing the function name."); } this.FunctionId = CoreFunctionIDHelper.GetId((StringConstant)originalArgs[0]); List <Expression> args = new List <Expression>(originalArgs); args.RemoveAt(0); this.Args = args.ToArray(); }
// pardon the double-plurals for the jaggy 2D arrays public TryStatement( Token tryToken, IList <Executable> tryBlock, List <Token> catchTokens, List <Token> exceptionVariableTokens, List <Token[]> catchBlockTypeTokenses, // tricksy tokenses List <string[]> catchBlockTypeses, List <Executable[]> catchBlockExecutableses, Token finallyToken, IList <Executable> finallyBlock, TopLevelConstruct owner) : base(tryToken, owner) { this.TryToken = tryToken; this.TryBlock = tryBlock.ToArray(); int catchBlockCount = catchTokens.Count; // individual catch-related inputs are trusted to all have same length this.CatchBlocks = new CatchBlock[catchBlockCount]; for (int i = 0; i < catchBlockCount; ++i) { Token catchToken = catchTokens[i]; Token variableName = exceptionVariableTokens[i]; Token[] catchBlockTypeTokens = catchBlockTypeTokenses[i]; string[] catchBlockTypes = catchBlockTypeses[i]; Executable[] catchBlockExecutables = catchBlockExecutableses[i]; this.CatchBlocks[i] = new CatchBlock() { CatchToken = catchToken, Code = catchBlockExecutables, ExceptionVariableToken = variableName, Types = catchBlockTypes, TypeTokens = catchBlockTypeTokens, VariableLocalScopeId = -1, }; } this.FinallyToken = finallyToken; this.FinallyBlock = finallyBlock == null ? new Executable[0] : finallyBlock.ToArray(); if (this.CatchBlocks.Length == 0 && this.FinallyBlock == null) { throw new ParserException(this.TryToken, "Cannot have a try block without a catch or finally block."); } }
internal override void PerformLocalIdAllocation(Parser parser, VariableIdAllocator varIds, VariableIdAllocPhase phase) { if ((phase & VariableIdAllocPhase.ALLOC) != 0) { this.LocalScopeId = varIds.GetVarId(this.FirstToken); if (this.LocalScopeId == -1) { string name = this.FirstToken.Value; if (parser.LibraryManager.IsValidLibraryName(parser, name)) { throw new ParserException(this.FirstToken, "'" + name + "' is referenced but not imported in this file."); } TopLevelConstruct owner = this.Owner; while (owner != null && !(owner is ClassDefinition)) { owner = owner.Owner; } if (owner != null) { ClassDefinition cd = (ClassDefinition)owner; foreach (FieldDeclaration fd in cd.Fields) { if (fd.NameToken.Value == name) { string message = "'" + name + "' is used like a local variable but it is " + (fd.IsStaticField ? "a static" : "an instance") + " field."; message += " Did you mean '" + (fd.IsStaticField ? cd.NameToken.Value : "this") + "." + name + "' instead of '" + name + "'?"; throw new ParserException(this.FirstToken, message); } } } // TODO: But if it's being called like a function then... // - give a better error message "function 'foo' is not defined" // - give an even better error message when there's a class or instance function with the same name // e.g. "'foo' is a static function and must be invoked with the class name: FooClass.foo(...) // - if there's a method, suggest using "this." throw new ParserException(this.FirstToken, "The variable '" + name + "' is used but is never assigned to."); } } }
public FunctionDefinition( Token functionToken, Library library, TopLevelConstruct nullableOwner, bool isStaticMethod, Token nameToken, IList <Annotation> functionAnnotations, string namespyace, FileScope fileScope) : base(functionToken, nullableOwner, fileScope) { this.Library = library; this.IsStaticMethod = isStaticMethod; this.Namespace = namespyace; this.NameToken = nameToken; this.annotations = new Dictionary <string, Annotation>(); foreach (Annotation annotation in functionAnnotations) { this.annotations[annotation.Type] = annotation; } this.MemberID = -1; }
public void ResolveBaseClasses() { List <ClassDefinition> baseClasses = new List <ClassDefinition>(); List <Token> baseClassesTokens = new List <Token>(); for (int i = 0; i < this.BaseClassDeclarations.Length; ++i) { string value = this.BaseClassDeclarations[i]; Token token = this.BaseClassTokens[i]; TopLevelConstruct baseClassInstance = this.FileScope.FileScopeEntityLookup.DoLookup(value, this); if (baseClassInstance == null) { throw new ParserException(token, "No class named '" + token.Value + "' was found."); } if (baseClassInstance is ClassDefinition) { baseClasses.Add((ClassDefinition)baseClassInstance); baseClassesTokens.Add(token); } // TODO: else if (baseClassInstance is InterfaceDefinition) { ... } else { throw new ParserException(token, "This is not a class."); } } if (baseClasses.Count > 1) { throw new ParserException(baseClassesTokens[1], "Multiple base classes found. Did you mean to use an interface?"); } if (baseClasses.Count == 1) { this.BaseClass = baseClasses[0]; } }
public Ternary(Expression condition, Expression trueValue, Expression falseValue, TopLevelConstruct owner) : base(condition.FirstToken, owner) { this.Condition = condition; this.TrueValue = trueValue; this.FalseValue = falseValue; }
public IsComparison(Expression root, Token isToken, Token firstClassToken, string classNameWithNamespace, TopLevelConstruct owner) : base(root.FirstToken, owner) { this.Expression = root; this.IsToken = isToken; this.ClassToken = firstClassToken; this.ClassName = classNameWithNamespace; }
public NullCoalescer(Expression primaryExpression, Expression secondaryExpression, TopLevelConstruct owner) : base(primaryExpression.FirstToken, owner) { this.PrimaryExpression = primaryExpression; this.SecondaryExpression = secondaryExpression; }
public FloatConstant(Token startValue, double value, TopLevelConstruct owner) : base(startValue, owner) { this.Value = value; }
public Expression(Token firstToken, TopLevelConstruct owner) : base(firstToken, owner) { this.Annotations = null; }
public ForLoop(Token forToken, IList <Executable> init, Expression condition, IList <Executable> step, IList <Executable> code, TopLevelConstruct owner) : base(forToken, owner) { this.Init = init.ToArray(); this.Condition = condition ?? new BooleanConstant(forToken, true, owner); this.Step = step.ToArray(); this.Code = code.ToArray(); }
public IfStatement(Token ifToken, Expression condition, IList <Executable> trueCode, IList <Executable> falseCode, TopLevelConstruct owner) : base(ifToken, owner) { this.Condition = condition; this.TrueCode = trueCode.ToArray(); this.FalseCode = falseCode.ToArray(); }
public NegativeSign(Token sign, Expression root, TopLevelConstruct owner) : base(sign, owner) { this.Root = root; }
public BooleanNot(Token bang, Expression root, TopLevelConstruct owner) : base(bang, owner) { this.Root = root; }
public WhileLoop(Token whileToken, Expression condition, IList <Executable> code, TopLevelConstruct owner) : base(whileToken, owner) { this.Condition = condition; this.Code = code.ToArray(); }
public Expression CloneValue(Token token, TopLevelConstruct owner) { return(new FloatConstant(token, this.Value, owner)); }
public ContinueStatement(Token continueToken, TopLevelConstruct owner) : base(continueToken, owner) { }
public Namespace(Token namespaceToken, string name, TopLevelConstruct owner, Library library, FileScope fileScope) : base(namespaceToken, owner, fileScope) { this.Library = library; this.Name = name; }
public ListSlice(Expression root, List <Expression> items, Token bracketToken, TopLevelConstruct owner) : base(root.FirstToken, owner) { this.Root = root; this.BracketToken = bracketToken; if (items.Count == 2) { items.Add(new IntegerConstant(null, 1, owner)); } if (items.Count != 3) { throw new Exception("Slices must have 2 or 3 components before passed into the constructor."); } if (items[2] == null) { items[2] = new IntegerConstant(null, 1, owner); } this.Items = items.ToArray(); }
public ForEachLoop(Token forToken, Token iterationVariable, Expression iterationExpression, IList <Executable> code, TopLevelConstruct owner) : base(forToken, owner) { this.IterationVariable = iterationVariable; this.IterationExpression = iterationExpression; this.Code = code.ToArray(); }