/// <summary> /// Este metodo es usado para crear un tipo al cual se hace referencia y es posible que no haya sido previamente creado en el codigo IL /// </summary> /// <param name="typeDeclaration"></param> /// <param name="typeId"></param> /// <returns></returns> private Type CreateTypeNotFounded(TypeDeclarationAST typeDeclaration, string typeId) { TypeInfo type = typeDeclaration.CurrentScope.GetTypeInfo(typeId); if (code.DefinedType.ContainsKey(type.CodeName)) { return(code.DefinedType[type.CodeName]); } TigerType t = type.Type; if (t is ArrayType) { Type baseType = CreateTypeNotFounded(typeDeclaration, ((ArrayType)t).BaseType.TypeID); Type arrayType = baseType.MakeArrayType(); code.DefinedType.Add(type.CodeName, arrayType); return(arrayType); } if (t is RecordType) { Type temp = code.Module.DefineType(type.CodeName); code.DefinedType.Add(type.CodeName, temp); return(temp); } throw new NotImplementedException("Los restantes tipos no estan soportados en tiger"); }
private bool VisitTypeDeclaration(TypeDeclarationAST typeDeclaration) { if (_scope.HasType(typeDeclaration.TypeId, out _) != ScopeLocation.NotDeclared) { _errorListener.Add(new AnalysisError(string.Format(AnalysisError.LoadMessage("TypeDecl"), typeDeclaration.TypeId), typeDeclaration.Line, typeDeclaration.Columns)); typeDeclaration.ReturnType = TigerType.GetType <ErrorType>(); return(false); } typeDeclaration.ReturnType = TigerType.GetType <NoType>(); return(true); }