internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { this.IterationExpression.ResolveVariableOrigins(parser, varIds, phase); if ((phase & VariableIdAllocPhase.REGISTER) != 0) { varIds.RegisterVariable(this.IterationType, this.IterationVariable.Value); this.IndexLocalId = varIds.RegisterSyntheticVariable(AType.Integer(this.FirstToken)); this.ListLocalId = varIds.RegisterSyntheticVariable(AType.Any(this.FirstToken)); } if (phase != VariableIdAllocPhase.REGISTER_AND_ALLOC) { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, phase); } } else { foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.REGISTER); } foreach (Executable ex in this.Code) { ex.ResolveVariableOrigins(parser, varIds, VariableIdAllocPhase.ALLOC); } } this.IterationVariableId = varIds.GetVarId(this.IterationVariable); }
internal override void ResolveVariableOrigins(ParserContext parser, VariableScope varIds, VariableIdAllocPhase phase) { this.Value.ResolveVariableOrigins(parser, varIds, phase); if ((phase & VariableIdAllocPhase.REGISTER) != 0) { bool isVariableAssigned = // A variable is considered declared if the target is a variable and = is used instead of something like += this.Target is Variable && this.Op == Ops.EQUALS; if (isVariableAssigned) { if (this.CompilationScope.IsStaticallyTyped) { if (this.NullableTypeDeclaration != null) { varIds.RegisterVariable(this.NullableTypeDeclaration, this.TargetAsVariable.Name, false); } } else { varIds.RegisterVariable(AType.Any(this.FirstToken), this.TargetAsVariable.Name); } } } this.Target.ResolveVariableOrigins(parser, varIds, phase); }
protected override AType PostProcess(AType argument, AType result) { // if there is any float in the integer list, convert the whole list to float if (argument.Type == ATypes.AInteger && result.Any(item => item.Type == ATypes.AFloat)) { result.ConvertToFloat(); } return(result); }
protected override AType PostProcess(AType argument, AType result) { // if there is any float in the integer list, convert the whole list to float if (argument.Type == ATypes.AInteger && result.Any(item => item.Type == ATypes.AFloat)) { result.ConvertToFloat(); } return result; }
protected override Pair <AType, Token> ParseForEachLoopIteratorVariable(TokenStream tokens, Node owner) { tokens.EnsureNotEof(); Token variable = tokens.PopIfWord(); if (variable == null) { throw new ParserException(tokens.Peek(), "Expected variable here."); } return(new Pair <AType, Token>(AType.Any(variable), variable)); }
internal override Expression Resolve(ParserContext parser) { ListDefinition ld = new ListDefinition( this.FirstToken, this.GetValues().Select(i => new IntegerConstant(this.FirstToken, i, this.Owner)).ToArray(), AType.Any(), this.Owner, true, null); ld.ResolvedType = this.ResolvedType; return(ld); }
protected override ConstDefinition ParseConst( TokenStream tokens, Node owner, FileScope fileScope, ModifierCollection modifiers, AnnotationCollection annotations) { Token constToken = tokens.PopExpected(this.parser.Keywords.CONST); Token nameToken = tokens.Pop(); ConstDefinition constStatement = new ConstDefinition(constToken, AType.Any(constToken), nameToken, owner, fileScope, modifiers, annotations); this.parser.VerifyIdentifier(nameToken); tokens.PopExpected("="); constStatement.Expression = this.parser.ExpressionParser.Parse(tokens, constStatement); tokens.PopExpected(";"); return(constStatement); }
// TODO: don't manually parse static here, just get it from modifiers protected override FieldDefinition ParseField( TokenStream tokens, ClassDefinition owner, ModifierCollection modifiers, AnnotationCollection annotations) { Token fieldToken = tokens.PopExpected(this.parser.Keywords.FIELD); Token nameToken = tokens.Pop(); this.parser.VerifyIdentifier(nameToken); FieldDefinition fd = new FieldDefinition(fieldToken, AType.Any(fieldToken), nameToken, owner, modifiers, annotations); if (tokens.PopIfPresent("=")) { fd.DefaultValue = this.parser.ExpressionParser.Parse(tokens, fd); } tokens.PopExpected(";"); return(fd); }
protected override FunctionDefinition ParseFunction( TokenStream tokens, TopLevelEntity nullableOwner, FileScope fileScope, ModifierCollection modifiers, AnnotationCollection annotations) { bool isStatic = nullableOwner != null && nullableOwner is ClassDefinition && tokens.PopIfPresent(this.parser.Keywords.STATIC); Token functionToken = tokens.PopExpected(this.parser.Keywords.FUNCTION); Token functionNameToken = tokens.Pop(); this.parser.VerifyIdentifier(functionNameToken); FunctionDefinition fd = new FunctionDefinition(functionToken, AType.Any(functionToken), nullableOwner, functionNameToken, modifiers, annotations, fileScope); tokens.PopExpected("("); List <Token> argNames = new List <Token>(); List <Expression> defaultValues = new List <Expression>(); List <AType> argTypes = new List <AType>(); this.ParseArgumentListDeclaration(tokens, fd, argTypes, argNames, defaultValues); fd.ArgTypes = argTypes.ToArray(); fd.ArgNames = argNames.ToArray(); fd.DefaultValues = defaultValues.ToArray(); fd.FinalizeArguments(); IList <Executable> code = this.parser.ExecutableParser.ParseBlock(tokens, true, fd); fd.Code = code.ToArray(); return(fd); }