Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Spot
go2pins
Commits
336ce4ac
Commit
336ce4ac
authored
Jun 06, 2021
by
Hugo Moreau
Browse files
Dependencies: passing wanted variables to dep
parent
29f9bb9a
Pipeline
#28374
passed with stage
in 2 minutes and 25 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
main.go
View file @
336ce4ac
...
...
@@ -103,7 +103,6 @@ func compileTo(filepath string, src []byte, file *os.File,
localvariable
:=
&
transform
.
LocalVariableAssignments
{
Global
:
true
}
res
:=
transform
.
ApplyAll
(
f
,
meta
,
[]
transform
.
Transform
{
// &transform.Dependencies{},
// &transform.DependenciesRework{},
// &transform.Debug{}, // only for debuging a special transformation
&
transform
.
Alive
{},
...
...
@@ -497,6 +496,24 @@ func treatGlobal(src []byte) ([]byte, bool) {
return
src
,
false
}
func
handleBlackboxBlocks
(
src
[]
byte
,
variables
map
[
string
]
bool
)
{
info
:=
&
types
.
Info
{
Uses
:
make
(
map
[
*
ast
.
Ident
]
types
.
Object
),
Selections
:
make
(
map
[
*
ast
.
SelectorExpr
]
*
types
.
Selection
),
}
fset
:=
token
.
NewFileSet
()
node
,
err
:=
parser
.
ParseFile
(
fset
,
""
,
src
,
0
)
if
err
!=
nil
{
fmt
.
Println
(
os
.
Stderr
,
err
.
Error
())
os
.
Exit
(
1
)
}
meta
:=
transform
.
NewMeta
(
fset
,
info
)
transform
.
ApplyAll
(
node
,
meta
,
[]
transform
.
Transform
{
&
transform
.
DependenciesRework
{
NVariables
:
variables
},
&
transform
.
Debug
{},
// only for debuging a special transformation
})
}
func
insertGlobalInBlackbox
(
meta
*
transform
.
Meta
,
filename
string
)
{
src
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
...
...
@@ -638,20 +655,20 @@ func main() {
defer
f
.
Close
()
var
configJson
[]
byte
var
variables
map
[
string
]
bool
if
len
(
flag
.
Args
())
>=
2
{
configJson
=
tools
.
GenerateSimpleConfig
(
flag
.
Args
()[
1
])
}
else
{
configJson
=
tools
.
GenerateEmptyConfig
()
}
if
*
formulae
!=
""
{
*
ignorefunc
,
_
=
tools
.
Formulae
(
flag
.
Args
()[
0
],
*
formulae
)
*
ignorefunc
,
variables
=
tools
.
Formulae
(
flag
.
Args
()[
0
],
*
formulae
)
configJson
=
tools
.
GenerateConfig
(
*
formulae
)
}
if
*
ignorefunc
!=
""
{
if
*
formulae
==
""
&&
len
(
flag
.
Args
())
>=
2
&&
*
ignorefunc
==
"auto"
{
*
ignorefunc
,
_
=
tools
.
Formula
(
flag
.
Args
()[
0
],
flag
.
Args
()[
1
])
*
ignorefunc
,
variables
=
tools
.
Formula
(
flag
.
Args
()[
0
],
flag
.
Args
()[
1
])
}
var
unspacify
=
regexp
.
MustCompile
(
` *`
)
s
:=
unspacify
.
ReplaceAllString
(
*
ignorefunc
,
""
)
...
...
@@ -669,6 +686,7 @@ func main() {
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
handleBlackboxBlocks
(
src
,
variables
)
// Check if all constraints are respected
info
:=
&
types
.
Info
{
...
...
transform/dependencies_rework.go
View file @
336ce4ac
...
...
@@ -7,8 +7,9 @@ import (
)
type
DependenciesRework
struct
{
GlobalVar
[]
*
ast
.
Object
Func
map
[
*
ast
.
Object
]
*
FuncInfosBis
GlobalVar
[]
*
ast
.
Object
Func
map
[
*
ast
.
Object
]
*
FuncInfosBis
NVariables
map
[
string
]
bool
}
type
VarInfos
struct
{
...
...
@@ -194,6 +195,9 @@ func (t *DependenciesRework) Post(meta *Meta, v *Visitor) bool {
c
:=
v
.
Cursor
()
switch
c
.
Node
()
.
(
type
)
{
case
*
ast
.
File
:
for
key
,
_
:=
range
t
.
NVariables
{
fmt
.
Println
(
key
)
}
for
_
,
v
:=
range
t
.
GlobalVar
{
fmt
.
Println
(
v
)
}
...
...
Write
Preview
Supports
Markdown
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