Skip to content

Commit

Permalink
- Added some more failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Aug 17, 2012
1 parent 5ac9249 commit 0ed3e3d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
33 changes: 33 additions & 0 deletions ilcc/ilcclib.Tests/Preprocessor/CPreprocessorTest.cs
Expand Up @@ -542,5 +542,38 @@ public void TestMacroSemicolon()

StringAssert.Contains(Text, @"do { do { } while (0); } while (0);");
}

[TestMethod]
public void TestBug3a()
{
CPreprocessor.PreprocessString(@"
#define DEMO_PRUEBA_TEST FINE
#define TEST(tbl) DEMO_##tbl##_TEST = 1
TEST(PRUEBA)
");

var Text = (CPreprocessor.TextWriter as StringWriter).ToString();
Console.WriteLine(Text);

StringAssert.Contains(Text, "FINE = 1");
}

[TestMethod]
public void TestBug3b()
{
CPreprocessor.PreprocessString(@"
#define DEMO_TEST_TEST FINE
#define DEMO_PRUEBA_TEST DEMO_##TEST##_TEST = 2
#define TEST(tbl) DEMO_##tbl##_TEST = 1
TEST(PRUEBA)
");

var Text = (CPreprocessor.TextWriter as StringWriter).ToString();
Console.WriteLine(Text);

StringAssert.Contains(Text, "FINE = 2 = 1");
}
}
}
9 changes: 8 additions & 1 deletion ilcc/ilcclib/Parser/CParser.Context.cs
Expand Up @@ -352,7 +352,14 @@ CType IIdentifierTypeResolver.ResolveIdentifierType(string Identifier)

object IConstantResolver.GetConstantIdentifier(string Name)
{
return CurrentScope.FindSymbol(Name).ConstantValue;
if (CurrentScope == null) return null;
var Symbol = CurrentScope.FindSymbol(Name);
if (Symbol == null)
{
Console.Error.WriteLine("Can't find symbol {0}", Name);
return null;
}
return Symbol.ConstantValue;
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions ilcc/ilcclib/Parser/CParser.Nodes.Expressions.cs
Expand Up @@ -74,7 +74,8 @@ protected override object __GetConstantValue(IConstantResolver IConstantResolver
var Value = IConstantResolver.GetConstantIdentifier(Identifier);
if (Value == null)
{
throw (new InvalidOperationException("A IdentifierExpression is not a constant value"));
//throw (new InvalidOperationException("A IdentifierExpression is not a constant value"));
//return null;
}
return Value;
}
Expand Down Expand Up @@ -884,7 +885,13 @@ public object GetCachedConstantValue(IConstantResolver Resolver)

public TType GetConstantValue<TType>(IConstantResolver IConstantResolver)
{
return (TType)__GetConstantValue(IConstantResolver);
var Value = __GetConstantValue(IConstantResolver);
if (Value == null)
{
Console.Error.WriteLine("Can't cast ConstantValue [{0}] to <{1}>", this.GetType(), typeof(TType));
return default(TType);
}
return (TType)Value;
}

abstract protected CType __GetCType(IIdentifierTypeResolver Resolver);
Expand Down

0 comments on commit 0ed3e3d

Please sign in to comment.