Defines the code to build the struct instance using the data in the local variables.
429801
private LocalVariableDefinition buildStruct(MethodDefinition read, Map<Short, LocalVariableDefinition> structData)
    {
        // construct the instance and store it in the instance local variable
        LocalVariableDefinition instance = constructStructInstance(read, structData);

        // inject fields
        injectStructFields(read, instance, structData);

        // inject methods
        injectStructMethods(read, instance, structData);

        // invoke factory method if present
        invokeFactoryMethod(read, structData, instance);

        return instance;
    }
247117
def _generate_struct_serializer(self, struct):
        """"""
        struct_name = fmt_class_prefix(struct)

        with self.block_func(
                func='serialize',
                args=fmt_func_args_declaration([('valueObj',
                                                 '{} *'.format(struct_name))]),
                return_type='NSDictionary<NSString *, id> *',
                class_func=True):
            if not struct.all_fields and not struct.has_enumerated_subtypes():
                self.emit('#pragma unused(valueObj)')

            self.emit(
                'NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];'
            )
            self.emit()
            for field in struct.all_fields:
                data_type, nullable = unwrap_nullable(field.data_type)

                input_value = 'valueObj.{}'.format(fmt_var(field.name))
                serialize_call = self._fmt_serialization_call(
                    field.data_type, input_value, True)

                if not nullable:
                    if is_primitive_type(data_type):
                        self.emit('jsonDict[@"{}"] = {};'.format(
                            field.name, input_value))
                    else:
                        self.emit('jsonDict[@"{}"] = {};'.format(
                            field.name, serialize_call))
                else:
                    with self.block('if ({})'.format(input_value)):
                        self.emit('jsonDict[@"{}"] = {};'.format(
                            field.name, serialize_call))
            self.emit()

            if struct.has_enumerated_subtypes():
                first_block = True
                for tags, subtype in struct.get_all_subtypes_with_tags():
                    assert len(tags) == 1, tags
                    tag = tags[0]
                    base_condition = '{} ([valueObj isKindOfClass:[{} class]])'
                    with self.block(
                            base_condition.format('if' if first_block else
                                                  'else if',
                                                  fmt_class_prefix(subtype))):
                        if first_block:
                            first_block = False
                        func_args = fmt_func_args([('value',
                            '({} *)valueObj'.format(
                                fmt_class_prefix(
                                    subtype)))])
                        caller = fmt_serial_class(fmt_class_prefix(subtype))
                        serialize_call = fmt_func_call(
                            caller=caller, callee='serialize', args=func_args)
                        self.emit('NSDictionary *subTypeFields = {};'.format(
                            serialize_call))
                        with self.block(
                                'for (NSString* key in subTypeFields)'):
                            self.emit('jsonDict[key] = subTypeFields[key];')
                        self.emit(
                            'jsonDict[@".tag"] = @"{}";'.format(fmt_var(tag)))
                self.emit()
            self.emit('return [jsonDict count] > 0 ? jsonDict : nil;')
        self.emit()
525630
private function buildVariableDefinitions() {
        foreach($this->getFields() as $field) {
            $variable = new Object\Variable();
            $variable->setName($field->getShortName());
            $variable->setAccess('protected');
            $variable->setAutoIncrementing($field->isAutoIncrementing());
            $variable->setDescription($field->getDescription());
            $variable->setLength($field->getLength());
            $variable->setNullable($field->isNullable());
            $variable->setPrimary($field->isPrimary());
            $variable->setType($field->getType());
            $this->getAbstractClass()->addVariable($variable);
        }
    }
1100184
def _construct_direct(cls, variables, coord_names, dims, attrs=None,
                          indexes=None, encoding=None, file_obj=None):
        
        obj = object.__new__(cls)
        obj._variables = variables
        obj._coord_names = coord_names
        obj._dims = dims
        obj._indexes = indexes
        obj._attrs = attrs
        obj._file_obj = file_obj
        obj._encoding = encoding
        obj._initialized = True
        return obj
380380
def _createFromLocal(self, data, schema):
        
        # make sure data could consumed multiple times
        if not isinstance(data, list):
            data = list(data)

        if schema is None or isinstance(schema, (list, tuple)):
            struct = self._inferSchemaFromList(data, names=schema)
            converter = _create_converter(struct)
            data = map(converter, data)
            if isinstance(schema, (list, tuple)):
                for i, name in enumerate(schema):
                    struct.fields[i].name = name
                    struct.names[i] = name
            schema = struct

        elif not isinstance(schema, StructType):
            raise TypeError("schema should be StructType or list or None, but got: %s" % schema)

        # convert python objects to sql data
        data = [schema.toInternal(row) for row in data]
        return self._sc.parallelize(data), schema
41875
def compile(self, source_code, post_treatment=''.join):
        
        # read structure
        structure = self._structure(source_code)
        values    = self._struct_to_values(structure, source_code)
        # create object code, translated in targeted language
        obj_code = langspec.translated(
            structure, values, 
            self.target_lang_spec
        )
        # apply post treatment and return
        return obj_code if post_treatment is None else post_treatment(obj_code)
1144841
private void injectStructFields(MethodDefinition read, LocalVariableDefinition instance, Map<Short, LocalVariableDefinition> structData)
    {
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            injectField(read, field, instance, structData.get(field.getId()));
        }
    }
849557
def assign_variable(type, name, value, node)
      scope    = assignment_scope(type)
      variable = scope.lookup(type, name)

      # If there's already a variable we'll just update it.
      if variable
        variable.reference_amount += 1

        # `value` is not for conditional assignments as those are handled
        # manually.
        variable.value = value if value
      else
        variable = Definition::RubyObject.new(
          :type             => type,
          :name             => name,
          :value            => value,
          :instance_type    => :instance,
          :reference_amount => 0,
          :line             => node.line,
          :column           => node.column,
          :file             => node.file
        )
      end

      buffer_assignment_value(value)

      # Primarily used by #after_send to support variable assignments as method
      # call arguments.
      if value and !value_stack.empty?
        value_stack.push(variable.value)
      end

      add_variable(variable, scope)
    end
869794
private function buildOnConstruct() {
        $content = '';
        foreach($this->getFields() as $field) {
            if(in_array($field->getType(), array('Date', 'DateTime'))) {
                $content .= '		$this->set' . ucfirst($field->getShortName()) . '(new ' . $field->getType() . '($this->get' . ucfirst($field->getShortName()) . '()));
';
            }
        }
        $content .= '		parent::onConstruct();';
        $method = new Object\Method();
        $method->setAccess('public');
        $method->setDescription('Used to Construct an instance');
        $method->setName('onConstruct');
        $method->setReturnType('void');
        $method->setContent($content);
        $this->getAbstractClass()->addMethod($method);
    }
1209712
def define_struct(defn):
    
    struct = parse_type(defn)
    ALL_TYPES[struct.name] = struct
    return struct
521935
protected Data init(Data data) {
	if (JSON_ARRAY == null) JSON_ARRAY = getFLF(data, "_literalArray");
	if (JSON_STRUCT == null) JSON_STRUCT = getFLF(data, "_literalStruct");
	if (GET_STATIC_SCOPE == null) GET_STATIC_SCOPE = getFLF(data, "_getStaticScope");
	if (GET_SUPER_STATIC_SCOPE == null) GET_SUPER_STATIC_SCOPE = getFLF(data, "_getSuperStaticScope");
	return data;
    }
853471
def object_build(self, node, obj):
        
        if obj in self._done:
            return self._done[obj]
        self._done[obj] = node
        for name in dir(obj):
            try:
                member = getattr(obj, name)
            except AttributeError:
                # damned ExtensionClass.Base, I know you're there !
                attach_dummy_node(node, name)
                continue
            if inspect.ismethod(member):
                member = member.__func__
            if inspect.isfunction(member):
                _build_from_function(node, name, member, self._module)
            elif inspect.isbuiltin(member):
                if not _io_discrepancy(member) and self.imported_member(
                    node, member, name
                ):
                    continue
                object_build_methoddescriptor(node, member, name)
            elif inspect.isclass(member):
                if self.imported_member(node, member, name):
                    continue
                if member in self._done:
                    class_node = self._done[member]
                    if class_node not in node.locals.get(name, ()):
                        node.add_local_node(class_node, name)
                else:
                    class_node = object_build_class(node, member, name)
                    # recursion
                    self.object_build(class_node, member)
                if name == "__class__" and class_node.parent is None:
                    class_node.parent = self._done[self._module]
            elif inspect.ismethoddescriptor(member):
                assert isinstance(member, object)
                object_build_methoddescriptor(node, member, name)
            elif inspect.isdatadescriptor(member):
                assert isinstance(member, object)
                object_build_datadescriptor(node, member, name)
            elif isinstance(member, _CONSTANTS):
                attach_const_node(node, name, member)
            elif inspect.isroutine(member):
                # This should be called for Jython, where some builtin
                # methods aren't caught by isbuiltin branch.
                _build_from_function(node, name, member, self._module)
            else:
                # create an empty node so that the name is actually defined
                attach_dummy_node(node, name, member)
        return None
899326
def struct_from_value( cls, name, volume,
			channel_list=None, mute=False, device=None ):
		''
		chan_map = c.PA_CHANNEL_MAP()
		if not channel_list: c.pa.channel_map_init_mono(chan_map)
		else:
			if not is_str(channel_list):
				channel_list = b','.join(map(c.force_bytes, channel_list))
			c.pa.channel_map_parse(chan_map, channel_list)
		if not isinstance(volume, PulseVolumeInfo):
			volume = PulseVolumeInfo(volume, chan_map.channels)
		struct = c.PA_EXT_STREAM_RESTORE_INFO(
			name=c.force_bytes(name),
			mute=int(bool(mute)), device=c.force_bytes(device),
			channel_map=chan_map, volume=volume.to_struct() )
		return struct
414247
private Struct toStruct(Attributes att) {
	int len = att.getLength();
	Struct sct = new StructImpl();
	for (int i = 0; i < len; i++) {
	    sct.setEL(att.getQName(i), att.getValue(i));
	}
	return sct;
    }
865534
private void defineWriteUnionMethod()
    {
        MethodDefinition write = new MethodDefinition(
                a(PUBLIC),
                "write",
                null,
                arg("struct", structType),
                arg("protocol", TProtocol.class)
        );

        classDefinition.addMethod(write);

        // TProtocolWriter writer = new TProtocolWriter(protocol);
        write.addLocalVariable(type(TProtocolWriter.class), "writer");
        write.newObject(TProtocolWriter.class);
        write.dup();
        write.loadVariable("protocol");
        write.invokeConstructor(type(TProtocolWriter.class), type(TProtocol.class));
        write.storeVariable("writer");

        LocalVariableDefinition protocol = write.getLocalVariable("writer");

        // protocol.writeStructBegin("bonk");
        write.loadVariable(protocol)
            .loadConstant(metadata.getStructName())
            .invokeVirtual(TProtocolWriter.class, "writeStructBegin", void.class, String.class);

        // find the @ThriftUnionId field
        ThriftFieldMetadata idField = getOnlyElement(metadata.getFields(THRIFT_UNION_ID));

        // load its value
        loadFieldValue(write, idField);

        // switch(fieldId)
        List<CaseStatement> cases = new ArrayList<>();
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            cases.add(caseStatement(field.getId(), field.getName() + "-write-field"));
        }
        write.switchStatement("default-write", cases);

        // write fields
        for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
            write.visitLabel(field.getName() + "-write-field");
            writeField(write, protocol, field);
            write.gotoLabel("default-write");
        }

        write.visitLabel("default-write")
            .loadVariable(protocol)
            .invokeVirtual(TProtocolWriter.class, "writeStructEnd", void.class);

        write.ret();
    }
431159
protected function prepareLocal() {
    // isSmooth: local header will have its general purpose bit set
    // => empty values in local header
    // => append data descriptor
    if ($this->isSmooth()) return;

    $size = filesize($this->path);
    $this->setSize($size);
    if (!$this->hasDeflation()) $this->setDeflatedSize($size);
    $this->setRawCrc(hash_file('crc32b', $this->path, TRUE));
  }
1127332
def p_struct(self, p):
        ''''''
        p[0] = ast.Struct(
            name=p[2], fields=p[4], annotations=p[6], lineno=p.lineno(2)
        )