Studio:Handling of pointer attribute tokens: Difference between revisions
No edit summary |
No edit summary |
||
Line 124: | Line 124: | ||
If for some reason the suggested update is not possible as a workaround that would allow successful compilation would be to predefine the old symbolic tokens as follows: | If for some reason the suggested update is not possible as a workaround that would allow successful compilation would be to predefine the old symbolic tokens as follows: | ||
* On the s2scompile command line as define options | * On the [[s2scompile]] command line as define options | ||
-D IN="IN" | -D IN="IN" | ||
-D OUT="OUT" | -D OUT="OUT" |
Revision as of 21:00, 7 October 2008
As of STRIDE 3.0.0102 the syntax of scl_ptr and scl_ptr_sized has changed. The direction and usage attributes are changed to be string literals (put in quotes).
The direction and usage attributes used to be specified with reserved symbolic tokens (such as IN, OUT, INOUT, RETURN, INRETURN, POOL, or PRIVATE) and that in many cases caused misterious compile failures when any of these tokens was user defined as something else. From this release on those attributes are required to be put in quotes. Previously written SCL will need to be updated or it would not compile anymore. The following sample perl script could be used to authomate the conversion process:
#!/usr/bin/perl
use Cwd;
use File::Basename;
use strict;
use Carp;
use File::Spec;
use File::Copy;
my $currentDirectory = getcwd;
ProcessSubdirectories($currentDirectory);
sub ProcessSubdirectories {
my ($currentDirectory) = @_;
opendir(DIR, $currentDirectory) || die "can't open directory";
my @testDirectoryNames = readdir(DIR);
closedir(DIR);
my $testDirectoryName;
foreach $testDirectoryName (@testDirectoryNames) {
my $testDirectory = File::Spec->catfile($currentDirectory, $testDirectoryName);
if ((-d $testDirectory) &&
($testDirectoryName ne ".") &&
($testDirectoryName ne "..") &&
($testDirectoryName ne ".svn")) {
ProcessSubdirectories($testDirectory);
}
}
ProcessFiles($currentDirectory);
}
sub ProcessFiles {
my ($currentDirectory) = @_;
my $candidateFileName;
opendir(DIR, $currentDirectory) || die "can't open test type directory";
my @candidateFileNames = readdir(DIR);
closedir(DIR);
foreach $candidateFileName (@candidateFileNames) {
my $relativeCandidateFileName = File::Spec->catfile($currentDirectory, $candidateFileName);
if (-f $relativeCandidateFileName) {
if ($candidateFileName =~ m/^.+\.(h|hpp|h\+\+|c|cpp|c\+\+|i)$/i) {
my $saveCwd = getcwd;
chdir($currentDirectory);
ConvertFile($currentDirectory, $candidateFileName);
chdir($saveCwd);
}
}
}
}
sub ConvertFile {
my ($currentDirectory, $file) = @_;
my $relativeFile = File::Spec->catfile($currentDirectory, $file);
my $convertedFile = $file . ".converted";
if (PerformConversion($file, $convertedFile)) {
copy($convertedFile, $file) or die "Copy failed: $!";
}
if (-f $convertedFile) {
unlink($convertedFile);
}
}
sub PerformConversion {
my ($convertFrom, $convertTo) = @_;
my $successfulConversion = 0;
open FILE, $convertFrom or die $!;
my @lines = <FILE>;
close FILE;
my $changed = 0;
my $numberOfLines = scalar @lines;
for (my $i = 0; $i < $numberOfLines; $i++) {
my $line = \@lines[$i];
if ($$line =~ m/^\s*(\/\/|\/\*)?\s*\#\s*pragma\s+scl_ptr\s*\(.+,\s*(INRETURN|INOUT|IN|OUT|RETURN)\s*,\s*(PRIVATE|POOL)\s*\).*$/ ) {
if (!$changed) {
print "Converting $convertFrom\n";
}
print "<- $$line";
$$line =~ s/,\s*INRETURN\s*,/, "INRETURN",/;
$$line =~ s/,\s*RETURN\s*,/, "RETURN",/;
$$line =~ s/,\s*INOUT\s*,/, "INOUT",/;
$$line =~ s/,\s*OUT\s*,/, "OUT",/;
$$line =~ s/,\s*IN\s*,/, "IN",/;
$$line =~ s/,\s*POOL\s*\)/, "POOL"\)/;
$$line =~ s/,\s*PRIVATE\s*\)/, "PRIVATE"\)/;
$changed = 1;
print "-> $$line";
} elsif ($$line =~ m/^\s*(\/\/|\/\*)?\s*\#\s*pragma\s+scl_ptr_sized\s*\(.+,\s*(INRETURN|INOUT|IN|OUT|RETURN)\s*,\s*(PRIVATE|POOL)\s*\,.+\).*$/ ) {
if (!$changed) {
print "Converting $convertFrom\n";
}
print "<- $$line";
$$line =~ s/,\s*INRETURN\s*,/, "INRETURN",/;
$$line =~ s/,\s*RETURN\s*,/, "RETURN",/;
$$line =~ s/,\s*INOUT\s*,/, "INOUT",/;
$$line =~ s/,\s*OUT\s*,/, "OUT",/;
$$line =~ s/,\s*IN\s*,/, "IN",/;
$$line =~ s/,\s*POOL\s*,/, "POOL",/;
$$line =~ s/,\s*PRIVATE\s*,/, "PRIVATE",/;
$changed = 1;
print "-> $$line";
}
}
if ($changed) {
open FILE, ">", $convertTo or die $!;
foreach my $line (@lines) {
print FILE $line;
}
close FILE;
}
return $changed;
}
If for some reason the suggested update is not possible as a workaround that would allow successful compilation would be to predefine the old symbolic tokens as follows:
- On the s2scompile command line as define options
-D IN="IN" -D OUT="OUT" -D INOUT="INOUT" -D RETURN="RETURN" -D INRETURN="INRETURN" -D PRIVATE="PRIVATE" -D POOL="POOL"
- In a common header as #define
#define IN "IN" #define OUT "OUT" #define INOUT "INOUT" #define RETURN "RETURN" #define INRETURN "INRETURN" #define PRIVATE "PRIVATE" #define POOL "POOL"