Beispiel #1
0
 public bool HasErrorReportForReferenceTo(ErrorTypes type, Declaration node)
 {
     return Errors.FindIndex((errMsg) => errMsg.ErrorType == type && errMsg.ReferencedNode == node) > -1;
 }
 private IType CheckDeclaredType(Declaration node)
 {
     IType declaredType;
     if (node.TypeName == MiniJavaInfo.VoidType)
     {
         if (node is VariableDeclaration)
         {
             ReportError(ErrorTypes.TypeReference, "Illegal type void in variable declaration.", node);
             declaredType = ErrorType.GetInstance();
         }
         else if (node.IsArray)
         {
             ReportError(ErrorTypes.TypeReference, "Illegal type void for array elements.", node);
             declaredType = ErrorType.GetInstance();
         }
         else // declaration is a void method
         {
             declaredType = VoidType.GetInstance();
         }
     }
     else
     {
         var nodeScalarTypeSymbol = _globalScope.ResolveType(node.TypeName);
         if (nodeScalarTypeSymbol == null)
         {   // Note: this error is also reported when a void type is encountered
             // for something other than a method declaration.
             ReportTypeNameError(node.TypeName, node);
             declaredType = ErrorType.GetInstance();
         }
         else
         {
             declaredType = BuildType(node, (ScalarType)nodeScalarTypeSymbol.Type);
         }
     }
     return declaredType;
 }
 private void ReportSymbolDefinitionError(Declaration node)
 {
     string errorMessage = String.Format("Symbol {0} is already defined.", node.Name);
     ReportError(ErrorTypes.ConflictingDefinitions, errorMessage, node);
 }
 private IType BuildType(Declaration node, ScalarType nodeScalarType)
 {
     IType actualType;
     if (node.IsArray)
     {
         var arraySymbol = _globalScope.ResolveArrayType(node.TypeName);
         if (arraySymbol == null)
         {
             actualType = DefineArrayType(nodeScalarType);
         }
         else
         {
             actualType = arraySymbol.Type;
         }
     }
     else
     {
         actualType = nodeScalarType;
     }
     return actualType;
 }