From 07cfecff4eabaf1b3dfc002a3e68c127d6ee26ea Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Mon, 14 Feb 2011 11:49:55 +0100 Subject: [PATCH] error if we can't find class name in the environment --- .../CS2JTranslator/CS2JTransform/NetMaker.g | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g index 0014f0d..ee9f4a2 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetMaker.g @@ -1406,15 +1406,20 @@ scope NSContext,SymTab; $NSContext::namespaces.Add($NSContext::currentNS); $NSContext::globalNamespaces.Add($NSContext::currentNS); ClassRepTemplate classTypeRep = (ClassRepTemplate)AppEnv.Search($NSContext::currentNS); - $SymTab::symtab["this"] = classTypeRep; - ClassRepTemplate baseType = ObjectType; - if (classTypeRep.Inherits != null && classTypeRep.Inherits.Length > 0) { - // if Inherits[0] is a class then it is parent, else system.object - ClassRepTemplate parent = AppEnv.Search(classTypeRep.Uses, classTypeRep.Inherits[0], ObjectType) as ClassRepTemplate; - if (parent != null) - baseType = parent; - } - $SymTab::symtab["super"] = baseType; + if (classTypeRep == null) { + Error($c.line, "Could not find class " + $NSContext::currentNS + " in the type environment"); + } + else { + $SymTab::symtab["this"] = classTypeRep; + ClassRepTemplate baseType = ObjectType; + if (classTypeRep.Inherits != null && classTypeRep.Inherits.Length > 0) { + // if Inherits[0] is a class then it is parent, else system.object + ClassRepTemplate parent = AppEnv.Search(classTypeRep.Uses, classTypeRep.Inherits[0], ObjectType) as ClassRepTemplate; + if (parent != null) + baseType = parent; + } + $SymTab::symtab["super"] = baseType; + } } class_body magicAnnotation[$modifiers.tree, $identifier.tree, null, $c.token]) -> {$class_implements.hasExtends && $class_implements.extendDotNetType.IsA(AppEnv.Search("System.Attribute", new UnknownRepTemplate("System.Attribute")), AppEnv)}? magicAnnotation