internal override Expression Resolve(Parser parser) { this.Root = this.Root.Resolve(parser); string step = this.StepToken.Value; if (this.Root is EnumReference) { EnumDefinition enumDef = ((EnumReference)this.Root).EnumDefinition; ConstantResolutionState resolutionState = parser.ConstantAndEnumResolutionState[enumDef]; if (resolutionState != ConstantResolutionState.RESOLVED) { enumDef.Resolve(parser); } switch (step) { case "length": return(new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.Owner)); case "max": return(new SpecialEntity.EnumMaxFunction(this.FirstToken, enumDef, this.Owner)); case "values": return(new SpecialEntity.EnumValuesFunction(this.FirstToken, enumDef, this.Owner)); } if (enumDef.IntValue.ContainsKey(step)) { return(new IntegerConstant(this.FirstToken, enumDef.IntValue[step], this.Owner)); } else { throw new ParserException(this.StepToken, "The enum '" + enumDef.Name + "' does not contain a definition for '" + step + "'"); } } if (this.Root is BaseKeyword) { return(new BaseMethodReference(this.Root.FirstToken, this.DotToken, this.StepToken, this.Owner).Resolve(parser)); } if (this.Root is StringConstant) { if (step == "join") { throw new ParserException(this.StepToken, "There is no join method on strings. Did you mean to do list.join(string) instead?"); } else if (step == "size") { throw new ParserException(this.StepToken, "String size is indicated by string.length."); } else if (step == "length") { int length = ((StringConstant)this.Root).Value.Length; return(new IntegerConstant(this.FirstToken, length, this.Owner)); } } return(this); }
internal override Expression Resolve(Parser parser) { this.Root = this.Root.Resolve(parser); string step = this.StepToken.Value; if (this.Root is EnumReference) { EnumDefinition enumDef = ((EnumReference)this.Root).EnumDefinition; int resolutionState = parser.ConstantAndEnumResolutionState[enumDef]; if (resolutionState != 2) { enumDef.Resolve(parser); } switch (step) { case "length": return(new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.FunctionOrClassOwner)); case "max": return(new SpecialEntity.EnumMaxFunction(this.FirstToken, enumDef, this.FunctionOrClassOwner)); case "values": return(new SpecialEntity.EnumValuesFunction(this.FirstToken, enumDef, this.FunctionOrClassOwner)); } if (enumDef.IntValue.ContainsKey(step)) { return(new IntegerConstant(this.FirstToken, enumDef.IntValue[step], this.FunctionOrClassOwner)); } else { throw new ParserException(this.StepToken, "The enum '" + enumDef.Name + "' does not contain a definition for '" + step + "'"); } } Variable variable = this.Root as Variable; if (variable != null) { string varName = variable.Name; if (parser.IsTranslateMode && varName.Contains('$')) { string[] parts = varName.Split('$'); if (parts.Length == 2 && parts[0].Length > 0 && parts[1].Length > 0) { // struct casting string structName = parts[0]; StructDefinition structDef = parser.GetStructDefinition(structName); if (structDef == null) { throw new ParserException(this.Root.FirstToken, "The struct '" + structName + "' does not exist."); } if (!structDef.IndexByField.ContainsKey(step)) { throw new ParserException(this.StepToken, "The struct '" + structDef.Name.Value + "' does not contain a field called '" + step + "'"); } return(new DotStepStruct(this.FirstToken, structDef, this, this.FunctionOrClassOwner)); } } } if (this.Root is BaseKeyword) { return(new BaseMethodReference(this.Root.FirstToken, this.DotToken, this.StepToken, this.FunctionOrClassOwner).Resolve(parser)); } if (this.Root is StringConstant) { if (step == "join") { throw new ParserException(this.StepToken, "There is no join method on strings. Did you mean to do list.join(string) instead?"); } else if (step == "size") { throw new ParserException(this.StepToken, "String size is indicated by string.length."); } else if (step == "length") { int length = ((StringConstant)this.Root).Value.Length; return(new IntegerConstant(this.FirstToken, length, this.FunctionOrClassOwner)); } } return(this); }