Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xcap-capability-linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xcap
xcap-capability-linux
Commits
bcffe497
Commit
bcffe497
authored
Sep 14, 2015
by
Sarah Spall
Committed by
Vikram Narayanan
Oct 25, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
symbol table for generating unique variable names during code generation
parent
e49732d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
0 deletions
+96
-0
tools/lcd/idl/include/symbol_table.h
tools/lcd/idl/include/symbol_table.h
+19
-0
tools/lcd/idl/symbol_table.cpp
tools/lcd/idl/symbol_table.cpp
+77
-0
No files found.
tools/lcd/idl/include/symbol_table.h
0 → 100644
View file @
bcffe497
#ifndef SYMBOL_TABLE_H
#define SYMBOL_TABLE_H
#include <vector>
#include <string>
class
SymbolTable
{
unsigned
int
last_tmp_
;
vector
<
const
char
*>
symbols_
;
public:
SymbolTable
();
const
char
*
unique_tmp
();
bool
contains
();
void
insert
(
const
char
*
symbol
);
void
insert
(
std
::
vector
<
const
char
*>
symbols
);
};
#endif
tools/lcd/idl/symbol_table.cpp
0 → 100644
View file @
bcffe497
#include "symbol_table.h"
SymbolTable
::
SymbolTable
()
{
// init symbols
}
SymbolTable
::
SymbolTable
(
std
::
vector
<
const
char
*>
symbols
)
{
this
->
symbols_
=
symbols
;
}
/*
* returns a unique const char* that begins with tmp
* that is not already in symbol table
* adds to symbol table
*/
const
char
*
SymbolTable
::
unique_tmp
()
{
std
::
string
str_tmp
=
"tmp"
+
std
::
to_string
(
this
->
last_tmp_
+
1
);
char
*
tmp
=
(
char
*
)
malloc
(
sizof
(
char
)
*
(
str_tmp
.
length
()
+
1
));
std
::
strcpy
(
tmp
,
str_tmp
.
c_str
());
if
(
!
contains
(
tmp
))
{
this
->
last_tmp_
+=
1
;
this
->
insert
(
tmp
);
return
tmp
;
}
else
{
this
->
last_tmp_
+=
1
;
return
unique_tmp
();
}
}
/*
* returns true if symbol table contains symbol
*/
bool
SymbolTable
::
contains
(
const
char
*
symbol
)
{
for
(
std
::
vector
<
const
char
*>::
iterator
it
=
this
->
symbols_
.
begin
();
it
!=
this
->
symbols_
.
end
();
it
++
)
{
const
char
*
str
=
(
const
char
*
)
*
it
;
if
(
strcmp
(
str
,
symbol
)
==
0
)
{
return
true
;
}
}
return
false
;
}
/*
* inserts symbol into symbol table
* if symbol is already in table returns -1
* returns 0 on success
*/
int
SymbolTable
::
insert
(
const
char
*
symbol
)
{
if
(
contains
(
symbol
))
return
-
1
;
this
->
symbols_
.
push_back
(
symbol
);
return
0
;
}
/*
* inserts a list of symbols into the symbol table
* if any of these symbols are already in the table it fails
* and returns -1
* returns 0 on success
*/
int
SymbolTable
::
insert
(
std
::
vector
<
const
char
*>
symbols
)
{
for
(
std
::
vector
<
const
char
*>::
iterator
it
=
symbols
.
begin
();
it
!=
symbols
.
end
();
it
++
)
{
const
char
*
str
=
(
const
char
*
)
*
it
;
if
(
contains
(
str
))
return
-
1
;
}
this
->
symbols_
.
insert
(
this
->
symbols_
.
end
(),
symbols
.
begin
(),
symbols
.
end
());
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment