internal override Expression ResolveWithTypeContext(PastelCompiler compiler) { for (int i = 0; i < this.Args.Length; ++i) { this.Args[i] = this.Args[i].ResolveWithTypeContext(compiler); } string type = this.Type.RootValue; switch (type) { case "Array": case "List": case "Dictionary": break; default: StructDefinition sd = compiler.GetStructDefinition(this.Type.RootValue); if (sd != null) { this.StructType = sd; } break; } return(this); }
internal override Expression ResolveType(VariableScope varScope, PastelCompiler compiler) { if (this.Root is Variable && ((Variable)this.Root).Name == "Native") { string name = this.FieldName.Value; return(new ExtensibleFunctionReference(this.FirstToken, name)); } this.Root = this.Root.ResolveType(varScope, compiler); string possibleStructName = this.Root.ResolvedType.RootValue; StructDefinition structDef = compiler.GetStructDefinition(possibleStructName); if (structDef != null) { this.StructType = structDef; int fieldIndex; if (!structDef.ArgIndexByName.TryGetValue(this.FieldName.Value, out fieldIndex)) { throw new ParserException(this.FieldName, "The struct '" + structDef.NameToken.Value + "' does not have a field called '" + this.FieldName.Value + "'"); } this.ResolvedType = structDef.ArgTypes[fieldIndex]; return(this); } this.NativeFunctionId = this.DetermineNativeFunctionId(this.Root.ResolvedType, this.FieldName.Value); if (this.NativeFunctionId != NativeFunction.NONE) { return(new NativeFunctionReference(this.FirstToken, this.NativeFunctionId, this.Root)); } throw new NotImplementedException(); }
internal void FinalizeType(PastelCompiler compilerContext) { if (this.isTypeFinalized) { return; } this.isTypeFinalized = true; if (this.Category == TypeCategory.STRUCT_OR_CLASS) { PastelCompiler targetContext = compilerContext; if (this.Namespace != null) { if (!compilerContext.IncludedScopeNamespacesToIndex.ContainsKey(this.Namespace)) { targetContext = null; } else { int index = compilerContext.IncludedScopeNamespacesToIndex[this.Namespace]; targetContext = compilerContext.IncludedScopes[index]; } } if (targetContext != null) { this.structReference = targetContext.GetStructDefinition(this.TypeName); this.classReference = targetContext.GetClassDefinition(this.TypeName); this.Category = this.structReference == null ? TypeCategory.CLASS : TypeCategory.STRUCT; } if (this.structReference == null && this.classReference == null) { throw new ParserException(this.FirstToken, "Could not find a class or struct by the name of '" + this.RootValue + "'"); } if (this.structReference != null && this.classReference != null) { throw new System.InvalidOperationException(); // this shouldn't happen. name conflicts should have been caught by now. } } for (int i = 0; i < this.Generics.Length; ++i) { this.Generics[i].FinalizeType(compilerContext); } }