Fixed namespace code generation for C++

The code generator was assuming all declarations for the current
file sit in the same namepace. Now uses the "on demand" namespace
switching we had for the forward declarations.

Also fixed a bug related to namespace lookup.

Change-Id: Ib54a3efbc752cbb9590302fa0707c0c73448db3d
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2016-02-12 16:20:33 -08:00
parent 472fb12273
commit 20c0082ee5
18 changed files with 1000 additions and 223 deletions

View File

@@ -0,0 +1,82 @@
<?php
// automatically generated, do not modify
namespace NamespaceA;
use \Google\FlatBuffers\Struct;
use \Google\FlatBuffers\Table;
use \Google\FlatBuffers\ByteBuffer;
use \Google\FlatBuffers\FlatBufferBuilder;
class SecondTableInA extends Table
{
/**
* @param ByteBuffer $bb
* @return SecondTableInA
*/
public static function getRootAsSecondTableInA(ByteBuffer $bb)
{
$obj = new SecondTableInA();
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
}
/**
* @param int $_i offset
* @param ByteBuffer $_bb
* @return SecondTableInA
**/
public function init($_i, ByteBuffer $_bb)
{
$this->bb_pos = $_i;
$this->bb = $_bb;
return $this;
}
public function getReferToC()
{
$obj = new TableInC();
$o = $this->__offset(4);
return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0;
}
/**
* @param FlatBufferBuilder $builder
* @return void
*/
public static function startSecondTableInA(FlatBufferBuilder $builder)
{
$builder->StartObject(1);
}
/**
* @param FlatBufferBuilder $builder
* @return SecondTableInA
*/
public static function createSecondTableInA(FlatBufferBuilder $builder, $refer_to_c)
{
$builder->startObject(1);
self::addReferToC($builder, $refer_to_c);
$o = $builder->endObject();
return $o;
}
/**
* @param FlatBufferBuilder $builder
* @param int
* @return void
*/
public static function addReferToC(FlatBufferBuilder $builder, $referToC)
{
$builder->addOffsetX(0, $referToC, 0);
}
/**
* @param FlatBufferBuilder $builder
* @return int table offset
*/
public static function endSecondTableInA(FlatBufferBuilder $builder)
{
$o = $builder->endObject();
return $o;
}
}