private ILTypeReference? TryResolveTypeReference(TypeReferenceNode typeReferenceNode, ILScope scope) { //Todo: Process embedded types switch (typeReferenceNode.Classification) { case TypeClassification.Standard: if (Types.IsBaseType(typeReferenceNode.Name)) { BaseType baseType = Types.GetBaseTypeByName(typeReferenceNode.Name); return new ILTypeReference(new ILBaseType(baseType), typeReferenceNode.Modifiers); } else if (scope.Typedefs.ContainsKey(typeReferenceNode.Name)) { ILTypeReference typedef = scope.Typedefs[typeReferenceNode.Name]; typedef.Modifiers |= typeReferenceNode.Modifiers; return typedef; } else if (scope.EnumNames.Contains(typeReferenceNode.Name)) { return new ILTypeReference(new ILBaseType(Types.GetEnumBaseType()), typeReferenceNode.Modifiers); } else { return null; } case TypeClassification.Struct: if (scope.Structs.ContainsKey(typeReferenceNode.Name)) return new ILTypeReference(scope.Structs[typeReferenceNode.Name], TypeModifiers.None); else return null; case TypeClassification.Pointer: ILTypeReference? innerType = TryResolveTypeReference(typeReferenceNode.InnerType, scope); if (innerType == null) return null; ILTypeReference returnType = new ILTypeReference(new ILPointerType(innerType.Value), typeReferenceNode.Modifiers); return returnType; default: throw new InternalCompilerException("Unexpected type classification."); } }
public void RegisterVariable(ILGenerationContext context, string name, ILTypeReference type) { if (Variables.ContainsKey(name)) throw new ParserException(string.Format("Duplicate definition for variable \"{0}\".", name), context.CurrentNode.TokenIndex, context.CurrentNode.Token); }