Hi Alan,

that line of code is part of the process where I allow simple templates created 
in code to overcome the limitation that all template parameters must be 
defined. Interpret that array copy as simply "increase the size of the array of 
parameters". 

// define and make room in locals (a hack to make new ST("simple template") 
work.)
if ( impl.formalArguments!=null ) {
        arg = impl.formalArguments.get(name);
}       
if ( arg==null ) { // not defined 
        arg = new FormalArgument(name);
        impl.addArg(arg);
        if ( locals==null ) locals = new Object[1];
        else locals = Arrays.copyOf(locals, impl.formalArguments.size());
        locals[arg.index] = EMPTY_ATTR;
}               

On Mar 25, 2011, at 8:21 AM, Alan Condit wrote:

> I have translated all of the ST4 runtime (excepting  gui) into ObjC. However, 
> I don't understand this line of Java code from ST.java.
> 
> locals = Arrays.copyOf(locals, impl.formalArguments.size())
> 
> I am working on the Test-ing. In TestCoreBasics, in TestaChainAttr (numbers 
> are because OCTest sorts the functions alphabetically)
> 
> - (void) test02aChainAttr
> {
>   NSString * template = @"<x>:<names>!";
>   ST *st = [ST newSTWithTemplate:template];
>   [[[st add:@"names" value:@"Ter"] add:@"names" value:@"Tom"] addInt:@"x" 
> value:1];
>   NSString * expected = @"1:TerTom!";
>   NSString * result = [st render];
>   STAssertTrue( [expected isEqualTo:result], @"Expected \"%@\" but got 
> \"%@\"", expected, result );
> }
> 
> "[expected isEqualTo:result]" should be true. Expected "1:TerTom!" but got 
> "1names!"
> 
> I have stepped through the whole thing in the debugger "Ter" and "Tom" are in 
> the dictionary but st render never looks up "names" in the dictionary. 
> However, it is obviously looking up 'x' in the dictionary and getting the 
> object "1". It is just being treated as a raw attribute. Any ideas what the 
> likely culprit is?
> 
> I am suspicious that it relates to the line of code that I referenced above. 
> In locals I have "Tom" and "Ter" in an array the pointer to which is at index 
> 0 in locals, "1" is stored as a pointer to string at index 1 in locals. Does 
> this sound correct or should the whole list "Ter", "Tom", and "1" be in one 
> list in locals?
> 
> It is passing tests 1, 2, but failing 2a and 3, then passing 4, 5, 6 after 6 
> it fails everything until it just bombs.
> 
> Alan
> 
> ---
> 
> Alan Condit
> 1085 Tierra Ct.
> Woodburn, OR 97071
> 
> Email -- acon...@ipns.com
> Home-Office (503) 982-0906
> 
> _______________________________________________
> antlr-dev mailing list
> antlr-dev@antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-dev

_______________________________________________
antlr-dev mailing list
antlr-dev@antlr.org
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to