An Automated Tool for Improving Code Quality Through Variable Name Refinement with Language Models
Project description
VarWizard
- Introduction
VarWizard is a language model-based tool to help generate more meaningful variable names in source code than the original version. It supports 10 programming languages: c, cpp, java, javascript, go, python, php, c_sharp, ruby, rust.
- Installation
You can easily install this package by the command
pip install varwizard
- Tutorial
Here is a simple example of VarWizard.
from varwizard import VarWizard
model = VarWizard()
code = """
static void lsp2poly ( int * var0, const int16_t * var1, int var2 ) { int var3, var4 ; var0 [ 0 ] = 0x400000 ; // 1.0 in (3.22) var0 [ 1 ] = - var1 [ 0 ] << 8 ; // *2 and (0.15) -> (3.22) for ( var3 = 2 ; var3 <= var2 ; var3 ++ ) { var0 [ var3 ] = var0 [ var3 - 2 ] ; for ( var4 = var3 ; var4 > 1 ; var4 -- ) var0 [ var4 ] -= MULL ( var0 [ var4 - 1 ], var1 [ 2 * var3 - 2 ], FRAC_BITS ) - var0 [ var4 - 2 ] ; var0 [ 1 ] -= var1 [ 2 * var3 - 2 ] << 8 ; } }"""
print(model.make_new_code(code, 'cpp'), device = 'cuda:0')
VarWizard produces the output
static void lsp2poly ( int * lsp, const int16_t * lsp2, int nbits ) { int index, count ; lsp [ 0 ] = 0x400000 ; // 1.0 in (3.22) lsp [ 1 ] = - lsp2 [ 0 ] << 8 ; // *2 and (0.15) -> (3.22) for ( index = 2 ; index <= nbits ; index ++ ) { lsp [ index ] = lsp [ index - 2 ] ; for ( count = index ; count > 1 ; count -- ) lsp [ count ] -= MULL ( lsp [ count - 1 ], lsp2 [ 2 * index - 2 ], FRAC_BITS ) - lsp [ count - 2 ] ; lsp [ 1 ] -= lsp2 [ 2 * index - 2 ] << 8 ; } }
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
varwizard-0.1.1.tar.gz
(1.1 MB
view hashes)
Built Distribution
Close
Hashes for varwizard-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e58586175700741148c20be02909d3d9c634fb50b714fe3204002889133d3bae |
|
MD5 | ad632368a91627efc4039f74c4793a82 |
|
BLAKE2b-256 | b897b1014ba0b62e753044842cc174038bb47d189f0f291537725168f25271d7 |