mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
Do not crash horribly if we don't have translations for some basic types (e.g. user passes invalid NetFramework)
This commit is contained in:
parent
52a2e5b301
commit
706afb8575
@ -60,7 +60,7 @@ namespace Twiglet.CS2J.Translator
|
||||
Console.Out.WriteLine("Usage: " + Path.GetFileNameWithoutExtension(System.Environment.GetCommandLineArgs()[0]));
|
||||
Console.Out.WriteLine(" [-help] (this usage message)");
|
||||
Console.Out.WriteLine(" [-v] (be [somewhat more] verbose, repeat for more verbosity)");
|
||||
Console.Out.WriteLine(" [-config <iniFile>] (read settings from <iniFile>, overriden from command line");
|
||||
Console.Out.WriteLine(" [-config <iniFile>] (read settings from <iniFile>, overriden from command line");
|
||||
Console.Out.WriteLine(" [-D <macroVariable>] (define C# preprocessor <macroVariable>, option can be repeated)");
|
||||
Console.Out.WriteLine(" [-show-tokens] (the lexer prints the tokenized input to the console)");
|
||||
Console.Out.WriteLine(" [-show-csharp] [-show-javasyntax] [-show-java] (show parse tree at various stages of the translation)");
|
||||
@ -93,6 +93,9 @@ namespace Twiglet.CS2J.Translator
|
||||
for (int i = 0; i < argDirs.Length; i++)
|
||||
{
|
||||
string dir = Path.GetFullPath(argDirs[i]).TrimEnd(Path.DirectorySeparatorChar);
|
||||
if (!(File.Exists(dir) || Directory.Exists(dir))) {
|
||||
Console.Out.WriteLine("WARNING: Cannot read " + dir);
|
||||
}
|
||||
strs.Add(dir);
|
||||
}
|
||||
}
|
||||
|
@ -2495,7 +2495,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
// Take care of arrays ....
|
||||
while (typeStr.StartsWith("[]"))
|
||||
{
|
||||
TypeRepTemplate arrayType = AppEnv.Search("System.Array'1");
|
||||
TypeRepTemplate arrayType = AppEnv.Search("System.Array'1", new UnknownRepTemplate("System.Array'1"));
|
||||
typeRep = arrayType.Instantiate(new TypeRepTemplate[] { typeRep });
|
||||
typeStr = typeStr.Substring(2).TrimStart();
|
||||
}
|
||||
@ -3842,7 +3842,15 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
||||
|
||||
public UnknownRepTemplate (string typeName) : base(typeName)
|
||||
{
|
||||
Inherits = new String[] { "System.Object" };
|
||||
// If we are creating an UnknownRepTemplate for System.Object then don't
|
||||
// inherit from ourselves, else we get stack overflow when resolving.
|
||||
// This should only happen in the case that we don't have a valid
|
||||
// net-templates-dir with a definition for System.Object.
|
||||
if (typeName != "System.Object") {
|
||||
Inherits = new String[] { "System.Object" };
|
||||
} else {
|
||||
Inherits = new String[] { };
|
||||
}
|
||||
}
|
||||
|
||||
public UnknownRepTemplate (TypeRepRef typeName) : this(typeName.Type)
|
||||
|
@ -549,7 +549,7 @@ scope MkNonGeneric {
|
||||
|
||||
foreach (string t in ScruTypeStrs)
|
||||
{
|
||||
if (sType.IsA(AppEnv.Search(t), AppEnv))
|
||||
if (sType.IsA(findType(t), AppEnv))
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
@ -1726,7 +1726,7 @@ initializer_value:
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
typeof_expression returns [TypeRepTemplate dotNetType, TypeRepTemplate typeofType]:
|
||||
^('typeof' (unbound_type_name | type { $typeofType = $type.dotNetType; } | 'void' { $typeofType = AppEnv.Search("System.Void"); }) ) { $dotNetType = AppEnv.Search("System.Type"); };
|
||||
^('typeof' (unbound_type_name | type { $typeofType = $type.dotNetType; } | 'void' { $typeofType = findType("System.Void"); }) ) { $dotNetType = findType("System.Type"); };
|
||||
// unbound type examples
|
||||
//foo<bar<X<>>>
|
||||
//bar::foo<>
|
||||
@ -2641,7 +2641,7 @@ scope NSContext,SymTab;
|
||||
}
|
||||
}
|
||||
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
|
||||
-> {$class_implements.hasExtends && $class_implements.extendDotNetType.IsA(findType("System.Attribute"), AppEnv)}? magicAnnotation
|
||||
-> ^($c 'partial'? PAYLOAD? attributes? modifiers? identifier type_parameter_constraints_clauses? type_parameter_list? class_implements? class_body);
|
||||
|
||||
type_parameter_list returns [List<string> tyParams]
|
||||
@ -3097,7 +3097,7 @@ scope {
|
||||
^(s='switch' se=expression[ObjectType] sv=magicScrutineeVar[$s.token]
|
||||
{
|
||||
if ($expression.dotNetType != null) {
|
||||
$switch_statement::isEnum = $expression.dotNetType.IsA(AppEnv.Search("System.Enum"), AppEnv);
|
||||
$switch_statement::isEnum = $expression.dotNetType.IsA(findType("System.Enum"), AppEnv);
|
||||
$switch_statement::convertToIfThenElse = typeIsInvalidForScrutinee($expression.dotNetType);
|
||||
$switch_statement::scrutVar = $sv.thetext;
|
||||
}
|
||||
@ -3427,7 +3427,7 @@ literal returns [TypeRepTemplate dotNetType]
|
||||
bool isNull = false;
|
||||
}
|
||||
@after {
|
||||
TypeRepTemplate retTy = AppEnv.Search(ns);
|
||||
TypeRepTemplate retTy = findType(ns);
|
||||
if (isNull) {
|
||||
retTy = new ClassRepTemplate((ClassRepTemplate)retTy);
|
||||
retTy.IsExplicitNull = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user